static int opt_no_enlarge_liveness = 0;
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_remat = 1.0
+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_remat = 1.0;
#ifdef WITH_LIBCORE
{ NULL, 0 }
};
-static lc_opt_enum_mask_var_t dump_var = {
+static lc_opt_enum_mask_var_t keep_alive_var = {
&opt_keep_alive, keepalive_items
};
{ "none", REMATS_NONE },
{ "briggs", REMATS_BRIGGS },
{ "noinverse", REMATS_NOINVERSE },
- { "ALL", REMATS_ALL },
+ { "all", REMATS_ALL },
{ NULL, 0 }
};
-static lc_opt_enum_mask_var_t dump_var = {
+static lc_opt_enum_mask_var_t remats_var = {
&opt_remats, remats_items
};
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 ("remat", "type of remats to insert (none, briggs, noinverse or all)", &remats_var),
+ LC_OPT_ENT_ENUM_INT ("remats", "type of remats to insert (none, briggs, noinverse or all)",&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_enlarge_liveness),
+ 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", "remat only values that can be used by real ops", &opt_remat_while_live),
LC_OPT_ENT_ENUM_MASK("dump", "dump ifg before, after or after each cloud", &dump_var),
}
#endif
-//#define EXECFREQ_LOOPDEPH /* compute execution frequency from loop depth only */
+
+//#define EXECFREQ_LOOPDEPH /* compute execution frequency from loop depth only */
+//#define SCHEDULE_PHIM /* insert phim nodes into schedule */
#define SOLVE
//#define SOLVE_LOCAL
#define LPP_SOLVER "cplex"
-#define MAX_PATHS 16
+#define MAX_PATHS INT_MAX
#define ILP_UNDEF -1
typedef struct _spill_ilp_t {
const ir_node *proj = NULL;
if(is_Proj(dest_value)) {
- op = get_irn_n(op, 0);
+ op = get_Proj_pred(op);
proj = dest_value;
}
get_irn_n_nonignore_args(const spill_ilp_t * si, const ir_node * irn)
{
int n;
- unsigned int ret = 0;
+ int ret = 0;
+
+// if(is_Proj(irn))
+// irn = get_Proj_pred(irn);
for(n=get_irn_arity(irn)-1; n>=0; --n) {
- if(has_reg_class(si, irn)) ++ret;
+ const ir_node *arg = get_irn_n(irn, n);
+
+ if(has_reg_class(si, arg)) ++ret;
}
return ret;
if(opt_no_enlarge_liveness) {
if(has_reg_class(si, arg) && live) {
- res &= pset_find_ptr(live, arg)?1:0;
+ res &= pset_find_ptr((pset*)live, arg)?1:0;
} else {
res &= value_is_defined_before(si, pos, arg);
}
*proj_copy;
op_t *op;
- DBG((si->dbg, LEVEL_3, "\t >inserting remat %+F\n", remat->op));
+ DBG((si->dbg, LEVEL_3, "\t >inserting remat2 %+F\n", remat->op));
copy = insert_copy_after(si, remat->op, pos);
irn = next;
}
- be_lv_foreach(si->lv, bb, be_lv_state_end | be_lv_state_in, i) {
- ir_node *value = be_lv_get_irn(si->lv, bb, i);
+ /* add remats at end if successor has multiple predecessors */
+ if(is_merge_edge(bb)) {
+ pset *live_out = pset_new_ptr_default();
+ ir_node *value;
+
+ be_lv_foreach(si->lv, bb, be_lv_state_end, i) {
+ value = be_lv_get_irn(si->lv, bb, i);
- /* add remats at end if successor has multiple predecessors */
- if(is_merge_edge(bb)) {
- /* add remats at end of block */
if (be_is_live_end(si->lv, bb, value) && has_reg_class(si, value)) {
- remat_info_t *remat_info,
- query;
- remat_t *remat;
+ pset_insert_ptr(live_out, value);
+ }
+ }
- query.irn = value;
- query.remats = NULL;
- query.remats_by_operand = NULL;
- remat_info = set_find(si->remat_info, &query, sizeof(query), HASH_PTR(value));
+ /* add remats at end of block */
+ pset_foreach(live_out, value) {
+ remat_info_t *remat_info,
+ query;
+ remat_t *remat;
- if(remat_info && remat_info->remats) {
- pset_foreach(remat_info->remats, remat) {
- DBG((si->dbg, LEVEL_4, "\t considering remat %+F at end of block %+F\n", remat->op, bb));
+ query.irn = value;
+ query.remats = NULL;
+ query.remats_by_operand = NULL;
+ remat_info = set_find(si->remat_info, &query, sizeof(query), HASH_PTR(value));
- insert_remat_before(si, remat, bb, NULL);
- }
+ if(remat_info && remat_info->remats) {
+ pset_foreach(remat_info->remats, remat) {
+ DBG((si->dbg, LEVEL_4, "\t considering remat %+F at end of block %+F\n", remat->op, bb));
+
+ insert_remat_before(si, remat, bb, live_out);
}
}
}
- if(is_diverge_edge(bb)) {
- /* add remat2s at beginning of block */
+ del_pset(live_out);
+ }
+
+ if(is_diverge_edge(bb)) {
+ pset *live_in = pset_new_ptr_default();
+ ir_node *value;
+
+ be_lv_foreach(si->lv, bb, be_lv_state_in, i) {
+ value = be_lv_get_irn(si->lv, bb, i);
+
+ if (has_reg_class(si, value)) {
+ pset_insert_ptr(live_in, value);
+ }
+ }
+
+ /* add remat2s at beginning of block */
+ pset_foreach(live_in, value) {
if ((be_is_live_in(si->lv, bb, value) || (is_Phi(value) && get_nodes_block(value)==bb)) && has_reg_class(si, value)) {
remat_info_t *remat_info,
query;
query.remats_by_operand = NULL;
remat_info = set_find(si->remat_info, &query, sizeof(query), HASH_PTR(value));
- if(remat_info && remat_info->remats) {
- pset_foreach(remat_info->remats, remat) {
- DBG((si->dbg, LEVEL_4, "\t considering remat %+F at beginning of block %+F\n", remat->op, bb));
+ if(remat_info && remat_info->remats_by_operand) {
+ pset_foreach(remat_info->remats_by_operand, remat) {
+ DBG((si->dbg, LEVEL_4, "\t considering remat2 %+F at beginning of block %+F\n", remat->op, bb));
/* put the remat here if all its args are available */
- insert_remat_after(si, remat, bb, NULL);
+ insert_remat_after(si, remat, bb, live_in);
}
}
}
}
+ del_pset(live_in);
}
}
ilp_cst_t rel_cst;
ir_snprintf(buf, sizeof(buf), "reload_%N_%N", bb, irn);
- reload = lpp_add_var_default(si->lpp, buf, lpp_binary, opt_cost_reload*execution_frequency(si, bb), 0.0);
+ reload = lpp_add_var_default(si->lpp, buf, lpp_binary, opt_cost_reload*execution_frequency(si, bb), 1.0);
set_insert_keyval(spill_bb->reloads, irn, INT_TO_PTR(reload));
/* reload <= mem_out */
spill->mem_in = lpp_add_var_default(si->lpp, buf, lpp_binary, 0.0, default_spilled);
lpp_set_factor_fast(si->lpp, cst, spill->mem_in, -1.0);
- if(is_Phi(spill->irn) && get_nodes_block(spill->irn) == bb) {
+ if(opt_memcopies && is_Phi(spill->irn) && get_nodes_block(spill->irn) == bb) {
int n;
op_t *op = get_irn_link(spill->irn);
assert(spill_p);
lpp_set_factor_fast(si->lpp, mem_in, spill_p->mem_out, -1.0);
- lpp_set_factor_fast(si->lpp, mem_in, op->attr.live_range.args.copies[n], -1.0);
+ if(opt_memcopies)
+ lpp_set_factor_fast(si->lpp, mem_in, op->attr.live_range.args.copies[n], -1.0);
+
lpp_set_factor_fast(si->lpp, reg_in, spill_p->reg_out, -1.0);
}
}
if(get_nodes_block(user) == bb
&& !is_Phi(user)
&& b != user
+ && !pset_find_ptr(si->inverse_ops, user)
&& value_dominates(b, user))
return 1;
}
/* a is only interesting if it is in my register class and if it is inside a phi class */
if (has_reg_class(si, a) && get_phi_class(a)) {
- if(a_op->is_remat)
+ if(a_op->is_remat || pset_find_ptr(si->inverse_ops, a))
continue;
for(l2=_be_lv_next_irn(si->lv, bb, 0xff, l1+1); l2>=0; l2=_be_lv_next_irn(si->lv, bb, 0xff, l2+1)) {
/* a and b are only interesting if they are in the same phi class */
if(has_reg_class(si, b) && get_phi_class(a) == get_phi_class(b)) {
- if(b_op->is_remat)
+ if(b_op->is_remat || pset_find_ptr(si->inverse_ops, b))
continue;
if(values_interfere_in_block(si, bb, a, b)) {
paths += find_copy_path(si, arg, target, any_interfere, copies, visited);
pset_remove(copies, INT_TO_PTR(copy), copy);
- /*if(paths > MAX_PATHS) {
+ if(paths > MAX_PATHS) {
if(pset_count(copies) == 0) {
ilp_cst_t cst;
char buf[256];
}
} else if(pset_count(copies) == 0) {
paths = 0;
- }*/
+ }
}
}
paths += find_copy_path(si, user, target, any_interfere, copies, visited);
pset_remove(copies, INT_TO_PTR(copy), copy);
- /*if(paths > MAX_PATHS) {
+ if(paths > MAX_PATHS) {
if(pset_count(copies) == 0) {
ilp_cst_t cst;
char buf[256];
}
} else if(pset_count(copies) == 0) {
paths = 0;
- }*/
+ }
}
}
ir_node *bad = get_irg_bad(si->chordal_env->irg);
if(si->keep) {
- ir_node *end = get_irg_end(si->chordal_env->irg);
- ir_node **keeps;
+// ir_node *end = get_irg_end(si->chordal_env->irg);
+// ir_node **keeps;
for (n=get_irn_arity(si->keep)-1; n>=0; --n) {
ir_node *keep_arg = get_irn_n(si->keep, n);
/**
* @param before The node after which the spill will be placed in the schedule
*/
-/* TODO set context properly */
static ir_node *
insert_spill(spill_ilp_t * si, ir_node * irn, const ir_node * value, ir_node * before)
{
set_irn_link(mem_phi, defs->spills);
defs->spills = mem_phi;
+#ifdef SCHEDULE_PHIM
sched_add_after(phi, mem_phi);
+#endif
if(opt_keep_alive & KEEPALIVE_SPILLS)
pset_insert_ptr(si->spills, mem_phi);