diff options
author | stozer <stephen.tozer@sony.com> | 2020-06-22 16:01:12 +0100 |
---|---|---|
committer | stozer <stephen.tozer@sony.com> | 2020-06-22 16:01:12 +0100 |
commit | 539381da26096df54ccf862088c8242498a7dcae (patch) | |
tree | d900f6b3513c227d8f5fd572b390705bb2f4ea0c /llvm/lib/CodeGen/MachineInstr.cpp | |
parent | 597a9070b52d235fac40ef55b9d16bf77d8f4dd7 (diff) | |
download | llvm-539381da26096df54ccf862088c8242498a7dcae.zip llvm-539381da26096df54ccf862088c8242498a7dcae.tar.gz llvm-539381da26096df54ccf862088c8242498a7dcae.tar.bz2 |
[DebugInfo] Update MachineInstr to help support variadic DBG_VALUE instructions
Following on from this RFC[0] from a while back, this is the first patch towards
implementing variadic debug values.
This patch specifically adds a set of functions to MachineInstr for performing
operations specific to debug values, and replacing uses of the more general
functions where appropriate. The most prevalent of these is replacing
getOperand(0) with getDebugOperand(0) for debug-value-specific code, as the
operands corresponding to values will no longer be at index 0, but index 2 and
upwards: getDebugOperand(x) == getOperand(x+2). Similar replacements have been
added for the other operands, along with some helper functions to replace
oft-repeated code and operate on a variable number of value operands.
[0] http://lists.llvm.org/pipermail/llvm-dev/2020-February/139376.html<Paste>
Differential Revision: https://reviews.llvm.org/D81852
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 987de0c..d418159 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -834,11 +834,26 @@ const DILabel *MachineInstr::getDebugLabel() const { return cast<DILabel>(getOperand(0).getMetadata()); } +const MachineOperand &MachineInstr::getDebugVariableOp() const { + assert(isDebugValue() && "not a DBG_VALUE"); + return getOperand(2); +} + +MachineOperand &MachineInstr::getDebugVariableOp() { + assert(isDebugValue() && "not a DBG_VALUE"); + return getOperand(2); +} + const DILocalVariable *MachineInstr::getDebugVariable() const { assert(isDebugValue() && "not a DBG_VALUE"); return cast<DILocalVariable>(getOperand(2).getMetadata()); } +MachineOperand &MachineInstr::getDebugExpressionOp() { + assert(isDebugValue() && "not a DBG_VALUE"); + return getOperand(3); +} + const DIExpression *MachineInstr::getDebugExpression() const { assert(isDebugValue() && "not a DBG_VALUE"); return cast<DIExpression>(getOperand(3).getMetadata()); @@ -1786,12 +1801,12 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, } // Print extra comments for DEBUG_VALUE. - if (isDebugValue() && getOperand(e - 2).isMetadata()) { + if (isDebugValue() && getDebugVariableOp().isMetadata()) { if (!HaveSemi) { OS << ";"; HaveSemi = true; } - auto *DV = cast<DILocalVariable>(getOperand(e - 2).getMetadata()); + auto *DV = getDebugVariable(); OS << " line no:" << DV->getLine(); if (isIndirectDebugValue()) OS << " indirect"; @@ -2097,7 +2112,8 @@ static const DIExpression *computeExprForSpill(const MachineInstr &MI) { const DIExpression *Expr = MI.getDebugExpression(); if (MI.isIndirectDebugValue()) { - assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset"); + assert(MI.getDebugOffset().getImm() == 0 && + "DBG_VALUE with nonzero offset"); Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore); } return Expr; @@ -2117,9 +2133,9 @@ MachineInstr *llvm::buildDbgValueForSpill(MachineBasicBlock &BB, void llvm::updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex) { const DIExpression *Expr = computeExprForSpill(Orig); - Orig.getOperand(0).ChangeToFrameIndex(FrameIndex); - Orig.getOperand(1).ChangeToImmediate(0U); - Orig.getOperand(3).setMetadata(Expr); + Orig.getDebugOperand(0).ChangeToFrameIndex(FrameIndex); + Orig.getDebugOffset().ChangeToImmediate(0U); + Orig.getDebugExpressionOp().setMetadata(Expr); } void MachineInstr::collectDebugValues( @@ -2133,8 +2149,7 @@ void MachineInstr::collectDebugValues( DI != DE; ++DI) { if (!DI->isDebugValue()) return; - if (DI->getOperand(0).isReg() && - DI->getOperand(0).getReg() == MI.getOperand(0).getReg()) + if (DI->getDebugOperandForReg(MI.getOperand(0).getReg())) DbgValues.push_back(&*DI); } } @@ -2146,21 +2161,20 @@ void MachineInstr::changeDebugValuesDefReg(Register Reg) { if (!getOperand(0).isReg()) return; - unsigned DefReg = getOperand(0).getReg(); + Register DefReg = getOperand(0).getReg(); auto *MRI = getRegInfo(); for (auto &MO : MRI->use_operands(DefReg)) { auto *DI = MO.getParent(); if (!DI->isDebugValue()) continue; - if (DI->getOperand(0).isReg() && - DI->getOperand(0).getReg() == DefReg){ + if (DI->getDebugOperandForReg(DefReg)) { DbgValues.push_back(DI); } } // Propagate Reg to debug value instructions. for (auto *DBI : DbgValues) - DBI->getOperand(0).setReg(Reg); + DBI->getDebugOperandForReg(DefReg)->setReg(Reg); } using MMOList = SmallVector<const MachineMemOperand *, 2>; |