16 #include "bephicongr_t.h"
17 #include "bephicoal_t.h"
20 #define DEBUG_LVL SET_LEVEL_1
22 #define DO_PHI_STATISTICS
23 #undef DUMP_IRG_PHI_STAT
25 #define DUMP_CUMULATIVE
26 #define CUMULATIVE_FILE "all.phistat"
28 #define ENV_PHI_STAT "PHI_STAT"
30 static firm_dbg_module_t *dbgphi = NULL;
32 static void phi_node_walker(ir_node *node, void *env) {
33 if (is_Phi(node) && mode_is_datab(get_irn_mode(node)))
34 pset_insert_ptr((pset *)env, node);
38 void be_phi_opt(ir_graph* irg) {
39 pset *all_phi_nodes, *all_phi_classes;
41 DBG((dbgphi, 1, "\n\n=======================> IRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
44 /* get all phi nodes */
45 DBG((dbgphi, 1, "-----------------------> Collecting phi nodes <-----------------------\n\n"));
46 all_phi_nodes = pset_new_ptr(64);
47 irg_walk_graph(irg, phi_node_walker, NULL, all_phi_nodes);
50 /* get all phi congruence classes */
51 DBG((dbgphi, 1, "-----------------------> Collecting phi classes <---------------------\n\n"));
52 all_phi_classes = be_phi_congr_classes(all_phi_nodes);
55 /* do some statistics */
56 #ifdef DO_PHI_STATISTICS
57 DBG((dbgphi, 1, "-----------------------> Collecting phi stats <-----------------------\n\n"));
59 phi_stat_collect(irg, all_phi_nodes, all_phi_classes);
60 #ifdef DUMP_IRG_PHI_STAT
63 snprintf(buf, sizeof(buf), "%s.phistat", get_entity_name(get_irg_entity(irg)));
65 phi_stat_dump_pretty(buf);
68 #ifdef DUMP_CUMULATIVE
69 phi_stat_update(CUMULATIVE_FILE);
71 phi_stat_update(getenv(ENV_PHI_STAT));
75 /* try to coalesce the colors of each phi class */
76 DBG((dbgphi, 1, "-----------------------> Coalescing <---------------------------------\n\n"));
78 be_phi_coalesce(all_phi_classes);
79 free_dom_and_peace(irg);
83 void be_phi_opt_init(void) {
84 dbgphi = firm_dbg_register("Phi optimizer");
85 firm_dbg_set_mask(dbgphi, DEBUG_LVL);
87 be_phi_congr_class_init();