[llvm] r274898 - Target: Avoid getFirstTerminator() => pointer, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 8 11:26:21 PDT 2016
Author: dexonsmith
Date: Fri Jul 8 13:26:20 2016
New Revision: 274898
URL: http://llvm.org/viewvc/llvm-project?rev=274898&view=rev
Log:
Target: Avoid getFirstTerminator() => pointer, NFC
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).
Modified:
llvm/trunk/lib/Target/AArch64/AArch64BranchRelaxation.cpp
llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp
Modified: llvm/trunk/lib/Target/AArch64/AArch64BranchRelaxation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64BranchRelaxation.cpp?rev=274898&r1=274897&r2=274898&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64BranchRelaxation.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64BranchRelaxation.cpp Fri Jul 8 13:26:20 2016
@@ -465,11 +465,11 @@ bool AArch64BranchRelaxation::relaxBranc
// 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;
}
Modified: llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp?rev=274898&r1=274897&r2=274898&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp Fri Jul 8 13:26:20 2016
@@ -275,13 +275,13 @@ void AArch64ConditionOptimizer::modifyCm
// 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();
Modified: llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp?rev=274898&r1=274897&r2=274898&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonInstrInfo.cpp Fri Jul 8 13:26:20 2016
@@ -585,7 +585,7 @@ unsigned HexagonInstrInfo::InsertBranch(
// 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();
More information about the llvm-commits
mailing list