removed call to my funcs. had to check in but couldn't test
[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 "bephicongr_t.h"
27 #include "bechordal.h"
28 #include "bechordal.h"
29 #include "bephiopt.h"
30 #include "phistat.h"
31
32 #undef DUMP_ALLOCATED
33 #undef DUMP_LOCALIZED
34
35 #define N_PHASES 256
36
37 typedef struct _be_graph_info_t {
38         bitset_t *applied_phases;
39 } be_graph_info_t;
40
41 static size_t be_info_offset = 0;
42
43 #define get_irg_be_info(irg) get_irg_data(irg, be_graph_info_t, be_info_offset)
44
45 static int phase_ids = 1;
46 static struct obstack obst;
47
48 int phase_register(phase_t *phase)
49 {
50         phase->id = phase_ids;
51         return phase_ids++;
52 }
53
54 void phase_applied(const ir_graph *irg, const phase_t *phase)
55 {
56         be_graph_info_t *info = get_irg_be_info(irg);
57
58         if(!info->applied_phases)
59                 info->applied_phases = bitset_obstack_alloc(&obst, N_PHASES);
60
61         bitset_set(info->applied_phases, phase->id);
62 }
63
64 int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...)
65 {
66         int errors = 0;
67         int i;
68         va_list args;
69
70         if(n > 0) {
71                 const be_graph_info_t *info = get_irg_be_info(irg);
72                 const bitset_t *applied_phases = info->applied_phases;
73
74                 va_start(args, n);
75
76                 for(i = 0; i < n; ++i) {
77                         const phase_t *dep_phase = va_arg(args, const phase_t *);
78
79                         if(!applied_phases || !bitset_is_set(applied_phases, dep_phase->id)) {
80                                 errors++;
81                                 fprintf(stderr, "phase dependency unfulfilled: \"%s\" depends on \"%s\"\n",
82                                                 phase->name, dep_phase->name);
83                         }
84                 }
85
86                 va_end(args);
87
88                 assert(errors > 0 && "There were phase dependency errors");
89         }
90
91         return errors;
92 }
93
94 void be_init(void)
95 {
96         obstack_init(&obst);
97         be_info_offset = register_additional_graph_data(sizeof(be_graph_info_t));
98
99         be_sched_init();
100         be_liveness_init();
101         be_numbering_init();
102         be_ra_init();
103         be_ra_chordal_init();
104         be_phi_opt_init();
105 }
106
107 extern void be_ra_chordal(ir_graph *irg);
108
109 static void be_main_loop(void)
110 {
111         int i, n;
112
113         for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
114                 ir_graph *irg = get_irp_irg(i);
115
116                 localize_consts(irg);
117 #ifdef DUMP_LOCALIZED
118                 dump_consts_local(0);
119                 dump_ir_block_graph(irg, "-local-const");
120 #endif
121                 be_numbering(irg);
122                 list_sched(irg, trivial_selector, NULL);
123                 be_liveness(irg);
124                 be_ra_chordal(irg);
125
126 #ifdef DUMP_ALLOCATED
127                 dump_allocated_irg(irg);
128 #endif
129                 //be_phi_opt(irg);
130
131                 be_ra_chordal_done(irg);
132                 be_numbering_done(irg);
133         }
134 }
135
136 void be_main(int argc, const char *argv[])
137 {
138         be_main_loop();
139 }