- }
-
- 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);
-
-}
-
-ir_node *be_get_end_of_block_insertion_point(const ir_node *block)
-{
- ir_node *last = sched_last(block);
-
- /* we might have keeps behind the jump... */
- while(be_is_Keep(last)) {
- last = sched_prev(last);
- assert(!sched_is_end(last));
- }
-
- assert(is_cfop(last));
-
- /* add the reload before the (cond-)jump */
- return last;
-}
-
-/**
- * Returns the point at which you can insert a node that should be executed
- * before block @p block when coming from pred @p pos.
- */
-static ir_node *get_block_insertion_point(ir_node *block, int pos)
-{
- ir_node *predblock;
-
- /* simply add the reload to the beginning of the block if we only have 1
- * predecessor. We don't need to check for phis as there can't be any in a
- * block with only 1 pred. */
- if(get_Block_n_cfgpreds(block) == 1) {
- assert(!is_Phi(sched_first(block)));
- return sched_first(block);
- }
-
- /* We have to reload the value in pred-block */
- predblock = get_Block_cfgpred_block(block, pos);
- return be_get_end_of_block_insertion_point(predblock);
-}
-
-void be_add_reload_at_end(spill_env_t *env, ir_node *to_spill,
- const ir_node *block,
- const arch_register_class_t *reload_cls,
- int allow_remat)
-{
- ir_node *before = be_get_end_of_block_insertion_point(block);
- be_add_reload(env, to_spill, before, reload_cls, allow_remat);
-}
-
-void be_add_reload_on_edge(spill_env_t *env, ir_node *to_spill, ir_node *block,
- int pos, const arch_register_class_t *reload_cls,
- int allow_remat)
-{
- ir_node *before = get_block_insertion_point(block, pos);
- be_add_reload(env, to_spill, before, reload_cls, allow_remat);
-}
-
-void be_spill_phi(spill_env_t *env, ir_node *node)
-{
- ir_node *block;
- spill_info_t* spill;
- int i, arity;
-
- assert(is_Phi(node));
-
- ir_nodeset_insert(&env->mem_phis, node);
-
- /* create spills for the phi arguments */
- block = get_nodes_block(node);
- spill = get_spillinfo(env, node);
- for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
- ir_node *arg = get_irn_n(node, i);
- ir_node *pred_block = get_Block_cfgpred_block(block, i);
- ir_node *insert = be_get_end_of_block_insertion_point(pred_block);
- //get_spillinfo(env, arg);
- be_add_spill(env, arg, insert);
- }
-}
-
-/*
- * ____ _ ____ _ _ _
- * / ___|_ __ ___ __ _| |_ ___ / ___| _ __ (_) | |___
- * | | | '__/ _ \/ _` | __/ _ \ \___ \| '_ \| | | / __|
- * | |___| | | __/ (_| | || __/ ___) | |_) | | | \__ \
- * \____|_| \___|\__,_|\__\___| |____/| .__/|_|_|_|___/
- * |_|
- */
-
-static ir_node *skip_keeps_phis(ir_node *node)
-{
- node = sched_next(node);
- while(is_Phi(node) || be_is_Keep(node)) {
- node = sched_next(node);
- }
- return node;
-}
-
-static void determine_spill_costs(spill_env_t *env, spill_info_t *spillinfo);
-
-/**
- * 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->to_spill;
- spill_t *spill;
-
- /* determine_spill_costs must have been run before */
- assert(spillinfo->spill_costs >= 0);
-
- /* some backends have virtual noreg/unknown nodes that are not scheduled
- * and simply always available. */
- if(!sched_is_scheduled(to_spill)) {
- /* override spillinfos or create a new one */
- spillinfo->spills->spill = new_NoMem();
- DB((dbg, LEVEL_1, "don't spill %+F use NoMem\n", to_spill));
- return;
- }
-
- DBG((dbg, LEVEL_1, "spilling %+F ... ", to_spill));
- spill = spillinfo->spills;
- for( ; spill != NULL; spill = spill->next) {
- ir_node *block = get_block(spill->before);
- ir_node *before = spill->before;
-
- /* place all spills before the reloads (as we can't guarantee the
- * same order as the be_add_spill and be_add_reload calls */
- while(get_irn_idx(sched_prev(before)) > env->new_nodes_idx) {
- before = sched_prev(before);