From 87e53a0ad8557162bc074e982df914beb9afa84d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 5 Nov 2021 19:39:06 -0700 Subject: [PATCH] [llvm] Use make_early_inc_range (NFC) --- llvm/lib/Analysis/MemorySSAUpdater.cpp | 6 +----- llvm/lib/CodeGen/InlineSpiller.cpp | 5 ++--- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 6 ++---- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 13 ++++++------- llvm/lib/IR/DebugInfo.cpp | 3 +-- llvm/lib/IR/Value.cpp | 4 +--- llvm/lib/Linker/LinkModules.cpp | 12 +++--------- llvm/lib/Transforms/IPO/IROutliner.cpp | 15 ++++++--------- llvm/tools/bugpoint/CrashDebugger.cpp | 15 +++++++-------- 9 files changed, 29 insertions(+), 50 deletions(-) diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index d7ebe0e..8de0adc 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -1135,11 +1135,7 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef Updates, if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) { for (auto &DefToReplaceUses : *DefsList) { BasicBlock *DominatingBlock = DefToReplaceUses.getBlock(); - Value::use_iterator UI = DefToReplaceUses.use_begin(), - E = DefToReplaceUses.use_end(); - for (; UI != E;) { - Use &U = *UI; - ++UI; + for (Use &U : llvm::make_early_inc_range(DefToReplaceUses.uses())) { MemoryAccess *Usr = cast(U.getUser()); if (MemoryPhi *UsrPhi = dyn_cast(Usr)) { BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U); diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp index 992b2e6..5b84f87 100644 --- a/llvm/lib/CodeGen/InlineSpiller.cpp +++ b/llvm/lib/CodeGen/InlineSpiller.cpp @@ -341,9 +341,8 @@ void InlineSpiller::collectRegsToSpill() { if (Original == Reg) return; - for (MachineRegisterInfo::reg_instr_iterator - RI = MRI.reg_instr_begin(Reg), E = MRI.reg_instr_end(); RI != E; ) { - MachineInstr &MI = *RI++; + for (MachineInstr &MI : + llvm::make_early_inc_range(MRI.reg_instructions(Reg))) { Register SnipReg = isFullCopyOf(MI, Reg); if (!isSibling(SnipReg)) continue; diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index ee81f59..4d1449b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -196,10 +196,8 @@ void FastISel::flushLocalValueMap() { EmitStartPt ? MachineBasicBlock::reverse_iterator(EmitStartPt) : FuncInfo.MBB->rend(); MachineBasicBlock::reverse_iterator RI(LastLocalValue); - for (; RI != RE;) { - MachineInstr &LocalMI = *RI; - // Increment before erasing what it points to. - ++RI; + for (MachineInstr &LocalMI : + llvm::make_early_inc_range(llvm::make_range(RI, RE))) { Register DefReg = findLocalRegDef(LocalMI); if (!DefReg) continue; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index af4e473..9667389 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -9819,21 +9819,20 @@ unsigned SelectionDAG::AssignTopologicalOrder() { // before SortedPos will contain the topological sort index, and the // Node Id fields for nodes At SortedPos and after will contain the // count of outstanding operands. - for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ) { - SDNode *N = &*I++; - checkForCycles(N, this); - unsigned Degree = N->getNumOperands(); + for (SDNode &N : llvm::make_early_inc_range(allnodes())) { + checkForCycles(&N, this); + unsigned Degree = N.getNumOperands(); if (Degree == 0) { // A node with no uses, add it to the result array immediately. - N->setNodeId(DAGSize++); - allnodes_iterator Q(N); + N.setNodeId(DAGSize++); + allnodes_iterator Q(&N); if (Q != SortedPos) SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q)); assert(SortedPos != AllNodes.end() && "Overran node list"); ++SortedPos; } else { // Temporarily use the Node Id as scratch space for the degree count. - N->setNodeId(Degree); + N.setNodeId(Degree); } } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 6e36400..7c69fbf 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -447,8 +447,7 @@ bool llvm::stripDebugInfo(Function &F) { DenseMap LoopIDsMap; for (BasicBlock &BB : F) { - for (auto II = BB.begin(), End = BB.end(); II != End;) { - Instruction &I = *II++; // We may delete the instruction, increment now. + for (Instruction &I : llvm::make_early_inc_range(BB)) { if (isa(&I)) { I.eraseFromParent(); Changed = true; diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 4136a9a..b475c83 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -546,9 +546,7 @@ void Value::replaceUsesWithIf(Value *New, SmallVector, 8> Consts; SmallPtrSet Visited; - for (use_iterator UI = use_begin(), E = use_end(); UI != E;) { - Use &U = *UI; - ++UI; + for (Use &U : llvm::make_early_inc_range(uses())) { if (!ShouldReplace(U)) continue; // Must handle Constants specially, we cannot call replaceUsesOfWith on a diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 77e5c85..f9f51bf 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -485,20 +485,14 @@ bool ModuleLinker::run() { // Alias have to go first, since we are not able to find their comdats // otherwise. - for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) { - GlobalAlias &GV = *I++; + for (GlobalAlias &GV : llvm::make_early_inc_range(DstM.aliases())) dropReplacedComdat(GV, ReplacedDstComdats); - } - for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) { - GlobalVariable &GV = *I++; + for (GlobalVariable &GV : llvm::make_early_inc_range(DstM.globals())) dropReplacedComdat(GV, ReplacedDstComdats); - } - for (auto I = DstM.begin(), E = DstM.end(); I != E;) { - Function &GV = *I++; + for (Function &GV : llvm::make_early_inc_range(DstM)) dropReplacedComdat(GV, ReplacedDstComdats); - } for (GlobalVariable &GV : SrcM->globals()) if (GV.hasLinkOnceLinkage()) diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index 9eae088..bd3012c 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -523,23 +523,20 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group, /// \param [out] NewEnds - The return blocks of the new overall function. static void moveFunctionData(Function &Old, Function &New, DenseMap &NewEnds) { - Function::iterator CurrBB, NextBB, FinalBB; - for (CurrBB = Old.begin(), FinalBB = Old.end(); CurrBB != FinalBB; - CurrBB = NextBB) { - NextBB = std::next(CurrBB); - CurrBB->removeFromParent(); - CurrBB->insertInto(&New); - Instruction *I = CurrBB->getTerminator(); + for (BasicBlock &CurrBB : llvm::make_early_inc_range(Old)) { + CurrBB.removeFromParent(); + CurrBB.insertInto(&New); + Instruction *I = CurrBB.getTerminator(); // For each block we find a return instruction is, it is a potential exit // path for the function. We keep track of each block based on the return // value here. if (ReturnInst *RI = dyn_cast(I)) - NewEnds.insert(std::make_pair(RI->getReturnValue(), &(*CurrBB))); + NewEnds.insert(std::make_pair(RI->getReturnValue(), &CurrBB)); std::vector DebugInsts; - for (Instruction &Val : *CurrBB) { + for (Instruction &Val : CurrBB) { // We must handle the scoping of called functions differently than // other outlined instructions. if (!isa(&Val)) { diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index 5a4528e..451e1cd 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -786,14 +786,13 @@ bool ReduceCrashingInstructions::TestInsts( for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI) - for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { - Instruction *Inst = &*I++; - if (!Instructions.count(Inst) && !Inst->isTerminator() && - !Inst->isEHPad() && !Inst->getType()->isTokenTy() && - !Inst->isSwiftError()) { - if (!Inst->getType()->isVoidTy()) - Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); - Inst->eraseFromParent(); + for (Instruction &Inst : llvm::make_early_inc_range(*FI)) { + if (!Instructions.count(&Inst) && !Inst.isTerminator() && + !Inst.isEHPad() && !Inst.getType()->isTokenTy() && + !Inst.isSwiftError()) { + if (!Inst.getType()->isVoidTy()) + Inst.replaceAllUsesWith(UndefValue::get(Inst.getType())); + Inst.eraseFromParent(); } } -- 2.7.4