[llvm] feb40a3 - [llvm] Use range-based for loops with instructions (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 14 19:41:04 PST 2021
Author: Kazu Hirata
Date: 2021-11-14T19:40:48-08:00
New Revision: feb40a3a475c1f87182f991409f4b77176415c9b
URL: https://github.com/llvm/llvm-project/commit/feb40a3a475c1f87182f991409f4b77176415c9b
DIFF: https://github.com/llvm/llvm-project/commit/feb40a3a475c1f87182f991409f4b77176415c9b.diff
LOG: [llvm] Use range-based for loops with instructions (NFC)
Added:
Modified:
llvm/lib/CodeGen/AtomicExpandPass.cpp
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysisEvaluator.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 1297f99698d8b..4838f6da750dd 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<FenceInst>(I))
- AtomicInsts.push_back(I);
- }
+ for (Instruction &I : instructions(F))
+ if (I.isAtomic() && !isa<FenceInst>(&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 401f988a18793..03638bcab4b9f 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<CallBase>(I)) {
+ if (auto *Call = dyn_cast<CallBase>(&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<LoadInst>(I)) {
+ } else if (LoadInst *LI = dyn_cast<LoadInst>(&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<StoreInst>(I)) {
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(&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<VAArgInst>(I)) {
+ } else if (VAArgInst *VI = dyn_cast<VAArgInst>(&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 d2121dcebe913..6b074ac5adab1 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<CallInst>(Inst)->getArgOperand(0);
- LLVM_DEBUG(dbgs() << "ObjCARCExpand: Old = " << *Inst
+ Value *Value = cast<CallInst>(&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 6fdfe787d4386..fe637ee066a42 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;
More information about the llvm-commits
mailing list