fix things when WITH_JVM and WITH_ILP is defined
[libfirm] / ir / be / bespillremat.c
index 0de1bdc..f4216c3 100644 (file)
@@ -94,7 +94,7 @@ static int opt_remat_while_live = 1;
 static int opt_timeout = 300;
 static double opt_cost_reload = 8.0;
 static double opt_cost_memoperand =  7.0;
-static double opt_cost_spill =  50.0;
+static double opt_cost_spill =  15.0;
 static double opt_cost_remat =  1.0;
 
 
@@ -136,17 +136,17 @@ static lc_opt_enum_mask_var_t remats_var = {
 };
 
 static const lc_opt_table_entry_t options[] = {
-       LC_OPT_ENT_ENUM_MASK("keepalive", "keep alive remats, spills or reloads",                   &keep_alive_var),
+       LC_OPT_ENT_ENUM_MASK("keepalive", "keep alive inserted nodes",                              &keep_alive_var),
 
        LC_OPT_ENT_BOOL     ("goodwin",  "activate goodwin reduction",                              &opt_goodwin),
        LC_OPT_ENT_BOOL     ("memcopies",  "activate memcopy handling",                             &opt_memcopies),
        LC_OPT_ENT_BOOL     ("memoperands",  "activate memoperands",                                &opt_memoperands),
-       LC_OPT_ENT_ENUM_INT ("remats",  "type of remats to insert (none, briggs, noinverse or all)",&remats_var),
+       LC_OPT_ENT_ENUM_INT ("remats",  "type of remats to insert",                                 &remats_var),
        LC_OPT_ENT_BOOL     ("repair_schedule",  "repair the schedule by rematting once used nodes",&opt_repair_schedule),
        LC_OPT_ENT_BOOL     ("no_enlage_liveness",  "do not enlarge liveness of operands of remats",&opt_no_enlarge_liveness),
        LC_OPT_ENT_BOOL     ("remat_while_live",  "only remat where rematted value was live",       &opt_remat_while_live),
 
-       LC_OPT_ENT_ENUM_MASK("dump", "dump problem, mps, solution, stats or pressure",              &dump_var),
+       LC_OPT_ENT_ENUM_MASK("dump", "dump problem, solution or statistical data",                  &dump_var),
        LC_OPT_ENT_BOOL     ("log",  "activate the lpp log",                                        &opt_log),
        LC_OPT_ENT_INT      ("timeout",  "ILP solver timeout",                                      &opt_timeout),
 
@@ -157,11 +157,17 @@ static const lc_opt_table_entry_t options[] = {
        { NULL }
 };
 
-void be_spill_remat_register_options(lc_opt_entry_t *grp)
+void be_init_spillremat(void)
 {
-       lc_opt_entry_t *my_grp = lc_opt_get_grp(grp, "remat");
-       lc_opt_add_table(my_grp, options);
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
+       lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");
+       lc_opt_entry_t *remat_grp = lc_opt_get_grp(chordal_grp, "remat");
+
+       lc_opt_add_table(remat_grp, options);
 }
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillremat);
 #endif
 
 
@@ -430,7 +436,7 @@ execution_frequency(const spill_ilp_t *si, const ir_node * irn)
                return ((double)be_profile_get_block_execcount(get_block(irn))) + FUDGE;
 
 #ifndef EXECFREQ_LOOPDEPH
-       return get_block_execfreq(si->chordal_env->exec_freq, get_block(irn)) + FUDGE;
+       return get_block_execfreq(si->chordal_env->birg->exec_freq, get_block(irn)) + FUDGE;
 #else
        if(is_Block(irn))
                return exp(get_loop_depth(get_irn_loop(irn)) * log(10)) + FUDGE;
@@ -501,7 +507,7 @@ get_remat_from_op(spill_ilp_t * si, const ir_node * dest_value, const ir_node *
 
                remat          = obstack_alloc(si->obst, sizeof(*remat));
                remat->op      = op;
-               remat->cost    = get_cost(si, op);
+               remat->cost    = (int)get_cost(si, op);
                remat->value   = dest_value;
                remat->proj    = proj;
                remat->inverse = 0;
@@ -1564,8 +1570,6 @@ luke_endwalker(ir_node * bb, void * data)
 
                ir_snprintf(buf, sizeof(buf), "reg_out_%N_%N", irn, bb);
                spill->reg_out = lpp_add_var_default(si->lpp, buf, lpp_binary, 0.0, 1.0);
-               /* if irn is used at the end of the block, then it is live anyway */
-               //lpp_set_factor_fast(si->lpp, cst, spill->reg_out, 1.0);
 
                ir_snprintf(buf, sizeof(buf), "mem_out_%N_%N", irn, bb);
                spill->mem_out = lpp_add_var_default(si->lpp, buf, lpp_binary, 0.0, 1.0);
@@ -2292,6 +2296,7 @@ skip_one_must_die:
 #endif
                        }
                } else {
+#if 0
                        pset_foreach(defs, tmp) {
                                op_t      *tmp_op = get_irn_link(tmp);
                                spill_t   *spill = set_find_spill(spill_bb->ilp, tmp);
@@ -2304,6 +2309,7 @@ skip_one_must_die:
                                lpp_set_factor_fast(si->lpp, cst, tmp_op->attr.live_range.ilp, 1.0);
                                lpp_set_factor_fast(si->lpp, cst, spill->spill, 1.0);
                        }
+#endif
                }
 
 
@@ -3401,16 +3407,14 @@ connect_all_spills_with_keep(spill_ilp_t * si)
 /** insert a spill at an arbitrary position */
 ir_node *be_spill2(const arch_env_t *arch_env, ir_node *irn, ir_node *insert)
 {
-       ir_node *bl     = is_Block(insert)?insert:get_nodes_block(insert);
+       ir_node  *bl    = is_Block(insert)?insert:get_nodes_block(insert);
        ir_graph *irg   = get_irn_irg(bl);
-       ir_node *frame  = get_irg_frame(irg);
-       ir_node *spill;
-       ir_node *next;
-
-       const arch_register_class_t *cls       = arch_get_irn_reg_class(arch_env, irn, -1);
-       const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
+       ir_node  *frame = get_irg_frame(irg);
+       ir_node  *spill;
+       ir_node  *next;
+       const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
 
-       spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
+       spill = be_new_Spill(cls, irg, bl, irn);
 
        /*
         * search the right insertion point. a spill of a phi cannot be put
@@ -3424,7 +3428,7 @@ ir_node *be_spill2(const arch_env_t *arch_env, ir_node *irn, ir_node *insert)
         * which is its default initialization (see above).
         */
 
-       if(bl == get_irg_start_block(irg) && sched_get_time_step(frame) >= sched_get_time_step(insert))
+       if (bl == get_irg_start_block(irg) && sched_get_time_step(frame) >= sched_get_time_step(insert))
                insert = frame;
 
        for (next = sched_next(insert); is_Phi(next) || is_Proj(next); next = sched_next(insert))
@@ -4135,9 +4139,9 @@ dump_phi_class(spill_ilp_t * si, pset * phiclass, const char * file)
 static void
 rewire_uses(spill_ilp_t * si)
 {
-       dom_front_info_t     *dfi = be_compute_dominance_frontiers(si->chordal_env->irg);
        defs_t               *defs;
        pset                 *ignore = pset_new_ptr(1);
+       be_dom_front_info_t *dom_front = si->chordal_env->birg->dom_front;
 
        pset_insert_ptr(ignore, get_irg_end(si->chordal_env->irg));
 
@@ -4166,7 +4170,7 @@ rewire_uses(spill_ilp_t * si)
                        //                              print_irn_pset(spills);
                        //                              print_irn_pset(reloads);
 
-                       be_ssa_constr_set_ignore(dfi, si->lv, spills, ignore);
+                       be_ssa_constr_set_ignore(dom_front, si->lv, spills, ignore);
                }
 
                del_pset(reloads);
@@ -4192,15 +4196,13 @@ rewire_uses(spill_ilp_t * si)
                        }
 
                        DBG((si->dbg, LEVEL_4, "\t    %d new definitions for value %+F\n", pset_count(nodes)-orig_kept, defs->value));
-                       be_ssa_constr_set(dfi, si->lv, nodes);
+                       be_ssa_constr_set(dom_front, si->lv, nodes);
 
                        del_pset(nodes);
                }
        }
 
 //     remove_unused_defs(si);
-
-       be_free_dominance_frontiers(dfi);
 }
 
 
@@ -4351,6 +4353,7 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
        char            dump_suffix2[256];
        struct obstack  obst;
        spill_ilp_t     si;
+       be_irg_t       *birg = chordal_env->birg;
 
        ir_snprintf(problem_name, sizeof(problem_name), "%F_%s", chordal_env->irg, chordal_env->cls->name);
        ir_snprintf(dump_suffix, sizeof(dump_suffix), "-%s-remats", chordal_env->cls->name);
@@ -4362,6 +4365,9 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
        if(opt_verify & VERIFY_DOMINANCE)
                be_check_dominance(chordal_env->irg);
 
+       be_assure_dom_front(birg);
+       be_assure_liveness(birg);
+
        obstack_init(&obst);
        si.chordal_env = chordal_env;
        si.obst = &obst;
@@ -4373,7 +4379,7 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
        si.all_possible_remats = pset_new_ptr_default();
        si.spills = pset_new_ptr_default();
        si.inverse_ops = pset_new_ptr_default();
-       si.lv = chordal_env->lv;
+       si.lv = birg->lv;
        si.keep = NULL;
        si.n_regs = get_n_regs(&si);
 
@@ -4536,7 +4542,7 @@ be_spill_remat(const be_chordal_env_t * chordal_env)
 
 #else                          /* WITH_ILP */
 
-static void
+static void INLINE
 only_that_you_can_compile_without_WITH_ILP_defined(void)
 {
 }