[PATCH] D111317: [DebugInfo][InstrRef] Track instructions that write-to-stack after having a spill fused into them

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 7 08:33:26 PDT 2021


jmorse created this revision.
jmorse added reviewers: Orlando, StephenTozer, TWeaver.
Herald added subscribers: hiraditya, qcolombet.
jmorse requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

During register allocation, some instructions can have stack spills fused into them. It means that when vregs are allocated on the stack we can convert:

  SETCCr %0
  DBG_VALUE $0

to

  SETCCm %stack.0
  DBG_VALUE %stack.0

for example. DBG_VALUE instructions can simply have their vreg operands replaced with a stack location, and it all Just Works (TM). Unfortunately instruction referencing finds this harder: a store to the stack doesn't have a specific operand number, therefore we don't substitute the old operand for a new operand, and the location is dropped.

This patch implements a solution: just recognise the memory operand attached to an instruction with a Special Number (TM), and record a substitution between the old value and the new one. Thus we would have:

  SETCCr %0 [...] debug-instr-number 1 :: (store (s32) into %stack.0)
  DBG_INSTR_REF 1, 0

become

  SETCCm %stack.0 [...] debug-instr-number 2 :: (store (s32) into %stack.0)
  DBG_INSTR_REF 1, 0

With a substitution from operand (1, 0) to (2, MemoryOperand). In LiveDebugValues, we can identify the stack slot written to just like a spill instruction, and track its value from that point onwards.

This patch installs the substitution code into InlineSpiller: it's not that interesting, just adds a substitution. It's not completely clear to me what all the circumstances that the spiller runs with are, so I've filtered to only substitute in common cases, see the two MIR tests added.

In InstrRefBasedLDV, we now:

- Recognise instructions that write to stack slots as def'ing that stack slot,
- Allow DBG_INSTR_REFs that refer to a memory operand to "read" the value defined by that instruction, in the stack slot.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111317

Files:
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/lib/CodeGen/InlineSpiller.cpp
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/test/DebugInfo/MIR/InstrRef/memory-operand-folding-tieddef.mir
  llvm/test/DebugInfo/MIR/InstrRef/memory-operand-folding.mir
  llvm/test/DebugInfo/MIR/InstrRef/memory-operand-tracking.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111317.377861.patch
Type: text/x-patch
Size: 29984 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211007/9591ccce/attachment.bin>


More information about the llvm-commits mailing list