#include "bespillbelady.h"
#include "beverify.h"
#include "benodesets.h"
+#include "bespilloptions.h"
#define DBG_LIVE 1
#define DBG_LOOPANA 2
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
typedef struct morgan_env {
- const be_chordal_env_t *cenv;
const arch_env_t *arch;
const arch_register_class_t *cls;
ir_graph *irg;
+ const be_lv_t *lv;
struct obstack obst;
/** maximum safe register pressure */
int registers_available;
bitset_t *livethrough_unused;
} loop_attr_t;
-typedef struct block_attr {
+typedef struct morgan_block_attr {
const ir_node *block;
/** set of all values that are live in the block but not used in the block */
bitset_t *livethrough_unused;
}
/**
- * Determine edges going out of a loop (= edges that go to a block that is not inside
- * the loop or one of its subloops)
+ * Determine edges going out of a loop (= edges that go to a block that is not
+ * inside the loop or one of its subloops)
*/
-static INLINE void construct_loop_edges(ir_node* block, void* data) {
+static INLINE void construct_loop_edges(ir_node *block, void *data) {
morgan_env_t *env = data;
int n_cfgpreds = get_Block_n_cfgpreds(block);
int i;
static INLINE void init_livethrough_unuseds(block_attr_t *attr, morgan_env_t *env) {
const ir_node *block;
int i;
+ const be_lv_t *lv = env->lv;
if(attr->livethrough_unused != NULL)
return;
attr->livethrough_unused = bitset_obstack_alloc(&env->obst, get_irg_last_idx(env->irg));
// copy all live-outs into the livethrough_unused set
- be_lv_foreach(env->cenv->lv, block, be_lv_state_in | be_lv_state_out, i) {
- ir_node *irn = be_lv_get_irn(env->cenv->lv, block, i);
+ be_lv_foreach(lv, block, be_lv_state_in | be_lv_state_out, i) {
+ ir_node *irn = be_lv_get_irn(lv, block, i);
int node_idx;
if(!consider_for_spilling(env->arch, env->cls, irn))
DBG((dbg, DBG_CHOOSE, "Spilling %+F ", to_spill));
for(edge = set_first(loop_attr->out_edges); edge != NULL; edge = set_next(loop_attr->out_edges)) {
- be_add_reload_on_edge(env->senv, to_spill, edge->block, edge->pos);
+ be_add_reload_on_edge(env->senv, to_spill, edge->block, edge->pos, env->cls, 1);
}
}
}
int max_pressure;
int loop_unused_spills_needed;
pset *live_nodes = pset_new_ptr_default();
+ const be_lv_t *lv = env->lv;
- be_liveness_end_of_block(env->cenv->lv, env->arch, env->cls, block, live_nodes);
+ be_liveness_end_of_block(lv, env->arch, env->cls, block, live_nodes);
max_pressure = pset_count(live_nodes);
DBG((dbg, DBG_LIVE, "Reduce pressure to %d In Block %+F:\n", env->registers_available, block));
return outer_spills_needed;
}
-void be_spill_morgan(be_chordal_env_t *chordal_env) {
- ir_graph *irg = chordal_env->irg;
+void be_spill_morgan(be_irg_t *birg, const arch_register_class_t *cls) {
+ ir_graph *irg = be_get_birg_irg(birg);
morgan_env_t env;
FIRM_DBG_REGISTER(dbg, "ir.be.spillmorgan");
//firm_dbg_set_mask(dbg, DBG_SPILLS | DBG_LOOPANA);
- env.cenv = chordal_env;
- env.arch = chordal_env->birg->main_env->arch_env;
- env.irg = chordal_env->irg;
- env.cls = chordal_env->cls;
- env.senv = be_new_spill_env(chordal_env);
+ be_assure_liveness(birg);
+
+ env.arch = birg->main_env->arch_env;
+ env.irg = irg;
+ env.cls = cls;
+ env.lv = be_get_birg_liveness(birg);
+ env.senv = be_new_spill_env(birg);
DEBUG_ONLY(be_set_spill_env_dbg_module(env.senv, dbg);)
obstack_init(&env.obst);
- env.registers_available = env.cls->n_regs - be_put_ignore_regs(chordal_env->birg, env.cls, NULL);
+ env.registers_available = env.cls->n_regs - be_put_ignore_regs(birg, env.cls, NULL);
env.loop_attr_set = new_set(loop_attr_cmp, 5);
env.block_attr_set = new_set(block_attr_cmp, 20);
/*-- Part1: Analysis --*/
- //Matze: I hope liveness information is up to date at this point...
- //be_liveness_recompute(chordal_env->lv);
/* construct control flow loop tree */
if(! (get_irg_loopinfo_state(irg) & loopinfo_cf_consistent)) {
be_insert_spills_reloads(env.senv);
/* Verify the result */
- if (chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN) {
+ if(birg->main_env->options->vrfy_option == BE_VRFY_WARN) {
be_verify_schedule(irg);
- } else if (chordal_env->opts->vrfy_option == BE_CH_VRFY_ASSERT) {
+ } else if (birg->main_env->options->vrfy_option == BE_VRFY_ASSERT) {
assert(be_verify_schedule(irg));
}
- if (chordal_env->opts->dump_flags & BE_CH_DUMP_SPILL)
- be_dump(irg, "-spillmorgan", dump_ir_block_graph_sched);
-
/* cleanup */
free_loop_edges(&env);
del_set(env.loop_attr_set);
del_set(env.block_attr_set);
/* fix the remaining places with too high register pressure with beladies algorithm */
- be_spill_belady_spill_env(chordal_env, env.senv);
+ be_spill_belady_spill_env(birg, cls, env.senv);
be_delete_spill_env(env.senv);
obstack_free(&env.obst, NULL);
}
+
+static void be_spill_morgan_oldinterface(const be_chordal_env_t *cenv)
+{
+ be_spill_morgan(cenv->birg, cenv->cls);
+}
+
+void be_init_spillmorgan(void)
+{
+ static be_spiller_t morgan_spiller = {
+ be_spill_morgan_oldinterface
+ };
+
+ be_register_spiller("morgan", &morgan_spiller);
+}
+
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillmorgan);