1//===- DataLayout.cpp - Data size & alignment routines ---------------------==//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file defines layout properties related to datatype size/offset/alignment
12// This structure should be created once, filled in if the defaults are not
13// correct and then passed around by const&. None of the members functions
14// require modification to the object.
16//===----------------------------------------------------------------------===//
44//===----------------------------------------------------------------------===//
45// Support for StructLayout
46//===----------------------------------------------------------------------===//
49 : StructSize(
TypeSize::getFixed(0)) {
50 assert(!
ST->isOpaque() &&
"Cannot get layout of opaque structs");
52 NumElements =
ST->getNumElements();
54 // Loop over each of the elements, placing them in memory.
55 for (
unsigned i = 0, e = NumElements; i !=
e; ++i) {
56 Type *Ty =
ST->getElementType(i);
57 if (i == 0 && Ty->isScalableTy())
60 const Align TyAlign =
ST->isPacked() ?
Align(1) :
DL.getABITypeAlign(Ty);
62 // Add padding if necessary to align the data element properly.
63 // Currently the only structure with scalable size will be the homogeneous
64 // scalable vector types. Homogeneous scalable vector types have members of
65 // the same data type so no alignment issue will happen. The condition here
66 // assumes so and needs to be adjusted if this assumption changes (e.g. we
67 // support structures with arbitrary scalable data type, or structure that
68 // contains both fixed size and scalable size data type members).
69 if (!StructSize.isScalable() && !
isAligned(TyAlign, StructSize)) {
74 // Keep track of maximum alignment constraint.
75 StructAlignment = std::max(TyAlign, StructAlignment);
77 getMemberOffsets()[i] = StructSize;
78 // Consume space for this data item
79 StructSize +=
DL.getTypeAllocSize(Ty);
82 // Add padding to the end of the struct so that it could be put in an array
83 // and all array elements would be aligned correctly.
84 if (!StructSize.isScalable() && !
isAligned(StructAlignment, StructSize)) {
90/// getElementContainingOffset - Given a valid offset into the structure,
91/// return the structure index that contains it.
93 assert(!StructSize.isScalable() &&
94 "Cannot get element at offset for structure containing scalable "
103 assert(
SI != MemberOffsets.
begin() &&
"Offset not in structure type!");
108 (
SI + 1 == MemberOffsets.
end() ||
110 "Upper bound didn't work!");
112 // Multiple fields can have the same offset if any of them are zero sized.
113 // For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop
114 // at the i32 element, because it is the last element at that offset. This is
115 // the right one to return, because anything after it will have a higher
116 // offset, implying that this element is non-empty.
117 return SI - MemberOffsets.
begin();
122class StructLayoutMap {
124 LayoutInfoTy LayoutInfo;
128 // Remove any layouts.
129 for (
const auto &
I : LayoutInfo) {
131 Value->~StructLayout();
136 StructLayout *&operator[](StructType *STy) {
return LayoutInfo[STy]; }
139}
// end anonymous namespace
141//===----------------------------------------------------------------------===//
142// DataLayout Class Implementation
143//===----------------------------------------------------------------------===//
159/// Predicate to sort primitive specs by bit width.
160struct LessPrimitiveBitWidth {
162 unsigned RHSBitWidth)
const {
163 return LHS.BitWidth < RHSBitWidth;
167/// Predicate to sort pointer specs by address space number.
168struct LessPointerAddrSpace {
170 unsigned RHSAddrSpace)
const {
171 return LHS.AddrSpace < RHSAddrSpace;
176// Default primitive type specifications.
177// NOTE: These arrays must be sorted by type bit width.
195// Default pointer type specifications.
208 if (
Error Err = parseLayoutString(LayoutString))
213 delete static_cast<StructLayoutMap *
>(LayoutMap);
215 StringRepresentation =
Other.StringRepresentation;
216 BigEndian =
Other.BigEndian;
217 AllocaAddrSpace =
Other.AllocaAddrSpace;
218 ProgramAddrSpace =
Other.ProgramAddrSpace;
219 DefaultGlobalsAddrSpace =
Other.DefaultGlobalsAddrSpace;
220 StackNaturalAlign =
Other.StackNaturalAlign;
221 FunctionPtrAlign =
Other.FunctionPtrAlign;
222 TheFunctionPtrAlignType =
Other.TheFunctionPtrAlignType;
223 ManglingMode =
Other.ManglingMode;
224 LegalIntWidths =
Other.LegalIntWidths;
225 IntSpecs =
Other.IntSpecs;
226 FloatSpecs =
Other.FloatSpecs;
227 VectorSpecs =
Other.VectorSpecs;
228 PointerSpecs =
Other.PointerSpecs;
229 StructABIAlignment =
Other.StructABIAlignment;
230 StructPrefAlignment =
Other.StructPrefAlignment;
235 // NOTE: StringRepresentation might differ, it is not canonicalized.
236 return BigEndian ==
Other.BigEndian &&
237 AllocaAddrSpace ==
Other.AllocaAddrSpace &&
238 ProgramAddrSpace ==
Other.ProgramAddrSpace &&
239 DefaultGlobalsAddrSpace ==
Other.DefaultGlobalsAddrSpace &&
240 StackNaturalAlign ==
Other.StackNaturalAlign &&
241 FunctionPtrAlign ==
Other.FunctionPtrAlign &&
242 TheFunctionPtrAlignType ==
Other.TheFunctionPtrAlignType &&
243 ManglingMode ==
Other.ManglingMode &&
244 LegalIntWidths ==
Other.LegalIntWidths && IntSpecs ==
Other.IntSpecs &&
245 FloatSpecs ==
Other.FloatSpecs && VectorSpecs ==
Other.VectorSpecs &&
246 PointerSpecs ==
Other.PointerSpecs &&
247 StructABIAlignment ==
Other.StructABIAlignment &&
248 StructPrefAlignment ==
Other.StructPrefAlignment;
253 if (
Error Err = Layout.parseLayoutString(LayoutString))
254 return std::move(Err);
263/// Attempts to parse an address space component of a specification.
274/// Attempts to parse a size component of a specification.
286/// Attempts to parse an alignment component of a specification.
288/// On success, returns the value converted to byte amount in \p Alignment.
289/// If the value is zero and \p AllowZero is true, \p Alignment is set to one.
291/// Return an error in a number of cases:
292/// - \p Str is empty or contains characters other than decimal digits;
293/// - the value is zero and \p AllowZero is false;
294/// - the value is too large;
295/// - the value is not a multiple of the byte width;
296/// - the value converted to byte amount is not not a power of two.
298 bool AllowZero =
false) {
309 Alignment =
Align(1);
313 constexpr unsigned ByteWidth = 8;
316 Name +
" alignment must be a power of two times the byte width");
323 // [ifv]<size>:<abi>[:<pref>]
326 assert(Specifier ==
'i' || Specifier ==
'f' || Specifier ==
'v');
329 if (Components.
size() < 2 || Components.
size() > 3)
332 // Size. Required, cannot be zero.
342 if (Specifier ==
'i' &&
BitWidth == 8 && ABIAlign != 1)
345 // Preferred alignment. Optional, defaults to the ABI alignment.
346 Align PrefAlign = ABIAlign;
347 if (Components.
size() > 2)
351 if (PrefAlign < ABIAlign)
353 "preferred alignment cannot be less than the ABI alignment");
355 setPrimitiveSpec(Specifier,
BitWidth, ABIAlign, PrefAlign);
360 // a<size>:<abi>[:<pref>]
365 if (Components.
size() < 2 || Components.
size() > 3)
368 // According to LangRef, <size> component must be absent altogether.
369 // For backward compatibility, allow it to be specified, but require
371 if (!Components[0].
empty()) {
377 // ABI alignment. Required. Can be zero, meaning use one byte alignment.
380 parseAlignment(Components[1], ABIAlign,
"ABI",
/*AllowZero=*/true))
383 // Preferred alignment. Optional, defaults to the ABI alignment.
384 Align PrefAlign = ABIAlign;
385 if (Components.
size() > 2)
389 if (PrefAlign < ABIAlign)
391 "preferred alignment cannot be less than the ABI alignment");
393 StructABIAlignment = ABIAlign;
394 StructPrefAlignment = PrefAlign;
399 // p[<n>]:<size>:<abi>[:<pref>[:<idx>]]
404 if (Components.
size() < 3 || Components.
size() > 5)
407 // Address space. Optional, defaults to 0.
408 unsigned AddrSpace = 0;
409 bool ExternalState =
false;
410 bool UnstableRepr =
false;
411 StringRef AddrSpaceStr = Components[0];
412 while (!AddrSpaceStr.
empty()) {
413 char C = AddrSpaceStr.
front();
415 ExternalState =
true;
416 }
else if (
C ==
'u') {
422 break;
// not a valid flag, remaining must be the address space number.
426 if (!AddrSpaceStr.
empty())
428 return Err;
// Failed to parse the remaining characters as a number
429 if (AddrSpace == 0 && (ExternalState || UnstableRepr))
431 "address space 0 cannot be unstable or have external state");
433 // Size. Required, cannot be zero.
438 // ABI alignment. Required, cannot be zero.
443 // Preferred alignment. Optional, defaults to the ABI alignment.
445 Align PrefAlign = ABIAlign;
446 if (Components.
size() > 3)
450 if (PrefAlign < ABIAlign)
452 "preferred alignment cannot be less than the ABI alignment");
454 // Index size. Optional, defaults to pointer size. Cannot be zero.
456 if (Components.
size() > 4)
457 if (
Error Err =
parseSize(Components[4], IndexBitWidth,
"index size"))
462 "index size cannot be larger than the pointer size");
464 setPointerSpec(AddrSpace,
BitWidth, ABIAlign, PrefAlign, IndexBitWidth,
465 UnstableRepr, ExternalState);
469Error DataLayout::parseSpecification(
471 // The "ni" specifier is the only two-character specifier. Handle it first.
473 // ni:<address space>[:<address space>]...
476 // Drop the first ':', then split the rest of the string the usual way.
480 for (StringRef Str :
split(Rest,
':')) {
486 NonIntegralAddressSpaces.
push_back(AddrSpace);
491 // The rest of the specifiers are single-character.
492 assert(!Spec.
empty() &&
"Empty specification is handled by the caller");
495 if (Specifier ==
'i' || Specifier ==
'f' || Specifier ==
'v')
496 return parsePrimitiveSpec(Spec);
498 if (Specifier ==
'a')
499 return parseAggregateSpec(Spec);
501 if (Specifier ==
'p')
502 return parsePointerSpec(Spec);
507 // Deprecated, but ignoring here to preserve loading older textual llvm
514 "malformed specification, must be just 'e' or 'E'");
517 case 'n':
// Native integer types.
518 // n<size>[:<size>]...
519 for (StringRef Str :
split(Rest,
':')) {
526 case 'S': {
// Stack natural alignment.
533 StackNaturalAlign = Alignment;
556 FunctionPtrAlign = Alignment;
559 case 'P': {
// Function address space.
566 case 'A': {
// Default stack/alloca address space.
573 case 'G': {
// Default address space for global variables.
589 ManglingMode = MM_ELF;
592 ManglingMode = MM_GOFF;
595 ManglingMode = MM_MachO;
598 ManglingMode = MM_Mips;
601 ManglingMode = MM_WinCOFF;
604 ManglingMode = MM_WinCOFFX86;
607 ManglingMode = MM_XCOFF;
619 StringRepresentation = std::string(LayoutString);
621 if (LayoutString.
empty())
624 // Split the data layout string into specifications separated by '-' and
625 // parse each specification individually, updating internal data structures.
626 SmallVector<unsigned, 8> NonIntegralAddressSpaces;
627 for (StringRef Spec :
split(LayoutString,
'-')) {
630 if (
Error Err = parseSpecification(Spec, NonIntegralAddressSpaces))
633 // Mark all address spaces that were qualified as non-integral now. This has
634 // to be done later since the non-integral property is not part of the data
635 // layout pointer specification.
636 for (
unsigned AS : NonIntegralAddressSpaces) {
637 // If there is no special spec for a given AS, getPointerSpec(AS) returns
638 // the spec for AS0, and we then update that to mark it non-integral.
640 setPointerSpec(AS, PS.BitWidth, PS.ABIAlign, PS.PrefAlign, PS.IndexBitWidth,
641 /*HasUnstableRepr=*/true,
/*HasExternalState=*/false);
647void DataLayout::setPrimitiveSpec(
char Specifier, uint32_t
BitWidth,
649 SmallVectorImpl<PrimitiveSpec> *Specs;
660 Specs = &VectorSpecs;
666 // Update the abi, preferred alignments.
667 I->ABIAlign = ABIAlign;
668 I->PrefAlign = PrefAlign;
670 // Insert before I to keep the vector sorted.
676DataLayout::getPointerSpec(uint32_t AddrSpace)
const {
677 if (AddrSpace != 0) {
678 auto I =
lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
679 if (
I != PointerSpecs.end() &&
I->AddrSpace == AddrSpace)
683 assert(PointerSpecs[0].AddrSpace == 0);
684 return PointerSpecs[0];
687void DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t
BitWidth,
689 uint32_t IndexBitWidth,
bool HasUnstableRepr,
690 bool HasExternalState) {
691 auto I =
lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
692 if (
I == PointerSpecs.end() ||
I->AddrSpace != AddrSpace) {
694 IndexBitWidth, HasUnstableRepr,
698 I->ABIAlign = ABIAlign;
699 I->PrefAlign = PrefAlign;
700 I->IndexBitWidth = IndexBitWidth;
701 I->HasUnstableRepresentation = HasUnstableRepr;
702 I->HasExternalState = HasExternalState;
707 bool abi_or_pref)
const {
708 auto I = IntSpecs.begin();
709 for (;
I != IntSpecs.end(); ++
I) {
714 // If we don't have an exact match, use alignment of next larger integer
715 // type. If there is none, use alignment of largest integer type by going
717 if (
I == IntSpecs.end())
719 return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
726 LayoutMap =
new StructLayoutMap();
728 StructLayoutMap *STM =
static_cast<StructLayoutMap*
>(LayoutMap);
732 // Otherwise, create the struct layout. Because it is variable length, we
733 // malloc it, then use placement new.
737 // Set SL before calling StructLayout's ctor. The ctor could cause other
738 // entries to be added to TheMap, invalidating our reference.
747 return getPointerSpec(AS).ABIAlign;
751 return getPointerSpec(AS).PrefAlign;
759 assert(Ty->isPtrOrPtrVectorTy() &&
760 "This should only be called with a pointer or pointer vector type");
761 Ty = Ty->getScalarType();
766 return divideCeil(getPointerSpec(AS).IndexBitWidth, 8);
770 assert(Ty->isPtrOrPtrVectorTy() &&
771 "This should only be called with a pointer or pointer vector type");
772 Ty = Ty->getScalarType();
777 \param abi_or_pref Flag that determines which alignment is returned. true
778 returns the ABI alignment, false returns the preferred alignment.
779 \param Ty The underlying type for which alignment is determined.
781 Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
782 == false) for the requested type \a Ty.
784Align DataLayout::getAlignment(
Type *Ty,
bool abi_or_pref)
const {
785 assert(Ty->isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
786 switch (Ty->getTypeID()) {
787 // Early escape for the non-numeric types.
799 // Packed structure types always have an ABI alignment of one.
803 // Get the layout annotation... which is lazily created on demand.
805 const Align Align = abi_or_pref ? StructABIAlignment : StructPrefAlignment;
814 // PPC_FP128TyID and FP128TyID have different data contents, but the
815 // same size and alignment, so they look the same here.
821 if (
I != FloatSpecs.end() &&
I->BitWidth ==
BitWidth)
822 return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
824 // If we still couldn't find a reasonable default alignment, fall back
825 // to a simple heuristic that the alignment is the first power of two
826 // greater-or-equal to the store size of the type. This is a reasonable
827 // approximation of reality, and if the user wanted something less
828 // less conservative, they should have specified it explicitly in the data
836 if (
I != VectorSpecs.end() &&
I->BitWidth ==
BitWidth)
837 return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
839 // By default, use natural alignment for vector types. This is consistent
840 // with what clang and llvm-gcc do.
842 // We're only calculating a natural alignment, so it doesn't have to be
843 // based on the full size for scalable vectors. Using the minimum element
844 // count should be enough here.
851 return getAlignment(LayoutTy, abi_or_pref);
859 switch (Ty->getTypeID()) {
861 // The alignment of the array is the alignment of the element, so there
862 // is no need for further adjustment.
877 unsigned BitWidth = Ty->getIntegerBitWidth();
883 unsigned AS = Ty->getPointerAddressSpace();
897 return getAlignment(Ty,
true);
901 return getAlignment(Ty,
false);
910 assert(Ty->isPtrOrPtrVectorTy() &&
911 "Expected a pointer or pointer vector type.");
920 for (
unsigned LegalIntWidth : LegalIntWidths)
921 if (Width <= LegalIntWidth)
928 return Max != LegalIntWidths.end() ? *Max : 0;
937 assert(Ty->isPtrOrPtrVectorTy() &&
938 "Expected a pointer or pointer vector type.");
953 for (; GTI != GTE; ++GTI) {
959 // Get structure layout information...
962 // Add in the offset, as calculated by the structure layout info...
974 // Skip over scalable or zero size elements. Also skip element sizes larger
975 // than the positive index space, because the arithmetic below may not be
976 // correct in that case.
985 Offset -= Index * FixedElemSize;
986 if (
Offset.isNegative()) {
987 // Prefer a positive remaining offset to allow struct indexing.
990 assert(
Offset.isNonNegative() &&
"Remaining offset shouldn't be negative");
998 ElemTy = ArrTy->getElementType();
1003 // Vector GEPs are partially broken (e.g. for overaligned element types),
1004 // and may be forbidden in the future, so avoid generating GEPs into
1005 // vectors. See https://discourse.llvm.org/t/67497
1006 return std::nullopt;
1013 return std::nullopt;
1017 ElemTy = STy->getElementType(Index);
1018 return APInt(32, Index);
1021 // Non-aggregate type.
1022 return std::nullopt;
1027 assert(ElemTy->isSized() &&
"Element type must be sized");
1040/// getPreferredAlign - Return the preferred alignment of the specified global.
1041/// This includes an explicitly requested alignment (if the global has one).
1044 // If a section is specified, always precisely honor explicit alignment,
1045 // so we don't insert padding into a section we don't control.
1047 return *GVAlignment;
1049 // If no explicit alignment is specified, compute the alignment based on
1050 // the IR type. If an alignment is specified, increase it to match the ABI
1051 // alignment of the IR type.
1053 // FIXME: Not sure it makes sense to use the alignment of the type if
1054 // there's already an explicit alignment specification.
1058 if (*GVAlignment >= Alignment)
1059 Alignment = *GVAlignment;
1064 // If no explicit alignment is specified, and the global is large, increase
1065 // the alignment to 16.
1066 // FIXME: Why 16, specifically?
1068 if (Alignment <
Align(16)) {
1069 // If the global is not external, see if it is large. If so, give it a
1070 // larger alignment.
1072 Alignment =
Align(16);
// 16-byte alignment.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Error parseSize(StringRef Str, unsigned &BitWidth, StringRef Name="size")
Attempts to parse a size component of a specification.
static APInt getElementIndex(TypeSize ElemSize, APInt &Offset)
static Error parseAddrSpace(StringRef Str, unsigned &AddrSpace)
Attempts to parse an address space component of a specification.
static Error createSpecFormatError(Twine Format)
static Error parseAlignment(StringRef Str, Align &Alignment, StringRef Name, bool AllowZero=false)
Attempts to parse an alignment component of a specification.
constexpr DataLayout::PrimitiveSpec DefaultFloatSpecs[]
constexpr DataLayout::PrimitiveSpec DefaultVectorSpecs[]
constexpr DataLayout::PointerSpec DefaultPointerSpecs[]
constexpr DataLayout::PrimitiveSpec DefaultIntSpecs[]
This file defines the DenseMap class.
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Class for arbitrary precision integers.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A parsed version of the target data layout string in and methods for querying it.
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
@ 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.
LLVM_ABI unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
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.
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.
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const
The size in bits of the index used in GEP calculation for this type.
LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const
The pointer representation size in bits for this type.
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.
LLVM_ABI 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.
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
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...
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.
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.
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.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
bool hasSection() const
Check if this global has a custom object file section.
Type * getValueType() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is an important class for using LLVM in a threaded context.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator insert(iterator I, T &&Elt)
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.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
TypeSize getSizeInBytes() const
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
Align getAlignment() const
Class to represent struct types.
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
@ 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)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
constexpr ScalarTy getFixedValue() const
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
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.
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
StructType * getStructTypeOrNull() const
TypeSize getSequentialElementStride(const DataLayout &DL) const
Value * getOperand() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ 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.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
gep_type_iterator gep_type_end(const User *GEP)
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
bool isAlpha(char C)
Checks if character C is a valid letter as classified by "C" locale.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
gep_type_iterator gep_type_begin(const User *GEP)
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
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.