+/**
+ * Reroute memory users of old memory that are dominated by a given block
+ * to a new memory IR-node.
+ *
+ * @param omem the old memory IR-node
+ * @param nmem the new memory IR-node
+ * @param pass_bl the block the memory must pass
+ */
+static void reroute_mem_through(ir_node *omem, ir_node *nmem, ir_node *pass_bl) {
+ int i, j, n = get_irn_n_outs(omem);
+ ir_def_use_edge *edges = NEW_ARR_D(ir_def_use_edge, &env.obst, n + 1);
+
+ for (i = j = 0; i < n; ++i) {
+ int n_pos;
+ ir_node *user = get_irn_out_ex(omem, i, &n_pos);
+ ir_node *use_bl = get_nodes_block(user);
+
+
+ if (is_Phi(user)) {
+ use_bl = get_Block_cfgpred_block(use_bl, n_pos);
+ }
+ if (block_dominates(pass_bl, use_bl)) {
+ /* found an user that is dominated */
+ ++j;
+ edges[j].pos = n_pos;
+ edges[j].use = user;
+
+ set_irn_n(user, n_pos, nmem);
+ }
+ }
+
+ /* Modify the out structure: we create a new out edge array on our
+ temporary obstack here. This should be no problem, as we invalidate the edges
+ at the end either. */
+ /* first entry is used for the length */
+ edges[0].pos = j;
+ nmem->out = edges;
+}
+
+