@@ -3147,14 +3147,21 @@ as follows:
31473147``A<address space>``
31483148 Specifies the address space of objects created by '``alloca``'.
31493149 Defaults to the default address space of 0.
3150- ``p[n]:<size>:<abi>[:<pref>][:<idx>]``
3151- This specifies the *size* of a pointer and its ``<abi>`` and
3152- ``<pref>``\erred alignments for address space ``n``.
3153- The fourth parameter ``<idx>`` is the size of the
3154- index that used for address calculation, which must be less than or equal
3155- to the pointer size. If not
3156- specified, the default index size is equal to the pointer size. All sizes
3157- are in bits. The address space, ``n``, is optional, and if not specified,
3150+ ``p[n]:<size>:<abi>[:<pref>[:<idx>]]``
3151+ This specifies the properties of a pointer in address space ``n``.
3152+ The ``<size>`` parameter specifies the size of the bitwise representation.
3153+ For :ref:`non-integral pointers <nointptrtype>` the representation size may
3154+ be larger than the address width of the underlying address space (e.g. to
3155+ accommodate additional metadata).
3156+ The alignment requirements are specified via the ``<abi>`` and
3157+ ``<pref>``\erred alignments parameters.
3158+ The fourth parameter ``<idx>`` is the size of the index that used for
3159+ address calculations such as :ref:`getelementptr <i_getelementptr>`.
3160+ It must be less than or equal to the pointer size. If not specified, the
3161+ default index size is equal to the pointer size.
3162+ The index size also specifies the width of addresses in this address space.
3163+ All sizes are in bits.
3164+ The address space, ``n``, is optional, and if not specified,
31583165 denotes the default address space 0. The value of ``n`` must be
31593166 in the range [1,2^24).
31603167``i<size>:<abi>[:<pref>]``
@@ -4266,6 +4273,16 @@ address spaces defined in the :ref:`datalayout string<langref_datalayout>`.
42664273the default globals address space and ``addrspace("P")`` the program address
42674274space.
42684275
4276+ The representation of pointers can be different for each address space and does
4277+ not necessarily need to be a plain integer address (e.g. for
4278+ :ref:`non-integral pointers <nointptrtype>`). In addition to a representation
4279+ bits size, pointers in each address space also have an index size which defines
4280+ the bitwidth of indexing operations as well as the size of `integer addresses`
4281+ in this address space. For example, CHERI capabilities are twice the size of the
4282+ underlying addresses to accommodate for additional metadata such as bounds and
4283+ permissions: on a 32-bit system the bitwidth of the pointer representation size
4284+ is 64, but the underlying address width remains 32 bits.
4285+
42694286The default address space is number zero.
42704287
42714288The semantics of non-zero address spaces are target-specific. Memory
@@ -12396,12 +12413,15 @@ Semantics:
1239612413""""""""""
1239712414
1239812415The '``ptrtoint``' instruction converts ``value`` to integer type
12399- ``ty2`` by interpreting the pointer value as an integer and either
12400- truncating or zero extending that value to the size of the integer type.
12416+ ``ty2`` by interpreting the all pointer representation bits as an integer
12417+ (equivalent to a ``bitcast``) and either truncating or zero extending that value
12418+ to the size of the integer type.
1240112419If ``value`` is smaller than ``ty2`` then a zero extension is done. If
1240212420``value`` is larger than ``ty2`` then a truncation is done. If they are
1240312421the same size, then nothing is done (*no-op cast*) other than a type
1240412422change.
12423+ The ``ptrtoint`` always :ref:`captures address and provenance <pointercapture>`
12424+ of the pointer argument.
1240512425
1240612426Example:
1240712427""""""""
@@ -12412,6 +12432,61 @@ Example:
1241212432 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
1241312433 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
1241412434
12435+ .. _i_ptrtoaddr:
12436+
12437+ '``ptrtoaddr .. to``' Instruction
12438+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12439+
12440+ Syntax:
12441+ """""""
12442+
12443+ ::
12444+
12445+ <result> = ptrtoaddr <ty> <value> to <ty2> ; yields ty2
12446+
12447+ Overview:
12448+ """""""""
12449+
12450+ The '``ptrtoaddr``' instruction converts the pointer or a vector of
12451+ pointers ``value`` to the underlying integer address (or vector of integers) of
12452+ type ``ty2``. This is different from :ref:`ptrtoint <i_ptrtoint>` in that it
12453+ only operates on the index bits of the pointer and ignores all other bits.
12454+
12455+ Arguments:
12456+ """"""""""
12457+
12458+ The '``ptrtoaddr``' instruction takes a ``value`` to cast, which must be
12459+ a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
12460+ type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
12461+ a vector of integers type.
12462+
12463+ Semantics:
12464+ """"""""""
12465+
12466+ The '``ptrtoaddr``' instruction converts ``value`` to integer type
12467+ ``ty2`` by interpreting the lowest index-width pointer representation bits as an
12468+ integer and either truncating or zero extending that value to the size of the
12469+ integer type.
12470+ If the address of ``value`` is smaller than ``ty2`` then a zero extension is
12471+ done. If the address of ``value`` is larger than ``ty2`` then a truncation is
12472+ done. If the address size and the pointer representation size are the same and
12473+ ``value`` and ``ty2`` are the same size, then nothing is done (*no-op cast*)
12474+ other than a type change.
12475+
12476+ The ``ptrtoaddr`` always :ref:`captures the address (but not provenance) <pointercapture>`
12477+ of the pointer argument.
12478+
12479+ Example:
12480+ """"""""
12481+ This example assumes pointers in address space 1 are 64 bits in size with an
12482+ address width of 32 bits (``p1:64:64:64:32`` :ref:`datalayout string<langref_datalayout>`)
12483+ .. code-block:: llvm
12484+
12485+ %X = ptrtoaddr ptr addrspace(1) %P to i8 ; extracts low 32 bits and truncates
12486+ %Y = ptrtoaddr ptr addrspace(1) %P to i64 ; extracts low 32 bits and zero extends
12487+ %Z = ptrtoaddr <4 x ptr addrspace(1)> %P to <4 x i64>; yields vector zero extension of low 32 bits for each pointer
12488+
12489+
1241512490.. _i_inttoptr:
1241612491
1241712492'``inttoptr .. to``' Instruction
@@ -12456,6 +12531,9 @@ of the integer ``value``. If ``value`` is larger than the size of a
1245612531pointer then a truncation is done. If ``value`` is smaller than the size
1245712532of a pointer then a zero extension is done. If they are the same size,
1245812533nothing is done (*no-op cast*).
12534+ The behavior is equivalent to a ``bitcast``, however, the resulting value is not
12535+ guaranteed to be dereferenceable (e.g. if the result type is a
12536+ :ref:`non-integral pointers <nointptrtype>`).
1245912537
1246012538Example:
1246112539""""""""
0 commit comments