ia32: improve Test peephole optimisation
[libfirm] / ir / be / bemain.c
index b113fd4..17297b1 100644 (file)
@@ -87,7 +87,7 @@ static be_options_t be_options = {
        0,                                 /* create PIC code */
        BE_VERIFY_WARN,                    /* verification level: warn */
        "",                                /* ilp server */
-       "cplex",                           /* ilp solver */
+       "",                                /* ilp solver */
        0,                                 /* enable statistic event dumping */
        "",                                /* print stat events */
 };
@@ -345,21 +345,24 @@ const backend_params *be_get_backend_param(void)
  * @param env          an empty environment
  * @param file_handle  the file handle where the output will be written to
  */
-static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle)
+static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle,
+                                  const char *compilation_unit_name)
 {
        memset(env, 0, sizeof(*env));
        env->options              = &be_options;
+       env->file_handle          = file_handle;
        env->ent_trampoline_map   = pmap_create();
        env->pic_trampolines_type = new_type_class(NEW_ID("$PIC_TRAMPOLINE_TYPE"));
        env->ent_pic_symbol_map   = pmap_create();
        env->pic_symbols_type     = new_type_struct(NEW_ID("$PIC_SYMBOLS_TYPE"));
+       env->cup_name             = compilation_unit_name;
 
        remove_irp_type(env->pic_trampolines_type);
        remove_irp_type(env->pic_symbols_type);
        set_class_final(env->pic_trampolines_type, 1);
 
        memset(asm_constraint_flags, 0, sizeof(asm_constraint_flags));
-       env->arch_env = arch_env_init(isa_if, file_handle, env);
+       env->arch_env = arch_env_init(isa_if, env);
 
        return env;
 }
@@ -420,6 +423,10 @@ static void initialize_birg(be_irg_t *birg, ir_graph *irg, be_main_env_t *env)
        /* Remove critical edges */
        remove_critical_cf_edges_ex(irg, /*ignore_exception_edges=*/0);
 
+       /* For code generation all unreachable code and Bad nodes should be gone */
+       remove_unreachable_code(irg);
+       remove_bads(irg);
+
        /* Ensure, that the ir_edges are computed. */
        edges_assure(irg);
 
@@ -475,17 +482,6 @@ void be_lower_for_target(void)
        set_irp_phase_state(phase_low);
 }
 
-static void emit_global_asms(void)
-{
-       size_t n = get_irp_n_asms();
-       size_t i;
-       for (i = 0; i < n; ++i) {
-               be_emit_cstring("#APP\n");
-               be_emit_ident(get_irp_asm(i));
-               be_emit_cstring("\n#NO_APP\n");
-       }
-}
-
 /**
  * The Firm backend main loop.
  * Do architecture specific lowering for all graphs
@@ -513,14 +509,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
                }
        }
 
-       be_init_env(&env, file_handle);
-       env.cup_name = cup_name;
-
-       be_dbg_open();
-       be_dbg_unit_begin(cup_name);
-       be_dbg_types();
-
-       emit_global_asms();
+       be_init_env(&env, file_handle, cup_name);
 
        arch_env = env.arch_env;
 
@@ -718,21 +707,6 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 
                dump(DUMP_RA, irg, "ra");
 
-               /* let the code generator prepare the graph for emitter */
-               be_timer_push(T_FINISH);
-               if (arch_env->impl->after_ra != NULL)
-                       arch_env->impl->after_ra(irg);
-               be_timer_pop(T_FINISH);
-
-               /* fix stack offsets */
-               be_timer_push(T_ABI);
-               be_abi_fix_stack_nodes(irg);
-               be_remove_dead_nodes_from_schedule(irg);
-               be_abi_fix_stack_bias(irg);
-               be_timer_pop(T_ABI);
-
-               dump(DUMP_SCHED, irg, "fix_stack_after_ra");
-
                be_timer_push(T_FINISH);
                if (arch_env->impl->finish != NULL)
                        arch_env->impl->finish(irg);
@@ -809,9 +783,6 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 
        arch_env_done(arch_env);
 
-       be_dbg_unit_end();
-       be_dbg_close();
-
        ir_profile_free();
        be_done_env(&env);