19#ifndef LLVM_IR_DATALAYOUT_H
20#define LLVM_IR_DATALAYOUT_H
106 bool BigEndian =
false;
108 unsigned AllocaAddrSpace = 0;
109 unsigned ProgramAddrSpace = 0;
110 unsigned DefaultGlobalsAddrSpace = 0;
114 FunctionPtrAlignType TheFunctionPtrAlignType =
127 ManglingModeT ManglingMode = MM_None;
130 SmallVector<unsigned char, 8> LegalIntWidths;
141 std::string StringRepresentation;
148 mutable void *LayoutMap =
nullptr;
160 Align PrefAlign,
uint32_t IndexBitWidth,
161 bool HasUnstableRepr,
bool HasExternalState);
170 Error parsePrimitiveSpec(StringRef Spec);
173 Error parseAggregateSpec(StringRef Spec);
176 Error parsePointerSpec(StringRef Spec);
179 Error parseSpecification(StringRef Spec,
180 SmallVectorImpl<unsigned> &NonIntegralAddressSpaces);
183 Error parseLayoutString(StringRef LayoutString);
216 return StringRepresentation;
220 bool isDefault()
const {
return StringRepresentation.empty(); }
253 return TheFunctionPtrAlignType;
258 return DefaultGlobalsAddrSpace;
262 return ManglingMode == MM_WinCOFFX86;
268 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
274 if (ManglingMode == MM_MachO)
280 switch (ManglingMode) {
296 switch (ManglingMode) {
321 for (
unsigned LegalIntWidth : LegalIntWidths)
322 if (Width <= LegalIntWidth)
372 if (PS.HasUnstableRepresentation || PS.HasExternalState ||
373 PS.BitWidth != PS.IndexBitWidth)
396 const auto &PS = getPointerSpec(AddrSpace);
397 return PS.BitWidth != PS.IndexBitWidth || PS.HasUnstableRepresentation ||
407 return getPointerSpec(AddrSpace).HasUnstableRepresentation;
423 return getPointerSpec(AddrSpace).HasExternalState;
480 return getPointerSpec(AS).BitWidth;
488 return getPointerSpec(AS).IndexBitWidth;
574 return {AlignedSizeInBits, BaseSize.
isScalable()};
620 return getIntegerAlignment(
BitWidth,
true);
641 unsigned Width = 0)
const;
712class StructLayout final :
private TrailingObjects<StructLayout, TypeSize> {
713 friend TrailingObjects;
716 Align StructAlignment;
717 unsigned IsPadded : 1;
718 unsigned NumElements : 31;
744 assert(Idx < NumElements &&
"Invalid element idx!");
761 assert(Ty->isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
762 switch (Ty->getTypeID()) {
798 uint64_t MinBits = EltCnt.getKnownMinValue() *
800 return TypeSize(MinBits, EltCnt.isScalable());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the SmallVector class.
This header defines support for implementing classes that have some trailing object (or arrays of obj...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent array types.
uint64_t getNumElements() const
Type * getElementType() const
A parsed version of the target data layout string in and methods for querying it.
unsigned getProgramAddressSpace() const
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
bool hasLinkerPrivateGlobalPrefix() const
bool hasExternalState(unsigned AddrSpace) const
Returns whether this address space has external state (implies having a non-integral pointer represen...
StringRef getLinkerPrivateGlobalPrefix() const
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
bool isNonIntegralPointerType(Type *Ty) const
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
@ Independent
The function pointer alignment is independent of the function alignment.
LLVM_ABI SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
bool isLittleEndian() const
Layout endianness...
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Type * getAddressType(Type *PtrTy) const
Returns the type of an address in AddressSpace.
TypeSize getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
LLVM_ABI unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
unsigned getAddressSizeInBits(unsigned AS) const
The size in bits of an address in for the given AS.
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU.
unsigned getDefaultGlobalsAddressSpace() const
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of an address in AddressSpace.
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
LLVM_ABI unsigned getIndexSize(unsigned AS) const
The index size in bytes used for address calculation, rounded up to a whole number of bytes.
bool mustNotIntroduceIntToPtr(unsigned AddrSpace) const
Returns whether passes must avoid introducing inttoptr instructions for this address space (unless th...
LLVM_ABI const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
LLVM_ABI DataLayout()
Constructs a DataLayout with default values.
bool hasUnstableRepresentation(unsigned AddrSpace) const
Returns whether this address space has an "unstable" pointer representation.
bool mustNotIntroduceIntToPtr(Type *Ty) const
unsigned getAddressSizeInBits(Type *Ty) const
The size in bits of an address for this type.
bool mustNotIntroducePtrToInt(Type *Ty) const
LLVM_ABI IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space.
unsigned getPointerTypeSize(Type *Ty) const
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Returns whether this address space has a non-integral pointer representation, i.e.
bool isIllegalInteger(uint64_t Width) const
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const
The size in bits of the index used in GEP calculation for this type.
PointerType * getAllocaPtrType(LLVMContext &Ctx) const
LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const
The pointer representation size in bits for this type.
SmallVector< unsigned, 8 > getNonStandardAddressSpaces() const
Return the address spaces with special pointer semantics (such as being unstable or non-integral).
MaybeAlign getStackAlignment() const
Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.
unsigned getAllocaAddrSpace() const
LLVM_ABI DataLayout & operator=(const DataLayout &Other)
LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool mustNotIntroducePtrToInt(unsigned AddrSpace) const
Returns whether passes must avoid introducing ptrtoint instructions for this address space (unless th...
LLVM_ABI std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
LLVM_ABI Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
bool hasExternalState(Type *Ty) const
LLVM_ABI Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU.
bool hasMicrosoftFastStdCallMangling() const
bool hasUnstableRepresentation(Type *Ty) const
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
bool isNonIntegralPointerType(PointerType *PT) const
LLVM_ABI Align getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
unsigned getIndexSizeInBits(unsigned AS) const
The size in bits of indices used for address calculation in getelementptr and for addresses in the gi...
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
StringRef getPrivateGlobalPrefix() const
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
bool operator!=(const DataLayout &Other) const
DataLayout(const DataLayout &DL)
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
char getGlobalPrefix() const
LLVM_ABI bool operator==(const DataLayout &Other) const
LLVM_ABI int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
unsigned getAddressSize(unsigned AS) const
The integral size of a pointer in a given address space in bytes, which is defined to be the same as ...
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlign(Ty),...
LLVM_ABI Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
LLVM_ABI Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
static LLVM_ABI Expected< DataLayout > parse(StringRef LayoutString)
Parse a data layout string and return the layout.
Tagged union holding either a T or a Error.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
TypeSize getSizeInBytes() const
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
MutableArrayRef< TypeSize > getMemberOffsets()
LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
TypeSize getElementOffset(unsigned Idx) const
ArrayRef< TypeSize > getMemberOffsets() const
TypeSize getSizeInBits() const
TypeSize getElementOffsetInBits(unsigned Idx) const
Align getAlignment() const
Class to represent struct types.
const T * getTrailingObjects() const
Triple - Helper class for working with autoconf configuration names.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM Value Representation.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
struct LLVMOpaqueTargetData * LLVMTargetDataRef
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Attribute unwrap(LLVMAttributeRef Attr)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVMAttributeRef wrap(Attribute Attr)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static constexpr Align Constant()
Allow constructions of constexpr Align.
Pointer type specification.
bool HasUnstableRepresentation
Pointers in this address space don't have a well-defined bitwise representation (e....
LLVM_ABI bool operator==(const PointerSpec &Other) const
bool HasExternalState
Pointers in this address space have additional state bits that are located at a target-defined locati...
uint32_t IndexBitWidth
The index bit width also defines the address size in this address space.
Primitive type specification.
LLVM_ABI bool operator==(const PrimitiveSpec &Other) const
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.