19#ifndef LLVM_IR_DATALAYOUT_H
20#define LLVM_IR_DATALAYOUT_H
97 bool BigEndian =
false;
99 unsigned AllocaAddrSpace = 0;
100 unsigned ProgramAddrSpace = 0;
101 unsigned DefaultGlobalsAddrSpace = 0;
118 ManglingModeT ManglingMode = MM_None;
121 SmallVector<unsigned char, 8> LegalIntWidths;
124 SmallVector<PrimitiveSpec, 6> IntSpecs;
125 SmallVector<PrimitiveSpec, 4> FloatSpecs;
126 SmallVector<PrimitiveSpec, 10> VectorSpecs;
129 SmallVector<PointerSpec, 8> PointerSpecs;
132 std::string StringRepresentation;
135 Align StructABIAlignment = Align::Constant<1>();
136 Align StructPrefAlignment = Align::Constant<8>();
139 mutable void *LayoutMap =
nullptr;
151 Align PrefAlign,
uint32_t IndexBitWidth,
158 Align getAlignment(Type *Ty,
bool abi_or_pref)
const;
161 Error parsePrimitiveSpec(StringRef Spec);
164 Error parseAggregateSpec(StringRef Spec);
167 Error parsePointerSpec(StringRef Spec);
170 Error parseSpecification(StringRef Spec,
171 SmallVectorImpl<unsigned> &NonIntegralAddressSpaces);
174 Error parseLayoutString(StringRef LayoutString);
207 return StringRepresentation;
211 bool isDefault()
const {
return StringRepresentation.empty(); }
244 return TheFunctionPtrAlignType;
249 return DefaultGlobalsAddrSpace;
253 return ManglingMode == MM_WinCOFFX86;
259 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
265 if (ManglingMode == MM_MachO)
271 switch (ManglingMode) {
287 switch (ManglingMode) {
314 for (
unsigned LegalIntWidth : LegalIntWidths)
315 if (Width <= LegalIntWidth)
365 if (PS.IsNonIntegral)
380 auto *PTy = dyn_cast<PointerType>(Ty);
485 return {AlignedSizeInBits, BaseSize.
isScalable()};
534 return getIntegerAlignment(
BitWidth,
true);
555 unsigned Width = 0)
const;
630 Align StructAlignment;
631 unsigned IsPadded : 1;
632 unsigned NumElements : 31;
658 assert(
Idx < NumElements &&
"Invalid element idx!");
675 assert(Ty->
isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
712 uint64_t MinBits = EltCnt.getKnownMinValue() *
714 return TypeSize(MinBits, EltCnt.isScalable());
717 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
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
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live value
This file defines the SmallVector class.
This header defines support for implementing classes that have some trailing object (or arrays of obj...
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
static LLVM_ABI const char * getManglingComponent(const Triple &T)
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.
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.
unsigned getAddressSizeInBits(Type *Ty) const
The size in bits of an address for this type.
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
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.
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...
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.
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
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 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.
SmallVector< unsigned, 8 > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
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.
See the file comment for details on the usage of the TrailingObjects type.
const T * getTrailingObjects() const
Returns a pointer to the trailing object array of the given type (which must be one of those specifie...
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.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
@ 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)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
TypeID getTypeID() const
Return the type id for the type.
LLVM_ABI unsigned getIntegerBitWidth() const
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.
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Attribute unwrap(LLVMAttributeRef Attr)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr unsigned BitWidth
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.
Pointer type specification.
LLVM_ABI bool operator==(const PointerSpec &Other) const
bool IsNonIntegral
Pointers in this address space don't have a well-defined bitwise representation (e....
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.