typedef struct _belady_env_t {
struct obstack ob;
- const be_node_factory_t *factory;
const arch_env_t *arch;
const arch_register_class_t *cls;
int n_regs; /** number of regs in this reg-class */
ir_node *instr; /**< current instruction */
unsigned instr_nr; /**< current instruction number (relative to block start) */
pset *used; /**< holds the values used (so far) in the current BB */
+ pset *copies; /**< holds all copies placed due to phi-spilling */
spill_env_t *senv; /* see bespill.h */
pset *reloads; /**< all reload nodes placed */
for (max=get_irn_arity(irn), o=0; o<max; ++o) {
ir_node *arg = get_irn_n(irn, o);
ir_node *pred_block = get_Block_cfgpred_block(get_nodes_block(irn), o);
- ir_node *cpy = new_Copy(bel->factory, bel->cls, irg, pred_block, arg);
+ ir_node *cpy = be_new_Copy(bel->cls, irg, pred_block, arg);
+ pset_insert_ptr(bel->copies, cpy);
DBG((dbg, DBG_START, " place a %+F of %+F in %+F\n", cpy, arg, pred_block));
sched_add_before(pred_block, cpy);
set_irn_n(irn, o, cpy);
pset_remove_ptr(rlds, irn);
}
+/**
+ * Removes all copies introduced for phi-spills
+ */
+static void remove_copies(belady_env_t *bel) {
+ ir_node *irn;
+
+ for (irn = pset_first(bel->copies); irn; irn = pset_next(bel->copies)) {
+ ir_node *src, *spill;
+
+ assert(be_is_Copy(irn));
+ assert(get_irn_n_edges(irn) == 1 && "This is not a copy introduced in 'compute_block_start_info()'. Who created it?");
+
+ spill = get_irn_edge(get_irn_irg(irn), irn, 0)->src;
+ assert(be_is_Spill(spill) && "This is not a copy introduced in 'compute_block_start_info()'. Who created it?");
+
+ src = get_irn_n(irn, 0);
+ set_irn_n(spill, 0, src);
+ }
+}
+
/**
* Finds all unused reloads and remove them from the schedule
* Also removes spills if they are not used anymore after removing reloads
/* init belady env */
obstack_init(&bel.ob);
- bel.factory = chordal_env->main_env->node_factory;
bel.arch = chordal_env->main_env->arch_env;
bel.cls = chordal_env->cls;
bel.n_regs = arch_register_class_n_regs(bel.cls);
bel.uses = be_begin_uses(chordal_env->irg, chordal_env->main_env->arch_env, bel.cls);
bel.senv = be_new_spill_env(dbg, chordal_env, is_mem_phi, NULL);
bel.reloads = pset_new_ptr_default();
+ bel.copies = pset_new_ptr_default();
/* do the work */
irg_block_walk_graph(chordal_env->irg, compute_block_start_info, NULL, &bel);
irg_block_walk_graph(chordal_env->irg, fix_block_borders, NULL, &bel);
be_insert_spills_reloads(bel.senv, bel.reloads);
remove_unused_reloads(chordal_env->irg, &bel);
+ remove_copies(&bel);
+
+
/* clean up */
del_pset(bel.reloads);