Bugfix
[libfirm] / ir / be / bemain.c
index 05e8fae..b5a35be 100644 (file)
@@ -8,6 +8,7 @@
 #endif
 
 #include <stdarg.h>
+#include <mcheck.h>
 
 #include "obst.h"
 #include "bitset.h"
@@ -36,7 +37,7 @@
 #include "bearch_firm.h"
 #include "benode_t.h"
 #include "beirgmod.h"
-#include "bedupl.h"
+#include "bespillilp.h"
 
 #include "beasm_dump_globals.h"
 #include "beasm_asm_gnu.h"
@@ -61,6 +62,8 @@ 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");
+  firm_dbg_set_mask(env->dbg, SET_LEVEL_1);
 
   env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0]));
   arch_env_init(env->arch_env, isa);
@@ -88,11 +91,11 @@ be_init_session_env(be_main_session_env_t *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);
+       /* set the current graph (this is important for several firm functions) */
+       current_ir_graph = s->irg;
+
+       /* Let the isa prepare the graph. */
+       s->main_env->arch_env->isa->prepare_graph(s->irg);
 
        /* Remove critical edges */
        remove_critical_cf_edges(s->irg);
@@ -105,7 +108,7 @@ static void prepare_graph(be_main_session_env_t *s)
        s->dom_front = be_compute_dominance_frontiers(s->irg);
 
        /* Ensure, that the ir_edges are computed. */
-       edges_assure(s->irg);
+       edges_activate(s->irg);
 
        /* Compute loop nesting information (for weighting copies) */
        if (get_irg_loopinfo_state(s->irg) != (loopinfo_valid & loopinfo_cf_consistent))
@@ -131,6 +134,8 @@ static void be_main_loop(void)
                ir_graph *irg = get_irp_irg(i);
                be_main_session_env_t session;
 
+               DBG((env.dbg, LEVEL_1, "====> IRG: %F\n", irg));
+
                /* Init the session. */
                be_init_session_env(&session, &env, irg);
 
@@ -139,58 +144,65 @@ static void be_main_loop(void)
 
                /* Schedule the graphs. */
                list_sched(irg, trivial_selector);
+               dump_ir_block_graph_sched(irg, "-sched");
 
                /* 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 */
+               /* Build liveness information */
                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;
                        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, "----> Reg class: %s\n", cls->name));
+
+      be_spill_ilp(&session, cls);
+                       dump_ir_block_graph_sched(session.irg, "-spill");
+
+                       be_liveness(irg);
+                       be_numbering(irg);
+                       be_check_pressure(&session, cls);
+
+#if 0
+                       {
+                               FILE *f;
+                               char buf[128];
+                               ir_snprintf(buf, sizeof(buf), "%F_%s-live.txt", irg, cls->name);
+                               if((f = fopen(buf, "wt")) != NULL) {
+                                       be_liveness_dump(session.irg, f);
+                                       fclose(f);
+                               }
+                       }
+#endif
+
+                       chordal_env = be_ra_chordal(&session, cls);
 
 #ifdef DUMP_ALLOCATED
                        dump_allocated_irg(env.arch_env, irg, "");
 #endif
+#if 0
                        copystat_collect_cls(chordal_env);
 
                        be_copy_opt(chordal_env);
 
-                       be_ssa_destruction(&session, chordal_env);
-                       be_ssa_destruction_check(&session, chordal_env);
+                       be_ssa_destruction(chordal_env);
+                       be_ssa_destruction_check(chordal_env);
+#endif
                        be_ra_chordal_check(chordal_env);
 
                        be_ra_chordal_done(chordal_env);
+                       be_numbering_done(irg);
                }
+               dump_ir_block_graph_sched(session.irg, "-post");
 
+               copystat_dump(irg);
                copystat_dump_pretty(irg);
-    be_numbering_done(irg);
        }
 }
 
@@ -199,7 +211,10 @@ void be_main(int argc, const char *argv[])
        assembler_t *gnu_assembler;
        FILE *asm_output_file;
 
+       mtrace();
        be_main_loop();
+       muntrace();
+
        gnu_assembler = gnuasm_create_assembler();
        asm_output_file = fopen("asm_output.asm", "w");
 
@@ -207,4 +222,5 @@ void be_main(int argc, const char *argv[])
        gnuasm_dump(gnu_assembler, asm_output_file);
        gnuasm_delete_assembler(gnu_assembler);
        fclose(asm_output_file);
+
 }