Go to the documentation of this file.
19 #ifndef LLVM_IR_DATALAYOUT_H
20 #define LLVM_IR_DATALAYOUT_H
126 unsigned AllocaAddrSpace;
128 unsigned ProgramAddrSpace;
129 unsigned DefaultGlobalsAddrSpace;
144 ManglingModeT ManglingMode;
146 SmallVector<unsigned char, 8> LegalIntWidths;
150 using AlignmentsTy = SmallVector<LayoutAlignElem, 16>;
151 AlignmentsTy Alignments;
155 return const_cast<DataLayout *
>(
this)->findAlignmentLowerBound(AlignType,
163 std::string StringRepresentation;
165 using PointersTy = SmallVector<PointerAlignElem, 8>;
171 mutable void *LayoutMap =
nullptr;
175 SmallVector<unsigned, 8> NonIntegralAddressSpaces;
192 Align getAlignment(Type *Ty,
bool abi_or_pref)
const;
196 Error parseSpecifier(StringRef Desc);
204 reset(LayoutDescription);
216 StringRepresentation =
DL.StringRepresentation;
217 BigEndian =
DL.isBigEndian();
218 AllocaAddrSpace =
DL.AllocaAddrSpace;
219 StackNaturalAlign =
DL.StackNaturalAlign;
220 FunctionPtrAlign =
DL.FunctionPtrAlign;
221 TheFunctionPtrAlignType =
DL.TheFunctionPtrAlignType;
222 ProgramAddrSpace =
DL.ProgramAddrSpace;
223 DefaultGlobalsAddrSpace =
DL.DefaultGlobalsAddrSpace;
224 ManglingMode =
DL.ManglingMode;
225 LegalIntWidths =
DL.LegalIntWidths;
226 Alignments =
DL.Alignments;
227 Pointers =
DL.Pointers;
228 NonIntegralAddressSpaces =
DL.NonIntegralAddressSpaces;
254 return StringRepresentation;
258 bool isDefault()
const {
return StringRepresentation.empty(); }
275 return StackNaturalAlign && (Alignment > *StackNaturalAlign);
279 assert(StackNaturalAlign &&
"StackNaturalAlign must be defined");
280 return *StackNaturalAlign;
293 return TheFunctionPtrAlignType;
298 return DefaultGlobalsAddrSpace;
302 return ManglingMode == MM_WinCOFFX86;
308 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
314 if (ManglingMode == MM_MachO)
320 switch (ManglingMode) {
336 switch (ManglingMode) {
363 for (
unsigned LegalIntWidth : LegalIntWidths)
364 if (
Width <= LegalIntWidth)
393 return NonIntegralAddressSpaces;
406 auto *PTy = dyn_cast<PointerType>(Ty);
542 return getIntegerAlignment(
BitWidth,
true);
627 Align StructAlignment;
628 unsigned IsPadded : 1;
629 unsigned NumElements : 31;
652 return llvm::ArrayRef(getTrailingObjects<uint64_t>(), NumElements);
656 assert(Idx < NumElements &&
"Invalid element idx!");
669 size_t numTrailingObjects(OverloadToken<uint64_t>)
const {
677 assert(Ty->
isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
715 uint64_t MinBits = EltCnt.getKnownMinValue() *
717 return TypeSize(MinBits, EltCnt.isScalable());
720 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
730 #endif // LLVM_IR_DATALAYOUT_H
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
@ FloatTyID
32-bit floating point type
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
@ DoubleTyID
64-bit floating point type
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
This is an optimization pass for GlobalISel generic memory operations.
bool exceedsNaturalStackAlignment(Align Alignment) const
Returns true if the given alignment exceeds the natural stack alignment.
TypeSize getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
A parsed version of the target data layout string in and methods for querying it.
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
unsigned getProgramAddressSpace() const
unsigned getDefaultGlobalsAddressSpace() const
Layout pointer alignment element.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
@ Independent
The function pointer alignment is independent of the function alignment.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
MutableArrayRef< uint64_t > getMemberOffsets()
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 getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
TypeID getTypeID() const
Return the type id for the type.
Triple - Helper class for working with autoconf configuration names.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Type * getIndexType(Type *PtrTy) const
Returns the type of a GEP index.
The instances of the Type class are immutable: once they are created, they are never changed.
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU.
static const char * getManglingComponent(const Triple &T)
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Type * getElementType() const
Tagged union holding either a T or a Error.
Class to represent array types.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
bool hasLinkerPrivateGlobalPrefix() const
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
static constexpr TypeSize Fixed(ScalarTy ExactSize)
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlignment(Ty),...
struct LLVMOpaqueTargetData * LLVMTargetDataRef
DataLayout & operator=(const DataLayout &DL)
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
uint64_t getSizeInBits() const
bool operator!=(const DataLayout &Other) const
static PointerAlignElem getInBits(uint32_t AddressSpace, Align ABIAlign, Align PrefAlign, uint32_t TypeBitWidth, uint32_t IndexBitWidth)
Initializer.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
uint64_t getNumElements() const
uint64_t getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
(vector float) vec_cmpeq(*A, *B) C
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
uint64_t getElementOffsetInBits(unsigned Idx) const
unsigned getPointerTypeSize(Type *Ty) const
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Class to represent integer types.
#define LLVM_DEPRECATED(MSG, FIX)
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Layout alignment element.
Attribute unwrap(LLVMAttributeRef Attr)
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
Align getStackAlignment() const
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
This struct is a compact representation of a valid (non-zero power of two) alignment.
@ BFloatTyID
16-bit floating point type (7-bit significand)
unsigned getIntegerBitWidth() const
void init(const Module *M)
StringRef getLinkerPrivateGlobalPrefix() const
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
bool hasMicrosoftFastStdCallMangling() const
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Base class of all SIMD vector types.
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
unsigned getMaxIndexSize() const
Returns the maximum index size over all address spaces.
bool isLittleEndian() const
Layout endianness...
This is an important class for using LLVM in a threaded context.
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Class to represent pointers.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
char getGlobalPrefix() const
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions inline
constexpr ScalarTy getFixedValue() const
typename SuperClass::const_iterator const_iterator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Expected< DataLayout > parse(StringRef LayoutDescription)
Parse a data layout string and return the layout.
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
A Module instance is used to store all the information related to an LLVM module.
DataLayout(const DataLayout &DL)
Class for arbitrary precision integers.
unsigned getMaxIndexSizeInBits() const
Returns the maximum index size over all address spaces.
@ FP128TyID
128-bit floating point type (112-bit significand)
LLVMAttributeRef wrap(Attribute Attr)
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
bool isNonIntegralPointerType(Type *Ty) const
Class to represent struct types.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
StringRef - Represent a constant reference to a string, i.e.
uint64_t getSizeInBytes() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isNonIntegralPointerType(PointerType *PT) const
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Machine Check Debug Module
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
unsigned getAllocaAddrSpace() const
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU.
Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
@ IntegerTyID
Arbitrary bit width integers.
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.
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
bool operator==(const LayoutAlignElem &rhs) const
uint64_t getElementOffset(unsigned Idx) const
StringRef getPrivateGlobalPrefix() const
@ FixedVectorTyID
Fixed width SIMD vector type.
bool operator==(const PointerAlignElem &rhs) const
constexpr unsigned BitWidth
bool isIllegalInteger(uint64_t Width) const
See the file comment for details on the usage of the TrailingObjects type.
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
std::optional< std::vector< StOtherPiece > > Other
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
typename SuperClass::iterator iterator
static LayoutAlignElem get(AlignTypeEnum align_type, Align abi_align, Align pref_align, uint32_t bit_width)
bool operator==(const DataLayout &Other) const
unsigned AlignType
Alignment type from AlignTypeEnum.
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
@ ScalableVectorTyID
Scalable SIMD vector type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Align getAlignment() const
ArrayRef< uint64_t > getMemberOffsets() const
@ TargetExtTyID
Target extension type.
@ HalfTyID
16-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
Type * getElementType() const
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...