Skip to content

[CodeGen] Use range-based for loops (NFC) #96777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
ScalarRetTy = RetTy->getScalarType();
}
SmallVector<Type *, 4> ScalarTys;
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
Type *Ty = Tys[i];
for (Type *Ty : Tys) {
if (auto *VTy = dyn_cast<VectorType>(Ty)) {
if (!SkipScalarizationCost)
ScalarizationCost += getScalarizationOverhead(
Expand Down Expand Up @@ -2368,17 +2367,16 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {

unsigned ScalarCalls = cast<FixedVectorType>(RetVTy)->getNumElements();
SmallVector<Type *, 4> ScalarTys;
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
Type *Ty = Tys[i];
for (Type *Ty : Tys) {
if (Ty->isVectorTy())
Ty = Ty->getScalarType();
ScalarTys.push_back(Ty);
}
IntrinsicCostAttributes Attrs(IID, RetTy->getScalarType(), ScalarTys, FMF);
InstructionCost ScalarCost =
thisT()->getIntrinsicInstrCost(Attrs, CostKind);
for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
if (auto *VTy = dyn_cast<VectorType>(Tys[i])) {
for (Type *Ty : Tys) {
if (auto *VTy = dyn_cast<VectorType>(Ty)) {
if (!ICA.skipScalarizationCost())
ScalarizationCost += getScalarizationOverhead(
VTy, /*Insert*/ false, /*Extract*/ true, CostKind);
Expand Down
20 changes: 8 additions & 12 deletions llvm/lib/CodeGen/AsmPrinter/DIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
ID.AddInteger(unsigned(Children));

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

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

// For each attribute description.
for (unsigned i = 0, N = Data.size(); i < N; ++i) {
const DIEAbbrevData &AttrData = Data[i];

for (const DIEAbbrevData &AttrData : Data) {
// Emit attribute type.
AP->emitULEB128(AttrData.getAttribute(),
dwarf::AttributeString(AttrData.getAttribute()).data());
Expand Down Expand Up @@ -109,14 +107,12 @@ void DIEAbbrev::print(raw_ostream &O) const {
<< dwarf::ChildrenString(Children)
<< '\n';

for (unsigned i = 0, N = Data.size(); i < N; ++i) {
O << " "
<< dwarf::AttributeString(Data[i].getAttribute())
<< " "
<< dwarf::FormEncodingString(Data[i].getForm());
for (const DIEAbbrevData &D : Data) {
O << " " << dwarf::AttributeString(D.getAttribute()) << " "
<< dwarf::FormEncodingString(D.getForm());

if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
O << " " << Data[i].getValue();
if (D.getForm() == dwarf::DW_FORM_implicit_const)
O << " " << D.getValue();

O << '\n';
}
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ class MemLocFragmentFill {
DenseMap<BasicBlock *, unsigned int> BBToOrder;
{ // Init OrderToBB and BBToOrder.
unsigned int RPONumber = 0;
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
OrderToBB[RPONumber] = *RI;
BBToOrder[*RI] = RPONumber;
for (BasicBlock *BB : RPOT) {
OrderToBB[RPONumber] = BB;
BBToOrder[BB] = RPONumber;
Worklist.push(RPONumber);
++RPONumber;
}
Expand Down Expand Up @@ -2312,9 +2312,9 @@ bool AssignmentTrackingLowering::run(FunctionVarLocsBuilder *FnVarLocsBuilder) {
DenseMap<BasicBlock *, unsigned int> BBToOrder;
{ // Init OrderToBB and BBToOrder.
unsigned int RPONumber = 0;
for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
OrderToBB[RPONumber] = *RI;
BBToOrder[*RI] = RPONumber;
for (BasicBlock *BB : RPOT) {
OrderToBB[RPONumber] = BB;
BBToOrder[BB] = RPONumber;
Worklist.push(RPONumber);
++RPONumber;
}
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/CodeGen/EarlyIfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,7 @@ void SSAIfConv::replacePHIInstrs() {
DebugLoc HeadDL = FirstTerm->getDebugLoc();

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

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

LLVM_DEBUG(dbgs() << "If-converting " << *PI.PHI);
Expand Down Expand Up @@ -962,8 +960,7 @@ bool EarlyIfConverter::shouldConvertIf() {
CriticalPathInfo TBlock{};
CriticalPathInfo FBlock{};
bool ShouldConvert = true;
for (unsigned i = 0, e = IfConv.PHIs.size(); i != e; ++i) {
SSAIfConv::PHIInfo &PI = IfConv.PHIs[i];
for (SSAIfConv::PHIInfo &PI : IfConv.PHIs) {
unsigned Slack = TailTrace.getInstrSlack(*PI.PHI);
unsigned MaxDepth = Slack + TailTrace.getInstrCycles(*PI.PHI).Depth;
LLVM_DEBUG(dbgs() << "Slack " << Slack << ":\t" << *PI.PHI);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/LexicalScopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ LLVM_DUMP_METHOD void LexicalScope::dump(unsigned Indent) const {

if (!Children.empty())
err << std::string(Indent + 2, ' ') << "Children ...\n";
for (unsigned i = 0, e = Children.size(); i != e; ++i)
if (Children[i] != this)
Children[i]->dump(Indent + 2);
for (const LexicalScope *Child : Children)
if (Child != this)
Child->dump(Indent + 2);
}
#endif
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,9 @@ void LDVImpl::print(raw_ostream &OS) {
#endif

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

UserValue *
Expand Down Expand Up @@ -1254,9 +1254,9 @@ void LDVImpl::computeIntervals() {
LexicalScopes LS;
LS.initialize(*MF);

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

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/PeepholeOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,7 @@ optimizeExtInstr(MachineInstr &MI, MachineBasicBlock &MBB,
PHIBBs.insert(UI.getParent());

const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
for (unsigned i = 0, e = Uses.size(); i != e; ++i) {
MachineOperand *UseMO = Uses[i];
for (MachineOperand *UseMO : Uses) {
MachineInstr *UseMI = UseMO->getParent();
MachineBasicBlock *UseMBB = UseMI->getParent();
if (PHIBBs.count(UseMBB))
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/RegisterCoalescer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,8 +1855,8 @@ void RegisterCoalescer::updateRegDefsUses(Register SrcReg, Register DstReg,
Reads = DstInt->liveAt(LIS->getInstructionIndex(*UseMI));

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

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

void RegisterCoalescer::coalesceLocals() {
copyCoalesceWorkList(LocalWorkList);
for (unsigned j = 0, je = LocalWorkList.size(); j != je; ++j) {
if (LocalWorkList[j])
WorkList.push_back(LocalWorkList[j]);
for (MachineInstr *MI : LocalWorkList) {
if (MI)
WorkList.push_back(MI);
}
LocalWorkList.clear();
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ void DAGTypeLegalizer::PerformExpensiveChecks() {

#ifndef NDEBUG
// Checked that NewNodes are only used by other NewNodes.
for (unsigned i = 0, e = NewNodes.size(); i != e; ++i) {
SDNode *N = NewNodes[i];
for (SDNode *N : NewNodes) {
for (SDNode *U : N->uses())
assert(U->getNodeId() == NewNode && "NewNode used by non-NewNode!");
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ void ScheduleDAGLinearize::Schedule() {
++DAGSize;
}

for (unsigned i = 0, e = Glues.size(); i != e; ++i) {
SDNode *Glue = Glues[i];
for (SDNode *Glue : Glues) {
SDNode *GUser = GluedMap[Glue];
unsigned Degree = Glue->getNodeId();
unsigned UDegree = GUser->getNodeId();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/StackSlotColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {

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

// Rewrite all MO_FrameIndex operands. Look for dead stores.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/TailDuplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ bool TailDuplicator::tailDuplicateAndUpdate(

// Eliminate some of the copies inserted by tail duplication to maintain
// SSA form.
for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
MachineInstr *Copy = Copies[i];
for (MachineInstr *Copy : Copies) {
if (!Copy->isCopy())
continue;
Register Dst = Copy->getOperand(0).getReg();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/VLIWMachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ bool VLIWResourceModel::isResourceAvailable(SUnit *SU, bool IsTop) {
// Now see if there are no other dependencies to instructions already
// in the packet.
if (IsTop) {
for (unsigned i = 0, e = Packet.size(); i != e; ++i)
if (hasDependence(Packet[i], SU))
for (const SUnit *U : Packet)
if (hasDependence(U, SU))
return false;
} else {
for (unsigned i = 0, e = Packet.size(); i != e; ++i)
if (hasDependence(SU, Packet[i]))
for (const SUnit *U : Packet)
if (hasDependence(SU, U))
return false;
}
return true;
Expand Down
Loading