basic-block.h (edge_def): Add dest_idx.
authorKazu Hirata <kazu@cs.umass.edu>
Sat, 20 Nov 2004 05:02:28 +0000 (05:02 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Sat, 20 Nov 2004 05:02:28 +0000 (05:02 +0000)
* basic-block.h (edge_def): Add dest_idx.
* cfg.c (unchecked_make_edge): Initialize dest_idx.
(remove_edge): Simplify the disconnection of an edge from its
destination.
(redirect_edge_succ): Likewise.
* cfghooks.c (verify_flow_info): Check the consistency of
dest_idx for each edge.

From-SVN: r90958

gcc/ChangeLog
gcc/basic-block.h
gcc/cfg.c
gcc/cfghooks.c

index 760e977ec5767bef8bf851512f21f3342c77a16a..be459bd389848a90d7f15e5221f63b3d07130068 100644 (file)
@@ -1,3 +1,13 @@
+2004-11-19  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * basic-block.h (edge_def): Add dest_idx.
+       * cfg.c (unchecked_make_edge): Initialize dest_idx.
+       (remove_edge): Simplify the disconnection of an edge from its
+       destination.
+       (redirect_edge_succ): Likewise.
+       * cfghooks.c (verify_flow_info): Check the consistency of
+       dest_idx for each edge.
+
 2004-11-19  Aldy Hernandez  <aldyh@redhat.com>
 
         * simplify-rtx.c (simplify_ternary_operation): Use
index a8db432a1e547b19e8dbcdcc447579075cb1a805..69fc0ab8294466d980d5bdda6acc2f02ce8343a7 100644 (file)
@@ -154,6 +154,10 @@ struct edge_def GTY(())
   int probability;             /* biased by REG_BR_PROB_BASE */
   gcov_type count;             /* Expected number of executions calculated
                                   in profile.c  */
+
+  /* The index number corresponding to this edge in the edge vector
+     dest->preds.  */
+  unsigned int dest_idx;
 };
 
 typedef struct edge_def *edge;
index b3da1429b1dbd748118e34dc5a38582473ed1509..67b0598341fad7736b9b76b066800e19b27f905a 100644 (file)
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -276,6 +276,7 @@ unchecked_make_edge (basic_block src, basic_block dst, int flags)
   e->src = src;
   e->dest = dst;
   e->flags = flags;
+  e->dest_idx = EDGE_COUNT (dst->preds) - 1;
 
   return e;
 }
@@ -355,11 +356,13 @@ remove_edge (edge e)
 {
   edge tmp;
   basic_block src, dest;
+  unsigned int dest_idx;
   bool found = false;
   edge_iterator ei;
 
   src = e->src;
   dest = e->dest;
+  dest_idx = e->dest_idx;
 
   for (ei = ei_start (src->succs); (tmp = ei_safe_edge (ei)); )
     {
@@ -375,20 +378,12 @@ remove_edge (edge e)
 
   gcc_assert (found);
 
-  found = false;
-  for (ei = ei_start (dest->preds); (tmp = ei_safe_edge (ei)); )
-    {
-      if (tmp == e)
-       {
-         VEC_unordered_remove (edge, dest->preds, ei.index);
-         found = true;
-         break;
-       }
-      else
-       ei_next (&ei);
-    }
+  VEC_unordered_remove (edge, dest->preds, dest_idx);
 
-  gcc_assert (found);
+  /* If we removed an edge in the middle of the edge vector, we need
+     to update dest_idx of the edge that moved into the "hole".  */
+  if (dest_idx < EDGE_COUNT (dest->preds))
+    EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
 
   free_edge (e);
 }
@@ -398,28 +393,20 @@ remove_edge (edge e)
 void
 redirect_edge_succ (edge e, basic_block new_succ)
 {
-  edge tmp;
-  edge_iterator ei;
-  bool found = false;
+  basic_block dest = e->dest;
+  unsigned int dest_idx = e->dest_idx;
 
-  /* Disconnect the edge from the old successor block.  */
-  for (ei = ei_start (e->dest->preds); (tmp = ei_safe_edge (ei)); )
-    {
-      if (tmp == e)
-       {
-         VEC_unordered_remove (edge, e->dest->preds, ei.index);
-         found = true;
-         break;
-       }
-      else
-       ei_next (&ei);
-    }
+  VEC_unordered_remove (edge, dest->preds, dest_idx);
 
-  gcc_assert (found);
+  /* If we removed an edge in the middle of the edge vector, we need
+     to update dest_idx of the edge that moved into the "hole".  */
+  if (dest_idx < EDGE_COUNT (dest->preds))
+    EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
 
   /* Reconnect the edge to the new successor block.  */
   VEC_safe_push (edge, new_succ->preds, e);
   e->dest = new_succ;
+  e->dest_idx = EDGE_COUNT (new_succ->preds) - 1;
 }
 
 /* Like previous but avoid possible duplicate edge.  */
index 00f4562d81ed0f85f55391ff1ac9aa575c7ee002..42d1183841a6ee0bf327c697eeca8de1fbe4f2c4 100644 (file)
@@ -178,6 +178,20 @@ verify_flow_info (void)
              fputc ('\n', stderr);
              err = 1;
            }
+
+         if (ei.index != e->dest_idx)
+           {
+             error ("basic block %d pred edge is corrupted", bb->index);
+             error ("its dest_idx should be %d, not %d",
+                    ei.index, e->dest_idx);
+             fputs ("Predecessor: ", stderr);
+             dump_edge_info (stderr, e, 0);
+             fputs ("\nSuccessor: ", stderr);
+             dump_edge_info (stderr, e, 1);
+             fputc ('\n', stderr);
+             err = 1;
+           }
+
          edge_checksum[e->dest->index + 2] -= (size_t) e;
        }
     }