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"
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 */
141 /* Perform the following for each register class. */
142 for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
143 const arch_register_class_t *cls = isa->get_reg_class(j);
145 be_ra_chordal(irg, isa, cls);
147 #ifdef DUMP_ALLOCATED
148 dump_allocated_irg(irg, "");
151 stat_collect_irg(irg);
153 be_copy_opt(irg, isa, cls);
154 be_ra_chordal_done(irg);
159 be_numbering_done(irg);
163 void be_main(int argc, const char *argv[])
165 assembler_t *gnu_assembler;
166 FILE *asm_output_file;
169 gnu_assembler = gnuasm_create_assembler();
170 asm_output_file = fopen("asm_output.asm", "w");
172 asm_dump_globals(gnu_assembler);
173 gnuasm_dump(gnu_assembler, asm_output_file);
174 gnuasm_delete_assembler(gnu_assembler);
175 fclose(asm_output_file);