Skip to content

Commit

Permalink
[CodeGen, Target] Use MachineBasicBlock::terminators (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Oct 31, 2021
1 parent c714da2 commit 72710af
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
8 changes: 3 additions & 5 deletions llvm/lib/CodeGen/ModuloSchedule.cpp
Expand Up @@ -141,13 +141,11 @@ void ModuloScheduleExpander::generatePipelinedLoop() {

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

NewKernel = KernelBB;
Expand Down
5 changes: 1 addition & 4 deletions llvm/lib/Target/AArch64/AArch64CondBrTuning.cpp
Expand Up @@ -295,10 +295,7 @@ bool AArch64CondBrTuning::runOnMachineFunction(MachineFunction &MF) {
bool Changed = false;
for (MachineBasicBlock &MBB : MF) {
bool LocalChange = false;
for (MachineBasicBlock::iterator I = MBB.getFirstTerminator(),
E = MBB.end();
I != E; ++I) {
MachineInstr &MI = *I;
for (MachineInstr &MI : MBB.terminators()) {
switch (MI.getOpcode()) {
default:
break;
Expand Down
12 changes: 4 additions & 8 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Expand Up @@ -2464,19 +2464,15 @@ bool SIInstrInfo::analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,

unsigned SIInstrInfo::removeBranch(MachineBasicBlock &MBB,
int *BytesRemoved) const {
MachineBasicBlock::iterator I = MBB.getFirstTerminator();

unsigned Count = 0;
unsigned RemovedSize = 0;
while (I != MBB.end()) {
MachineBasicBlock::iterator Next = std::next(I);
for (MachineInstr &MI : llvm::make_early_inc_range(MBB.terminators())) {
// Skip over artificial terminators when removing instructions.
if (I->isBranch() || I->isReturn()) {
RemovedSize += getInstSizeInBytes(*I);
I->eraseFromParent();
if (MI.isBranch() || MI.isReturn()) {
RemovedSize += getInstSizeInBytes(MI);
MI.eraseFromParent();
++Count;
}
I = Next;
}

if (BytesRemoved)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
Expand Up @@ -343,8 +343,8 @@ static bool hasTailCall(const MachineBasicBlock &MBB) {

/// Returns true if MBB contains an instruction that returns.
static bool hasReturn(const MachineBasicBlock &MBB) {
for (auto I = MBB.getFirstTerminator(), E = MBB.end(); I != E; ++I)
if (I->isReturn())
for (const MachineInstr &MI : MBB.terminators())
if (MI.isReturn())
return true;
return false;
}
Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Target/SystemZ/SystemZMachineScheduler.cpp
Expand Up @@ -106,13 +106,12 @@ void SystemZPostRASchedStrategy::enterMBB(MachineBasicBlock *NextMBB) {

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

0 comments on commit 72710af

Please sign in to comment.