Skip to content

Commit 66cd2e0

Browse files
[CodeGen] Use range-based for loops (NFC) (#98706)
1 parent a4f8705 commit 66cd2e0

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,8 @@ void SwingSchedulerDAG::updatePhiDependences() {
999999
RemoveDeps.push_back(PI);
10001000
}
10011001
}
1002-
for (int i = 0, e = RemoveDeps.size(); i != e; ++i)
1003-
I.removePred(RemoveDeps[i]);
1002+
for (const SDep &D : RemoveDeps)
1003+
I.removePred(D);
10041004
}
10051005
}
10061006

@@ -1041,18 +1041,18 @@ void SwingSchedulerDAG::changeDependences() {
10411041
for (const SDep &P : I.Preds)
10421042
if (P.getSUnit() == DefSU)
10431043
Deps.push_back(P);
1044-
for (int i = 0, e = Deps.size(); i != e; i++) {
1045-
Topo.RemovePred(&I, Deps[i].getSUnit());
1046-
I.removePred(Deps[i]);
1044+
for (const SDep &D : Deps) {
1045+
Topo.RemovePred(&I, D.getSUnit());
1046+
I.removePred(D);
10471047
}
10481048
// Remove the chain dependence between the instructions.
10491049
Deps.clear();
10501050
for (auto &P : LastSU->Preds)
10511051
if (P.getSUnit() == &I && P.getKind() == SDep::Order)
10521052
Deps.push_back(P);
1053-
for (int i = 0, e = Deps.size(); i != e; i++) {
1054-
Topo.RemovePred(LastSU, Deps[i].getSUnit());
1055-
LastSU->removePred(Deps[i]);
1053+
for (const SDep &D : Deps) {
1054+
Topo.RemovePred(LastSU, D.getSUnit());
1055+
LastSU->removePred(D);
10561056
}
10571057

10581058
// Add a dependence between the new instruction and the instruction

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,8 @@ unsigned RAGreedy::tryLocalSplit(const LiveInterval &VirtReg,
16641664

16651665
// Remove any gaps with regmask clobbers.
16661666
if (Matrix->checkRegMaskInterference(VirtReg, PhysReg))
1667-
for (unsigned I = 0, E = RegMaskGaps.size(); I != E; ++I)
1668-
GapWeight[RegMaskGaps[I]] = huge_valf;
1667+
for (unsigned Gap : RegMaskGaps)
1668+
GapWeight[Gap] = huge_valf;
16691669

16701670
// Try to find the best sequence of gaps to close.
16711671
// The new spill weight must be larger than any gap interference.

llvm/lib/CodeGen/SelectOptimize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ void SelectOptimizeImpl::getExclBackwardsSlice(Instruction *I,
10711071
Slice.push(II);
10721072

10731073
// Explore all the operands of the current instruction to expand the slice.
1074-
for (unsigned k = 0; k < II->getNumOperands(); ++k)
1075-
if (auto *OpI = dyn_cast<Instruction>(II->getOperand(k)))
1074+
for (Value *Op : II->operand_values())
1075+
if (auto *OpI = dyn_cast<Instruction>(Op))
10761076
Worklist.push(OpI);
10771077
}
10781078
}

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20544,8 +20544,8 @@ bool DAGCombiner::checkMergeStoreCandidatesForDependencies(
2054420544
// * (Op 3) -> Represents the pre or post-indexing offset (or undef for
2054520545
// non-indexed stores). Not constant on all targets (e.g. ARM)
2054620546
// and so can participate in a cycle.
20547-
for (unsigned j = 0; j < N->getNumOperands(); ++j)
20548-
Worklist.push_back(N->getOperand(j).getNode());
20547+
for (const SDValue &Op : N->op_values())
20548+
Worklist.push_back(Op.getNode());
2054920549
}
2055020550
// Search through DAG. We can stop early if we find a store node.
2055120551
for (unsigned i = 0; i < NumStores; ++i)

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,8 @@ EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
11821182
append_range(UsedRegs, MCID.implicit_uses());
11831183
// In addition to declared implicit uses, we must also check for
11841184
// direct RegisterSDNode operands.
1185-
for (unsigned i = 0, e = F->getNumOperands(); i != e; ++i)
1186-
if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(F->getOperand(i))) {
1185+
for (const SDValue &Op : F->op_values())
1186+
if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
11871187
Register Reg = R->getReg();
11881188
if (Reg.isPhysical())
11891189
UsedRegs.push_back(Reg);

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,10 +5608,8 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
56085608
MVT MidVT = getPromotedVectorElementType(TLI, EltVT, NewEltVT);
56095609

56105610
SmallVector<SDValue, 8> NewOps;
5611-
for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I) {
5612-
SDValue Op = Node->getOperand(I);
5611+
for (const SDValue &Op : Node->op_values())
56135612
NewOps.push_back(DAG.getNode(ISD::BITCAST, SDLoc(Op), MidVT, Op));
5614-
}
56155613

56165614
SDLoc SL(Node);
56175615
SDValue Concat =

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,10 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
224224
li.incrementWeight(
225225
LiveIntervals::getSpillWeight(false, true, MBFI, MI));
226226
}
227-
for (MachineInstr::mmo_iterator MMOI = MI.memoperands_begin(),
228-
EE = MI.memoperands_end();
229-
MMOI != EE; ++MMOI) {
230-
MachineMemOperand *MMO = *MMOI;
227+
for (MachineMemOperand *MMO : MI.memoperands()) {
231228
if (const FixedStackPseudoSourceValue *FSV =
232-
dyn_cast_or_null<FixedStackPseudoSourceValue>(
233-
MMO->getPseudoValue())) {
229+
dyn_cast_or_null<FixedStackPseudoSourceValue>(
230+
MMO->getPseudoValue())) {
234231
int FI = FSV->getFrameIndex();
235232
if (FI >= 0)
236233
SSRefs[FI].push_back(MMO);
@@ -552,8 +549,8 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
552549
Next = -1;
553550

554551
SSIntervals.clear();
555-
for (unsigned i = 0, e = SSRefs.size(); i != e; ++i)
556-
SSRefs[i].clear();
552+
for (auto &RefMMOs : SSRefs)
553+
RefMMOs.clear();
557554
SSRefs.clear();
558555
OrigAlignments.clear();
559556
OrigSizes.clear();

0 commit comments

Comments
 (0)