@@ -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