[llvm] [CodeGen] Use range-based for loops (NFC) (PR #98706)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 19:56:58 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/98706.diff
7 Files Affected:
- (modified) llvm/lib/CodeGen/MachinePipeliner.cpp (+8-8)
- (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+2-2)
- (modified) llvm/lib/CodeGen/SelectOptimize.cpp (+2-2)
- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+2-2)
- (modified) llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp (+2-2)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (+1-3)
- (modified) llvm/lib/CodeGen/StackSlotColoring.cpp (+5-8)
``````````diff
diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp
index 2488f81fee228..497e282bb9768 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -999,8 +999,8 @@ void SwingSchedulerDAG::updatePhiDependences() {
RemoveDeps.push_back(PI);
}
}
- for (int i = 0, e = RemoveDeps.size(); i != e; ++i)
- I.removePred(RemoveDeps[i]);
+ for (const SDep &D : RemoveDeps)
+ I.removePred(D);
}
}
@@ -1041,18 +1041,18 @@ void SwingSchedulerDAG::changeDependences() {
for (const SDep &P : I.Preds)
if (P.getSUnit() == DefSU)
Deps.push_back(P);
- for (int i = 0, e = Deps.size(); i != e; i++) {
- Topo.RemovePred(&I, Deps[i].getSUnit());
- I.removePred(Deps[i]);
+ for (const SDep &D : Deps) {
+ Topo.RemovePred(&I, D.getSUnit());
+ I.removePred(D);
}
// Remove the chain dependence between the instructions.
Deps.clear();
for (auto &P : LastSU->Preds)
if (P.getSUnit() == &I && P.getKind() == SDep::Order)
Deps.push_back(P);
- for (int i = 0, e = Deps.size(); i != e; i++) {
- Topo.RemovePred(LastSU, Deps[i].getSUnit());
- LastSU->removePred(Deps[i]);
+ for (const SDep &D : Deps) {
+ Topo.RemovePred(LastSU, D.getSUnit());
+ LastSU->removePred(D);
}
// Add a dependence between the new instruction and the instruction
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 048b855058328..310050d92d744 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -1664,8 +1664,8 @@ unsigned RAGreedy::tryLocalSplit(const LiveInterval &VirtReg,
// Remove any gaps with regmask clobbers.
if (Matrix->checkRegMaskInterference(VirtReg, PhysReg))
- for (unsigned I = 0, E = RegMaskGaps.size(); I != E; ++I)
- GapWeight[RegMaskGaps[I]] = huge_valf;
+ for (unsigned Gap : RegMaskGaps)
+ GapWeight[Gap] = huge_valf;
// Try to find the best sequence of gaps to close.
// The new spill weight must be larger than any gap interference.
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp
index 0a5f0a861d48b..61341e1f2d04c 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -1071,8 +1071,8 @@ void SelectOptimizeImpl::getExclBackwardsSlice(Instruction *I,
Slice.push(II);
// Explore all the operands of the current instruction to expand the slice.
- for (unsigned k = 0; k < II->getNumOperands(); ++k)
- if (auto *OpI = dyn_cast<Instruction>(II->getOperand(k)))
+ for (Value *Op : II->operand_values())
+ if (auto *OpI = dyn_cast<Instruction>(Op))
Worklist.push(OpI);
}
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 428cdda21cd41..cece76f658307 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -20544,8 +20544,8 @@ bool DAGCombiner::checkMergeStoreCandidatesForDependencies(
// * (Op 3) -> Represents the pre or post-indexing offset (or undef for
// non-indexed stores). Not constant on all targets (e.g. ARM)
// and so can participate in a cycle.
- for (unsigned j = 0; j < N->getNumOperands(); ++j)
- Worklist.push_back(N->getOperand(j).getNode());
+ for (const SDValue &Op : N->op_values())
+ Worklist.push_back(Op.getNode());
}
// Search through DAG. We can stop early if we find a store node.
for (unsigned i = 0; i < NumStores; ++i)
diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
index 36738961382ef..4ce92e156cf85 100644
--- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
@@ -1182,8 +1182,8 @@ EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
append_range(UsedRegs, MCID.implicit_uses());
// In addition to declared implicit uses, we must also check for
// direct RegisterSDNode operands.
- for (unsigned i = 0, e = F->getNumOperands(); i != e; ++i)
- if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(F->getOperand(i))) {
+ for (const SDValue &Op : F->op_values())
+ if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
Register Reg = R->getReg();
if (Reg.isPhysical())
UsedRegs.push_back(Reg);
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 1be93276b6961..9f515739ee048 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -5608,10 +5608,8 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
MVT MidVT = getPromotedVectorElementType(TLI, EltVT, NewEltVT);
SmallVector<SDValue, 8> NewOps;
- for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I) {
- SDValue Op = Node->getOperand(I);
+ for (const SDValue &Op : Node->op_values())
NewOps.push_back(DAG.getNode(ISD::BITCAST, SDLoc(Op), MidVT, Op));
- }
SDLoc SL(Node);
SDValue Concat =
diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp
index 638ae51bc7334..df06577e14e77 100644
--- a/llvm/lib/CodeGen/StackSlotColoring.cpp
+++ b/llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -224,13 +224,10 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
li.incrementWeight(
LiveIntervals::getSpillWeight(false, true, MBFI, MI));
}
- for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(),
- EE = MI.memoperands_end();
- MMOI != EE; ++MMOI) {
- MachineMemOperand *MMO = *MMOI;
+ for (MachineMemOperand *MMO : MI.memoperands()) {
if (const FixedStackPseudoSourceValue *FSV =
- dyn_cast_or_null<FixedStackPseudoSourceValue>(
- MMO->getPseudoValue())) {
+ dyn_cast_or_null<FixedStackPseudoSourceValue>(
+ MMO->getPseudoValue())) {
int FI = FSV->getFrameIndex();
if (FI >= 0)
SSRefs[FI].push_back(MMO);
@@ -552,8 +549,8 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
Next = -1;
SSIntervals.clear();
- for (unsigned i = 0, e = SSRefs.size(); i != e; ++i)
- SSRefs[i].clear();
+ for (auto &RefMMOs : SSRefs)
+ RefMMOs.clear();
SSRefs.clear();
OrigAlignments.clear();
OrigSizes.clear();
``````````
</details>
https://github.com/llvm/llvm-project/pull/98706
More information about the llvm-commits
mailing list