Hi,
This patch adds support to the instruction-referencing LiveDebugValues implementation for emitting entry values. It depends on the parent patch to detect when variable locations are clobbered within blocks. Here are the headline figures from the 'PC Ranges covered' field of llvm-locstats:
VarLocBasedLDV | InstrRefBasedLDV | |
No entry values | 54% | 56% |
Entry values enabled | 56% | 61% |
Which, assuming that I've followed the preconditions for emitting entry value locations, is an improvement. Full output of llvm-locstats can be found here [0]. ("Total availability" goes down a little because instr-ref-ldv is a little more aggressive about not propagating variable locations out of their scopes).
The instruction referencing implementations tracking by value rather than location means that we can get around two of the issues with the VarLoc implementation. DBG_VALUE instructions that re-assign the same value to a variable are no longer a problem, because we can "see through" to the value being assigned rather than just the location. We also don't need to do anything special during the dataflow stages: the "variable value problem" doesn't need to know whether a value is available most of the time, and the times it does needs to know are always when entry values need to be terminated (i.e., when differing variable values merge).
The patch modifies the "TransferTracker" class, which is responsible for turning maps of variable => values, and values => locations, into DBG_VALUE instructions within blocks. Two helper functions identify when a variable is an entry value candidate; and when a machine value is an entry value. recoverAsEntryValue tests these two things and emits a DBG_VALUE with an entry value expression if they're true. recoverAsEntryValue is called on two occasions: when a register (or spill slot) is clobbered and we can't find a replacement location for the value it contained; and on entry to a block, if the value isn't live at that point.
This can be tested by using the flag added in the parent patch: -force-instr-ref-livedebugvalues=1. I've added additional RUN lines to a bunch of entry value tests to ensure they work with InstRefBasedLDV: I found these by "git grep"'ing for 'entry_value' and ignoring anything that appeared to be testing call sites. Note that there's one serious modification to a test, kill-entry-value-after-diamond-bbs.mir. My reading of the test is that VarLocBasedLDV has to drop the entry value location because it doesn't know if the DBG_VALUEs in the diamond structure are new value assignments; wheras InstrRefBasedLDV can "see" that the DBG_VALUEs aren't assigning a new value. Advice most welcome: it might be best to update the test to ensure the DBG_VALUEs refer to a different value.
[0] https://gist.github.com/jmorse/a14763d935ef5d20e6e5dc41672c734a
Should this be a separate patch? Does this affect/apply to the "copies" as backups?