+static void place_copies_for_phi(spill_env_t *env, ir_node* node) {
+ int i, arity;
+
+ assert(is_Phi(node));
+
+ /* We have to place copy nodes in the predecessor blocks to temporarily
+ * produce new values that get separate spill slots
+ */
+ for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
+ ir_node *pred_block, *arg, *copy, *insert_point;
+
+ /* Don't do anything for looping edges (there's no need
+ * and placing copies here breaks stuff as it suddenly
+ * generates new living values through the whole loop)
+ */
+ arg = get_irn_n(node, i);
+ if(arg == node)
+ continue;
+
+ pred_block = get_Block_cfgpred_block(get_nodes_block(node), i);
+ copy = be_new_Copy(env->cls, get_irn_irg(arg), pred_block, arg);
+
+ ARR_APP1(ir_node*, env->copies, copy);
+ insert_point = find_last_use_def(env, pred_block, arg);
+ sched_add_before(insert_point, copy);
+
+ set_irn_n(node, i, copy);
+ }
+}
+
+void be_place_copies(spill_env_t *env) {
+ ir_node *node;
+
+ foreach_pset(env->mem_phis, node) {
+ place_copies_for_phi(env, node);
+ }
+}
+