forked from OSchip/llvm-project
Omit extracting a loop if one of the exits is a landing pad.
The landing pad must accompany the invoke when it's extracted. However, if it does, then the loop isn't properly extracted. I.e., the resulting extraction has a loop in it. The extracted function is then extracted, etc. resulting in an infinite loop. llvm-svn: 140193
This commit is contained in:
parent
7c2b28a16f
commit
0058520770
|
@ -101,18 +101,24 @@ bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
L->getHeader()->getParent()->getEntryBlock().getTerminator();
|
L->getHeader()->getParent()->getEntryBlock().getTerminator();
|
||||||
if (!isa<BranchInst>(EntryTI) ||
|
if (!isa<BranchInst>(EntryTI) ||
|
||||||
!cast<BranchInst>(EntryTI)->isUnconditional() ||
|
!cast<BranchInst>(EntryTI)->isUnconditional() ||
|
||||||
EntryTI->getSuccessor(0) != L->getHeader())
|
EntryTI->getSuccessor(0) != L->getHeader()) {
|
||||||
ShouldExtractLoop = true;
|
ShouldExtractLoop = true;
|
||||||
else {
|
} else {
|
||||||
// Check to see if any exits from the loop are more than just return
|
// Check to see if any exits from the loop are more than just return
|
||||||
// blocks.
|
// blocks. We also must omit landing pads. Landing pads must accompany the
|
||||||
|
// invoke instruction. But this would result in a loop in the extracted
|
||||||
|
// function. An infinite cycle occurs when it tries to extract that loop as
|
||||||
|
// well.
|
||||||
SmallVector<BasicBlock*, 8> ExitBlocks;
|
SmallVector<BasicBlock*, 8> ExitBlocks;
|
||||||
L->getExitBlocks(ExitBlocks);
|
L->getExitBlocks(ExitBlocks);
|
||||||
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
|
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
|
||||||
if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator())) {
|
if (!isa<ReturnInst>(ExitBlocks[i]->getTerminator()))
|
||||||
ShouldExtractLoop = true;
|
ShouldExtractLoop = true;
|
||||||
|
if (ExitBlocks[i]->isLandingPad()) {
|
||||||
|
ShouldExtractLoop = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ShouldExtractLoop) {
|
if (ShouldExtractLoop) {
|
||||||
if (NumLoops == 0) return Changed;
|
if (NumLoops == 0) return Changed;
|
||||||
|
|
Loading…
Reference in New Issue