-/**
- * Find the copy of the given original node whose value is 'active'
- * at a usage.
- *
- * The usage is given as a node and a position. Initially, the given operand
- * points to a node for which copies were introduced. We have to find
- * the valid copy for this usage. This is done by travering the
- * dominance tree upwards. If the usage is a phi function, we start
- * traversing from the predecessor block which corresponds to the phi
- * usage.
- *
- * @param usage The node which uses the original node.
- * @param pos The number of the argument which corresponds to the
- * original node.
- * @param copy_blocks A set containing all basic block in which copies
- * of the original node are located.
- * @param copies A set containing all node which are copies from the
- * original node.
- * @return The valid copy for usage.
- */
-static ir_node *search_def(ir_node *usage, int pos, pset *copies, pset *copy_blocks)
-{
- ir_node *curr_bl;
-
- curr_bl = get_nodes_block(usage);
-
- /*
- * If the usage is in a phi node, search the copy in the
- * predecessor denoted by pos.
- */
- if(is_Phi(usage))
- curr_bl = get_nodes_block(get_irn_n(curr_bl, pos));
-
- /*
- * Traverse the dominance tree upwards from the
- * predecessor block of the usage.
- */
- while(curr_bl != NULL) {
-
- /*
- * If this block contains a copy, search the block
- * instruction by instruction.
- */
- if(pset_find_ptr(copy_blocks, curr_bl)) {
- ir_node *irn;
-
- /* Look at each instruction from last to first. */
- sched_foreach_reverse(curr_bl, irn) {
-
- /* Take the first copy we find. */
- if(pset_find_ptr(copies, irn))
- return irn;
- }
-
- assert(0 && "We must have encountered a copy");
- }
-
- /* If were not done yet, look in the immediate dominator */
- curr_bl = get_Block_idom(curr_bl);
- }
-
- return NULL;
-}
-
-static void fix_usages(ir_node *orig, pset *copies, pset *copy_blocks)
-{
- int i;
- int n_outs = 0;
- const ir_edge_t *edge;
- const ir_edge_t **outs;
-
- /* Count the number of outs. */
- foreach_out_edge(orig, edge)
- n_outs++;
-
- /*
- * Put all outs into an array.
- * This is neccessary, since the outs would be modified while
- * interating on them what could bring the outs module in trouble.
- */
- outs = malloc(n_outs * sizeof(outs[0]));
- foreach_out_edge(orig, edge)
- outs[i++] = edge;
-
- /*
- * Search the valid def for each out and set it.
- */
- for(i = 0; i < n_outs; ++i) {
- ir_node *def;
- ir_node *irn = get_edge_src_irn(outs[i]);
- int pos = get_edge_src_pos(outs[i]);
-
- def = search_def(irn, pos, copies, copy_blocks);
- set_irn_n(irn, pos, def);
- }
-
- free(outs);