[llvm-commits] [llvm] r64388 - in /llvm/trunk: include/llvm/Analysis/LoopInfo.h lib/Transforms/Scalar/LoopIndexSplit.cpp
Dan Gohman
gohman at apple.com
Thu Feb 12 10:08:24 PST 2009
Author: djg
Date: Thu Feb 12 12:08:24 2009
New Revision: 64388
URL: http://llvm.org/viewvc/llvm-project?rev=64388&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Analysis/LoopInfo.h
llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=64388&r1=64387&r2=64388&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Thu Feb 12 12:08:24 2009
@@ -184,6 +184,16 @@
}
}
+ /// 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.
///
Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=64388&r1=64387&r2=64388&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Thu Feb 12 12:08:24 2009
@@ -236,15 +236,14 @@
}
// 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);
More information about the llvm-commits
mailing list