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