- /* introduce copies, rewire the uses */
- assert(pset_count(values) > 0 && "???");
- pset_insert_ptr(values, si->spilled_node);
- be_ssa_constr_set_ignore(env->chordal_env->dom_front, values, env->mem_phis);
-
- del_pset(values);
- }
-
- remove_copies(env);
-
- // reloads are placed now, but we might reuse the spill environment for further spilling decisions
- del_set(env->spills);
- env->spills = new_set(cmp_spillinfo, 1024);
-}
-
-void be_add_reload(spill_env_t *env, ir_node *to_spill, ir_node *before) {
- spill_info_t templ, *res;
- reloader_t *rel;
-
- assert(sched_is_scheduled(before));
- assert(arch_irn_consider_in_reg_alloc(env->chordal_env->birg->main_env->arch_env, env->cls, to_spill));
-
- templ.spilled_node = to_spill;
- templ.reloaders = NULL;
- res = set_insert(env->spills, &templ, sizeof(templ), HASH_PTR(to_spill));
-
- rel = obstack_alloc(&env->obst, sizeof(rel[0]));
- rel->reloader = before;
- rel->next = res->reloaders;
- res->reloaders = rel;
-}
-
-void be_add_reload_on_edge(spill_env_t *env, ir_node *to_spill, ir_node *block, int pos) {
- ir_node *predblock, *last;
-
- /* 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)));
- be_add_reload(env, to_spill, sched_first(block));
- return;
- }
-
- /* We have to reload the value in pred-block */
- predblock = get_Block_cfgpred_block(block, pos);
- last = sched_last(predblock);
-
- /* we might have projs and keepanys behind the jump... */
- while(is_Proj(last) || be_is_Keep(last)) {
- last = sched_prev(last);
- assert(!sched_is_end(last));
- }
- assert(is_cfop(last));
-
- // add the reload before the (cond-)jump
- be_add_reload(env, to_spill, last);
-}
-
-/****************************************
-
- SPILL SLOT MANAGEMENT AND OPTS
-
-****************************************/
-
-typedef struct _spill_slot_t {
- unsigned size;
- unsigned align;
- pset *members;
- ir_mode *largest_mode; /* the mode of all members with largest size */
-} spill_slot_t;
-
-typedef struct _ss_env_t {
- struct obstack ob;
- be_chordal_env_t *cenv;
- pmap *slots; /* maps spill_contexts to spill_slots */
- pmap *types; /* maps modes to types */
- DEBUG_ONLY(firm_dbg_module_t *dbg;)
-} ss_env_t;
-
-
-/**
- * Walker: compute the spill slots
- */
-static void compute_spill_slots_walker(ir_node *spill, void *env) {
- ss_env_t *ssenv = env;
- arch_env_t *arch_env = ssenv->cenv->birg->main_env->arch_env;
- ir_node *ctx;
- pmap_entry *entry;
- spill_slot_t *ss;
- const arch_register_class_t *cls;
-
- if (! be_is_Spill(spill))
- return;
-
- cls = arch_get_irn_reg_class(arch_env, spill, be_pos_Spill_val);
-
- if (cls != ssenv->cenv->cls)
- return;
-
- /* check, if this spill is for a context already known */
- ctx = be_get_Spill_context(spill);
- entry = pmap_find(ssenv->slots, ctx);
-
- if (! entry) {
- ir_mode *largest_mode = arch_register_class_mode(cls);
-
- /* this is a new spill context */
- ss = obstack_alloc(&ssenv->ob, sizeof(*ss));
- ss->members = pset_new_ptr(8);
- ss->largest_mode = largest_mode;
- ss->size = get_mode_size_bytes(ss->largest_mode);
- ss->align = arch_isa_get_reg_class_alignment(arch_env->isa, cls);
- pmap_insert(ssenv->slots, ctx, ss);
- } else {
- /* values with the same spill_ctx must go into the same spill slot */
- ss = entry->value;
-
-#ifndef NDEBUG
- /* ugly mega assert :-) */
- {
- ir_node *irn;
- struct _arch_env_t *arch_env = ssenv->cenv->birg->main_env->arch_env;
- const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, spill, be_pos_Spill_val);
- int size = get_mode_size_bytes(arch_register_class_mode(cls));
- assert((int) ss->size == size && "Different sizes for the same spill slot are not allowed.");
- for (irn = pset_first(ss->members); irn; irn = pset_next(ss->members)) {
- /* use values_interfere here, because it uses the dominance check,
- which does work for values in memory */
- assert(!values_interfere(spill, irn) && "Spills for the same spill slot must not interfere!");
- }