diff options
author | Max Kazantsev <max.kazantsev@azul.com> | 2019-02-17 18:21:51 +0000 |
---|---|---|
committer | Max Kazantsev <max.kazantsev@azul.com> | 2019-02-17 18:21:51 +0000 |
commit | 4561475e0913db9dd36890284044190d6ab395de (patch) | |
tree | 90f391b5b4a03765de169d26d78239255f515584 /llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp | |
parent | f62aeda58dbc68912660d02cf67fa518e5d5bb24 (diff) | |
download | bcm5719-llvm-4561475e0913db9dd36890284044190d6ab395de.tar.gz bcm5719-llvm-4561475e0913db9dd36890284044190d6ab395de.zip |
[NFC] Teach getInnermostLoopFor walk up the loop trees
This should be NFC in current use case of this method, but it will
help to use it for solving more compex tasks in follow-up patches.
llvm-svn: 354227
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp index 4f1213d92a3..eb8de34c3af 100644 --- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -94,15 +94,19 @@ static void removeBlockFromLoops(BasicBlock *BB, Loop *FirstLoop, /// contains the header of loop \p L. static Loop *getInnermostLoopFor(SmallPtrSetImpl<BasicBlock *> &BBs, Loop &L, LoopInfo &LI) { - Loop *StillReachable = nullptr; + Loop *Innermost = nullptr; for (BasicBlock *BB : BBs) { Loop *BBL = LI.getLoopFor(BB); - if (BBL && BBL->contains(L.getHeader())) - if (!StillReachable || - BBL->getLoopDepth() > StillReachable->getLoopDepth()) - StillReachable = BBL; + while (BBL && !BBL->contains(L.getHeader())) + BBL = BBL->getParentLoop(); + if (BBL == &L) + BBL = BBL->getParentLoop(); + if (!BBL) + continue; + if (!Innermost || BBL->getLoopDepth() > Innermost->getLoopDepth()) + Innermost = BBL; } - return StillReachable; + return Innermost; } namespace { |