From 2ae51d315c24f83166bac43f3898220fdb676812 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 21 Jul 2014 17:06:51 +0000 Subject: [PATCH] Revert "[C++11] Add predecessors(BasicBlock *) / successors(BasicBlock *) iterator ranges." This reverts commit r213474 (and r213475), which causes a miscompile on a stage2 LTO build. I'll reply on the list in a moment. llvm-svn: 213562 --- docs/ProgrammersManual.rst | 5 +- include/llvm/IR/CFG.h | 12 ----- lib/Analysis/BranchProbabilityInfo.cpp | 13 +++-- lib/Analysis/Interval.cpp | 5 +- lib/Analysis/LazyValueInfo.cpp | 4 +- lib/Analysis/LoopInfo.cpp | 19 ++++---- lib/Analysis/ScalarEvolution.cpp | 9 ++-- lib/CodeGen/CodeGenPrepare.cpp | 10 ++-- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 5 +- lib/CodeGen/SjLjEHPrepare.cpp | 4 +- lib/CodeGen/UnreachableBlockElim.cpp | 4 +- lib/IR/BasicBlock.cpp | 3 +- lib/IR/Dominators.cpp | 4 +- lib/IR/Verifier.cpp | 4 +- lib/Transforms/IPO/ArgumentPromotion.cpp | 3 +- lib/Transforms/IPO/LoopExtractor.cpp | 4 +- lib/Transforms/IPO/PartialInlining.cpp | 9 ++-- .../InstCombine/InstructionCombining.cpp | 4 +- .../Scalar/DeadStoreElimination.cpp | 3 +- lib/Transforms/Scalar/GVN.cpp | 15 ++++-- lib/Transforms/Scalar/JumpThreading.cpp | 23 +++++---- lib/Transforms/Scalar/LoopInstSimplify.cpp | 4 +- lib/Transforms/Scalar/LoopUnswitch.cpp | 8 ++-- lib/Transforms/Scalar/SampleProfile.cpp | 6 ++- lib/Transforms/Scalar/Sink.cpp | 9 ++-- lib/Transforms/Scalar/StructurizeCFG.cpp | 32 ++++++++----- .../Scalar/TailRecursionElimination.cpp | 5 +- lib/Transforms/Utils/BasicBlockUtils.cpp | 5 +- lib/Transforms/Utils/BreakCriticalEdges.cpp | 8 +++- lib/Transforms/Utils/CloneFunction.cpp | 5 +- lib/Transforms/Utils/CodeExtractor.cpp | 11 +++-- lib/Transforms/Utils/Local.cpp | 16 +++---- lib/Transforms/Utils/LoopSimplify.cpp | 31 ++++++++---- lib/Transforms/Utils/LoopUnroll.cpp | 14 +++--- lib/Transforms/Utils/LoopUnrollRuntime.cpp | 5 +- .../Utils/PromoteMemoryToRegister.cpp | 9 ++-- lib/Transforms/Utils/SSAUpdater.cpp | 6 ++- lib/Transforms/Utils/SimplifyCFG.cpp | 48 ++++++++++--------- lib/Transforms/Vectorize/LoopVectorize.cpp | 5 +- tools/bugpoint/CrashDebugger.cpp | 4 +- tools/llvm-diff/DifferenceEngine.cpp | 4 +- 41 files changed, 230 insertions(+), 167 deletions(-) diff --git a/docs/ProgrammersManual.rst b/docs/ProgrammersManual.rst index 049e3720369..46ec15f93a3 100644 --- a/docs/ProgrammersManual.rst +++ b/docs/ProgrammersManual.rst @@ -1854,11 +1854,12 @@ iterate over all predecessors of BB: #include "llvm/Support/CFG.h" BasicBlock *BB = ...; - for (BasicBlock *Pred : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *Pred = *PI; // ... } -Similarly, to iterate over successors use ``successors``. +Similarly, to iterate over successors use ``succ_iterator/succ_begin/succ_end``. .. _simplechanges: diff --git a/include/llvm/IR/CFG.h b/include/llvm/IR/CFG.h index 91cd84a1595..c8be8bd1f2a 100644 --- a/include/llvm/IR/CFG.h +++ b/include/llvm/IR/CFG.h @@ -93,12 +93,6 @@ inline pred_iterator pred_end(BasicBlock *BB) { return pred_iterator(BB, true);} inline const_pred_iterator pred_end(const BasicBlock *BB) { return const_pred_iterator(BB, true); } -inline iterator_range predecessors(BasicBlock *BB) { - return make_range(pred_begin(BB), pred_end(BB)); -} -inline iterator_range predecessors(const BasicBlock *BB) { - return make_range(pred_begin(BB), pred_end(BB)); -} @@ -263,12 +257,6 @@ inline succ_iterator succ_end(BasicBlock *BB) { inline succ_const_iterator succ_end(const BasicBlock *BB) { return succ_const_iterator(BB->getTerminator(), true); } -inline iterator_range successors(BasicBlock *BB) { - return make_range(succ_begin(BB), succ_end(BB)); -} -inline iterator_range successors(const BasicBlock *BB) { - return make_range(succ_begin(BB), succ_end(BB)); -} template struct isPodLike > { static const bool value = isPodLike::value; diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index fa9df4c8edb..bbd87505952 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -528,9 +528,13 @@ void BranchProbabilityInfo::print(raw_ostream &OS, const Module *) const { // We print the probabilities from the last function the analysis ran over, // or the function it is currently running over. assert(LastF && "Cannot print prior to running over a function"); - for (const BasicBlock &BB : *LastF) - for (const BasicBlock *Succ : successors(&BB)) - printEdgeProbability(OS << " ", &BB, Succ); + for (Function::const_iterator BI = LastF->begin(), BE = LastF->end(); + BI != BE; ++BI) { + for (succ_const_iterator SI = succ_begin(BI), SE = succ_end(BI); + SI != SE; ++SI) { + printEdgeProbability(OS << " ", BI, *SI); + } + } } uint32_t BranchProbabilityInfo::getSumForBlock(const BasicBlock *BB) const { @@ -559,7 +563,8 @@ BasicBlock *BranchProbabilityInfo::getHotSucc(BasicBlock *BB) const { uint32_t MaxWeight = 0; BasicBlock *MaxSucc = nullptr; - for (BasicBlock *Succ : successors(BB)) { + for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) { + BasicBlock *Succ = *I; uint32_t Weight = getEdgeWeight(BB, Succ); uint32_t PrevSum = Sum; diff --git a/lib/Analysis/Interval.cpp b/lib/Analysis/Interval.cpp index ca71cf38628..e3e785ffc45 100644 --- a/lib/Analysis/Interval.cpp +++ b/lib/Analysis/Interval.cpp @@ -29,8 +29,9 @@ using namespace llvm; bool Interval::isLoop() const { // There is a loop in this interval iff one of the predecessors of the header // node lives in the interval. - for (BasicBlock *Pred : predecessors(HeaderNode)) - if (contains(Pred)) + for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode); + I != E; ++I) + if (contains(*I)) return true; return false; } diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp index a65480c2e40..9f919f7644a 100644 --- a/lib/Analysis/LazyValueInfo.cpp +++ b/lib/Analysis/LazyValueInfo.cpp @@ -625,9 +625,9 @@ bool LazyValueInfoCache::solveBlockValueNonLocal(LVILatticeVal &BBLV, // Loop over all of our predecessors, merging what we know from them into // result. bool EdgesMissing = false; - for (BasicBlock *Pred : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { LVILatticeVal EdgeResult; - EdgesMissing |= !getEdgeValue(Val, Pred, BB, EdgeResult); + EdgesMissing |= !getEdgeValue(Val, *PI, BB, EdgeResult); if (EdgesMissing) continue; diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index a6d8b55c08f..46c0eaabe1a 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -336,8 +336,9 @@ bool Loop::hasDedicatedExits() const { SmallVector ExitBlocks; getExitBlocks(ExitBlocks); for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) - for (BasicBlock *Pred : predecessors(ExitBlocks[i])) - if (!contains(Pred)) + for (pred_iterator PI = pred_begin(ExitBlocks[i]), + PE = pred_end(ExitBlocks[i]); PI != PE; ++PI) + if (!contains(*PI)) return false; // All the requirements are met. return true; @@ -359,12 +360,12 @@ Loop::getUniqueExitBlocks(SmallVectorImpl &ExitBlocks) const { BasicBlock *current = *BI; switchExitBlocks.clear(); - for (BasicBlock *Succ : successors(*BI)) { + for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) { // If block is inside the loop then it is not a exit block. - if (contains(Succ)) + if (contains(*I)) continue; - pred_iterator PI = pred_begin(Succ); + pred_iterator PI = pred_begin(*I); BasicBlock *firstPred = *PI; // If current basic block is this exit block's first predecessor @@ -378,17 +379,17 @@ Loop::getUniqueExitBlocks(SmallVectorImpl &ExitBlocks) const { // then it is possible that there are multiple edges from current block // to one exit block. if (std::distance(succ_begin(current), succ_end(current)) <= 2) { - ExitBlocks.push_back(Succ); + ExitBlocks.push_back(*I); continue; } // In case of multiple edges from current block to exit block, collect // only one edge in ExitBlocks. Use switchExitBlocks to keep track of // duplicate edges. - if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), Succ) + if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), *I) == switchExitBlocks.end()) { - switchExitBlocks.push_back(Succ); - ExitBlocks.push_back(Succ); + switchExitBlocks.push_back(*I); + ExitBlocks.push_back(*I); } } } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index fd5b86b4634..06dbde58c10 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -4512,12 +4512,13 @@ ScalarEvolution::ComputeExitLimit(const Loop *L, BasicBlock *ExitingBlock) { // lead to the loop header. bool MustExecuteLoopHeader = true; BasicBlock *Exit = nullptr; - for (BasicBlock *Succ : successors(ExitingBlock)) - if (!L->contains(Succ)) { + for (succ_iterator SI = succ_begin(ExitingBlock), SE = succ_end(ExitingBlock); + SI != SE; ++SI) + if (!L->contains(*SI)) { if (Exit) // Multiple exit successors. return getCouldNotCompute(); - Exit = Succ; - } else if (Succ != L->getHeader()) { + Exit = *SI; + } else if (*SI != L->getHeader()) { MustExecuteLoopHeader = false; } diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index 6f3ec1bda48..d5039b2e851 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -453,8 +453,8 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) { for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i) PN->addIncoming(InVal, BBPN->getIncomingBlock(i)); } else { - for (BasicBlock *Pred : predecessors(BB)) - PN->addIncoming(InVal, Pred); + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + PN->addIncoming(InVal, *PI); } } } @@ -977,11 +977,11 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(BasicBlock *BB) { } } else { SmallPtrSet VisitedBBs; - for (BasicBlock *Pred : predecessors(BB)) { - if (!VisitedBBs.insert(Pred)) + for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) { + if (!VisitedBBs.insert(*PI)) continue; - BasicBlock::InstListType &InstList = Pred->getInstList(); + BasicBlock::InstListType &InstList = (*PI)->getInstList(); BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin(); BasicBlock::InstListType::reverse_iterator RE = InstList.rend(); do { ++RI; } while (RI != RE && isa(&*RI)); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index af7ecff9fc4..57e22e21c37 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1052,8 +1052,9 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) { if (OptLevel != CodeGenOpt::None) { bool AllPredsVisited = true; - for (const BasicBlock *Pred : predecessors(LLVMBB)) { - if (!FuncInfo->VisitedBBs.count(Pred)) { + for (const_pred_iterator PI = pred_begin(LLVMBB), PE = pred_end(LLVMBB); + PI != PE; ++PI) { + if (!FuncInfo->VisitedBBs.count(*PI)) { AllPredsVisited = false; break; } diff --git a/lib/CodeGen/SjLjEHPrepare.cpp b/lib/CodeGen/SjLjEHPrepare.cpp index 1cfd4d255ed..b0950ded270 100644 --- a/lib/CodeGen/SjLjEHPrepare.cpp +++ b/lib/CodeGen/SjLjEHPrepare.cpp @@ -142,8 +142,8 @@ static void MarkBlocksLiveIn(BasicBlock *BB, if (!LiveBBs.insert(BB)) return; // already been here. - for (BasicBlock *Pred : predecessors(BB)) - MarkBlocksLiveIn(Pred, LiveBBs); + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + MarkBlocksLiveIn(*PI, LiveBBs); } /// substituteLPadValues - Substitute the values returned by the landingpad diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp index 0476a1292f8..2e220820b92 100644 --- a/lib/CodeGen/UnreachableBlockElim.cpp +++ b/lib/CodeGen/UnreachableBlockElim.cpp @@ -79,8 +79,8 @@ bool UnreachableBlockElim::runOnFunction(Function &F) { PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); BB->getInstList().pop_front(); } - for (BasicBlock *S : successors(BB)) - S->removePredecessor(BB); + for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) + (*SI)->removePredecessor(BB); BB->dropAllReferences(); } diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp index 8ddcf25fced..ba07433103b 100644 --- a/lib/IR/BasicBlock.cpp +++ b/lib/IR/BasicBlock.cpp @@ -321,9 +321,10 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) { // successors. If there were PHI nodes in the successors, then they need to // know that incoming branches will be from New, not from Old. // - for (BasicBlock *Successor : successors(New)) { + for (succ_iterator I = succ_begin(New), E = succ_end(New); I != E; ++I) { // Loop over any phi nodes in the basic block, updating the BB field of // incoming values... + BasicBlock *Successor = *I; PHINode *PN; for (BasicBlock::iterator II = Successor->begin(); (PN = dyn_cast(II)); ++II) { diff --git a/lib/IR/Dominators.cpp b/lib/IR/Dominators.cpp index f45543a4e71..d6649d6c706 100644 --- a/lib/IR/Dominators.cpp +++ b/lib/IR/Dominators.cpp @@ -179,7 +179,9 @@ bool DominatorTree::dominates(const BasicBlockEdge &BBE, // trivially dominates itself, so we only have to find if it dominates the // other predecessors. Since the only way out of X is via NormalDest, X can // only properly dominate a node if NormalDest dominates that node too. - for (const BasicBlock *BB : predecessors(End)) { + for (const_pred_iterator PI = pred_begin(End), E = pred_end(End); + PI != E; ++PI) { + const BasicBlock *BB = *PI; if (BB == Start) continue; diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 5b7a3475574..9cf911b51a4 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -2107,8 +2107,8 @@ void Verifier::visitLandingPadInst(LandingPadInst &LPI) { // The landingpad instruction defines its parent as a landing pad block. The // landing pad block may be branched to only by the unwind edge of an invoke. - for (BasicBlock *Pred : predecessors(BB)) { - const InvokeInst *II = dyn_cast(Pred->getTerminator()); + for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { + const InvokeInst *II = dyn_cast((*I)->getTerminator()); Assert1(II && II->getUnwindDest() == BB && II->getNormalDest() != BB, "Block containing LandingPadInst must be jumped to " "only by the unwind edge of an invoke.", &LPI); diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 816fc291dc5..f9de54a173d 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -473,7 +473,8 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, // Now check every path from the entry block to the load for transparency. // To do this, we perform a depth first search on the inverse CFG from the // loading block. - for (BasicBlock *P : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *P = *PI; for (idf_ext_iterator > I = idf_ext_begin(P, TranspBlocks), E = idf_ext_end(P, TranspBlocks); I != E; ++I) diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp index 3f973c716ff..20414aa05b4 100644 --- a/lib/Transforms/IPO/LoopExtractor.cpp +++ b/lib/Transforms/IPO/LoopExtractor.cpp @@ -229,7 +229,9 @@ void BlockExtractorPass::SplitLandingPadPreds(Function *F) { // Look through the landing pad's predecessors. If one of them ends in an // 'invoke', then we want to split the landing pad. bool Split = false; - for (BasicBlock *BB : predecessors(LPad)) { + for (pred_iterator + PI = pred_begin(LPad), PE = pred_end(LPad); PI != PE; ++PI) { + BasicBlock *BB = *PI; if (BB->isLandingPad() && BB != Parent && isa(Parent->getTerminator())) { Split = true; diff --git a/lib/Transforms/IPO/PartialInlining.cpp b/lib/Transforms/IPO/PartialInlining.cpp index 5957e84ffab..76d6dfa8e88 100644 --- a/lib/Transforms/IPO/PartialInlining.cpp +++ b/lib/Transforms/IPO/PartialInlining.cpp @@ -58,12 +58,13 @@ Function* PartialInliner::unswitchFunction(Function* F) { BasicBlock* returnBlock = nullptr; BasicBlock* nonReturnBlock = nullptr; unsigned returnCount = 0; - for (BasicBlock *Succ : successors(entryBlock)) - if (isa(Succ->getTerminator())) { - returnBlock = Succ; + for (succ_iterator SI = succ_begin(entryBlock), SE = succ_end(entryBlock); + SI != SE; ++SI) + if (isa((*SI)->getTerminator())) { + returnBlock = *SI; returnCount++; } else - nonReturnBlock = Succ; + nonReturnBlock = *SI; if (returnCount != 1) return nullptr; diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 0e8518108da..d3648e2d050 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2718,8 +2718,8 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { if (UserParent != BB) { bool UserIsSuccessor = false; // See if the user is one of our successors. - for (BasicBlock *Succ : successors(BB)) - if (Succ == UserParent) { + for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) + if (*SI == UserParent) { UserIsSuccessor = true; break; } diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 51e0bc289bb..3af8ee7546f 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -642,7 +642,8 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { /// them to F. static void FindUnconditionalPreds(SmallVectorImpl &Blocks, BasicBlock *BB, DominatorTree *DT) { - for (BasicBlock *Pred : predecessors(BB)) { + for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { + BasicBlock *Pred = *I; if (Pred == BB) continue; TerminatorInst *PredTI = Pred->getTerminator(); if (PredTI->getNumSuccessors() != 1) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 3ed7e3e5a3e..106eba099ca 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1555,7 +1555,9 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock, FullyAvailableBlocks[UnavailableBlocks[i]] = false; SmallVector CriticalEdgePred; - for (BasicBlock *Pred : predecessors(LoadBB)) { + for (pred_iterator PI = pred_begin(LoadBB), E = pred_end(LoadBB); + PI != E; ++PI) { + BasicBlock *Pred = *PI; if (IsValueFullyAvailableInBlock(Pred, FullyAvailableBlocks, 0)) { continue; } @@ -2481,7 +2483,9 @@ bool GVN::performPRE(Function &F) { BasicBlock *PREPred = nullptr; predMap.clear(); - for (BasicBlock *P : predecessors(CurrentBlock)) { + for (pred_iterator PI = pred_begin(CurrentBlock), + PE = pred_end(CurrentBlock); PI != PE; ++PI) { + BasicBlock *P = *PI; // We're not interested in PRE where the block is its // own predecessor, or in blocks with predecessors // that are not reachable. @@ -2709,13 +2713,14 @@ void GVN::addDeadBlock(BasicBlock *BB) { for (SmallVectorImpl::iterator I = Dom.begin(), E = Dom.end(); I != E; I++) { BasicBlock *B = *I; - for (BasicBlock *S : successors(B)) { + for (succ_iterator SI = succ_begin(B), SE = succ_end(B); SI != SE; SI++) { + BasicBlock *S = *SI; if (DeadBlocks.count(S)) continue; bool AllPredDead = true; - for (BasicBlock *Pred : predecessors(S)) - if (!DeadBlocks.count(Pred)) { + for (pred_iterator PI = pred_begin(S), PE = pred_end(S); PI != PE; PI++) + if (!DeadBlocks.count(*PI)) { AllPredDead = false; break; } diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index d9b6d560f09..21f80385cf4 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -353,8 +353,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result, // If V is a constant, then it is known in all predecessors. if (Constant *KC = getKnownConstant(V, Preference)) { - for (BasicBlock *Pred : predecessors(BB)) - Result.push_back(std::make_pair(KC, Pred)); + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + Result.push_back(std::make_pair(KC, *PI)); return true; } @@ -377,7 +377,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result, // "X < 4" and "X < 3" is known true but "X < 4" itself is not available. // Perhaps getConstantOnEdge should be smart enough to do this? - for (BasicBlock *P : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *P = *PI; // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. Constant *PredCst = LVI->getConstantOnEdge(V, P, BB); @@ -531,7 +532,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result, cast(Cmp->getOperand(0))->getParent() != BB) { Constant *RHSCst = cast(Cmp->getOperand(1)); - for (BasicBlock *P : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB);PI != E; ++PI){ + BasicBlock *P = *PI; // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. LazyValueInfo::Tristate Res = @@ -604,8 +606,8 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result, // If all else fails, see if LVI can figure out a constant value for us. Constant *CI = LVI->getConstant(V, BB); if (Constant *KC = getKnownConstant(CI, Preference)) { - for (BasicBlock *Pred : predecessors(BB)) - Result.push_back(std::make_pair(KC, Pred)); + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + Result.push_back(std::make_pair(KC, *PI)); } return !Result.empty(); @@ -897,7 +899,10 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) { // If we got here, the loaded value is transparent through to the start of the // block. Check to see if it is available in any of the predecessor blocks. - for (BasicBlock *PredBB : predecessors(LoadBB)) { + for (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB); + PI != PE; ++PI) { + BasicBlock *PredBB = *PI; + // If we already scanned this predecessor, skip it. if (!PredsScanned.insert(PredBB)) continue; @@ -947,7 +952,9 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) { AvailablePredSet.insert(AvailablePreds[i].first); // Add all the unavailable predecessors to the PredsToSplit list. - for (BasicBlock *P : predecessors(LoadBB)) { + for (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB); + PI != PE; ++PI) { + BasicBlock *P = *PI; // If the predecessor is an indirect goto, we can't split the edge. if (isa(P->getTerminator())) return false; diff --git a/lib/Transforms/Scalar/LoopInstSimplify.cpp b/lib/Transforms/Scalar/LoopInstSimplify.cpp index 657038eeca7..ab1a9393c52 100644 --- a/lib/Transforms/Scalar/LoopInstSimplify.cpp +++ b/lib/Transforms/Scalar/LoopInstSimplify.cpp @@ -145,7 +145,9 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // bodies of subloops. We visit the headers of loops so that we can process // their phis, but we contract the rest of the subloop body and only follow // edges leading back to the original loop. - for (BasicBlock *SuccBB : successors(BB)) { + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; + ++SI) { + BasicBlock *SuccBB = *SI; if (!Visited.insert(SuccBB)) continue; diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 68bd4b82959..977c53a3bc6 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -515,9 +515,9 @@ static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB, } // Otherwise, this is an unvisited intra-loop node. Check all successors. - for (BasicBlock *Succ : successors(BB)) { + for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) { // Check to see if the successor is a trivial loop exit. - if (!isTrivialLoopExitBlockHelper(L, Succ, ExitBB, Visited)) + if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited)) return false; } @@ -861,7 +861,9 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, PHINode *PN = PHINode::Create(LPad->getType(), 0, "", ExitSucc->getFirstInsertionPt()); - for (BasicBlock *BB : predecessors(ExitSucc)) { + for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc); + I != E; ++I) { + BasicBlock *BB = *I; LandingPadInst *LPI = BB->getLandingPadInst(); LPI->replaceAllUsesWith(PN); PN->addIncoming(LPI, BB); diff --git a/lib/Transforms/Scalar/SampleProfile.cpp b/lib/Transforms/Scalar/SampleProfile.cpp index 8e3583a1237..73c97ffeef4 100644 --- a/lib/Transforms/Scalar/SampleProfile.cpp +++ b/lib/Transforms/Scalar/SampleProfile.cpp @@ -865,7 +865,8 @@ void SampleFunctionProfile::buildEdges(Function &F) { SmallPtrSet Visited; if (!Predecessors[B1].empty()) llvm_unreachable("Found a stale predecessors list in a basic block."); - for (BasicBlock *B2 : predecessors(B1)) { + for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) { + BasicBlock *B2 = *PI; if (Visited.insert(B2)) Predecessors[B1].push_back(B2); } @@ -874,7 +875,8 @@ void SampleFunctionProfile::buildEdges(Function &F) { Visited.clear(); if (!Successors[B1].empty()) llvm_unreachable("Found a stale successors list in a basic block."); - for (BasicBlock *B2 : successors(B1)) { + for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) { + BasicBlock *B2 = *SI; if (Visited.insert(B2)) Successors[B1].push_back(B2); } diff --git a/lib/Transforms/Scalar/Sink.cpp b/lib/Transforms/Scalar/Sink.cpp index 2f7a9f9a65c..7348c45c5d3 100644 --- a/lib/Transforms/Scalar/Sink.cpp +++ b/lib/Transforms/Scalar/Sink.cpp @@ -258,11 +258,10 @@ bool Sinking::SinkInstruction(Instruction *Inst, // If no suitable postdominator was found, look at all the successors and // decide which one we should sink to, if any. - for (BasicBlock *Succ : successors(Inst->getParent())) { - if (SuccToSinkTo) - break; - if (IsAcceptableTarget(Inst, Succ)) - SuccToSinkTo = Succ; + for (succ_iterator I = succ_begin(Inst->getParent()), + E = succ_end(Inst->getParent()); I != E && !SuccToSinkTo; ++I) { + if (IsAcceptableTarget(Inst, *I)) + SuccToSinkTo = *I; } // If we couldn't find a block to sink to, ignore this instruction. diff --git a/lib/Transforms/Scalar/StructurizeCFG.cpp b/lib/Transforms/Scalar/StructurizeCFG.cpp index d2206e380c1..b9673ed655e 100644 --- a/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -365,39 +365,41 @@ void StructurizeCFG::gatherPredicates(RegionNode *N) { BBPredicates &Pred = Predicates[BB]; BBPredicates &LPred = LoopPreds[BB]; - for (BasicBlock *Predecessor : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); + PI != PE; ++PI) { + // Ignore it if it's a branch from outside into our region entry - if (!ParentRegion->contains(Predecessor)) + if (!ParentRegion->contains(*PI)) continue; - Region *R = RI->getRegionFor(Predecessor); + Region *R = RI->getRegionFor(*PI); if (R == ParentRegion) { // It's a top level block in our region - BranchInst *Term = cast(Predecessor->getTerminator()); + BranchInst *Term = cast((*PI)->getTerminator()); for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) { BasicBlock *Succ = Term->getSuccessor(i); if (Succ != BB) continue; - if (Visited.count(Predecessor)) { + if (Visited.count(*PI)) { // Normal forward edge if (Term->isConditional()) { // Try to treat it like an ELSE block BasicBlock *Other = Term->getSuccessor(!i); if (Visited.count(Other) && !Loops.count(Other) && - !Pred.count(Other) && !Pred.count(Predecessor)) { + !Pred.count(Other) && !Pred.count(*PI)) { Pred[Other] = BoolFalse; - Pred[Predecessor] = BoolTrue; + Pred[*PI] = BoolTrue; continue; } } - Pred[Predecessor] = buildCondition(Term, i, false); + Pred[*PI] = buildCondition(Term, i, false); } else { // Back edge - LPred[Predecessor] = buildCondition(Term, i, true); + LPred[*PI] = buildCondition(Term, i, true); } } @@ -572,8 +574,11 @@ void StructurizeCFG::killTerminator(BasicBlock *BB) { if (!Term) return; - for (BasicBlock *Succ : successors(BB)) - delPhiValues(BB, Succ); + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); + SI != SE; ++SI) { + + delPhiValues(BB, *SI); + } Term->eraseFromParent(); } @@ -587,7 +592,10 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit, BasicBlock *Dominator = nullptr; // Find all the edges from the sub region to the exit - for (BasicBlock *BB : predecessors(OldExit)) { + for (pred_iterator I = pred_begin(OldExit), E = pred_end(OldExit); + I != E;) { + + BasicBlock *BB = *I++; if (!SubRegion->contains(BB)) continue; diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index d9280ac6c9c..05b9892470b 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -335,7 +335,7 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) { } } - for (auto *SuccBB : successors(BB)) { + for (auto *SuccBB : make_range(succ_begin(BB), succ_end(BB))) { auto &State = Visited[SuccBB]; if (State < Escaped) { State = Escaped; @@ -807,7 +807,8 @@ bool TailCallElim::FoldReturnAndProcessPred(BasicBlock *BB, // predecessors and perform TRC there. Look for predecessors that end // in unconditional branch and recursive call(s). SmallVector UncondBranchPreds; - for (BasicBlock *Pred : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *Pred = *PI; TerminatorInst *PTI = Pred->getTerminator(); if (BranchInst *BI = dyn_cast(PTI)) if (BI->isUnconditional()) diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 5af417cd936..602e8ba5510 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -549,11 +549,14 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB, // Move the remaining edges from OrigBB to point to NewBB2. SmallVector NewBB2Preds; - for (BasicBlock *Pred : predecessors(OrigBB)) { + for (pred_iterator i = pred_begin(OrigBB), e = pred_end(OrigBB); + i != e; ) { + BasicBlock *Pred = *i++; if (Pred == NewBB1) continue; assert(!isa(Pred->getTerminator()) && "Cannot split an edge from an IndirectBrInst"); NewBB2Preds.push_back(Pred); + e = pred_end(OrigBB); } BasicBlock *NewBB2 = nullptr; diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp index dc12f977046..80bd5163751 100644 --- a/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -233,7 +233,9 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, if (PN->getIncomingBlock(i) != NewBB) OtherPreds.push_back(PN->getIncomingBlock(i)); } else { - for (BasicBlock *P : predecessors(DestBB)) { + for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); + I != E; ++I) { + BasicBlock *P = *I; if (P != NewBB) OtherPreds.push_back(P); } @@ -319,7 +321,9 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, // the predecessor must be directly in TIL, not in a subloop, or again // LoopSimplify doesn't hold. SmallVector LoopPreds; - for (BasicBlock *P : predecessors(DestBB)) { + for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); I != E; + ++I) { + BasicBlock *P = *I; if (P == NewBB) continue; // The new block is known. if (LI->getLoopFor(P) != TIL) { diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index f148ea17481..5c8f20d5f88 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -514,8 +514,9 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, assert(NumPreds < PN->getNumIncomingValues()); // Count how many times each predecessor comes to this block. std::map PredCount; - for (BasicBlock *Pred : predecessors(NewBB)) - --PredCount[Pred]; + for (pred_iterator PI = pred_begin(NewBB), E = pred_end(NewBB); + PI != E; ++PI) + --PredCount[*PI]; // Figure out how many entries to remove from each PHI. for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index d7445ef65b6..e70a7d6e76c 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -91,8 +91,9 @@ static SetVector buildExtractionBlockSet(IteratorT BBBegin, for (SetVector::iterator I = std::next(Result.begin()), E = Result.end(); I != E; ++I) - for (BasicBlock *Pred : predecessors(*I)) - assert(Result.count(Pred) && + for (pred_iterator PI = pred_begin(*I), PE = pred_end(*I); + PI != PE; ++PI) + assert(Result.count(*PI) && "No blocks in this region may have entries from outside the region" " except for the first block!"); #endif @@ -720,9 +721,9 @@ Function *CodeExtractor::extractCodeRegion() { SmallPtrSet ExitBlocks; for (SetVector::iterator I = Blocks.begin(), E = Blocks.end(); I != E; ++I) - for (BasicBlock *Succ : successors(*I)) - if (!Blocks.count(Succ)) - ExitBlocks.insert(Succ); + for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) + if (!Blocks.count(*SI)) + ExitBlocks.insert(*SI); NumExitBlocks = ExitBlocks.size(); // Construct new function based on inputs/outputs & add allocas for all defs. diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 113a2ae7584..a5e443fcf46 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -1129,8 +1129,8 @@ static void changeToUnreachable(Instruction *I, bool UseLLVMTrap) { BasicBlock *BB = I->getParent(); // Loop over all of the successors, removing BB's entry from any PHI // nodes. - for (BasicBlock *Succ : successors(BB)) - Succ->removePredecessor(BB); + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) + (*SI)->removePredecessor(BB); // Insert a call to llvm.trap right before this. This turns the undefined // behavior into a hard fail instead of falling through into random code. @@ -1236,9 +1236,9 @@ static bool markAliveBlocks(BasicBlock *BB, } Changed |= ConstantFoldTerminator(BB, true); - for (BasicBlock *Succ : successors(BB)) - if (Reachable.insert(Succ)) - Worklist.push_back(Succ); + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) + if (Reachable.insert(*SI)) + Worklist.push_back(*SI); } while (!Worklist.empty()); return Changed; } @@ -1263,9 +1263,9 @@ bool llvm::removeUnreachableBlocks(Function &F) { if (Reachable.count(BB)) continue; - for (BasicBlock *Succ : successors(BB)) - if (Reachable.count(Succ)) - Succ->removePredecessor(BB); + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) + if (Reachable.count(*SI)) + (*SI)->removePredecessor(BB); BB->dropAllReferences(); } diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index faab7725855..ef422914b6b 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -114,7 +114,9 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, Pass *PP) { // Compute the set of predecessors of the loop that are not in the loop. SmallVector OutsideBlocks; - for (BasicBlock *P : predecessors(Header)) { + for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header); + PI != PE; ++PI) { + BasicBlock *P = *PI; if (!L->contains(P)) { // Coming in from outside the loop? // If the loop is branched to from an indirect branch, we won't // be able to fully transform the loop, because it prohibits @@ -156,7 +158,8 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, Pass *PP) { /// the loop. static BasicBlock *rewriteLoopExitBlock(Loop *L, BasicBlock *Exit, Pass *PP) { SmallVector LoopBlocks; - for (BasicBlock *P : predecessors(Exit)) { + for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) { + BasicBlock *P = *I; if (L->contains(P)) { // Don't do this if the loop is exited via an indirect branch. if (isa(P->getTerminator())) return nullptr; @@ -196,8 +199,10 @@ static void addBlockAndPredsToSet(BasicBlock *InputBB, BasicBlock *StopBlock, if (Blocks.insert(BB).second && BB != StopBlock) // If BB is not already processed and it is not a stop block then // insert its predecessor in the work list - for (BasicBlock *WBB : predecessors(BB)) + for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { + BasicBlock *WBB = *I; Worklist.push_back(WBB); + } } while (!Worklist.empty()); } @@ -311,7 +316,8 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader, // Determine which blocks should stay in L and which should be moved out to // the Outer loop now. std::set BlocksInL; - for (BasicBlock *P : predecessors(Header)) { + for (pred_iterator PI=pred_begin(Header), E = pred_end(Header); PI!=E; ++PI) { + BasicBlock *P = *PI; if (DT->dominates(Header, P)) addBlockAndPredsToSet(P, Header, BlocksInL); } @@ -365,7 +371,9 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader, // Figure out which basic blocks contain back-edges to the loop header. std::vector BackedgeBlocks; - for (BasicBlock *P : predecessors(Header)) { + for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I){ + BasicBlock *P = *I; + // Indirectbr edges cannot be split, so we must fail if we find one. if (isa(P->getTerminator())) return nullptr; @@ -480,7 +488,9 @@ ReprocessLoop: if (*BB == L->getHeader()) continue; SmallPtrSet BadPreds; - for (BasicBlock *P : predecessors(*BB)) { + for (pred_iterator PI = pred_begin(*BB), + PE = pred_end(*BB); PI != PE; ++PI) { + BasicBlock *P = *PI; if (!L->contains(P)) BadPreds.insert(P); } @@ -493,8 +503,8 @@ ReprocessLoop: << (*I)->getName() << "\n"); // Inform each successor of each dead pred. - for (BasicBlock *Succ : successors(*I)) - Succ->removePredecessor(*I); + for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) + (*SI)->removePredecessor(*I); // Zap the dead pred's terminator and replace it with unreachable. TerminatorInst *TI = (*I)->getTerminator(); TI->replaceAllUsesWith(UndefValue::get(TI->getType())); @@ -551,10 +561,11 @@ ReprocessLoop: for (SmallSetVector::iterator I = ExitBlockSet.begin(), E = ExitBlockSet.end(); I != E; ++I) { BasicBlock *ExitBlock = *I; - for (BasicBlock *Pred : predecessors(ExitBlock)) + for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); + PI != PE; ++PI) // Must be exactly this loop: no subloops, parent loops, or non-loop preds // allowed. - if (!L->contains(Pred)) { + if (!L->contains(*PI)) { if (rewriteLoopExitBlock(L, ExitBlock, PP)) { ++NumInserted; Changed = true; diff --git a/lib/Transforms/Utils/LoopUnroll.cpp b/lib/Transforms/Utils/LoopUnroll.cpp index 3b0e813072d..ab1c25a75e2 100644 --- a/lib/Transforms/Utils/LoopUnroll.cpp +++ b/lib/Transforms/Utils/LoopUnroll.cpp @@ -328,10 +328,11 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, L->addBasicBlockToLoop(New, LI->getBase()); // Add phi entries for newly created values to all exit blocks. - for (BasicBlock *Succ : successors(*BB)) { - if (L->contains(Succ)) + for (succ_iterator SI = succ_begin(*BB), SE = succ_end(*BB); + SI != SE; ++SI) { + if (L->contains(*SI)) continue; - for (BasicBlock::iterator BBI = Succ->begin(); + for (BasicBlock::iterator BBI = (*SI)->begin(); PHINode *phi = dyn_cast(BBI); ++BBI) { Value *Incoming = phi->getIncomingValueForBlock(*BB); ValueToValueMapTy::iterator It = LastValueMap.find(Incoming); @@ -413,10 +414,11 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, // Remove phi operands at this loop exit if (Dest != LoopExit) { BasicBlock *BB = Latches[i]; - for (BasicBlock *Succ : successors(BB)) { - if (Succ == Headers[i]) + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); + SI != SE; ++SI) { + if (*SI == Headers[i]) continue; - for (BasicBlock::iterator BBI = Succ->begin(); + for (BasicBlock::iterator BBI = (*SI)->begin(); PHINode *Phi = dyn_cast(BBI); ++BBI) { Phi->removeIncomingValue(BB, false); } diff --git a/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/lib/Transforms/Utils/LoopUnrollRuntime.cpp index ce420ee4bf0..a96c46ad63e 100644 --- a/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -66,8 +66,9 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count, // The new PHI node is inserted in the prolog end basic block. // The new PHI name is added as an operand of a PHI node in either // the loop header or the loop exit block. - for (BasicBlock *Succ : successors(Latch)) { - for (BasicBlock::iterator BBI = Succ->begin(); + for (succ_iterator SBI = succ_begin(Latch), SBE = succ_end(Latch); + SBI != SBE; ++SBI) { + for (BasicBlock::iterator BBI = (*SBI)->begin(); PHINode *PN = dyn_cast(BBI); ++BBI) { // Add a new PHI node to the prolog end block and add the diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index a3da9892314..06d73feb1cc 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -822,7 +822,9 @@ void PromoteMem2Reg::ComputeLiveInBlocks( // Since the value is live into BB, it is either defined in a predecessor or // live into it to. Add the preds to the worklist unless they are a // defining block. - for (BasicBlock *P : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *P = *PI; + // The value is not live into a predecessor if it defines the value. if (DefBlocks.count(P)) continue; @@ -883,8 +885,9 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum, DomTreeNode *Node = Worklist.pop_back_val(); BasicBlock *BB = Node->getBlock(); - for (BasicBlock *Succ : successors(BB)) { - DomTreeNode *SuccNode = DT.getNode(Succ); + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; + ++SI) { + DomTreeNode *SuccNode = DT.getNode(*SI); // Quickly skip all CFG edges that are also dominator tree edges instead // of catching them below. diff --git a/lib/Transforms/Utils/SSAUpdater.cpp b/lib/Transforms/Utils/SSAUpdater.cpp index 67d06d1ef64..3fcb789bd84 100644 --- a/lib/Transforms/Utils/SSAUpdater.cpp +++ b/lib/Transforms/Utils/SSAUpdater.cpp @@ -110,7 +110,8 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) { } } else { bool isFirstPred = true; - for (BasicBlock *PredBB : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *PredBB = *PI; Value *PredVal = GetValueAtEndOfBlock(PredBB); PredValues.push_back(std::make_pair(PredBB, PredVal)); @@ -247,7 +248,8 @@ public: for (unsigned PI = 0, E = SomePhi->getNumIncomingValues(); PI != E; ++PI) Preds->push_back(SomePhi->getIncomingBlock(PI)); } else { - Preds->insert(Preds->end(), pred_begin(BB), pred_end(BB)); + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + Preds->push_back(*PI); } } diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 4e589cc6ab8..960b198f36b 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -130,9 +130,9 @@ static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) { BasicBlock *SI2BB = SI2->getParent(); SmallPtrSet SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); - for (BasicBlock *Succ : successors(SI2BB)) - if (SI1Succs.count(Succ)) - for (BasicBlock::iterator BBI = Succ->begin(); + for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) + if (SI1Succs.count(*I)) + for (BasicBlock::iterator BBI = (*I)->begin(); isa(BBI); ++BBI) { PHINode *PN = cast(BBI); if (PN->getIncomingValueForBlock(SI1BB) != @@ -171,9 +171,9 @@ static bool isProfitableToFoldUnconditional(BranchInst *SI1, BasicBlock *SI1BB = SI1->getParent(); BasicBlock *SI2BB = SI2->getParent(); SmallPtrSet SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); - for (BasicBlock *Succ : successors(SI2BB)) - if (SI1Succs.count(Succ)) - for (BasicBlock::iterator BBI = Succ->begin(); + for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) + if (SI1Succs.count(*I)) + for (BasicBlock::iterator BBI = (*I)->begin(); isa(BBI); ++BBI) { PHINode *PN = cast(BBI); if (PN->getIncomingValueForBlock(SI1BB) != Cond || @@ -683,9 +683,9 @@ SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI, // Remove PHI node entries for dead edges. BasicBlock *CheckEdge = TheRealDest; - for (BasicBlock *Succ : successors(TIBB)) - if (Succ != CheckEdge) - Succ->removePredecessor(TIBB); + for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI) + if (*SI != CheckEdge) + (*SI)->removePredecessor(TIBB); else CheckEdge = nullptr; @@ -981,9 +981,9 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI, // to put the select in this case. static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2, Instruction *I1, Instruction *I2) { - for (BasicBlock *Succ : successors(BB1)) { + for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { PHINode *PN; - for (BasicBlock::iterator BBI = Succ->begin(); + for (BasicBlock::iterator BBI = SI->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1063,9 +1063,9 @@ HoistTerminator: if (isa(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2)) return Changed; - for (BasicBlock *Succ : successors(BB1)) { + for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { PHINode *PN; - for (BasicBlock::iterator BBI = Succ->begin(); + for (BasicBlock::iterator BBI = SI->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1094,9 +1094,9 @@ HoistTerminator: // them. If they do, all PHI entries for BB1/BB2 must agree for all PHI // nodes, so we insert select instruction to compute the final result. std::map, SelectInst*> InsertedSelects; - for (BasicBlock *Succ : successors(BB1)) { + for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { PHINode *PN; - for (BasicBlock::iterator BBI = Succ->begin(); + for (BasicBlock::iterator BBI = SI->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1118,8 +1118,8 @@ HoistTerminator: } // Update any PHI nodes in our new successors. - for (BasicBlock *Succ : successors(BB1)) - AddPredecessorToBlock(Succ, BIParent, BB1); + for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) + AddPredecessorToBlock(*SI, BIParent, BB1); EraseTerminatorInstAndDCECond(BI); return true; @@ -2051,7 +2051,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, const DataLayout *DL) { if (TrueDest == BB || FalseDest == BB) return false; - for (BasicBlock *PredBlock : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *PredBlock = *PI; BranchInst *PBI = dyn_cast(PredBlock->getTerminator()); // Check that we have two conditional branches. If there is a PHI node in @@ -2884,8 +2885,8 @@ bool SimplifyCFGOpt::SimplifyResume(ResumeInst *RI, IRBuilder<> &Builder) { // Turn all invokes that unwind here into calls and delete the basic block. bool InvokeRequiresTableEntry = false; bool Changed = false; - for (BasicBlock *Pred : predecessors(BB)) { - InvokeInst *II = cast(Pred->getTerminator()); + for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) { + InvokeInst *II = cast((*PI++)->getTerminator()); if (II->hasFnAttr(Attribute::UWTable)) { // Don't remove an `invoke' instruction if the ABI requires an entry into @@ -2932,7 +2933,8 @@ bool SimplifyCFGOpt::SimplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) { // Find predecessors that end with branches. SmallVector UncondBranchPreds; SmallVector CondBranchPreds; - for (BasicBlock *P : predecessors(BB)) { + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *P = *PI; TerminatorInst *PTI = P->getTerminator(); if (BranchInst *BI = dyn_cast(PTI)) { if (BI->isUnconditional()) @@ -4098,8 +4100,8 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) { return SimplifyCFG(BB, TTI, DL) | true; // Scan predecessor blocks for conditional branches. - for (BasicBlock *Pred : predecessors(BB)) - if (BranchInst *PBI = dyn_cast(Pred->getTerminator())) + for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) + if (BranchInst *PBI = dyn_cast((*PI)->getTerminator())) if (PBI != BI && PBI->isConditional()) if (SimplifyCondBranchToCondBranch(PBI, BI)) return SimplifyCFG(BB, TTI, DL) | true; diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 13201bf11fe..b66c9ba4807 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2950,8 +2950,9 @@ InnerLoopVectorizer::createBlockInMask(BasicBlock *BB) { Value *Zero = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 0); VectorParts BlockMask = getVectorValue(Zero); - for (BasicBlock *Pred : predecessors(BB)) { - VectorParts EM = createEdgeMask(Pred, BB); + // For each pred: + for (pred_iterator it = pred_begin(BB), e = pred_end(BB); it != e; ++it) { + VectorParts EM = createEdgeMask(*it, BB); for (unsigned part = 0; part < UF; ++part) BlockMask[part] = Builder.CreateOr(BlockMask[part], EM[part]); } diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index a3f3b4491c5..8bd61b3c096 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -292,8 +292,8 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { if (!Blocks.count(BB) && BB->getTerminator()->getNumSuccessors()) { // Loop over all of the successors of this block, deleting any PHI nodes // that might include it. - for (BasicBlock *Succ : successors(BB)) - Succ->removePredecessor(BB); + for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) + (*SI)->removePredecessor(BB); TerminatorInst *BBTerm = BB->getTerminator(); diff --git a/tools/llvm-diff/DifferenceEngine.cpp b/tools/llvm-diff/DifferenceEngine.cpp index f8e957fa506..7d379ef5dc4 100644 --- a/tools/llvm-diff/DifferenceEngine.cpp +++ b/tools/llvm-diff/DifferenceEngine.cpp @@ -125,8 +125,8 @@ class FunctionDifferenceEngine { unsigned getUnprocPredCount(BasicBlock *Block) const { unsigned Count = 0; - for (BasicBlock *Pred : predecessors(Block)) - if (!Blocks.count(Pred)) Count++; + for (pred_iterator I = pred_begin(Block), E = pred_end(Block); I != E; ++I) + if (!Blocks.count(*I)) Count++; return Count; }