1803ec4a0c353cf4ead00374ed7dbd0333244205
[libfirm] / ir / be / bephiopt.c
1 /**
2  * @author Daniel Grund
3  * @date 04.01.2005
4  */
5
6 #include "pset.h"
7 #include "irgraph.h"
8 #include "irnode.h"
9 #include "irgwalk.h"
10
11 #include "domtree.h"
12 #include "bephiopt.h"
13 #include "bephicongr_t.h"
14 #include "bephicoal_t.h"
15 #include "phistat.h"
16
17 #define CUMULATIVE_FILE "~/all.phistat"
18
19 static void phi_node_walker(ir_node *node, void *env) {
20         if (is_Phi(node) && mode_is_datab(get_irn_mode(node)))
21                 pset_insert_ptr((pset *)env, node);
22 }
23
24
25 void be_phi_opt(ir_graph* irg) {
26         dominfo_t *dominfo;
27         pset *all_phi_nodes, *all_phi_classes;
28         char buf[1024];
29
30         /* get all phi nodes */
31         printf("-----------------------> Collecting phi nodes <-----------------------\n");
32         all_phi_nodes = pset_new_ptr(64);
33         irg_walk_graph(irg, phi_node_walker, NULL, all_phi_nodes);
34
35         /* get all phi congruence classes */
36         printf("-----------------------> Collecting phi classes <-----------------------\n");
37         all_phi_classes = be_phi_congr_classes(all_phi_nodes);
38
39         /* do some statistics */
40         printf("-----------------------> Collecting phi stats <-----------------------\n");
41         phi_stat_reset();
42         phi_stat_collect(irg, all_phi_nodes, all_phi_classes);
43         snprintf(buf, sizeof(buf), "%s.phistat", get_entity_name(get_irg_entity(irg)));
44         //phi_stat_dump_pretty(buf);
45         phi_stat_dump(buf, CUMULATIVE_FILE);
46
47         /* try to coalesce the colors of each phi class */
48         printf("-----------------------> Building domtree <-----------------------\n");
49         dominfo = domtree_create(irg);
50         printf("-----------------------> Coalescing <-----------------------\n");
51         be_phi_coalesce_locals(all_phi_classes, dominfo);
52         printf("-----------------------> Destroying domtree <-----------------------\n");
53         domtree_free(dominfo);
54 }
55
56
57 void be_phi_opt_init(void) {
58         be_phi_congr_class_init();
59         be_phi_coal_init();
60 }