+void be_spill_phi(spill_env_t *env, ir_node *node) {
+ spill_info_t* spill;
+ int i, arity;
+
+ assert(is_Phi(node));
+
+ pset_insert_ptr(env->mem_phis, node);
+
+ // create spillinfos for the phi arguments
+ spill = get_spillinfo(env, node);
+ for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
+ ir_node *arg = get_irn_n(node, i);
+ get_spillinfo(env, arg);
+ }
+
+ // if we had a spill for the phi value before, then remove this spill from
+ // schedule, as we will remove it in the insert spill/reload phase
+ if(spill->spill != NULL && !is_Phi(spill->spill)) {
+ spill->old_spill = spill->spill;
+ spill->spill = NULL;
+ }
+}
+
+/*
+ * ____ _ ____ _ _ _
+ * / ___|_ __ ___ __ _| |_ ___ / ___| _ __ (_) | |___
+ * | | | '__/ _ \/ _` | __/ _ \ \___ \| '_ \| | | / __|
+ * | |___| | | __/ (_| | || __/ ___) | |_) | | | \__ \
+ * \____|_| \___|\__,_|\__\___| |____/| .__/|_|_|_|___/
+ * |_|
+ */
+
+/**
+ * Schedules a node after an instruction. (That is the place after all projs and phis
+ * that are scheduled after the instruction)
+ * This function also skips phi nodes at the beginning of a block
+ */
+static void sched_add_after_insn(ir_node *sched_after, ir_node *node) {
+ ir_node *next = sched_next(sched_after);
+ while(is_Proj(next) || is_Phi(next)) {
+ next = sched_next(next);
+ }
+ assert(next != NULL);
+
+ if(sched_is_end(next)) {
+ sched_add_after(sched_last(get_nodes_block(sched_after)), 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 void spill_irn(spill_env_t *env, spill_info_t *spillinfo) {
+ ir_node *to_spill = spillinfo->spilled_node;
+
+ DBG((env->dbg, LEVEL_1, "%+F\n", to_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
+ *
+ * (although rematerialization code should handle most of these cases
+ * this can still happen when spilling Phis)
+ */
+ if(be_is_Reload(to_spill)) {
+ spillinfo->spill = get_irn_n(to_spill, be_pos_Reload_mem);
+ return;
+ }
+
+ if (arch_irn_is(env->arch_env, to_spill, dont_spill)) {
+ if (env->chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN)
+ ir_fprintf(stderr, "Verify warning: spilling 'dont_spill' node %+F\n", to_spill);
+ else if (env->chordal_env->opts->vrfy_option == BE_CH_VRFY_ASSERT)
+ assert(0 && "Attempt to spill a node marked 'dont_spill'");
+ }
+
+ spillinfo->spill = be_spill(env->arch_env, to_spill);
+ sched_add_after_insn(to_spill, spillinfo->spill);
+}
+
+static void spill_node(spill_env_t *env, spill_info_t *spillinfo);
+