From feb40a3a475c1f87182f991409f4b77176415c9b Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 14 Nov 2021 19:40:48 -0800 Subject: [PATCH] [llvm] Use range-based for loops with instructions (NFC) --- llvm/lib/CodeGen/AtomicExpandPass.cpp | 8 +++----- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 18 ++++++++---------- llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp | 14 ++++++-------- .../Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp | 8 ++++---- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp index 1297f99..4838f6d 100644 --- a/llvm/lib/CodeGen/AtomicExpandPass.cpp +++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp @@ -180,11 +180,9 @@ bool AtomicExpand::runOnFunction(Function &F) { // Changing control-flow while iterating through it is a bad idea, so gather a // list of all atomic instructions before we start. - for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) { - Instruction *I = &*II; - if (I->isAtomic() && !isa(I)) - AtomicInsts.push_back(I); - } + for (Instruction &I : instructions(F)) + if (I.isAtomic() && !isa(&I)) + AtomicInsts.push_back(&I); bool MadeChange = false; for (auto I : AtomicInsts) { diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 401f988..03638bc 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -142,12 +142,10 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody, // Scan the function body for instructions that may read or write memory. bool ReadsMemory = false; bool WritesMemory = false; - for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) { - Instruction *I = &*II; - + for (Instruction &I : instructions(F)) { // Some instructions can be ignored even if they read or write memory. // Detect these now, skipping to the next instruction if one is found. - if (auto *Call = dyn_cast(I)) { + if (auto *Call = dyn_cast(&I)) { // Ignore calls to functions in the same SCC, as long as the call sites // don't have operand bundles. Calls with operand bundles are allowed to // have memory effects not described by the memory effects of the call @@ -187,7 +185,7 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody, continue; MemoryLocation Loc = - MemoryLocation::getBeforeOrAfter(Arg, I->getAAMetadata()); + MemoryLocation::getBeforeOrAfter(Arg, I.getAAMetadata()); // Skip accesses to local or constant memory as they don't impact the // externally visible mod/ref behavior. @@ -202,21 +200,21 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody, ReadsMemory = true; } continue; - } else if (LoadInst *LI = dyn_cast(I)) { + } else if (LoadInst *LI = dyn_cast(&I)) { // Ignore non-volatile loads from local memory. (Atomic is okay here.) if (!LI->isVolatile()) { MemoryLocation Loc = MemoryLocation::get(LI); if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true)) continue; } - } else if (StoreInst *SI = dyn_cast(I)) { + } else if (StoreInst *SI = dyn_cast(&I)) { // Ignore non-volatile stores to local memory. (Atomic is okay here.) if (!SI->isVolatile()) { MemoryLocation Loc = MemoryLocation::get(SI); if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true)) continue; } - } else if (VAArgInst *VI = dyn_cast(I)) { + } else if (VAArgInst *VI = dyn_cast(&I)) { // Ignore vaargs on local memory. MemoryLocation Loc = MemoryLocation::get(VI); if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true)) @@ -227,10 +225,10 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody, // read or write memory. // // Writes memory, remember that. - WritesMemory |= I->mayWriteToMemory(); + WritesMemory |= I.mayWriteToMemory(); // If this instruction may read memory, remember that. - ReadsMemory |= I->mayReadFromMemory(); + ReadsMemory |= I.mayReadFromMemory(); } if (WritesMemory) { diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp index d2121dc..6b074ac 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp @@ -56,12 +56,10 @@ static bool runImpl(Function &F) { LLVM_DEBUG(dbgs() << "ObjCARCExpand: Visiting Function: " << F.getName() << "\n"); - for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) { - Instruction *Inst = &*I; + for (Instruction &Inst : instructions(&F)) { + LLVM_DEBUG(dbgs() << "ObjCARCExpand: Visiting: " << Inst << "\n"); - LLVM_DEBUG(dbgs() << "ObjCARCExpand: Visiting: " << *Inst << "\n"); - - switch (GetBasicARCInstKind(Inst)) { + switch (GetBasicARCInstKind(&Inst)) { case ARCInstKind::Retain: case ARCInstKind::RetainRV: case ARCInstKind::Autorelease: @@ -73,12 +71,12 @@ static bool runImpl(Function &F) { // harder. Undo any uses of this optimization that the front-end // emitted here. We'll redo them in the contract pass. Changed = true; - Value *Value = cast(Inst)->getArgOperand(0); - LLVM_DEBUG(dbgs() << "ObjCARCExpand: Old = " << *Inst + Value *Value = cast(&Inst)->getArgOperand(0); + LLVM_DEBUG(dbgs() << "ObjCARCExpand: Old = " << Inst << "\n" " New = " << *Value << "\n"); - Inst->replaceAllUsesWith(Value); + Inst.replaceAllUsesWith(Value); break; } default: diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp index 6fdfe78..fe637ee 100644 --- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp +++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp @@ -58,11 +58,11 @@ bool PAEval::runOnFunction(Function &F) { for (auto &Arg : F.args()) insertIfNamed(Values, &Arg); - for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) { - insertIfNamed(Values, &*I); + for (Instruction &I : instructions(F)) { + insertIfNamed(Values, &I); - for (auto &Op : I->operands()) - insertIfNamed(Values, Op); + for (auto &Op : I.operands()) + insertIfNamed(Values, Op); } ProvenanceAnalysis PA; -- 2.7.4