On Mon, Oct 22, 2012 at 11:09 PM, Jakub Jelinek <[email protected]> wrote:
> Wouldn't it be way cheaper to just export dfs_find_deadend from cfganal.c
> and call it in calc_dfs_tree on each unconnected bb?
> I.e. (untested with the exception of the testcase):
FWIW, dfs_find_deadend looks broken to me for this usage case. It
could return a self-loop block with more than one successor. For a
pre-order search like dominance.c needs, you'd have to look as deep as
possible, something like this:
Index: cfganal.c
===================================================================
--- cfganal.c (revision 192696)
+++ cfganal.c (working copy)
@@ -598,18 +598,26 @@ dfs_find_deadend (basic_block bb)
{
sbitmap visited = sbitmap_alloc (last_basic_block);
sbitmap_zero (visited);
+ basic_block next_bb = NULL;
+ edge_iterator ei;
+ edge e;
for (;;)
{
SET_BIT (visited, bb->index);
- if (EDGE_COUNT (bb->succs) == 0
- || TEST_BIT (visited, EDGE_SUCC (bb, 0)->dest->index))
+ /* Look for any not yet visited successors.
+ If all successors have been visited then
+ this is the dead end we're looking for. */
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ if (! TEST_BIT (visited, e->dest->index))
+ break;
+ if (e == NULL)
{
sbitmap_free (visited);
return bb;
}
- bb = EDGE_SUCC (bb, 0)->dest;
+ bb = e->dest;
}
gcc_unreachable ();
(And the (EDGE_COUNT(bb->succs) == 0) is unnecessary for
inverted_post_order_compute because it already puts all such blocks on
the initial work list :-)
Ciao!
Steven