From aa2091505f6de0ababf8a6ec54e8a26c8b0be2be Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 26 Jun 2016 17:27:42 +0000 Subject: [PATCH] Apply clang-tidy's modernize-loop-convert to lib/Analysis. Only minor manual fixes. No functionality change intended. llvm-svn: 273816 --- llvm/include/llvm/Analysis/Interval.h | 10 +++-- llvm/lib/Analysis/AliasAnalysisEvaluator.cpp | 39 ++++++++++---------- llvm/lib/Analysis/AliasSetTracker.cpp | 19 +++++----- llvm/lib/Analysis/CallGraph.cpp | 18 ++++----- llvm/lib/Analysis/CallGraphSCCPass.cpp | 8 ++-- llvm/lib/Analysis/CostModel.cpp | 9 ++--- llvm/lib/Analysis/DependenceAnalysis.cpp | 16 ++++---- llvm/lib/Analysis/IVUsers.cpp | 17 ++++----- llvm/lib/Analysis/Interval.cpp | 15 +++----- llvm/lib/Analysis/IntervalPartition.cpp | 5 +-- llvm/lib/Analysis/LazyValueInfo.cpp | 4 +- llvm/lib/Analysis/LoopInfo.cpp | 9 ++--- llvm/lib/Analysis/LoopPass.cpp | 4 +- llvm/lib/Analysis/MemDepPrinter.cpp | 14 +++---- llvm/lib/Analysis/MemoryBuiltins.cpp | 4 +- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 11 +++--- llvm/lib/Analysis/RegionPrinter.cpp | 4 +- llvm/lib/Analysis/ScalarEvolution.cpp | 16 ++++---- llvm/lib/Analysis/SparsePropagation.cpp | 4 +- 19 files changed, 105 insertions(+), 121 deletions(-) diff --git a/llvm/include/llvm/Analysis/Interval.h b/llvm/include/llvm/Analysis/Interval.h index 01eba3f16c01..a904753adaab 100644 --- a/llvm/include/llvm/Analysis/Interval.h +++ b/llvm/include/llvm/Analysis/Interval.h @@ -67,8 +67,9 @@ public: /// contains - Find out if a basic block is in this interval inline bool contains(BasicBlock *BB) const { - for (unsigned i = 0; i < Nodes.size(); ++i) - if (Nodes[i] == BB) return true; + for (BasicBlock *Node : Nodes) + if (Node == BB) + return true; return false; // I don't want the dependency on //return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end(); @@ -76,8 +77,9 @@ public: /// isSuccessor - find out if a basic block is a successor of this Interval inline bool isSuccessor(BasicBlock *BB) const { - for (unsigned i = 0; i < Successors.size(); ++i) - if (Successors[i] == BB) return true; + for (BasicBlock *Successor : Successors) + if (Successor == BB) + return true; return false; // I don't want the dependency on //return find(Successors.begin(), Successors.end(), BB) != Successors.end(); diff --git a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp index 74216aab0691..baf8f3f881db 100644 --- a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp +++ b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp @@ -175,29 +175,27 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) { if (EvalAAMD) { // iterate over all pairs of load, store - for (SetVector::iterator I1 = Loads.begin(), E = Loads.end(); - I1 != E; ++I1) { - for (SetVector::iterator I2 = Stores.begin(), E2 = Stores.end(); - I2 != E2; ++I2) { - switch (AA.alias(MemoryLocation::get(cast(*I1)), - MemoryLocation::get(cast(*I2)))) { + for (Value *Load : Loads) { + for (Value *Store : Stores) { + switch (AA.alias(MemoryLocation::get(cast(Load)), + MemoryLocation::get(cast(Store)))) { case NoAlias: - PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2, + PrintLoadStoreResults("NoAlias", PrintNoAlias, Load, Store, F.getParent()); ++NoAliasCount; break; case MayAlias: - PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2, + PrintLoadStoreResults("MayAlias", PrintMayAlias, Load, Store, F.getParent()); ++MayAliasCount; break; case PartialAlias: - PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2, + PrintLoadStoreResults("PartialAlias", PrintPartialAlias, Load, Store, F.getParent()); ++PartialAliasCount; break; case MustAlias: - PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2, + PrintLoadStoreResults("MustAlias", PrintMustAlias, Load, Store, F.getParent()); ++MustAliasCount; break; @@ -237,30 +235,31 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) { } // Mod/ref alias analysis: compare all pairs of calls and values - for (auto C = CallSites.begin(), Ce = CallSites.end(); C != Ce; ++C) { - Instruction *I = C->getInstruction(); + for (CallSite C : CallSites) { + Instruction *I = C.getInstruction(); - for (SetVector::iterator V = Pointers.begin(), Ve = Pointers.end(); - V != Ve; ++V) { + for (auto Pointer : Pointers) { uint64_t Size = MemoryLocation::UnknownSize; - Type *ElTy = cast((*V)->getType())->getElementType(); + Type *ElTy = cast(Pointer->getType())->getElementType(); if (ElTy->isSized()) Size = DL.getTypeStoreSize(ElTy); - switch (AA.getModRefInfo(*C, *V, Size)) { + switch (AA.getModRefInfo(C, Pointer, Size)) { case MRI_NoModRef: - PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent()); + PrintModRefResults("NoModRef", PrintNoModRef, I, Pointer, + F.getParent()); ++NoModRefCount; break; case MRI_Mod: - PrintModRefResults("Just Mod", PrintMod, I, *V, F.getParent()); + PrintModRefResults("Just Mod", PrintMod, I, Pointer, F.getParent()); ++ModCount; break; case MRI_Ref: - PrintModRefResults("Just Ref", PrintRef, I, *V, F.getParent()); + PrintModRefResults("Just Ref", PrintRef, I, Pointer, F.getParent()); ++RefCount; break; case MRI_ModRef: - PrintModRefResults("Both ModRef", PrintModRef, I, *V, F.getParent()); + PrintModRefResults("Both ModRef", PrintModRef, I, Pointer, + F.getParent()); ++ModRefCount; break; } diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp index 4cf7641dd771..d349ac51a9b9 100644 --- a/llvm/lib/Analysis/AliasSetTracker.cpp +++ b/llvm/lib/Analysis/AliasSetTracker.cpp @@ -234,15 +234,15 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr, /// alias sets. bool AliasSetTracker::containsPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) const { - for (const_iterator I = begin(), E = end(); I != E; ++I) - if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA)) + for (const AliasSet &AS : *this) + if (!AS.Forward && AS.aliasesPointer(Ptr, Size, AAInfo, AA)) return true; return false; } bool AliasSetTracker::containsUnknown(const Instruction *Inst) const { - for (const_iterator I = begin(), E = end(); I != E; ++I) - if (!I->Forward && I->aliasesUnknownInst(Inst, AA)) + for (const AliasSet &AS : *this) + if (!AS.Forward && AS.aliasesUnknownInst(Inst, AA)) return true; return false; } @@ -409,10 +409,9 @@ void AliasSetTracker::add(const AliasSetTracker &AST) { // Loop over all of the alias sets in AST, adding the pointers contained // therein into the current alias sets. This can cause alias sets to be // merged together in the current AST. - for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) { - if (I->Forward) continue; // Ignore forwarding alias sets - - AliasSet &AS = const_cast(*I); + for (const AliasSet &AS : AST) { + if (AS.Forward) + continue; // Ignore forwarding alias sets // If there are any call sites in the alias set, add them to this AST. for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i) @@ -648,8 +647,8 @@ void AliasSet::print(raw_ostream &OS) const { void AliasSetTracker::print(raw_ostream &OS) const { OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for " << PointerMap.size() << " pointer values.\n"; - for (const_iterator I = begin(), E = end(); I != E; ++I) - I->print(OS); + for (const AliasSet &AS : *this) + AS.print(OS); OS << "\n"; } diff --git a/llvm/lib/Analysis/CallGraph.cpp b/llvm/lib/Analysis/CallGraph.cpp index 7d9252f746d8..39cb86d2ccb1 100644 --- a/llvm/lib/Analysis/CallGraph.cpp +++ b/llvm/lib/Analysis/CallGraph.cpp @@ -80,11 +80,9 @@ void CallGraph::addToCallGraph(Function *F) { Node->addCalledFunction(CallSite(), CallsExternalNode.get()); // Look for calls by this function. - for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB) - for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; - ++II) { - CallSite CS(cast(II)); - if (CS) { + for (BasicBlock &BB : *F) + for (Instruction &I : BB) { + if (auto CS = CallSite(&I)) { const Function *Callee = CS.getCalledFunction(); if (!Callee || !Intrinsic::isLeaf(Callee->getIntrinsicID())) // Indirect calls of intrinsics are not allowed so no need to check. @@ -111,8 +109,8 @@ void CallGraph::print(raw_ostream &OS) const { SmallVector Nodes; Nodes.reserve(FunctionMap.size()); - for (auto I = begin(), E = end(); I != E; ++I) - Nodes.push_back(I->second.get()); + for (const auto &I : *this) + Nodes.push_back(I.second.get()); std::sort(Nodes.begin(), Nodes.end(), [](CallGraphNode *LHS, CallGraphNode *RHS) { @@ -186,9 +184,9 @@ void CallGraphNode::print(raw_ostream &OS) const { OS << "<<" << this << ">> #uses=" << getNumReferences() << '\n'; - for (const_iterator I = begin(), E = end(); I != E; ++I) { - OS << " CS<" << I->first << "> calls "; - if (Function *FI = I->second->getFunction()) + for (const auto &I : *this) { + OS << " CS<" << I.first << "> calls "; + if (Function *FI = I.second->getFunction()) OS << "function '" << FI->getName() <<"'\n"; else OS << "external node\n"; diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp index 29c4ba980cd6..69d767354785 100644 --- a/llvm/lib/Analysis/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp @@ -261,10 +261,10 @@ bool CGPassManager::RefreshCallGraph(CallGraphSCC &CurSCC, // Loop over all of the instructions in the function, getting the callsites. // Keep track of the number of direct/indirect calls added. unsigned NumDirectAdded = 0, NumIndirectAdded = 0; - - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { - CallSite CS(cast(I)); + + for (BasicBlock &BB : *F) + for (Instruction &I : BB) { + CallSite CS(&I); if (!CS) continue; Function *Callee = CS.getCalledFunction(); if (Callee && Callee->isIntrinsic()) continue; diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp index 36a1db664e12..68a4bea96baa 100644 --- a/llvm/lib/Analysis/CostModel.cpp +++ b/llvm/lib/Analysis/CostModel.cpp @@ -522,16 +522,15 @@ void CostModelAnalysis::print(raw_ostream &OS, const Module*) const { if (!F) return; - for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) { - for (BasicBlock::iterator it = B->begin(), e = B->end(); it != e; ++it) { - Instruction *Inst = &*it; - unsigned Cost = getInstructionCost(Inst); + for (BasicBlock &B : *F) { + for (Instruction &Inst : B) { + unsigned Cost = getInstructionCost(&Inst); if (Cost != (unsigned)-1) OS << "Cost Model: Found an estimated cost of " << Cost; else OS << "Cost Model: Unknown cost"; - OS << " for instruction: "<< *Inst << "\n"; + OS << " for instruction: " << Inst << "\n"; } } } diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp index 796c872f0141..eb4d925fea73 100644 --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -781,9 +781,9 @@ void DependenceInfo::unifySubscriptType(ArrayRef Pairs) { // Go through each pair and find the widest bit to which we need // to extend all of them. - for (unsigned i = 0; i < Pairs.size(); i++) { - const SCEV *Src = Pairs[i]->Src; - const SCEV *Dst = Pairs[i]->Dst; + for (Subscript *Pair : Pairs) { + const SCEV *Src = Pair->Src; + const SCEV *Dst = Pair->Dst; IntegerType *SrcTy = dyn_cast(Src->getType()); IntegerType *DstTy = dyn_cast(Dst->getType()); if (SrcTy == nullptr || DstTy == nullptr) { @@ -806,9 +806,9 @@ void DependenceInfo::unifySubscriptType(ArrayRef Pairs) { assert(widestWidthSeen > 0); // Now extend each pair to the widest seen. - for (unsigned i = 0; i < Pairs.size(); i++) { - const SCEV *Src = Pairs[i]->Src; - const SCEV *Dst = Pairs[i]->Dst; + for (Subscript *Pair : Pairs) { + const SCEV *Src = Pair->Src; + const SCEV *Dst = Pair->Dst; IntegerType *SrcTy = dyn_cast(Src->getType()); IntegerType *DstTy = dyn_cast(Dst->getType()); if (SrcTy == nullptr || DstTy == nullptr) { @@ -819,10 +819,10 @@ void DependenceInfo::unifySubscriptType(ArrayRef Pairs) { } if (SrcTy->getBitWidth() < widestWidthSeen) // Sign-extend Src to widestType - Pairs[i]->Src = SE->getSignExtendExpr(Src, widestType); + Pair->Src = SE->getSignExtendExpr(Src, widestType); if (DstTy->getBitWidth() < widestWidthSeen) { // Sign-extend Dst to widestType - Pairs[i]->Dst = SE->getSignExtendExpr(Dst, widestType); + Pair->Dst = SE->getSignExtendExpr(Dst, widestType); } } } diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp index 2cd67f0a7898..e974cb9e7119 100644 --- a/llvm/lib/Analysis/IVUsers.cpp +++ b/llvm/lib/Analysis/IVUsers.cpp @@ -290,21 +290,18 @@ void IVUsers::print(raw_ostream &OS, const Module *M) const { } OS << ":\n"; - for (ilist::const_iterator UI = IVUses.begin(), - E = IVUses.end(); UI != E; ++UI) { + for (const IVStrideUse &IVUse : IVUses) { OS << " "; - UI->getOperandValToReplace()->printAsOperand(OS, false); - OS << " = " << *getReplacementExpr(*UI); - for (PostIncLoopSet::const_iterator - I = UI->PostIncLoops.begin(), - E = UI->PostIncLoops.end(); I != E; ++I) { + IVUse.getOperandValToReplace()->printAsOperand(OS, false); + OS << " = " << *getReplacementExpr(IVUse); + for (auto PostIncLoop : IVUse.PostIncLoops) { OS << " (post-inc with loop "; - (*I)->getHeader()->printAsOperand(OS, false); + PostIncLoop->getHeader()->printAsOperand(OS, false); OS << ")"; } OS << " in "; - if (UI->getUser()) - UI->getUser()->print(OS); + if (IVUse.getUser()) + IVUse.getUser()->print(OS); else OS << "Printing User"; OS << '\n'; diff --git a/llvm/lib/Analysis/Interval.cpp b/llvm/lib/Analysis/Interval.cpp index e3e785ffc45f..6c10d73bcb44 100644 --- a/llvm/lib/Analysis/Interval.cpp +++ b/llvm/lib/Analysis/Interval.cpp @@ -42,17 +42,14 @@ void Interval::print(raw_ostream &OS) const { << "Interval Contents:\n"; // Print out all of the basic blocks in the interval... - for (std::vector::const_iterator I = Nodes.begin(), - E = Nodes.end(); I != E; ++I) - OS << **I << "\n"; + for (const BasicBlock *Node : Nodes) + OS << *Node << "\n"; OS << "Interval Predecessors:\n"; - for (std::vector::const_iterator I = Predecessors.begin(), - E = Predecessors.end(); I != E; ++I) - OS << **I << "\n"; + for (const BasicBlock *Predecessor : Predecessors) + OS << *Predecessor << "\n"; OS << "Interval Successors:\n"; - for (std::vector::const_iterator I = Successors.begin(), - E = Successors.end(); I != E; ++I) - OS << **I << "\n"; + for (const BasicBlock *Successor : Successors) + OS << *Successor << "\n"; } diff --git a/llvm/lib/Analysis/IntervalPartition.cpp b/llvm/lib/Analysis/IntervalPartition.cpp index a0583e86d185..a4e56e0694bc 100644 --- a/llvm/lib/Analysis/IntervalPartition.cpp +++ b/llvm/lib/Analysis/IntervalPartition.cpp @@ -57,9 +57,8 @@ void IntervalPartition::addIntervalToPartition(Interval *I) { // void IntervalPartition::updatePredecessors(Interval *Int) { BasicBlock *Header = Int->getHeaderNode(); - for (Interval::succ_iterator I = Int->Successors.begin(), - E = Int->Successors.end(); I != E; ++I) - getBlockInterval(*I)->Predecessors.push_back(Header); + for (BasicBlock *Successor : Int->Successors) + getBlockInterval(Successor)->Predecessors.push_back(Header); } // IntervalPartition ctor - Build the first level interval partition for the diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 62568f298793..fe7601858355 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -563,8 +563,8 @@ void LazyValueInfoCache::eraseBlock(BasicBlock *BB) { if (ODI != OverDefinedCache.end()) OverDefinedCache.erase(ODI); - for (auto I = ValueCache.begin(), E = ValueCache.end(); I != E; ++I) - I->second.erase(BB); + for (auto &I : ValueCache) + I.second.erase(BB); } void LazyValueInfoCache::solve() { diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 2628d651d0c6..30f7ef392422 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -434,17 +434,16 @@ void UnloopUpdater::updateBlockParents() { // Perform a post order CFG traversal of all blocks within this loop, // propagating the nearest loop from sucessors to predecessors. LoopBlocksTraversal Traversal(DFS, LI); - for (LoopBlocksTraversal::POTIterator POI = Traversal.begin(), - POE = Traversal.end(); POI != POE; ++POI) { + for (BasicBlock *POI : Traversal) { - Loop *L = LI->getLoopFor(*POI); - Loop *NL = getNearestLoop(*POI, L); + Loop *L = LI->getLoopFor(POI); + Loop *NL = getNearestLoop(POI, L); if (NL != L) { // For reducible loops, NL is now an ancestor of Unloop. assert((NL != &Unloop && (!NL || NL->contains(&Unloop))) && "uninitialized successor"); - LI->changeLoopFor(*POI, NL); + LI->changeLoopFor(POI, NL); } else { // Or the current block is part of a subloop, in which case its parent diff --git a/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp index 84a5611e34d8..222345c9a980 100644 --- a/llvm/lib/Analysis/LoopPass.cpp +++ b/llvm/lib/Analysis/LoopPass.cpp @@ -109,9 +109,7 @@ void LPPassManager::cloneBasicBlockSimpleAnalysis(BasicBlock *From, /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes. void LPPassManager::deleteSimpleAnalysisValue(Value *V, Loop *L) { if (BasicBlock *BB = dyn_cast(V)) { - for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; - ++BI) { - Instruction &I = *BI; + for (Instruction &I : *BB) { deleteSimpleAnalysisValue(&I, L); } } diff --git a/llvm/lib/Analysis/MemDepPrinter.cpp b/llvm/lib/Analysis/MemDepPrinter.cpp index 9116b8255013..e7a85ae06e68 100644 --- a/llvm/lib/Analysis/MemDepPrinter.cpp +++ b/llvm/lib/Analysis/MemDepPrinter.cpp @@ -111,10 +111,9 @@ bool MemDepPrinter::runOnFunction(Function &F) { MDA.getNonLocalCallDependency(CS); DepSet &InstDeps = Deps[Inst]; - for (MemoryDependenceResults::NonLocalDepInfo::const_iterator - I = NLDI.begin(), E = NLDI.end(); I != E; ++I) { - const MemDepResult &Res = I->getResult(); - InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB())); + for (const NonLocalDepEntry &I : NLDI) { + const MemDepResult &Res = I.getResult(); + InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB())); } } else { SmallVector NLDI; @@ -123,10 +122,9 @@ bool MemDepPrinter::runOnFunction(Function &F) { MDA.getNonLocalPointerDependency(Inst, NLDI); DepSet &InstDeps = Deps[Inst]; - for (SmallVectorImpl::const_iterator - I = NLDI.begin(), E = NLDI.end(); I != E; ++I) { - const MemDepResult &Res = I->getResult(); - InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB())); + for (const NonLocalDepResult &I : NLDI) { + const MemDepResult &Res = I.getResult(); + InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB())); } } } diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index e0497cbc8018..d16b5f86af68 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -661,8 +661,8 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::compute(Value *V) { // erase everything that was computed in this iteration from the cache, so // that no dangling references are left behind. We could be a bit smarter if // we kept a dependency graph. It's probably not worth the complexity. - for (PtrSetTy::iterator I=SeenVals.begin(), E=SeenVals.end(); I != E; ++I) { - CacheMapTy::iterator CacheIt = CacheMap.find(*I); + for (const Value *SeenVal : SeenVals) { + CacheMapTy::iterator CacheIt = CacheMap.find(SeenVal); // non-computable results can be safely cached if (CacheIt != CacheMap.end() && anyKnown(CacheIt->second)) CacheMap.erase(CacheIt); diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index 7c57c0592e66..ff41581e5998 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -76,24 +76,23 @@ void ModuleSummaryIndexBuilder::computeFunctionSummary( DenseSet RefEdges; SmallPtrSet Visited; - for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) - for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; - ++I) { + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) { if (!isa(I)) ++NumInsts; - if (auto CS = ImmutableCallSite(&*I)) { + if (auto CS = ImmutableCallSite(&I)) { auto *CalledFunction = CS.getCalledFunction(); if (CalledFunction && CalledFunction->hasName() && !CalledFunction->isIntrinsic()) { - auto ScaledCount = BFI ? BFI->getBlockProfileCount(&*BB) : None; + auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None; auto *CalleeId = M->getValueSymbolTable().lookup(CalledFunction->getName()); CallGraphEdges[CalleeId] += (ScaledCount ? ScaledCount.getValue() : 0); } } - findRefEdges(&*I, RefEdges, Visited); + findRefEdges(&I, RefEdges, Visited); } GlobalValueSummary::GVFlags Flags(F); diff --git a/llvm/lib/Analysis/RegionPrinter.cpp b/llvm/lib/Analysis/RegionPrinter.cpp index acb218d5fea0..30a4e011060e 100644 --- a/llvm/lib/Analysis/RegionPrinter.cpp +++ b/llvm/lib/Analysis/RegionPrinter.cpp @@ -117,8 +117,8 @@ struct DOTGraphTraits : public DOTGraphTraits { << ((R.getDepth() * 2 % 12) + 2) << "\n"; } - for (Region::const_iterator RI = R.begin(), RE = R.end(); RI != RE; ++RI) - printRegionCluster(**RI, GW, depth + 1); + for (const auto &RI : R) + printRegionCluster(*RI, GW, depth + 1); const RegionInfo &RI = *static_cast(R.getRegionInfo()); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index c2e1825c0273..40274f77c6f4 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5485,8 +5485,8 @@ void ScalarEvolution::forgetLoop(const Loop *L) { // Forget all contained loops too, to avoid dangling entries in the // ValuesAtScopes map. - for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) - forgetLoop(*I); + for (Loop *I : *L) + forgetLoop(I); LoopHasNoAbnormalExits.erase(L); } @@ -9534,8 +9534,8 @@ bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount(const Loop *L) { static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE, const Loop *L) { // Print all inner loops first - for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) - PrintLoopInfo(OS, SE, *I); + for (Loop *I : *L) + PrintLoopInfo(OS, SE, I); OS << "Loop "; L->getHeader()->printAsOperand(OS, /*PrintType=*/false); @@ -9676,8 +9676,8 @@ void ScalarEvolution::print(raw_ostream &OS) const { OS << "Determining loop execution counts for: "; F.printAsOperand(OS, /*PrintType=*/false); OS << "\n"; - for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) - PrintLoopInfo(OS, &SE, *I); + for (Loop *I : LI) + PrintLoopInfo(OS, &SE, I); } ScalarEvolution::LoopDisposition @@ -10429,8 +10429,8 @@ PredicatedScalarEvolution::PredicatedScalarEvolution( const PredicatedScalarEvolution &Init) : RewriteMap(Init.RewriteMap), SE(Init.SE), L(Init.L), Preds(Init.Preds), Generation(Init.Generation), BackedgeCount(Init.BackedgeCount) { - for (auto I = Init.FlagsMap.begin(), E = Init.FlagsMap.end(); I != E; ++I) - FlagsMap.insert(*I); + for (const auto &I : Init.FlagsMap) + FlagsMap.insert(I); } void PredicatedScalarEvolution::print(raw_ostream &OS, unsigned Depth) const { diff --git a/llvm/lib/Analysis/SparsePropagation.cpp b/llvm/lib/Analysis/SparsePropagation.cpp index f5a927b80525..79dc84e25533 100644 --- a/llvm/lib/Analysis/SparsePropagation.cpp +++ b/llvm/lib/Analysis/SparsePropagation.cpp @@ -320,8 +320,8 @@ void SparseSolver::Solve(Function &F) { // Notify all instructions in this basic block that they are newly // executable. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - visitInst(*I); + for (Instruction &I : *BB) + visitInst(I); } } }