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

This commit is contained in:
Kazu Hirata 2021-11-28 10:04:54 -08:00
parent 8874ada906
commit c73fc74ce0
11 changed files with 28 additions and 45 deletions

View File

@ -581,11 +581,9 @@ bool InlineSpiller::reMaterializeFor(LiveInterval &VirtReg, MachineInstr &MI) {
if (!ParentVNI) { if (!ParentVNI) {
LLVM_DEBUG(dbgs() << "\tadding <undef> flags: "); LLVM_DEBUG(dbgs() << "\tadding <undef> flags: ");
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { for (MachineOperand &MO : MI.operands())
MachineOperand &MO = MI.getOperand(i);
if (MO.isReg() && MO.isUse() && MO.getReg() == VirtReg.reg()) if (MO.isReg() && MO.isUse() && MO.getReg() == VirtReg.reg())
MO.setIsUndef(); MO.setIsUndef();
}
LLVM_DEBUG(dbgs() << UseIdx << '\t' << MI); LLVM_DEBUG(dbgs() << UseIdx << '\t' << MI);
return true; return true;
} }

View File

@ -2546,8 +2546,7 @@ void SMSchedule::orderDependence(SwingSchedulerDAG *SSD, SUnit *SU,
unsigned Pos = 0; unsigned Pos = 0;
for (std::deque<SUnit *>::iterator I = Insts.begin(), E = Insts.end(); I != E; for (std::deque<SUnit *>::iterator I = Insts.begin(), E = Insts.end(); I != E;
++I, ++Pos) { ++I, ++Pos) {
for (unsigned i = 0, e = MI->getNumOperands(); i < e; ++i) { for (MachineOperand &MO : MI->operands()) {
MachineOperand &MO = MI->getOperand(i);
if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg())) if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg()))
continue; continue;

View File

@ -1005,8 +1005,7 @@ void ModuloScheduleExpander::updateInstruction(MachineInstr *NewMI,
unsigned CurStageNum, unsigned CurStageNum,
unsigned InstrStageNum, unsigned InstrStageNum,
ValueMapTy *VRMap) { ValueMapTy *VRMap) {
for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) { for (MachineOperand &MO : NewMI->operands()) {
MachineOperand &MO = NewMI->getOperand(i);
if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg())) if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg()))
continue; continue;
Register reg = MO.getReg(); Register reg = MO.getReg();

View File

@ -1258,8 +1258,7 @@ void RegAllocFast::allocateInstruction(MachineInstr &MI) {
// Free registers occupied by defs. // Free registers occupied by defs.
// Iterate operands in reverse order, so we see the implicit super register // Iterate operands in reverse order, so we see the implicit super register
// defs first (we added them earlier in case of <def,read-undef>). // defs first (we added them earlier in case of <def,read-undef>).
for (unsigned I = MI.getNumOperands(); I-- > 0;) { for (MachineOperand &MO : llvm::reverse(MI.operands())) {
MachineOperand &MO = MI.getOperand(I);
if (!MO.isReg() || !MO.isDef()) if (!MO.isReg() || !MO.isDef())
continue; continue;
@ -1362,8 +1361,7 @@ void RegAllocFast::allocateInstruction(MachineInstr &MI) {
// Free early clobbers. // Free early clobbers.
if (HasEarlyClobber) { if (HasEarlyClobber) {
for (unsigned I = MI.getNumOperands(); I-- > 0; ) { for (MachineOperand &MO : llvm::reverse(MI.operands())) {
MachineOperand &MO = MI.getOperand(I);
if (!MO.isReg() || !MO.isDef() || !MO.isEarlyClobber()) if (!MO.isReg() || !MO.isDef() || !MO.isEarlyClobber())
continue; continue;
// subreg defs don't free the full register. We left the subreg number // subreg defs don't free the full register. We left the subreg number
@ -1440,8 +1438,7 @@ void RegAllocFast::handleBundle(MachineInstr &MI) {
MachineBasicBlock::instr_iterator BundledMI = MI.getIterator(); MachineBasicBlock::instr_iterator BundledMI = MI.getIterator();
++BundledMI; ++BundledMI;
while (BundledMI->isBundledWithPred()) { while (BundledMI->isBundledWithPred()) {
for (unsigned I = 0; I < BundledMI->getNumOperands(); ++I) { for (MachineOperand &MO : BundledMI->operands()) {
MachineOperand &MO = BundledMI->getOperand(I);
if (!MO.isReg()) if (!MO.isReg())
continue; continue;

View File

@ -393,8 +393,7 @@ void StackSlotColoring::RewriteInstruction(MachineInstr &MI,
SmallVectorImpl<int> &SlotMapping, SmallVectorImpl<int> &SlotMapping,
MachineFunction &MF) { MachineFunction &MF) {
// Update the operands. // Update the operands.
for (unsigned i = 0, ee = MI.getNumOperands(); i != ee; ++i) { for (MachineOperand &MO : MI.operands()) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isFI()) if (!MO.isFI())
continue; continue;
int OldFI = MO.getIndex(); int OldFI = MO.getIndex();

View File

@ -88,12 +88,9 @@ MachineInstr *AArch64CondBrTuning::convertToFlagSetting(MachineInstr &MI,
// If this is already the flag setting version of the instruction (e.g., SUBS) // If this is already the flag setting version of the instruction (e.g., SUBS)
// just make sure the implicit-def of NZCV isn't marked dead. // just make sure the implicit-def of NZCV isn't marked dead.
if (IsFlagSetting) { if (IsFlagSetting) {
for (unsigned I = MI.getNumExplicitOperands(), E = MI.getNumOperands(); for (MachineOperand &MO : MI.implicit_operands())
I != E; ++I) {
MachineOperand &MO = MI.getOperand(I);
if (MO.isReg() && MO.isDead() && MO.getReg() == AArch64::NZCV) if (MO.isReg() && MO.isDead() && MO.getReg() == AArch64::NZCV)
MO.setIsDead(false); MO.setIsDead(false);
}
return &MI; return &MI;
} }
bool Is64Bit; bool Is64Bit;

View File

@ -6452,8 +6452,7 @@ static void fixupPHIOpBanks(MachineInstr &MI, MachineRegisterInfo &MRI,
MachineIRBuilder MIB(MI); MachineIRBuilder MIB(MI);
// Go through each operand and ensure it has the same regbank. // Go through each operand and ensure it has the same regbank.
for (unsigned OpIdx = 1; OpIdx < MI.getNumOperands(); ++OpIdx) { for (MachineOperand &MO : llvm::drop_begin(MI.operands())) {
MachineOperand &MO = MI.getOperand(OpIdx);
if (!MO.isReg()) if (!MO.isReg())
continue; continue;
Register OpReg = MO.getReg(); Register OpReg = MO.getReg();

View File

@ -1219,9 +1219,9 @@ int ARMConstantIslands::findInRangeCPEntry(CPUser& U, unsigned UserOffset) {
// Point the CPUser node to the replacement // Point the CPUser node to the replacement
U.CPEMI = CPEs[i].CPEMI; U.CPEMI = CPEs[i].CPEMI;
// Change the CPI in the instruction operand to refer to the clone. // Change the CPI in the instruction operand to refer to the clone.
for (unsigned j = 0, e = UserMI->getNumOperands(); j != e; ++j) for (MachineOperand &MO : UserMI->operands())
if (UserMI->getOperand(j).isCPI()) { if (MO.isCPI()) {
UserMI->getOperand(j).setIndex(CPEs[i].CPI); MO.setIndex(CPEs[i].CPI);
break; break;
} }
// Adjust the refcount of the clone... // Adjust the refcount of the clone...
@ -1601,9 +1601,9 @@ bool ARMConstantIslands::handleConstantPoolUser(unsigned CPUserIndex,
BBUtils->adjustBBOffsetsAfter(&*--NewIsland->getIterator()); BBUtils->adjustBBOffsetsAfter(&*--NewIsland->getIterator());
// Finally, change the CPI in the instruction operand to be ID. // Finally, change the CPI in the instruction operand to be ID.
for (unsigned i = 0, e = UserMI->getNumOperands(); i != e; ++i) for (MachineOperand &MO : UserMI->operands())
if (UserMI->getOperand(i).isCPI()) { if (MO.isCPI()) {
UserMI->getOperand(i).setIndex(ID); MO.setIndex(ID);
break; break;
} }

View File

@ -237,12 +237,9 @@ static bool isEvenReg(unsigned Reg) {
} }
static void removeKillInfo(MachineInstr &MI, unsigned RegNotKilled) { static void removeKillInfo(MachineInstr &MI, unsigned RegNotKilled) {
for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) { for (MachineOperand &Op : MI.operands())
MachineOperand &Op = MI.getOperand(I); if (Op.isReg() && Op.getReg() == RegNotKilled && Op.isKill())
if (!Op.isReg() || Op.getReg() != RegNotKilled || !Op.isKill()) Op.setIsKill(false);
continue;
Op.setIsKill(false);
}
} }
/// Returns true if it is unsafe to move a copy instruction from \p UseReg to /// Returns true if it is unsafe to move a copy instruction from \p UseReg to

View File

@ -1066,9 +1066,9 @@ int MipsConstantIslands::findInRangeCPEntry(CPUser& U, unsigned UserOffset)
// Point the CPUser node to the replacement // Point the CPUser node to the replacement
U.CPEMI = CPEs[i].CPEMI; U.CPEMI = CPEs[i].CPEMI;
// Change the CPI in the instruction operand to refer to the clone. // Change the CPI in the instruction operand to refer to the clone.
for (unsigned j = 0, e = UserMI->getNumOperands(); j != e; ++j) for (MachineOperand &MO : UserMI->operands())
if (UserMI->getOperand(j).isCPI()) { if (MO.isCPI()) {
UserMI->getOperand(j).setIndex(CPEs[i].CPI); MO.setIndex(CPEs[i].CPI);
break; break;
} }
// Adjust the refcount of the clone... // Adjust the refcount of the clone...
@ -1122,9 +1122,9 @@ int MipsConstantIslands::findLongFormInRangeCPEntry
// Point the CPUser node to the replacement // Point the CPUser node to the replacement
U.CPEMI = CPEs[i].CPEMI; U.CPEMI = CPEs[i].CPEMI;
// Change the CPI in the instruction operand to refer to the clone. // Change the CPI in the instruction operand to refer to the clone.
for (unsigned j = 0, e = UserMI->getNumOperands(); j != e; ++j) for (MachineOperand &MO : UserMI->operands())
if (UserMI->getOperand(j).isCPI()) { if (MO.isCPI()) {
UserMI->getOperand(j).setIndex(CPEs[i].CPI); MO.setIndex(CPEs[i].CPI);
break; break;
} }
// Adjust the refcount of the clone... // Adjust the refcount of the clone...
@ -1392,9 +1392,9 @@ bool MipsConstantIslands::handleConstantPoolUser(unsigned CPUserIndex) {
adjustBBOffsetsAfter(&*--NewIsland->getIterator()); adjustBBOffsetsAfter(&*--NewIsland->getIterator());
// Finally, change the CPI in the instruction operand to be ID. // Finally, change the CPI in the instruction operand to be ID.
for (unsigned i = 0, e = UserMI->getNumOperands(); i != e; ++i) for (MachineOperand &MO : UserMI->operands())
if (UserMI->getOperand(i).isCPI()) { if (MO.isCPI()) {
UserMI->getOperand(i).setIndex(ID); MO.setIndex(ID);
break; break;
} }

View File

@ -209,10 +209,8 @@ void X86ExpandPseudo::expandCALL_RVMARKER(MachineBasicBlock &MBB,
llvm_unreachable("unexpected opcode"); llvm_unreachable("unexpected opcode");
OriginalCall = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr(); OriginalCall = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr();
unsigned OpStart = 1;
bool RAXImplicitDead = false; bool RAXImplicitDead = false;
for (; OpStart < MI.getNumOperands(); ++OpStart) { for (MachineOperand &Op : llvm::drop_begin(MI.operands())) {
MachineOperand &Op = MI.getOperand(OpStart);
// RAX may be 'implicit dead', if there are no other users of the return // RAX may be 'implicit dead', if there are no other users of the return
// value. We introduce a new use, so change it to 'implicit def'. // value. We introduce a new use, so change it to 'implicit def'.
if (Op.isReg() && Op.isImplicit() && Op.isDead() && if (Op.isReg() && Op.isImplicit() && Op.isDead() &&