Skip to content

Commit dae061f

Browse files
[CodeGen] Use range-based for loops (NFC) (#96777)
1 parent 1fa9f50 commit dae061f

13 files changed

+45
-58
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,8 +1945,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19451945
ScalarRetTy = RetTy->getScalarType();
19461946
}
19471947
SmallVector<Type *, 4> ScalarTys;
1948-
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
1949-
Type *Ty = Tys[i];
1948+
for (Type *Ty : Tys) {
19501949
if (auto *VTy = dyn_cast<VectorType>(Ty)) {
19511950
if (!SkipScalarizationCost)
19521951
ScalarizationCost += getScalarizationOverhead(
@@ -2368,17 +2367,16 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23682367

23692368
unsigned ScalarCalls = cast<FixedVectorType>(RetVTy)->getNumElements();
23702369
SmallVector<Type *, 4> ScalarTys;
2371-
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
2372-
Type *Ty = Tys[i];
2370+
for (Type *Ty : Tys) {
23732371
if (Ty->isVectorTy())
23742372
Ty = Ty->getScalarType();
23752373
ScalarTys.push_back(Ty);
23762374
}
23772375
IntrinsicCostAttributes Attrs(IID, RetTy->getScalarType(), ScalarTys, FMF);
23782376
InstructionCost ScalarCost =
23792377
thisT()->getIntrinsicInstrCost(Attrs, CostKind);
2380-
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
2381-
if (auto *VTy = dyn_cast<VectorType>(Tys[i])) {
2378+
for (Type *Ty : Tys) {
2379+
if (auto *VTy = dyn_cast<VectorType>(Ty)) {
23822380
if (!ICA.skipScalarizationCost())
23832381
ScalarizationCost += getScalarizationOverhead(
23842382
VTy, /*Insert*/ false, /*Extract*/ true, CostKind);

llvm/lib/CodeGen/AsmPrinter/DIE.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
5353
ID.AddInteger(unsigned(Children));
5454

5555
// For each attribute description.
56-
for (unsigned i = 0, N = Data.size(); i < N; ++i)
57-
Data[i].Profile(ID);
56+
for (const DIEAbbrevData &D : Data)
57+
D.Profile(ID);
5858
}
5959

6060
/// Emit - Print the abbreviation using the specified asm printer.
@@ -67,9 +67,7 @@ void DIEAbbrev::Emit(const AsmPrinter *AP) const {
6767
AP->emitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
6868

6969
// For each attribute description.
70-
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
71-
const DIEAbbrevData &AttrData = Data[i];
72-
70+
for (const DIEAbbrevData &AttrData : Data) {
7371
// Emit attribute type.
7472
AP->emitULEB128(AttrData.getAttribute(),
7573
dwarf::AttributeString(AttrData.getAttribute()).data());
@@ -109,14 +107,12 @@ void DIEAbbrev::print(raw_ostream &O) const {
109107
<< dwarf::ChildrenString(Children)
110108
<< '\n';
111109

112-
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
113-
O << " "
114-
<< dwarf::AttributeString(Data[i].getAttribute())
115-
<< " "
116-
<< dwarf::FormEncodingString(Data[i].getForm());
110+
for (const DIEAbbrevData &D : Data) {
111+
O << " " << dwarf::AttributeString(D.getAttribute()) << " "
112+
<< dwarf::FormEncodingString(D.getForm());
117113

118-
if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
119-
O << " " << Data[i].getValue();
114+
if (D.getForm() == dwarf::DW_FORM_implicit_const)
115+
O << " " << D.getValue();
120116

121117
O << '\n';
122118
}

llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ class MemLocFragmentFill {
891891
DenseMap<BasicBlock *, unsigned int> BBToOrder;
892892
{ // Init OrderToBB and BBToOrder.
893893
unsigned int RPONumber = 0;
894-
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
895-
OrderToBB[RPONumber] = *RI;
896-
BBToOrder[*RI] = RPONumber;
894+
for (BasicBlock *BB : RPOT) {
895+
OrderToBB[RPONumber] = BB;
896+
BBToOrder[BB] = RPONumber;
897897
Worklist.push(RPONumber);
898898
++RPONumber;
899899
}
@@ -2312,9 +2312,9 @@ bool AssignmentTrackingLowering::run(FunctionVarLocsBuilder *FnVarLocsBuilder) {
23122312
DenseMap<BasicBlock *, unsigned int> BBToOrder;
23132313
{ // Init OrderToBB and BBToOrder.
23142314
unsigned int RPONumber = 0;
2315-
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
2316-
OrderToBB[RPONumber] = *RI;
2317-
BBToOrder[*RI] = RPONumber;
2315+
for (BasicBlock *BB : RPOT) {
2316+
OrderToBB[RPONumber] = BB;
2317+
BBToOrder[BB] = RPONumber;
23182318
Worklist.push(RPONumber);
23192319
++RPONumber;
23202320
}

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ void SSAIfConv::replacePHIInstrs() {
617617
DebugLoc HeadDL = FirstTerm->getDebugLoc();
618618

619619
// Convert all PHIs to select instructions inserted before FirstTerm.
620-
for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
621-
PHIInfo &PI = PHIs[i];
620+
for (PHIInfo &PI : PHIs) {
622621
LLVM_DEBUG(dbgs() << "If-converting " << *PI.PHI);
623622
Register DstReg = PI.PHI->getOperand(0).getReg();
624623
if (hasSameValue(*MRI, TII, PI.TReg, PI.FReg)) {
@@ -645,8 +644,7 @@ void SSAIfConv::rewritePHIOperands() {
645644
DebugLoc HeadDL = FirstTerm->getDebugLoc();
646645

647646
// Convert all PHIs to select instructions inserted before FirstTerm.
648-
for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
649-
PHIInfo &PI = PHIs[i];
647+
for (PHIInfo &PI : PHIs) {
650648
unsigned DstReg = 0;
651649

652650
LLVM_DEBUG(dbgs() << "If-converting " << *PI.PHI);
@@ -962,8 +960,7 @@ bool EarlyIfConverter::shouldConvertIf() {
962960
CriticalPathInfo TBlock{};
963961
CriticalPathInfo FBlock{};
964962
bool ShouldConvert = true;
965-
for (unsigned i = 0, e = IfConv.PHIs.size(); i != e; ++i) {
966-
SSAIfConv::PHIInfo &PI = IfConv.PHIs[i];
963+
for (SSAIfConv::PHIInfo &PI : IfConv.PHIs) {
967964
unsigned Slack = TailTrace.getInstrSlack(*PI.PHI);
968965
unsigned MaxDepth = Slack + TailTrace.getInstrCycles(*PI.PHI).Depth;
969966
LLVM_DEBUG(dbgs() << "Slack " << Slack << ":\t" << *PI.PHI);

llvm/lib/CodeGen/LexicalScopes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ LLVM_DUMP_METHOD void LexicalScope::dump(unsigned Indent) const {
340340

341341
if (!Children.empty())
342342
err << std::string(Indent + 2, ' ') << "Children ...\n";
343-
for (unsigned i = 0, e = Children.size(); i != e; ++i)
344-
if (Children[i] != this)
345-
Children[i]->dump(Indent + 2);
343+
for (const LexicalScope *Child : Children)
344+
if (Child != this)
345+
Child->dump(Indent + 2);
346346
}
347347
#endif

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ void LDVImpl::print(raw_ostream &OS) {
764764
#endif
765765

766766
void UserValue::mapVirtRegs(LDVImpl *LDV) {
767-
for (unsigned i = 0, e = locations.size(); i != e; ++i)
768-
if (locations[i].isReg() && locations[i].getReg().isVirtual())
769-
LDV->mapVirtReg(locations[i].getReg(), this);
767+
for (const MachineOperand &MO : locations)
768+
if (MO.isReg() && MO.getReg().isVirtual())
769+
LDV->mapVirtReg(MO.getReg(), this);
770770
}
771771

772772
UserValue *
@@ -1254,9 +1254,9 @@ void LDVImpl::computeIntervals() {
12541254
LexicalScopes LS;
12551255
LS.initialize(*MF);
12561256

1257-
for (unsigned i = 0, e = userValues.size(); i != e; ++i) {
1258-
userValues[i]->computeIntervals(MF->getRegInfo(), *TRI, *LIS, LS);
1259-
userValues[i]->mapVirtRegs(this);
1257+
for (const auto &UV : userValues) {
1258+
UV->computeIntervals(MF->getRegInfo(), *TRI, *LIS, LS);
1259+
UV->mapVirtRegs(this);
12601260
}
12611261
}
12621262

llvm/lib/CodeGen/PeepholeOptimizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ optimizeExtInstr(MachineInstr &MI, MachineBasicBlock &MBB,
615615
PHIBBs.insert(UI.getParent());
616616

617617
const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
618-
for (unsigned i = 0, e = Uses.size(); i != e; ++i) {
619-
MachineOperand *UseMO = Uses[i];
618+
for (MachineOperand *UseMO : Uses) {
620619
MachineInstr *UseMI = UseMO->getParent();
621620
MachineBasicBlock *UseMBB = UseMI->getParent();
622621
if (PHIBBs.count(UseMBB))

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,8 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
18551855
Reads = DstInt->liveAt(LIS->getInstructionIndex(*UseMI));
18561856

18571857
// Replace SrcReg with DstReg in all UseMI operands.
1858-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
1859-
MachineOperand &MO = UseMI->getOperand(Ops[i]);
1858+
for (unsigned Op : Ops) {
1859+
MachineOperand &MO = UseMI->getOperand(Op);
18601860

18611861
// Adjust <undef> flags in case of sub-register joins. We don't want to
18621862
// turn a full def into a read-modify-write sub-register def and vice
@@ -4136,9 +4136,9 @@ RegisterCoalescer::copyCoalesceInMBB(MachineBasicBlock *MBB) {
41364136

41374137
void RegisterCoalescer::coalesceLocals() {
41384138
copyCoalesceWorkList(LocalWorkList);
4139-
for (unsigned j = 0, je = LocalWorkList.size(); j != je; ++j) {
4140-
if (LocalWorkList[j])
4141-
WorkList.push_back(LocalWorkList[j]);
4139+
for (MachineInstr *MI : LocalWorkList) {
4140+
if (MI)
4141+
WorkList.push_back(MI);
41424142
}
41434143
LocalWorkList.clear();
41444144
}

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ void DAGTypeLegalizer::PerformExpensiveChecks() {
188188

189189
#ifndef NDEBUG
190190
// Checked that NewNodes are only used by other NewNodes.
191-
for (unsigned i = 0, e = NewNodes.size(); i != e; ++i) {
192-
SDNode *N = NewNodes[i];
191+
for (SDNode *N : NewNodes) {
193192
for (SDNode *U : N->uses())
194193
assert(U->getNodeId() == NewNode && "NewNode used by non-NewNode!");
195194
}

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ void ScheduleDAGLinearize::Schedule() {
748748
++DAGSize;
749749
}
750750

751-
for (unsigned i = 0, e = Glues.size(); i != e; ++i) {
752-
SDNode *Glue = Glues[i];
751+
for (SDNode *Glue : Glues) {
753752
SDNode *GUser = GluedMap[Glue];
754753
unsigned Degree = Glue->getNodeId();
755754
unsigned UDegree = GUser->getNodeId();

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
400400

401401
const PseudoSourceValue *NewSV = MF.getPSVManager().getFixedStack(NewFI);
402402
SmallVectorImpl<MachineMemOperand *> &RefMMOs = SSRefs[SS];
403-
for (unsigned i = 0, e = RefMMOs.size(); i != e; ++i)
404-
RefMMOs[i]->setValue(NewSV);
403+
for (MachineMemOperand *MMO : RefMMOs)
404+
MMO->setValue(NewSV);
405405
}
406406

407407
// Rewrite all MO_FrameIndex operands. Look for dead stores.

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ bool TailDuplicator::tailDuplicateAndUpdate(
253253

254254
// Eliminate some of the copies inserted by tail duplication to maintain
255255
// SSA form.
256-
for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
257-
MachineInstr *Copy = Copies[i];
256+
for (MachineInstr *Copy : Copies) {
258257
if (!Copy->isCopy())
259258
continue;
260259
Register Dst = Copy->getOperand(0).getReg();

llvm/lib/CodeGen/VLIWMachineScheduler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ bool VLIWResourceModel::isResourceAvailable(SUnit *SU, bool IsTop) {
130130
// Now see if there are no other dependencies to instructions already
131131
// in the packet.
132132
if (IsTop) {
133-
for (unsigned i = 0, e = Packet.size(); i != e; ++i)
134-
if (hasDependence(Packet[i], SU))
133+
for (const SUnit *U : Packet)
134+
if (hasDependence(U, SU))
135135
return false;
136136
} else {
137-
for (unsigned i = 0, e = Packet.size(); i != e; ++i)
138-
if (hasDependence(SU, Packet[i]))
137+
for (const SUnit *U : Packet)
138+
if (hasDependence(SU, U))
139139
return false;
140140
}
141141
return true;

0 commit comments

Comments
 (0)