summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LoopUnroll.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2006-08-29 06:10:56 +0000
committerOwen Anderson <resistor@mac.com>2006-08-29 06:10:56 +0000
commitd648e140a525301b9fd82b6148e0c37877b0134d (patch)
tree66a10fb5b8f128f659c37c44de9291f7996e3f2e /lib/Transforms/Scalar/LoopUnroll.cpp
parent06abd22b1ad203103c1a07a030ebc5c1c4cfbb14 (diff)
downloadexternal_llvm-d648e140a525301b9fd82b6148e0c37877b0134d.zip
external_llvm-d648e140a525301b9fd82b6148e0c37877b0134d.tar.gz
external_llvm-d648e140a525301b9fd82b6148e0c37877b0134d.tar.bz2
Clean up a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29950 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnroll.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopUnroll.cpp83
1 files changed, 32 insertions, 51 deletions
diff --git a/lib/Transforms/Scalar/LoopUnroll.cpp b/lib/Transforms/Scalar/LoopUnroll.cpp
index 3bff273..f1a826e 100644
--- a/lib/Transforms/Scalar/LoopUnroll.cpp
+++ b/lib/Transforms/Scalar/LoopUnroll.cpp
@@ -128,66 +128,47 @@ BasicBlock* LoopUnroll::FoldBlockIntoPredecessor(BasicBlock* BB) {
// pred, and if there is only one distinct successor of the predecessor, and
// if there are no PHI nodes.
//
- pred_iterator PI(pred_begin(BB)), PE(pred_end(BB));
- BasicBlock *OnlyPred = *PI++;
- for (; PI != PE; ++PI) // Search all predecessors, see if they are all same
- if (*PI != OnlyPred) {
- OnlyPred = 0; // There are multiple different predecessors...
- break;
- }
+ BasicBlock *OnlyPred = BB->getSinglePredecessor();
+ if (!OnlyPred) return 0;
- BasicBlock *OnlySucc = 0;
- if (OnlyPred && OnlyPred != BB && // Don't break self loops
- OnlyPred->getTerminator()->getOpcode() != Instruction::Invoke) {
- // Check to see if there is only one distinct successor...
- succ_iterator SI(succ_begin(OnlyPred)), SE(succ_end(OnlyPred));
- OnlySucc = BB;
- for (; SI != SE; ++SI)
- if (*SI != OnlySucc) {
- OnlySucc = 0; // There are multiple distinct successors!
- break;
- }
- }
+ if (OnlyPred->getTerminator()->getNumSuccessors() != 1)
+ return 0;
- if (OnlySucc) {
- DEBUG(std::cerr << "Merging: " << *BB << "into: " << *OnlyPred);
- TerminatorInst *Term = OnlyPred->getTerminator();
-
- // Resolve any PHI nodes at the start of the block. They are all
- // guaranteed to have exactly one entry if they exist, unless there are
- // multiple duplicate (but guaranteed to be equal) entries for the
- // incoming edges. This occurs when there are multiple edges from
- // OnlyPred to OnlySucc.
- //
- while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
- PN->replaceAllUsesWith(PN->getIncomingValue(0));
- BB->getInstList().pop_front(); // Delete the phi node...
- }
+ DEBUG(std::cerr << "Merging: " << *BB << "into: " << *OnlyPred);
+ TerminatorInst *Term = OnlyPred->getTerminator();
- // Delete the unconditional branch from the predecessor...
- OnlyPred->getInstList().pop_back();
+ // Resolve any PHI nodes at the start of the block. They are all
+ // guaranteed to have exactly one entry if they exist, unless there are
+ // multiple duplicate (but guaranteed to be equal) entries for the
+ // incoming edges. This occurs when there are multiple edges from
+ // OnlyPred to OnlySucc.
+ //
+ while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
+ PN->replaceAllUsesWith(PN->getIncomingValue(0));
+ BB->getInstList().pop_front(); // Delete the phi node...
+ }
- // Move all definitions in the successor to the predecessor...
- OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
+ // Delete the unconditional branch from the predecessor...
+ OnlyPred->getInstList().pop_back();
- // Make all PHI nodes that referred to BB now refer to Pred as their
- // source...
- BB->replaceAllUsesWith(OnlyPred);
+ // Move all definitions in the successor to the predecessor...
+ OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
- std::string OldName = BB->getName();
+ // Make all PHI nodes that referred to BB now refer to Pred as their
+ // source...
+ BB->replaceAllUsesWith(OnlyPred);
- // Erase basic block from the function...
- LI->removeBlock(BB);
- BB->eraseFromParent();
+ std::string OldName = BB->getName();
- // Inherit predecessors name if it exists...
- if (!OldName.empty() && !OnlyPred->hasName())
- OnlyPred->setName(OldName);
+ // Erase basic block from the function...
+ LI->removeBlock(BB);
+ BB->eraseFromParent();
- return OnlyPred;
- }
-
- return 0;
+ // Inherit predecessors name if it exists...
+ if (!OldName.empty() && !OnlyPred->hasName())
+ OnlyPred->setName(OldName);
+
+ return OnlyPred;
}
bool LoopUnroll::visitLoop(Loop *L) {