[PATCH] D114364: [DebugInfo][5/N] Recognise extra indirection in instruction-referencing for NRVO tests

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 22 05:32:49 PST 2021


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

In some scenarios, usually involving NRVO, we can issue indirect DBG_VALUEs after SelectionDAG, even in instruction referencing mode (if the variable is an argument). If the corresponding argument value is spilt to the stack, then we have:

- Indirection because it's on the stack,
- Indirection because of the nature of the variable (i.e., it was created with indirection),

However InstrRefBasedLDV only emits one level of indirection. This patch adds the second, by adding an extra DW_OP_deref if necessary.

The two tests modified fail otherwise -- they feature some NRVO, and require two levels of indirection to be correct.

(An alternate solution would be to stop emitting DBG_VALUEs with indirection -- that'll probably work, but I think it should be part of a refactor. InstrRefBasedLDV is agnostic as to whether it's working on DBG_INSTR_REFs or DBG_VALUEs, I might have baked more assumptions into it).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114364

Files:
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll
  llvm/test/DebugInfo/X86/spill-nontrivial-param.ll


Index: llvm/test/DebugInfo/X86/spill-nontrivial-param.ll
===================================================================
--- llvm/test/DebugInfo/X86/spill-nontrivial-param.ll
+++ llvm/test/DebugInfo/X86/spill-nontrivial-param.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -experimental-debug-variable-locations=false | FileCheck %s
+; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck %s
 
 ; Make sure we insert DW_OP_deref when spilling indirect DBG_VALUE instructions.
 ; In this example, 'nt' is passed by address because it is not trivially
Index: llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll
===================================================================
--- llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll
+++ llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -experimental-debug-variable-locations=false | FileCheck -check-prefixes=CHECK,OPT %s
-; RUN: llc -O0 < %s -experimental-debug-variable-locations=false | FileCheck -check-prefixes=CHECK,OPTNONE %s
+; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck -check-prefixes=CHECK,OPT %s
+; RUN: llc -O0 < %s -experimental-debug-variable-locations=true | FileCheck -check-prefixes=CHECK,OPTNONE %s
 
 ; Make sure we insert DW_OP_deref when spilling indirect DBG_VALUE instructions.
 
Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -836,6 +836,15 @@
       unsigned Base = Spill.SpillBase;
       MIB.addReg(Base);
       MIB.addImm(0);
+
+      // Being on the stack makes this location indirect; if it was _already_
+      // indirect though, we need to add extra indirection. See this test for
+      // a scenario where this happens:
+      //     llvm/test/DebugInfo/X86/spill-nontrivial-param.ll
+      if (Properties.Indirect) {
+        std::vector<uint64_t> Elts = {dwarf::DW_OP_deref};
+        Expr = DIExpression::append(Expr, Elts);
+      }
     } else {
       // This is a stack location with a weird subregister offset: emit an undef
       // DBG_VALUE instead.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114364.388888.patch
Type: text/x-patch
Size: 2211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211122/d325f4cd/attachment.bin>


More information about the llvm-commits mailing list