[llvm-dev] [Debuginfo] Changing llvm.dbg.value and DBG_VALUE to support multiple location operands

Adrian Prantl via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 11 12:24:37 PDT 2020



> On Sep 11, 2020, at 11:12 AM, Tozer, Stephen <stephen.tozer at sony.com> wrote:
> 
> > Can you elaborate what "direct" means? I'm having trouble understanding what the opposite (a non-exact value) would be.
> 
> Apologies, "exact" was a misleading/incorrect term. By direct, I mean that the expression computes the value of the variable, as opposed to its memory address, or the value that it points to.

That sounds to me to be the same concept that I am calling rvalue vs. lvalue. Do you agree, or is there some subtlety that I am missing?

> Within LLVM, where we don't have DW_OP_reg/DW_OP_breg but instead simply refer to a generic SSA value, this could mean either a register location or stack value.
> 
> > At the moment we don't make the lvalue/rvalue distinction in LLVM at all. We make an educated guess in AsmPrinter. But that's wrong and something we should strive to fix during this redesigning.
> 
> I think the opposite; I don't believe there's any reason we need to make the explicit lvalue/rvalue distinction until we're writing DWARF.

Here is an example of why I think that an optimization pass must have the ability to downgrade an lvalue to an rvalue:

; BEFORE
%foo = i32 ...
%mem = alloca i32
call %llvm.dbg.declare(%mem, !DILocalVariable("x"))
store i32* %mem, i32 %foo
...
store i32* %mem, i32 0
...
store i32* %mem, i32 %foo
...

; AFTER
%foo = i32 ...
%mem = alloca i32
call %llvm.dbg.value(%mem, !DILocalVariable("x"), !DIExpression(DW_OP_deref))
store i32* %mem, i32 %foo
; optimization eliminated the store of 0 to %mem and replaced all loads of %mem with "i32 0".
call %llvm.dbg.value(%mem, !DILocalVariable("x"), !DIExpression(DW_OP_constu 0, DW_OP_stack_value))
...
call %llvm.dbg.value(%mem, !DILocalVariable("x"), !DIExpression(DW_OP_deref))
...

The optimization eliminated the store of constant 0 to %mem and replaced all loads of %mem in the subsequent block with a constant "i32 0". This means that we need mark the first dbg.value (that would otherwise look like an lvalue) as an rvalue, because writing a new value to %mem there would not affect the code that is now hardcoded to use a constant 0 value for "x".

what do you think?

-- adrian

> To put it in more general terms, I think that the IR/MIR debug value instructions should only care about how the variable's value can be computed. Whether the result of that computation is an lvalue is unimportant within LLVM itself as far as I can tell, and is redundant when it can be computed from just the DIExpression and location operands.
> 
> >As stated above, I don't think we can trivially determine this, because (at least for dbg.values) this info was lost already in LLVM IR. Unless we say the dbg.declare / dbg.value distinction is what determines lvalues vs. rvalues.
> 
> With the proposed operator, it would be trivial to determine lvalue vs rvalue debug values with a set of rules (ignoring any fragment operator, which may appear at the end but does not affect the location type):
> 
>   1. If the expression is empty, or any location arguments are $noreg => Empty
>   2. If the expression ends with DW_OP_implicit_ptr => Implicit pointer (rvalue)
>   3. If the expression ends with DW_OP_stack_value =>Stack value (rvalue)  // LLVM should produce LLVM_direct instead.
>   4. If the expression ends with DW_OP_LLVM_direct, then...
>     4a. If the preceding expression is just DW_OP_LLVM_arg, 0 and the only location operand is a register => Register location (lvalue)
>     4b. Otherwise => Stack value (rvalue)
>   5. Otherwise => Memory location (lvalue)
> 
> This covers all the expected cases without ambiguity or almost any reduced expressiveness. I believe that the only expression that LLVM will not be able to produce like this is DW_OP_bregN, DW_OP_stack_value due to fact that when DW_OP_LLVM_direct is used, this would be written as a register location instead of a stack value. I don't think there are any cases where we would choose to emit a stack value location when we're able to produce a register location instead, so this shouldn't be a problem.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200911/e502f4b7/attachment.html>


More information about the llvm-dev mailing list