<div dir="ltr"><div>Hi Paul,</div><div><br></div><div>As David already replied about the emergence of DW_OP_LLVM_explicit_pointer. Let me explain a bit more about it.</div><div><br></div><div>In order to address a case David has put regarding a variable pointing to a temporary (which happens in case of references). For the same case a solution is already suggested by you (using artificial variable for temporary).</div><div><br></div><div>To make maximum use of the discussion, I tried to provide additional option to choose from.</div><div><br></div><div>Note that this case is not handled even by gnu gcc, So how much gcc does should be *must* for us and beyond that anything should be *aspire*.</div><div><br></div><div>Now to include that aspire case we have two options</div><div><br></div><div>1. Create Artificial variable (flip side we need to carry extra artifical DIE)</div><div>2. Define the value inline using DW_OP_LLVM_explicit_pointer (flip side new operator need to be introduced)</div><div><br></div><div>I think we should go ahead with *must* functionality anyway and chose one of the options for *aspire* functionality.<br></div><div><br></div><div>Regards,</div><div>Alok<br></div><div><br></div><div>Since this case <br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 19, 2019 at 9:57 PM Robinson, Paul <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_8772719259635154186WordSection1">
<p class="MsoNormal">I regret to say I also have not been following this with the attention it deserves, and I am pretty much on holiday until 14 January.<u></u><u></u></p>
<p class="MsoNormal">I am particularly surprised by the appearance of something called DW_OP_LLVM_explicit_pointer, which I wouldn’t have thought necessary and don’t remember from the discussions that I did read.<u></u><u></u></p>
<p class="MsoNormal">I will try to mend my ways and pay more attention when I return.<u></u><u></u></p>
<p class="MsoNormal">--paulr<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> <br>
<b>Sent:</b> Wednesday, December 18, 2019 6:24 PM<br>
<b>To:</b> Alok Sharma <<a href="mailto:aloksharma.knit@gmail.com" target="_blank">aloksharma.knit@gmail.com</a>>; Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>>; Jonas Devlieghere <<a href="mailto:jdevlieghere@apple.com" target="_blank">jdevlieghere@apple.com</a>>; Robinson, Paul <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>><br>
<b>Cc:</b> Jeremy Morse <<a href="mailto:jeremy.morse.llvm@gmail.com" target="_blank">jeremy.morse.llvm@gmail.com</a>>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; <a href="mailto:AlokKumar.Sharma@amd.com" target="_blank">AlokKumar.Sharma@amd.com</a>; Vedant Kumar <<a href="mailto:vedant_kumar@apple.com" target="_blank">vedant_kumar@apple.com</a>><br>
<b>Subject:</b> Re: [llvm-dev] DW_OP_implicit_pointer design/implementation in general<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">(I'm still pretty concerned that there are IR changes going in for a feature that seems incomplete and more invasive than really seems justified to me - though I admit I'm clearly not paying enough attention to this feature to have a nuanced/fully
 informed opinion & so maybe I just need to step back from all of this - but given the addition of new intrinsics, it seems like there should be more clear design discussion)<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Dec 10, 2019 at 9:06 PM Alok Sharma <<a href="mailto:aloksharma.knit@gmail.com" target="_blank">aloksharma.knit@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi David,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This is regarding missing multilevel handling in branch for explicit pointers.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">> * does the proposed IR format support multiple layers of dereference (eg: int ** where we know it ultimately points to the value 3 but can't describe either the first or second level pointers that get to that value) - it sounds like any
 intrinsic that's special cased to deref (like llvm.dbg.derefval) wouldn't be able to capture that, which seems like it's overly narrow/special case, then?
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">The PoC of DW_OP_LLVM_explicit_pointer does not have handling of multilevel indirection. As of now it is so due to below reason.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> Explicit pointer handles cases when variable points to a temporary which contains constant. Due to language standard constraints, we don't find pointers in such cases, what we get is references. Unlike pointers, references have single
 level. (reference to reference is just reference while pointer to pointer is double pointer).<u></u><u></u></p>
</div>
</div>
</blockquote>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"> Case of reference to reference,  second level can be handled using DW_OP_LLVM_explicit_pointer itself.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> Case of pointer to reference, second level can be handled using DW_OP_implicit_pointer.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Though it would not be complex to make explicit pointer multilevel, I avoided so due to lack of use case. Please let me know if I am missing something.<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><br>
Sorry, I couldn't understand your language related to references and pointers - I don't understand why they would be handled differently or represent challenges/tradeoffs for features related to collapsed indirection like this.<br>
<br>
Multi-level indirection seems to have as much use as single level indirection. (if a DWARF user may want to know what a pointer points to even when what it points to isn't in memory, the same would hold true for pointers to pointers, etc)<br>
<br>
I would expect this to be handled with a general OP saying "hey, I'm skipping one level of indirection indirection in the resulting value, because that indirection is missing/not in the final program" and that this would be encoded in a llvm.dbg.value/DIExpression
 as usual, without the need for new IR intrinsics, though possibly with the need for an LLVM extension DWARF OP (DW_OP_LLVM_explicit_pointer?)<br>
<br>
To reconstitute that general form into the current DWARF limited "indirection needs to refer to another variable DIE" issue - as I think Paul speculated previously, we could always reconstitute a synthetic variable DIE & not try to reflect the case where the
 indirection lands at another named/known variable - as I expect that's the minority case. In most cases in C++ I expect pointers and references do not refer to named variables in the same function. They refer to return values from functions, they refer to
 array elements in dynamically allocated arrays, etc, etc.<br>
 <u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Alok<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, Nov 29, 2019 at 10:12 AM Alok Sharma <<a href="mailto:aloksharma.knit@gmail.com" target="_blank">aloksharma.knit@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Let me try to summarize the implementation first.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">At the moment, there are two branches.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">1. When an existing variable is optimized out and that variable is used to get the de-refereced value, pointed to by another pointer/reference variable.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">  Such cases are being addressed using Dwarf expression DW_OP_implicit_pointer as de-referenced value of a pointer can be seen implicitly (using another variable). Before Dwarf is dumped in LLVM IR, we represent it using dbg.derefval (which
 denotes derefereced value of pointer or reference) and DW_OP_LLVM_implicit_pointer operation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">2. When a temporary variable is optimized out and that variable is used to get de-referenced value of another reference variable (AFAIK it can not be reproduced with pointers)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">  Such cases are being addressed using new Dwarf expression DW_OP_explicit_pointer as de-referenced value can be displayed explicitly (in place). In LLVM IR, we represent it using dbg.derefval and DW_OP_LLVM_explicit_pointer operation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Both of these two branches have some common implementation to define new operations (Dwarf and IR). (D70642, D70643, D69999, D69886).
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">First branch has additional patches (D70260, 70384, D70385, D70419).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Second branch has additional patch ( D70833).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Let me try to comment on points raised by you.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">- Branch 2, (patch D70833) handles cases when temporaries (not existing variables) are optimized out.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">- In patch D70385, I have included test points to display that multi layered pointers are working (llvm/test/DebugInfo/dwarfdump-implicit_pointer_mem2reg.c).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I feel that review of branch 1 (implicit pointer) can be resumed (which was halted due to current discussion), while we can continue to discuss branch 2 (explicit pointers D7083) if you want. David, what do you think?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Alok<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, Nov 29, 2019 at 4:40 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">Sorry I haven't been more engaged with this thread, I have been reading it, so hopefully my reply isn't completely out of line/irrelevant - but I still feel like having a custom dwarf expression operator (& no new intrinsics), like we have
 for one or two other DW_OP_LLVM_* (that aren't actually generated into the DWARF - though this one perhaps could be in some/all cases as an extension, maybe - or a synthesized variable could be created for compatibility with the current DWARF standard) would
 make the most sense.<br>
<br>
Some thought experiments that I think are relevant:<br>
* does the proposed IR format scale to pointers that don't point to existing variables (that I think has already been touched on in this thread)<br>
* does the proposed IR format support multiple layers of dereference (eg: int ** where we know it ultimately points to the value 3 but can't describe either the first or second level pointers that get to that value) - it sounds like any intrinsic that's special
 cased to deref (like llvm.dbg.derefval) wouldn't be able to capture that, which seems like it's overly narrow/special case, then?<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Thu, Nov 28, 2019 at 2:29 PM Alok Sharma via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi folks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am pushing a PoC patch <a href="https://reviews.llvm.org/D70833" target="_blank">
https://reviews.llvm.org/D70833</a> for review which includes the case when temporary is promoted.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">For such cases it generates IR as <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">  call void @llvm.dbg.derefval(metadata i32 3, metadata !25, metadata !DIExpression(DW_OP_LLVM_explicit_pointer, DW_OP_LLVM_arg0)), !dbg !32<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">And llvm-darfdump output looks like <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">------------- <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">0x0000007b:     DW_TAG_inlined_subroutine<br>
                  DW_AT_abstract_origin (0x0000004f "_Z4sinkRKi")<br>
                  DW_AT_low_pc  (0x00000000004004c6)<br>
                  DW_AT_high_pc (0x00000000004004d0)<br>
                  DW_AT_call_file       ("/home/alok/openllvm/llvm-project_derefval/build.d/david.cc")<br>
                  DW_AT_call_line       (10)<br>
                  DW_AT_call_column     (0x03)<br>
<br>
0x00000088:       DW_TAG_formal_parameter<br>
                    DW_AT_location      (indexed (0x0) loclist = 0x00000010:<br>
                       [0x00000000004004c6, 0x00000000004004d4): DW_OP_explicit_pointer, DW_OP_lit3)<br>
                    DW_AT_abstract_origin       (0x00000055 "p")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">------------ <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Please note that DW_OP_explicit_pointer denotes that following value represents de-referenced value of optimized out pointer. With necessary changes in LLDB debugger this dwarf info can help to detect the explicit de-referenced value of
 'p'.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Hi David,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Should we keep on working for the above case separately and resume the review of implicit pointer independently now, which is updated with many suggestions from this discussion?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Regards,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Alok<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Nov 20, 2019 at 11:24 PM Jeremy Morse <<a href="mailto:jeremy.morse.llvm@gmail.com" target="_blank">jeremy.morse.llvm@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi,<br>
<br>
For a new way of representing things,<br>
<br>
Adrian wrote:<br>
> llvm.dbg.value_new(DILocalVariable("y"), DIExpression(DW_OP_LLVM_arg0, DW_OP_LLVM_arg1, DW_OP_plus),<br>
>                    %ptr, %ofs)<br>
<br>
I think this would be great -- there're definitely some constructs<br>
created by the induction-variables pass and similar where one could<br>
recover an implicit variable value, if you could for example subtract<br>
one pointer from another.<br>
<br>
With the current model of storing DIExpressions as a vector of<br>
opcodes, it might become a pain to salvage a Value that gets optimised<br>
out --in the example, if %ofs were salvaged, presumably<br>
DW_OP_LLVM_arg1 could have to be replaced with several extra<br>
operations. This isn't insurmountable, but I've repeatedly shied away<br>
from scanning through DIExpressions to patch them up. A vector of<br>
opcodes is the final output of the compiler, IMHO richer metadata<br>
should be used in the meantime.<br>
<br>
IMHO the implicit pointer work doesn't need to block on this. As said<br>
my mild preference would be for a new intrinsic for this form of<br>
variable location.<br>
<br>
~<br>
<br>
Inre PR37682,<br>
<br>
> I’ve been reminded of PR37682, where a function with a reference parameter might spend all its time computing the “referenced” value in a temp, and only move the final value back to the referenced object at the end.  This is clearly a situation that could
 benefit from DW_OP_implicit_pointer, and there is really no other-object DIE for it to refer to.  Given the current spec, the compiler would need to produce a DW_TAG_dwarf_procedure for the parameter DIE to refer to.  Appendix D (Figure D.61) has an example
 of this construction, although it’s a more contrived source example.<br>
<br>
This has been working through my mind too, and I think it's slightly<br>
different to what implicit_pointer is trying to achieve. In the case<br>
implicit_pointer is designed for, it's a strict improvement in debug<br>
experience because you're recovering information that couldn't be<br>
expressed. However for PR37682 it's a trade-off between whether the<br>
user might want to examine the pointer, or the pointed-at integer:<br>
AFAIUI, we can only express one of the two, not both. Wheras for<br>
mem2reg'd variables referred to by DIE, there is never a pointer to be<br>
lost.<br>
<br>
I think my preference would always be to see temporarily-promoted<br>
values as there's no other way of observing them, but others might<br>
disagree.<br>
<br>
--<br>
Thanks,<br>
Jeremy<u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>