[llvm] 9d74582 - [Target] use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 7 21:20:46 PST 2022
Author: Kazu Hirata
Date: 2022-01-07T21:20:36-08:00
New Revision: 9d745828105097e04c7b757a9496c2450438399e
URL: https://github.com/llvm/llvm-project/commit/9d745828105097e04c7b757a9496c2450438399e
DIFF: https://github.com/llvm/llvm-project/commit/9d745828105097e04c7b757a9496c2450438399e.diff
LOG: [Target] use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
llvm/lib/Target/Mips/MipsFastISel.cpp
llvm/lib/Target/Mips/MipsISelLowering.cpp
llvm/lib/Target/Mips/MipsMachineFunction.cpp
llvm/lib/Target/Mips/MipsRegisterInfo.cpp
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 5d026785b9219..ab32af3ba275a 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -80,13 +80,9 @@ bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
MipsFI = MF.getInfo<MipsFunctionInfo>();
if (Subtarget->inMips16Mode())
- for (std::map<
- const char *,
- const Mips16HardFloatInfo::FuncSignature *>::const_iterator
- it = MipsFI->StubsNeeded.begin();
- it != MipsFI->StubsNeeded.end(); ++it) {
- const char *Symbol = it->first;
- const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
+ for (const auto &I : MipsFI->StubsNeeded) {
+ const char *Symbol = I.first;
+ const Mips16HardFloatInfo::FuncSignature *Signature = I.second;
if (StubsNeeded.find(Symbol) == StubsNeeded.end())
StubsNeeded[Symbol] = Signature;
}
@@ -1279,11 +1275,11 @@ void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {
// Align all blocks that are jumped to through jump table.
if (MachineJumpTableInfo *JtInfo = MF.getJumpTableInfo()) {
const std::vector<MachineJumpTableEntry> &JT = JtInfo->getJumpTables();
- for (unsigned I = 0; I < JT.size(); ++I) {
- const std::vector<MachineBasicBlock*> &MBBs = JT[I].MBBs;
+ for (const auto &I : JT) {
+ const std::vector<MachineBasicBlock *> &MBBs = I.MBBs;
- for (unsigned J = 0; J < MBBs.size(); ++J)
- MBBs[J]->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
+ for (MachineBasicBlock *MBB : MBBs)
+ MBB->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
}
}
diff --git a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
index 2d27d7553de6c..f807f47849f0c 100644
--- a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
+++ b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
@@ -309,12 +309,12 @@ INITIALIZE_PASS(MipsDelaySlotFiller, DEBUG_TYPE,
static void insertDelayFiller(Iter Filler, const BB2BrMap &BrMap) {
MachineFunction *MF = Filler->getParent()->getParent();
- for (BB2BrMap::const_iterator I = BrMap.begin(); I != BrMap.end(); ++I) {
- if (I->second) {
- MIBundleBuilder(I->second).append(MF->CloneMachineInstr(&*Filler));
+ for (const auto &I : BrMap) {
+ if (I.second) {
+ MIBundleBuilder(I.second).append(MF->CloneMachineInstr(&*Filler));
++UsefulSlots;
} else {
- I->first->insert(I->first->end(), MF->CloneMachineInstr(&*Filler));
+ I.first->insert(I.first->end(), MF->CloneMachineInstr(&*Filler));
}
}
}
diff --git a/llvm/lib/Target/Mips/MipsFastISel.cpp b/llvm/lib/Target/Mips/MipsFastISel.cpp
index 05c1c06ffefec..77d05abd3c93b 100644
--- a/llvm/lib/Target/Mips/MipsFastISel.cpp
+++ b/llvm/lib/Target/Mips/MipsFastISel.cpp
@@ -1607,9 +1607,9 @@ bool MipsFastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
return true;
} else {
unsigned TempReg[3];
- for (int i = 0; i < 3; i++) {
- TempReg[i] = createResultReg(&Mips::GPR32RegClass);
- if (TempReg[i] == 0)
+ for (unsigned &R : TempReg) {
+ R = createResultReg(&Mips::GPR32RegClass);
+ if (R == 0)
return false;
}
emitInst(Mips::SLL, TempReg[0]).addReg(SrcReg).addImm(8);
@@ -1628,9 +1628,9 @@ bool MipsFastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
return true;
} else {
unsigned TempReg[8];
- for (int i = 0; i < 8; i++) {
- TempReg[i] = createResultReg(&Mips::GPR32RegClass);
- if (TempReg[i] == 0)
+ for (unsigned &R : TempReg) {
+ R = createResultReg(&Mips::GPR32RegClass);
+ if (R == 0)
return false;
}
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 9377e83524e17..8ef0de95fb5e7 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -3051,17 +3051,15 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
// stuck together.
SDValue InFlag;
- for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
- Chain = CLI.DAG.getCopyToReg(Chain, CLI.DL, RegsToPass[i].first,
- RegsToPass[i].second, InFlag);
+ for (auto &R : RegsToPass) {
+ Chain = CLI.DAG.getCopyToReg(Chain, CLI.DL, R.first, R.second, InFlag);
InFlag = Chain.getValue(1);
}
// Add argument registers to the end of the list so that they are
// known live into the call.
- for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
- Ops.push_back(CLI.DAG.getRegister(RegsToPass[i].first,
- RegsToPass[i].second.getValueType()));
+ for (auto &R : RegsToPass)
+ Ops.push_back(CLI.DAG.getRegister(R.first, R.second.getValueType()));
// Add a register mask operand representing the call-preserved registers.
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
diff --git a/llvm/lib/Target/Mips/MipsMachineFunction.cpp b/llvm/lib/Target/Mips/MipsMachineFunction.cpp
index a7a2be30f58a4..411a26e42713e 100644
--- a/llvm/lib/Target/Mips/MipsMachineFunction.cpp
+++ b/llvm/lib/Target/Mips/MipsMachineFunction.cpp
@@ -148,14 +148,14 @@ void MipsFunctionInfo::initGlobalBaseReg(MachineFunction &MF) {
void MipsFunctionInfo::createEhDataRegsFI(MachineFunction &MF) {
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
- for (int I = 0; I < 4; ++I) {
+ for (int &I : EhDataRegFI) {
const TargetRegisterClass &RC =
static_cast<const MipsTargetMachine &>(MF.getTarget()).getABI().IsN64()
? Mips::GPR64RegClass
: Mips::GPR32RegClass;
- EhDataRegFI[I] = MF.getFrameInfo().CreateStackObject(
- TRI.getSpillSize(RC), TRI.getSpillAlign(RC), false);
+ I = MF.getFrameInfo().CreateStackObject(TRI.getSpillSize(RC),
+ TRI.getSpillAlign(RC), false);
}
}
@@ -167,9 +167,9 @@ void MipsFunctionInfo::createISRRegFI(MachineFunction &MF) {
const TargetRegisterClass &RC = Mips::GPR32RegClass;
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
- for (int I = 0; I < 2; ++I)
- ISRDataRegFI[I] = MF.getFrameInfo().CreateStackObject(
- TRI.getSpillSize(RC), TRI.getSpillAlign(RC), false);
+ for (int &I : ISRDataRegFI)
+ I = MF.getFrameInfo().CreateStackObject(TRI.getSpillSize(RC),
+ TRI.getSpillAlign(RC), false);
}
bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
diff --git a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
index 7cba3118cd627..390ab9d22024b 100644
--- a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
@@ -159,8 +159,8 @@ getReservedRegs(const MachineFunction &MF) const {
BitVector Reserved(getNumRegs());
const MipsSubtarget &Subtarget = MF.getSubtarget<MipsSubtarget>();
- for (unsigned I = 0; I < array_lengthof(ReservedGPR32); ++I)
- Reserved.set(ReservedGPR32[I]);
+ for (MCPhysReg R : ReservedGPR32)
+ Reserved.set(R);
// Reserve registers for the NaCl sandbox.
if (Subtarget.isTargetNaCl()) {
@@ -169,8 +169,8 @@ getReservedRegs(const MachineFunction &MF) const {
Reserved.set(Mips::T8); // Reserved for thread pointer.
}
- for (unsigned I = 0; I < array_lengthof(ReservedGPR64); ++I)
- Reserved.set(ReservedGPR64[I]);
+ for (MCPhysReg R : ReservedGPR64)
+ Reserved.set(R);
// For mno-abicalls, GP is a program invariant!
if (!Subtarget.isABICalls()) {
diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
index 40b215a8204cd..346ebe9664fc6 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
@@ -85,18 +85,18 @@ MipsSETargetLowering::MipsSETargetLowering(const MipsTargetMachine &TM,
if (Subtarget.hasDSP()) {
MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8};
- for (unsigned i = 0; i < array_lengthof(VecTys); ++i) {
- addRegisterClass(VecTys[i], &Mips::DSPRRegClass);
+ for (const auto &VecTy : VecTys) {
+ addRegisterClass(VecTy, &Mips::DSPRRegClass);
// Expand all builtin opcodes.
for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
- setOperationAction(Opc, VecTys[i], Expand);
+ setOperationAction(Opc, VecTy, Expand);
- setOperationAction(ISD::ADD, VecTys[i], Legal);
- setOperationAction(ISD::SUB, VecTys[i], Legal);
- setOperationAction(ISD::LOAD, VecTys[i], Legal);
- setOperationAction(ISD::STORE, VecTys[i], Legal);
- setOperationAction(ISD::BITCAST, VecTys[i], Legal);
+ setOperationAction(ISD::ADD, VecTy, Legal);
+ setOperationAction(ISD::SUB, VecTy, Legal);
+ setOperationAction(ISD::LOAD, VecTy, Legal);
+ setOperationAction(ISD::STORE, VecTy, Legal);
+ setOperationAction(ISD::BITCAST, VecTy, Legal);
}
setTargetDAGCombine(ISD::SHL);
@@ -2931,7 +2931,7 @@ static SDValue lowerVECTOR_SHUFFLE_PCKOD(SDValue Op, EVT ResTy,
// operand is unused and can be replaced with anything. We choose to replace it
// with the used operand since this reduces the number of instructions overall.
static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy,
- SmallVector<int, 16> Indices,
+ const SmallVector<int, 16> &Indices,
SelectionDAG &DAG) {
SmallVector<SDValue, 16> Ops;
SDValue Op0;
@@ -2953,9 +2953,8 @@ static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy,
Using2ndVec = true;
}
- for (SmallVector<int, 16>::iterator I = Indices.begin(); I != Indices.end();
- ++I)
- Ops.push_back(DAG.getTargetConstant(*I, DL, MaskEltTy));
+ for (int Idx : Indices)
+ Ops.push_back(DAG.getTargetConstant(Idx, DL, MaskEltTy));
SDValue MaskVec = DAG.getBuildVector(MaskVecTy, DL, Ops);
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index 16add48d4602e..1b1ac437c735c 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1214,9 +1214,9 @@ void NVPTXAsmPrinter::emitDemotedVars(const Function *f, raw_ostream &O) {
std::vector<const GlobalVariable *> &gvars = localDecls[f];
- for (unsigned i = 0, e = gvars.size(); i != e; ++i) {
+ for (const GlobalVariable *GV : gvars) {
O << "\t// demoted variable\n\t";
- printModuleLevelGV(gvars[i], O, true);
+ printModuleLevelGV(GV, O, true);
}
}
diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
index a9a5eae42c1d0..888fc8ffac2c5 100644
--- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
@@ -96,20 +96,18 @@ bool GenericToNVVM::runOnModule(Module &M) {
// Walk through the instructions in function defitinions, and replace any use
// of original global variables in GVMap with a use of the corresponding
// copies in GVMap. If necessary, promote constants to instructions.
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
- if (I->isDeclaration()) {
+ for (Function &F : M) {
+ if (F.isDeclaration()) {
continue;
}
- IRBuilder<> Builder(I->getEntryBlock().getFirstNonPHIOrDbg());
- for (Function::iterator BBI = I->begin(), BBE = I->end(); BBI != BBE;
- ++BBI) {
- for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE;
- ++II) {
- for (unsigned i = 0, e = II->getNumOperands(); i < e; ++i) {
- Value *Operand = II->getOperand(i);
+ IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg());
+ for (BasicBlock &BB : F) {
+ for (Instruction &II : BB) {
+ for (unsigned i = 0, e = II.getNumOperands(); i < e; ++i) {
+ Value *Operand = II.getOperand(i);
if (isa<Constant>(Operand)) {
- II->setOperand(
- i, remapConstant(&M, &*I, cast<Constant>(Operand), Builder));
+ II.setOperand(
+ i, remapConstant(&M, &F, cast<Constant>(Operand), Builder));
}
}
}
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
index 74d129d330f30..2d6d72777db22 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
@@ -286,8 +286,7 @@ bool getAlign(const Function &F, unsigned index, unsigned &align) {
bool retval = findAllNVVMAnnotation(&F, "align", Vs);
if (!retval)
return false;
- for (int i = 0, e = Vs.size(); i < e; i++) {
- unsigned v = Vs[i];
+ for (unsigned v : Vs) {
if ((v >> 16) == index) {
align = v & 0xFFFF;
return true;
More information about the llvm-commits
mailing list