From 04671b92e9b90bb4fa22ee8872f5e3244eb1fb68 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 8 Jul 2016 18:26:20 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274898 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64BranchRelaxation.cpp | 10 +++++----- lib/Target/AArch64/AArch64ConditionOptimizer.cpp | 8 ++++---- lib/Target/Hexagon/HexagonInstrInfo.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Target/AArch64/AArch64BranchRelaxation.cpp b/lib/Target/AArch64/AArch64BranchRelaxation.cpp index b7515679ce8..49e334aedff 100644 --- a/lib/Target/AArch64/AArch64BranchRelaxation.cpp +++ b/lib/Target/AArch64/AArch64BranchRelaxation.cpp @@ -465,11 +465,11 @@ bool AArch64BranchRelaxation::relaxBranchInstructions() { // 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; } diff --git a/lib/Target/AArch64/AArch64ConditionOptimizer.cpp b/lib/Target/AArch64/AArch64ConditionOptimizer.cpp index 5a11a05bba8..935a1433107 100644 --- a/lib/Target/AArch64/AArch64ConditionOptimizer.cpp +++ b/lib/Target/AArch64/AArch64ConditionOptimizer.cpp @@ -275,13 +275,13 @@ void AArch64ConditionOptimizer::modifyCmp(MachineInstr *CmpMI, // 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(); diff --git a/lib/Target/Hexagon/HexagonInstrInfo.cpp b/lib/Target/Hexagon/HexagonInstrInfo.cpp index 277ea80f4c5..d3fd517fe49 100644 --- a/lib/Target/Hexagon/HexagonInstrInfo.cpp +++ b/lib/Target/Hexagon/HexagonInstrInfo.cpp @@ -585,7 +585,7 @@ unsigned HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB, // into an infinite loop. MachineBasicBlock *NewTBB, *NewFBB; SmallVector 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(); -- 2.49.0