[llvm] 7d8c2d1 - [llvm] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 3 23:27:58 PDT 2022
Author: Kazu Hirata
Date: 2022-09-03T23:27:25-07:00
New Revision: 7d8c2d17eb3c1631ce33f1497a6d9ca76bfbfd44
URL: https://github.com/llvm/llvm-project/commit/7d8c2d17eb3c1631ce33f1497a6d9ca76bfbfd44
DIFF: https://github.com/llvm/llvm-project/commit/7d8c2d17eb3c1631ce33f1497a6d9ca76bfbfd44.diff
LOG: [llvm] Use range-based for loops (NFC)
Identified with modernize-loop-convert.
Added:
Modified:
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/XCore/XCoreISelLowering.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index ed4cfe369a60a..f776cdeecac23 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3394,8 +3394,8 @@ OpenMPIRBuilder::createOrderedDepend(const LocationDescription &Loc,
InsertPointTy AllocaIP, unsigned NumLoops,
ArrayRef<llvm::Value *> StoreValues,
const Twine &Name, bool IsDependSource) {
- for (size_t I = 0; I < StoreValues.size(); I++)
- assert(StoreValues[I]->getType()->isIntegerTy(64) &&
+ for (const llvm::Value *SV : StoreValues)
+ assert(SV->getType()->isIntegerTy(64) &&
"OpenMP runtime requires depend vec with i64 type");
if (!updateToLocation(Loc))
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index edf7bf53bb6cb..c949c5fbb7487 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -9837,9 +9837,9 @@ static SDValue ReconstructTruncateFromBuildVector(SDValue V, SelectionDAG &DAG)
SDValue Trunc[4] = {
V.getOperand(0).getOperand(0), V.getOperand(4).getOperand(0),
V.getOperand(8).getOperand(0), V.getOperand(12).getOperand(0)};
- for (int I = 0; I < 4; I++)
- if (Trunc[I].getValueType() == MVT::v4i32)
- Trunc[I] = DAG.getNode(ISD::TRUNCATE, DL, MVT::v4i16, Trunc[I]);
+ for (SDValue &V : Trunc)
+ if (V.getValueType() == MVT::v4i32)
+ V = DAG.getNode(ISD::TRUNCATE, DL, MVT::v4i16, V);
SDValue Concat0 =
DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v8i16, Trunc[0], Trunc[1]);
SDValue Concat1 =
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
index 6723574aeba4a..ae0329f13b3aa 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
@@ -765,10 +765,9 @@ void MFMASmallGemmOpt::applyIGLPStrategy(
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups) {
// Count the number of MFMA instructions.
unsigned MFMACount = 0;
- for (auto I = DAG->begin(), E = DAG->end(); I != E; ++I) {
- if (TII->isMFMA(*I))
+ for (const MachineInstr &I : *DAG)
+ if (TII->isMFMA(I))
++MFMACount;
- }
const unsigned PipelineSyncID = 0;
SchedGroup *SG = nullptr;
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index 8843bd8cae8af..1015399d381f7 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -13307,9 +13307,8 @@ static bool findConsecutiveLoad(LoadSDNode *LD, SelectionDAG &DAG) {
Visited.clear();
Queue.clear();
- for (SmallSet<SDNode *, 16>::iterator I = LoadRoots.begin(),
- IE = LoadRoots.end(); I != IE; ++I) {
- Queue.push_back(*I);
+ for (SDNode *I : LoadRoots) {
+ Queue.push_back(I);
while (!Queue.empty()) {
SDNode *LoadRoot = Queue.pop_back_val();
@@ -15915,8 +15914,8 @@ Align PPCTargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
// boundary so that the entire loop fits in one instruction-cache line.
uint64_t LoopSize = 0;
for (auto I = ML->block_begin(), IE = ML->block_end(); I != IE; ++I)
- for (auto J = (*I)->begin(), JE = (*I)->end(); J != JE; ++J) {
- LoopSize += TII->getInstSizeInBytes(*J);
+ for (const MachineInstr &J : **I) {
+ LoopSize += TII->getInstSizeInBytes(J);
if (LoopSize > 32)
break;
}
diff --git a/llvm/lib/Target/XCore/XCoreISelLowering.cpp b/llvm/lib/Target/XCore/XCoreISelLowering.cpp
index 70a1901bb04f3..758532106a415 100644
--- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp
+++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp
@@ -1383,23 +1383,21 @@ SDValue XCoreTargetLowering::LowerCCCArguments(
// Aggregates passed "byVal" need to be copied by the callee.
// The callee will use a pointer to this copy, rather than the original
// pointer.
- for (SmallVectorImpl<ArgDataPair>::const_iterator ArgDI = ArgData.begin(),
- ArgDE = ArgData.end();
- ArgDI != ArgDE; ++ArgDI) {
- if (ArgDI->Flags.isByVal() && ArgDI->Flags.getByValSize()) {
- unsigned Size = ArgDI->Flags.getByValSize();
+ for (const ArgDataPair &ArgDI : ArgData) {
+ if (ArgDI.Flags.isByVal() && ArgDI.Flags.getByValSize()) {
+ unsigned Size = ArgDI.Flags.getByValSize();
Align Alignment =
- std::max(Align(StackSlotSize), ArgDI->Flags.getNonZeroByValAlign());
+ std::max(Align(StackSlotSize), ArgDI.Flags.getNonZeroByValAlign());
// Create a new object on the stack and copy the pointee into it.
int FI = MFI.CreateStackObject(Size, Alignment, false);
SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
InVals.push_back(FIN);
MemOps.push_back(DAG.getMemcpy(
- Chain, dl, FIN, ArgDI->SDV, DAG.getConstant(Size, dl, MVT::i32),
+ Chain, dl, FIN, ArgDI.SDV, DAG.getConstant(Size, dl, MVT::i32),
Alignment, false, false, false, MachinePointerInfo(),
MachinePointerInfo()));
} else {
- InVals.push_back(ArgDI->SDV);
+ InVals.push_back(ArgDI.SDV);
}
}
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 81f1fa1b5199a..9ab8014e60d63 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1126,13 +1126,13 @@ SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc());
// Move the edges from Preds to point to NewBB instead of BB.
- for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+ for (BasicBlock *Pred : Preds) {
// This is slightly more strict than necessary; the minimum requirement
// is that there be no more than one indirectbr branching to BB. And
// all BlockAddress uses would need to be updated.
- assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
+ assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
"Cannot split an edge from an IndirectBrInst");
- Preds[i]->getTerminator()->replaceSuccessorWith(BB, NewBB);
+ Pred->getTerminator()->replaceSuccessorWith(BB, NewBB);
}
// Insert a new PHI node into NewBB for every PHI node in BB and that new PHI
@@ -1208,13 +1208,13 @@ static void SplitLandingPadPredecessorsImpl(
BI1->setDebugLoc(OrigBB->getFirstNonPHI()->getDebugLoc());
// Move the edges from Preds to point to NewBB1 instead of OrigBB.
- for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+ for (BasicBlock *Pred : Preds) {
// This is slightly more strict than necessary; the minimum requirement
// is that there be no more than one indirectbr branching to BB. And
// all BlockAddress uses would need to be updated.
- assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
+ assert(!isa<IndirectBrInst>(Pred->getTerminator()) &&
"Cannot split an edge from an IndirectBrInst");
- Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
+ Pred->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1);
}
bool HasLoopExit = false;
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 0dab4f4d69ef3..d61cb0b2469c0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -831,8 +831,8 @@ static bool ValuesOverlap(std::vector<ValueEqualityComparisonCase> &C1,
if (V1->size() == 1) {
// Just scan V2.
ConstantInt *TheVal = (*V1)[0].Value;
- for (unsigned i = 0, e = V2->size(); i != e; ++i)
- if (TheVal == (*V2)[i].Value)
+ for (const ValueEqualityComparisonCase &VECC : *V2)
+ if (TheVal == VECC.Value)
return true;
}
@@ -2825,11 +2825,8 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
// Consider any sink candidates which are only used in ThenBB as costs for
// speculation. Note, while we iterate over a DenseMap here, we are summing
// and so iteration order isn't significant.
- for (SmallDenseMap<Instruction *, unsigned, 4>::iterator
- I = SinkCandidateUseCounts.begin(),
- E = SinkCandidateUseCounts.end();
- I != E; ++I)
- if (I->first->hasNUses(I->second)) {
+ for (const auto &[Inst, Count] : SinkCandidateUseCounts)
+ if (Inst->hasNUses(Count)) {
++SpeculatedInstructions;
if (SpeculatedInstructions > 1)
return false;
More information about the llvm-commits
mailing list