Skip to content

Commit a4c4127

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.6-beta.1 [skip ci]
1 parent 2d2d753 commit a4c4127

File tree

2 files changed

+87
-18
lines changed

2 files changed

+87
-18
lines changed

llvm/docs/LangRef.rst

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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>[:<addr>]]]``
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>`.
42664273
the default globals address space and ``addrspace("P")`` the program address
42674274
space.
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+
42694286
The default address space is number zero.
42704287

42714288
The semantics of non-zero address spaces are target-specific. Memory
@@ -12396,12 +12413,15 @@ Semantics:
1239612413
""""""""""
1239712414

1239812415
The '``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.
1240112419
If ``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
1240312421
the same size, then nothing is done (*no-op cast*) other than a type
1240412422
change.
12423+
The ``ptrtoint`` always :ref:`captures address and provenance <pointercapture>`
12424+
of the pointer argument.
1240512425

1240612426
Example:
1240712427
""""""""
@@ -12456,6 +12476,9 @@ of the integer ``value``. If ``value`` is larger than the size of a
1245612476
pointer then a truncation is done. If ``value`` is smaller than the size
1245712477
of a pointer then a zero extension is done. If they are the same size,
1245812478
nothing is done (*no-op cast*).
12479+
The behavior is equivalent to a ``bitcast``, however, the resulting value is not
12480+
guaranteed to be dereferenceable (e.g. if the result type is a
12481+
:ref:`non-integral pointers <nointptrtype>`).
1245912482

1246012483
Example:
1246112484
""""""""

llvm/include/llvm/IR/DataLayout.h

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,38 @@ class DataLayout {
324324
/// the backends/clients are updated.
325325
Align getPointerPrefAlignment(unsigned AS = 0) const;
326326

327-
/// Layout pointer size in bytes, rounded up to a whole
328-
/// number of bytes.
327+
/// The pointer representation size in bytes, rounded up to a whole number of
328+
/// bytes. The difference between this function and getPointerAddressSize() is
329+
/// this one returns the size of the entire pointer type (this includes
330+
/// metadata bits for fat pointers) and the latter only returns the number of
331+
/// address bits.
332+
/// \sa DataLayout::getPointerAddressSizeInBits
329333
/// FIXME: The defaults need to be removed once all of
330334
/// the backends/clients are updated.
331335
unsigned getPointerSize(unsigned AS = 0) const;
332336

333-
// Index size in bytes used for address calculation,
334-
/// rounded up to a whole number of bytes.
337+
/// The index size in bytes used for address calculation, rounded up to a
338+
/// whole number of bytes. This not only defines the size used in
339+
/// getelementptr operations, but also the size of addresses in this \p AS.
340+
/// For example, a 64-bit CHERI-enabled target has 128-bit pointers of which
341+
/// only 64 are used to represent the address and the remaining ones are used
342+
/// for metadata such as bounds and access permissions. In this case
343+
/// getPointerSize() returns 16, but getIndexSize() returns 8.
344+
/// To help with code understanding, the alias getPointerAddressSize() can be
345+
/// used instead of getIndexSize() to clarify that an address width is needed.
335346
unsigned getIndexSize(unsigned AS) const;
336347

348+
/// The integral size of a pointer in a given address space in bytes, which
349+
/// is defined to be the same as getIndexSize(). This exists as a separate
350+
/// function to make it clearer when reading code that the size of an address
351+
/// is being requested. While targets exist where index size and the
352+
/// underlying address width are not identical (e.g. AMDGPU fat pointers with
353+
/// 48-bit addresses and 32-bit offsets indexing), there is currently no need
354+
/// to differentiate these properties in LLVM.
355+
/// \sa DataLayout::getIndexSize
356+
/// \sa DataLayout::getPointerAddressSizeInBits
357+
unsigned getPointerAddressSize(unsigned AS) const { return getIndexSize(AS); }
358+
337359
/// Return the address spaces containing non-integral pointers. Pointers in
338360
/// this address space don't have a well-defined bitwise representation.
339361
SmallVector<unsigned, 8> getNonIntegralAddressSpaces() const {
@@ -358,29 +380,53 @@ class DataLayout {
358380
return PTy && isNonIntegralPointerType(PTy);
359381
}
360382

361-
/// Layout pointer size, in bits
383+
/// The size in bits of the pointer representation in a given address space.
384+
/// This is not necessarily the same as the integer address of a pointer (e.g.
385+
/// for fat pointers).
386+
/// \sa DataLayout::getPointerAddressSizeInBits()
362387
/// FIXME: The defaults need to be removed once all of
363388
/// the backends/clients are updated.
364389
unsigned getPointerSizeInBits(unsigned AS = 0) const {
365390
return getPointerSpec(AS).BitWidth;
366391
}
367392

368-
/// Size in bits of index used for address calculation in getelementptr.
393+
/// The size in bits of indices used for address calculation in getelementptr
394+
/// and for addresses in the given AS. See getIndexSize() for more
395+
/// information.
396+
/// \sa DataLayout::getPointerAddressSizeInBits()
369397
unsigned getIndexSizeInBits(unsigned AS) const {
370398
return getPointerSpec(AS).IndexBitWidth;
371399
}
372400

373-
/// Layout pointer size, in bits, based on the type. If this function is
401+
/// The size in bits of an address in for the given AS. This is defined to
402+
/// return the same value as getIndexSizeInBits() since there is currently no
403+
/// target that requires these two properties to have different values. See
404+
/// getIndexSize() for more information.
405+
/// \sa DataLayout::getIndexSizeInBits()
406+
unsigned getPointerAddressSizeInBits(unsigned AS) const {
407+
return getIndexSizeInBits(AS);
408+
}
409+
410+
/// The pointer representation size in bits for this type. If this function is
374411
/// called with a pointer type, then the type size of the pointer is returned.
375412
/// If this function is called with a vector of pointers, then the type size
376413
/// of the pointer is returned. This should only be called with a pointer or
377414
/// vector of pointers.
378415
unsigned getPointerTypeSizeInBits(Type *) const;
379416

380-
/// Layout size of the index used in GEP calculation.
417+
/// The size in bits of the index used in GEP calculation for this type.
381418
/// The function should be called with pointer or vector of pointers type.
419+
/// This is defined to return the same value as getPointerAddressSizeInBits(),
420+
/// but separate functions exist for code clarity.
382421
unsigned getIndexTypeSizeInBits(Type *Ty) const;
383422

423+
/// The size in bits of an address for this type.
424+
/// This is defined to return the same value as getIndexTypeSizeInBits(),
425+
/// but separate functions exist for code clarity.
426+
unsigned getPointerAddressSizeInBits(Type *Ty) const {
427+
return getIndexTypeSizeInBits(Ty);
428+
}
429+
384430
unsigned getPointerTypeSize(Type *Ty) const {
385431
return getPointerTypeSizeInBits(Ty) / 8;
386432
}

0 commit comments

Comments
 (0)