This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Teach LDV how to handle identical variable fragments
ClosedPublic

Authored by Orlando on Feb 5 2020, 8:08 AM.

Details

Summary

This stack of patches are the result of the discussion on D70121 and is split up
to (hopefully) make reviewing easier:

D74052 -- (Mostly) NFC: Prep work
<this> -- Functional change
D74055 -- NFC: Update DbgValueLocation class name and instance names to suit new semantics
D74057 -- NFC: Update UserValue methods to use FragmentInfo instead of DIExpression

These patches fix the issues shown in:
https://bugs.llvm.org/show_bug.cgi?id=41992
https://bugs.llvm.org/show_bug.cgi?id=43957

Functional change summary:
LDV uses interval maps to explicitly represent DBG_VALUE intervals. DBG_VALUEs
are filtered into an interval map based on their { Variable, DIExpression }. The
interval map will coalesce adjacent entries that use the same { Location }.

This causes incorrect debuginfo. Consider the following example:

DBG_VALUE %0, $noreg, "x", DIExpression() ; DV1
...
DBG_VALUE %1, $noreg, "x", DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value) ; DV2
...
DBG_VALUE %0, $noreg, "x", DIExpression() ; DV3

DV2 is put into a separate interval map because it has a different
{ Variable, DIExpression } pair so we get:

Map A:
  [DV1, DV3):%0, [DV3, ...):%0
  ** ranges because they use the same { Location }.
  [DV1, ...):%0
Map B:
  [DV2, ...):%1+4

When the maps are used to emit DBG_VALUEs again we get:

DBG_VALUE %0, $noreg, "x", DIExpression() ; DV1
...
DBG_VALUE %1, $noreg, "x", DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value) ; DV2

This patch fixes the problem by using { Variable, Fragment } to filter the
DBG_VALUEs into maps, and coalesces adjacent entries iff they have the same
{ Location, DIExpression } pair.

The solution is not perfect because we see the similar issues appear when
partially overlapping fragments are encountered, but is far simpler than a
complete solution (i.e. D70121).

Diff Detail

Event Timeline

Orlando created this revision.Feb 5 2020, 8:08 AM
Orlando created this object with visibility "No One".
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2020, 8:08 AM
Orlando edited the summary of this revision. (Show Details)Feb 5 2020, 8:19 AM
Orlando added reviewers: vsk, aprantl, bjope, djtodoro.
Orlando changed the visibility from "No One" to "Public (No Login Required)".
Orlando added a project: debug-info.
Orlando marked an inline comment as done.Feb 5 2020, 8:30 AM
Orlando added inline comments.
llvm/lib/CodeGen/LiveDebugVariables.cpp
113

This should be const. I'll fix this when I address reviewer comments.

djtodoro added inline comments.Feb 6 2020, 12:10 AM
llvm/test/DebugInfo/X86/live-debug-vars-intervals.mir
47

Could be deleted.

49

Could be deleted.

105

I think you do not need most of the attributes (probably only name and alignment ).

168

Here as well.

Orlando updated this revision to Diff 242835.Feb 6 2020, 1:37 AM
Orlando marked 4 inline comments as done.

Thanks for reviewing this @djtodoro

+ Make getExpression const.
+ Tidy up the test.
+ Adjust llvm-locstats test which fails with this patch.

Orlando updated this revision to Diff 243138.Feb 7 2020, 4:43 AM
Orlando edited the summary of this revision. (Show Details)

+ Rebase (see 6531a78ac4b5 caused conflicts) and remove parent.
+ Include bugzilla links in summary.

aprantl accepted this revision.Feb 10 2020, 4:15 PM
This revision is now accepted and ready to land.Feb 10 2020, 4:15 PM

Thanks for reviewing these patches! I will land them now.