3 * @author Sebastian Hack
21 #include "iredges_t.h"
24 #include "bechordal_t.h"
26 #include "besched_t.h"
27 #include "belistsched.h"
30 #include "bechordal.h"
32 #include "becopyoptmain.h"
33 #include "becopystat.h"
34 #include "bessadestr.h"
35 #include "bearch_firm.h"
39 #include "beasm_dump_globals.h"
40 #include "beasm_asm_gnu.h"
58 static be_main_env_t *be_init_env(be_main_env_t *env)
60 const arch_isa_if_t *isa = &firm_isa;
62 obstack_init(&env->obst);
64 env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0]));
65 arch_env_init(env->arch_env, isa);
66 env->arch_env->isa->init();
68 env->node_factory = obstack_alloc(&env->obst, sizeof(*env->node_factory));
69 be_node_factory_init(env->node_factory, isa);
71 arch_env_add_irn_handler(env->arch_env, &firm_irn_handler);
72 arch_env_add_irn_handler(env->arch_env,
73 be_node_get_irn_handler(env->node_factory));
78 static be_main_session_env_t *
79 be_init_session_env(be_main_session_env_t *env,
80 be_main_env_t *main_env, ir_graph *irg)
82 env->main_env = main_env;
88 static void prepare_graph(be_main_session_env_t *s)
91 * Duplicate consts in each block
92 * (This is just for the firm dummy backend)
94 // localize_consts(s->irg);
96 /* Remove critical edges */
97 remove_critical_cf_edges(s->irg);
99 /* Compute the dominance information. */
100 free_dom_and_peace(s->irg);
101 compute_doms(s->irg);
103 /* Compute the dominance frontiers */
104 s->dom_front = be_compute_dominance_frontiers(s->irg);
106 /* Ensure, that the ir_edges are computed. */
107 edges_assure(s->irg);
109 dump_dominator_information(true);
110 dump_ir_block_graph(s->irg, "-prepared");
111 dump_dominator_information(false);
114 static void be_main_loop(void)
118 const arch_isa_if_t *isa;
121 isa = arch_env_get_isa(env.arch_env);
124 for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
126 ir_graph *irg = get_irp_irg(i);
127 be_main_session_env_t session;
129 /* Init the session. */
130 be_init_session_env(&session, &env, irg);
132 /* Compute some analyses and prepare the graph for backend use. */
133 prepare_graph(&session);
135 #ifdef DUMP_LOCALIZED
136 dump_consts_local(0);
137 dump_ir_block_graph(irg, "-local-const");
141 /* Schedule the graphs. */
142 list_sched(irg, trivial_selector);
144 /* Verify the schedule */
145 sched_verify_irg(irg);
147 /* Liveness analysis */
150 dump_ir_block_graph_sched(irg, "-sched");
152 copystat_collect_irg(irg, env.arch_env);
154 /* Perform the following for each register class. */
155 for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
156 be_chordal_env_t *chordal_env;
157 const arch_register_class_t *cls = isa->get_reg_class(j);
159 chordal_env = be_ra_chordal(irg, env.arch_env, cls);
161 #ifdef DUMP_ALLOCATED
162 dump_allocated_irg(env.arch_env, irg, "");
164 copystat_collect_cls(chordal_env);
166 be_copy_opt(chordal_env);
167 // be_ssa_destruction(&session, chordal_env);
168 be_ra_chordal_done(chordal_env);
170 copystat_dump_pretty(irg);
171 be_numbering_done(irg);
175 void be_main(int argc, const char *argv[])
177 assembler_t *gnu_assembler;
178 FILE *asm_output_file;
181 gnu_assembler = gnuasm_create_assembler();
182 asm_output_file = fopen("asm_output.asm", "w");
184 asm_dump_globals(gnu_assembler);
185 gnuasm_dump(gnu_assembler, asm_output_file);
186 gnuasm_delete_assembler(gnu_assembler);
187 fclose(asm_output_file);