- DBG((dbg, LEVEL_1, "spilling %+F ... \n", to_spill));
- spill = spillinfo->spills;
- for( ; spill != NULL; spill = spill->next) {
- ir_node *after = spill->after;
- ir_node *block = get_block(after);
-
- after = skip_keeps_phis(after);
-
- spill->spill = be_spill(env->arch_env, block, to_spill);
- sched_add_after(after, spill->spill);
- DB((dbg, LEVEL_1, "\t%+F after %+F\n", spill->spill, after));
-#ifdef FIRM_STATISTICS
- env->spill_count++;
-#endif
- }
- DBG((dbg, LEVEL_1, "\n"));
-}
-
-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_graph *irg = env->irg;
- ir_node *phi = spillinfo->to_spill;
- ir_node *block = get_nodes_block(phi);
- ir_node *unknown;
- ir_node **ins;
- spill_t *spill;
- int i;
- int arity;
-
- assert(is_Phi(phi));
- assert(!get_opt_cse());
- DBG((dbg, LEVEL_1, "spilling Phi %+F:\n", phi));
-
- /* build a new PhiM */
- arity = get_irn_arity(phi);
- ins = alloca(sizeof(ir_node*) * arity);
- unknown = new_r_Unknown(irg, mode_M);
- for(i = 0; i < arity; ++i) {
- ins[i] = unknown;
- }
-
- /* override or replace spills list... */
- spill = obstack_alloc(&env->obst, sizeof(spill[0]));
- spill->after = skip_keeps_phis(phi);
- spill->spill = new_r_Phi(irg, block, arity, ins, mode_M);
- spill->next = NULL;
-
- spillinfo->spills = spill;
-#ifdef FIRM_STATISTICS
- env->spilled_phi_count++;
-#endif
-
- for(i = 0; i < arity; ++i) {
- ir_node *arg = get_irn_n(phi, i);
- spill_info_t *arg_info = get_spillinfo(env, arg);
-
- determine_spill_costs(env, arg_info);
- spill_node(env, arg_info);
-
- set_irn_n(spill->spill, i, arg_info->spills->spill);
- }
- DBG((dbg, LEVEL_1, "... done spilling Phi %+F, created PhiM %+F\n", phi,
- spill->spill));
-}
-
-/**
- * Spill a node.
- *
- * @param senv the spill environment
- * @param to_spill the node that should be spilled
- */
-static void spill_node(spill_env_t *env, spill_info_t *spillinfo)
-{
- ir_node *to_spill;
-
- /* node is already spilled */
- if(spillinfo->spills != NULL && spillinfo->spills->spill != NULL)
- return;
-
- to_spill = spillinfo->to_spill;
-
- if (is_Phi(to_spill) && ir_nodeset_contains(&env->mem_phis, to_spill)) {
- spill_phi(env, spillinfo);
- } else {
- spill_irn(env, spillinfo);
- }
-}
-
-/*
- *
- * ____ _ _ _ _
- * | _ \ ___ _ __ ___ __ _| |_ ___ _ __(_) __ _| (_)_______
- * | |_) / _ \ '_ ` _ \ / _` | __/ _ \ '__| |/ _` | | |_ / _ \
- * | _ < __/ | | | | | (_| | || __/ | | | (_| | | |/ / __/
- * |_| \_\___|_| |_| |_|\__,_|\__\___|_| |_|\__,_|_|_/___\___|
- *
- */
-
-/**
- * Tests whether value @p arg is available before node @p reloader
- * @returns 1 if value is available, 0 otherwise
- */
-static int is_value_available(spill_env_t *env, const ir_node *arg,
- const ir_node *reloader)
-{
- if(is_Unknown(arg) || arg == new_NoMem())
- return 1;
-
- if(be_is_Spill(arg))
- return 1;
-
- if(arg == get_irg_frame(env->irg))
- return 1;
-
- /* hack for now (happens when command should be inserted at end of block) */
- if(is_Block(reloader)) {
- return 0;
- }
-