-/**
- * Insert a copy for the argument of @p start_phi found at position @p pos.
- * Also searches a phi-loop of arbitrary length to detect and resolve
- * the class of phi-swap-problems. To search for a loop recursion is used.
- *
- * 1) Simplest case (phi with a non-phi arg):
- * A single copy is inserted.
- *
- * 2) Phi chain (phi (with phi-arg)* with non=phi arg):
- * Several copies are placed, each after returning from recursion.
- *
- * 3) Phi-loop:
- * On detection a loop breaker is inserted, which is a copy of the start_phi.
- * This copy then pretends beeing the argumnent of the last phi.
- * Now case 2) can be used.
- *
- * The values of @p start_phi and @p pos never change during recursion.
- *
- * @p raenv Environment with all the stuff needed
- * @p start_phi Phi node to process
- * @p pos Argument position to insert copy/copies for
- * @p curr_phi Phi node currently processed during recursion. Equals start_phi on initial call
- *
- * @return NULL If no copy is necessary
- * NULL If the phi has already been processed at this pos
- * Link field is used to keep track of processed positions
- * In all other cases the ir_node *copy which was placed is returned.
- */
-static ir_node *insert_copies(be_raext_env_t *raenv, ir_node *start_phi, int pos, ir_node *curr_phi) {
- ir_node *arg = get_irn_n(curr_phi, pos);
- ir_node *arg_blk = get_nodes_block(arg);
- ir_node *pred_blk = get_Block_cfgpred_block(get_nodes_block(curr_phi), pos);
- ir_node *curr_cpy, *last_cpy;
-
- assert(is_Phi(start_phi) && is_Phi(curr_phi));
-
- if (has_been_done(start_phi, pos))
- return NULL;
-
- /* In case this is a 'normal' phi we insert into
- * the schedule before the pred_blk irn */
- last_cpy = pred_blk;
-
- /* If we detect a loop stop recursion. */
- if (arg == start_phi) {
- ir_node *loop_breaker;
- if (start_phi == curr_phi) {
- /* Phi directly uses itself. No copy necessary */
- return NULL;
- }
-
- /* At least 2 phis are involved */
- /* Insert a loop breaking copy (an additional variable T) */
- loop_breaker = be_new_Copy(raenv->cls, raenv->irg, pred_blk, start_phi);
- sched_add_before(pred_blk, loop_breaker);
-
- arg = loop_breaker;
- }
-
- /* If arg is a phi in the same block we have to continue search */
- if (is_Phi(arg) && arg_blk == get_nodes_block(start_phi))
- last_cpy = insert_copies(raenv, start_phi, pos, arg);
-
- /* Insert copy of argument (may be the loop-breaker) */
- curr_cpy = be_new_Copy(raenv->cls, raenv->irg, pred_blk, arg);
- set_irn_n(curr_phi, pos, curr_cpy);
- mark_as_done(curr_phi, pos);
- sched_add_before(last_cpy, curr_cpy);
- return curr_cpy;
-}
-
-
-/**
- * Perform simple SSA-destruction with copies.
- * The order of processing _must_ be
- * for all positions {
- * for all phis {
- * doit
- * }
- * }
- * else the magic to keep track of processed phi-positions will fail in
- * function 'insert_copies'
- */
-static void ssa_destr_simple_walker(ir_node *blk, void *env) {
- be_raext_env_t *raenv = env;
- int pos, max;
- ir_node *phi;
-
- /* for all argument positions of the phis */
- for (pos=0, max=get_irn_arity(blk); pos<max; ++pos) {
-
- /* for all phi nodes (which are scheduled first) */
- sched_foreach(blk, phi) {
- if (!is_Phi(phi))
- break;
-
- raenv->cls = arch_get_irn_reg_class(raenv->aenv, phi, -1);
- insert_copies(raenv, phi, pos, phi);