[llvm] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-11-25 22:17:10 -08:00
parent 654c89d85a
commit 259cd6f893
10 changed files with 28 additions and 48 deletions

View File

@ -354,8 +354,7 @@ void AggressiveAntiDepBreaker::PrescanInstruction(
// dead, or because only a subregister is live at the def. If we // dead, or because only a subregister is live at the def. If we
// don't do this the dead def will be incorrectly merged into the // don't do this the dead def will be incorrectly merged into the
// previous def. // previous def.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isDef()) continue; if (!MO.isReg() || !MO.isDef()) continue;
Register Reg = MO.getReg(); Register Reg = MO.getReg();
if (Reg == 0) continue; if (Reg == 0) continue;
@ -407,8 +406,7 @@ void AggressiveAntiDepBreaker::PrescanInstruction(
// Scan the register defs for this instruction and update // Scan the register defs for this instruction and update
// live-ranges. // live-ranges.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isDef()) continue; if (!MO.isReg() || !MO.isDef()) continue;
Register Reg = MO.getReg(); Register Reg = MO.getReg();
if (Reg == 0) continue; if (Reg == 0) continue;
@ -495,8 +493,7 @@ void AggressiveAntiDepBreaker::ScanInstruction(MachineInstr &MI,
LLVM_DEBUG(dbgs() << "\tKill Group:"); LLVM_DEBUG(dbgs() << "\tKill Group:");
unsigned FirstReg = 0; unsigned FirstReg = 0;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg()) continue; if (!MO.isReg()) continue;
Register Reg = MO.getReg(); Register Reg = MO.getReg();
if (Reg == 0) continue; if (Reg == 0) continue;

View File

@ -3732,8 +3732,7 @@ void CombinerHelper::applyExtendThroughPhis(MachineInstr &MI,
Builder.setInstrAndDebugLoc(MI); Builder.setInstrAndDebugLoc(MI);
auto NewPhi = Builder.buildInstrNoInsert(TargetOpcode::G_PHI); auto NewPhi = Builder.buildInstrNoInsert(TargetOpcode::G_PHI);
NewPhi.addDef(DstReg); NewPhi.addDef(DstReg);
for (unsigned SrcIdx = 1; SrcIdx < MI.getNumOperands(); ++SrcIdx) { for (const MachineOperand &MO : llvm::drop_begin(MI.operands())) {
auto &MO = MI.getOperand(SrcIdx);
if (!MO.isReg()) { if (!MO.isReg()) {
NewPhi.addMBB(MO.getMBB()); NewPhi.addMBB(MO.getMBB());
continue; continue;

View File

@ -585,8 +585,8 @@ simpleLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size,
// FIXME: What does the original arg index mean here? // FIXME: What does the original arg index mean here?
SmallVector<CallLowering::ArgInfo, 3> Args; SmallVector<CallLowering::ArgInfo, 3> Args;
for (unsigned i = 1; i < MI.getNumOperands(); i++) for (const MachineOperand &MO : llvm::drop_begin(MI.operands()))
Args.push_back({MI.getOperand(i).getReg(), OpType, 0}); Args.push_back({MO.getReg(), OpType, 0});
return createLibcall(MIRBuilder, Libcall, return createLibcall(MIRBuilder, Libcall,
{MI.getOperand(0).getReg(), OpType, 0}, Args); {MI.getOperand(0).getReg(), OpType, 0}, Args);
} }
@ -1500,8 +1500,8 @@ LegalizerHelper::widenScalarMergeValues(MachineInstr &MI, unsigned TypeIdx,
LLT WideDstTy = LLT::scalar(NumMerge * WideSize); LLT WideDstTy = LLT::scalar(NumMerge * WideSize);
// Decompose the original operands if they don't evenly divide. // Decompose the original operands if they don't evenly divide.
for (int I = 1, E = MI.getNumOperands(); I != E; ++I) { for (const MachineOperand &MO : llvm::drop_begin(MI.operands())) {
Register SrcReg = MI.getOperand(I).getReg(); Register SrcReg = MO.getReg();
if (GCD == SrcSize) { if (GCD == SrcSize) {
Unmerges.push_back(SrcReg); Unmerges.push_back(SrcReg);
} else { } else {
@ -4037,8 +4037,8 @@ LegalizerHelper::fewerElementsVectorMerge(MachineInstr &MI, unsigned TypeIdx,
// Break into a common type // Break into a common type
SmallVector<Register, 16> Parts; SmallVector<Register, 16> Parts;
for (unsigned I = 1, E = MI.getNumOperands(); I != E; ++I) for (const MachineOperand &MO : llvm::drop_begin(MI.operands()))
extractGCDType(Parts, GCDTy, MI.getOperand(I).getReg()); extractGCDType(Parts, GCDTy, MO.getReg());
// Build the requested new merge, padding with undef. // Build the requested new merge, padding with undef.
LLT LCMTy = buildLCMMergePieces(DstTy, NarrowTy, GCDTy, Parts, LLT LCMTy = buildLCMMergePieces(DstTy, NarrowTy, GCDTy, Parts,

View File

@ -1276,11 +1276,9 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (DstTy.getNumElements() != MI->getNumOperands() - 1) if (DstTy.getNumElements() != MI->getNumOperands() - 1)
report("G_BUILD_VECTOR must have an operand for each elemement", MI); report("G_BUILD_VECTOR must have an operand for each elemement", MI);
for (unsigned i = 2; i < MI->getNumOperands(); ++i) { for (const MachineOperand &MO : llvm::drop_begin(MI->operands(), 2))
if (MRI->getType(MI->getOperand(1).getReg()) != if (MRI->getType(MI->getOperand(1).getReg()) != MRI->getType(MO.getReg()))
MRI->getType(MI->getOperand(i).getReg()))
report("G_BUILD_VECTOR source operand types are not homogeneous", MI); report("G_BUILD_VECTOR source operand types are not homogeneous", MI);
}
break; break;
} }
@ -1292,12 +1290,10 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (!DstTy.isVector() || SrcEltTy.isVector()) if (!DstTy.isVector() || SrcEltTy.isVector())
report("G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands", report("G_BUILD_VECTOR_TRUNC must produce a vector from scalar operands",
MI); MI);
for (unsigned i = 2; i < MI->getNumOperands(); ++i) { for (const MachineOperand &MO : llvm::drop_begin(MI->operands(), 2))
if (MRI->getType(MI->getOperand(1).getReg()) != if (MRI->getType(MI->getOperand(1).getReg()) != MRI->getType(MO.getReg()))
MRI->getType(MI->getOperand(i).getReg()))
report("G_BUILD_VECTOR_TRUNC source operand types are not homogeneous", report("G_BUILD_VECTOR_TRUNC source operand types are not homogeneous",
MI); MI);
}
if (SrcEltTy.getSizeInBits() <= DstTy.getElementType().getSizeInBits()) if (SrcEltTy.getSizeInBits() <= DstTy.getElementType().getSizeInBits())
report("G_BUILD_VECTOR_TRUNC source operand types are not larger than " report("G_BUILD_VECTOR_TRUNC source operand types are not larger than "
"dest elt type", "dest elt type",
@ -1316,11 +1312,9 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
if (MI->getNumOperands() < 3) if (MI->getNumOperands() < 3)
report("G_CONCAT_VECTOR requires at least 2 source operands", MI); report("G_CONCAT_VECTOR requires at least 2 source operands", MI);
for (unsigned i = 2; i < MI->getNumOperands(); ++i) { for (const MachineOperand &MO : llvm::drop_begin(MI->operands(), 2))
if (MRI->getType(MI->getOperand(1).getReg()) != if (MRI->getType(MI->getOperand(1).getReg()) != MRI->getType(MO.getReg()))
MRI->getType(MI->getOperand(i).getReg()))
report("G_CONCAT_VECTOR source operand types are not homogeneous", MI); report("G_CONCAT_VECTOR source operand types are not homogeneous", MI);
}
if (DstTy.getNumElements() != if (DstTy.getNumElements() !=
SrcTy.getNumElements() * (MI->getNumOperands() - 1)) SrcTy.getNumElements() * (MI->getNumOperands() - 1))
report("G_CONCAT_VECTOR num dest and source elements should match", MI); report("G_CONCAT_VECTOR num dest and source elements should match", MI);

View File

@ -957,8 +957,7 @@ bool TargetInstrInfo::isReallyTriviallyReMaterializableGeneric(
// If any of the registers accessed are non-constant, conservatively assume // If any of the registers accessed are non-constant, conservatively assume
// the instruction is not rematerializable. // the instruction is not rematerializable.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
const MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg()) continue; if (!MO.isReg()) continue;
Register Reg = MO.getReg(); Register Reg = MO.getReg();
if (Reg == 0) if (Reg == 0)

View File

@ -492,8 +492,7 @@ void TwoAddressInstructionPass::removeClobberedSrcRegMap(MachineInstr *MI) {
return; return;
} }
for (unsigned i = 0, NumOps = MI->getNumOperands(); i != NumOps; ++i) { for (const MachineOperand &MO : MI->operands()) {
const MachineOperand &MO = MI->getOperand(i);
if (MO.isRegMask()) { if (MO.isRegMask()) {
removeMapRegEntry(MO, SrcRegMap, TRI); removeMapRegEntry(MO, SrcRegMap, TRI);
continue; continue;
@ -1335,8 +1334,7 @@ tryInstructionTransform(MachineBasicBlock::iterator &mi,
// Success, or at least we made an improvement. Keep the unfolded // Success, or at least we made an improvement. Keep the unfolded
// instructions and discard the original. // instructions and discard the original.
if (LV) { if (LV) {
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (MO.isReg() && MO.getReg().isVirtual()) { if (MO.isReg() && MO.getReg().isVirtual()) {
if (MO.isUse()) { if (MO.isUse()) {
if (MO.isKill()) { if (MO.isKill()) {

View File

@ -186,8 +186,8 @@ public:
TII->getRegClass(TII->get(DstOpcode), 0, MRI->getTargetRegisterInfo(), TII->getRegClass(TII->get(DstOpcode), 0, MRI->getTargetRegisterInfo(),
*MBB->getParent())); *MBB->getParent()));
MachineInstrBuilder Bld = BuildMI(*MBB, MI, DL, TII->get(DstOpcode), Reg); MachineInstrBuilder Bld = BuildMI(*MBB, MI, DL, TII->get(DstOpcode), Reg);
for (unsigned Idx = 1, End = MI->getNumOperands(); Idx < End; ++Idx) for (const MachineOperand &MO : llvm::drop_begin(MI->operands()))
Bld.add(MI->getOperand(Idx)); Bld.add(MO);
BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY)) BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::COPY))
.add(MI->getOperand(0)) .add(MI->getOperand(0))

View File

@ -278,10 +278,9 @@ FixupLEAPass::usesRegister(MachineOperand &p, MachineBasicBlock::iterator I) {
RegUsageState RegUsage = RU_NotUsed; RegUsageState RegUsage = RU_NotUsed;
MachineInstr &MI = *I; MachineInstr &MI = *I;
for (unsigned i = 0; i < MI.getNumOperands(); ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &opnd = MI.getOperand(i); if (MO.isReg() && MO.getReg() == p.getReg()) {
if (opnd.isReg() && opnd.getReg() == p.getReg()) { if (MO.isDef())
if (opnd.isDef())
return RU_Write; return RU_Write;
RegUsage = RU_Read; RegUsage = RU_Read;
} }

View File

@ -446,11 +446,9 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
// Get dead variables list now because the MI pointer may be deleted as part // Get dead variables list now because the MI pointer may be deleted as part
// of processing! // of processing!
SmallVector<unsigned, 8> DeadRegs; SmallVector<unsigned, 8> DeadRegs;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands())
const MachineOperand &MO = MI.getOperand(i);
if (MO.isReg() && MO.isDead()) if (MO.isReg() && MO.isDead())
DeadRegs.push_back(MO.getReg()); DeadRegs.push_back(MO.getReg());
}
switch (FPInstClass) { switch (FPInstClass) {
case X86II::ZeroArgFP: handleZeroArgFP(I); break; case X86II::ZeroArgFP: handleZeroArgFP(I); break;
@ -1672,8 +1670,7 @@ void FPS::handleSpecialFP(MachineBasicBlock::iterator &Inst) {
// Collect all FP registers (register operands with constraints "t", "u", // Collect all FP registers (register operands with constraints "t", "u",
// and "f") to kill afer the instruction. // and "f") to kill afer the instruction.
unsigned FPKills = ((1u << NumFPRegs) - 1) & ~0xff; unsigned FPKills = ((1u << NumFPRegs) - 1) & ~0xff;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &Op : MI.operands()) {
MachineOperand &Op = MI.getOperand(i);
if (!Op.isReg() || Op.getReg() < X86::FP0 || Op.getReg() > X86::FP6) if (!Op.isReg() || Op.getReg() < X86::FP0 || Op.getReg() > X86::FP6)
continue; continue;
unsigned FPReg = getFPReg(Op); unsigned FPReg = getFPReg(Op);

View File

@ -1163,8 +1163,7 @@ void X86InstrInfo::reMaterialize(MachineBasicBlock &MBB,
/// True if MI has a condition code def, e.g. EFLAGS, that is not marked dead. /// True if MI has a condition code def, e.g. EFLAGS, that is not marked dead.
bool X86InstrInfo::hasLiveCondCodeDef(MachineInstr &MI) const { bool X86InstrInfo::hasLiveCondCodeDef(MachineInstr &MI) const {
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (MO.isReg() && MO.isDef() && if (MO.isReg() && MO.isDef() &&
MO.getReg() == X86::EFLAGS && !MO.isDead()) { MO.getReg() == X86::EFLAGS && !MO.isDead()) {
return true; return true;
@ -5676,10 +5675,8 @@ static MachineInstr *FuseTwoAddrInst(MachineFunction &MF, unsigned Opcode,
MachineOperand &MO = MI.getOperand(i + 2); MachineOperand &MO = MI.getOperand(i + 2);
MIB.add(MO); MIB.add(MO);
} }
for (unsigned i = NumOps + 2, e = MI.getNumOperands(); i != e; ++i) { for (const MachineOperand &MO : llvm::drop_begin(MI.operands(), NumOps + 2))
MachineOperand &MO = MI.getOperand(i);
MIB.add(MO); MIB.add(MO);
}
updateOperandRegConstraints(MF, *NewMI, TII); updateOperandRegConstraints(MF, *NewMI, TII);