[PATCH] D85775: [DebugInstrRef][9/9] Handle DBG_INSTR_REFs use-before-defs in LiveDebugValues

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 13:02:25 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.

The MachineSink pass has a lot of code to handle how variable locations move when an instruction sinks. I wrote in PR44117 how it becomes difficult to determine the correct behaviour in the general case. Dealing with this with instruction-referencing variable locations is simple: we just tolerate DBG_INSTR_REFs referring to values that haven't been computed yet. This patch adds support into InstrRefBasedLDV to record when a variable value appears in the middle of a block, and should have a DBG_VALUE added when it appears (a debug use before def).

While described simply, this relies heavily on the value-propagation algorithm in InstrRefBasedLDV. The implementation doesn't attempt to verify the location of a value unless something non-trivial occurs to merge variable values in vlocJoin. This means that a variable with a value that has no location can retain it across all control flow (including loops). It's only when another debug instruction specifies a different variable value that we have to check, and find there's no location.

This property means that if a machine value is defined in a block dominated by a DBG_INSTR_REF that refers to it, all the successor blocks can automatically find a location for that value (if it's not clobbered). Thus in a sense, InstrRefBasedLDV is already supporting and implementing use-before-defs. This patch allows us to specify a variable location in the block where it's defined.

When loading live-in variable locations, TransferTracker currently discards those where it can't find a location for the variable value. However, we can tell from the machine value number whether the value is defined in this block. If it is, add it to a set of use-before-def records. Then, once the relevant instruction has been processed, emit a DBG_VALUE immediately after it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85775

Files:
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/test/DebugInfo/MIR/InstrRef/livedebugvalues_instrref_tolocs.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85775.284864.patch
Type: text/x-patch
Size: 9567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/7d32c971/attachment.bin>


More information about the llvm-commits mailing list