[PATCH] D59941: [DebugInfo] Improve handling of clobbered fragments

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 08:53:21 PDT 2019


dstenb created this revision.
dstenb added reviewers: aprantl, probinson, dblaikie, rnk, bjope.
dstenb added a project: debug-info.
Herald added subscribers: llvm-commits, jdoerfert, kristof.beyls, javed.absar.
Herald added a project: LLVM.

Currently the DbgValueHistorymap only keeps track of clobbered registers
for the last debug value that it has encountered. This could lead to
preceding register-described debug values living on longer in the
location lists than they should. See PR40283 for an example.  This
patch does not introduce tracking of multiple registers, but changes
the DbgValueHistoryMap structure to allow for that in a follow-up
patch. This patch is not NFC, as it at least fixes two bugs in
DwarfDebug (both are covered in the new clobbered-fragments.mir test):

- If a debug value was clobbered (its End pointer set), the value would still be added to OpenRanges, meaning that the succeeding location list entries could potentially contain stale values.

- If a debug value was clobbered, and there were non-overlapping fragments that were still live after the clobbering, DwarfDebug would not create a location list entry starting directly after the clobbering instruction. This meant that the location list could have a gap until the next debug value for the variable was encountered.

Before this patch, the history map was represented by <Begin, End>
pairs, where a new pair was created for each new debug value. When
dealing with partially overlapping register-described debug values, such
as in the following example:

  DBG_VALUE $reg2, $noreg, !1, !DIExpression(DW_OP_LLVM_fragment, 32, 32)
  [...]
  DBG_VALUE $reg3, $noreg, !1, !DIExpression(DW_OP_LLVM_fragment, 64, 32)
  [...]
  $reg2 = insn1
  [...]
  $reg3 = insn2

the history map would then contain the entries `[<DV1, insn1>, [<DV2, insn2>]`.
This would leave it up to the users of the map to be aware of
the relative order of the instructions, which e.g. could make
DwarfDebug::buildLocationList() needlessly complex. Instead, this patch
makes the history map structure monotonically increasing by dropping the
End pointer, and replacing that with explicit clobbering entries in the
vector. Each debug value has an "end index", which if set, points to the
entry in the vector that ends the debug value. The ending entry can
either be an overlapping debug value, or an instruction which clobbers
the register that the debug value is described by. The ending entry's
instruction can thus either be excluded or included in the debug value's
range. If the end index is not set, the debug value that the entry
introduces is valid until the end of the function.

Changes to test cases:

- DebugInfo/X86/pieces-3.ll: The range of the first DBG_VALUE, which describes that the fragment (0, 64) is located in RDI, was incorrectly ended by the clobbering of RAX, which the second (non-overlapping) DBG_VALUE was described by. With this patch we get a second entry that only describes RDI after that clobbering.
- DebugInfo/ARM/partial-subreg.ll: This test seems to indiciate a bug in LiveDebugValues that is caused by it not being aware of fragments. I have added some comments in the test case about that. Also, before this patch DwarfDebug would incorrectly include a register-described debug value from a preceding block in a location list entry.


Repository:
  rL LLVM

https://reviews.llvm.org/D59941

Files:
  include/llvm/CodeGen/DbgEntityHistoryCalculator.h
  lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
  lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  test/DebugInfo/ARM/partial-subreg.ll
  test/DebugInfo/MIR/X86/clobbered-fragments.mir
  test/DebugInfo/X86/pieces-3.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59941.192645.patch
Type: text/x-patch
Size: 35316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190328/c8af7dcc/attachment.bin>


More information about the llvm-commits mailing list