diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2016-06-26 12:28:59 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2016-06-26 12:28:59 +0000 |
commit | 5288df58b7bed9c6fa88860284ab0a5c4e90ae9a (patch) | |
tree | ce60307d3834722b3febea14d7226df639c213ce | |
parent | 9aed97cfb6e157057939e180d3b4b79d1d9e4586 (diff) |
Apply clang-tidy's modernize-loop-convert to most of lib/Transforms.
Only minor manual fixes. No functionality change intended.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273808 91177308-0d34-0410-b5e6-96231b3b80d8
53 files changed, 398 insertions, 519 deletions
diff --git a/include/llvm/PassAnalysisSupport.h b/include/llvm/PassAnalysisSupport.h index 8be46e4e2ae..abd99293805 100644 --- a/include/llvm/PassAnalysisSupport.h +++ b/include/llvm/PassAnalysisSupport.h @@ -153,9 +153,9 @@ public: /// Find pass that is implementing PI. Pass *findImplPass(AnalysisID PI) { Pass *ResultPass = nullptr; - for (unsigned i = 0; i < AnalysisImpls.size() ; ++i) { - if (AnalysisImpls[i].first == PI) { - ResultPass = AnalysisImpls[i].second; + for (const auto &AnalysisImpl : AnalysisImpls) { + if (AnalysisImpl.first == PI) { + ResultPass = AnalysisImpl.second; break; } } diff --git a/include/llvm/Support/GenericDomTree.h b/include/llvm/Support/GenericDomTree.h index a74f31d5f18..77b5ba7e3e9 100644 --- a/include/llvm/Support/GenericDomTree.h +++ b/include/llvm/Support/GenericDomTree.h @@ -109,13 +109,13 @@ public: return true; SmallPtrSet<const NodeT *, 4> OtherChildren; - for (const_iterator I = Other->begin(), E = Other->end(); I != E; ++I) { - const NodeT *Nd = (*I)->getBlock(); + for (const DomTreeNodeBase *I : *Other) { + const NodeT *Nd = I->getBlock(); OtherChildren.insert(Nd); } - for (const_iterator I = begin(), E = end(); I != E; ++I) { - const NodeT *N = (*I)->getBlock(); + for (const DomTreeNodeBase *I : *this) { + const NodeT *N = I->getBlock(); if (OtherChildren.count(N) == 0) return true; } @@ -349,17 +349,14 @@ public: if (DomTreeNodes.size() != OtherDomTreeNodes.size()) return true; - for (typename DomTreeNodeMapType::const_iterator - I = this->DomTreeNodes.begin(), - E = this->DomTreeNodes.end(); - I != E; ++I) { - NodeT *BB = I->first; + for (const auto &DomTreeNode : this->DomTreeNodes) { + NodeT *BB = DomTreeNode.first; typename DomTreeNodeMapType::const_iterator OI = OtherDomTreeNodes.find(BB); if (OI == OtherDomTreeNodes.end()) return true; - DomTreeNodeBase<NodeT> &MyNd = *I->second; + DomTreeNodeBase<NodeT> &MyNd = *DomTreeNode.second; DomTreeNodeBase<NodeT> &OtherNd = *OI->second; if (MyNd.compare(&OtherNd)) diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 1599ddd2ad5..65a7f9c5af5 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -705,12 +705,11 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F, } // Add a parameter to the function for each element passed in. - for (ScalarizeTable::iterator SI = ArgIndices.begin(), - E = ArgIndices.end(); SI != E; ++SI) { + for (const auto &ArgIndex : ArgIndices) { // not allowed to dereference ->begin() if size() is 0 Params.push_back(GetElementPtrInst::getIndexedType( cast<PointerType>(I->getType()->getScalarType())->getElementType(), - SI->second)); + ArgIndex.second)); assert(Params.back()); } @@ -805,27 +804,25 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F, // Store the Value* version of the indices in here, but declare it now // for reuse. std::vector<Value*> Ops; - for (ScalarizeTable::iterator SI = ArgIndices.begin(), - E = ArgIndices.end(); SI != E; ++SI) { + for (const auto &ArgIndex : ArgIndices) { Value *V = *AI; - LoadInst *OrigLoad = OriginalLoads[std::make_pair(&*I, SI->second)]; - if (!SI->second.empty()) { - Ops.reserve(SI->second.size()); + LoadInst *OrigLoad = + OriginalLoads[std::make_pair(&*I, ArgIndex.second)]; + if (!ArgIndex.second.empty()) { + Ops.reserve(ArgIndex.second.size()); Type *ElTy = V->getType(); - for (IndicesVector::const_iterator II = SI->second.begin(), - IE = SI->second.end(); - II != IE; ++II) { + for (unsigned long II : ArgIndex.second) { // Use i32 to index structs, and i64 for others (pointers/arrays). // This satisfies GEP constraints. Type *IdxTy = (ElTy->isStructTy() ? Type::getInt32Ty(F->getContext()) : Type::getInt64Ty(F->getContext())); - Ops.push_back(ConstantInt::get(IdxTy, *II)); + Ops.push_back(ConstantInt::get(IdxTy, II)); // Keep track of the type we're currently indexing. - ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(*II); + ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(II); } // And create a GEP to extract those indices. - V = GetElementPtrInst::Create(SI->first, V, Ops, + V = GetElementPtrInst::Create(ArgIndex.first, V, Ops, V->getName() + ".idx", Call); Ops.clear(); } diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 70b0bd8ee64..c8c895b1879 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -119,9 +119,9 @@ bool DeadArgumentEliminationPass::DeleteDeadVarargs(Function &Fn) { // Okay, we know we can transform this function if safe. Scan its body // looking for calls marked musttail or calls to llvm.vastart. - for (Function::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) { - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { - CallInst *CI = dyn_cast<CallInst>(I); + for (BasicBlock &BB : Fn) { + for (Instruction &I : BB) { + CallInst *CI = dyn_cast<CallInst>(&I); if (!CI) continue; if (CI->isMustTailCall()) @@ -607,9 +607,8 @@ void DeadArgumentEliminationPass::MarkValue(const RetOrArg &RA, Liveness L, { // Note any uses of this value, so this return value can be // marked live whenever one of the uses becomes live. - for (UseVector::const_iterator UI = MaybeLiveUses.begin(), - UE = MaybeLiveUses.end(); UI != UE; ++UI) - Uses.insert(std::make_pair(*UI, RA)); + for (const auto &MaybeLiveUse : MaybeLiveUses) + Uses.insert(std::make_pair(MaybeLiveUse, RA)); break; } } @@ -982,8 +981,8 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) { // If we change the return value of the function we must rewrite any return // instructions. Check this now. if (F->getReturnType() != NF->getReturnType()) - for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB) - if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { + for (BasicBlock &BB : *NF) + if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator())) { Value *RetVal; if (NFTy->getReturnType()->isVoidTy()) { @@ -1018,7 +1017,7 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) { // Replace the return instruction with one returning the new return // value (possibly 0 if we became void). ReturnInst::Create(F->getContext(), RetVal, RI); - BB->getInstList().erase(RI); + BB.getInstList().erase(RI); } // Patch the pointer to LLVM function in debug info descriptor. diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index e1bd676373b..479fd182598 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -104,20 +104,20 @@ namespace { } // Visit the Functions. - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + for (Function &F : M) { bool Delete = - deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration(); + deleteStuff == (bool)Named.count(&F) && !F.isDeclaration(); if (!Delete) { - if (I->hasAvailableExternallyLinkage()) + if (F.hasAvailableExternallyLinkage()) continue; } - makeVisible(*I, Delete); + makeVisible(F, Delete); if (Delete) { // Make this a declaration and drop it's comdat. - I->deleteBody(); - I->setComdat(nullptr); + F.deleteBody(); + F.setComdat(nullptr); } } diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index f437235a28d..4ae9b170a3a 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -536,12 +536,9 @@ static bool addArgumentAttrs(const SCCNodeSet &SCCNodes) { // then it must be calling into another function in our SCC. Save // its particulars for Argument-SCC analysis later. ArgumentGraphNode *Node = AG[&*A]; - for (SmallVectorImpl<Argument *>::iterator - UI = Tracker.Uses.begin(), - UE = Tracker.Uses.end(); - UI != UE; ++UI) { - Node->Uses.push_back(AG[*UI]); - if (*UI != &*A) + for (Argument *Use : Tracker.Uses) { + Node->Uses.push_back(AG[Use]); + if (Use != &*A) HasNonLocalUses = true; } } @@ -606,17 +603,15 @@ static bool addArgumentAttrs(const SCCNodeSet &SCCNodes) { SmallPtrSet<Argument *, 8> ArgumentSCCNodes; // Fill ArgumentSCCNodes with the elements of the ArgumentSCC. Used for // quickly looking up whether a given Argument is in this ArgumentSCC. - for (auto I = ArgumentSCC.begin(), E = ArgumentSCC.end(); I != E; ++I) { - ArgumentSCCNodes.insert((*I)->Definition); + for (ArgumentGraphNode *I : ArgumentSCC) { + ArgumentSCCNodes.insert(I->Definition); } for (auto I = ArgumentSCC.begin(), E = ArgumentSCC.end(); I != E && !SCCCaptured; ++I) { ArgumentGraphNode *N = *I; - for (SmallVectorImpl<ArgumentGraphNode *>::iterator UI = N->Uses.begin(), - UE = N->Uses.end(); - UI != UE; ++UI) { - Argument *A = (*UI)->Definition; + for (ArgumentGraphNode *Use : N->Uses) { + Argument *A = Use->Definition; if (A->hasNoCaptureAttr() || ArgumentSCCNodes.count(A)) continue; SCCCaptured = true; @@ -682,8 +677,8 @@ static bool addArgumentAttrs(const SCCNodeSet &SCCNodes) { /// doesn't alias any other pointer visible to the caller. static bool isFunctionMallocLike(Function *F, const SCCNodeSet &SCCNodes) { SmallSetVector<Value *, 8> FlowsToReturn; - for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (ReturnInst *Ret = dyn_cast<ReturnInst>(I->getTerminator())) + for (BasicBlock &BB : *F) + if (ReturnInst *Ret = dyn_cast<ReturnInst>(BB.getTerminator())) FlowsToReturn.insert(Ret->getReturnValue()); for (unsigned i = 0; i != FlowsToReturn.size(); ++i) { @@ -1109,8 +1104,8 @@ bool PostOrderFunctionAttrsLegacyPass::runOnSCC(CallGraphSCC &SCC) { // part of the SCC. SCCNodeSet SCCNodes; bool ExternalNode = false; - for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { - Function *F = (*I)->getFunction(); + for (CallGraphNode *I : SCC) { + Function *F = I->getFunction(); if (!F || F->hasFnAttribute(Attribute::OptimizeNone)) { // External node or function we're trying not to optimize - we both avoid // transform them and avoid leveraging information they provide. diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index ded55dbb443..310c29275fa 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2174,10 +2174,8 @@ static bool EvaluateStaticConstructor(Function *F, const DataLayout &DL, DEBUG(dbgs() << "FULLY EVALUATED GLOBAL CTOR FUNCTION '" << F->getName() << "' to " << Eval.getMutatedMemory().size() << " stores.\n"); - for (DenseMap<Constant*, Constant*>::const_iterator I = - Eval.getMutatedMemory().begin(), E = Eval.getMutatedMemory().end(); - I != E; ++I) - CommitValueTo(I->second, I->first); + for (const auto &I : Eval.getMutatedMemory()) + CommitValueTo(I.second, I.first); for (GlobalVariable *GV : Eval.getInvariants()) GV->setConstant(true); } diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index b3ee499ce96..916135e33cd 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -147,8 +147,8 @@ static bool PropagateConstantReturn(Function &F) { RetVals.push_back(UndefValue::get(F.getReturnType())); unsigned NumNonConstant = 0; - 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())) { for (unsigned i = 0, e = RetVals.size(); i != e; ++i) { // Already found conflicting return values? Value *RV = RetVals[i]; @@ -266,13 +266,13 @@ bool IPCP::runOnModule(Module &M) { // making changes. while (LocalChange) { LocalChange = false; - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isDeclaration()) { + for (Function &F : M) + if (!F.isDeclaration()) { // Delete any klingons. - I->removeDeadConstantUsers(); - if (I->hasLocalLinkage()) - LocalChange |= PropagateConstantsIntoArguments(*I); - Changed |= PropagateConstantReturn(*I); + F.removeDeadConstantUsers(); + if (F.hasLocalLinkage()) + LocalChange |= PropagateConstantsIntoArguments(F); + Changed |= PropagateConstantReturn(F); } Changed |= LocalChange; } diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp index 7578e6a6d19..f898c3b5a93 100644 --- a/lib/Transforms/IPO/LoopExtractor.cpp +++ b/lib/Transforms/IPO/LoopExtractor.cpp @@ -275,15 +275,13 @@ bool BlockExtractorPass::runOnModule(Module &M) { std::string &FuncName = BlocksToNotExtractByName.back().first; std::string &BlockName = BlocksToNotExtractByName.back().second; - for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) { - Function &F = *FI; + for (Function &F : M) { if (F.getName() != FuncName) continue; - for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) { - BasicBlock &BB = *BI; + for (BasicBlock &BB : F) { if (BB.getName() != BlockName) continue; - TranslatedBlocksToNotExtract.insert(&*BI); + TranslatedBlocksToNotExtract.insert(&BB); } } @@ -293,18 +291,18 @@ bool BlockExtractorPass::runOnModule(Module &M) { // Now that we know which blocks to not extract, figure out which ones we WANT // to extract. std::vector<BasicBlock*> BlocksToExtract; - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) { - SplitLandingPadPreds(&*F); - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) - if (!TranslatedBlocksToNotExtract.count(&*BB)) - BlocksToExtract.push_back(&*BB); + for (Function &F : M) { + SplitLandingPadPreds(&F); + for (BasicBlock &BB : F) + if (!TranslatedBlocksToNotExtract.count(&BB)) + BlocksToExtract.push_back(&BB); } - for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i) { + for (BasicBlock *BlockToExtract : BlocksToExtract) { SmallVector<BasicBlock*, 2> BlocksToExtractVec; - BlocksToExtractVec.push_back(BlocksToExtract[i]); + BlocksToExtractVec.push_back(BlockToExtract); if (const InvokeInst *II = - dyn_cast<InvokeInst>(BlocksToExtract[i]->getTerminator())) + dyn_cast<InvokeInst>(BlockToExtract->getTerminator())) BlocksToExtractVec.push_back(II->getUnwindDest()); CodeExtractor(BlocksToExtractVec).extractCodeRegion(); } diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index adf0d3f680b..fe653a75ddb 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -1578,10 +1578,10 @@ bool MergeFunctions::runOnModule(Module &M) { DEBUG(dbgs() << "size of worklist: " << Worklist.size() << '\n'); // Insert functions and merge them. - for (std::vector<WeakVH>::iterator I = Worklist.begin(), - E = Worklist.end(); I != E; ++I) { - if (!*I) continue; - Function *F = cast<Function>(*I); + for (WeakVH &I : Worklist) { + if (!I) + continue; + Function *F = cast<Function>(I); if (!F->isDeclaration() && !F->hasAvailableExternallyLinkage()) { Changed |= insert(F); } diff --git a/lib/Transforms/IPO/PartialInlining.cpp b/lib/Transforms/IPO/PartialInlining.cpp index b602cf4fb58..95468c2a382 100644 --- a/lib/Transforms/IPO/PartialInlining.cpp +++ b/lib/Transforms/IPO/PartialInlining.cpp @@ -110,11 +110,10 @@ Function* PartialInliner::unswitchFunction(Function* F) { // Gather up the blocks that we're going to extract. std::vector<BasicBlock*> toExtract; toExtract.push_back(newNonReturnBlock); - for (Function::iterator FI = duplicateFunction->begin(), - FE = duplicateFunction->end(); FI != FE; ++FI) - if (&*FI != newEntryBlock && &*FI != newReturnBlock && - &*FI != newNonReturnBlock) - toExtract.push_back(&*FI); + for (BasicBlock &BB : *duplicateFunction) + if (&BB != newEntryBlock && &BB != newReturnBlock && + &BB != newNonReturnBlock) + toExtract.push_back(&BB); // The CodeExtractor needs a dominator tree. DominatorTree DT; @@ -129,11 +128,10 @@ Function* PartialInliner::unswitchFunction(Function* F) { // Inline the top-level if test into all callers. std::vector<User *> Users(duplicateFunction->user_begin(), duplicateFunction->user_end()); - for (std::vector<User*>::iterator UI = Users.begin(), UE = Users.end(); - UI != UE; ++UI) - if (CallInst *CI = dyn_cast<CallInst>(*UI)) + for (User *User : Users) + if (CallInst *CI = dyn_cast<CallInst>(User)) InlineFunction(CI, IFI); - else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) + else if (InvokeInst *II = dyn_cast<InvokeInst>(User)) InlineFunction(II, IFI); // Ditch the duplicate, since we're done with it, and rewrite all remaining @@ -152,10 +150,10 @@ bool PartialInliner::runOnModule(Module& M) { std::vector<Function*> worklist; worklist.reserve(M.size()); - for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) - if (!FI->use_empty() && !FI->isDeclaration()) - worklist.push_back(&*FI); - + for (Function &F : M) + if (!F.use_empty() && !F.isDeclaration()) + worklist.push_back(&F); + bool changed = false; while (!worklist.empty()) { Function* currFunc = worklist.back(); diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 04383f4f3fa..df56d8ddd12 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -72,13 +72,13 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC) { // Fill SCCNodes with the elements of the SCC. Used for quickly // looking up whether a given CallGraphNode is in this SCC. - for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) - SCCNodes.insert(*I); + for (CallGraphNode *I : SCC) + SCCNodes.insert(I); // First pass, scan all of the functions in the SCC, simplifying them // according to what we know. - for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) - if (Function *F = (*I)->getFunction()) + for (CallGraphNode *I : SCC) + if (Function *F = I->getFunction()) MadeChange |= SimplifyFunction(F); // Next, check to see if any callees might throw or if there are any external @@ -158,8 +158,8 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC) { // If the SCC doesn't unwind or doesn't throw, note this fact. if (!SCCMightUnwind || !SCCMightReturn) - for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { - Function *F = (*I)->getFunction(); + for (CallGraphNode *I : SCC) { + Function *F = I->getFunction(); if (!SCCMightUnwind && !F->hasFnAttribute(Attribute::NoUnwind)) { F->addFnAttr(Attribute::NoUnwind); @@ -172,11 +172,11 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC) { } } - for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { + for (CallGraphNode *I : SCC) { // Convert any invoke instructions to non-throwing functions in this node // into call instructions with a branch. This makes the exception blocks // dead. - if (Function *F = (*I)->getFunction()) + if (Function *F = I->getFunction()) MadeChange |= SimplifyFunction(F); } diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index 3202837ec30..fd250366cef 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -215,11 +215,11 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) { I->setName(""); // Internal symbols can't participate in linkage } - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { - if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0) - if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg")) - I->setName(""); // Internal symbols can't participate in linkage - StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo); + for (Function &I : M) { + if (I.hasLocalLinkage() && llvmUsedValues.count(&I) == 0) + if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg")) + I.setName(""); // Internal symbols can't participate in linkage + StripSymtab(I.getValueSymbolTable(), PreserveDbgInfo); } // Remove all names from types. diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index dd4e7e27a96..f94a65a75f0 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -699,10 +699,9 @@ Value *FAddCombine::createNaryFAdd bool LastValNeedNeg = false; // Iterate the addends, creating fadd/fsub using adjacent two addends. - for (AddendVect::const_iterator I = Opnds.begin(), E = Opnds.end(); - I != E; I++) { + for (const FAddend *Opnd : Opnds) { bool NeedNeg; - Value *V = createAddendVal(**I, NeedNeg); + Value *V = createAddendVal(*Opnd, NeedNeg); if (!LastVal) { LastVal = V; LastValNeedNeg = NeedNeg; @@ -791,9 +790,7 @@ unsigned FAddCombine::calcInstrNumber(const AddendVect &Opnds) { unsigned NegOpndNum = 0; // Adjust the number of instructions needed to emit the N-ary add. - for (AddendVect::const_iterator I = Opnds.begin(), E = Opnds.end(); - I != E; I++) { - const FAddend *Opnd = *I; + for (const FAddend *Opnd : Opnds) { if (Opnd->isConstant()) continue; diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index a02d8ea396d..2d3ff839f1f 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3046,11 +3046,11 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL, // Do a quick scan over the function. If we find any blocks that are // unreachable, remove any instructions inside of them. This prevents // the instcombine code from having to deal with some bad special cases. - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (Visited.count(&*BB)) + for (BasicBlock &BB : F) { + if (Visited.count(&BB)) continue; - unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&*BB); + unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB); MadeIRChange |= NumDeadInstInBB > 0; NumDeadInst += NumDeadInstInBB; } diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 33693eb5417..736adeccb58 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1010,9 +1010,9 @@ void AddressSanitizer::instrumentPointerComparisonOrSubtraction( IRBuilder<> IRB(I); Function *F = isa<ICmpInst>(I) ? AsanPtrCmpFunction : AsanPtrSubFunction; Value *Param[2] = {I->getOperand(0), I->getOperand(1)}; - for (int i = 0; i < 2; i++) { - if (Param[i]->getType()->isPointerTy()) - Param[i] = IRB.CreatePointerCast(Param[i], IntptrTy); + for (Value *&i : Param) { + if (i->getType()->isPointerTy()) + i = IRB.CreatePointerCast(i, IntptrTy); } IRB.CreateCall(F, Param); } diff --git a/lib/Transforms/Instrumentation/BoundsChecking.cpp b/lib/Transforms/Instrumentation/BoundsChecking.cpp index f2ccc6d3272..d4c8369fa9d 100644 --- a/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ b/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -185,9 +185,8 @@ bool BoundsChecking::runOnFunction(Function &F) { } bool MadeChange = false; - for (std::vector<Instruction*>::iterator i = WorkList.begin(), - e = WorkList.end(); i != e; ++i) { - Inst = *i; + for (Instruction *i : WorkList) { + Inst = i; Builder->SetInsertPoint(Inst); if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) { diff --git a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index c964a1f37e5..b34d5b8c45a 100644 --- a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -791,25 +791,20 @@ bool DataFlowSanitizer::runOnModule(Module &M) { } } - for (std::vector<Function *>::iterator i = FnsToInstrument.begin(), - e = FnsToInstrument.end(); - i != e; ++i) { - if (!*i || (*i)->isDeclaration()) + for (Function *i : FnsToInstrument) { + if (!i || i->isDeclaration()) continue; - removeUnreachableBlocks(**i); + removeUnreachableBlocks(*i); - DFSanFunction DFSF(*this, *i, FnsWithNativeABI.count(*i)); + DFSanFunction DFSF(*this, i, FnsWithNativeABI.count(i)); // DFSanVisitor may create new basic blocks, which confuses df_iterator. // Build a copy of the list before iterating over it. - llvm::SmallVector<BasicBlock *, 4> BBList( - depth_first(&(*i)->getEntryBlock())); + llvm::SmallVector<BasicBlock *, 4> BBList(depth_first(&i->getEntryBlock())); - for (llvm::SmallVector<BasicBlock *, 4>::iterator i = BBList.begin(), - e = BBList.end(); - i != e; ++i) { - Instruction *Inst = &(*i)->front(); + for (BasicBlock *i : BBList) { + Instruction *Inst = &i->front(); while (1) { // DFSanVisitor may split the current basic block, changing the current // instruction's next pointer and moving the next instruction to the @@ -1066,11 +1061,10 @@ Value *DFSanFunction::loadShadow(Value *Addr, uint64_t Size, uint64_t Align, SmallVector<Value *, 2> Objs; GetUnderlyingObjects(Addr, Objs, Pos->getModule()->getDataLayout()); bool AllConstants = true; - for (SmallVector<Value *, 2>::iterator i = Objs.begin(), e = Objs.end(); - i != e; ++i) { - if (isa<Function>(*i) || isa<BlockAddress>(*i)) + for (Value *Obj : Objs) { + if (isa<Function>(Obj) || isa<BlockAddress>(Obj)) continue; - if (isa<GlobalVariable>(*i) && cast<GlobalVariable>(*i)->isConstant()) + if (isa<GlobalVariable>(Obj) && cast<GlobalVariable>(Obj)->isConstant()) continue; AllConstants = false; diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index df48897f2c7..1288175200c 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -265,10 +265,9 @@ namespace { void writeOut() { uint32_t Len = 3; SmallVector<StringMapEntry<GCOVLines *> *, 32> SortedLinesByFile; - for (StringMap<GCOVLines *>::iterator I = LinesByFile.begin(), - E = LinesByFile.end(); I != E; ++I) { - Len += I->second->length(); - SortedLinesByFile.push_back(&*I); + for (auto &I : LinesByFile) { + Len += I.second->length(); + SortedLinesByFile.push_back(&I); } writeBytes(LinesTag, 4); @@ -280,10 +279,8 @@ namespace { StringMapEntry<GCOVLines *> *RHS) { return LHS->getKey() < RHS->getKey(); }); - for (SmallVectorImpl<StringMapEntry<GCOVLines *> *>::iterator - I = SortedLinesByFile.begin(), E = SortedLinesByFile.end(); - I != E; ++I) - (*I)->getValue()->writeOut(); + for (auto &I : SortedLinesByFile) + I->getValue()->writeOut(); write(0); write(0); } @@ -742,8 +739,8 @@ GlobalVariable *GCOVProfiler::buildEdgeLookupTable( EdgeTable[i] = NullValue; unsigned Edge = 0; - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { - TerminatorInst *TI = BB->getTerminator(); + for (BasicBlock &BB : *F) { + TerminatorInst *TI = BB.getTerminator(); int Successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors(); if (Successors > 1 && !isa<BranchInst>(TI) && !isa<ReturnInst>(TI)) { for (int i = 0; i != Successors; ++i) { @@ -752,7 +749,7 @@ GlobalVariable *GCOVProfiler::buildEdgeLookupTable( Value *Counter = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Edge + i); EdgeTable[((Succs.idFor(Succ) - 1) * Preds.size()) + - (Preds.idFor(&*BB) - 1)] = cast<Constant>(Counter); + (Preds.idFor(&BB) - 1)] = cast<Constant>(Counter); } } Edge += Successors; @@ -972,10 +969,8 @@ insertFlush(ArrayRef<std::pair<GlobalVariable*, MDNode*> > CountersBySP) { Builder.CreateCall(WriteoutF, {}); // Zero out the counters. - for (ArrayRef<std::pair<GlobalVariable *, MDNode *> >::iterator - I = CountersBySP.begin(), E = CountersBySP.end(); - I != E; ++I) { - GlobalVariable *GV = I->first; + for (const auto &I : CountersBySP) { + GlobalVariable *GV = I.first; Constant *Null = Constant::getNullValue(GV->getValueType()); Builder.CreateStore(Null, GV); } diff --git a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 3445596fb61..a6907b56cf4 100644 --- a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -1551,9 +1551,7 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( unsigned NewCount = 0; bool FirstRelease = true; for (;;) { - for (SmallVectorImpl<Instruction *>::const_iterator - NI = NewRetains.begin(), NE = NewRetains.end(); NI != NE; ++NI) { - Instruction *NewRetain = *NI; + for (Instruction *NewRetain : NewRetains) { auto It = Retains.find(NewRetain); assert(It != Retains.end()); const RRInfo &NewRetainRRI = It->second; @@ -1627,9 +1625,7 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( if (NewReleases.empty()) break; // Back the other way. - for (SmallVectorImpl<Instruction *>::const_iterator - NI = NewReleases.begin(), NE = NewReleases.end(); NI != NE; ++NI) { - Instruction *NewRelease = *NI; + for (Instruction *NewRelease : NewReleases) { auto It = Releases.find(NewRelease); assert(It != Releases.end()); const RRInfo &NewReleaseRRI = It->second; diff --git a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index ca0e62c2e14..9085f07ee21 100644 --- a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/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/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 22d08e03674..595a556b505 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/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/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index de1691d5052..321fc7b8074 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/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/lib/Transforms/Scalar/LoopDataPrefetch.cpp b/lib/Transforms/Scalar/LoopDataPrefetch.cpp index 0c5325405d8..66b59d27dfd 100644 --- a/lib/Transforms/Scalar/LoopDataPrefetch.cpp +++ b/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/lib/Transforms/Scalar/LoopDeletion.cpp b/lib/Transforms/Scalar/LoopDeletion.cpp index 2e07f343681..daf0eb9dc2c 100644 --- a/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/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/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 17985e06a6b..a226865262e 100644 --- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/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/lib/Transforms/Scalar/LoopInterchange.cpp b/lib/Transforms/Scalar/LoopInterchange.cpp index 2f50e2dd77f..9241ec36527 100644 --- a/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/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/lib/Transforms/Scalar/LoopRerollPass.cpp b/lib/Transforms/Scalar/LoopRerollPass.cpp index 2c08ee68871..d2f1b66076a 100644 --- a/lib/Transforms/Scalar/LoopRerollPass.cpp +++ b/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/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp index 46db8f1210b..549248fbf73 100644 --- a/lib/Transforms/Scalar/LoopRotation.cpp +++ b/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/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 0b128a16183..71980e85e8c 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/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/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 76b9f55ad0c..d64c658f843 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/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/lib/Transforms/Scalar/PlaceSafepoints.cpp b/lib/Transforms/Scalar/PlaceSafepoints.cpp index 029178388b7..e47b636348e 100644 --- a/lib/Transforms/Scalar/PlaceSafepoints.cpp +++ b/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/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 8e7eaf844c6..b09ed246387 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/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/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp index 5ee2070d86c..615029dd161 100644 --- a/lib/Transforms/Scalar/Reg2Mem.cpp +++ b/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/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index a4b8519c910..bab39a32677 100644 --- a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/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/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 91e625b7aac..d4c156e994c 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/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/lib/Transforms/Scalar/Scalarizer.cpp b/lib/Transforms/Scalar/Scalarizer.cpp index 5e6df0ddf6d..15aa541de30 100644 --- a/lib/Transforms/Scalar/Scalarizer.cpp +++ b/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/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp index 2bc0087f063..d6ae186698c 100644 --- a/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp +++ b/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/lib/Transforms/Scalar/Sink.cpp b/lib/Transforms/Scalar/Sink.cpp index c5f29fa99dc..5fa43bda9d0 100644 --- a/lib/Transforms/Scalar/Sink.cpp +++ b/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/lib/Transforms/Scalar/StructurizeCFG.cpp b/lib/Transforms/Scalar/StructurizeCFG.cpp index ff46d81cb4d..be9b6e4534c 100644 --- a/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/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/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index 0198d3adebe..4126cd67f69 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/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; } diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 58a5f5e1443..b90349d3cda 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -152,10 +152,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT, if (DomTreeNode *DTN = DT->getNode(BB)) { DomTreeNode *PredDTN = DT->getNode(PredBB); SmallVector<DomTreeNode *, 8> Children(DTN->begin(), DTN->end()); - for (SmallVectorImpl<DomTreeNode *>::iterator DI = Children.begin(), - DE = Children.end(); - DI != DE; ++DI) - DT->changeImmediateDominator(*DI, PredDTN); + for (DomTreeNode *DI : Children) + DT->changeImmediateDominator(DI, PredDTN); DT->eraseNode(BB); } @@ -240,8 +238,8 @@ unsigned llvm::SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options) { unsigned NumBroken = 0; - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { - TerminatorInst *TI = I->getTerminator(); + for (BasicBlock &BB : F) { + TerminatorInst *TI = BB.getTerminator(); if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI)) for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) if (SplitCriticalEdge(TI, i, Options)) @@ -266,15 +264,11 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, if (DT) // Old dominates New. New node dominates all other nodes dominated by Old. if (DomTreeNode *OldNode = DT->getNode(Old)) { - std::vector<DomTreeNode *> Children; - for (DomTreeNode::iterator I = OldNode->begin(), E = OldNode->end(); - I != E; ++I) - Children.push_back(*I); + std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end()); DomTreeNode *NewNode = DT->addNewBlock(New, Old); - for (std::vector<DomTreeNode *>::iterator I = Children.begin(), - E = Children.end(); I != E; ++I) - DT->changeImmediateDominator(*I, NewNode); + for (DomTreeNode *I : Children) + DT->changeImmediateDominator(I, NewNode); } return New; @@ -299,10 +293,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, // this split will affect loops. bool IsLoopEntry = !!L; bool SplitMakesNewLoopHeader = false; - for (ArrayRef<BasicBlock *>::iterator i = Preds.begin(), e = Preds.end(); - i != e; ++i) { - BasicBlock *Pred = *i; - + for (BasicBlock *Pred : Preds) { // If we need to preserve LCSSA, determine if any of the preds is a loop // exit. if (PreserveLCSSA) @@ -330,9 +321,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, // loops enclose them, and select the most-nested loop which contains the // loop containing the block being split. Loop *InnermostPredLoop = nullptr; - for (ArrayRef<BasicBlock*>::iterator - i = Preds.begin(), e = Preds.end(); i != e; ++i) { - BasicBlock *Pred = *i; + for (BasicBlock *Pred : Preds) { if (Loop *PredLoop = LI->getLoopFor(Pred)) { // Seek a loop which actually contains the block being split (to avoid // adjacent loops). @@ -543,9 +532,8 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB, BI2->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc()); // Move the remaining edges from OrigBB to point to NewBB2. - for (SmallVectorImpl<BasicBlock*>::iterator - i = NewBB2Preds.begin(), e = NewBB2Preds.end(); i != e; ++i) - (*i)->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2); + for (BasicBlock *NewBB2Pred : NewBB2Preds) + NewBB2Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB2); // Update DominatorTree, LoopInfo, and LCCSA analysis information. HasLoopExit = false; @@ -649,7 +637,7 @@ llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, std::vector<DomTreeNode *> Children(OldNode->begin(), OldNode->end()); DomTreeNode *NewNode = DT->addNewBlock(Tail, Head); - for (auto Child : Children) + for (DomTreeNode *Child : Children) DT->changeImmediateDominator(Child, NewNode); // Head dominates ThenBlock. diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index fcdb45b6611..c5ca56360fc 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -519,10 +519,9 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, // entries. BasicBlock::iterator I = NewBB->begin(); for (; (PN = dyn_cast<PHINode>(I)); ++I) { - for (std::map<BasicBlock*, unsigned>::iterator PCI =PredCount.begin(), - E = PredCount.end(); PCI != E; ++PCI) { - BasicBlock *Pred = PCI->first; - for (unsigned NumToRemove = PCI->second; NumToRemove; --NumToRemove) + for (const auto &PCI : PredCount) { + BasicBlock *Pred = PCI.first; + for (unsigned NumToRemove = PCI.second; NumToRemove; --NumToRemove) PN->removeIncomingValue(Pred, false); } } diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 4eed60492a7..17e34c4ffa0 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -64,12 +64,11 @@ std::unique_ptr<Module> llvm::CloneModule( } // Loop over the functions in the module, making external functions as before - for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { - Function *NF = - Function::Create(cast<FunctionType>(I->getValueType()), - I->getLinkage(), I->getName(), New.get()); - NF->copyAttributesFrom(&*I); - VMap[&*I] = NF; + for (const Function &I : *M) { + Function *NF = Function::Create(cast<FunctionType>(I.getValueType()), + I.getLinkage(), I.getName(), New.get()); + NF->copyAttributesFrom(&I); + VMap[&I] = NF; } // Loop over the aliases in the module @@ -124,12 +123,12 @@ std::unique_ptr<Module> llvm::CloneModule( // Similarly, copy over function bodies now... // - for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { - if (I->isDeclaration()) + for (const Function &I : *M) { + if (I.isDeclaration()) continue; - Function *F = cast<Function>(VMap[&*I]); - if (!ShouldCloneDefinition(&*I)) { + Function *F = cast<Function>(VMap[&I]); + if (!ShouldCloneDefinition(&I)) { // Skip after setting the correct linkage for an external reference. F->setLinkage(GlobalValue::ExternalLinkage); // Personality function is not valid on a declaration. @@ -138,17 +137,17 @@ std::unique_ptr<Module> llvm::CloneModule( } Function::arg_iterator DestI = F->arg_begin(); - for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end(); + for (Function::const_arg_iterator J = I.arg_begin(); J != I.arg_end(); ++J) { DestI->setName(J->getName()); VMap[&*J] = &*DestI++; } SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned. - CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); + CloneFunctionInto(F, &I, VMap, /*ModuleLevelChanges=*/true, Returns); - if (I->hasPersonalityFn()) - F->setPersonalityFn(MapValue(I->getPersonalityFn(), VMap)); + if (I.hasPersonalityFn()) + F->setPersonalityFn(MapValue(I.getPersonalityFn(), VMap)); } // And aliases diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 3d2ee73669b..a2fa6a76d26 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -159,23 +159,18 @@ static bool definedInCaller(const SetVector<BasicBlock *> &Blocks, Value *V) { void CodeExtractor::findInputsOutputs(ValueSet &Inputs, ValueSet &Outputs) const { - for (SetVector<BasicBlock *>::const_iterator I = Blocks.begin(), - E = Blocks.end(); - I != E; ++I) { - BasicBlock *BB = *I; - + for (BasicBlock *BB : Blocks) { // If a used value is defined outside the region, it's an input. If an // instruction is used outside the region, it's an output. - for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); - II != IE; ++II) { - for (User::op_iterator OI = II->op_begin(), OE = II->op_end(); - OI != OE; ++OI) + for (Instruction &II : *BB) { + for (User::op_iterator OI = II.op_begin(), OE = II.op_end(); OI != OE; + ++OI) if (definedInCaller(Blocks, *OI)) Inputs.insert(*OI); - for (User *U : II->users()) + for (User *U : II.users()) if (!definedInRegion(Blocks, U)) { - Outputs.insert(&*II); + Outputs.insert(&II); break; } } @@ -263,25 +258,21 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) { } void CodeExtractor::splitReturnBlocks() { - for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end(); - I != E; ++I) - if (ReturnInst *RI = dyn_cast<ReturnInst>((*I)->getTerminator())) { + for (BasicBlock *Block : Blocks) + if (ReturnInst *RI = dyn_cast<ReturnInst>(Block->getTerminator())) { BasicBlock *New = - (*I)->splitBasicBlock(RI->getIterator(), (*I)->getName() + ".ret"); + Block->splitBasicBlock(RI->getIterator(), Block->getName() + ".ret"); if (DT) { // Old dominates New. New node dominates all other nodes dominated // by Old. - DomTreeNode *OldNode = DT->getNode(*I); - SmallVector<DomTreeNode*, 8> Children; - for (DomTreeNode::iterator DI = OldNode->begin(), DE = OldNode->end(); - DI != DE; ++DI) - Children.push_back(*DI); + DomTreeNode *OldNode = DT->getNode(Block); + SmallVector<DomTreeNode *, 8> Children(OldNode->begin(), + OldNode->end()); - DomTreeNode *NewNode = DT->addNewBlock(New, *I); + DomTreeNode *NewNode = DT->addNewBlock(New, Block); - for (SmallVectorImpl<DomTreeNode *>::iterator I = Children.begin(), - E = Children.end(); I != E; ++I) - DT->changeImmediateDominator(*I, NewNode); + for (DomTreeNode *I : Children) + DT->changeImmediateDominator(I, NewNode); } } } @@ -310,27 +301,23 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs, std::vector<Type*> paramTy; // Add the types of the input values to the function's argument list - for (ValueSet::const_iterator i = inputs.begin(), e = inputs.end(); - i != e; ++i) { - const Value *value = *i; + for (Value *value : inputs) { DEBUG(dbgs() << "value used in func: " << *value << "\n"); paramTy.push_back(value->getType()); } // Add the types of the output values to the function's argument list. - for (ValueSet::const_iterator I = outputs.begin(), E = outputs.end(); - I != E; ++I) { - DEBUG(dbgs() << "instr used in func: " << **I << "\n"); + for (Value *output : outputs) { + DEBUG(dbgs() << "instr used in func: " << *output << "\n"); if (AggregateArgs) - paramTy.push_back((*I)->getType()); + paramTy.push_back(output->getType()); else - paramTy.push_back(PointerType::getUnqual((*I)->getType())); + paramTy.push_back(PointerType::getUnqual(output->getType())); } DEBUG(dbgs() << "Function type: " << *RetTy << " f("); - for (std::vector<Type*>::iterator i = paramTy.begin(), - e = paramTy.end(); i != e; ++i) - DEBUG(dbgs() << **i << ", "); + for (Type *i : paramTy) + DEBUG(dbgs() << *i << ", "); DEBUG(dbgs() << ")\n"); StructType *StructTy; @@ -372,9 +359,8 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs, RewriteVal = &*AI++; std::vector<User*> Users(inputs[i]->user_begin(), inputs[i]->user_end()); - for (std::vector<User*>::iterator use = Users.begin(), useE = Users.end(); - use != useE; ++use) - if (Instruction* inst = dyn_cast<Instruction>(*use)) + for (User *use : Users) + if (Instruction *inst = dyn_cast<Instruction>(use)) if (Blocks.count(inst->getParent())) inst->replaceUsesOfWith(inputs[i], RewriteVal); } @@ -429,19 +415,19 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, LLVMContext &Context = newFunction->getContext(); // Add inputs as params, or to be filled into the struct - for (ValueSet::iterator i = inputs.begin(), e = inputs.end(); i != e; ++i) + for (Value *input : inputs) if (AggregateArgs) - StructValues.push_back(*i); + StructValues.push_back(input); else - params.push_back(*i); + params.push_back(input); // Create allocas for the outputs - for (ValueSet::iterator i = outputs.begin(), e = outputs.end(); i != e; ++i) { + for (Value *output : outputs) { if (AggregateArgs) { - StructValues.push_back(*i); + StructValues.push_back(output); } else { AllocaInst *alloca = - new AllocaInst((*i)->getType(), nullptr, (*i)->getName() + ".loc", + new AllocaInst(output->getType(), nullptr, output->getName() + ".loc", &codeReplacer->getParent()->front().front()); ReloadOutputs.push_back(alloca); params.push_back(alloca); @@ -522,9 +508,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, std::map<BasicBlock*, BasicBlock*> ExitBlockMap; unsigned switchVal = 0; - for (SetVector<BasicBlock*>::const_iterator i = Blocks.begin(), - e = Blocks.end(); i != e; ++i) { - TerminatorInst *TI = (*i)->getTerminator(); + for (BasicBlock *Block : Blocks) { + TerminatorInst *TI = Block->getTerminator(); for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) if (!Blocks.count(TI->getSuccessor(i))) { BasicBlock *OldTarget = TI->getSuccessor(i); @@ -576,10 +561,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Make sure we are looking at the original successor block, not // at a newly inserted exit block, which won't be in the dominator // info. - for (std::map<BasicBlock*, BasicBlock*>::iterator I = - ExitBlockMap.begin(), E = ExitBlockMap.end(); I != E; ++I) - if (DefBlock == I->second) { - DefBlock = I->first; + for (const auto &I : ExitBlockMap) + if (DefBlock == I.second) { + DefBlock = I.first; break; } @@ -677,13 +661,12 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) { Function::BasicBlockListType &oldBlocks = oldFunc->getBasicBlockList(); Function::BasicBlockListType &newBlocks = newFunction->getBasicBlockList(); - for (SetVector<BasicBlock*>::const_iterator i = Blocks.begin(), - e = Blocks.end(); i != e; ++i) { + for (BasicBlock *Block : Blocks) { // Delete the basic block from the old function, and the list of blocks - oldBlocks.remove(*i); + oldBlocks.remove(Block); // Insert this basic block into the new function - newBlocks.push_back(*i); + newBlocks.push_back(Block); } } @@ -721,9 +704,9 @@ Function *CodeExtractor::extractCodeRegion() { findInputsOutputs(inputs, outputs); SmallPtrSet<BasicBlock *, 1> ExitBlocks; - for (SetVector<BasicBlock *>::iterator I = Blocks.begin(), E = Blocks.end(); - I != E; ++I) - for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I); SI != SE; ++SI) + for (BasicBlock *Block : Blocks) + for (succ_iterator SI = succ_begin(Block), SE = succ_end(Block); SI != SE; + ++SI) if (!Blocks.count(*SI)) ExitBlocks.insert(*SI); NumExitBlocks = ExitBlocks.size(); diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index a06c8499e19..1fbb19d2b8a 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -732,12 +732,11 @@ static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) { // inter-procedural alias analysis passes. We can revisit this if it becomes // an efficiency or overhead problem. - for (Function::const_iterator I = CalledFunc->begin(), IE = CalledFunc->end(); - I != IE; ++I) - for (BasicBlock::const_iterator J = I->begin(), JE = I->end(); J != JE; ++J) { - if (const MDNode *M = J->getMetadata(LLVMContext::MD_alias_scope)) + for (const BasicBlock &I : *CalledFunc) + for (const Instruction &J : I) { + if (const MDNode *M = J.getMetadata(LLVMContext::MD_alias_scope)) MD.insert(M); - if (const MDNode *M = J->getMetadata(LLVMContext::MD_noalias)) + if (const MDNode *M = J.getMetadata(LLVMContext::MD_noalias)) MD.insert(M); } @@ -759,20 +758,18 @@ static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) { // the noalias scopes and the lists of those scopes. SmallVector<TempMDTuple, 16> DummyNodes; DenseMap<const MDNode *, TrackingMDNodeRef> MDMap; - for (SetVector<const MDNode *>::iterator I = MD.begin(), IE = MD.end(); - I != IE; ++I) { + for (const MDNode *I : MD) { DummyNodes.push_back(MDTuple::getTemporary(CalledFunc->getContext(), None)); - MDMap[*I].reset(DummyNodes.back().get()); + MDMap[I].reset(DummyNodes.back().get()); } // Create new metadata nodes to replace the dummy nodes, replacing old // metadata references with either a dummy node or an already-created new // node. - for (SetVector<const MDNode *>::iterator I = MD.begin(), IE = MD.end(); - I != IE; ++I) { + for (const MDNode *I : MD) { SmallVector<Metadata *, 4> NewOps; - for (unsigned i = 0, ie = (*I)->getNumOperands(); i != ie; ++i) { - const Metadata *V = (*I)->getOperand(i); + for (unsigned i = 0, ie = I->getNumOperands(); i != ie; ++i) { + const Metadata *V = I->getOperand(i); if (const MDNode *M = dyn_cast<MDNode>(V)) NewOps.push_back(MDMap[M]); else @@ -780,7 +777,7 @@ static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) { } MDNode *NewM = MDNode::get(CalledFunc->getContext(), NewOps); - MDTuple *TempM = cast<MDTuple>(MDMap[*I]); + MDTuple *TempM = cast<MDTuple>(MDMap[I]); assert(TempM->isTemporary() && "Expected temporary node"); TempM->replaceAllUsesWith(NewM); diff --git a/lib/Transforms/Utils/InstructionNamer.cpp b/lib/Transforms/Utils/InstructionNamer.cpp index da890a29700..8a1973d1db0 100644 --- a/lib/Transforms/Utils/InstructionNamer.cpp +++ b/lib/Transforms/Utils/InstructionNamer.cpp @@ -37,13 +37,13 @@ namespace { if (!AI->hasName() && !AI->getType()->isVoidTy()) AI->setName("arg"); - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!BB->hasName()) - BB->setName("bb"); - - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (!I->hasName() && !I->getType()->isVoidTy()) - I->setName("tmp"); + for (BasicBlock &BB : F) { + if (!BB.hasName()) + BB.setName("bb"); + + for (Instruction &I : BB) + if (!I.hasName() && !I.getType()->isVoidTy()) + I.setName("tmp"); } return true; } diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 2509b0a058f..66aef29ea24 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -501,14 +501,13 @@ ReprocessLoop: // trip count computations. SmallVector<BasicBlock*, 8> ExitingBlocks; L->getExitingBlocks(ExitingBlocks); - for (SmallVectorImpl<BasicBlock *>::iterator I = ExitingBlocks.begin(), - E = ExitingBlocks.end(); I != E; ++I) - if (BranchInst *BI = dyn_cast<BranchInst>((*I)->getTerminator())) + for (BasicBlock *ExitingBlock : ExitingBlocks) + if (BranchInst *BI = dyn_cast<BranchInst>(ExitingBlock->getTerminator())) if (BI->isConditional()) { if (UndefValue *Cond = dyn_cast<UndefValue>(BI->getCondition())) { DEBUG(dbgs() << "LoopSimplify: Resolving \"br i1 undef\" to exit in " - << (*I)->getName() << "\n"); + << ExitingBlock->getName() << "\n"); BI->setCondition(ConstantInt::get(Cond->getType(), !L->contains(BI->getSuccessor(0)))); @@ -540,9 +539,7 @@ ReprocessLoop: SmallSetVector<BasicBlock *, 8> ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end()); - for (SmallSetVector<BasicBlock *, 8>::iterator I = ExitBlockSet.begin(), - E = ExitBlockSet.end(); I != E; ++I) { - BasicBlock *ExitBlock = *I; + for (BasicBlock *ExitBlock : ExitBlockSet) { for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); PI != PE; ++PI) // Must be exactly this loop: no subloops, parent loops, or non-loop preds diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index 7f90e3e8b60..1b31c5ae580 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -52,8 +52,8 @@ FunctionPass *llvm::createLowerInvokePass() { bool LowerInvoke::runOnFunction(Function &F) { bool Changed = false; - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) - if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { + for (BasicBlock &BB : F) + if (InvokeInst *II = dyn_cast<InvokeInst>(BB.getTerminator())) { SmallVector<Value*,16> CallArgs(II->op_begin(), II->op_end() - 3); // Insert a normal call instruction... CallInst *NewCall = CallInst::Create(II->getCalledValue(), @@ -68,10 +68,10 @@ bool LowerInvoke::runOnFunction(Function &F) { BranchInst::Create(II->getNormalDest(), II); // Remove any PHI node entries from the exception destination. - II->getUnwindDest()->removePredecessor(&*BB); + II->getUnwindDest()->removePredecessor(&BB); // Remove the invoke instruction now. - BB->getInstList().erase(II); + BB.getInstList().erase(II); ++NumInvokes; Changed = true; } diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 7924c33038a..0504646c304 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1083,13 +1083,10 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI, // If there are any constants vectored to BB that TI doesn't handle, // they must go to the default destination of TI. - for (std::set<ConstantInt *, ConstantIntOrdering>::iterator - I = PTIHandled.begin(), - E = PTIHandled.end(); - I != E; ++I) { + for (ConstantInt *I : PTIHandled) { if (PredHasWeights || SuccHasWeights) - Weights.push_back(WeightsForHandled[*I]); - PredCases.push_back(ValueEqualityComparisonCase(*I, BBDefault)); + Weights.push_back(WeightsForHandled[I]); + PredCases.push_back(ValueEqualityComparisonCase(I, BBDefault)); NewSuccessors.push_back(BBDefault); } } @@ -2150,8 +2147,8 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI, static bool checkCSEInPredecessor(Instruction *Inst, BasicBlock *PB) { if (!isa<BinaryOperator>(Inst) && !isa<CmpInst>(Inst)) return false; - for (BasicBlock::iterator I = PB->begin(), E = PB->end(); I != E; I++) { - Instruction *PBI = &*I; + for (Instruction &I : *PB) { + Instruction *PBI = &I; // Check whether Inst and PBI generate the same value. if (Inst->isIdenticalTo(PBI)) { Inst->replaceAllUsesWith(PBI); @@ -2465,9 +2462,9 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) { // could replace PBI's branch probabilities with BI's. // Copy any debug value intrinsics into the end of PredBlock. - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (isa<DbgInfoIntrinsic>(*I)) - I->clone()->insertBefore(PBI); + for (Instruction &I : *BB) + if (isa<DbgInfoIntrinsic>(I)) + I.clone()->insertBefore(PBI); return true; } diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index 6b1d1dae5f0..9385f825523 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -66,9 +66,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { "UnifiedUnreachableBlock", &F); new UnreachableInst(F.getContext(), UnreachableBlock); - for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), - E = UnreachableBlocks.end(); I != E; ++I) { - BasicBlock *BB = *I; + for (BasicBlock *BB : UnreachableBlocks) { BB->getInstList().pop_back(); // Remove the unreachable inst. BranchInst::Create(UnreachableBlock, BB); } @@ -104,10 +102,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { // Loop over all of the blocks, replacing the return instruction with an // unconditional branch. // - for (std::vector<BasicBlock*>::iterator I = ReturningBlocks.begin(), - E = ReturningBlocks.end(); I != E; ++I) { - BasicBlock *BB = *I; - + for (BasicBlock *BB : ReturningBlocks) { // Add an incoming element to the PHI node for every return instruction that // is merging into this new block... if (PN) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 336ce708cb7..0b3e5562eac 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5018,9 +5018,9 @@ void LoopVectorizationLegality::collectLoopUniforms() { for (Loop::block_iterator B = TheLoop->block_begin(), BE = TheLoop->block_end(); B != BE; ++B) - for (BasicBlock::iterator I = (*B)->begin(), IE = (*B)->end(); I != IE; ++I) - if (I->getType()->isPointerTy() && isConsecutivePtr(&*I)) - Worklist.insert(Worklist.end(), I->op_begin(), I->op_end()); + for (Instruction &I : **B) + if (I.getType()->isPointerTy() && isConsecutivePtr(&I)) + Worklist.insert(Worklist.end(), I.op_begin(), I.op_end()); while (!Worklist.empty()) { Instruction *I = dyn_cast<Instruction>(Worklist.back()); diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 774650b0c55..09ae5517c8c 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -131,8 +131,8 @@ static BasicBlock *getSameBlock(ArrayRef<Value *> VL) { /// \returns True if all of the values in \p VL are constants. static bool allConstant(ArrayRef<Value *> VL) { - for (unsigned i = 0, e = VL.size(); i < e; ++i) - if (!isa<Constant>(VL[i])) + for (Value *i : VL) + if (!isa<Constant>(i)) return false; return true; } @@ -958,8 +958,8 @@ void BoUpSLP::buildTree(ArrayRef<Value *> Roots, buildTree_rec(Roots, 0); // Collect the values that we need to extract from the tree. - for (int EIdx = 0, EE = VectorizableTree.size(); EIdx < EE; ++EIdx) { - TreeEntry *Entry = &VectorizableTree[EIdx]; + for (TreeEntry &EIdx : VectorizableTree) { + TreeEntry *Entry = &EIdx; // For each lane: for (int Lane = 0, LE = Entry->Scalars.size(); Lane != LE; ++Lane) { @@ -1159,8 +1159,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<PHINode>(VL[j])->getIncomingValueForBlock( + for (Value *j : VL) + Operands.push_back(cast<PHINode>(j)->getIncomingValueForBlock( PH->getIncomingBlock(i))); buildTree_rec(Operands, Depth + 1); @@ -1248,8 +1248,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(i)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(i)); buildTree_rec(Operands, Depth+1); } @@ -1277,8 +1277,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(i)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(i)); buildTree_rec(Operands, Depth+1); } @@ -1319,8 +1319,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(i)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(i)); buildTree_rec(Operands, Depth+1); } @@ -1367,8 +1367,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = 2; i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(i)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(i)); buildTree_rec(Operands, Depth + 1); } @@ -1388,8 +1388,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { DEBUG(dbgs() << "SLP: added a vector of stores.\n"); ValueList Operands; - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(0)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(0)); buildTree_rec(Operands, Depth + 1); return; @@ -1451,8 +1451,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = CI->getNumArgOperands(); i != e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) { - CallInst *CI2 = dyn_cast<CallInst>(VL[j]); + for (Value *j : VL) { + CallInst *CI2 = dyn_cast<CallInst>(j); Operands.push_back(CI2->getArgOperand(i)); } buildTree_rec(Operands, Depth + 1); @@ -1483,8 +1483,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) { ValueList Operands; // Prepare the operand vector. - for (unsigned j = 0; j < VL.size(); ++j) - Operands.push_back(cast<Instruction>(VL[j])->getOperand(i)); + for (Value *j : VL) + Operands.push_back(cast<Instruction>(j)->getOperand(i)); buildTree_rec(Operands, Depth + 1); } @@ -1770,8 +1770,8 @@ int BoUpSLP::getEntryCost(TreeEntry *E) { TargetTransformInfo::OK_AnyValue; int ScalarCost = 0; int VecCost = 0; - for (unsigned i = 0; i < VL.size(); ++i) { - Instruction *I = cast<Instruction>(VL[i]); + for (Value *i : VL) { + Instruction *I = cast<Instruction>(i); if (!I) break; ScalarCost += @@ -1826,8 +1826,8 @@ int BoUpSLP::getSpillCost() { SmallPtrSet<Instruction*, 4> LiveValues; Instruction *PrevInst = nullptr; - for (unsigned N = 0; N < VectorizableTree.size(); ++N) { - Instruction *Inst = dyn_cast<Instruction>(VectorizableTree[N].Scalars[0]); + for (const auto &N : VectorizableTree) { + Instruction *Inst = dyn_cast<Instruction>(N.Scalars[0]); if (!Inst) continue; @@ -1967,9 +1967,9 @@ void BoUpSLP::reorderAltShuffleOperands(ArrayRef<Value *> VL, SmallVectorImpl<Value *> &Left, SmallVectorImpl<Value *> &Right) { // Push left and right operands of binary operation into Left and Right - for (unsigned i = 0, e = VL.size(); i < e; ++i) { - Left.push_back(cast<Instruction>(VL[i])->getOperand(0)); - Right.push_back(cast<Instruction>(VL[i])->getOperand(1)); + for (Value *i : VL) { + Left.push_back(cast<Instruction>(i)->getOperand(0)); + Right.push_back(cast<Instruction>(i)->getOperand(1)); } // Reorder if we have a commutative operation and consecutive access @@ -2656,10 +2656,9 @@ Value *BoUpSLP::vectorizeTree() { DEBUG(dbgs() << "SLP: Extracting " << ExternalUses.size() << " values .\n"); // Extract all of the elements with the external uses. - for (UserList::iterator it = ExternalUses.begin(), e = ExternalUses.end(); - it != e; ++it) { - Value *Scalar = it->Scalar; - llvm::User *User = it->User; + for (const auto &ExternalUse : ExternalUses) { + Value *Scalar = ExternalUse.Scalar; + llvm::User *User = ExternalUse.User; // Skip users that we already RAUW. This happens when one instruction // has multiple uses of the same value. @@ -2675,7 +2674,7 @@ Value *BoUpSLP::vectorizeTree() { Value *Vec = E->VectorizedValue; assert(Vec && "Can't find vectorizable value"); - Value *Lane = Builder.getInt32(it->Lane); + Value *Lane = Builder.getInt32(ExternalUse.Lane); // Generate extracts for out-of-tree users. // Find the insertion point for the extractelement lane. if (auto *VecI = dyn_cast<Instruction>(Vec)) { @@ -2718,8 +2717,8 @@ Value *BoUpSLP::vectorizeTree() { } // For each vectorized value: - for (int EIdx = 0, EE = VectorizableTree.size(); EIdx < EE; ++EIdx) { - TreeEntry *Entry = &VectorizableTree[EIdx]; + for (TreeEntry &EIdx : VectorizableTree) { + TreeEntry *Entry = &EIdx; // For each lane: for (int Lane = 0, LE = Entry->Scalars.size(); Lane != LE; ++Lane) { @@ -2760,9 +2759,8 @@ void BoUpSLP::optimizeGatherSequence() { DEBUG(dbgs() << "SLP: Optimizing " << GatherSeq.size() << " gather sequences instructions.\n"); // LICM InsertElementInst sequences. - for (SetVector<Instruction *>::iterator it = GatherSeq.begin(), - e = GatherSeq.end(); it != e; ++it) { - InsertElementInst *Insert = dyn_cast<InsertElementInst>(*it); + for (Instruction *it : GatherSeq) { + InsertElementInst *Insert = dyn_cast<InsertElementInst>(it); if (!Insert) continue; @@ -2823,12 +2821,10 @@ void BoUpSLP::optimizeGatherSequence() { // Check if we can replace this instruction with any of the // visited instructions. - for (SmallVectorImpl<Instruction *>::iterator v = Visited.begin(), - ve = Visited.end(); - v != ve; ++v) { - if (In->isIdenticalTo(*v) && - DT->dominates((*v)->getParent(), In->getParent())) { - In->replaceAllUsesWith(*v); + for (Instruction *v : Visited) { + if (In->isIdenticalTo(v) && + DT->dominates(v->getParent(), In->getParent())) { + In->replaceAllUsesWith(v); eraseInstruction(In); In = nullptr; break; |