-
- foreach_pset(env->mem_phis, node) {
- place_copies_for_phi(env, node);
- }
-}
-
-void be_spill_phi(spill_env_t *env, ir_node *node) {
- assert(is_Phi(node));
-
- pset_insert_ptr(env->mem_phis, node);
-}
-
-void be_insert_spills_reloads(spill_env_t *env) {
- const arch_env_t *arch_env = env->chordal_env->birg->main_env->arch_env;
- //ir_node *node;
- spill_info_t *si;
-
-#if 0
- // Matze: This should be pointless as beladies fix_block_borders
- // should result in the same
- DBG((env->dbg, LEVEL_1, "Reloads for mem-phis:\n"));
- foreach_pset(env->mem_phis, node) {
- const ir_edge_t *e;
-
- assert(is_Phi(node));
-
- /* Add reloads for mem_phis */
- /* BETTER: These reloads (1) should only be inserted, if they are really needed */
- DBG((env->dbg, LEVEL_1, " Mem-phi %+F\n", node));
- foreach_out_edge(node, e) {
- ir_node *user = e->src;
- if (is_Phi(user) && !pset_find_ptr(env->mem_phis, user)) {
- ir_node *use_bl = get_nodes_block(user);
- DBG((env->dbg, LEVEL_1, " non-mem-phi user %+F\n", user));
- be_add_reload_on_edge(env, node, use_bl, e->pos); /* (1) */
- }
- }
- }
-#endif
-
- /* process each spilled node */
- DBG((env->dbg, LEVEL_1, "Insert spills and reloads:\n"));
- for(si = set_first(env->spills); si; si = set_next(env->spills)) {
- reloader_t *rld;
- ir_mode *mode = get_irn_mode(si->spilled_node);
- pset *values = pset_new_ptr(16);
-
- /* go through all reloads for this spill */
- for(rld = si->reloaders; rld; rld = rld->next) {
- ir_node *new_val;
-
- if (check_remat_conditions(env, si->spilled_node, rld->reloader)) {
- new_val = do_remat(env, si->spilled_node, rld->reloader);
- } else {
- /* the spill for this reloader */
- ir_node *spill = be_spill_node(env, si->spilled_node);
-
- /* do a reload */
- new_val = be_reload(arch_env, env->cls, rld->reloader, mode, spill);
- }
-
- DBG((env->dbg, LEVEL_1, " %+F of %+F before %+F\n", new_val, si->spilled_node, rld->reloader));
- pset_insert_ptr(values, new_val);
- }
-
- /* 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));