<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 22, 2021 at 6:16 PM Kaylor, Andrew via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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>
<p class="MsoNormal">Honestly, I didn’t (and still don’t) understand enough about the intrinsics Craig mentioned to even be sure they were analogous to the case I brought up. It seemed like they might be more interested in debug types than IR types and may
 or may not be going down the same paths of reasoning, but I just don’t understand what the intrinsics are doing.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">We’re scrambling to get our out-of-tree code caught up with the opaque pointer transition. I think the scatter/gather intrinsics are likely to be our first useful overlap with the in-tree work to be done, though now that I’ve thought about
 it a bit more, I think the type in that can just be inferred from non-pointer arguments. In any case, I guess talking about it and agreeing on an approach is a good first step.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I started trying to mock up some IR for how this might work, but I wasn’t entirely happy with it. Specifically, how do you describe an IR type in metadata. We could use an undef value in the metadata, similar to what Arthur proposed as
 an argument, but that only moves the ugliness. This is kind of what I was thinking<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">define void @f() {<u></u><u></u></p>
<p class="MsoNormal">  ptr %p = <however we got %p><u></u><u></u></p>
<p class="MsoNormal">  call void @llvm.some.intrinsic(ptr %p, metadata !1)<u></u><u></u></p>
<p class="MsoNormal">  <…><u></u><u></u></p>
<p class="MsoNormal">  return void<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">define void @llvm.some.intrinsic(ptr, metadata)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">%MyElementTy = type { <whatever> }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">!1 = !{ %MyElementTy undef }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I guess that would work, but I don’t really like it. I looked at the way TBAA and debug info describe types, but that’s not describing the IR type and so it seems simultaneously fragile and too verbose. Is there a better way to do this?
 What about introducing a parameter attribute that would be considered required for the intrinsic? Something like this:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">define void @f() {<u></u><u></u></p>
<p class="MsoNormal">  ptr %p = <however we got %p><u></u><u></u></p>
<p class="MsoNormal">  call void @llvm.some.intrinsic(ptr elementtype(%MyElementTy) %p)<u></u><u></u></p>
<p class="MsoNormal">  <…><u></u><u></u></p>
<p class="MsoNormal">  return void<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">; Requires ‘elementype’ parameter attribute<u></u><u></u></p>
<p class="MsoNormal">define void @llvm.some.intrinsic(ptr)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">%MyElementTy = type { <whatever> }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Does that feel like a step backward to you? I don’t know how hard it would be for front end’s to generate something like that, but it hasn’t the benefit that the elementtype would have intentional and well-defined semantic meaning.</p></div></div></blockquote><div><br></div><div>Maybe the byref attribute is suitable for this? That is @llvm.some.intrinsic(ptr byref(%ElemTy) %p).</div><div><br></div><div>I believe byref() doesn't carry any particular semantics apart from providing the element type. It's currently used to carry ABI information in the presence of opaque pointers (for AMDGPU kernels), but I think it would be suitable for use with intrinsics as well.<br></div><div><br></div><div>Regards,</div><div>Nikita<br></div><div> </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>
<p class="MsoNormal"></p>
<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> Monday, June 21, 2021 6:00 PM<br>
<b>To:</b> Kaylor, Andrew <<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>>; <a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a><br>
<b>Cc:</b> Arthur Eubanks <<a href="mailto:aeubanks@google.com" target="_blank">aeubanks@google.com</a>>; <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Opaque Pointers Help Wanted<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">It looks like Craig's pointed out some cases that come up in LLVM. Perhaps you could try fixing one of the in-tree examples to help explore/set the direction for your out of tree work?<br>
<br>
Metadata arguments sound like a direction worth exploring. (& would be consistent with the way parameter attributes have been approached - still using a type argument even though the length is all that matters in those cases)<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Jun 21, 2021 at 2:28 PM Kaylor, Andrew 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">This has probably been discussed somewhere, but I missed it. Can you elaborate a bit on this?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoNormal" style="color:rgb(36,41,46);margin-top:3pt;background:white none repeat scroll 0% 0%">
<span style="font-size:12pt;font-family:-apple-system">Allow bitcode auto-upgrade of legacy pointer type to the new opaque pointer type (not to be turned on until ready)</span><u></u><u></u></li></ul>
<ul type="disc">
<ul type="circle">
<li class="MsoNormal" style="color:rgb(36,41,46);background:white none repeat scroll 0% 0%">
<span style="font-size:12pt;font-family:-apple-system">To support legacy bitcode, such as legacy stores/loads, we need to track pointee types for all values since legacy instructions may infer the types from a pointer operand's pointee type</span><u></u><u></u></li></ul>
</ul>
<p class="MsoNormal">I‘m specifically trying to understand what will happen when typed pointer support is removed. How will IR with typed pointers be auto-upgraded to pure opaque pointer IR? Will the
 bitcode reader keep some level of typed pointer support indefinitely?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Also, do you have a plan for replacing intrinsics that currently rely on pointee types? For example, the load instruction was updated to take an explicit type operand but I don’t
 think we can do the same thing for an intrinsic like llvm.masked.load since there is Value for Type. This is an easy problem to work around for something like masked.load, but more complicated if anyone has a downstream GEP-like intrinsic that needs more than
 the size of an element (spoiler alert: I do have such an intrinsic). Would you use a metadata argument?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Andy<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<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> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>Arthur Eubanks via llvm-dev<br>
<b>Sent:</b> Monday, June 21, 2021 12:03 PM<br>
<b>To:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [llvm-dev] Opaque Pointers Help Wanted<u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">For the opaque pointers project, <a href="https://llvm.org/docs/OpaquePointers.html#transition-plan" target="_blank">https://llvm.org/docs/OpaquePointers.html#transition-plan</a>
 contains high level steps for what to do before we can enable opaque pointers. (Looks like the page hasn't been rebuilt in a while, <a href="https://github.com/llvm/llvm-project/blob/main/llvm/docs/OpaquePointers.rst#transition-plan" target="_blank">https://github.com/llvm/llvm-project/blob/main/llvm/docs/OpaquePointers.rst#transition-plan</a>
 contains some more concrete steps)<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Essentially almost all of the work boils down to figuring out how to remove calls to `PointerType::getElementType()` and `Type::getPointerElementType()`. Everything else derives
 from that.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Any help with this is welcome and appreciated!<u></u><u></u></p>
</div>
</div>
</div>
</div>
</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>
</div>
</div>

_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>