fixed lea->add conversion
[libfirm] / ir / be / bestat.c
1 /**
2  * This file calls the corresponding statistic functions for
3  * some backend statistics.
4  * $Id$
5  */
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #ifdef FIRM_STATISTICS
11
12 #include "irnode_t.h"
13 #include "irprintf.h"
14 #include "irgwalk.h"
15 #include "irhooks.h"
16 #include "dbginfo_t.h"
17 #include "firmstat_t.h"
18 #include "irtools.h"
19
20 #include "bestat.h"
21 #include "belive_t.h"
22 #include "besched.h"
23
24 /**
25  * Collect reg pressure statistics per block and per class.
26  */
27 static void stat_reg_pressure_block(ir_node *block, void *env) {
28         be_irg_t         *birg = env;
29         const arch_env_t *aenv = birg->main_env->arch_env;
30         int i, n = arch_isa_get_n_reg_class(aenv->isa);
31
32         for (i = 0; i < n; i++) {
33                 const arch_register_class_t *cls = arch_isa_get_reg_class(aenv->isa, i);
34                 ir_node  *irn;
35                 pset     *live_nodes = pset_new_ptr(64);
36                 int       max_live;
37
38                 live_nodes = be_liveness_end_of_block(aenv, cls, block, live_nodes);
39                 max_live   = pset_count(live_nodes);
40
41                 sched_foreach_reverse(block, irn) {
42                         int cnt;
43
44                         live_nodes = be_liveness_transfer(aenv, cls, irn, live_nodes);
45                         cnt        = pset_count(live_nodes);
46
47                         max_live = cnt < max_live ? max_live : cnt;
48                 }
49
50                 stat_be_block_regpressure(birg->irg, block, MIN(max_live, 5), cls->name);
51         }
52 }
53
54 void be_do_stat_reg_pressure(be_irg_t *birg) {
55         if (stat_is_active()) {
56                 be_liveness(birg->irg);
57                 /* Collect register pressure information for each block */
58                 irg_block_walk_graph(birg->irg, stat_reg_pressure_block, NULL, birg);
59         }
60 }
61
62 /**
63  * Notify statistic module about amount of ready nodes.
64  */
65 void be_do_stat_sched_ready(ir_node *block, nodeset *ready_set) {
66         if (stat_is_active()) {
67                 stat_be_block_sched_ready(get_irn_irg(block), block, nodeset_count(ready_set));
68         }
69 }
70
71 /**
72  * Pass information about a perm to the statistic module.
73  */
74 void be_do_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {
75         if (stat_is_active()) {
76                 stat_be_block_stat_perm(class_name, n_regs, perm, block, n, real_size);
77         }
78 }
79
80 /**
81  * Pass information about a cycle or chain in a perm to the statistic module.
82  */
83 void be_do_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block, int is_chain, int n_elems, int n_ops) {
84         if (stat_is_active()) {
85                 stat_be_block_stat_permcycle(class_name, perm, block, is_chain, n_elems, n_ops);
86         }
87 }
88
89 #else
90
91 void (be_do_stat_reg_pressure)(be_irg_t *birg) {}
92 void (be_do_stat_sched_ready)(ir_node *block, nodeset *ready_set) {}
93 void (be_do_stat_perm)(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {}
94
95 #endif /* FIRM_STATISTICS */