llvm::DataLayout

A parsed version of the target data layout string in and methods for querying it.

Synopsis

Declared in <llvm/IR/DataLayout.h>

class DataLayout;

Description

The target data layout string is specified by the target - a frontend generating LLVM IR is required to generate the right target data for the target being codegen'd to.

Types

NameDescription
PointerSpec Pointer type specification.
PrimitiveSpec Primitive type specification.

Enums

Name
FunctionPtrAlignType

Member Functions

NameDescription
DataLayout [constructor]Constructors
~DataLayout [destructor]Destructor
operator= Copy assignment operator
doNotMangleLeadingQuestionMark Returns true if symbols with leading question marks should not receive IR mangling. True for Windows mangling modes.
fitsInLegalInteger Returns true if the specified type fits in a native integer type supported by the CPU.
getABIIntegerTypeAlignment Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
getABITypeAlign Returns the minimum ABI-required alignment for the specified type.
getAddressSize The integral size of a pointer in a given address space in bytes, which is defined to be the same as getIndexSize(). This exists as a separate function to make it clearer when reading code that the size of an address is being requested. While targets exist where index size and the underlying address width are not identical (e.g. AMDGPU fat pointers with 48-bit addresses and 32-bit offsets indexing), there is currently no need to differentiate these properties in LLVM.
getAddressSizeInBits getAddressSizeInBits overloads
getAddressSpaceName
getAddressType Returns the type of an address in AddressSpace
getAllocaAddrSpace
getAllocaPtrType
getBytePtrType getBytePtrType overloads
getDefaultGlobalsAddressSpace
getFunctionPtrAlign Returns the alignment of function pointers, which may or may not be related to the alignment of functions.
getFunctionPtrAlignType Return the type of function pointer alignment.
getGEPIndexForOffset Get single GEP index to access Offset inside ElemTy. Returns std::nullopt if index cannot be computed, e.g. because the type is not an aggregate. ElemTy is updated to be the result element type and Offset to be the residual offset.
getGEPIndicesForOffset Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be the result element type and Offset to be the residual offset.
getGlobalPrefix
getIndexSize The index size in bytes used for address calculation, rounded up to a whole number of bytes. This not only defines the size used in getelementptr operations, but also the size of addresses in this AS. For example, a 64-bit CHERI-enabled target has 128-bit pointers of which only 64 are used to represent the address and the remaining ones are used for metadata such as bounds and access permissions. In this case getPointerSize() returns 16, but getIndexSize() returns 8. To help with code understanding, the alias getAddressSize() can be used instead of getIndexSize() to clarify that an address width is needed.
getIndexSizeInBits The size in bits of indices used for address calculation in getelementptr and for addresses in the given AS. See getIndexSize() for more information.
getIndexType getIndexType overloads
getIndexTypeSizeInBits The size in bits of the index used in GEP calculation for this type. The function should be called with pointer or vector of pointers type. This is defined to return the same value as getAddressSizeInBits(), but separate functions exist for code clarity.
getIndexedOffsetInType Returns the offset from the beginning of the type for the specified indices.
getIntPtrType getIntPtrType overloads
getInternalSymbolPrefix
getLargestLegalIntType Returns the largest legal integer type, or null if none are set.
getLargestLegalIntTypeSizeInBits Returns the size of largest legal integer type size, or 0 if none are set.
getLinkerPrivateGlobalPrefix
getNamedAddressSpace
getNonStandardAddressSpaces Return the address spaces with special pointer semantics (such as being unstable or non-integral).
getNullPtrValue Returns the null pointer bit pattern for the given address space.
getPointerABIAlignment Layout pointer alignment.
getPointerPrefAlignment Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of the backends/clients are updated.
getPointerSize The pointer representation size in bytes, rounded up to a whole number of bytes. The difference between this function and getAddressSize() is that this one returns the size of the entire pointer representation (including metadata bits for fat pointers) and the latter only returns the number of address bits.
getPointerSizeInBits The size in bits of the pointer representation in a given address space. This is not necessarily the same as the integer address of a pointer (e.g. for fat pointers).
getPointerTypeSize
getPointerTypeSizeInBits The pointer representation size in bits for this type. If this function is called with a pointer type, then the type size of the pointer is returned. If this function is called with a vector of pointers, then the type size of the pointer is returned. This should only be called with a pointer or vector of pointers.
getPrefTypeAlign Returns the preferred stack/global alignment for the specified type.
getPreferredAlign Returns the preferred alignment of the specified global.
getProgramAddressSpace
getSmallestLegalIntType Returns the smallest integer type with size at least as big as Width bits.
getStackAlignment Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.
getStringRepresentation Returns the string representation of the DataLayout.
getStructLayout Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of its fields.
getTypeAllocSize Returns the offset in bytes between successive objects of the specified type, including alignment padding.
getTypeAllocSizeInBits Returns the offset in bits between successive objects of the specified type, including alignment padding; always a multiple of 8.
getTypeSizeInBits Returns the number of bits necessary to hold the specified type.
getTypeStoreSize Returns the maximum number of bytes that may be overwritten by storing the specified type.
getTypeStoreSizeInBits Returns the maximum number of bits that may be overwritten by storing the specified type; always a multiple of 8.
getValueOrABITypeAlignment Helper function to return Alignment if it's set or the result of getABITypeAlign(Ty), in any case the result is a valid alignment.
hasExternalState Returns whether this address space has external state (implies having a non-integral pointer representation). These pointer types must be loaded and stored using appropriate instructions and cannot use integer loads/stores as this would not propagate the out-of-band state. An example of such a pointer type is a CHERI capability that contain bounds, permissions and an out-of-band validity bit that is invalidated whenever an integer/FP store is performed to the associated memory location.
hasLinkerPrivateGlobalPrefix
hasMicrosoftFastStdCallMangling
hasUnstableRepresentation Returns whether this address space has an "unstable" pointer representation. The bitwise pattern of such pointers is allowed to change in a target-specific way. For example, this could be used for copying garbage collection where the garbage collector could update the pointer value as part of the collection sweep.
isBigEndian
isDefault Test if the DataLayout was constructed from an empty string.
isIllegalInteger
isLegalInteger Returns true if the specified type is known to be a native integer type supported by the CPU.
isLittleEndian Layout endianness...
isNonIntegralAddressSpace Returns whether this address space has a non-integral pointer representation, i.e. the pointer is not just an integer address but some other bitwise representation. When true, passes cannot assume that all bits of the representation map directly to the allocation address. NOTE: This also returns true for "unstable" pointers where the representation may be just an address, but this value can change at any given time (e.g. due to copying garbage collection). Examples include AMDGPU buffer descriptors with a 128-bit fat pointer and a 32-bit offset or CHERI capabilities that contain bounds, permissions and an out-of-band validity bit.
isNonIntegralPointerType
mustNotIntroduceIntToPtr Returns whether passes must avoid introducing inttoptr instructions for this address space (unless they have target-specific knowledge).
mustNotIntroducePtrToInt Returns whether passes must avoid introducing ptrtoint instructions for this address space (unless they have target-specific knowledge).
typeSizeEqualsStoreSize Returns true if no extra padding bits are needed when storing the specified type.
vectorsAreElementAligned Whether vectors are element aligned, rather than naturally aligned.
operator== Equality operator
operator!= Inequality operator

Static Member Functions

NameDescription
parse Parse a data layout string and return the layout. Return an error description on failure.

Non-Member Functions

NameDescription
ComputeValueTypesGiven an LLVM IR type, compute non-aggregate subtypes. Optionally also compute their offsets.
computeValueLLTscomputeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individual underlying non-aggregate types that comprise it.
copyRangeMetadataCopy a range metadata node to a new load instruction.
decomposeLinearExpressionDecompose a pointer into a linear expression. This may look through multiple GEPs.
at::calculateFragmentIntersectCalculate the fragment of the variable in DAI covered from (Dest + SliceOffsetInBits) to to (Dest + SliceOffsetInBits + SliceSizeInBits)