Skip to content

Commit 2c4ba3e

Browse files
[Target] Use make_early_inc_range (NFC)
1 parent 9342110 commit 2c4ba3e

15 files changed

+39
-80
lines changed

llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,11 +1029,8 @@ void SIWholeQuadMode::lowerBlock(MachineBasicBlock &MBB) {
10291029
SmallVector<MachineInstr *, 4> SplitPoints;
10301030
char State = BI.InitialState;
10311031

1032-
auto II = MBB.getFirstNonPHI(), IE = MBB.end();
1033-
while (II != IE) {
1034-
auto Next = std::next(II);
1035-
MachineInstr &MI = *II;
1036-
1032+
for (MachineInstr &MI : llvm::make_early_inc_range(
1033+
llvm::make_range(MBB.getFirstNonPHI(), MBB.end()))) {
10371034
if (StateTransition.count(&MI))
10381035
State = StateTransition[&MI];
10391036

@@ -1051,8 +1048,6 @@ void SIWholeQuadMode::lowerBlock(MachineBasicBlock &MBB) {
10511048
}
10521049
if (SplitPoint)
10531050
SplitPoints.push_back(SplitPoint);
1054-
1055-
II = Next;
10561051
}
10571052

10581053
// Perform splitting after instruction scan to simplify iteration.

llvm/lib/Target/AVR/AVRFrameLowering.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,16 @@ static void fixStackStores(MachineBasicBlock &MBB,
303303
MachineBasicBlock::iterator MI,
304304
const TargetInstrInfo &TII, Register FP) {
305305
// Iterate through the BB until we hit a call instruction or we reach the end.
306-
for (auto I = MI, E = MBB.end(); I != E && !I->isCall();) {
307-
MachineBasicBlock::iterator NextMI = std::next(I);
308-
MachineInstr &MI = *I;
309-
unsigned Opcode = I->getOpcode();
306+
for (MachineInstr &MI :
307+
llvm::make_early_inc_range(llvm::make_range(MI, MBB.end()))) {
308+
if (MI.isCall())
309+
break;
310+
311+
unsigned Opcode = MI.getOpcode();
310312

311313
// Only care of pseudo store instructions where SP is the base pointer.
312-
if (Opcode != AVR::STDSPQRr && Opcode != AVR::STDWSPQRr) {
313-
I = NextMI;
314+
if (Opcode != AVR::STDSPQRr && Opcode != AVR::STDWSPQRr)
314315
continue;
315-
}
316316

317317
assert(MI.getOperand(0).getReg() == AVR::SP &&
318318
"Invalid register, should be SP!");
@@ -324,8 +324,6 @@ static void fixStackStores(MachineBasicBlock &MBB,
324324

325325
MI.setDesc(TII.get(STOpc));
326326
MI.getOperand(0).setReg(FP);
327-
328-
I = NextMI;
329327
}
330328
}
331329

llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,13 @@ void BPFMISimplifyPatchable::checkADDrr(MachineRegisterInfo *MRI,
9797

9898
// Go through all uses of %1 as in %1 = ADD_rr %2, %3
9999
const MachineOperand Op0 = Inst->getOperand(0);
100-
auto Begin = MRI->use_begin(Op0.getReg()), End = MRI->use_end();
101-
decltype(End) NextI;
102-
for (auto I = Begin; I != End; I = NextI) {
103-
NextI = std::next(I);
100+
for (MachineOperand &MO :
101+
llvm::make_early_inc_range(MRI->use_operands(Op0.getReg()))) {
104102
// The candidate needs to have a unique definition.
105-
if (!MRI->getUniqueVRegDef(I->getReg()))
103+
if (!MRI->getUniqueVRegDef(MO.getReg()))
106104
continue;
107105

108-
MachineInstr *DefInst = I->getParent();
106+
MachineInstr *DefInst = MO.getParent();
109107
unsigned Opcode = DefInst->getOpcode();
110108
unsigned COREOp;
111109
if (Opcode == BPF::LDB || Opcode == BPF::LDH || Opcode == BPF::LDW ||
@@ -131,7 +129,7 @@ void BPFMISimplifyPatchable::checkADDrr(MachineRegisterInfo *MRI,
131129
Opcode == BPF::STD || Opcode == BPF::STB32 || Opcode == BPF::STH32 ||
132130
Opcode == BPF::STW32) {
133131
const MachineOperand &Opnd = DefInst->getOperand(0);
134-
if (Opnd.isReg() && Opnd.getReg() == I->getReg())
132+
if (Opnd.isReg() && Opnd.getReg() == MO.getReg())
135133
continue;
136134
}
137135

llvm/lib/Target/Hexagon/HexagonConstPropagation.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,9 @@ bool MachineConstPropagator::rewrite(MachineFunction &MF) {
10451045
// erase instructions during rewriting, so this needs to be delayed until
10461046
// now.
10471047
for (MachineBasicBlock &B : MF) {
1048-
MachineBasicBlock::iterator I = B.begin(), E = B.end();
1049-
while (I != E) {
1050-
auto Next = std::next(I);
1051-
if (I->isBranch() && !InstrExec.count(&*I))
1052-
B.erase(I);
1053-
I = Next;
1054-
}
1048+
for (MachineInstr &MI : llvm::make_early_inc_range(B))
1049+
if (MI.isBranch() && !InstrExec.count(&MI))
1050+
B.erase(&MI);
10551051
}
10561052
return Changed;
10571053
}

llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,9 @@ bool HexagonPacketizer::runOnMachineFunction(MachineFunction &MF) {
234234
// dependence between Insn 0 and Insn 2. This can lead to incorrect
235235
// packetization
236236
for (MachineBasicBlock &MB : MF) {
237-
auto End = MB.end();
238-
auto MI = MB.begin();
239-
while (MI != End) {
240-
auto NextI = std::next(MI);
241-
if (MI->isKill()) {
242-
MB.erase(MI);
243-
End = MB.end();
244-
}
245-
MI = NextI;
246-
}
237+
for (MachineInstr &MI : llvm::make_early_inc_range(MB))
238+
if (MI.isKill())
239+
MB.erase(&MI);
247240
}
248241

249242
// TinyCore with Duplexes: Translate to big-instructions.

llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ namespace {
185185
// nothing to do.
186186
if (MF.size() < 2)
187187
return Changed;
188-
189-
// We can't use a range-based for loop due to clobbering the iterator.
190-
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E;) {
191-
MachineBasicBlock &B = *I++;
188+
189+
for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
192190
Changed |= processBlock(B);
193-
}
194191

195192
return Changed;
196193
}

llvm/lib/Target/PowerPC/PPCTLSDynamicCall.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,9 @@ namespace {
208208

209209
bool Changed = false;
210210

211-
for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
212-
MachineBasicBlock &B = *I++;
211+
for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
213212
if (processBlock(B))
214213
Changed = true;
215-
}
216214

217215
return Changed;
218216
}

llvm/lib/Target/PowerPC/PPCTOCRegDeps.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,9 @@ namespace {
131131
bool runOnMachineFunction(MachineFunction &MF) override {
132132
bool Changed = false;
133133

134-
for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
135-
MachineBasicBlock &B = *I++;
134+
for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
136135
if (processBlock(B))
137136
Changed = true;
138-
}
139137

140138
return Changed;
141139
}

llvm/lib/Target/PowerPC/PPCVSXCopy.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,9 @@ namespace {
148148

149149
bool Changed = false;
150150

151-
for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
152-
MachineBasicBlock &B = *I++;
151+
for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
153152
if (processBlock(B))
154153
Changed = true;
155-
}
156154

157155
return Changed;
158156
}
@@ -169,4 +167,3 @@ INITIALIZE_PASS(PPCVSXCopy, DEBUG_TYPE,
169167
char PPCVSXCopy::ID = 0;
170168
FunctionPass*
171169
llvm::createPPCVSXCopyPass() { return new PPCVSXCopy(); }
172-

llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,9 @@ namespace {
361361
if (DisableVSXFMAMutate)
362362
return Changed;
363363

364-
for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
365-
MachineBasicBlock &B = *I++;
364+
for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
366365
if (processBlock(B))
367366
Changed = true;
368-
}
369367

370368
return Changed;
371369
}

0 commit comments

Comments
 (0)