1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[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
This commit is contained in:
Max Kazantsev 2019-02-17 18:21:51 +00:00
parent 33359a68d7
commit 5987038dc3

View File

@ -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 {