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)) {
50assert(!
ST->isOpaque() &&
"Cannot get layout of opaque structs");
52 NumElements =
ST->getNumElements();
54// Loop over each of the elements, placing them in memory. 55for (
unsigned i = 0, e = NumElements; i !=
e; ++i) {
56Type *Ty =
ST->getElementType(i);
60constAlign 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). 69if (!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. 84if (!StructSize.isScalable() && !
isAligned(StructAlignment, StructSize)) {
90/// getElementContainingOffset - Given a valid offset into the structure, 91/// return the structure index that contains it. 94"Cannot get element at offset for structure containing scalable " 100 std::upper_bound(MemberOffsets.
begin(), MemberOffsets.
end(),
Offset,
102 return TypeSize::isKnownLT(LHS, RHS);
104assert(SI != MemberOffsets.
begin() &&
"Offset not in structure type!");
109 (SI + 1 == MemberOffsets.
end() ||
111"Upper bound didn't work!");
113// Multiple fields can have the same offset if any of them are zero sized. 114// For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop 115// at the i32 element, because it is the last element at that offset. This is 116// the right one to return, because anything after it will have a higher 117// offset, implying that this element is non-empty. 118return SI - MemberOffsets.
begin();
123classStructLayoutMap {
125 LayoutInfoTy LayoutInfo;
129// Remove any layouts. 130for (
constauto &
I : LayoutInfo) {
132Value->~StructLayout();
140}
// end anonymous namespace 142//===----------------------------------------------------------------------===// 143// DataLayout Class Implementation 144//===----------------------------------------------------------------------===// 153 ABIAlign ==
Other.ABIAlign && PrefAlign ==
Other.PrefAlign &&
154 IndexBitWidth ==
Other.IndexBitWidth &&
155 IsNonIntegral ==
Other.IsNonIntegral;
159/// Predicate to sort primitive specs by bit width. 160structLessPrimitiveBitWidth {
162unsigned RHSBitWidth)
const{
163returnLHS.BitWidth < RHSBitWidth;
167/// Predicate to sort pointer specs by address space number. 168structLessPointerAddrSpace {
170unsigned RHSAddrSpace)
const{
171returnLHS.AddrSpace < RHSAddrSpace;
177if (
T.isOSBinFormatGOFF())
179if (
T.isOSBinFormatMachO())
181if ((
T.isOSWindows() ||
T.isUEFI()) &&
T.isOSBinFormatCOFF())
183if (
T.isOSBinFormatXCOFF())
188// Default primitive type specifications. 189// NOTE: These arrays must be sorted by type bit width. 191 {1, Align::Constant<1>(), Align::Constant<1>()},
// i1:8:8 192 {8, Align::Constant<1>(), Align::Constant<1>()},
// i8:8:8 193 {16, Align::Constant<2>(), Align::Constant<2>()},
// i16:16:16 194 {32, Align::Constant<4>(), Align::Constant<4>()},
// i32:32:32 195 {64, Align::Constant<4>(), Align::Constant<8>()},
// i64:32:64 198 {16, Align::Constant<2>(), Align::Constant<2>()},
// f16:16:16 199 {32, Align::Constant<4>(), Align::Constant<4>()},
// f32:32:32 200 {64, Align::Constant<8>(), Align::Constant<8>()},
// f64:64:64 201 {128, Align::Constant<16>(), Align::Constant<16>()},
// f128:128:128 204 {64, Align::Constant<8>(), Align::Constant<8>()},
// v64:64:64 205 {128, Align::Constant<16>(), Align::Constant<16>()},
// v128:128:128 208// Default pointer type specifications. 211 {0, 64, Align::Constant<8>(), Align::Constant<8>(), 64,
false},
221if (
Error Err = parseLayoutString(LayoutString))
226deletestatic_cast<StructLayoutMap *
>(LayoutMap);
228 StringRepresentation =
Other.StringRepresentation;
229 BigEndian =
Other.BigEndian;
230 AllocaAddrSpace =
Other.AllocaAddrSpace;
231 ProgramAddrSpace =
Other.ProgramAddrSpace;
232 DefaultGlobalsAddrSpace =
Other.DefaultGlobalsAddrSpace;
233 StackNaturalAlign =
Other.StackNaturalAlign;
234 FunctionPtrAlign =
Other.FunctionPtrAlign;
235 TheFunctionPtrAlignType =
Other.TheFunctionPtrAlignType;
236 ManglingMode =
Other.ManglingMode;
237 LegalIntWidths =
Other.LegalIntWidths;
238 IntSpecs =
Other.IntSpecs;
239 FloatSpecs =
Other.FloatSpecs;
240 VectorSpecs =
Other.VectorSpecs;
241 PointerSpecs =
Other.PointerSpecs;
242 StructABIAlignment =
Other.StructABIAlignment;
243 StructPrefAlignment =
Other.StructPrefAlignment;
248// NOTE: StringRepresentation might differ, it is not canonicalized. 249return BigEndian ==
Other.BigEndian &&
250 AllocaAddrSpace ==
Other.AllocaAddrSpace &&
251 ProgramAddrSpace ==
Other.ProgramAddrSpace &&
252 DefaultGlobalsAddrSpace ==
Other.DefaultGlobalsAddrSpace &&
253 StackNaturalAlign ==
Other.StackNaturalAlign &&
254 FunctionPtrAlign ==
Other.FunctionPtrAlign &&
255 TheFunctionPtrAlignType ==
Other.TheFunctionPtrAlignType &&
256 ManglingMode ==
Other.ManglingMode &&
257 LegalIntWidths ==
Other.LegalIntWidths && IntSpecs ==
Other.IntSpecs &&
258 FloatSpecs ==
Other.FloatSpecs && VectorSpecs ==
Other.VectorSpecs &&
259 PointerSpecs ==
Other.PointerSpecs &&
260 StructABIAlignment ==
Other.StructABIAlignment &&
261 StructPrefAlignment ==
Other.StructPrefAlignment;
266if (
Error Err = Layout.parseLayoutString(LayoutString))
267return std::move(Err);
276/// Attempts to parse an address space component of a specification. 281if (!to_integer(Str, AddrSpace, 10) || !isUInt<24>(AddrSpace))
287/// Attempts to parse a size component of a specification. 299/// Attempts to parse an alignment component of a specification. 301/// On success, returns the value converted to byte amount in \p Alignment. 302/// If the value is zero and \p AllowZero is true, \p Alignment is set to one. 304/// Return an error in a number of cases: 305/// - \p Str is empty or contains characters other than decimal digits; 306/// - the value is zero and \p AllowZero is false; 307/// - the value is too large; 308/// - the value is not a multiple of the byte width; 309/// - the value converted to byte amount is not not a power of two. 311bool AllowZero =
false) {
316if (!to_integer(Str,
Value, 10) || !isUInt<16>(
Value))
326constexprunsigned ByteWidth = 8;
329Name +
" alignment must be a power of two times the byte width");
336// [ifv]<size>:<abi>[:<pref>] 338char Specifier =
Spec.front();
339assert(Specifier ==
'i' || Specifier ==
'f' || Specifier ==
'v');
340Spec.drop_front().split(Components,
':');
342if (Components.
size() < 2 || Components.
size() > 3)
345// Size. Required, cannot be zero. 355if (Specifier ==
'i' &&
BitWidth == 8 && ABIAlign != 1)
358// Preferred alignment. Optional, defaults to the ABI alignment. 359Align PrefAlign = ABIAlign;
360if (Components.
size() > 2)
364if (PrefAlign < ABIAlign)
366"preferred alignment cannot be less than the ABI alignment");
368 setPrimitiveSpec(Specifier,
BitWidth, ABIAlign, PrefAlign);
373// a<size>:<abi>[:<pref>] 376Spec.drop_front().split(Components,
':');
378if (Components.
size() < 2 || Components.
size() > 3)
381// According to LangRef, <size> component must be absent altogether. 382// For backward compatibility, allow it to be specified, but require 384if (!Components[0].empty()) {
390// ABI alignment. Required. Can be zero, meaning use one byte alignment. 396// Preferred alignment. Optional, defaults to the ABI alignment. 397Align PrefAlign = ABIAlign;
398if (Components.
size() > 2)
402if (PrefAlign < ABIAlign)
404"preferred alignment cannot be less than the ABI alignment");
406 StructABIAlignment = ABIAlign;
407 StructPrefAlignment = PrefAlign;
412// p[<n>]:<size>:<abi>[:<pref>[:<idx>]] 415Spec.drop_front().split(Components,
':');
417if (Components.
size() < 3 || Components.
size() > 5)
420// Address space. Optional, defaults to 0. 421unsigned AddrSpace = 0;
422if (!Components[0].empty())
426// Size. Required, cannot be zero. 431// ABI alignment. Required, cannot be zero. 436// Preferred alignment. Optional, defaults to the ABI alignment. 438Align PrefAlign = ABIAlign;
439if (Components.
size() > 3)
443if (PrefAlign < ABIAlign)
445"preferred alignment cannot be less than the ABI alignment");
447// Index size. Optional, defaults to pointer size. Cannot be zero. 449if (Components.
size() > 4)
450if (
Error Err =
parseSize(Components[4], IndexBitWidth,
"index size"))
455"index size cannot be larger than the pointer size");
457 setPointerSpec(AddrSpace,
BitWidth, ABIAlign, PrefAlign, IndexBitWidth,
462Error DataLayout::parseSpecification(
464// The "ni" specifier is the only two-character specifier. Handle it first. 465if (
Spec.starts_with(
"ni")) {
466// ni:<address space>[:<address space>]... 469// Drop the first ':', then split the rest of the string the usual way. 479 NonIntegralAddressSpaces.
push_back(AddrSpace);
484// The rest of the specifiers are single-character. 485assert(!
Spec.empty() &&
"Empty specification is handled by the caller");
486char Specifier =
Spec.front();
488if (Specifier ==
'i' || Specifier ==
'f' || Specifier ==
'v')
489return parsePrimitiveSpec(
Spec);
492return parseAggregateSpec(
Spec);
495return parsePointerSpec(
Spec);
500// Deprecated, but ignoring here to preserve loading older textual llvm 507"malformed specification, must be just 'e' or 'E'");
508 BigEndian = Specifier ==
'E';
510case'n':
// Native integer types. 511// n<size>[:<size>]... 519case'S': {
// Stack natural alignment. 526 StackNaturalAlign = Alignment;
549 FunctionPtrAlign = Alignment;
552case'P': {
// Function address space. 559case'A': {
// Default stack/alloca address space. 566case'G': {
// Default address space for global variables. 582 ManglingMode = MM_ELF;
585 ManglingMode = MM_GOFF;
588 ManglingMode = MM_MachO;
591 ManglingMode = MM_Mips;
594 ManglingMode = MM_WinCOFF;
597 ManglingMode = MM_WinCOFFX86;
600 ManglingMode = MM_XCOFF;
612 StringRepresentation = std::string(LayoutString);
614if (LayoutString.
empty())
617// Split the data layout string into specifications separated by '-' and 618// parse each specification individually, updating internal data structures. 623if (
Error Err = parseSpecification(
Spec, NonIntegralAddressSpaces))
626// Mark all address spaces that were qualified as non-integral now. This has 627// to be done later since the non-integral property is not part of the data 628// layout pointer specification. 629for (
unsigned AS : NonIntegralAddressSpaces) {
630// If there is no special spec for a given AS, getPointerSpec(AS) returns 631// the spec for AS0, and we then update that to mark it non-integral. 632const PointerSpec &PS = getPointerSpec(AS);
633 setPointerSpec(AS, PS.BitWidth, PS.ABIAlign, PS.PrefAlign, PS.IndexBitWidth,
653 Specs = &VectorSpecs;
659// Update the abi, preferred alignments. 660I->ABIAlign = ABIAlign;
661I->PrefAlign = PrefAlign;
663// Insert before I to keep the vector sorted. 669DataLayout::getPointerSpec(
uint32_t AddrSpace)
const{
671autoI =
lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
672if (
I != PointerSpecs.end() &&
I->AddrSpace == AddrSpace)
676assert(PointerSpecs[0].AddrSpace == 0);
677return PointerSpecs[0];
682uint32_t IndexBitWidth,
bool IsNonIntegral) {
683autoI =
lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
684if (
I == PointerSpecs.end() ||
I->AddrSpace != AddrSpace) {
685 PointerSpecs.insert(
I, PointerSpec{AddrSpace,
BitWidth, ABIAlign, PrefAlign,
686 IndexBitWidth, IsNonIntegral});
689I->ABIAlign = ABIAlign;
690I->PrefAlign = PrefAlign;
691I->IndexBitWidth = IndexBitWidth;
692I->IsNonIntegral = IsNonIntegral;
697bool abi_or_pref)
const{
699// If we don't have an exact match, use alignment of next larger integer 700// type. If there is none, use alignment of largest integer type by going 702if (
I == IntSpecs.end())
704return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
711 LayoutMap =
new StructLayoutMap();
713 StructLayoutMap *STM =
static_cast<StructLayoutMap*
>(LayoutMap);
717// Otherwise, create the struct layout. Because it is variable length, we 718// malloc it, then use placement new. 722// Set SL before calling StructLayout's ctor. The ctor could cause other 723// entries to be added to TheMap, invalidating our reference. 745"This should only be called with a pointer or pointer vector type");
751returndivideCeil(getPointerSpec(AS).IndexBitWidth, 8);
756"This should only be called with a pointer or pointer vector type");
762 \param abi_or_pref Flag that determines which alignment is returned. true 763 returns the ABI alignment, false returns the preferred alignment. 764 \param Ty The underlying type for which alignment is determined. 766 Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref 767 == false) for the requested type \a Ty. 769Align DataLayout::getAlignment(
Type *Ty,
bool abi_or_pref)
const{
770assert(Ty->
isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
772// Early escape for the non-numeric types. 776unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
781return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
784// Packed structure types always have an ABI alignment of one. 785if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
788// Get the layout annotation... which is lazily created on demand. 790constAlignAlign = abi_or_pref ? StructABIAlignment : StructPrefAlignment;
799// PPC_FP128TyID and FP128TyID have different data contents, but the 800// same size and alignment, so they look the same here. 806if (
I != FloatSpecs.end() &&
I->BitWidth ==
BitWidth)
807return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
809// If we still couldn't find a reasonable default alignment, fall back 810// to a simple heuristic that the alignment is the first power of two 811// greater-or-equal to the store size of the type. This is a reasonable 812// approximation of reality, and if the user wanted something less 813// less conservative, they should have specified it explicitly in the data 821if (
I != VectorSpecs.end() &&
I->BitWidth ==
BitWidth)
822return abi_or_pref ?
I->ABIAlign :
I->PrefAlign;
824// By default, use natural alignment for vector types. This is consistent 825// with what clang and llvm-gcc do. 827// We're only calculating a natural alignment, so it doesn't have to be 828// based on the full size for scalable vectors. Using the minimum element 829// count should be enough here. 835Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
836return getAlignment(LayoutTy, abi_or_pref);
844return getAlignment(Ty,
true);
848return getAlignment(Ty,
false);
858"Expected a pointer or pointer vector type.");
861if (
VectorType *VecTy = dyn_cast<VectorType>(Ty))
867for (
unsigned LegalIntWidth : LegalIntWidths)
868if (Width <= LegalIntWidth)
875return Max != LegalIntWidths.
end() ? *Max : 0;
885"Expected a pointer or pointer vector type.");
888if (
VectorType *VecTy = dyn_cast<VectorType>(Ty))
900for (; GTI != GTE; ++GTI) {
903assert(
Idx->getType()->isIntegerTy(32) &&
"Illegal struct idx");
904unsigned FieldNo = cast<ConstantInt>(
Idx)->getZExtValue();
906// Get structure layout information... 909// Add in the offset, as calculated by the structure layout info... 912if (int64_t ArrayIdx = cast<ConstantInt>(
Idx)->getSExtValue())
921// Skip over scalable or zero size elements. Also skip element sizes larger 922// than the positive index space, because the arithmetic below may not be 923// correct in that case. 931Offset -= Index * ElemSize;
933// Prefer a positive remaining offset to allow struct indexing. 936assert(
Offset.isNonNegative() &&
"Remaining offset shouldn't be negative");
943if (
auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
944 ElemTy = ArrTy->getElementType();
948if (isa<VectorType>(ElemTy)) {
949// Vector GEPs are partially broken (e.g. for overaligned element types), 950// and may be forbidden in the future, so avoid generating GEPs into 951// vectors. See https://discourse.llvm.org/t/67497 955if (
auto *STy = dyn_cast<StructType>(ElemTy)) {
963 ElemTy = STy->getElementType(Index);
964returnAPInt(32, Index);
967// Non-aggregate type. 986/// getPreferredAlign - Return the preferred alignment of the specified global. 987/// This includes an explicitly requested alignment (if the global has one). 990// If a section is specified, always precisely honor explicit alignment, 991// so we don't insert padding into a section we don't control. 995// If no explicit alignment is specified, compute the alignment based on 996// the IR type. If an alignment is specified, increase it to match the ABI 997// alignment of the IR type. 999// FIXME: Not sure it makes sense to use the alignment of the type if 1000// there's already an explicit alignment specification. 1004if (*GVAlignment >= Alignment)
1005 Alignment = *GVAlignment;
1010// If no explicit alignment is specified, and the global is large, increase 1011// the alignment to 16. 1012// FIXME: Why 16, specifically? 1014if (Alignment <
Align(16)) {
1015// If the global is not external, see if it is large. If so, give it a 1018 Alignment =
Align(16);
// 16-byte alignment. MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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[]
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
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some functions that are useful when dealing with strings.
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.
static const char * getManglingComponent(const Triple &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 ...
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
@ Independent
The function pointer alignment is independent of the function alignment.
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
DataLayout()
Constructs a DataLayout with default values.
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.
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
DataLayout & operator=(const DataLayout &Other)
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...
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
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
Size in bits of index used for address calculation in getelementptr.
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
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
static 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.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
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.
Class to represent integer types.
static 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.
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()
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.
unsigned getNumElements() const
Random access to the elements.
Triple - Helper class for working with autoconf configuration names.
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.
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)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
TypeID getTypeID() const
Return the type id for the type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVM Value Representation.
Base class of all SIMD vector types.
static 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)
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.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
gep_type_iterator gep_type_end(const User *GEP)
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.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
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
gep_type_iterator gep_type_begin(const User *GEP)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Pointer type specification.
bool operator==(const PointerSpec &Other) const
Primitive type specification.
bool operator==(const PrimitiveSpec &Other) const
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.