+void be_delete_spill_env(spill_env_t *env)
+{
+ del_set(env->spills);
+ ir_nodeset_destroy(&env->mem_phis);
+ obstack_free(&env->obst, NULL);
+ free(env);
+}
+
+/*
+ * ____ _ ____ _ _
+ * | _ \| | __ _ ___ ___ | _ \ ___| | ___ __ _ __| |___
+ * | |_) | |/ _` |/ __/ _ \ | |_) / _ \ |/ _ \ / _` |/ _` / __|
+ * | __/| | (_| | (_| __/ | _ < __/ | (_) | (_| | (_| \__ \
+ * |_| |_|\__,_|\___\___| |_| \_\___|_|\___/ \__,_|\__,_|___/
+ *
+ */
+
+void be_add_spill(spill_env_t *env, ir_node *to_spill, ir_node *after)
+{
+ spill_info_t *spill_info = get_spillinfo(env, to_spill);
+ spill_t *spill;
+ spill_t *s;
+ spill_t *last;
+
+ assert(! arch_irn_is(env->arch_env, to_spill, dont_spill));
+ DB((dbg, LEVEL_1, "Add spill of %+F after %+F\n", to_spill, after));
+
+ /* Just for safety make sure that we do not insert the spill in front of a phi */
+ assert(!is_Phi(sched_next(after)));
+
+ /* spills that are dominated by others are not needed */
+ last = NULL;
+ s = spill_info->spills;
+ for( ; s != NULL; s = s->next) {
+ /* no need to add this spill if it is dominated by another */
+ if(value_dominates(s->after, after)) {
+ DB((dbg, LEVEL_1, "...dominated by %+F, not added\n", s->after));
+ return;
+ }
+ /* remove spills that we dominate */
+ if(value_dominates(after, s->after)) {
+ DB((dbg, LEVEL_1, "...remove old spill at %+F\n", s->after));
+ if(last != NULL) {
+ last->next = s->next;
+ } else {
+ spill_info->spills = s->next;
+ }
+ } else {
+ last = s;
+ }
+ }
+
+ spill = obstack_alloc(&env->obst, sizeof(spill[0]));
+ spill->after = after;
+ spill->next = spill_info->spills;
+ spill->spill = NULL;
+
+ spill_info->spills = spill;
+}
+
+void be_add_remat(spill_env_t *env, ir_node *to_spill, ir_node *before,
+ ir_node *rematted_node)
+{
+ spill_info_t *spill_info;
+ reloader_t *reloader;
+
+ spill_info = get_spillinfo(env, to_spill);
+
+ /* add the remat information */
+ reloader = obstack_alloc(&env->obst, sizeof(reloader[0]));
+ reloader->next = spill_info->reloaders;
+ reloader->reloader = before;
+ reloader->rematted_node = rematted_node;
+ reloader->remat_cost_delta = 0; /* We will never have a cost win over a
+ reload since we're not even allowed to
+ create a reload */
+
+ spill_info->reloaders = reloader;
+
+ DBG((dbg, LEVEL_1, "creating spillinfo for %+F, will be rematerialized before %+F\n",
+ to_spill, before));
+}
+
+void be_add_reload2(spill_env_t *env, ir_node *to_spill, ir_node *before,
+ ir_node *can_spill_after, const arch_register_class_t *reload_cls,
+ int allow_remat)
+{
+ spill_info_t *info;
+ reloader_t *rel;
+
+ assert(! arch_irn_is(env->arch_env, to_spill, dont_spill));
+
+ info = get_spillinfo(env, to_spill);
+
+ if (is_Phi(to_spill)) {
+ int i, arity;
+
+ /* create spillinfos for the phi arguments */
+ for (i = 0, arity = get_irn_arity(to_spill); i < arity; ++i) {
+ ir_node *arg = get_irn_n(to_spill, i);
+ get_spillinfo(env, arg);
+ }
+ }
+
+ assert(!is_Proj(before) && !be_is_Keep(before));
+
+ /* put reload into list */
+ rel = obstack_alloc(&env->obst, sizeof(rel[0]));
+ rel->next = info->reloaders;
+ rel->reloader = before;
+ rel->rematted_node = NULL;
+ rel->can_spill_after = can_spill_after;
+ rel->remat_cost_delta = allow_remat ? 0 : REMAT_COST_INFINITE;
+
+ info->reloaders = rel;
+ assert(info->reload_cls == NULL || info->reload_cls == reload_cls);
+ info->reload_cls = reload_cls;
+
+ DBG((dbg, LEVEL_1, "creating spillinfo for %+F, will be reloaded before %+F, may%s be rematerialized\n",
+ to_spill, before, allow_remat ? "" : " not"));
+}
+
+void be_add_reload(spill_env_t *senv, ir_node *to_spill, ir_node *before,
+ const arch_register_class_t *reload_cls, int allow_remat)
+{
+ be_add_reload2(senv, to_spill, before, to_spill, reload_cls, allow_remat);
+