#include "benode_t.h"
#include "bechordal_t.h"
+#undef REMAT
/* This enables re-computation of values. Current state: Unfinished and buggy. */
#undef BUGGY_REMAT
} spill_ctx_t;
struct _spill_env_t {
- firm_dbg_module_t *dbg;
const arch_register_class_t *cls;
const be_chordal_env_t *chordal_env;
struct obstack obst;
set *spill_ctxs;
set *spills; /**< all spill_info_t's, which must be placed */
- pset *mem_phis; /**< set of all special spilled phis. allocated and freed seperately */
+ pset *mem_phis; /**< set of all special spilled phis. allocated and freed separately */
decide_irn_t is_mem_phi; /**< callback func to decide if a phi needs special spilling */
void *data; /**< data passed to all callbacks */
+ DEBUG_ONLY(firm_dbg_module_t *dbg;)
};
static int cmp_spillctx(const void *a, const void *b, size_t n) {
return ! (xx->spilled_node == yy->spilled_node);
}
-spill_env_t *be_new_spill_env(firm_dbg_module_t *dbg,
- const be_chordal_env_t *chordal_env,
- decide_irn_t is_mem_phi, void *data) {
-
+spill_env_t *be_new_spill_env(const be_chordal_env_t *chordal_env, decide_irn_t is_mem_phi, void *data) {
spill_env_t *env = xmalloc(sizeof(env[0]));
env->spill_ctxs = new_set(cmp_spillctx, 1024);
env->spills = new_set(cmp_spillinfo, 1024);
env->cls = chordal_env->cls;
- env->dbg = dbg;
env->is_mem_phi = is_mem_phi;
env->data = data;
env->chordal_env = chordal_env;
}
}
+#ifdef REMAT
#ifdef BUGGY_REMAT
return 1;
}
+#else /* BUGGY_REMAT */
+
+static int check_remat_conditions(spill_env_t *senv, ir_node *spill, ir_node *spilled, ir_node *reloader) {
+ const arch_env_t *aenv = senv->chordal_env->birg->main_env->arch_env;
+
+ return get_irn_arity(spilled) == 0 &&
+ be_is_Spill(spill) &&
+ arch_irn_is(aenv, spilled, rematerializable);
+}
+
+#endif /* BUGGY_REMAT */
+
static ir_node *do_remat(spill_env_t *senv, ir_node *spilled, ir_node *reloader) {
ir_node *res;
ir_node *bl = (is_Block(reloader)) ? reloader : get_nodes_block(reloader);
get_irn_mode(spilled),
get_irn_arity(spilled),
get_irn_in(spilled));
+ copy_node_attr(spilled, res);
DBG((senv->dbg, LEVEL_1, "Insert remat %+F before reloader %+F\n", res, reloader));
/* the spill for this reloader */
ir_node *spill = be_spill_node(senv, si->spilled_node);
-#ifdef BUGGY_REMAT
+#ifdef REMAT
if (check_remat_conditions(senv, spill, si->spilled_node, rld->reloader))
new_val = do_remat(senv, si->spilled_node, rld->reloader);
else
} spill_slot_t;
typedef struct _ss_env_t {
- firm_dbg_module_t *dbg;
struct obstack ob;
be_chordal_env_t *cenv;
pmap *slots; /* maps spill_contexts to spill_slots */
- pmap *types; /* maps modes to types */
+ pmap *types; /* maps modes to types */
+ DEBUG_ONLY(firm_dbg_module_t *dbg;)
} ss_env_t;
-
+/**
+ * Walker: compute the spill slots
+ */
static void compute_spill_slots_walker(ir_node *spill, void *env) {
ss_env_t *ssenv = env;
ir_node *ctx;
entry = pmap_find(ssenv->slots, ctx);
if (!entry) {
+ struct _arch_env_t *arch_env = ssenv->cenv->birg->main_env->arch_env;
+ ir_node *spilled = get_irn_n(spill, be_pos_Spill_val);
+ const arch_register_t *reg = arch_get_irn_register(arch_env, spilled);
+ const arch_register_class_t *cls = arch_register_get_class(reg);
+ ir_mode *largest_mode = arch_register_class_mode(cls);
+
/* this is a new spill context */
ss = obstack_alloc(&ssenv->ob, sizeof(*ss));
- ss->members = pset_new_ptr(8);
- ss->largest_mode = get_irn_mode(get_irn_n(spill, be_pos_Spill_val));
- ss->size = get_mode_size_bytes(ss->largest_mode);
- ss->align = ss->size; /* TODO Assumed for now */
+ ss->members = pset_new_ptr(8);
+ ss->largest_mode = largest_mode;
+ ss->size = get_mode_size_bytes(ss->largest_mode);
+ ss->align = arch_isa_get_reg_class_alignment(arch_env->isa, cls);
pmap_insert(ssenv->slots, ctx, ss);
} else {
ir_node *irn;
ssenv.cenv = cenv;
ssenv.slots = pmap_create();
ssenv.types = pmap_create();
- ssenv.dbg = firm_dbg_register("ir.be.spillslots");
+ FIRM_DBG_REGISTER(ssenv.dbg, "ir.be.spillslots");
/* Get initial spill slots */
irg_walk_graph(cenv->irg, NULL, compute_spill_slots_walker, &ssenv);