c59fc5432c1776ef28bbf19451566254c2ea5822
[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         be_liveness(birg->irg);
56         /* Collect register pressure information for each block */
57         irg_block_walk_graph(birg->irg, stat_reg_pressure_block, NULL, birg);
58 }
59
60 /**
61  * Notify statistic module about amount of ready nodes.
62  */
63 void be_do_stat_sched_ready(ir_node *block, nodeset *ready_set) {
64         stat_be_block_sched_ready(get_irn_irg(block), block, nodeset_count(ready_set));
65 }
66
67 /**
68  * Pass information about a perm to the statistic module.
69  */
70 void be_do_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {
71         stat_be_block_stat_perm(class_name, n_regs, perm, block, n, real_size);
72 }
73
74 /**
75  * Pass information about a cycle or chain in a perm to the statistic module.
76  */
77 void be_do_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block, int is_chain, int n_elems, int n_ops) {
78         stat_be_block_stat_permcycle(class_name, perm, block, is_chain, n_elems, n_ops);
79 }
80
81 #else
82
83 void (be_do_stat_reg_pressure)(be_irg_t *birg) {}
84 void (be_do_stat_sched_ready)(ir_node *block, nodeset *ready_set) {}
85 void (be_do_stat_perm)(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {}
86
87 #endif /* FIRM_STATISTICS */