[DebugInfo] Emit undef DBG_VALUEs when SDNodes are optimised out
authorJeremy Morse <jeremy.morse.llvm@gmail.com>
Mon, 10 Dec 2018 11:20:47 +0000 (11:20 +0000)
committerJeremy Morse <jeremy.morse.llvm@gmail.com>
Mon, 10 Dec 2018 11:20:47 +0000 (11:20 +0000)
commit045c67769d7fe577fc38cccb6fb40fd814437447
tree6c1c9c40451d39815096bcb9a9d8d5cc879de5f7
parente79477895e1af4425aecaded2881e3b3c878faf5
[DebugInfo] Emit undef DBG_VALUEs when SDNodes are optimised out

This is a fix for PR39896, where dbg.value's of SDNodes that have been
optimised out do not lead to "DBG_VALUE undef" instructions being created.
Such undef instructions are necessary to terminate earlier variable
ranges, otherwise variable values leak past the point where they're valid.

The "invalidated" flag of SDDbgValue is currently being abused to mean two
things:
 * The corresponding SDNode is now invalid
 * This SDDbgValue should not be emitted
Of which there are several legitimate combinations of meaning:
 * The SDNode has been invalidated and we should emit "DBG_VALUE undef"
 * The SDNode has been invalidated but the debug data was salvaged, don't
   emit anything for this SDDbgValue
 * This SDDbgValue has been emitted

This patch introduces distinct "Emitted" and "Invalidated" fields to the
SDDbgValue class, updates users accordingly, and generates "undef"
DBG_VALUEs for invalidated records. Awkwardly, there are circumstances
where we emit SDDbgValue's twice, specifically DebugInfo/X86/dbg-addr-dse.ll
which I've preserved.

Differential Revision: https://reviews.llvm.org/D55372

llvm-svn: 348751
llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h
llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp
llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/pr39896.ll [new file with mode: 0644]
llvm/test/DebugInfo/NVPTX/debug-info.ll
llvm/test/DebugInfo/X86/dbg-value-inlined-parameter.ll
llvm/test/DebugInfo/X86/pieces-3.ll