This is an archive of the discontinued LLVM Phabricator instance.

[If Converter] Convert recursion to iteration
ClosedPublic

Authored by ahatanak on Jun 19 2015, 6:53 PM.

Details

Summary

I have a large program that has a CFG structure that looks like this:

BB0:

if (condition0)
  goto BB1
goto BB2

BB1:

goto BB2

BB2:

if (condition1)
  goto BB3
goto BB4

BB3:
...
(repeat until BB7488)

When I compile this program targeting armv7, function IfConverter::AnalyzeBlock gets called recursively a large number of times, which eventually results in hitting the stack limit and segfaulting.

This patch changes the function to use iteration instead of recursion to avoid the segfault.

Diff Detail

Event Timeline

ahatanak updated this revision to Diff 28060.Jun 19 2015, 6:53 PM
ahatanak retitled this revision from to [If Converter] Convert recursion to iteration.
ahatanak updated this object.
ahatanak edited the test plan for this revision. (Show Details)
ahatanak added a subscriber: Unknown Object (MLST).
MatzeB accepted this revision.Jun 24 2015, 1:00 PM
MatzeB added a reviewer: MatzeB.
MatzeB added a subscriber: MatzeB.

LGTM with small nitpicks below:

lib/CodeGen/IfConversion.cpp
772

Use ///

780
  • Adding a BBState &State = BBStack.back(); would avoid three repeated BBStack.back() calls later.
  • "MachineBasicBlock *" instead of "auto" is friendlier for the reader.
This revision is now accepted and ready to land.Jun 24 2015, 1:00 PM
ahatanak updated this revision to Diff 28392.Jun 24 2015, 1:24 PM
ahatanak edited edge metadata.

Thank you Matthias. I'll commit this patch shortly.

This revision was automatically updated to reflect the committed changes.