added additional cut inequalities for multi-col-usage.
[libfirm] / ir / be / bemain.c
index a0971d9..05e8fae 100644 (file)
@@ -17,6 +17,9 @@
 #include "irgraph.h"
 #include "irdump.h"
 #include "phiclass.h"
+#include "irdom_t.h"
+#include "iredges_t.h"
+#include "irloop_t.h"
 
 #include "be_t.h"
 #include "bechordal_t.h"
 #include "bessadestr.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
 
@@ -72,7 +76,8 @@ static be_main_env_t *be_init_env(be_main_env_t *env)
   return env;
 }
 
-be_main_session_env_t *be_init_session_env(be_main_session_env_t *env,
+static be_main_session_env_t *
+be_init_session_env(be_main_session_env_t *env,
     be_main_env_t *main_env, ir_graph *irg)
 {
   env->main_env = main_env;
@@ -81,6 +86,36 @@ be_main_session_env_t *be_init_session_env(be_main_session_env_t *env,
   return env;
 }
 
+static void prepare_graph(be_main_session_env_t *s)
+{
+       /*
+        * Duplicate consts in each block
+        * (This is just for the firm dummy backend)
+        */
+       // localize_consts(s->irg);
+
+       /* Remove critical edges */
+       remove_critical_cf_edges(s->irg);
+
+       /* Compute the dominance information. */
+       free_dom_and_peace(s->irg);
+       compute_doms(s->irg);
+
+       /* Compute the dominance frontiers */
+       s->dom_front = be_compute_dominance_frontiers(s->irg);
+
+       /* 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);
+}
+
 static void be_main_loop(void)
 {
        int i, n;
@@ -96,25 +131,43 @@ static void be_main_loop(void)
                ir_graph *irg = get_irp_irg(i);
                be_main_session_env_t session;
 
+               /* Init the session. */
                be_init_session_env(&session, &env, irg);
 
-               remove_critical_cf_edges(irg);
-
-               localize_consts(irg);
-#ifdef DUMP_LOCALIZED
-               dump_consts_local(0);
-               dump_ir_block_graph(irg, "-local-const");
-#endif
-               be_numbering(irg);
+               /* Compute some analyses and prepare the graph for backend use. */
+               prepare_graph(&session);
 
                /* Schedule the graphs. */
                list_sched(irg, trivial_selector);
 
+               /* Verify the schedule */
+               sched_verify_irg(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");
+
+               be_numbering(irg);
+
                /* Liveness analysis */
                be_liveness(irg);
 
+               dump_ir_block_graph_sched(irg, "-sched");
+
                copystat_reset();
                copystat_collect_irg(irg, env.arch_env);
+
+    /*
+     * Spilling changed the liveness information.
+     * Recompute it now.
+     */
+    be_liveness(irg);
+
+    /*
+     * 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;
@@ -128,11 +181,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_check(&session, chordal_env);
+                       be_ra_chordal_check(chordal_env);
+
                        be_ra_chordal_done(chordal_env);
                }
+
                copystat_dump_pretty(irg);
-           be_numbering_done(irg);
+    be_numbering_done(irg);
        }
 }