On Wed, 2013-04-24 at 14:31 -0600, Jeff Law wrote:
> On 04/24/2013 11:38 AM, Steve Ellcey wrote:

> Just do duplicate_block (B, NULL, NULL)
> 
> Then I'd remove the switch statement and the outgoing edges from B' 
> except the edge B'->C.
> 
> Then I'd fixup the PHIs in C.  That's update_destination_phis.
> 
> 
> Then you need to wire up A->B'.  If B' has PHIs, then you'll have to fix 
> those as well as any PHIs in C.  Note that PHIs in B just lost an 
> argument, but that'll be handled automatically when you redirect the 
> edge from A->B to A->B'.
> 
> I think that's the proper sequencing (and I certainly had to read the 
> code, it's been a long time since I looked at it in this level of detail)

I am still having trouble with this and with figuring out how to
straighten out my PHI nodes.  I have decided to try a slightly different
tack and see if I could create a routine that would do a generic basic
block copy, handling all the needed bookkeeping internally and fixing
all the PHI nodes after the copy.  I am trying to create a slow but
dependable and easy to use function and would consider completely
regenerating all the PHI information if that was the easiest thing to
do.  Here is what I have so far:


/* Copy the basic block that is the destination block of orig_edge, then
   modify/replace the edge in orig_edge->src basic block with a new edge
   that goes to the new block.  Fix up any PHI nodes that may need to be
   updated.  Remove the dominance info since it may have been messed up.  */

edge
duplicate_succ_block (edge orig_edge)
{
  edge new_edge;
  basic_block orig_block, new_block;

  initialize_original_copy_tables ();
  orig_block = orig_edge->dest;
  fprintf(stderr, "Duplicating block %d\n", orig_block->index);
  new_block = duplicate_block (orig_block, NULL, NULL);
  update_destination_phis (orig_block, new_block);
  new_edge = redirect_edge_and_branch (orig_edge, new_block);
  remove_phi_args (orig_edge);
  free_dominance_info (CDI_DOMINATORS);
  free_original_copy_tables ();
  return new_edge;
}

When I use this to copy a block I get a failure from verify_ssa.

The block I am trying to copy (based on my original example) is:

  <bb 8>:
  # s_1 = PHI <s_6(D)(2), s_8(7)>
  # t_3 = PHI <0(2), t_2(7)>
  # c_4 = PHI <c_7(2), c_9(7)>
  if (c_4 != 0)
    goto <bb 3>;
  else
    goto <bb 9>;

There are two edges leading here (from block 2 and block 7) and I want
to change the 2->8 edge to be a 2->8_prime edge where 8_prime is my new
basic block.  That obviously affects the PHI nodes in both block 8 and
the new 8_prime block.  I don't think any other PHI's are affected in
this case, but obviously, I would like my routine to work on any block I
want to copy even if it does affect PHI nodes in successor blocks.

Steve Ellcey
sell...@mips.com


Reply via email to