3 * @author Sebastian Hack
23 #include "besched_t.h"
24 #include "belistsched.h"
27 #include "bechordal.h"
29 #include "becopyoptmain.h"
30 #include "becopystat.h"
32 #include "beasm_dump_globals.h"
33 #include "beasm_asm_gnu.h"
36 #define DUMP_LOCALIZED
40 typedef struct _be_graph_info_t {
41 bitset_t *applied_phases;
44 static size_t be_info_offset = 0;
46 #define get_irg_be_info(irg) get_irg_data(irg, be_graph_info_t, be_info_offset)
48 static int phase_ids = 1;
49 static struct obstack obst;
51 int phase_register(phase_t *phase)
53 phase->id = phase_ids;
57 void phase_applied(const ir_graph *irg, const phase_t *phase)
59 be_graph_info_t *info = get_irg_be_info(irg);
61 if(!info->applied_phases)
62 info->applied_phases = bitset_obstack_alloc(&obst, N_PHASES);
64 bitset_set(info->applied_phases, phase->id);
67 int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...)
74 const be_graph_info_t *info = get_irg_be_info(irg);
75 const bitset_t *applied_phases = info->applied_phases;
79 for(i = 0; i < n; ++i) {
80 const phase_t *dep_phase = va_arg(args, const phase_t *);
82 if(!applied_phases || !bitset_is_set(applied_phases, dep_phase->id)) {
84 fprintf(stderr, "phase dependency unfulfilled: \"%s\" depends on \"%s\"\n",
85 phase->name, dep_phase->name);
91 assert(errors > 0 && "There were phase dependency errors");
100 be_info_offset = register_additional_graph_data(sizeof(be_graph_info_t));
106 be_ra_chordal_init();
113 /* The preliminary Firm backend isa. */
114 extern arch_isa_if_t arch_isa_if_firm;
116 static void be_main_loop(void)
119 const arch_isa_if_t *isa = &arch_isa_if_firm;
121 for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
123 ir_graph *irg = get_irp_irg(i);
125 localize_consts(irg);
126 #ifdef DUMP_LOCALIZED
127 dump_consts_local(0);
128 dump_ir_block_graph(irg, "-local-const");
132 /* Schedule the graphs. */
133 list_sched(irg, trivial_selector);
135 /* Liveness analysis */
140 stat_collect_irg(irg);
142 /* Perform the following for each register class. */
143 for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
144 const arch_register_class_t *cls = isa->get_reg_class(j);
146 be_ra_chordal(irg, isa, cls);
148 #ifdef DUMP_ALLOCATED
149 dump_allocated_irg(irg, "");
151 be_copy_opt(irg, isa, cls);
152 be_ra_chordal_done(irg);
157 be_numbering_done(irg);
161 void be_main(int argc, const char *argv[])
163 assembler_t *gnu_assembler;
164 FILE *asm_output_file;
167 gnu_assembler = gnuasm_create_assembler();
168 asm_output_file = fopen("asm_output.asm", "w");
170 asm_dump_globals(gnu_assembler);
171 gnuasm_dump(gnu_assembler, asm_output_file);
172 gnuasm_delete_assembler(gnu_assembler);
173 fclose(asm_output_file);