bestat is only compiled if FIRMSTAT is defined
[libfirm] / ir / be / bestat.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #ifdef FIRM_STATISTICS
6
7 #include "irnode_t.h"
8 #include "irprintf.h"
9 #include "irgwalk.h"
10 #include "irhooks.h"
11 #include "dbginfo_t.h"
12 #include "firmstat.h"
13 #include "ident.h"
14
15 #include "bestat.h"
16 #include "belive_t.h"
17 #include "besched.h"
18
19 #undef MIN
20 #define MIN(a, b) (a < b ? a : b)
21
22 /**
23  * Collect reg pressure statistics per block and per class.
24  */
25 static void stat_reg_pressure_block(ir_node *block, void *env) {
26         be_irg_t         *birg = env;
27         const arch_env_t *aenv = birg->main_env->arch_env;
28         int i, n = arch_isa_get_n_reg_class(aenv->isa);
29
30         for (i = 0; i < n; i++) {
31                 const arch_register_class_t *cls = arch_isa_get_reg_class(aenv->isa, i);
32                 ir_node  *irn;
33                 pset     *live_nodes = pset_new_ptr(64);
34                 int       max_live;
35
36                 live_nodes = be_liveness_end_of_block(aenv, cls, block, live_nodes);
37                 max_live   = pset_count(live_nodes);
38
39                 sched_foreach_reverse(block, irn) {
40                         int cnt;
41
42                         live_nodes = be_liveness_transfer(aenv, cls, irn, live_nodes);
43                         cnt        = pset_count(live_nodes);
44
45                         max_live = cnt < max_live ? max_live : cnt;
46                 }
47
48                 hook_be_block_regpressure(block, birg->irg, max_live, new_id_from_str(cls->name));
49         }
50 }
51
52 void be_do_stat_reg_pressure(be_irg_t *birg) {
53         /* Collect register pressure information for each block */
54         irg_block_walk_graph(birg->irg, stat_reg_pressure_block, NULL, birg);
55 }
56
57 /**
58  * Notify statistic module about amount of ready nodes.
59  */
60 void be_do_stat_sched_ready(ir_node *block, nodeset *ready_set) {
61         hook_be_block_sched_ready(block, get_irn_irg(block), MIN(nodeset_count(ready_set), 5));
62 }
63
64 #else
65
66 void (be_do_stat_reg_pressure)(be_irg_t *birg) {}
67 void (be_do_stat_sched_ready)(ir_node *block, nodeset *ready_set) {}
68
69 #endif /* FIRM_STATISTICS */