[PATCH] D74691: [Attributor] Detect possibly unbounded cycles in functions

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 16:26:35 PST 2020


baziotis added a comment.

In D74691#1908641 <https://reviews.llvm.org/D74691#1908641>, @jdoerfert wrote:

> - If the algorithm to distinguish cycles and loops makes problems, we can just go through all loops in loop info and verify there is no irreducible control (see for example `mayContainIrreducibleControl` in `MustExecute.cpp`)


That's a great idea! @omarahmed note that `LoopInfo` gives you the top-level loops (https://llvm.org/docs/LoopTerminology.html#id3). One way to get top-level loops is getLoopsInPreorder() <https://llvm.org/doxygen/classllvm_1_1LoopInfoBase.html#a8e8fcfd829c6c03cc0dc77873624faef>. Then, you can get all the sub-loops of a loop using getSubLoops() <https://llvm.org/doxygen/classllvm_1_1LoopBase.html#a47bb4b8ffdd881717123e9b244a10b12>. However, note that this will give you the immediate children if I'm not mistaken. That is, say you have a top-level loop A that contains B that contains C. `A->getSubLoops()` will give you `B`. You then have to do `B->getSubLoops()` to get C.
Before you do all that, you check for irreducible control of course.

Other than that, and you may skip that, I think it's interesting to see what happens behind the scenes. `mayContainIrreducibleControl()` calls containsIrreducibleCFG() <https://llvm.org/doxygen/Analysis_2CFG_8h_source.html#l00145>.
This requires `LoopInfo`. Apart from its implementation that is interesting, it's also educational to read about how do you test for irreducible control in a CFG (i.e. cycle that is not a `Loop` in the LLVM terms) //without// `LoopInfo`.
Here's the diff in which it was added: https://reviews.llvm.org/D40874#1013599 . Check online for T1 / T2 transformations in control-flow graphs (I just did 'cause of course I didn't know any of that and it's quite fun).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74691/new/

https://reviews.llvm.org/D74691





More information about the llvm-commits mailing list