[llvm] r274931 - NVPTX: Avoid implicit iterator conversions, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 8 14:10:58 PDT 2016
Author: dexonsmith
Date: Fri Jul 8 16:10:58 2016
New Revision: 274931
URL: http://llvm.org/viewvc/llvm-project?rev=274931&view=rev
Log:
NVPTX: Avoid implicit iterator conversions, NFC
Avoid implicit conversions from MachineInstrBundleIterator to
MachineInstr* in the NVPTX backend, mainly by preferring MachineInstr&
over MachineInstr* when a pointer isn't nullable and using range-based
for loops.
There was one piece of questionable code in
NVPTXInstrInfo::AnalyzeBranch, where a condition checked a pointer
converted from an iterator for nullptr. Since this case is impossible
(moreover, the code above guarantees that the iterator is valid), I
removed the check when I changed the pointer to a reference.
Despite that case, there should be no functionality change here.
Modified:
llvm/trunk/lib/Target/NVPTX/NVPTXFrameLowering.cpp
llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.cpp
llvm/trunk/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXFrameLowering.cpp?rev=274931&r1=274930&r2=274931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXFrameLowering.cpp Fri Jul 8 16:10:58 2016
@@ -34,7 +34,7 @@ void NVPTXFrameLowering::emitPrologue(Ma
MachineBasicBlock &MBB) const {
if (MF.getFrameInfo()->hasStackObjects()) {
assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
- MachineInstr *MI = MBB.begin();
+ MachineInstr *MI = &MBB.front();
MachineRegisterInfo &MR = MF.getRegInfo();
// This instruction really occurs before first instruction
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.cpp?rev=274931&r1=274930&r2=274931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXInstrInfo.cpp Fri Jul 8 16:10:58 2016
@@ -155,17 +155,17 @@ bool NVPTXInstrInfo::AnalyzeBranch(
return false;
// Get the last instruction in the block.
- MachineInstr *LastInst = I;
+ MachineInstr &LastInst = *I;
// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
- if (LastInst->getOpcode() == NVPTX::GOTO) {
- TBB = LastInst->getOperand(0).getMBB();
+ if (LastInst.getOpcode() == NVPTX::GOTO) {
+ TBB = LastInst.getOperand(0).getMBB();
return false;
- } else if (LastInst->getOpcode() == NVPTX::CBranch) {
+ } else if (LastInst.getOpcode() == NVPTX::CBranch) {
// Block ends with fall-through condbranch.
- TBB = LastInst->getOperand(1).getMBB();
- Cond.push_back(LastInst->getOperand(0));
+ TBB = LastInst.getOperand(1).getMBB();
+ Cond.push_back(LastInst.getOperand(0));
return false;
}
// Otherwise, don't know what this is.
@@ -173,26 +173,26 @@ bool NVPTXInstrInfo::AnalyzeBranch(
}
// Get the instruction before it if it's a terminator.
- MachineInstr *SecondLastInst = I;
+ MachineInstr &SecondLastInst = *I;
// If there are three terminators, we don't know what sort of block this is.
- if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
+ if (I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;
// If the block ends with NVPTX::GOTO and NVPTX:CBranch, handle it.
- if (SecondLastInst->getOpcode() == NVPTX::CBranch &&
- LastInst->getOpcode() == NVPTX::GOTO) {
- TBB = SecondLastInst->getOperand(1).getMBB();
- Cond.push_back(SecondLastInst->getOperand(0));
- FBB = LastInst->getOperand(0).getMBB();
+ if (SecondLastInst.getOpcode() == NVPTX::CBranch &&
+ LastInst.getOpcode() == NVPTX::GOTO) {
+ TBB = SecondLastInst.getOperand(1).getMBB();
+ Cond.push_back(SecondLastInst.getOperand(0));
+ FBB = LastInst.getOperand(0).getMBB();
return false;
}
// If the block ends with two NVPTX:GOTOs, handle it. The second one is not
// executed, so remove it.
- if (SecondLastInst->getOpcode() == NVPTX::GOTO &&
- LastInst->getOpcode() == NVPTX::GOTO) {
- TBB = SecondLastInst->getOperand(0).getMBB();
+ if (SecondLastInst.getOpcode() == NVPTX::GOTO &&
+ LastInst.getOpcode() == NVPTX::GOTO) {
+ TBB = SecondLastInst.getOperand(0).getMBB();
I = LastInst;
if (AllowModify)
I->eraseFromParent();
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp?rev=274931&r1=274930&r2=274931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp Fri Jul 8 16:10:58 2016
@@ -55,11 +55,10 @@ bool NVPTXPrologEpilogPass::runOnMachine
calculateFrameObjectOffsets(MF);
- for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) {
- for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
- MachineInstr *MI = I;
- for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
- if (!MI->getOperand(i).isFI())
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : MBB) {
+ for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
+ if (!MI.getOperand(i).isFI())
continue;
TRI.eliminateFrameIndex(MI, 0, i, nullptr);
Modified = true;
More information about the llvm-commits
mailing list