Skip to content

Commit 72710af

Browse files
[CodeGen, Target] Use MachineBasicBlock::terminators (NFC)
1 parent c714da2 commit 72710af

File tree

5 files changed

+16
-26
lines changed

5 files changed

+16
-26
lines changed

llvm/lib/CodeGen/ModuloSchedule.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ void ModuloScheduleExpander::generatePipelinedLoop() {
141141

142142
// Copy any terminator instructions to the new kernel, and update
143143
// names as needed.
144-
for (MachineBasicBlock::iterator I = BB->getFirstTerminator(),
145-
E = BB->instr_end();
146-
I != E; ++I) {
147-
MachineInstr *NewMI = MF.CloneMachineInstr(&*I);
144+
for (MachineInstr &MI : BB->terminators()) {
145+
MachineInstr *NewMI = MF.CloneMachineInstr(&MI);
148146
updateInstruction(NewMI, false, MaxStageCount, 0, VRMap);
149147
KernelBB->push_back(NewMI);
150-
InstrMap[NewMI] = &*I;
148+
InstrMap[NewMI] = &MI;
151149
}
152150

153151
NewKernel = KernelBB;

llvm/lib/Target/AArch64/AArch64CondBrTuning.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,7 @@ bool AArch64CondBrTuning::runOnMachineFunction(MachineFunction &MF) {
295295
bool Changed = false;
296296
for (MachineBasicBlock &MBB : MF) {
297297
bool LocalChange = false;
298-
for (MachineBasicBlock::iterator I = MBB.getFirstTerminator(),
299-
E = MBB.end();
300-
I != E; ++I) {
301-
MachineInstr &MI = *I;
298+
for (MachineInstr &MI : MBB.terminators()) {
302299
switch (MI.getOpcode()) {
303300
default:
304301
break;

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,19 +2464,15 @@ bool SIInstrInfo::analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
24642464

24652465
unsigned SIInstrInfo::removeBranch(MachineBasicBlock &MBB,
24662466
int *BytesRemoved) const {
2467-
MachineBasicBlock::iterator I = MBB.getFirstTerminator();
2468-
24692467
unsigned Count = 0;
24702468
unsigned RemovedSize = 0;
2471-
while (I != MBB.end()) {
2472-
MachineBasicBlock::iterator Next = std::next(I);
2469+
for (MachineInstr &MI : llvm::make_early_inc_range(MBB.terminators())) {
24732470
// Skip over artificial terminators when removing instructions.
2474-
if (I->isBranch() || I->isReturn()) {
2475-
RemovedSize += getInstSizeInBytes(*I);
2476-
I->eraseFromParent();
2471+
if (MI.isBranch() || MI.isReturn()) {
2472+
RemovedSize += getInstSizeInBytes(MI);
2473+
MI.eraseFromParent();
24772474
++Count;
24782475
}
2479-
I = Next;
24802476
}
24812477

24822478
if (BytesRemoved)

llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ static bool hasTailCall(const MachineBasicBlock &MBB) {
343343

344344
/// Returns true if MBB contains an instruction that returns.
345345
static bool hasReturn(const MachineBasicBlock &MBB) {
346-
for (auto I = MBB.getFirstTerminator(), E = MBB.end(); I != E; ++I)
347-
if (I->isReturn())
346+
for (const MachineInstr &MI : MBB.terminators())
347+
if (MI.isReturn())
348348
return true;
349349
return false;
350350
}

llvm/lib/Target/SystemZ/SystemZMachineScheduler.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ void SystemZPostRASchedStrategy::enterMBB(MachineBasicBlock *NextMBB) {
106106

107107
// Emit incoming terminator(s). Be optimistic and assume that branch
108108
// prediction will generally do "the right thing".
109-
for (MachineBasicBlock::iterator I = SinglePredMBB->getFirstTerminator();
110-
I != SinglePredMBB->end(); I++) {
111-
LLVM_DEBUG(dbgs() << "** Emitting incoming branch: "; I->dump(););
112-
bool TakenBranch = (I->isBranch() &&
113-
(TII->getBranchInfo(*I).isIndirect() ||
114-
TII->getBranchInfo(*I).getMBBTarget() == MBB));
115-
HazardRec->emitInstruction(&*I, TakenBranch);
109+
for (MachineInstr &MI : SinglePredMBB->terminators()) {
110+
LLVM_DEBUG(dbgs() << "** Emitting incoming branch: "; MI.dump(););
111+
bool TakenBranch = (MI.isBranch() &&
112+
(TII->getBranchInfo(MI).isIndirect() ||
113+
TII->getBranchInfo(MI).getMBBTarget() == MBB));
114+
HazardRec->emitInstruction(&MI, TakenBranch);
116115
if (TakenBranch)
117116
break;
118117
}

0 commit comments

Comments
 (0)