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