- 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)) {
- 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);
-
-/**
- * If the first usage of a Phi result would be out of memory
- * there is no sense in allocating a register for it.
- * Thus we spill it and all its operands to the same spill slot.
- * Therefore the phi/dataB becomes a phi/Memory
- *
- * @param senv the spill environment
- * @param phi the Phi node that should be spilled
- * @param ctx_irn an user of the spilled node
- */
-static void spill_phi(spill_env_t *env, spill_info_t *spillinfo) {
- ir_node *phi = spillinfo->spilled_node;
- int i;
- int arity = get_irn_arity(phi);
- ir_node *block = get_nodes_block(phi);
- ir_node **ins;
-
- assert(is_Phi(phi));
-
- /* build a new PhiM */
- ins = alloca(sizeof(ir_node*) * arity);
- for(i = 0; i < arity; ++i) {
- ins[i] = get_irg_bad(env->irg);
- }
- spillinfo->spill = new_r_Phi(env->irg, block, arity, ins, mode_M);
-
- for(i = 0; i < arity; ++i) {
- ir_node *arg = get_irn_n(phi, i);
- spill_info_t *arg_info = get_spillinfo(env, arg);
-
- spill_node(env, arg_info);
-
- set_irn_n(spillinfo->spill, i, arg_info->spill);
- }
-
- // rewire reloads from old_spill to phi
- if(spillinfo->old_spill != NULL) {
- const ir_edge_t *edge, *next;
- ir_node *old_spill = spillinfo->old_spill;
-
- foreach_out_edge_safe(old_spill, edge, next) {
- ir_node* reload = get_edge_src_irn(edge);
- assert(be_is_Reload(reload) || is_Phi(reload));
- set_irn_n(reload, get_edge_src_pos(edge), spillinfo->spill);