@@ -92,6 +92,7 @@ class DataLayout {
9292 // / The function pointer alignment is a multiple of the function alignment.
9393 MultipleOfFunctionAlign,
9494 };
95+
9596private:
9697 bool BigEndian = false ;
9798
@@ -324,16 +325,38 @@ class DataLayout {
324325 // / the backends/clients are updated.
325326 Align getPointerPrefAlignment (unsigned AS = 0 ) const ;
326327
327- // / Layout pointer size in bytes, rounded up to a whole
328- // / number of bytes.
328+ // / The pointer representation size in bytes, rounded up to a whole number of
329+ // / bytes. The difference between this function and getAddressSize() is that
330+ // / this one returns the size of the entire pointer representation (including
331+ // / metadata bits for fat pointers) and the latter only returns the number of
332+ // / address bits.
333+ // / \sa DataLayout::getAddressSizeInBits
329334 // / FIXME: The defaults need to be removed once all of
330335 // / the backends/clients are updated.
331336 unsigned getPointerSize (unsigned AS = 0 ) const ;
332337
333- // Index size in bytes used for address calculation,
334- // / rounded up to a whole number of bytes.
338+ // / The index size in bytes used for address calculation, rounded up to a
339+ // / whole number of bytes. This not only defines the size used in
340+ // / getelementptr operations, but also the size of addresses in this \p AS.
341+ // / For example, a 64-bit CHERI-enabled target has 128-bit pointers of which
342+ // / only 64 are used to represent the address and the remaining ones are used
343+ // / for metadata such as bounds and access permissions. In this case
344+ // / getPointerSize() returns 16, but getIndexSize() returns 8.
345+ // / To help with code understanding, the alias getAddressSize() can be used
346+ // / instead of getIndexSize() to clarify that an address width is needed.
335347 unsigned getIndexSize (unsigned AS) const ;
336348
349+ // / The integral size of a pointer in a given address space in bytes, which
350+ // / is defined to be the same as getIndexSize(). This exists as a separate
351+ // / function to make it clearer when reading code that the size of an address
352+ // / is being requested. While targets exist where index size and the
353+ // / underlying address width are not identical (e.g. AMDGPU fat pointers with
354+ // / 48-bit addresses and 32-bit offsets indexing), there is currently no need
355+ // / to differentiate these properties in LLVM.
356+ // / \sa DataLayout::getIndexSize
357+ // / \sa DataLayout::getAddressSizeInBits
358+ unsigned getAddressSize (unsigned AS) const { return getIndexSize (AS); }
359+
337360 // / Return the address spaces containing non-integral pointers. Pointers in
338361 // / this address space don't have a well-defined bitwise representation.
339362 SmallVector<unsigned , 8 > getNonIntegralAddressSpaces () const {
@@ -358,29 +381,53 @@ class DataLayout {
358381 return PTy && isNonIntegralPointerType (PTy);
359382 }
360383
361- // / Layout pointer size, in bits
384+ // / The size in bits of the pointer representation in a given address space.
385+ // / This is not necessarily the same as the integer address of a pointer (e.g.
386+ // / for fat pointers).
387+ // / \sa DataLayout::getAddressSizeInBits()
362388 // / FIXME: The defaults need to be removed once all of
363389 // / the backends/clients are updated.
364390 unsigned getPointerSizeInBits (unsigned AS = 0 ) const {
365391 return getPointerSpec (AS).BitWidth ;
366392 }
367393
368- // / Size in bits of index used for address calculation in getelementptr.
394+ // / The size in bits of indices used for address calculation in getelementptr
395+ // / and for addresses in the given AS. See getIndexSize() for more
396+ // / information.
397+ // / \sa DataLayout::getAddressSizeInBits()
369398 unsigned getIndexSizeInBits (unsigned AS) const {
370399 return getPointerSpec (AS).IndexBitWidth ;
371400 }
372401
373- // / Layout pointer size, in bits, based on the type. If this function is
402+ // / The size in bits of an address in for the given AS. This is defined to
403+ // / return the same value as getIndexSizeInBits() since there is currently no
404+ // / target that requires these two properties to have different values. See
405+ // / getIndexSize() for more information.
406+ // / \sa DataLayout::getIndexSizeInBits()
407+ unsigned getAddressSizeInBits (unsigned AS) const {
408+ return getIndexSizeInBits (AS);
409+ }
410+
411+ // / The pointer representation size in bits for this type. If this function is
374412 // / called with a pointer type, then the type size of the pointer is returned.
375413 // / If this function is called with a vector of pointers, then the type size
376414 // / of the pointer is returned. This should only be called with a pointer or
377415 // / vector of pointers.
378416 unsigned getPointerTypeSizeInBits (Type *) const ;
379417
380- // / Layout size of the index used in GEP calculation.
418+ // / The size in bits of the index used in GEP calculation for this type .
381419 // / The function should be called with pointer or vector of pointers type.
420+ // / This is defined to return the same value as getAddressSizeInBits(),
421+ // / but separate functions exist for code clarity.
382422 unsigned getIndexTypeSizeInBits (Type *Ty) const ;
383423
424+ // / The size in bits of an address for this type.
425+ // / This is defined to return the same value as getIndexTypeSizeInBits(),
426+ // / but separate functions exist for code clarity.
427+ unsigned getAddressSizeInBits (Type *Ty) const {
428+ return getIndexTypeSizeInBits (Ty);
429+ }
430+
384431 unsigned getPointerTypeSize (Type *Ty) const {
385432 return getPointerTypeSizeInBits (Ty) / 8 ;
386433 }
@@ -515,15 +562,21 @@ class DataLayout {
515562 // / are set.
516563 unsigned getLargestLegalIntTypeSizeInBits () const ;
517564
518- // / Returns the type of a GEP index in AddressSpace.
565+ // / Returns the type of a GEP index in \p AddressSpace.
519566 // / If it was not specified explicitly, it will be the integer type of the
520567 // / pointer width - IntPtrType.
521568 IntegerType *getIndexType (LLVMContext &C, unsigned AddressSpace) const ;
569+ // / Returns the type of an address in \p AddressSpace
570+ IntegerType *getAddressType (LLVMContext &C, unsigned AddressSpace) const {
571+ return getIndexType (C, AddressSpace);
572+ }
522573
523574 // / Returns the type of a GEP index.
524575 // / If it was not specified explicitly, it will be the integer type of the
525576 // / pointer width - IntPtrType.
526577 Type *getIndexType (Type *PtrTy) const ;
578+ // / Returns the type of an address in \p AddressSpace
579+ Type *getAddressType (Type *PtrTy) const { return getIndexType (PtrTy); }
527580
528581 // / Returns the offset from the beginning of the type for the specified
529582 // / indices.
0 commit comments