16 #include "bephicongr_t.h"
17 #include "bephicoal_t.h"
20 #define DO_PHI_STATISTICS
21 #undef DUMP_IRG_PHI_STAT
22 #define DUMP_ALL_PHI_STAT
26 #define CUMULATIVE_FILE "all.phistat"
27 #define ENV_PHI_STAT "PHI_STAT"
29 static firm_dbg_module_t *dbgphi = NULL;
31 static void phi_node_walker(ir_node *node, void *env) {
32 if (is_Phi(node) && mode_is_datab(get_irn_mode(node)))
33 pset_insert_ptr((pset *)env, node);
37 void be_phi_opt(ir_graph* irg) {
38 pset *all_phi_nodes, *all_phi_classes;
40 DBG((dbgphi, 1, "\n\n=======================> IRG: %s\n\n", get_entity_name(get_irg_entity(irg))));
43 /* get all phi nodes */
44 DBG((dbgphi, 1, "-----------------------> Collecting phi nodes <-----------------------\n\n"));
45 all_phi_nodes = pset_new_ptr(64);
46 irg_walk_graph(irg, phi_node_walker, NULL, all_phi_nodes);
49 /* get all phi congruence classes */
50 DBG((dbgphi, 1, "-----------------------> Collecting phi classes <---------------------\n\n"));
51 all_phi_classes = be_phi_congr_classes(all_phi_nodes);
54 /* do some statistics */
55 #ifdef DO_PHI_STATISTICS
56 DBG((dbgphi, 1, "-----------------------> Collecting phi stats <-----------------------\n\n"));
58 phi_stat_collect(irg, all_phi_nodes, all_phi_classes);
59 #ifdef DUMP_IRG_PHI_STAT
62 snprintf(buf, sizeof(buf), "%s.phistat", get_entity_name(get_irg_entity(irg)));
64 phi_stat_dump_pretty(buf);
67 #ifdef DUMP_ALL_PHI_STAT
68 phi_stat_update(CUMULATIVE_FILE);
70 phi_stat_update(getenv(ENV_PHI_STAT));
74 /* try to coalesce the colors of each phi class */
75 DBG((dbgphi, 1, "-----------------------> Coalescing <---------------------------------\n\n"));
77 be_phi_coalesce(all_phi_classes);
78 free_dom_and_peace(irg);
82 void be_phi_opt_init(void) {
83 dbgphi = firm_dbg_register("Phi optimizer");
84 firm_dbg_set_mask(dbgphi, DEBUG_LVL);
86 be_phi_congr_class_init();