phi opt deactivated due to bug.
[libfirm] / ir / be / bemain.c
1 /**
2  * Backend driver.
3  * @author Sebastian Hack
4  * @date 25.11.2004
5  */
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <stdarg.h>
11
12 #include "obst.h"
13 #include "bitset.h"
14
15 #include "irprog.h"
16 #include "irgraph.h"
17 #include "irdump.h"
18
19 #include "be_t.h"
20 #include "bera_t.h"
21 #include "benumb_t.h"
22 #include "besched_t.h"
23 #include "belistsched.h"
24 #include "belive_t.h"
25 #include "beutil.h"
26 #include "phiclass_t.h"
27 #include "bechordal.h"
28 #include "bechordal.h"
29 #include "bephiopt.h"
30 #include "phistat.h"
31
32 #define DUMP_LOCAL 1
33
34 #define N_PHASES 256
35
36 typedef struct _be_graph_info_t {
37         bitset_t *applied_phases;
38 } be_graph_info_t;
39
40 static size_t be_info_offset = 0;
41
42 #define get_irg_be_info(irg) get_irg_data(irg, be_graph_info_t, be_info_offset)
43
44 static int phase_ids = 1;
45 static struct obstack obst;
46
47 int phase_register(phase_t *phase)
48 {
49         phase->id = phase_ids;
50         return phase_ids++;
51 }
52
53 void phase_applied(const ir_graph *irg, const phase_t *phase)
54 {
55         be_graph_info_t *info = get_irg_be_info(irg);
56
57         if(!info->applied_phases)
58                 info->applied_phases = bitset_obstack_alloc(&obst, N_PHASES);
59
60         bitset_set(info->applied_phases, phase->id);
61 }
62
63 int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...)
64 {
65         int errors = 0;
66         int i;
67         va_list args;
68
69         if(n > 0) {
70                 const be_graph_info_t *info = get_irg_be_info(irg);
71                 const bitset_t *applied_phases = info->applied_phases;
72
73                 va_start(args, n);
74
75                 for(i = 0; i < n; ++i) {
76                         const phase_t *dep_phase = va_arg(args, const phase_t *);
77
78                         if(!applied_phases || !bitset_is_set(applied_phases, dep_phase->id)) {
79                                 errors++;
80                                 fprintf(stderr, "phase dependency unfulfilled: \"%s\" depends on \"%s\"\n",
81                                                 phase->name, dep_phase->name);
82                         }
83                 }
84
85                 va_end(args);
86
87                 assert(errors > 0 && "There were phase dependency errors");
88         }
89
90         return errors;
91 }
92
93 void be_init(void)
94 {
95         obstack_init(&obst);
96         be_info_offset = register_additional_graph_data(sizeof(be_graph_info_t));
97
98         be_sched_init();
99         be_liveness_init();
100         be_numbering_init();
101         be_ra_init();
102         be_ra_chordal_init();
103         be_phi_opt_init();
104 }
105
106 extern void be_ra_chordal(ir_graph *irg);
107
108 static void be_main_loop(void)
109 {
110         int i, n;
111
112         for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
113                 ir_graph *irg = get_irp_irg(i);
114
115                 localize_consts(irg);
116                 if (DUMP_LOCAL) {
117                         dump_consts_local(0);
118                         dump_ir_block_graph(irg, "-local");
119                 }
120
121                 be_numbering(irg);
122                 list_sched(irg, trivial_selector, NULL);
123                 be_liveness(irg);
124                 be_ra_chordal(irg);
125                 //be_phi_opt(irg);
126                 //be_phi_destruction(irg);
127
128                 be_ra_chordal_done(irg);
129                 be_numbering_done(irg);
130         }
131 }
132
133 void be_main(int argc, const char *argv[])
134 {
135         be_main_loop();
136 }