Page MenuHomePhabricator

[DebugInfo] Add replaceArg function for removing duplicates from DBG_VALUE_LIST expressions

Authored by StephenTozer on Jul 15 2020, 11:31 AM.



This patch continues the work discussed in the RFC[0] for DBG_VALUE_LIST.

This is a very simple patch that is not needed for the basic addition of the DBG_VALUE_LIST instruction, but is needed for both the LiveDebugValues and LiveDebugVariables patches that follow it.

When a DBG_VALUE_LIST contains 2 or more identical debug operands, at certain passes we want to be able to remove the duplicate operands; the purpose of the replaceArg function is to modify a DIExpression by removing a duplicated operand. This means given a base operand x and a duplicate operand y, replacing each instance of DW_OP_LLVM_arg y with DW_OP_LLVM_arg x, and decrementing all arg > y as the operand array indices shift. For example, if we have:

DBG_VALUE_LIST "x", DIExpression(DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus, DW_OP_LLVM_arg 2, DW_OP_mul), %0, %0, %1

The debug operands 0 and 1 are the same, so we can remove debug operand 1 and replace its uses with debug operand 0, giving us:

DBG_VALUE_LIST "x", DIExpression(DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 0, DW_OP_plus, DW_OP_LLVM_arg 1, DW_OP_mul), %0, %1

This isn't necessary when handling the instruction in generic passes, but when we perform more in-depth analysis on debug value liveness (as in LiveDebugValues and LiveDebugVariables) having the same location appear more than once in a variable location is an issue, so we remove duplicates only as we enter those passes.


Diff Detail

Event Timeline

StephenTozer created this revision.Jul 15 2020, 11:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2020, 11:31 AM
StephenTozer retitled this revision from [DebugInfo] Add replaceArg function for handling DBG_VALUE_LIST expressions to [DebugInfo] Add replaceArg function for removing duplicates from DBG_VALUE_LIST expressions.Jul 15 2020, 11:35 AM
StephenTozer edited the summary of this revision. (Show Details)
StephenTozer added a project: debug-info.
StephenTozer added a subscriber: debug-info.
StephenTozer edited the summary of this revision. (Show Details)Jul 15 2020, 5:33 PM

Could you please add a unit test for this?


I see the comment of the function above makes the same mistake: This is creating a copy of Expr, not modifying it.

Add a simple unit test for the new function.

aprantl accepted this revision.Jul 27 2020, 1:01 PM
aprantl added inline comments.

would you mind fixing this, too?

This revision is now accepted and ready to land.Jul 27 2020, 1:01 PM

Rebased to recent master, no actual changes.

This revision was landed with ongoing or failed builds.Mar 9 2021, 9:41 AM
This revision was automatically updated to reflect the committed changes.