forked from OSchip/llvm-project
Add a utility function to LoopInfo to return the exit block
when the loop has exactly one exit, and make use of it in LoopIndexSplit. llvm-svn: 64388
This commit is contained in:
parent
6a60fa2428
commit
656b097b8a
|
@ -184,6 +184,16 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// getExitingBlock - If getExitingBlocks would return exactly one block,
|
||||||
|
/// return that block. Otherwise return null.
|
||||||
|
BlockT *getExitingBlock() const {
|
||||||
|
SmallVector<BlockT*, 8> ExitingBlocks;
|
||||||
|
getExitingBlocks(ExitingBlocks);
|
||||||
|
if (ExitingBlocks.size() == 1)
|
||||||
|
return ExitingBlocks[0];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// getExitBlocks - Return all of the successor blocks of this loop. These
|
/// getExitBlocks - Return all of the successor blocks of this loop. These
|
||||||
/// are the blocks _outside of the current loop_ which are branched to.
|
/// are the blocks _outside of the current loop_ which are branched to.
|
||||||
///
|
///
|
||||||
|
|
|
@ -236,15 +236,14 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject loop if loop exit condition is not suitable.
|
// Reject loop if loop exit condition is not suitable.
|
||||||
SmallVector<BasicBlock *, 2> EBs;
|
BasicBlock *ExitingBlock = L->getExitingBlock();
|
||||||
L->getExitingBlocks(EBs);
|
if (!ExitingBlock)
|
||||||
if (EBs.size() != 1)
|
|
||||||
return false;
|
return false;
|
||||||
BranchInst *EBR = dyn_cast<BranchInst>(EBs[0]->getTerminator());
|
BranchInst *EBR = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
|
||||||
if (!EBR) return false;
|
if (!EBR) return false;
|
||||||
ExitCondition = dyn_cast<ICmpInst>(EBR->getCondition());
|
ExitCondition = dyn_cast<ICmpInst>(EBR->getCondition());
|
||||||
if (!ExitCondition) return false;
|
if (!ExitCondition) return false;
|
||||||
if (EBs[0] != L->getLoopLatch()) return false;
|
if (ExitingBlock != L->getLoopLatch()) return false;
|
||||||
IVExitValue = ExitCondition->getOperand(1);
|
IVExitValue = ExitCondition->getOperand(1);
|
||||||
if (!L->isLoopInvariant(IVExitValue))
|
if (!L->isLoopInvariant(IVExitValue))
|
||||||
IVExitValue = ExitCondition->getOperand(0);
|
IVExitValue = ExitCondition->getOperand(0);
|
||||||
|
|
Loading…
Reference in New Issue