Separate new_edges compute in copy_bbs
authorRichard Biener <rguenther@suse.de>
Wed, 21 Oct 2020 07:45:50 +0000 (09:45 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 21 Oct 2020 08:45:08 +0000 (10:45 +0200)
This separates out a loop finding new_edges from edges in copy_bbs,
making its complexity cheaper overall from total number of succs in
copied bbs times num_edges to num_edges times the complexity of
find_edge.

2020-10-21  Richard Biener  <rguenther@suse.de>

* cfghooks.c (copy_bbs): Split out loop computing new_edges.

gcc/cfghooks.c

index 71c6b63ad3bedb6da47be861ded0656470190f80..14c006df6e1dbd41356874adae17b91eabaa5767 100644 (file)
@@ -1391,8 +1391,6 @@ copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
     }
 
   /* Redirect edges.  */
-  for (j = 0; j < num_edges; j++)
-    new_edges[j] = NULL;
   for (i = 0; i < n; i++)
     {
       edge_iterator ei;
@@ -1401,15 +1399,26 @@ copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
 
       FOR_EACH_EDGE (e, ei, new_bb->succs)
        {
-         for (j = 0; j < num_edges; j++)
-           if (edges[j] && edges[j]->src == bb && edges[j]->dest == e->dest)
-             new_edges[j] = e;
-
          if (!(e->dest->flags & BB_DUPLICATED))
            continue;
          redirect_edge_and_branch_force (e, get_bb_copy (e->dest));
        }
     }
+  for (j = 0; j < num_edges; j++)
+    {
+      if (!edges[j])
+       new_edges[j] = NULL;
+      else
+       {
+         basic_block src = edges[j]->src;
+         basic_block dest = edges[j]->dest;
+         if (src->flags & BB_DUPLICATED)
+           src = get_bb_copy (src);
+         if (dest->flags & BB_DUPLICATED)
+           dest = get_bb_copy (dest);
+         new_edges[j] = find_edge (src, dest);
+       }
+    }
 
   /* Clear information about duplicates.  */
   for (i = 0; i < n; i++)