https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124651

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Heiko Eißfeldt from comment #11)
> Created attachment 64119 [details]
> patch to replace recursion with a worklist in find_function_exit()
> 
> tested OK against Winfinite-recursion*.c tests from testsuite.

My suggestion is to use 3 as the builtin size for the auto_vec. Or figure out
how much on average the max worklist size is. I suspect 3 (but that is just a
guess).

My other suggestion is to don't add to the worklist if we already visted the
block.

So the code would be something like:
```
auto_vec<basic_block, 3> worklist;
worklist.safe_push (bb_start);
bitmap_set_bit (m_visited, bb_start->index);

while (!worklist.is_empty ())
  {
....
    FOR_EACH_EDGE (e, ei, bb->succs)
      if (bitmap_set_bit (m_visited, e->dest->index))
        worklist.safe_push (e->dest);
  }
```

This is so the worklist is never more than the number of basic blocks.

Reply via email to