3 * @author Sebastian Hack
22 #include "besched_t.h"
23 #include "belistsched.h"
26 #include "bechordal.h"
28 #include "becopyoptmain.h"
30 #include "beasm_dump_globals.h"
31 #include "beasm_asm_gnu.h"
38 typedef struct _be_graph_info_t {
39 bitset_t *applied_phases;
42 static size_t be_info_offset = 0;
44 #define get_irg_be_info(irg) get_irg_data(irg, be_graph_info_t, be_info_offset)
46 static int phase_ids = 1;
47 static struct obstack obst;
49 int phase_register(phase_t *phase)
51 phase->id = phase_ids;
55 void phase_applied(const ir_graph *irg, const phase_t *phase)
57 be_graph_info_t *info = get_irg_be_info(irg);
59 if(!info->applied_phases)
60 info->applied_phases = bitset_obstack_alloc(&obst, N_PHASES);
62 bitset_set(info->applied_phases, phase->id);
65 int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...)
72 const be_graph_info_t *info = get_irg_be_info(irg);
73 const bitset_t *applied_phases = info->applied_phases;
77 for(i = 0; i < n; ++i) {
78 const phase_t *dep_phase = va_arg(args, const phase_t *);
80 if(!applied_phases || !bitset_is_set(applied_phases, dep_phase->id)) {
82 fprintf(stderr, "phase dependency unfulfilled: \"%s\" depends on \"%s\"\n",
83 phase->name, dep_phase->name);
89 assert(errors > 0 && "There were phase dependency errors");
98 be_info_offset = register_additional_graph_data(sizeof(be_graph_info_t));
104 be_ra_chordal_init();
108 /* The preliminary Firm backend isa. */
109 extern arch_isa_if_t arch_isa_if_firm;
111 static void be_main_loop(void)
114 const arch_isa_if_t *isa = &arch_isa_if_firm;
116 for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
119 ir_graph *irg = get_irp_irg(i);
121 localize_consts(irg);
122 #ifdef DUMP_LOCALIZED
123 dump_consts_local(0);
124 dump_ir_block_graph(irg, "-local-const");
128 /* Schedule the graphs. */
129 list_sched(irg, trivial_selector);
131 /* Liveness analysis */
135 * Perform the following for each register
138 for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
139 const arch_register_class_t *cls = isa->get_reg_class(j);
141 be_ra_chordal(irg, isa, cls);
143 #ifdef DUMP_ALLOCATED
144 dump_allocated_irg(irg, "");
147 be_ra_chordal_done(irg);
150 be_numbering_done(irg);
154 void be_main(int argc, const char *argv[])
156 assembler_t *gnu_assembler;
157 FILE *asm_output_file;
160 gnu_assembler = gnuasm_create_assembler();
161 asm_output_file = fopen("asm_output.asm", "w");
163 asm_dump_globals(gnu_assembler);
164 gnuasm_dump(gnu_assembler, asm_output_file);
165 gnuasm_delete_assembler(gnu_assembler);
166 fclose(asm_output_file);