+ spill_info_t *si;
+ struct obstack ob;
+
+ obstack_init(&ob);
+
+ /* get all special spilled phis */
+ DBG((senv->dbg, LEVEL_1, "Mem-phis:\n"));
+ senv->mem_phis = pset_new_ptr_default();
+ irg_walk_graph(senv->chordal_env->irg, phi_walker, NULL, senv);
+
+ /* Add reloads for mem_phis */
+ /* BETTER: These reloads (1) should only be inserted, if they are really needed */
+ DBG((senv->dbg, LEVEL_1, "Reloads for mem-phis:\n"));
+ for(irn = pset_first(senv->mem_phis); irn; irn = pset_next(senv->mem_phis)) {
+ const ir_edge_t *e;
+ DBG((senv->dbg, LEVEL_1, " Mem-phi %+F\n", irn));
+ foreach_out_edge(irn, e) {
+ ir_node *user = e->src;
+ if (is_Phi(user) && !pset_find_ptr(senv->mem_phis, user)) {
+ ir_node *use_bl = get_nodes_block(user);
+ DBG((senv->dbg, LEVEL_1, " non-mem-phi user %+F\n", user));
+ be_add_reload_on_edge(senv, irn, use_bl, e->pos); /* (1) */
+ }
+ }
+ }
+
+ /* process each spilled node */
+ DBG((senv->dbg, LEVEL_1, "Insert spills and reloads:\n"));
+ for(si = set_first(senv->spills); si; si = set_next(senv->spills)) {
+ reloader_t *rld;
+ ir_node **reloads;
+ int n_reloads = 0;
+ ir_mode *mode = get_irn_mode(si->spilled_node);
+
+ /* go through all reloads for this spill */
+ for(rld = si->reloaders; rld; rld = rld->next) {
+ /* the spill for this reloader */
+ ir_node *spill = be_spill_node(senv, si->spilled_node);
+
+ /* the reload */
+ ir_node *bl = is_Block(rld->reloader) ? rld->reloader : get_nodes_block(rld->reloader);
+ ir_node *reload = new_Reload(senv->chordal_env->main_env->node_factory,
+ senv->cls, irg, bl, mode, spill);
+
+ DBG((senv->dbg, LEVEL_1, " %+F of %+F before %+F\n", reload, si->spilled_node, rld->reloader));
+ if(reload_set)
+ pset_insert_ptr(reload_set, reload);
+
+ /* remember the reaload */
+ obstack_ptr_grow(&ob, reload);
+ sched_add_before(rld->reloader, reload);
+ n_reloads++;
+ }
+
+ assert(n_reloads > 0);
+ reloads = obstack_finish(&ob);
+ be_introduce_copies_ignore(senv->chordal_env->dom_front, si->spilled_node,
+ n_reloads, reloads, senv->mem_phis);
+ obstack_free(&ob, reloads);
+ }
+
+ obstack_free(&ob, NULL);
+