Index: docs/ProgrammersManual.rst =================================================================== --- docs/ProgrammersManual.rst +++ docs/ProgrammersManual.rst @@ -1856,12 +1856,11 @@ #include "llvm/Support/CFG.h" BasicBlock *BB = ...; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *Pred = *PI; + for (BasicBlock *Pred : predecessors(BB)) { // ... } -Similarly, to iterate over successors use ``succ_iterator/succ_begin/succ_end``. +Similarly, to iterate over successors use ``successors``. .. _simplechanges: Index: include/llvm/IR/CFG.h =================================================================== --- include/llvm/IR/CFG.h +++ include/llvm/IR/CFG.h @@ -93,6 +93,12 @@ 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)); +} @@ -257,6 +263,12 @@ 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; Index: lib/Analysis/BranchProbabilityInfo.cpp =================================================================== --- lib/Analysis/BranchProbabilityInfo.cpp +++ lib/Analysis/BranchProbabilityInfo.cpp @@ -530,9 +530,8 @@ assert(LastF && "Cannot print prior to running over a function"); 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); + for (const BasicBlock *Succ : successors(BI)) { + printEdgeProbability(OS << " ", BI, Succ); } } } @@ -563,8 +562,7 @@ uint32_t MaxWeight = 0; BasicBlock *MaxSucc = nullptr; - for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) { - BasicBlock *Succ = *I; + for (BasicBlock *Succ : successors(BB)) { uint32_t Weight = getEdgeWeight(BB, Succ); uint32_t PrevSum = Sum; Index: lib/Analysis/DominanceFrontier.cpp =================================================================== --- lib/Analysis/DominanceFrontier.cpp +++ lib/Analysis/DominanceFrontier.cpp @@ -63,11 +63,10 @@ visited.insert(currentBB); // Loop over CFG successors to calculate DFlocal[currentNode] - for (succ_iterator SI = succ_begin(currentBB), SE = succ_end(currentBB); - SI != SE; ++SI) { + for (BasicBlock *Succ : successors(currentBB)) { // Does Node immediately dominate this successor? - if (DT[*SI]->getIDom() != currentNode) - S.insert(*SI); + if (DT[Succ]->getIDom() != currentNode) + S.insert(Succ); } } Index: lib/Analysis/Interval.cpp =================================================================== --- lib/Analysis/Interval.cpp +++ lib/Analysis/Interval.cpp @@ -29,9 +29,8 @@ 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 (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode); - I != E; ++I) - if (contains(*I)) + for (BasicBlock *Pred : predecessors(HeaderNode)) + if (contains(Pred)) return true; return false; } Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -625,9 +625,9 @@ // Loop over all of our predecessors, merging what we know from them into // result. bool EdgesMissing = false; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + for (BasicBlock *Pred : predecessors(BB)) { LVILatticeVal EdgeResult; - EdgesMissing |= !getEdgeValue(Val, *PI, BB, EdgeResult); + EdgesMissing |= !getEdgeValue(Val, Pred, BB, EdgeResult); if (EdgesMissing) continue; Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -336,9 +336,8 @@ SmallVector ExitBlocks; getExitBlocks(ExitBlocks); for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) - for (pred_iterator PI = pred_begin(ExitBlocks[i]), - PE = pred_end(ExitBlocks[i]); PI != PE; ++PI) - if (!contains(*PI)) + for (BasicBlock *Pred : predecessors(ExitBlocks[i])) + if (!contains(Pred)) return false; // All the requirements are met. return true; @@ -360,12 +359,12 @@ BasicBlock *current = *BI; switchExitBlocks.clear(); - for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) { + for (BasicBlock *Succ : successors(*BI)) { // If block is inside the loop then it is not a exit block. - if (contains(*I)) + if (contains(Succ)) continue; - pred_iterator PI = pred_begin(*I); + pred_iterator PI = pred_begin(Succ); BasicBlock *firstPred = *PI; // If current basic block is this exit block's first predecessor @@ -379,17 +378,17 @@ // 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(*I); + ExitBlocks.push_back(Succ); 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(), *I) + if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), Succ) == switchExitBlocks.end()) { - switchExitBlocks.push_back(*I); - ExitBlocks.push_back(*I); + switchExitBlocks.push_back(Succ); + ExitBlocks.push_back(Succ); } } } Index: lib/Analysis/RegionInfo.cpp =================================================================== --- lib/Analysis/RegionInfo.cpp +++ lib/Analysis/RegionInfo.cpp @@ -162,13 +162,9 @@ } BasicBlock *Region::getEnteringBlock() const { - BasicBlock *entry = getEntry(); - BasicBlock *Pred; BasicBlock *enteringBlock = nullptr; - for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE; - ++PI) { - Pred = *PI; + for (BasicBlock *Pred : predecessors(getEntry())) { if (DT->getNode(Pred) && !contains(Pred)) { if (enteringBlock) return nullptr; @@ -182,15 +178,12 @@ BasicBlock *Region::getExitingBlock() const { BasicBlock *exit = getExit(); - BasicBlock *Pred; BasicBlock *exitingBlock = nullptr; if (!exit) return nullptr; - for (pred_iterator PI = pred_begin(exit), PE = pred_end(exit); PI != PE; - ++PI) { - Pred = *PI; + for (BasicBlock *Pred : predecessors(exit)) { if (contains(Pred)) { if (exitingBlock) return nullptr; @@ -236,13 +229,13 @@ BasicBlock *entry = getEntry(), *exit = getExit(); - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) - if (!contains(*SI) && exit != *SI) + for (BasicBlock *Succ : successors(BB)) + if (!contains(Succ) && exit != Succ) llvm_unreachable("Broken region found!"); if (entry != BB) - for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB); SI != SE; ++SI) - if (!contains(*SI)) + for (BasicBlock *Pred : predecessors(BB)) + if (!contains(Pred)) llvm_unreachable("Broken region found!"); } @@ -253,9 +246,9 @@ verifyBBInRegion(BB); - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) - if (*SI != exit && visited->find(*SI) == visited->end()) - verifyWalk(*SI, visited); + for (BasicBlock *Succ : successors(BB)) + if (Succ != exit && visited->find(Succ) == visited->end()) + verifyWalk(Succ, visited); } void Region::verifyRegion() const { @@ -402,9 +395,8 @@ if (NumSuccessors == 0) return nullptr; - for (pred_iterator PI = pred_begin(getExit()), PE = pred_end(getExit()); - PI != PE; ++PI) - if (!DT->dominates(getEntry(), *PI)) + for (BasicBlock *Pred : predecessors(getExit())) + if (!DT->dominates(getEntry(), Pred)) return nullptr; Region *R = RI->getRegionFor(exit); @@ -420,10 +412,9 @@ R = R->getParent(); if (!DT->dominates(getEntry(), R->getExit())) - for (pred_iterator PI = pred_begin(getExit()), PE = pred_end(getExit()); - PI != PE; ++PI) - if (!DT->dominates(R->getExit(), *PI)) - return nullptr; + for (BasicBlock *Pred : predecessors(getExit())) + if (!DT->dominates(R->getExit(), Pred)) + return nullptr; return new Region(getEntry(), R->getExit(), RI, DT); } @@ -484,11 +475,9 @@ bool RegionInfo::isCommonDomFrontier(BasicBlock *BB, BasicBlock *entry, BasicBlock *exit) const { - for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(BB)) if (DT->dominates(entry, P) && !DT->dominates(exit, P)) return false; - } return true; } @@ -783,9 +772,8 @@ && ExitR->getParent()->getEntry() == Exit) ExitR = ExitR->getParent(); - for (pred_iterator PI = pred_begin(Exit), PE = pred_end(Exit); PI != PE; - ++PI) - if (!R->contains(*PI) && !ExitR->contains(*PI)) + for (BasicBlock *Pred : predecessors(Exit)) + if (!R->contains(Pred) && !ExitR->contains(Pred)) break; // This stops infinite cycles. Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -4512,13 +4512,12 @@ // lead to the loop header. bool MustExecuteLoopHeader = true; BasicBlock *Exit = nullptr; - for (succ_iterator SI = succ_begin(ExitingBlock), SE = succ_end(ExitingBlock); - SI != SE; ++SI) - if (!L->contains(*SI)) { + for (BasicBlock *Succ : successors(ExitingBlock)) + if (!L->contains(Succ)) { if (Exit) // Multiple exit successors. return getCouldNotCompute(); - Exit = *SI; - } else if (*SI != L->getHeader()) { + Exit = Succ; + } else if (Succ != L->getHeader()) { MustExecuteLoopHeader = false; } Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -453,8 +453,8 @@ for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i) PN->addIncoming(InVal, BBPN->getIncomingBlock(i)); } else { - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - PN->addIncoming(InVal, *PI); + for (BasicBlock *Pred : predecessors(BB)) + PN->addIncoming(InVal, Pred); } } } @@ -977,11 +977,11 @@ } } else { SmallPtrSet VisitedBBs; - for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) { - if (!VisitedBBs.insert(*PI)) + for (BasicBlock *Pred : predecessors(BB)) { + if (!VisitedBBs.insert(Pred)) continue; - BasicBlock::InstListType &InstList = (*PI)->getInstList(); + BasicBlock::InstListType &InstList = Pred->getInstList(); BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin(); BasicBlock::InstListType::reverse_iterator RE = InstList.rend(); do { ++RI; } while (RI != RE && isa(&*RI)); Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1052,9 +1052,8 @@ if (OptLevel != CodeGenOpt::None) { bool AllPredsVisited = true; - for (const_pred_iterator PI = pred_begin(LLVMBB), PE = pred_end(LLVMBB); - PI != PE; ++PI) { - if (!FuncInfo->VisitedBBs.count(*PI)) { + for (const BasicBlock *Pred : predecessors(LLVMBB)) { + if (!FuncInfo->VisitedBBs.count(Pred)) { AllPredsVisited = false; break; } Index: lib/CodeGen/SjLjEHPrepare.cpp =================================================================== --- lib/CodeGen/SjLjEHPrepare.cpp +++ lib/CodeGen/SjLjEHPrepare.cpp @@ -142,8 +142,8 @@ if (!LiveBBs.insert(BB)) return; // already been here. - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - MarkBlocksLiveIn(*PI, LiveBBs); + for (BasicBlock *Pred : predecessors(BB)) + MarkBlocksLiveIn(Pred, LiveBBs); } /// substituteLPadValues - Substitute the values returned by the landingpad Index: lib/CodeGen/UnreachableBlockElim.cpp =================================================================== --- lib/CodeGen/UnreachableBlockElim.cpp +++ lib/CodeGen/UnreachableBlockElim.cpp @@ -79,8 +79,8 @@ PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); BB->getInstList().pop_front(); } - for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) - (*SI)->removePredecessor(BB); + for (BasicBlock *S : successors(BB)) + S->removePredecessor(BB); BB->dropAllReferences(); } Index: lib/IR/BasicBlock.cpp =================================================================== --- lib/IR/BasicBlock.cpp +++ lib/IR/BasicBlock.cpp @@ -321,10 +321,9 @@ // 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 (succ_iterator I = succ_begin(New), E = succ_end(New); I != E; ++I) { + for (BasicBlock *Successor : successors(New)) { // 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) { Index: lib/IR/Dominators.cpp =================================================================== --- lib/IR/Dominators.cpp +++ lib/IR/Dominators.cpp @@ -179,9 +179,7 @@ // 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_pred_iterator PI = pred_begin(End), E = pred_end(End); - PI != E; ++PI) { - const BasicBlock *BB = *PI; + for (const BasicBlock *BB : predecessors(End)) { if (BB == Start) continue; Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -2100,8 +2100,8 @@ // 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 (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { - const InvokeInst *II = dyn_cast((*I)->getTerminator()); + for (BasicBlock *Pred : predecessors(BB)) { + const InvokeInst *II = dyn_cast(Pred->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); Index: lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- lib/Transforms/IPO/ArgumentPromotion.cpp +++ lib/Transforms/IPO/ArgumentPromotion.cpp @@ -473,8 +473,7 @@ // 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 (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(BB)) { for (idf_ext_iterator > I = idf_ext_begin(P, TranspBlocks), E = idf_ext_end(P, TranspBlocks); I != E; ++I) Index: lib/Transforms/IPO/LoopExtractor.cpp =================================================================== --- lib/Transforms/IPO/LoopExtractor.cpp +++ lib/Transforms/IPO/LoopExtractor.cpp @@ -229,9 +229,7 @@ // 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 (pred_iterator - PI = pred_begin(LPad), PE = pred_end(LPad); PI != PE; ++PI) { - BasicBlock *BB = *PI; + for (BasicBlock *BB : predecessors(LPad)) { if (BB->isLandingPad() && BB != Parent && isa(Parent->getTerminator())) { Split = true; Index: lib/Transforms/IPO/PartialInlining.cpp =================================================================== --- lib/Transforms/IPO/PartialInlining.cpp +++ lib/Transforms/IPO/PartialInlining.cpp @@ -58,13 +58,12 @@ BasicBlock* returnBlock = nullptr; BasicBlock* nonReturnBlock = nullptr; unsigned returnCount = 0; - for (succ_iterator SI = succ_begin(entryBlock), SE = succ_end(entryBlock); - SI != SE; ++SI) - if (isa((*SI)->getTerminator())) { - returnBlock = *SI; + for (BasicBlock *Succ : successors(entryBlock)) + if (isa(Succ->getTerminator())) { + returnBlock = Succ; returnCount++; } else - nonReturnBlock = *SI; + nonReturnBlock = Succ; if (returnCount != 1) return nullptr; Index: lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- lib/Transforms/InstCombine/InstructionCombining.cpp +++ lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2721,8 +2721,8 @@ if (UserParent != BB) { bool UserIsSuccessor = false; // See if the user is one of our successors. - for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) - if (*SI == UserParent) { + for (BasicBlock *Succ : successors(BB)) + if (Succ == UserParent) { UserIsSuccessor = true; break; } Index: lib/Transforms/Scalar/DeadStoreElimination.cpp =================================================================== --- lib/Transforms/Scalar/DeadStoreElimination.cpp +++ lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -642,8 +642,7 @@ /// them to F. static void FindUnconditionalPreds(SmallVectorImpl &Blocks, BasicBlock *BB, DominatorTree *DT) { - for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { - BasicBlock *Pred = *I; + for (BasicBlock *Pred : predecessors(BB)) { if (Pred == BB) continue; TerminatorInst *PredTI = Pred->getTerminator(); if (PredTI->getNumSuccessors() != 1) Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -1555,9 +1555,7 @@ FullyAvailableBlocks[UnavailableBlocks[i]] = false; SmallVector CriticalEdgePred; - for (pred_iterator PI = pred_begin(LoadBB), E = pred_end(LoadBB); - PI != E; ++PI) { - BasicBlock *Pred = *PI; + for (BasicBlock *Pred : predecessors(LoadBB)) { if (IsValueFullyAvailableInBlock(Pred, FullyAvailableBlocks, 0)) { continue; } @@ -2483,9 +2481,7 @@ BasicBlock *PREPred = nullptr; predMap.clear(); - for (pred_iterator PI = pred_begin(CurrentBlock), - PE = pred_end(CurrentBlock); PI != PE; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(CurrentBlock)) { // We're not interested in PRE where the block is its // own predecessor, or in blocks with predecessors // that are not reachable. @@ -2713,14 +2709,13 @@ for (SmallVectorImpl::iterator I = Dom.begin(), E = Dom.end(); I != E; I++) { BasicBlock *B = *I; - for (succ_iterator SI = succ_begin(B), SE = succ_end(B); SI != SE; SI++) { - BasicBlock *S = *SI; + for (BasicBlock *S : successors(B)) { if (DeadBlocks.count(S)) continue; bool AllPredDead = true; - for (pred_iterator PI = pred_begin(S), PE = pred_end(S); PI != PE; PI++) - if (!DeadBlocks.count(*PI)) { + for (BasicBlock *Pred : predecessors(S)) + if (!DeadBlocks.count(Pred)) { AllPredDead = false; break; } Index: lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- lib/Transforms/Scalar/JumpThreading.cpp +++ lib/Transforms/Scalar/JumpThreading.cpp @@ -353,8 +353,8 @@ // If V is a constant, then it is known in all predecessors. if (Constant *KC = getKnownConstant(V, Preference)) { - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - Result.push_back(std::make_pair(KC, *PI)); + for (BasicBlock *Pred : predecessors(BB)) + Result.push_back(std::make_pair(KC, Pred)); return true; } @@ -377,8 +377,7 @@ // "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 (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(BB)) { // 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); @@ -532,8 +531,7 @@ cast(Cmp->getOperand(0))->getParent() != BB) { Constant *RHSCst = cast(Cmp->getOperand(1)); - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB);PI != E; ++PI){ - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(BB)) { // 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 = @@ -606,8 +604,8 @@ // 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 (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - Result.push_back(std::make_pair(KC, *PI)); + for (BasicBlock *Pred : predecessors(BB)) + Result.push_back(std::make_pair(KC, Pred)); } return !Result.empty(); @@ -899,10 +897,7 @@ // 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 (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB); - PI != PE; ++PI) { - BasicBlock *PredBB = *PI; - + for (BasicBlock *PredBB : predecessors(LoadBB)) { // If we already scanned this predecessor, skip it. if (!PredsScanned.insert(PredBB)) continue; @@ -952,9 +947,7 @@ AvailablePredSet.insert(AvailablePreds[i].first); // Add all the unavailable predecessors to the PredsToSplit list. - for (pred_iterator PI = pred_begin(LoadBB), PE = pred_end(LoadBB); - PI != PE; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(LoadBB)) { // If the predecessor is an indirect goto, we can't split the edge. if (isa(P->getTerminator())) return false; Index: lib/Transforms/Scalar/LoopInstSimplify.cpp =================================================================== --- lib/Transforms/Scalar/LoopInstSimplify.cpp +++ lib/Transforms/Scalar/LoopInstSimplify.cpp @@ -145,9 +145,7 @@ // 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 (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; - ++SI) { - BasicBlock *SuccBB = *SI; + for (BasicBlock *SuccBB : successors(BB)) { if (!Visited.insert(SuccBB)) continue; Index: lib/Transforms/Scalar/LoopUnswitch.cpp =================================================================== --- lib/Transforms/Scalar/LoopUnswitch.cpp +++ lib/Transforms/Scalar/LoopUnswitch.cpp @@ -515,9 +515,9 @@ } // Otherwise, this is an unvisited intra-loop node. Check all successors. - for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) { + for (BasicBlock *Succ : successors(BB)) { // Check to see if the successor is a trivial loop exit. - if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited)) + if (!isTrivialLoopExitBlockHelper(L, Succ, ExitBB, Visited)) return false; } @@ -861,9 +861,7 @@ PHINode *PN = PHINode::Create(LPad->getType(), 0, "", ExitSucc->getFirstInsertionPt()); - for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc); - I != E; ++I) { - BasicBlock *BB = *I; + for (BasicBlock *BB : predecessors(ExitSucc)) { LandingPadInst *LPI = BB->getLandingPadInst(); LPI->replaceAllUsesWith(PN); PN->addIncoming(LPI, BB); Index: lib/Transforms/Scalar/SampleProfile.cpp =================================================================== --- lib/Transforms/Scalar/SampleProfile.cpp +++ lib/Transforms/Scalar/SampleProfile.cpp @@ -865,8 +865,7 @@ SmallPtrSet Visited; if (!Predecessors[B1].empty()) llvm_unreachable("Found a stale predecessors list in a basic block."); - for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) { - BasicBlock *B2 = *PI; + for (BasicBlock *B2 : predecessors(B1)) { if (Visited.insert(B2)) Predecessors[B1].push_back(B2); } @@ -875,8 +874,7 @@ Visited.clear(); if (!Successors[B1].empty()) llvm_unreachable("Found a stale successors list in a basic block."); - for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) { - BasicBlock *B2 = *SI; + for (BasicBlock *B2 : successors(B1)) { if (Visited.insert(B2)) Successors[B1].push_back(B2); } Index: lib/Transforms/Scalar/Sink.cpp =================================================================== --- lib/Transforms/Scalar/Sink.cpp +++ lib/Transforms/Scalar/Sink.cpp @@ -258,10 +258,11 @@ // If no suitable postdominator was found, look at all the successors and // decide which one we should sink to, if any. - for (succ_iterator I = succ_begin(Inst->getParent()), - E = succ_end(Inst->getParent()); I != E && !SuccToSinkTo; ++I) { - if (IsAcceptableTarget(Inst, *I)) - SuccToSinkTo = *I; + for (BasicBlock *Succ : successors(Inst->getParent())) { + if (SuccToSinkTo) + break; + if (IsAcceptableTarget(Inst, Succ)) + SuccToSinkTo = Succ; } // If we couldn't find a block to sink to, ignore this instruction. Index: lib/Transforms/Scalar/StructurizeCFG.cpp =================================================================== --- lib/Transforms/Scalar/StructurizeCFG.cpp +++ lib/Transforms/Scalar/StructurizeCFG.cpp @@ -365,41 +365,39 @@ BBPredicates &Pred = Predicates[BB]; BBPredicates &LPred = LoopPreds[BB]; - for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); - PI != PE; ++PI) { - + for (BasicBlock *Predecessor : predecessors(BB)) { // Ignore it if it's a branch from outside into our region entry - if (!ParentRegion->contains(*PI)) + if (!ParentRegion->contains(Predecessor)) continue; - Region *R = RI->getRegionFor(*PI); + Region *R = RI->getRegionFor(Predecessor); if (R == ParentRegion) { // It's a top level block in our region - BranchInst *Term = cast((*PI)->getTerminator()); + BranchInst *Term = cast(Predecessor->getTerminator()); for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) { BasicBlock *Succ = Term->getSuccessor(i); if (Succ != BB) continue; - if (Visited.count(*PI)) { + if (Visited.count(Predecessor)) { // 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(*PI)) { + !Pred.count(Other) && !Pred.count(Predecessor)) { Pred[Other] = BoolFalse; - Pred[*PI] = BoolTrue; + Pred[Predecessor] = BoolTrue; continue; } } - Pred[*PI] = buildCondition(Term, i, false); + Pred[Predecessor] = buildCondition(Term, i, false); } else { // Back edge - LPred[*PI] = buildCondition(Term, i, true); + LPred[Predecessor] = buildCondition(Term, i, true); } } @@ -574,11 +572,8 @@ if (!Term) return; - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); - SI != SE; ++SI) { - - delPhiValues(BB, *SI); - } + for (BasicBlock *Succ : successors(BB)) + delPhiValues(BB, Succ); Term->eraseFromParent(); } @@ -592,10 +587,7 @@ BasicBlock *Dominator = nullptr; // Find all the edges from the sub region to the exit - for (pred_iterator I = pred_begin(OldExit), E = pred_end(OldExit); - I != E;) { - - BasicBlock *BB = *I++; + for (BasicBlock *BB : predecessors(OldExit)) { if (!SubRegion->contains(BB)) continue; Index: lib/Transforms/Scalar/TailRecursionElimination.cpp =================================================================== --- lib/Transforms/Scalar/TailRecursionElimination.cpp +++ lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -335,7 +335,7 @@ } } - for (auto *SuccBB : make_range(succ_begin(BB), succ_end(BB))) { + for (auto *SuccBB : successors(BB)) { auto &State = Visited[SuccBB]; if (State < Escaped) { State = Escaped; @@ -807,8 +807,7 @@ // predecessors and perform TRC there. Look for predecessors that end // in unconditional branch and recursive call(s). SmallVector UncondBranchPreds; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *Pred = *PI; + for (BasicBlock *Pred : predecessors(BB)) { TerminatorInst *PTI = Pred->getTerminator(); if (BranchInst *BI = dyn_cast(PTI)) if (BI->isUnconditional()) Index: lib/Transforms/Utils/BasicBlockUtils.cpp =================================================================== --- lib/Transforms/Utils/BasicBlockUtils.cpp +++ lib/Transforms/Utils/BasicBlockUtils.cpp @@ -549,14 +549,11 @@ // Move the remaining edges from OrigBB to point to NewBB2. SmallVector NewBB2Preds; - for (pred_iterator i = pred_begin(OrigBB), e = pred_end(OrigBB); - i != e; ) { - BasicBlock *Pred = *i++; + for (BasicBlock *Pred : predecessors(OrigBB)) { 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; Index: lib/Transforms/Utils/BreakCriticalEdges.cpp =================================================================== --- lib/Transforms/Utils/BreakCriticalEdges.cpp +++ lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -233,9 +233,7 @@ if (PN->getIncomingBlock(i) != NewBB) OtherPreds.push_back(PN->getIncomingBlock(i)); } else { - for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); - I != E; ++I) { - BasicBlock *P = *I; + for (BasicBlock *P : predecessors(DestBB)) { if (P != NewBB) OtherPreds.push_back(P); } @@ -321,9 +319,7 @@ // the predecessor must be directly in TIL, not in a subloop, or again // LoopSimplify doesn't hold. SmallVector LoopPreds; - for (pred_iterator I = pred_begin(DestBB), E = pred_end(DestBB); I != E; - ++I) { - BasicBlock *P = *I; + for (BasicBlock *P : predecessors(DestBB)) { if (P == NewBB) continue; // The new block is known. if (LI->getLoopFor(P) != TIL) { Index: lib/Transforms/Utils/CloneFunction.cpp =================================================================== --- lib/Transforms/Utils/CloneFunction.cpp +++ lib/Transforms/Utils/CloneFunction.cpp @@ -514,9 +514,8 @@ assert(NumPreds < PN->getNumIncomingValues()); // Count how many times each predecessor comes to this block. std::map PredCount; - for (pred_iterator PI = pred_begin(NewBB), E = pred_end(NewBB); - PI != E; ++PI) - --PredCount[*PI]; + for (BasicBlock *Pred : predecessors(NewBB)) + --PredCount[Pred]; // Figure out how many entries to remove from each PHI. for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) Index: lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- lib/Transforms/Utils/CodeExtractor.cpp +++ lib/Transforms/Utils/CodeExtractor.cpp @@ -91,9 +91,8 @@ for (SetVector::iterator I = std::next(Result.begin()), E = Result.end(); I != E; ++I) - for (pred_iterator PI = pred_begin(*I), PE = pred_end(*I); - PI != PE; ++PI) - assert(Result.count(*PI) && + for (BasicBlock *Pred : predecessors(*I)) + assert(Result.count(Pred) && "No blocks in this region may have entries from outside the region" " except for the first block!"); #endif @@ -721,9 +720,9 @@ SmallPtrSet ExitBlocks; for (SetVector::iterator I = Blocks.begin(), E = Blocks.end(); I != E; ++I) - for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) - if (!Blocks.count(*SI)) - ExitBlocks.insert(*SI); + for (BasicBlock *Succ : successors(*I)) + if (!Blocks.count(Succ)) + ExitBlocks.insert(Succ); NumExitBlocks = ExitBlocks.size(); // Construct new function based on inputs/outputs & add allocas for all defs. Index: lib/Transforms/Utils/Local.cpp =================================================================== --- lib/Transforms/Utils/Local.cpp +++ lib/Transforms/Utils/Local.cpp @@ -1129,8 +1129,8 @@ BasicBlock *BB = I->getParent(); // Loop over all of the successors, removing BB's entry from any PHI // nodes. - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) - (*SI)->removePredecessor(BB); + for (BasicBlock *Succ : successors(BB)) + Succ->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 @@ } Changed |= ConstantFoldTerminator(BB, true); - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) - if (Reachable.insert(*SI)) - Worklist.push_back(*SI); + for (BasicBlock *Succ : successors(BB)) + if (Reachable.insert(Succ)) + Worklist.push_back(Succ); } while (!Worklist.empty()); return Changed; } @@ -1263,9 +1263,9 @@ if (Reachable.count(BB)) continue; - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) - if (Reachable.count(*SI)) - (*SI)->removePredecessor(BB); + for (BasicBlock *Succ : successors(BB)) + if (Reachable.count(Succ)) + Succ->removePredecessor(BB); BB->dropAllReferences(); } Index: lib/Transforms/Utils/LoopSimplify.cpp =================================================================== --- lib/Transforms/Utils/LoopSimplify.cpp +++ lib/Transforms/Utils/LoopSimplify.cpp @@ -114,9 +114,7 @@ // Compute the set of predecessors of the loop that are not in the loop. SmallVector OutsideBlocks; - for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header); - PI != PE; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(Header)) { 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 @@ -158,8 +156,7 @@ /// the loop. static BasicBlock *rewriteLoopExitBlock(Loop *L, BasicBlock *Exit, Pass *PP) { SmallVector LoopBlocks; - for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I) { - BasicBlock *P = *I; + for (BasicBlock *P : predecessors(Exit)) { if (L->contains(P)) { // Don't do this if the loop is exited via an indirect branch. if (isa(P->getTerminator())) return nullptr; @@ -199,10 +196,8 @@ 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 (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) { - BasicBlock *WBB = *I; + for (BasicBlock *WBB : predecessors(BB)) Worklist.push_back(WBB); - } } while (!Worklist.empty()); } @@ -316,8 +311,7 @@ // Determine which blocks should stay in L and which should be moved out to // the Outer loop now. std::set BlocksInL; - for (pred_iterator PI=pred_begin(Header), E = pred_end(Header); PI!=E; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(Header)) { if (DT->dominates(Header, P)) addBlockAndPredsToSet(P, Header, BlocksInL); } @@ -371,9 +365,7 @@ // Figure out which basic blocks contain back-edges to the loop header. std::vector BackedgeBlocks; - for (pred_iterator I = pred_begin(Header), E = pred_end(Header); I != E; ++I){ - BasicBlock *P = *I; - + for (BasicBlock *P : predecessors(Header)) { // Indirectbr edges cannot be split, so we must fail if we find one. if (isa(P->getTerminator())) return nullptr; @@ -488,9 +480,7 @@ if (*BB == L->getHeader()) continue; SmallPtrSet BadPreds; - for (pred_iterator PI = pred_begin(*BB), - PE = pred_end(*BB); PI != PE; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(*BB)) { if (!L->contains(P)) BadPreds.insert(P); } @@ -503,8 +493,8 @@ << (*I)->getName() << "\n"); // Inform each successor of each dead pred. - for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) - (*SI)->removePredecessor(*I); + for (BasicBlock *Succ : successors(*I)) + Succ->removePredecessor(*I); // Zap the dead pred's terminator and replace it with unreachable. TerminatorInst *TI = (*I)->getTerminator(); TI->replaceAllUsesWith(UndefValue::get(TI->getType())); @@ -561,11 +551,10 @@ for (SmallSetVector::iterator I = ExitBlockSet.begin(), E = ExitBlockSet.end(); I != E; ++I) { BasicBlock *ExitBlock = *I; - for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); - PI != PE; ++PI) + for (BasicBlock *Pred : predecessors(ExitBlock)) // Must be exactly this loop: no subloops, parent loops, or non-loop preds // allowed. - if (!L->contains(*PI)) { + if (!L->contains(Pred)) { if (rewriteLoopExitBlock(L, ExitBlock, PP)) { ++NumInserted; Changed = true; Index: lib/Transforms/Utils/LoopUnroll.cpp =================================================================== --- lib/Transforms/Utils/LoopUnroll.cpp +++ lib/Transforms/Utils/LoopUnroll.cpp @@ -328,11 +328,10 @@ L->addBasicBlockToLoop(New, LI->getBase()); // Add phi entries for newly created values to all exit blocks. - for (succ_iterator SI = succ_begin(*BB), SE = succ_end(*BB); - SI != SE; ++SI) { - if (L->contains(*SI)) + for (BasicBlock *Succ : successors(*BB)) { + if (L->contains(Succ)) continue; - for (BasicBlock::iterator BBI = (*SI)->begin(); + for (BasicBlock::iterator BBI = Succ->begin(); PHINode *phi = dyn_cast(BBI); ++BBI) { Value *Incoming = phi->getIncomingValueForBlock(*BB); ValueToValueMapTy::iterator It = LastValueMap.find(Incoming); @@ -414,11 +413,10 @@ // Remove phi operands at this loop exit if (Dest != LoopExit) { BasicBlock *BB = Latches[i]; - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); - SI != SE; ++SI) { - if (*SI == Headers[i]) + for (BasicBlock *Succ : successors(BB)) { + if (Succ == Headers[i]) continue; - for (BasicBlock::iterator BBI = (*SI)->begin(); + for (BasicBlock::iterator BBI = Succ->begin(); PHINode *Phi = dyn_cast(BBI); ++BBI) { Phi->removeIncomingValue(BB, false); } Index: lib/Transforms/Utils/LoopUnrollRuntime.cpp =================================================================== --- lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -66,9 +66,8 @@ // 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 (succ_iterator SBI = succ_begin(Latch), SBE = succ_end(Latch); - SBI != SBE; ++SBI) { - for (BasicBlock::iterator BBI = (*SBI)->begin(); + for (BasicBlock *Succ : successors(Latch)) { + for (BasicBlock::iterator BBI = Succ->begin(); PHINode *PN = dyn_cast(BBI); ++BBI) { // Add a new PHI node to the prolog end block and add the Index: lib/Transforms/Utils/PromoteMemoryToRegister.cpp =================================================================== --- lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -822,9 +822,7 @@ // 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 (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *P = *PI; - + for (BasicBlock *P : predecessors(BB)) { // The value is not live into a predecessor if it defines the value. if (DefBlocks.count(P)) continue; @@ -885,9 +883,8 @@ DomTreeNode *Node = Worklist.pop_back_val(); BasicBlock *BB = Node->getBlock(); - for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; - ++SI) { - DomTreeNode *SuccNode = DT.getNode(*SI); + for (BasicBlock *Succ : successors(BB)) { + DomTreeNode *SuccNode = DT.getNode(Succ); // Quickly skip all CFG edges that are also dominator tree edges instead // of catching them below. Index: lib/Transforms/Utils/SSAUpdater.cpp =================================================================== --- lib/Transforms/Utils/SSAUpdater.cpp +++ lib/Transforms/Utils/SSAUpdater.cpp @@ -110,8 +110,7 @@ } } else { bool isFirstPred = true; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *PredBB = *PI; + for (BasicBlock *PredBB : predecessors(BB)) { Value *PredVal = GetValueAtEndOfBlock(PredBB); PredValues.push_back(std::make_pair(PredBB, PredVal)); @@ -248,8 +247,7 @@ for (unsigned PI = 0, E = SomePhi->getNumIncomingValues(); PI != E; ++PI) Preds->push_back(SomePhi->getIncomingBlock(PI)); } else { - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - Preds->push_back(*PI); + Preds->insert(Preds->end(), pred_begin(BB), pred_end(BB)); } } Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -130,9 +130,9 @@ BasicBlock *SI2BB = SI2->getParent(); SmallPtrSet SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); - for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) - if (SI1Succs.count(*I)) - for (BasicBlock::iterator BBI = (*I)->begin(); + for (BasicBlock *Succ : successors(SI2BB)) + if (SI1Succs.count(Succ)) + for (BasicBlock::iterator BBI = Succ->begin(); isa(BBI); ++BBI) { PHINode *PN = cast(BBI); if (PN->getIncomingValueForBlock(SI1BB) != @@ -171,9 +171,9 @@ BasicBlock *SI1BB = SI1->getParent(); BasicBlock *SI2BB = SI2->getParent(); SmallPtrSet SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); - for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) - if (SI1Succs.count(*I)) - for (BasicBlock::iterator BBI = (*I)->begin(); + for (BasicBlock *Succ : successors(SI2BB)) + if (SI1Succs.count(Succ)) + for (BasicBlock::iterator BBI = Succ->begin(); isa(BBI); ++BBI) { PHINode *PN = cast(BBI); if (PN->getIncomingValueForBlock(SI1BB) != Cond || @@ -683,9 +683,9 @@ // Remove PHI node entries for dead edges. BasicBlock *CheckEdge = TheRealDest; - for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI) - if (*SI != CheckEdge) - (*SI)->removePredecessor(TIBB); + for (BasicBlock *Succ : successors(TIBB)) + if (Succ != CheckEdge) + Succ->removePredecessor(TIBB); else CheckEdge = nullptr; @@ -981,9 +981,9 @@ // to put the select in this case. static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2, Instruction *I1, Instruction *I2) { - for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { + for (BasicBlock *Succ : successors(BB1)) { PHINode *PN; - for (BasicBlock::iterator BBI = SI->begin(); + for (BasicBlock::iterator BBI = Succ->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1063,9 +1063,9 @@ if (isa(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2)) return Changed; - for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { + for (BasicBlock *Succ : successors(BB1)) { PHINode *PN; - for (BasicBlock::iterator BBI = SI->begin(); + for (BasicBlock::iterator BBI = Succ->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1094,9 +1094,9 @@ // 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 (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) { + for (BasicBlock *Succ : successors(BB1)) { PHINode *PN; - for (BasicBlock::iterator BBI = SI->begin(); + for (BasicBlock::iterator BBI = Succ->begin(); (PN = dyn_cast(BBI)); ++BBI) { Value *BB1V = PN->getIncomingValueForBlock(BB1); Value *BB2V = PN->getIncomingValueForBlock(BB2); @@ -1118,8 +1118,8 @@ } // Update any PHI nodes in our new successors. - for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) - AddPredecessorToBlock(*SI, BIParent, BB1); + for (BasicBlock *Succ : successors(BB1)) + AddPredecessorToBlock(Succ, BIParent, BB1); EraseTerminatorInstAndDCECond(BI); return true; @@ -2051,8 +2051,7 @@ if (TrueDest == BB || FalseDest == BB) return false; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *PredBlock = *PI; + for (BasicBlock *PredBlock : predecessors(BB)) { BranchInst *PBI = dyn_cast(PredBlock->getTerminator()); // Check that we have two conditional branches. If there is a PHI node in @@ -2885,8 +2884,8 @@ // Turn all invokes that unwind here into calls and delete the basic block. bool InvokeRequiresTableEntry = false; bool Changed = false; - for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) { - InvokeInst *II = cast((*PI++)->getTerminator()); + for (BasicBlock *Pred : predecessors(BB)) { + InvokeInst *II = cast(Pred->getTerminator()); if (II->hasFnAttr(Attribute::UWTable)) { // Don't remove an `invoke' instruction if the ABI requires an entry into @@ -2933,8 +2932,7 @@ // Find predecessors that end with branches. SmallVector UncondBranchPreds; SmallVector CondBranchPreds; - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { - BasicBlock *P = *PI; + for (BasicBlock *P : predecessors(BB)) { TerminatorInst *PTI = P->getTerminator(); if (BranchInst *BI = dyn_cast(PTI)) { if (BI->isUnconditional()) @@ -4100,8 +4098,8 @@ return SimplifyCFG(BB, TTI, DL) | true; // Scan predecessor blocks for conditional branches. - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - if (BranchInst *PBI = dyn_cast((*PI)->getTerminator())) + for (BasicBlock *Pred : predecessors(BB)) + if (BranchInst *PBI = dyn_cast(Pred->getTerminator())) if (PBI != BI && PBI->isConditional()) if (SimplifyCondBranchToCondBranch(PBI, BI)) return SimplifyCFG(BB, TTI, DL) | true; Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2889,9 +2889,8 @@ Value *Zero = ConstantInt::get(IntegerType::getInt1Ty(BB->getContext()), 0); VectorParts BlockMask = getVectorValue(Zero); - // For each pred: - for (pred_iterator it = pred_begin(BB), e = pred_end(BB); it != e; ++it) { - VectorParts EM = createEdgeMask(*it, BB); + for (BasicBlock *Pred : predecessors(BB)) { + VectorParts EM = createEdgeMask(Pred, BB); for (unsigned part = 0; part < UF; ++part) BlockMask[part] = Builder.CreateOr(BlockMask[part], EM[part]); } Index: tools/bugpoint/CrashDebugger.cpp =================================================================== --- tools/bugpoint/CrashDebugger.cpp +++ tools/bugpoint/CrashDebugger.cpp @@ -292,8 +292,8 @@ 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 (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) - (*SI)->removePredecessor(BB); + for (BasicBlock *Succ : successors(BB)) + Succ->removePredecessor(BB); TerminatorInst *BBTerm = BB->getTerminator(); Index: tools/llvm-diff/DifferenceEngine.cpp =================================================================== --- tools/llvm-diff/DifferenceEngine.cpp +++ tools/llvm-diff/DifferenceEngine.cpp @@ -125,8 +125,8 @@ unsigned getUnprocPredCount(BasicBlock *Block) const { unsigned Count = 0; - for (pred_iterator I = pred_begin(Block), E = pred_end(Block); I != E; ++I) - if (!Blocks.count(*I)) Count++; + for (BasicBlock *Pred : predecessors(Block)) + if (!Blocks.count(Pred)) Count++; return Count; }