Stop using an implicit conversion from the return of
MachineBasicBlock::getFirstTerminator to MachineInstr*. In two cases,
directly dereference to a MachineInstr& since later code assumes it's
valid. In a third case, change to an iterator since later code checks
against MachineBasicBlock::end.
Although the fix for the third case avoids undefined behaviour, I expect
this doesn't cause a functionality change in practice (since the basic
block already has a terminator).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274898
91177308-0d34-0410-b5e6-
96231b3b80d8
// end() for termination.
for (MachineFunction::iterator I = MF->begin(); I != MF->end(); ++I) {
MachineBasicBlock &MBB = *I;
- MachineInstr *MI = MBB.getFirstTerminator();
- if (isConditionalBranch(MI->getOpcode()) &&
- !isBlockInRange(MI, getDestBlock(MI),
- getBranchDisplacementBits(MI->getOpcode()))) {
- fixupConditionalBranch(MI);
+ MachineInstr &MI = *MBB.getFirstTerminator();
+ if (isConditionalBranch(MI.getOpcode()) &&
+ !isBlockInRange(&MI, getDestBlock(&MI),
+ getBranchDisplacementBits(MI.getOpcode()))) {
+ fixupConditionalBranch(&MI);
++NumRelaxed;
Changed = true;
}
// The fact that this comparison was picked ensures that it's related to the
// first terminator instruction.
- MachineInstr *BrMI = MBB->getFirstTerminator();
+ MachineInstr &BrMI = *MBB->getFirstTerminator();
// Change condition in branch instruction.
- BuildMI(*MBB, BrMI, BrMI->getDebugLoc(), TII->get(AArch64::Bcc))
+ BuildMI(*MBB, BrMI, BrMI.getDebugLoc(), TII->get(AArch64::Bcc))
.addImm(Cmp)
- .addOperand(BrMI->getOperand(1));
- BrMI->eraseFromParent();
+ .addOperand(BrMI.getOperand(1));
+ BrMI.eraseFromParent();
MBB->updateTerminator();
// into an infinite loop.
MachineBasicBlock *NewTBB, *NewFBB;
SmallVector<MachineOperand, 4> Cond;
- MachineInstr *Term = MBB.getFirstTerminator();
+ auto Term = MBB.getFirstTerminator();
if (Term != MBB.end() && isPredicated(*Term) &&
!AnalyzeBranch(MBB, NewTBB, NewFBB, Cond, false)) {
MachineBasicBlock *NextBB = &*++MBB.getIterator();