[PATCH] D105407: [LangRef] Add elementtype attribute

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 4 07:06:55 PDT 2021


nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added a subscriber: jdoerfert.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This adds an `elementtype(<ty>)` attribute, which can be used to attach an element type to a pointer typed argument. It is similar to `byval`/`byref` in purpose, but unlike those does not carry any specific semantics by itself. However, certain intrinsics may require it and interpret it in specific ways.

The in-tree use cases for this that I'm currently aware of are:

  call ptr @llvm.preserve.array.access.index.p0(ptr elementtype(%ty) %base, i32 %dim, i32 %index)
  call ptr @llvm.preserve.struct.access.index.p0(ptr elementtype(%ty) %base, i32 %gep_index, i32 %di_index)
  ; Possibly also @llvm.preserve.union.access.index.p0(), though I think it doesn't need it.
  
  call token @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0, ptr addrspace(1) %obj)

Notably, the `gc.statepoint` case needs a function as element type, in which case the workaround of adding a separate `%ty undef` argument would not work, as arguments cannot be unsized.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105407

Files:
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -1165,6 +1165,21 @@
     The sret type argument specifies the in memory type, which must be
     the same as the pointee type of the argument.
 
+``elementtype(<ty>)``
+
+    The ``elementtype`` argument attribute can be used to specify a pointer
+    element type in a way that is compatible with `opaque pointers
+    <OpaquePointers.html>`.
+
+    The ``elementtype`` attribute by itself does not carry any specific
+    semantics. However, certain intrinsics may require this attribute to be
+    present and assign it particular semantics. This will be documented on
+    individual intrinsics.
+
+    The attribute may only be applied to pointer typed arguments. For
+    non-opaque pointers, the type passed to ``elementtype`` must match the
+    pointer element type.
+
 .. _attr_align:
 
 ``align <n>`` or ``align(<n>)``


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105407.356378.patch
Type: text/x-patch
Size: 982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210704/bfbffdf5/attachment.bin>


More information about the llvm-commits mailing list