[PATCH] D85749: [DebugInstrRef][4/9] Support recording of instruction reference substitutions

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 09:32:38 PDT 2020


jmorse created this revision.
jmorse added a reviewer: debug-info.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
jmorse requested review of this revision.

At various points in the post-isel optimisation passes, instructions get rewritten and replaced. One way to handle this is just to transfer the instruction number from the old to the new instruction -- however that doesn't account for passes like TwoAddressInstruction, which change the positions of operands. Instead:

- We never re-use instruction numbers: when a new instruction is created, it gets a new number,
- This patch adds a table of "substitutions": a mapping from old <inst,operand> pairs to the new ones.

This stems from patch 1 in this series: there's no connection between instruction numbers and DBG_INSTR_REFs preserved.

The downside of this is that we end up preserving in memory a mapping table, which more or less contains the history of optimisations that have happened to the function; and we have to apply the substitutions later, when LiveDebugValues runs. IMO this is a worthy price to pay, one table isn't highly expensive, and it models the way I'd like variable location tracking to work, doing as little work as possible during compilation and resolving variables back to locations at the end.

An additional benefit of changing instruction numbers when the instruction is recreated / modified is that changes which destroy the creator of a value can be expressed, by not creating a substitution for the old <inst,operand> pair. An example would be, if there were a divide instruction that generated the quotient and remainder, and it were replaced by one that only generated the quotient:

  $rax, $rcx = div-and-remainder $rdx, $rsi, debug-instr-num 1
  DBG_INSTR_REF 1, 0
  DBG_INSTR_REF 1, 1

Would become

  $rax = div $rdx, $rsi, debug-instr-num 2
  DBG_INSTR_REF 1, 0
  DBG_INSTR_REF 1, 1

With a substitution entered from <1, 0> to <2, 0>, and no substitution created for <1, 1> as it's no longer generated.

This patch only adds the data structure and MIR format, plus round-trip test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85749

Files:
  llvm/include/llvm/CodeGen/MIRYamlMapping.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MIRPrinter.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/test/DebugInfo/MIR/InstrRef/substitusions-roundtrip.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85749.284787.patch
Type: text/x-patch
Size: 8201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/0a8f8559/attachment.bin>


More information about the llvm-commits mailing list