[llvm-dev] DW_OP_implicit_pointer design/implementation in general

Alok Sharma via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 19 20:55:52 PST 2019


 > I don't have a strong opinion on representation. I can see how having a
dedicated instruction to model implicit pointers would aid readability & be
simpler to document/grok, but perhaps in the future we'll want to support
other operations that refer to variable > DIEs. In the short term migrating
to an extended dbg.value representation might take more work. Alok, wdyt?

Below is what I think for each suggestion.

DW_OP_LLVM_implicit_pointer
  * This is a good suggestion to include that in LLVM IR, because
representation and specification (types of operands) of it a bit different
that actual dwarf expression DW_OP_LLVM_implicit_pointer. while creating
actual dwarf info it will be converted to DW_OP_LLVM_implicit_pointer. This
is implemented and patch is updated for it.

DW_OP_LLVM_arg0
  * This is good suggestion and will help in readability. It is also
implemented and is available in updated patch.

Splitting dbg.value
  * This is also a good idea from readability point of view. It also opens
possibility of extension below is explanation.
Since dbg.value currently represents (VAR=VALUE), the new intrinsic
dbg.deref_value will represent de-referenced value (*VAR = VAL)
    - Below represents ptr=null
      call void @llvm.dbg.value(metadata i32* null, metadata !21, metadata
!DIExpression())
    - And below represents *ptr=var
      call void @llvm.dbg.deref.value(metadata !16, metadata !21, metadata
!DIExpression(DW_OP_LLVM_implicit_pointer, DW_OP_LLVM_arg0, 0))
    - And below represents *ptr=arr[1]
      call void @llvm.dbg.deref.value(metadata !16, metadata !21, metadata
!DIExpression(DW_OP_LLVM_implicit_pointer, DW_OP_LLVM_arg0, 4))
With this new representation we should be able to represent the case
mentioned by David (in LLVM IR, we would still need some Dwarf operator to
be understood by LLDB) when a variable points to temporary (initialized by
constant) and temporary is optimized out.
      tmp=[CONST]; ptr=&tmp;
call void @llvm.dbg.deref.value(metadata [const], metadata !21, metadata
!DIExpression(DW_OP_LLVM_arg0))
I shall update my patch with introduction of dbg.deref_value. Please do
review.

Variadic dbg.value
   It is also a good idea. But since no immediate benefit seem to be
availed by implicit pointer, it can be done independently.

Regards,
Alok


On Wed, Nov 20, 2019 at 5:23 AM Vedant Kumar via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

>
>
> > On Nov 19, 2019, at 9:41 AM, Adrian Prantl via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
> >
> >
> >
> >> On Nov 18, 2019, at 8:33 AM, Jeremy Morse <jeremy.morse.llvm at gmail.com>
> wrote:
> >>
> >> Hi llvm-dev@,
> >>
> >> Switching focus to the LLVM implementation, the significant change is
> >> using dbg.value's first operand to refer to a DILocalVariable, rather
> >> than a Value. There's some impedance mismatch here, because all the
> >> documentation (for example in the DbgVariableIntrinsic class)
> >> expresses everything in terms of the variables location, whereas
> >> implicit pointers don't have a location as they represent an extra
> >> level of indirection. This is best demonstrated by the change to
> >> IntrinsicInst.cpp in this patch [0] -- calling getVariableLocation on
> >> any normal dbg.value will return the locations Value, but if it's an
> >> implicit pointer then you'll get the meaningless MetadataAsValue
> >> wrapper back instead. This isn't the variable location, might surprise
> >> existing handlers of dbg.values, and just seems a little off.
> >>
> >> I can see why this route has been taken, but by putting a non-Value in
> >> dbg.value's, it really changes what dbg.values represent, a variable
> >> location in the IR. Is there any appetite out there for using a
> >> different intrinsic, something like 'dbg.loc.implicit', instead of
> >> using dbg.value? IMO it would be worthwhile to separate:
> >> * Debug intrinsics where their position in the IR is important, from
> >> * Debug intrinsics where both their position in the IR, _and_ a Value
> >> in the IR, are important.
> >> Of which (I think) implicit pointers are the former, and current [2]
> >> dbg.values are the latter. This would also avoid putting
> >> DW_OP_implicit_pointer into expressions in the IR, pre-isel at least.
> >>
> >
> >
> > On that particular point, I would like to see is a generalization of
> dbg.value: Currently llvm.dbg.value binds an SSA value (including constants
> and undef) and a DIExpression to a DILocalVariable at a position in the
> instruction stream. That first SSA value argument is an implicit first
> element in the DIExpression.
> >
> > A more general form would be a more printf-like signature:
> >
> > llvm.dbg.value(DILocalVariable, DIExpression, ...)
> >
> > for example
> >
> > llvm.dbg.value_new(DILocalVariable("x"), DIExpression(DW_OP_LLVM_arg0),
> %x)
> > llvm.dbg.value_new(DILocalVariable("y"), DIExpression(DW_OP_LLVM_arg0,
> DW_OP_LLVM_arg1, DW_OP_plus),
> >                   %ptr, %ofs)
> > llvm.dbg.value_new(DILocalVariable("z"),
> DIExpression(DW_OP_implicit_pointer, DW_OP_LLVM_arg0, 32),
> >                   DILocalVariable("base"))
> > llvm.dbg.value_new(DILocalVariable("c"), DIExpression(DW_OP_constu, 1))
> >
> > The mandatory arguments would be the variable and the expression, and an
> arbitrary number of SSA values and potentially other variables.
>
> I don't have a strong opinion on representation. I can see how having a
> dedicated instruction to model implicit pointers would aid readability & be
> simpler to document/grok, but perhaps in the future we'll want to support
> other operations that refer to variable DIEs. In the short term migrating
> to an extended dbg.value representation might take more work. Alok, wdyt?
>
> vedant
>
> >
> >
> > As far as DW_OP_LLVM_implicit_pointer in particular is concerned, we
> could also treat the peculiarities of DW_OP_implicit_pointer as a DWARF
> implementation detail, introduce DW_OP_LLVM_implicit_pointer which
> transforms the top-of-stack into an implicit pointer (similar to
> DW_OP_stack_value) and have the DWARF backend insert an artificial variable
> on the fly.
> >
> > LLVM IR:
> >
> > llvm.dbg.value(%base, DILocalVariable("z"),
> DIExpression(DW_OP_LLVM_implicit_pointer))
> >
> > AsmPrinter would expand this into two DW_TAG_variable tags with one
> location (list) entry each.
> >
> > -- adrian
> >
> >> There's also Vedants suggestion [1] for linking implicit pointer
> >> locations with the dbg.values of the underlying DILocalVariable. I
> >> suspect the presence of control flow might make it difficult (there's
> >> no dbg.phi instruction), but I like the idea of having more explicit
> >> links in the IR, it would be much clearer to interpret what's going
> >> on.
> >>
> >> [0] https://reviews.llvm.org/D69999?id=229790
> >> [1] https://reviews.llvm.org/D69886#1736182
> >> [2] Technically dbg.value(undef,...) is the former too, I guess.
> >>
> >> --
> >> Thanks,
> >> Jeremy
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191120/c0870841/attachment.html>


More information about the llvm-dev mailing list