From 6e3ac342029b7aa5bde9be1f980f3ff6792ca625 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 1 Jul 2016 00:40:57 +0000 Subject: [PATCH] CodeGen: Use MachineInstr& in PrologEpilogInserter, NFC Use MachineInstr& over MachineInstr* to avoid implicit iterator to pointer conversions. MachineInstr*-as-nullptr was being used as a flag for whether the for loop terminated normally; I added an explicit `bool` instead. llvm-svn: 274310 --- llvm/lib/CodeGen/PrologEpilogInserter.cpp | 38 ++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index fb335ee79f61..20a9a394ebd0 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -1062,24 +1062,25 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, continue; } - MachineInstr *MI = I; + MachineInstr &MI = *I; bool DoIncr = true; - for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { - if (!MI->getOperand(i).isFI()) + bool DidFinishLoop = true; + for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { + if (!MI.getOperand(i).isFI()) continue; // Frame indices in debug values are encoded in a target independent // way with simply the frame index and offset rather than any // target-specific addressing mode. - if (MI->isDebugValue()) { + if (MI.isDebugValue()) { assert(i == 0 && "Frame indices can only appear as the first " "operand of a DBG_VALUE machine instruction"); unsigned Reg; - MachineOperand &Offset = MI->getOperand(1); - Offset.setImm(Offset.getImm() + - TFI->getFrameIndexReference( - Fn, MI->getOperand(0).getIndex(), Reg)); - MI->getOperand(0).ChangeToRegister(Reg, false /*isDef*/); + MachineOperand &Offset = MI.getOperand(1); + Offset.setImm( + Offset.getImm() + + TFI->getFrameIndexReference(Fn, MI.getOperand(0).getIndex(), Reg)); + MI.getOperand(0).ChangeToRegister(Reg, false /*isDef*/); continue; } @@ -1088,16 +1089,16 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, // implementation other than historical accident. The only // remaining difference is the unconditional use of the stack // pointer as the base register. - if (MI->getOpcode() == TargetOpcode::STATEPOINT) { - assert((!MI->isDebugValue() || i == 0) && + if (MI.getOpcode() == TargetOpcode::STATEPOINT) { + assert((!MI.isDebugValue() || i == 0) && "Frame indicies can only appear as the first operand of a " "DBG_VALUE machine instruction"); unsigned Reg; - MachineOperand &Offset = MI->getOperand(i + 1); + MachineOperand &Offset = MI.getOperand(i + 1); int refOffset = TFI->getFrameIndexReferencePreferSP( - Fn, MI->getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false); + Fn, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false); Offset.setImm(Offset.getImm() + refOffset); - MI->getOperand(i).ChangeToRegister(Reg, false /*isDef*/); + MI.getOperand(i).ChangeToRegister(Reg, false /*isDef*/); continue; } @@ -1123,7 +1124,7 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, DoIncr = false; } - MI = nullptr; + DidFinishLoop = false; break; } @@ -1134,13 +1135,14 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, // Note that this must come after eliminateFrameIndex, because // if I itself referred to a frame index, we shouldn't count its own // adjustment. - if (MI && InsideCallSequence) - SPAdj += TII.getSPAdjust(*MI); + if (DidFinishLoop && InsideCallSequence) + SPAdj += TII.getSPAdjust(MI); if (DoIncr && I != BB->end()) ++I; // Update register states. - if (RS && !FrameIndexVirtualScavenging && MI) RS->forward(MI); + if (RS && !FrameIndexVirtualScavenging && DidFinishLoop) + RS->forward(MI); } }