- 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 separately */
- ir_node **copies; /**< set of copies placed because of phi spills */
- DEBUG_ONLY(firm_dbg_module_t *dbg;)
-};
-
-/* associated Phi -> Spill*/
-typedef struct _phi_spill_assoc_t {
- ir_node *phi;
- ir_node *spill;
-} phi_spill_assoc_t;
-
-/**
- * Compare two Phi->Spill associations.
- */
-static int cmp_phi_spill_assoc(const void *a, const void *b, size_t n) {
- const phi_spill_assoc_t *p1 = a;
- const phi_spill_assoc_t *p2 = b;
- return p1->phi != p2->phi;
-}
-
-/**
- * compare two spill contexts.
- */
-static int cmp_spillctx(const void *a, const void *b, size_t n) {
- const spill_ctx_t *p = a;
- const spill_ctx_t *q = b;
- return p->user != q->user || p->spilled != q->spilled;
-}
-
-/**
- * Compare two spill infos.
- */
-static int cmp_spillinfo(const void *x, const void *y, size_t size) {
- const spill_info_t *xx = x;
- const spill_info_t *yy = y;
- return xx->spilled_node != yy->spilled_node;
-}
-
-DEBUG_ONLY(
-/* Sets the debug module of a spill environment. */
-void be_set_spill_env_dbg_module(spill_env_t *env, firm_dbg_module_t *dbg) {
- env->dbg = dbg;
-}
-)
-
-/* Creates a new spill environment. */
-spill_env_t *be_new_spill_env(const be_chordal_env_t *chordal_env) {
- 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->chordal_env = chordal_env;
- env->mem_phis = pset_new_ptr_default();
- env->copies = NEW_ARR_F(ir_node*, 0);
- obstack_init(&env->obst);
- return env;
-}
-
-/* Deletes a spill environment. */
-void be_delete_spill_env(spill_env_t *env) {
- del_set(env->spill_ctxs);
- del_set(env->spills);
- del_pset(env->mem_phis);
- DEL_ARR_F(env->copies);
- obstack_free(&env->obst, NULL);
- free(env);
-}
-
-/**
- * Returns a spill context. If the context did not exists, create one.
- *
- * @param sc the set containing all spill contexts
- * @param to_spill the node that should be spilled
- * @param ctx_irn an user of the spilled node
- *
- * @return a spill context.
- */
-static spill_ctx_t *be_get_spill_ctx(set *sc, ir_node *to_spill, ir_node *ctx_irn) {
- spill_ctx_t templ;
-
- templ.spilled = to_spill;
- templ.user = ctx_irn;
- templ.spill = NULL;
-
- return set_insert(sc, &templ, sizeof(templ), HASH_COMBINE(HASH_PTR(to_spill), HASH_PTR(ctx_irn)));
-}
-
-/**
- * Schedules a node after an instruction. (That is the place after all projs and phis
- * that are scheduled after the instruction)
- */
-static void sched_add_after_insn(ir_node *sched_after, ir_node *node) {
- ir_node *next = sched_next(sched_after);
- while(!sched_is_end(next)) {
- if(!is_Proj(next) && !is_Phi(next))
- break;
- next = sched_next(next);
- }
-
- if(sched_is_end(next)) {
- next = sched_last(get_nodes_block(sched_after));
- sched_add_after(next, node);
- } else {
- sched_add_before(next, node);
- }
-}
-
-/**
- * Creates a spill.
- *
- * @param senv the spill environment
- * @param irn the node that should be spilled
- * @param ctx_irn an user of the spilled node
- *
- * @return a be_Spill node
- */
-static ir_node *be_spill_irn(spill_env_t *senv, ir_node *irn, ir_node *ctx_irn) {
- spill_ctx_t *ctx;
- const be_main_env_t *env = senv->chordal_env->birg->main_env;
- DBG((senv->dbg, LEVEL_1, "%+F in ctx %+F\n", irn, ctx_irn));
-
- // Has the value already been spilled?
- ctx = be_get_spill_ctx(senv->spill_ctxs, irn, ctx_irn);
- if(ctx->spill)
- return ctx->spill;
-
- /* Trying to spill an already spilled value, no need for a new spill
- * node then, we can simply connect to the same one for this reload