From d648e140a525301b9fd82b6148e0c37877b0134d Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 29 Aug 2006 06:10:56 +0000 Subject: [PATCH] Clean up a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29950 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnroll.cpp | 83 +++++++++++----------------- 1 file changed, 32 insertions(+), 51 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnroll.cpp b/lib/Transforms/Scalar/LoopUnroll.cpp index 3bff2737bcd..f1a826e127c 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(&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(&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) { -- 2.34.1