3 * @author Sebastian Hack
21 #include "iredges_t.h"
25 #include "bechordal_t.h"
27 #include "besched_t.h"
28 #include "belistsched.h"
31 #include "bechordal.h"
33 #include "becopyoptmain.h"
34 #include "becopystat.h"
35 #include "bessadestr.h"
36 #include "bearch_firm.h"
41 #include "beasm_dump_globals.h"
42 #include "beasm_asm_gnu.h"
59 static be_main_env_t *be_init_env(be_main_env_t *env)
61 const arch_isa_if_t *isa = &firm_isa;
63 obstack_init(&env->obst);
65 env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0]));
66 arch_env_init(env->arch_env, isa);
67 env->arch_env->isa->init();
69 env->node_factory = obstack_alloc(&env->obst, sizeof(*env->node_factory));
70 be_node_factory_init(env->node_factory, isa);
72 arch_env_add_irn_handler(env->arch_env, &firm_irn_handler);
73 arch_env_add_irn_handler(env->arch_env,
74 be_node_get_irn_handler(env->node_factory));
79 static be_main_session_env_t *
80 be_init_session_env(be_main_session_env_t *env,
81 be_main_env_t *main_env, ir_graph *irg)
83 env->main_env = main_env;
89 static void prepare_graph(be_main_session_env_t *s)
92 * Duplicate consts in each block
93 * (This is just for the firm dummy backend)
95 // localize_consts(s->irg);
97 /* Remove critical edges */
98 remove_critical_cf_edges(s->irg);
100 /* Compute the dominance information. */
101 free_dom_and_peace(s->irg);
102 compute_doms(s->irg);
104 /* Compute the dominance frontiers */
105 s->dom_front = be_compute_dominance_frontiers(s->irg);
107 /* Ensure, that the ir_edges are computed. */
108 edges_assure(s->irg);
110 /* Compute loop nesting information (for weighting copies) */
111 if (get_irg_loopinfo_state(s->irg) != (loopinfo_valid & loopinfo_cf_consistent))
112 construct_cf_backedges(s->irg);
114 dump_dominator_information(true);
115 dump_ir_block_graph(s->irg, "-prepared");
116 dump_dominator_information(false);
119 static void be_main_loop(void)
123 const arch_isa_if_t *isa;
126 isa = arch_env_get_isa(env.arch_env);
129 for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
131 ir_graph *irg = get_irp_irg(i);
132 be_main_session_env_t session;
134 /* Init the session. */
135 be_init_session_env(&session, &env, irg);
137 /* Compute some analyses and prepare the graph for backend use. */
138 prepare_graph(&session);
140 /* Schedule the graphs. */
141 list_sched(irg, trivial_selector);
143 /* Verify the schedule */
144 sched_verify_irg(irg);
146 /* Remove all cases where a phi and one of its arguments interfere */
147 be_eliminate_phi_interferences(&session);
148 dump_ir_block_graph(session.irg, "-prephase");
152 /* Liveness analysis */
155 dump_ir_block_graph_sched(irg, "-sched");
157 copystat_collect_irg(irg, env.arch_env);
159 /* Perform the following for each register class. */
160 for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
161 be_chordal_env_t *chordal_env;
162 const arch_register_class_t *cls = isa->get_reg_class(j);
164 chordal_env = be_ra_chordal(irg, env.arch_env, cls);
166 #ifdef DUMP_ALLOCATED
167 dump_allocated_irg(env.arch_env, irg, "");
169 copystat_collect_cls(chordal_env);
171 be_copy_opt(chordal_env);
173 be_ssa_destruction(&session, chordal_env);
174 be_ssa_destruction_check(&session, chordal_env);
175 be_ra_chordal_check(chordal_env);
177 be_ra_chordal_done(chordal_env);
179 copystat_dump_pretty(irg);
180 be_numbering_done(irg);
184 void be_main(int argc, const char *argv[])
186 assembler_t *gnu_assembler;
187 FILE *asm_output_file;
190 gnu_assembler = gnuasm_create_assembler();
191 asm_output_file = fopen("asm_output.asm", "w");
193 asm_dump_globals(gnu_assembler);
194 gnuasm_dump(gnu_assembler, asm_output_file);
195 gnuasm_delete_assembler(gnu_assembler);
196 fclose(asm_output_file);