This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] tree-ssa-threadupdate.c: Remove copy_phis_to_block.


Attached is a patch to remove copy_phis_to_block as it is a duplicate
of tree-ssa.c:flush_pending_stmt.

thread_block makes several copies of the basic block that a jump is
threaded through and then calls copy_phis_to_block to install
appropriate PHI arguments to each copy.  Note that

1) these copies are made while keeping the order of PHI nodes
   identical to the original basic block, and that

2) ssa_redirect_edge stuffs PENDING_STMT in the same order as the PHI
   nodes at the original basic block.

so the order of PHI nodes in PENDING_STMT and those at each copy are
the same.  Thus copy_phis_to_block could walk through PENDING_STMT and
the PHI chain at the same time like so:

  for (phi = phi_nodes (e->dest), arg = PENDING_STMT (e);
       phi = TREE_CHAIN (phi), arg = TREE_CHAIN (arg))

rather than searching for a PHI node for every element in the linked
list pointed to by PENDING_STMT.

It turns out that once we implement the idea above, copy_phis_to_block
ends up being identical to tree-ssa.c:flush_pending_stmt, so the patch
simply replaces the call to copy_phis_to_block with

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-11-07  Kazu Hirata  <>

	* tree-ssa-threadupdate.c (copy_phis_to_block): Remove.
	(thread_block): Call flush_pending_stmt instead of

Index: tree-ssa-threadupdate.c
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-threadupdate.c,v
retrieving revision 2.12
diff -u -d -p -r2.12 tree-ssa-threadupdate.c
--- tree-ssa-threadupdate.c	2 Nov 2004 12:51:09 -0000	2.12
+++ tree-ssa-threadupdate.c	6 Nov 2004 20:13:08 -0000
@@ -95,39 +95,6 @@ struct redirection_data
 /* Main data structure to hold information for duplicates of BB.  */
 static varray_type redirection_data;
-/* Add to the destination of edge E those PHI arguments queued on
-   E.  */
-static void
-copy_phis_to_block (edge e)
-  basic_block dest = e->dest;
-  tree var;
-  for (var = PENDING_STMT (e); var; var = TREE_CHAIN (var))
-    {
-      tree result = TREE_PURPOSE (var);
-      tree arg = TREE_VALUE (var);
-      tree new_phi;
-      /* First try to find a PHI node in NEW_BB which has the same
-         PHI_RESULT as the PHI from BB we are currently processing.  */
-      for (new_phi = phi_nodes (dest); new_phi;
-	   new_phi = PHI_CHAIN (new_phi))
-	if (PHI_RESULT (new_phi) == result)
-	  break;
-      /* If we did not find a suitable PHI in NEW_BB, create one.  */
-      if (!new_phi)
-	new_phi = create_phi_node (result, dest);
-      /* Now add that same argument to the new PHI node in block NEW_BB.  */
-      add_phi_arg (&new_phi, arg, e);
-    }
 /* Remove the last statement in block BB if it is a control statement
    Also remove all outgoing edges except the edge which reaches DEST_BB.
    If DEST_BB is NULL, then remove all outgoing edges.  */
@@ -368,7 +335,7 @@ thread_block (basic_block bb)
 			 e->src->index, e->dest->index, rd->dup_block->index);
 	      e2 = redirect_edge_and_branch (e, rd->dup_block);
-	      copy_phis_to_block (e2);
+	      flush_pending_stmts (e2);
 	      if ((dump_file && (dump_flags & TDF_DETAILS))
 		  && e->src != e2->src)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]