Changed ->link to set_irn_link.
[libfirm] / ir / be / bemain.c
index a062658..c42486e 100644 (file)
@@ -19,6 +19,7 @@
 #include "phiclass.h"
 #include "irdom_t.h"
 #include "iredges_t.h"
+#include "irloop_t.h"
 
 #include "be_t.h"
 #include "bechordal_t.h"
 #include "bearch_firm.h"
 #include "benode_t.h"
 #include "beirgmod.h"
+#include "bedupl.h"
 
 #include "beasm_dump_globals.h"
 #include "beasm_asm_gnu.h"
 
 #undef DUMP_ALLOCATED
-#undef DUMP_LOCALIZED
 
 #define N_PHASES 256
 
@@ -60,6 +61,7 @@ static be_main_env_t *be_init_env(be_main_env_t *env)
   const arch_isa_if_t *isa = &firm_isa;
 
   obstack_init(&env->obst);
+  env->dbg = firm_dbg_register("be.main");
 
   env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0]));
   arch_env_init(env->arch_env, isa);
@@ -106,6 +108,10 @@ static void prepare_graph(be_main_session_env_t *s)
        /* Ensure, that the ir_edges are computed. */
        edges_assure(s->irg);
 
+       /* Compute loop nesting information (for weighting copies) */
+       if (get_irg_loopinfo_state(s->irg) != (loopinfo_valid & loopinfo_cf_consistent))
+               construct_cf_backedges(s->irg);
+
        dump_dominator_information(true);
        dump_ir_block_graph(s->irg, "-prepared");
        dump_dominator_information(false);
@@ -126,37 +132,50 @@ static void be_main_loop(void)
                ir_graph *irg = get_irp_irg(i);
                be_main_session_env_t session;
 
+               DBG((env.dbg, LEVEL_1, "be irg: %F\n", irg));
+
                /* Init the session. */
                be_init_session_env(&session, &env, irg);
 
                /* Compute some analyses and prepare the graph for backend use. */
                prepare_graph(&session);
 
-#ifdef DUMP_LOCALIZED
-               dump_consts_local(0);
-               dump_ir_block_graph(irg, "-local-const");
-#endif
-               be_numbering(irg);
-
                /* Schedule the graphs. */
                list_sched(irg, trivial_selector);
+               dump_ir_block_graph_sched(irg, "-sched");
 
                /* Verify the schedule */
                sched_verify_irg(irg);
 
+               /* Build liveness information */
+               be_liveness(irg);
+
+               /* Remove all cases where a phi and one of its arguments interfere */
+               be_eliminate_phi_interferences(&session);
+               dump_ir_block_graph(session.irg, "-prephase");
+
                /* Liveness analysis */
                be_liveness(irg);
 
-               dump_ir_block_graph_sched(irg, "-sched");
                copystat_reset();
                copystat_collect_irg(irg, env.arch_env);
 
+               /*
+                * Verifying the schedule once again cannot hurt.
+                */
+               sched_verify_irg(irg);
+
                /* Perform the following for each register class. */
                for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
                        be_chordal_env_t *chordal_env;
                        const arch_register_class_t *cls = isa->get_reg_class(j);
 
-      chordal_env = be_ra_chordal(irg, env.arch_env, cls);
+                       DBG((env.dbg, LEVEL_1, "\treg class: %s\n", cls->name));
+
+                       be_numbering(irg);
+                       be_liveness(irg);
+
+                       chordal_env = be_ra_chordal(irg, env.arch_env, cls);
 
 #ifdef DUMP_ALLOCATED
                        dump_allocated_irg(env.arch_env, irg, "");
@@ -164,11 +183,16 @@ static void be_main_loop(void)
                        copystat_collect_cls(chordal_env);
 
                        be_copy_opt(chordal_env);
-                       // be_ssa_destruction(&session, chordal_env);
+
+                       be_ssa_destruction(&session, chordal_env);
+                       be_ssa_destruction_check(&session, chordal_env);
+                       be_ra_chordal_check(chordal_env);
+
                        be_ra_chordal_done(chordal_env);
+                       be_numbering_done(irg);
                }
+
                copystat_dump_pretty(irg);
-           be_numbering_done(irg);
        }
 }