diff options
author | Dan Gohman <gohman@apple.com> | 2009-02-12 18:08:24 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-02-12 18:08:24 +0000 |
commit | c83324682f3409c15dad992cd62928426c9ad83d (patch) | |
tree | 0c31573c0c1c9425a476c7eedef8401d7fa2a15f | |
parent | 8c4d1b2bcfa63d064a7bcbd9cd23ebe3b282f853 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64388 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/LoopInfo.h | 10 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopIndexSplit.cpp | 9 |
2 files changed, 14 insertions, 5 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 0fa4abe056..b2268a2d74 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -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 /// are the blocks _outside of the current loop_ which are branched to. /// diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index f625c13d45..2bcb10849e 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -236,15 +236,14 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { } // Reject loop if loop exit condition is not suitable. - SmallVector<BasicBlock *, 2> EBs; - L->getExitingBlocks(EBs); - if (EBs.size() != 1) + BasicBlock *ExitingBlock = L->getExitingBlock(); + if (!ExitingBlock) return false; - BranchInst *EBR = dyn_cast<BranchInst>(EBs[0]->getTerminator()); + BranchInst *EBR = dyn_cast<BranchInst>(ExitingBlock->getTerminator()); if (!EBR) return false; ExitCondition = dyn_cast<ICmpInst>(EBR->getCondition()); if (!ExitCondition) return false; - if (EBs[0] != L->getLoopLatch()) return false; + if (ExitingBlock != L->getLoopLatch()) return false; IVExitValue = ExitCondition->getOperand(1); if (!L->isLoopInvariant(IVExitValue)) IVExitValue = ExitCondition->getOperand(0); |