diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
21 files changed, 124 insertions, 159 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index ca0e62c2e14..9085f07ee21 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -393,9 +393,9 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) { bool FnChanged = false; - for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) { + for (BasicBlock &BB : F) { bool BBChanged = false; - for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ) { + for (BasicBlock::iterator BI = BB.begin(), BE = BB.end(); BI != BE;) { Instruction *II = &*BI++; switch (II->getOpcode()) { case Instruction::Select: @@ -422,7 +422,7 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) { } } - Instruction *Term = FI->getTerminator(); + Instruction *Term = BB.getTerminator(); switch (Term->getOpcode()) { case Instruction::Switch: BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI); diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 22d08e03674..595a556b505 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -693,9 +693,8 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, // Stores to stack values are valid candidates for removal. bool AllDead = true; - for (SmallVectorImpl<Value *>::iterator I = Pointers.begin(), - E = Pointers.end(); I != E; ++I) - if (!DeadStackObjects.count(*I)) { + for (Value *Pointer : Pointers) + if (!DeadStackObjects.count(Pointer)) { AllDead = false; break; } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index de1691d5052..321fc7b8074 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -901,8 +901,8 @@ bool llvm::promoteLoopAccessesToScalars( // cannot (yet) promote a memory location that is loaded and stored in // different sizes. While we are at it, collect alignment and AA info. bool Changed = false; - for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI) { - Value *ASIV = ASI->getValue(); + for (const auto &ASI : AS) { + Value *ASIV = ASI.getValue(); PointerMustAliases.insert(ASIV); // Check that all of the pointers in the alias set have the same type. We diff --git a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp index 0c5325405d8..66b59d27dfd 100644 --- a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp @@ -166,8 +166,8 @@ bool LoopDataPrefetch::runOnFunction(Function &F) { bool MadeChange = false; - for (auto I = LI->begin(), IE = LI->end(); I != IE; ++I) - for (auto L = df_begin(*I), LE = df_end(*I); L != LE; ++L) + for (Loop *I : *LI) + for (auto L = df_begin(I), LE = df_end(I); L != LE; ++L) MadeChange |= runOnLoop(*L); return MadeChange; @@ -253,10 +253,8 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { // is known to be within one cache line of some other load that has // already been prefetched, then don't prefetch this one as well. bool DupPref = false; - for (SmallVector<std::pair<Instruction *, const SCEVAddRecExpr *>, - 16>::iterator K = PrefLoads.begin(), KE = PrefLoads.end(); - K != KE; ++K) { - const SCEV *PtrDiff = SE->getMinusSCEV(LSCEVAddRec, K->second); + for (const auto &PrefLoad : PrefLoads) { + const SCEV *PtrDiff = SE->getMinusSCEV(LSCEVAddRec, PrefLoad.second); if (const SCEVConstant *ConstPtrDiff = dyn_cast<SCEVConstant>(PtrDiff)) { int64_t PD = std::abs(ConstPtrDiff->getValue()->getSExtValue()); diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp index 2e07f343681..daf0eb9dc2c 100644 --- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp @@ -115,9 +115,8 @@ bool LoopDeletion::isLoopDead(Loop *L, ScalarEvolution &SE, // information to identify readonly and readnone calls. for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end(); LI != LE; ++LI) { - for (BasicBlock::iterator BI = (*LI)->begin(), BE = (*LI)->end(); - BI != BE; ++BI) { - if (BI->mayHaveSideEffects()) + for (Instruction &I : **LI) { + if (I.mayHaveSideEffects()) return false; } } @@ -217,9 +216,8 @@ bool LoopDeletion::runOnLoop(Loop *L, LPPassManager &) { // Move all of the block's children to be children of the preheader, which // allows us to remove the domtree entry for the block. ChildNodes.insert(ChildNodes.begin(), DT[*LI]->begin(), DT[*LI]->end()); - for (SmallVectorImpl<DomTreeNode *>::iterator DI = ChildNodes.begin(), - DE = ChildNodes.end(); DI != DE; ++DI) { - DT.changeImmediateDominator(*DI, DT[preheader]); + for (DomTreeNode *ChildNode : ChildNodes) { + DT.changeImmediateDominator(ChildNode, DT[preheader]); } ChildNodes.clear(); diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 17985e06a6b..a226865262e 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -666,9 +666,9 @@ mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L, for (Loop::block_iterator BI = L->block_begin(), E = L->block_end(); BI != E; ++BI) - for (BasicBlock::iterator I = (*BI)->begin(), E = (*BI)->end(); I != E; ++I) - if (IgnoredStores.count(&*I) == 0 && - (AA.getModRefInfo(&*I, StoreLoc) & Access)) + for (Instruction &I : **BI) + if (IgnoredStores.count(&I) == 0 && + (AA.getModRefInfo(&I, StoreLoc) & Access)) return true; return false; diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index 2f50e2dd77f..9241ec36527 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -471,8 +471,7 @@ struct LoopInterchange : public FunctionPass { } bool isComputableLoopNest(LoopVector LoopList) { - for (auto I = LoopList.begin(), E = LoopList.end(); I != E; ++I) { - Loop *L = *I; + for (Loop *L : LoopList) { const SCEV *ExitCountOuter = SE->getBackedgeTakenCount(L); if (ExitCountOuter == SE->getCouldNotCompute()) { DEBUG(dbgs() << "Couldn't compute Backedge count\n"); @@ -901,8 +900,7 @@ int LoopInterchangeProfitability::getInstrOrderCost() { BadOrder = GoodOrder = 0; for (auto BI = InnerLoop->block_begin(), BE = InnerLoop->block_end(); BI != BE; ++BI) { - for (auto I = (*BI)->begin(), E = (*BI)->end(); I != E; ++I) { - const Instruction &Ins = *I; + for (Instruction &Ins : **BI) { if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&Ins)) { unsigned NumOp = GEP->getNumOperands(); bool FoundInnerInduction = false; @@ -1093,8 +1091,7 @@ void LoopInterchangeTransform::splitInnerLoopHeader() { PHI->replaceAllUsesWith(V); PHIVec.push_back((PHI)); } - for (auto I = PHIVec.begin(), E = PHIVec.end(); I != E; ++I) { - PHINode *P = *I; + for (PHINode *P : PHIVec) { P->eraseFromParent(); } } else { @@ -1211,8 +1208,7 @@ bool LoopInterchangeTransform::adjustLoopBranches() { PHINode *LcssaPhi = cast<PHINode>(I); LcssaVec.push_back(LcssaPhi); } - for (auto I = LcssaVec.begin(), E = LcssaVec.end(); I != E; ++I) { - PHINode *P = *I; + for (PHINode *P : LcssaVec) { Value *Incoming = P->getIncomingValueForBlock(InnerLoopLatch); P->replaceAllUsesWith(Incoming); P->eraseFromParent(); diff --git a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp index 2c08ee68871..d2f1b66076a 100644 --- a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp @@ -735,9 +735,8 @@ void LoopReroll::DAGRootTracker::collectInLoopUserSet( const SmallInstructionSet &Exclude, const SmallInstructionSet &Final, DenseSet<Instruction *> &Users) { - for (SmallInstructionVector::const_iterator I = Roots.begin(), - IE = Roots.end(); I != IE; ++I) - collectInLoopUserSet(*I, Exclude, Final, Users); + for (Instruction *Root : Roots) + collectInLoopUserSet(Root, Exclude, Final, Users); } static bool isSimpleLoadStore(Instruction *I) { @@ -1562,9 +1561,7 @@ void LoopReroll::DAGRootTracker::replaceIV(Instruction *Inst, // entries must appear in order. bool LoopReroll::ReductionTracker::validateSelected() { // For a non-associative reduction, the chain entries must appear in order. - for (DenseSet<int>::iterator RI = Reds.begin(), RIE = Reds.end(); - RI != RIE; ++RI) { - int i = *RI; + for (int i : Reds) { int PrevIter = 0, BaseCount = 0, Count = 0; for (Instruction *J : PossibleReds[i]) { // Note that all instructions in the chain must have been found because @@ -1608,9 +1605,7 @@ bool LoopReroll::ReductionTracker::validateSelected() { void LoopReroll::ReductionTracker::replaceSelected() { // Fixup reductions to refer to the last instruction associated with the // first iteration (not the last). - for (DenseSet<int>::iterator RI = Reds.begin(), RIE = Reds.end(); - RI != RIE; ++RI) { - int i = *RI; + for (int i : Reds) { int j = 0; for (int e = PossibleReds[i].size(); j != e; ++j) if (PossibleRedIter[PossibleReds[i][j]] != 0) { @@ -1624,9 +1619,8 @@ void LoopReroll::ReductionTracker::replaceSelected() { Users.push_back(cast<Instruction>(U)); } - for (SmallInstructionVector::iterator J = Users.begin(), - JE = Users.end(); J != JE; ++J) - (*J)->replaceUsesOfWith(PossibleReds[i].getReducedValue(), + for (Instruction *User : Users) + User->replaceUsesOfWith(PossibleReds[i].getReducedValue(), PossibleReds[i][j]); } } @@ -1745,9 +1739,8 @@ bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) { // For each possible IV, collect the associated possible set of 'root' nodes // (i+1, i+2, etc.). - for (SmallInstructionVector::iterator I = PossibleIVs.begin(), - IE = PossibleIVs.end(); I != IE; ++I) - if (reroll(*I, L, Header, IterCount, Reductions)) { + for (Instruction *PossibleIV : PossibleIVs) + if (reroll(PossibleIV, L, Header, IterCount, Reductions)) { Changed = true; break; } diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp index 46db8f1210b..549248fbf73 100644 --- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp +++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp @@ -397,18 +397,17 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) { // be split. SmallVector<BasicBlock *, 4> ExitPreds(pred_begin(Exit), pred_end(Exit)); bool SplitLatchEdge = false; - for (SmallVectorImpl<BasicBlock *>::iterator PI = ExitPreds.begin(), - PE = ExitPreds.end(); - PI != PE; ++PI) { + for (BasicBlock *ExitPred : ExitPreds) { // We only need to split loop exit edges. - Loop *PredLoop = LI->getLoopFor(*PI); + Loop *PredLoop = LI->getLoopFor(ExitPred); if (!PredLoop || PredLoop->contains(Exit)) continue; - if (isa<IndirectBrInst>((*PI)->getTerminator())) + if (isa<IndirectBrInst>(ExitPred->getTerminator())) continue; - SplitLatchEdge |= L->getLoopLatch() == *PI; + SplitLatchEdge |= L->getLoopLatch() == ExitPred; BasicBlock *ExitSplit = SplitCriticalEdge( - *PI, Exit, CriticalEdgeSplittingOptions(DT, LI).setPreserveLCSSA()); + ExitPred, Exit, + CriticalEdgeSplittingOptions(DT, LI).setPreserveLCSSA()); ExitSplit->moveBefore(Exit); } assert(SplitLatchEdge && diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 0b128a16183..71980e85e8c 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -685,8 +685,8 @@ static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB, // Okay, everything after this looks good, check to make sure that this block // doesn't include any side effects. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (I->mayHaveSideEffects()) + for (Instruction &I : *BB) + if (I.mayHaveSideEffects()) return false; return true; @@ -736,8 +736,8 @@ static Loop *CloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, New.addBasicBlockToLoop(cast<BasicBlock>(VM[*I]), *LI); // Add all of the subloops to the new loop. - for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) - CloneLoop(*I, &New, VM, LI, LPM); + for (Loop *I : *L) + CloneLoop(I, &New, VM, LI, LPM); return &New; } @@ -1132,9 +1132,8 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, // Rewrite the code to refer to itself. for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i) - for (BasicBlock::iterator I = NewBlocks[i]->begin(), - E = NewBlocks[i]->end(); I != E; ++I) - RemapInstruction(&*I, VMap, + for (Instruction &I : *NewBlocks[i]) + RemapInstruction(&I, VMap, RF_NoModuleLevelChanges | RF_IgnoreMissingLocals); // Rewrite the original preheader to select between versions of the loop. @@ -1237,9 +1236,8 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, Worklist.push_back(UI); } - for (std::vector<Instruction*>::iterator UI = Worklist.begin(), - UE = Worklist.end(); UI != UE; ++UI) - (*UI)->replaceUsesOfWith(LIC, Replacement); + for (Instruction *UI : Worklist) + UI->replaceUsesOfWith(LIC, Replacement); SimplifyCode(Worklist, L); return; diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 76b9f55ad0c..d64c658f843 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1334,8 +1334,8 @@ bool MemCpyOptPass::iterateOnFunction(Function &F) { bool MadeChange = false; // Walk all instruction in the function. - for (Function::iterator BB = F.begin(), BBE = F.end(); BB != BBE; ++BB) { - for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) { + for (BasicBlock &BB : F) { + for (BasicBlock::iterator BI = BB.begin(), BE = BB.end(); BI != BE;) { // Avoid invalidating the iterator. Instruction *I = &*BI++; @@ -1357,7 +1357,8 @@ bool MemCpyOptPass::iterateOnFunction(Function &F) { // Reprocess the instruction if desired. if (RepeatInstruction) { - if (BI != BB->begin()) --BI; + if (BI != BB.begin()) + --BI; MadeChange = true; } } diff --git a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp index 029178388b7..e47b636348e 100644 --- a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp +++ b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp @@ -122,8 +122,8 @@ struct PlaceBackedgeSafepointsImpl : public FunctionPass { bool runOnLoop(Loop *); void runOnLoopAndSubLoops(Loop *L) { // Visit all the subloops - for (auto I = L->begin(), E = L->end(); I != E; I++) - runOnLoopAndSubLoops(*I); + for (Loop *I : *L) + runOnLoopAndSubLoops(I); runOnLoop(L); } @@ -131,8 +131,8 @@ struct PlaceBackedgeSafepointsImpl : public FunctionPass { SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); - for (auto I = LI->begin(), E = LI->end(); I != E; I++) { - runOnLoopAndSubLoops(*I); + for (Loop *I : *LI) { + runOnLoopAndSubLoops(I); } return false; } diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index 8e7eaf844c6..b09ed246387 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -155,17 +155,15 @@ void ReassociatePass::BuildRankMap( DEBUG(dbgs() << "Calculated Rank[" << I->getName() << "] = " << i << "\n"); } - for (ReversePostOrderTraversal<Function*>::rpo_iterator I = RPOT.begin(), - E = RPOT.end(); I != E; ++I) { - BasicBlock *BB = *I; + for (BasicBlock *BB : RPOT) { unsigned BBRank = RankMap[BB] = ++i << 16; // Walk the basic block, adding precomputed ranks for any instructions that // we cannot move. This ensures that the ranks for these instructions are // all different in the block. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (mayBeMemoryDependent(*I)) - ValueRankMap[&*I] = ++BBRank; + for (Instruction &I : *BB) + if (mayBeMemoryDependent(I)) + ValueRankMap[&I] = ++BBRank; } } diff --git a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp index 5ee2070d86c..615029dd161 100644 --- a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp +++ b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp @@ -89,10 +89,9 @@ bool RegToMem::runOnFunction(Function &F) { // Find the escaped instructions. But don't create stack slots for // allocas in entry block. std::list<Instruction*> WorkList; - for (Function::iterator ibb = F.begin(), ibe = F.end(); - ibb != ibe; ++ibb) - for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->end(); - iib != iie; ++iib) { + for (BasicBlock &ibb : F) + for (BasicBlock::iterator iib = ibb.begin(), iie = ibb.end(); iib != iie; + ++iib) { if (!(isa<AllocaInst>(iib) && iib->getParent() == BBEntry) && valueEscapes(&*iib)) { WorkList.push_front(&*iib); @@ -101,25 +100,22 @@ bool RegToMem::runOnFunction(Function &F) { // Demote escaped instructions NumRegsDemoted += WorkList.size(); - for (std::list<Instruction*>::iterator ilb = WorkList.begin(), - ile = WorkList.end(); ilb != ile; ++ilb) - DemoteRegToStack(**ilb, false, AllocaInsertionPoint); + for (Instruction *ilb : WorkList) + DemoteRegToStack(*ilb, false, AllocaInsertionPoint); WorkList.clear(); // Find all phi's - for (Function::iterator ibb = F.begin(), ibe = F.end(); - ibb != ibe; ++ibb) - for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->end(); - iib != iie; ++iib) + for (BasicBlock &ibb : F) + for (BasicBlock::iterator iib = ibb.begin(), iie = ibb.end(); iib != iie; + ++iib) if (isa<PHINode>(iib)) WorkList.push_front(&*iib); // Demote phi nodes NumPhisDemoted += WorkList.size(); - for (std::list<Instruction*>::iterator ilb = WorkList.begin(), - ile = WorkList.end(); ilb != ile; ++ilb) - DemotePHIToStack(cast<PHINode>(*ilb), AllocaInsertionPoint); + for (Instruction *ilb : WorkList) + DemotePHIToStack(cast<PHINode>(ilb), AllocaInsertionPoint); return true; } diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index a4b8519c910..bab39a32677 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1553,9 +1553,8 @@ static void relocationViaAlloca( // record initial number of (static) allocas; we'll check we have the same // number when we get done. int InitialAllocaNum = 0; - for (auto I = F.getEntryBlock().begin(), E = F.getEntryBlock().end(); I != E; - I++) - if (isa<AllocaInst>(*I)) + for (Instruction &I : F.getEntryBlock()) + if (isa<AllocaInst>(I)) InitialAllocaNum++; #endif diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 91e625b7aac..d4c156e994c 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1277,11 +1277,11 @@ void SCCPSolver::Solve() { /// conservatively, as "(zext i8 X -> i32) & 0xFF00" must always return zero, /// even if X isn't defined. bool SCCPSolver::ResolvedUndefsIn(Function &F) { - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!BBExecutable.count(&*BB)) + for (BasicBlock &BB : F) { + if (!BBExecutable.count(&BB)) continue; - for (Instruction &I : *BB) { + for (Instruction &I : BB) { // Look for instructions which produce undef values. if (I.getType()->isVoidTy()) continue; @@ -1505,7 +1505,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // Check to see if we have a branch or switch on an undefined value. If so // we force the branch to go one way or the other to make the successor // values live. It doesn't really matter which way we force it. - TerminatorInst *TI = BB->getTerminator(); + TerminatorInst *TI = BB.getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { if (!BI->isConditional()) continue; if (!getValueState(BI->getCondition()).isUndefined()) @@ -1515,7 +1515,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // false. if (isa<UndefValue>(BI->getCondition())) { BI->setCondition(ConstantInt::getFalse(BI->getContext())); - markEdgeExecutable(&*BB, TI->getSuccessor(1)); + markEdgeExecutable(&BB, TI->getSuccessor(1)); return true; } @@ -1537,7 +1537,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // the first constant. if (isa<UndefValue>(SI->getCondition())) { SI->setCondition(SI->case_begin().getCaseValue()); - markEdgeExecutable(&*BB, SI->case_begin().getCaseSuccessor()); + markEdgeExecutable(&BB, SI->case_begin().getCaseSuccessor()); return true; } @@ -1578,12 +1578,12 @@ static bool runSCCP(Function &F, const DataLayout &DL, // delete their contents now. Note that we cannot actually delete the blocks, // as we cannot modify the CFG of the function. - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!Solver.isBlockExecutable(&*BB)) { - DEBUG(dbgs() << " BasicBlock Dead:" << *BB); + for (BasicBlock &BB : F) { + if (!Solver.isBlockExecutable(&BB)) { + DEBUG(dbgs() << " BasicBlock Dead:" << BB); ++NumDeadBlocks; - NumInstRemoved += removeAllNonTerminatorAndEHPadInstructions(&*BB); + NumInstRemoved += removeAllNonTerminatorAndEHPadInstructions(&BB); MadeChanges = true; continue; @@ -1592,7 +1592,7 @@ static bool runSCCP(Function &F, const DataLayout &DL, // Iterate over all of the instructions in a function, replacing them with // constants if we have found them to be of constant values. // - for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { + for (BasicBlock::iterator BI = BB.begin(), E = BB.end(); BI != E;) { Instruction *Inst = &*BI++; if (Inst->getType()->isVoidTy() || isa<TerminatorInst>(Inst)) continue; @@ -1760,8 +1760,8 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, DEBUG(dbgs() << "RESOLVING UNDEFS\n"); ResolvedUndefs = false; - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) - ResolvedUndefs |= Solver.ResolvedUndefsIn(*F); + for (Function &F : M) + ResolvedUndefs |= Solver.ResolvedUndefsIn(F); } bool MadeChanges = false; @@ -1771,13 +1771,13 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // SmallVector<BasicBlock*, 512> BlocksToErase; - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) { - if (F->isDeclaration()) + for (Function &F : M) { + if (F.isDeclaration()) continue; - if (Solver.isBlockExecutable(&F->front())) { - for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); - AI != E; ++AI) { + if (Solver.isBlockExecutable(&F.front())) { + for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end(); AI != E; + ++AI) { if (AI->use_empty() || AI->getType()->isStructTy()) continue; // TODO: Could use getStructLatticeValueFor to find out if the entire @@ -1797,7 +1797,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, } } - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { if (!Solver.isBlockExecutable(&*BB)) { DEBUG(dbgs() << " BasicBlock Dead:" << *BB); @@ -1807,7 +1807,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, MadeChanges = true; - if (&*BB != &F->front()) + if (&*BB != &F.front()) BlocksToErase.push_back(&*BB); continue; } @@ -1889,7 +1889,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, } // Finally, delete the basic block. - F->getBasicBlockList().erase(DeadBB); + F.getBasicBlockList().erase(DeadBB); } BlocksToErase.clear(); } @@ -1908,18 +1908,17 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // TODO: Process multiple value ret instructions also. const DenseMap<Function*, LatticeVal> &RV = Solver.getTrackedRetVals(); - for (DenseMap<Function*, LatticeVal>::const_iterator I = RV.begin(), - E = RV.end(); I != E; ++I) { - Function *F = I->first; - if (I->second.isOverdefined() || F->getReturnType()->isVoidTy()) + for (const auto &I : RV) { + Function *F = I.first; + if (I.second.isOverdefined() || F->getReturnType()->isVoidTy()) continue; // We can only do this if we know that nothing else can call the function. if (!F->hasLocalLinkage() || AddressTakenFunctions.count(F)) continue; - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) - if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) + for (BasicBlock &BB : *F) + if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator())) if (!isa<UndefValue>(RI->getOperand(0))) ReturnsToZap.push_back(RI); } diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp index 5e6df0ddf6d..15aa541de30 100644 --- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -335,12 +335,9 @@ void Scalarizer::transferMetadata(Instruction *Op, const ValueVector &CV) { Op->getAllMetadataOtherThanDebugLoc(MDs); for (unsigned I = 0, E = CV.size(); I != E; ++I) { if (Instruction *New = dyn_cast<Instruction>(CV[I])) { - for (SmallVectorImpl<std::pair<unsigned, MDNode *>>::iterator - MI = MDs.begin(), - ME = MDs.end(); - MI != ME; ++MI) - if (canTransferMetadata(MI->first)) - New->setMetadata(MI->first, MI->second); + for (const auto &MD : MDs) + if (canTransferMetadata(MD.first)) + New->setMetadata(MD.first, MD.second); if (Op->getDebugLoc() && !New->getDebugLoc()) New->setDebugLoc(Op->getDebugLoc()); } @@ -648,10 +645,9 @@ bool Scalarizer::finish() { // made to the Function. if (Gathered.empty() && Scattered.empty()) return false; - for (GatherList::iterator GMI = Gathered.begin(), GME = Gathered.end(); - GMI != GME; ++GMI) { - Instruction *Op = GMI->first; - ValueVector &CV = *GMI->second; + for (const auto &GMI : Gathered) { + Instruction *Op = GMI.first; + ValueVector &CV = *GMI.second; if (!Op->use_empty()) { // The value is still needed, so recreate it using a series of // InsertElements. diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp index 2bc0087f063..d6ae186698c 100644 --- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp +++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp @@ -590,9 +590,9 @@ Value *ConstantOffsetExtractor::rebuildWithoutConstOffset() { distributeExtsAndCloneChain(UserChain.size() - 1); // Remove all nullptrs (used to be s/zext) from UserChain. unsigned NewSize = 0; - for (auto I = UserChain.begin(), E = UserChain.end(); I != E; ++I) { - if (*I != nullptr) { - UserChain[NewSize] = *I; + for (User *I : UserChain) { + if (I != nullptr) { + UserChain[NewSize] = I; NewSize++; } } @@ -1075,8 +1075,8 @@ bool SeparateConstOffsetFromGEP::runOnFunction(Function &F) { LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); bool Changed = false; - for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B) { - for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE;) + for (BasicBlock &B : F) { + for (BasicBlock::iterator I = B.begin(), IE = B.end(); I != IE;) if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I++)) Changed |= splitGEP(GEP); // No need to split GEP ConstantExprs because all its indices are constant @@ -1162,8 +1162,8 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Function &F) { } void SeparateConstOffsetFromGEP::verifyNoDeadCode(Function &F) { - for (auto &B : F) { - for (auto &I : B) { + for (BasicBlock &B : F) { + for (Instruction &I : B) { if (isInstructionTriviallyDead(&I)) { std::string ErrMessage; raw_string_ostream RSO(ErrMessage); diff --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp index c5f29fa99dc..5fa43bda9d0 100644 --- a/llvm/lib/Transforms/Scalar/Sink.cpp +++ b/llvm/lib/Transforms/Scalar/Sink.cpp @@ -241,9 +241,8 @@ static bool iterativelySinkInstructions(Function &F, DominatorTree &DT, MadeChange = false; DEBUG(dbgs() << "Sinking iteration " << NumSinkIter << "\n"); // Process all basic blocks. - for (Function::iterator I = F.begin(), E = F.end(); - I != E; ++I) - MadeChange |= ProcessBlock(*I, DT, LI, AA); + for (BasicBlock &I : F) + MadeChange |= ProcessBlock(I, DT, LI, AA); EverMadeChange |= MadeChange; NumSinkIter++; } while (MadeChange); diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp index ff46d81cb4d..be9b6e4534c 100644 --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -594,20 +594,18 @@ void StructurizeCFG::addPhiValues(BasicBlock *From, BasicBlock *To) { /// \brief Add the real PHI value as soon as everything is set up void StructurizeCFG::setPhiValues() { SSAUpdater Updater; - for (BB2BBVecMap::iterator AI = AddedPhis.begin(), AE = AddedPhis.end(); - AI != AE; ++AI) { + for (const auto &AddedPhi : AddedPhis) { - BasicBlock *To = AI->first; - BBVector &From = AI->second; + BasicBlock *To = AddedPhi.first; + const BBVector &From = AddedPhi.second; if (!DeletedPhis.count(To)) continue; PhiMap &Map = DeletedPhis[To]; - for (PhiMap::iterator PI = Map.begin(), PE = Map.end(); - PI != PE; ++PI) { + for (const auto &PI : Map) { - PHINode *Phi = PI->first; + PHINode *Phi = PI.first; Value *Undef = UndefValue::get(Phi->getType()); Updater.Initialize(Phi->getType(), ""); Updater.AddAvailableValue(&Func->getEntryBlock(), Undef); @@ -615,22 +613,20 @@ void StructurizeCFG::setPhiValues() { NearestCommonDominator Dominator(DT); Dominator.addBlock(To, false); - for (BBValueVector::iterator VI = PI->second.begin(), - VE = PI->second.end(); VI != VE; ++VI) { + for (const auto &VI : PI.second) { - Updater.AddAvailableValue(VI->first, VI->second); - Dominator.addBlock(VI->first); + Updater.AddAvailableValue(VI.first, VI.second); + Dominator.addBlock(VI.first); } if (!Dominator.wasResultExplicitMentioned()) Updater.AddAvailableValue(Dominator.getResult(), Undef); - for (BBVector::iterator FI = From.begin(), FE = From.end(); - FI != FE; ++FI) { + for (BasicBlock *FI : From) { - int Idx = Phi->getBasicBlockIndex(*FI); + int Idx = Phi->getBasicBlockIndex(FI); assert(Idx != -1); - Phi->setIncomingValue(Idx, Updater.GetValueAtEndOfBlock(*FI)); + Phi->setIncomingValue(Idx, Updater.GetValueAtEndOfBlock(FI)); } } diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp index 0198d3adebe..4126cd67f69 100644 --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -392,8 +392,8 @@ static Value *getCommonReturnValue(ReturnInst *IgnoreRI, CallInst *CI) { Function *F = CI->getParent()->getParent(); Value *ReturnedValue = nullptr; - for (Function::iterator BBI = F->begin(), E = F->end(); BBI != E; ++BBI) { - ReturnInst *RI = dyn_cast<ReturnInst>(BBI->getTerminator()); + for (BasicBlock &BBI : *F) { + ReturnInst *RI = dyn_cast<ReturnInst>(BBI.getTerminator()); if (RI == nullptr || RI == IgnoreRI) continue; // We can only perform this transformation if the value returned is @@ -652,8 +652,8 @@ static bool eliminateRecursiveTailCall(CallInst *CI, ReturnInst *Ret, // Finally, rewrite any return instructions in the program to return the PHI // node instead of the "initval" that they do currently. This loop will // actually rewrite the return value we are destroying, but that's ok. - for (Function::iterator BBI = F->begin(), E = F->end(); BBI != E; ++BBI) - if (ReturnInst *RI = dyn_cast<ReturnInst>(BBI->getTerminator())) + for (BasicBlock &BBI : *F) + if (ReturnInst *RI = dyn_cast<ReturnInst>(BBI.getTerminator())) RI->setOperand(0, AccPN); ++NumAccumAdded; } |