*** empty log message ***
[libfirm] / ir / be / bephiopt.c
1 /**
2  * @author Daniel Grund
3  * @date 04.01.2005
4  */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8
9 #include "pset.h"
10 #include "irgraph.h"
11 #include "irnode.h"
12 #include "irgwalk.h"
13 #include "irouts.h"
14 #include "irdom.h"
15
16 #include "bephiopt.h"
17 #include "bephicongr_t.h"
18 #include "bephicoal_t.h"
19 #include "phistat.h"
20
21 #define DEBUG_LVL SET_LEVEL_1
22
23 #define DO_PHI_STATISTICS
24 #undef DUMP_IRG_PHI_STAT
25
26 #define DUMP_CUMULATIVE
27 #define CUMULATIVE_FILE "all.phistat"
28
29 #define ENV_PHI_STAT "PHI_STAT"
30
31 static firm_dbg_module_t *dbgphi = NULL;
32
33 static void phi_node_walker(ir_node *node, void *env) {
34         if (is_Phi(node) && mode_is_datab(get_irn_mode(node)))
35                 pset_insert_ptr((pset *)env, node);
36 }
37
38
39 void be_phi_opt(ir_graph* irg) {
40         pset *all_phi_nodes, *all_phi_classes;
41
42         DBG((dbgphi, 1, "\n\n=======================> IRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
43
44
45         /* get all phi nodes */
46         DBG((dbgphi, 1, "-----------------------> Collecting phi nodes <-----------------------\n\n"));
47         all_phi_nodes = pset_new_ptr(64);
48         irg_walk_graph(irg, phi_node_walker, NULL, all_phi_nodes);
49
50
51         /* get all phi congruence classes */
52         DBG((dbgphi, 1, "-----------------------> Collecting phi classes <---------------------\n\n"));
53         all_phi_classes = be_phi_congr_classes(all_phi_nodes);
54
55
56         /* do some statistics */
57 #ifdef DO_PHI_STATISTICS
58         DBG((dbgphi, 1, "-----------------------> Collecting phi stats <-----------------------\n\n"));
59         phi_stat_reset();
60         phi_stat_collect(irg, all_phi_nodes, all_phi_classes);
61 #ifdef DUMP_IRG_PHI_STAT
62         {
63                 char buf[1024];
64                 snprintf(buf, sizeof(buf), "%s.phistat", get_entity_name(get_irg_entity(irg)));
65                 //phi_stat_dump(buf);
66                 phi_stat_dump_pretty(buf);
67         }
68 #endif
69 #ifdef DUMP_CUMULATIVE
70         phi_stat_update(CUMULATIVE_FILE);
71 #endif
72         phi_stat_update(getenv(ENV_PHI_STAT));
73 #endif
74
75
76         /* try to coalesce the colors of each phi class */
77         DBG((dbgphi, 1, "-----------------------> Coalescing <---------------------------------\n\n"));
78         compute_outs(irg);
79         compute_doms(irg);
80         be_phi_coalesce(all_phi_classes);
81         free_dom_and_peace(irg);
82 }
83
84
85 void be_phi_opt_init(void) {
86         dbgphi = firm_dbg_register("Phi optimizer");
87         firm_dbg_set_mask(dbgphi, DEBUG_LVL);
88
89         be_phi_congr_class_init();
90         be_phi_coal_init();
91 }