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

+2-7
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

+7-9
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

+5-7
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

+3-7
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

+3-10
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

+2-5
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

+1-3
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

+1-3
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

+1-4
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

+1-3
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
}

llvm/lib/Target/X86/X86ISelLowering.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -33838,14 +33838,11 @@ X86TargetLowering::EmitLoweredSelect(MachineInstr &MI,
3383833838
}
3383933839

3384033840
// Transfer any debug instructions inside the CMOV sequence to the sunk block.
33841-
auto DbgEnd = MachineBasicBlock::iterator(LastCMOV);
33842-
auto DbgIt = MachineBasicBlock::iterator(MI);
33843-
while (DbgIt != DbgEnd) {
33844-
auto Next = std::next(DbgIt);
33845-
if (DbgIt->isDebugInstr())
33846-
SinkMBB->push_back(DbgIt->removeFromParent());
33847-
DbgIt = Next;
33848-
}
33841+
auto DbgRange = llvm::make_range(MachineBasicBlock::iterator(MI),
33842+
MachineBasicBlock::iterator(LastCMOV));
33843+
for (MachineInstr &MI : llvm::make_early_inc_range(DbgRange))
33844+
if (MI.isDebugInstr())
33845+
SinkMBB->push_back(MI.removeFromParent());
3384933846

3385033847
// Transfer the remainder of ThisMBB and its successor edges to SinkMBB.
3385133848
SinkMBB->splice(SinkMBB->end(), ThisMBB,

llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ X86LowerAMXIntrinsics::lowerTileDP(Instruction *TileDP) {
498498
Value *ResAMX =
499499
Builder.CreateBitCast(ResVec, Type::getX86_AMXTy(Builder.getContext()));
500500
// Delete TileDP intrinsic and do some clean-up.
501-
for (auto UI = TileDP->use_begin(), UE = TileDP->use_end(); UI != UE;) {
502-
Instruction *I = cast<Instruction>((UI++)->getUser());
501+
for (Use &U : llvm::make_early_inc_range(TileDP->uses())) {
502+
Instruction *I = cast<Instruction>(U.getUser());
503503
Value *Vec;
504504
if (match(I, m_BitCast(m_Value(Vec)))) {
505505
I->replaceAllUsesWith(ResVec);
@@ -542,9 +542,8 @@ bool X86LowerAMXIntrinsics::lowerTileLoadStore(Instruction *TileLoadStore) {
542542
Value *ResAMX =
543543
Builder.CreateBitCast(ResVec, Type::getX86_AMXTy(Builder.getContext()));
544544
// Delete tileloadd6 intrinsic and do some clean-up
545-
for (auto UI = TileLoadStore->use_begin(), UE = TileLoadStore->use_end();
546-
UI != UE;) {
547-
Instruction *I = cast<Instruction>((UI++)->getUser());
545+
for (Use &U : llvm::make_early_inc_range(TileLoadStore->uses())) {
546+
Instruction *I = cast<Instruction>(U.getUser());
548547
Value *Vec;
549548
if (match(I, m_BitCast(m_Value(Vec)))) {
550549
I->replaceAllUsesWith(ResVec);

llvm/lib/Target/X86/X86LowerAMXType.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ bool X86LowerAMXType::visit() {
302302
Col2Row.clear();
303303

304304
for (BasicBlock *BB : post_order(&Func)) {
305-
for (BasicBlock::reverse_iterator II = BB->rbegin(), IE = BB->rend();
306-
II != IE;) {
307-
Instruction &Inst = *II++;
305+
for (Instruction &Inst : llvm::make_early_inc_range(llvm::reverse(*BB))) {
308306
auto *Bitcast = dyn_cast<BitCastInst>(&Inst);
309307
if (!Bitcast)
310308
continue;

llvm/lib/Target/X86/X86LowerTileCopy.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ bool X86LowerTileCopy::runOnMachineFunction(MachineFunction &MF) {
7575
bool Changed = false;
7676

7777
for (MachineBasicBlock &MBB : MF) {
78-
for (MachineBasicBlock::iterator MII = MBB.begin(), MIE = MBB.end();
79-
MII != MIE;) {
80-
MachineInstr &MI = *MII++;
78+
for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) {
8179
if (!MI.isCopy())
8280
continue;
8381
MachineOperand &DstMO = MI.getOperand(0);

llvm/lib/Target/X86/X86OptimizeLEAs.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,8 @@ bool X86OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) {
653653
// isReplaceable function.
654654
Register FirstVReg = First.getOperand(0).getReg();
655655
Register LastVReg = Last.getOperand(0).getReg();
656-
for (auto UI = MRI->use_begin(LastVReg), UE = MRI->use_end();
657-
UI != UE;) {
658-
MachineOperand &MO = *UI++;
656+
for (MachineOperand &MO :
657+
llvm::make_early_inc_range(MRI->use_operands(LastVReg))) {
659658
MachineInstr &MI = *MO.getParent();
660659

661660
if (MI.isDebugValue()) {

0 commit comments

Comments
 (0)