Skip to content

[AMDGPU] Use range-based for loops. NFC. #99047

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
merged 2 commits into from
Jul 17, 2024
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
8 changes: 2 additions & 6 deletions llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,9 @@ class SchedGroup {
// Returns true if the SU matches all rules
bool allowedByRules(const SUnit *SU,
SmallVectorImpl<SchedGroup> &SyncPipe) const {
if (Rules.empty())
return true;
for (size_t I = 0; I < Rules.size(); I++) {
auto TheRule = Rules[I].get();
if (!TheRule->apply(SU, Collection, SyncPipe)) {
for (auto &Rule : Rules) {
if (!Rule.get()->apply(SU, Collection, SyncPipe))
return false;
}
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,8 @@ SDValue AMDGPUTargetLowering::lowerUnhandledCall(CallLoweringInfo &CLI,
DAG.getContext()->diagnose(NoCalls);

if (!CLI.IsTailCall) {
for (unsigned I = 0, E = CLI.Ins.size(); I != E; ++I)
InVals.push_back(DAG.getUNDEF(CLI.Ins[I].VT));
for (ISD::InputArg &Arg : CLI.Ins)
InVals.push_back(DAG.getUNDEF(Arg.VT));
}

return DAG.getEntryNode();
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,8 @@ bool AMDGPULibCalls::TDOFold(CallInst *CI, const FuncInfo &FInfo) {
Constant *nval;
if (getArgType(FInfo) == AMDGPULibFunc::F32) {
SmallVector<float, 0> FVal;
for (unsigned i = 0; i < DVal.size(); ++i) {
FVal.push_back((float)DVal[i]);
}
for (double D : DVal)
FVal.push_back((float)D);
ArrayRef<float> tmp(FVal);
nval = ConstantDataVector::get(context, tmp);
} else { // F64
Expand Down Expand Up @@ -1082,9 +1081,8 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
}
if (getArgType(FInfo) == AMDGPULibFunc::F32) {
SmallVector<float, 0> FVal;
for (unsigned i=0; i < DVal.size(); ++i) {
FVal.push_back((float)DVal[i]);
}
for (double D : DVal)
FVal.push_back((float)D);
ArrayRef<float> tmp(FVal);
cnval = ConstantDataVector::get(M->getContext(), tmp);
} else {
Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ class AMDGPULowerModuleLDS {
ArrayType *KernelOffsetsType = ArrayType::get(I32, Variables.size());

SmallVector<Constant *> Elements;
for (size_t i = 0; i < Variables.size(); i++) {
GlobalVariable *GV = Variables[i];
for (GlobalVariable *GV : Variables) {
auto ConstantGepIt = LDSVarsToConstantGEP.find(GV);
if (ConstantGepIt != LDSVarsToConstantGEP.end()) {
auto elt = ConstantExpr::getPtrToInt(ConstantGepIt->second, I32);
Expand Down Expand Up @@ -1194,10 +1193,10 @@ class AMDGPULowerModuleLDS {
IsPaddingField.reserve(LDSVarsToTransform.size());
{
uint64_t CurrentOffset = 0;
for (size_t I = 0; I < LayoutFields.size(); I++) {
GlobalVariable *FGV = static_cast<GlobalVariable *>(
const_cast<void *>(LayoutFields[I].Id));
Align DataAlign = LayoutFields[I].Alignment;
for (auto &F : LayoutFields) {
GlobalVariable *FGV =
static_cast<GlobalVariable *>(const_cast<void *>(F.Id));
Align DataAlign = F.Alignment;

uint64_t DataAlignV = DataAlign.value();
if (uint64_t Rem = CurrentOffset % DataAlignV) {
Expand All @@ -1218,7 +1217,7 @@ class AMDGPULowerModuleLDS {

LocalVars.push_back(FGV);
IsPaddingField.push_back(false);
CurrentOffset += LayoutFields[I].Size;
CurrentOffset += F.Size;
}
}

Expand Down
18 changes: 8 additions & 10 deletions llvm/lib/Target/AMDGPU/R600EmitClauseMarkers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ class R600EmitClauseMarkers : public MachineFunctionPass {
assert(
(TII->isALUInstr(MI.getOpcode()) || MI.getOpcode() == R600::DOT_4) &&
"Can't assign Const");
for (unsigned i = 0, n = Consts.size(); i < n; ++i) {
if (Consts[i].first->getReg() != R600::ALU_CONST)
for (auto &[Op, Sel] : Consts) {
if (Op->getReg() != R600::ALU_CONST)
continue;
unsigned Sel = Consts[i].second;
unsigned Chan = Sel & 3, Index = ((Sel >> 2) - 512) & 31;
unsigned KCacheIndex = Index * 4 + Chan;
const std::pair<unsigned, unsigned> &BankLine = getAccessedBankLine(Sel);
Expand Down Expand Up @@ -155,17 +154,16 @@ class R600EmitClauseMarkers : public MachineFunctionPass {
if (!UpdateInstr)
return true;

for (unsigned i = 0, j = 0, n = Consts.size(); i < n; ++i) {
if (Consts[i].first->getReg() != R600::ALU_CONST)
unsigned j = 0;
for (auto &[Op, Sel] : Consts) {
if (Op->getReg() != R600::ALU_CONST)
continue;
switch(UsedKCache[j].first) {
switch (UsedKCache[j].first) {
case 0:
Consts[i].first->setReg(
R600::R600_KC0RegClass.getRegister(UsedKCache[j].second));
Op->setReg(R600::R600_KC0RegClass.getRegister(UsedKCache[j].second));
break;
case 1:
Consts[i].first->setReg(
R600::R600_KC1RegClass.getRegister(UsedKCache[j].second));
Op->setReg(R600::R600_KC1RegClass.getRegister(UsedKCache[j].second));
break;
default:
llvm_unreachable("Wrong Cache Line");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/R600MachineCFGStructurizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ void R600MachineCFGStructurizer::wrapup(MachineBasicBlock *MBB) {
}

//delete continue right before endloop
for (unsigned i = 0; i < ContInstr.size(); ++i)
ContInstr[i]->eraseFromParent();
for (auto *MI : ContInstr)
MI->eraseFromParent();

// TODO to fix up jump table so later phase won't be confused. if
// (jumpTableInfo->isEmpty() == false) { need to clean the jump table, but
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ class R600OpenCLImageTypeLoweringPass : public ModulePass {
Modified |= replaceSamplerUses(Arg, ResourceID);
}
}
for (unsigned i = 0; i < InstsToErase.size(); ++i) {
InstsToErase[i]->eraseFromParent();
}
for (auto *Inst : InstsToErase)
Inst->eraseFromParent();

return Modified;
}
Expand Down
14 changes: 5 additions & 9 deletions llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,8 @@ bool SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {
TII = ST.getInstrInfo();
MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();

for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
BI != BE; ++BI) {
MachineBasicBlock *MBB = &*BI;
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
for (MachineBasicBlock &MBB : MF) {
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E;
++I) {
MachineInstr &MI = *I;

Expand Down Expand Up @@ -665,7 +663,7 @@ bool SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {
Register NewDst = MRI->createVirtualRegister(DestRC);
MachineBasicBlock *BlockToInsertCopy =
MI.isPHI() ? MI.getOperand(MO.getOperandNo() + 1).getMBB()
: MBB;
: &MBB;
MachineBasicBlock::iterator PointToInsertCopy =
MI.isPHI() ? BlockToInsertCopy->getFirstInstrTerminator() : I;

Expand Down Expand Up @@ -1095,10 +1093,8 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {

void SIFixSGPRCopies::fixSCCCopies(MachineFunction &MF) {
bool IsWave32 = MF.getSubtarget<GCNSubtarget>().isWave32();
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end(); BI != BE;
++BI) {
MachineBasicBlock *MBB = &*BI;
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
for (MachineBasicBlock &MBB : MF) {
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E;
++I) {
MachineInstr &MI = *I;
// May already have been lowered.
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,7 @@ bool SIFoldOperands::tryFoldRegSequence(MachineInstr &MI) {
if (!getRegSeqInit(Defs, Reg, MCOI::OPERAND_REGISTER))
return false;

for (auto &Def : Defs) {
const auto *Op = Def.first;
for (auto &[Op, SubIdx] : Defs) {
if (!Op->isReg())
return false;
if (TRI->isAGPR(*MRI, Op->getReg()))
Expand Down Expand Up @@ -1809,8 +1808,7 @@ bool SIFoldOperands::tryFoldRegSequence(MachineInstr &MI) {
auto RS = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
TII->get(AMDGPU::REG_SEQUENCE), Dst);

for (unsigned I = 0; I < Defs.size(); ++I) {
MachineOperand *Def = Defs[I].first;
for (auto &[Def, SubIdx] : Defs) {
Def->setIsKill(false);
if (TRI->isAGPR(*MRI, Def->getReg())) {
RS.add(*Def);
Expand All @@ -1819,7 +1817,7 @@ bool SIFoldOperands::tryFoldRegSequence(MachineInstr &MI) {
SubDef->getOperand(1).setIsKill(false);
RS.addReg(SubDef->getOperand(1).getReg(), 0, Def->getSubReg());
}
RS.addImm(Defs[I].second);
RS.addImm(SubIdx);
}

Op->setReg(Dst);
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3250,8 +3250,7 @@ SDValue SITargetLowering::LowerCallResult(
CCInfo.AnalyzeCallResult(Ins, RetCC);

// Copy all of the result registers out of their specified physreg.
for (unsigned i = 0; i != RVLocs.size(); ++i) {
CCValAssign VA = RVLocs[i];
for (CCValAssign VA : RVLocs) {
SDValue Val;

if (VA.isRegLoc()) {
Expand Down Expand Up @@ -3642,8 +3641,8 @@ SDValue SITargetLowering::LowerCall(CallLoweringInfo &CLI,

if (Callee.isUndef() || isNullConstant(Callee)) {
if (!CLI.IsTailCall) {
for (unsigned I = 0, E = CLI.Ins.size(); I != E; ++I)
InVals.push_back(DAG.getUNDEF(CLI.Ins[I].VT));
for (ISD::InputArg &Arg : CLI.Ins)
InVals.push_back(DAG.getUNDEF(Arg.VT));
}

return Chain;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ void SIMachineFunctionInfo::shiftSpillPhysVGPRsToLowestRange(
MachineFunction &MF) {
const SIRegisterInfo *TRI = MF.getSubtarget<GCNSubtarget>().getRegisterInfo();
MachineRegisterInfo &MRI = MF.getRegInfo();
for (unsigned I = 0, E = SpillPhysVGPRs.size(); I < E; ++I) {
Register Reg = SpillPhysVGPRs[I];
for (Register &Reg : SpillPhysVGPRs) {
Register NewReg =
TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass, MF);
if (!NewReg || NewReg >= Reg)
Expand All @@ -334,7 +333,6 @@ void SIMachineFunctionInfo::shiftSpillPhysVGPRsToLowestRange(
MRI.replaceRegWith(Reg, NewReg);

// Update various tables with the new VGPR.
SpillPhysVGPRs[I] = NewReg;
WWMReservedRegs.remove(Reg);
WWMReservedRegs.insert(NewReg);
WWMSpills.insert(std::make_pair(NewReg, WWMSpills[Reg]));
Expand All @@ -344,6 +342,8 @@ void SIMachineFunctionInfo::shiftSpillPhysVGPRsToLowestRange(
MBB.removeLiveIn(Reg);
MBB.sortUniqueLiveIns();
}

Reg = NewReg;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit subtle. It updates the entry in SpillPhysVGPRs. I don't know if there's a good way to make this more obvious to the reader.

}
}

Expand Down
Loading