tree-cfg.c (reinstall_phi_args): New.
authorKazu Hirata <kazu@cs.umass.edu>
Fri, 19 Nov 2004 22:14:35 +0000 (22:14 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Fri, 19 Nov 2004 22:14:35 +0000 (22:14 +0000)
* tree-cfg.c (reinstall_phi_args): New.
(tree_split_edge): Use it after redirecting an edge.  Don't
modify PHI_ARG_EDGE.

From-SVN: r90940

gcc/ChangeLog
gcc/tree-cfg.c

index 631c61b7887433fa7f1faaf58a8b560547c6a9d4..d6f9f790cc54fd76c8d6fed1105fbd3a569afe36 100644 (file)
@@ -1,3 +1,9 @@
+2004-11-19  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * tree-cfg.c (reinstall_phi_args): New.
+       (tree_split_edge): Use it after redirecting an edge.  Don't
+       modify PHI_ARG_EDGE.
+
 2004-11-19  Andreas Tobler  <a.tobler@schweiz.ch>
 
        * tree-vectorizer.c (slpeel_verify_cfg_after_peeling): Define only
index d77199549b538c5d795fa6e60d736067de99cd5c..337463c0e39213d4bb2a7c6e040f4b9a531e45d2 100644 (file)
@@ -3113,6 +3113,31 @@ bsi_insert_on_edge_immediate (edge e, tree stmt)
             Tree specific functions for CFG manipulation
 ---------------------------------------------------------------------------*/
 
+/* Reinstall those PHI arguments queued in OLD_EDGE to NEW_EDGE.  */
+
+static void
+reinstall_phi_args (edge new_edge, edge old_edge)
+{
+  tree var, phi;
+
+  if (!PENDING_STMT (old_edge))
+    return;
+  
+  for (var = PENDING_STMT (old_edge), phi = phi_nodes (new_edge->dest);
+       var && phi;
+       var = TREE_CHAIN (var), phi = PHI_CHAIN (phi))
+    {
+      tree result = TREE_PURPOSE (var);
+      tree arg = TREE_VALUE (var);
+
+      gcc_assert (result == PHI_RESULT (phi));
+
+      add_phi_arg (&phi, arg, new_edge);
+    }
+
+  PENDING_STMT (old_edge) = NULL;
+}
+
 /* Split a (typically critical) edge EDGE_IN.  Return the new block.
    Abort on abnormal edges.  */
 
@@ -3121,8 +3146,6 @@ tree_split_edge (edge edge_in)
 {
   basic_block new_bb, after_bb, dest, src;
   edge new_edge, e;
-  tree phi;
-  int i, num_elem;
   edge_iterator ei;
 
   /* Abnormal edges cannot be split.  */
@@ -3149,23 +3172,9 @@ tree_split_edge (edge edge_in)
   new_edge->probability = REG_BR_PROB_BASE;
   new_edge->count = edge_in->count;
 
-  /* Find all the PHI arguments on the original edge, and change them to
-     the new edge.  Do it before redirection, so that the argument does not
-     get removed.  */
-  for (phi = phi_nodes (dest); phi; phi = PHI_CHAIN (phi))
-    {
-      num_elem = PHI_NUM_ARGS (phi);
-      for (i = 0; i < num_elem; i++)
-       if (PHI_ARG_EDGE (phi, i) == edge_in)
-         {
-           PHI_ARG_EDGE (phi, i) = new_edge;
-           break;
-         }
-    }
-
   e = redirect_edge_and_branch (edge_in, new_bb);
   gcc_assert (e);
-  gcc_assert (!PENDING_STMT (edge_in));
+  reinstall_phi_args (new_edge, e);
 
   return new_bb;
 }