[PATCH] D70121: [WIP][DebugInfo][LDV] Attempt to teach LDV how to handle fragments

Orlando Cazalet-Hyams via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 05:36:52 PST 2019


Orlando created this revision.
Orlando added reviewers: aprantl, vsk, probinson, bjope.
Orlando added a project: debug-info.
Herald added subscribers: llvm-commits, hiraditya, kristof.beyls.
Herald added a project: LLVM.

Related bugs [0, 1]: 41992, 43957

This patch prevents DBG_VALUE instructions being incorrectly coalesced by LiveDebugVariables.

A UserValue represents part of a source variable. Without this patch, a UserValue was identified is looking at the source variable, DIExpression, and the inlined scope of the source variable. DBG_VALUES definitions are added to a particular UserValue if it can be identified by these constraints. The definitions are coalesced if they refer to the same location and are at adjacent slots.

This is a problem because this means arbitrary DIExpressions were being used to classify the definitions. For example, a DW_OP_deref on the value presented in the DBG_VALUE shouldn't change what source variable (part) we're describing, but it would according to that model. Instead of looking at the whole expression to classify definitions we should just be looking at the fragment.

This patch groups UserValues by source variable and inline scope into UserValueGroups. Within the group the UserValues are finally grouped by the fragment from their Expression. When adding a definition to a UserValue in a UserValueGroup, we search for other UserValues in the group with overlapping fragments and add a dummy 'blocker' definition into their location interval map to prevent adjacent locations being coalesced and the definition range being extended beyond this point.

UserValue no longer tracks the Variable and InlinedAt - this is the same for all UserValues in a UserValueGroup. In addition, UserValue no longer tracks the DIExpression associated with the set of DBG_VALUES. DbgValueLocation seemed like a good place to keep track of the DIExpression used by the DBG_VALUE because:

1. This stops the locations with the same FragmentInfo but different DIExpressions being coalesced by the interval map used to track the uses.
2. We can use nullptr to represent a dummy value to prevent coalescing.
3. There is a 1-to-1 mapping of use locations to DIExpressions.

I've addded test pr41992.ll which covers 3 previously failing cases.

[0] https://bugs.llvm.org/show_bug.cgi?id=41992
[1] https://bugs.llvm.org/show_bug.cgi?id=43957

This is a WIP, here is some more info and notes:

1. This is loosely based on top of D68816 <https://reviews.llvm.org/D68816> (adding a read-from-invalid-ptr fix), but removes or changes a lot of it, so I've included all of it in this diff.

2. I want to improve test coverage for this.

3. I had to modify llvm/test/DebugInfo/ARM/PR26163.ll to make it pass and I believe this is a valid change. Diffing the output of this command (pre-patch, patch):



  llc -filetype=obj llvm/test/DebugInfo/ARM/PR26163.ll -stop-after=livedebugvars -o -

gives the following, which looks valid (but not necessarily sensible/optimal) to me since the second DBG_VALUE clobbers the first:

  @@ -117,7 +117,6 @@ body:             |
      frame-setup CFI_INSTRUCTION def_cfa_offset 8
      frame-setup CFI_INSTRUCTION offset $lr, -4
      frame-setup CFI_INSTRUCTION offset $r11, -8
  [-    DBG_VALUE 0, $noreg, !19, !DIExpression(DW_OP_LLVM_fragment, 0, 64), debug-location !27-]
      DBG_VALUE 0, $noreg, !19, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !27
      BL @foo, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, debug-location !28
      $r0 = MOVi 0, 14, $noreg, $noreg, debug-location !29

4. Many `const DIExpression *` params could be `const DIExpression &` to show that they expect a valid pointer. This might make a nice NFC separately.


Repository:
  rL LLVM

https://reviews.llvm.org/D70121

Files:
  llvm/lib/CodeGen/LiveDebugVariables.cpp
  llvm/test/DebugInfo/ARM/PR26163.ll
  llvm/test/DebugInfo/X86/dbg-addr-dse.ll
  llvm/test/DebugInfo/X86/live-debug-vars-dse.mir
  llvm/test/DebugInfo/pr41992.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70121.228876.patch
Type: text/x-patch
Size: 34961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191112/4d4ecd57/attachment.bin>


More information about the llvm-commits mailing list