54 for (
unsigned i = 0, e = NumElements; i != e; ++i) {
59 if ((StructSize & (TyAlign-1)) != 0) {
61 StructSize =
alignTo(StructSize, TyAlign);
65 StructAlignment =
std::max(TyAlign, StructAlignment);
67 MemberOffsets[i] = StructSize;
72 if (StructAlignment == 0) StructAlignment = 1;
76 if ((StructSize & (StructAlignment-1)) != 0) {
78 StructSize =
alignTo(StructSize, StructAlignment);
86 std::upper_bound(&MemberOffsets[0], &MemberOffsets[NumElements], Offset);
87 assert(SI != &MemberOffsets[0] &&
"Offset not in structure type!");
89 assert(*SI <= Offset &&
"upper_bound didn't work");
90 assert((SI == &MemberOffsets[0] || *(SI-1) <= Offset) &&
91 (SI+1 == &MemberOffsets[NumElements] || *(SI+1) > Offset) &&
92 "Upper bound didn't work!");
99 return SI-&MemberOffsets[0];
108 unsigned pref_align,
uint32_t bit_width) {
109 assert(abi_align <= pref_align &&
"Preferred alignment worse than ABI!");
132 unsigned PrefAlign,
uint32_t TypeByteWidth) {
133 assert(ABIAlign <= PrefAlign &&
"Preferred alignment worse than ABI!");
183 StackNaturalAlign = 0;
184 ManglingMode = MM_None;
185 NonIntegralAddressSpaces.
clear();
192 setPointerAlignment(0, 8, 8, 8);
194 parseSpecifier(Desc);
199 assert(!Str.
empty() &&
"parse error, string can't be empty here");
200 std::pair<StringRef, StringRef>
Split = Str.
split(Separator);
201 if (Split.second.empty() && Split.first != Str)
203 if (!Split.second.empty() && Split.first.empty())
225 StringRepresentation =
Desc;
226 while (!Desc.
empty()) {
228 std::pair<StringRef, StringRef>
Split =
split(Desc,
'-');
232 Split =
split(Split.first,
':');
240 Split =
split(Rest,
':');
242 unsigned AS =
getInt(Split.first);
246 }
while (!Rest.
empty());
251 char Specifier = Tok.
front();
267 unsigned AddrSpace = Tok.
empty() ? 0 :
getInt(Tok);
268 if (!isUInt<24>(AddrSpace))
274 "Missing size specification for pointer in datalayout string");
275 Split =
split(Rest,
':');
283 "Missing alignment specification for pointer in datalayout string");
284 Split =
split(Rest,
':');
288 "Pointer ABI alignment must be a power of 2");
291 unsigned PointerPrefAlign = PointerABIAlign;
293 Split =
split(Rest,
':');
297 "Pointer preferred alignment must be a power of 2");
300 setPointerAlignment(AddrSpace, PointerABIAlign, PointerPrefAlign,
322 "Sized aggregate specification in datalayout string");
327 "Missing alignment specification in datalayout string");
328 Split =
split(Rest,
':');
332 "ABI alignment specification must be >0 for non-aggregate types");
335 unsigned PrefAlign = ABIAlign;
337 Split =
split(Rest,
':');
341 setAlignment(AlignType, ABIAlign, PrefAlign, Size);
347 unsigned Width =
getInt(Tok);
350 "Zero width native integer type in datalayout string");
354 Split =
split(Rest,
':');
362 AllocaAddrSpace =
getInt(Tok);
363 if (!isUInt<24>(AllocaAddrSpace))
369 report_fatal_error(
"Unexpected trailing characters after mangling specifier in datalayout string");
378 ManglingMode = MM_ELF;
381 ManglingMode = MM_MachO;
384 ManglingMode = MM_Mips;
387 ManglingMode = MM_WinCOFF;
390 ManglingMode = MM_WinCOFFX86;
408 bool Ret = BigEndian == Other.BigEndian &&
409 AllocaAddrSpace == Other.AllocaAddrSpace &&
410 StackNaturalAlign == Other.StackNaturalAlign &&
411 ManglingMode == Other.ManglingMode &&
412 LegalIntWidths == Other.LegalIntWidths &&
413 Alignments == Other.Alignments && Pointers == Other.Pointers;
421 auto Pair = std::make_pair((
unsigned)AlignType, BitWidth);
422 return std::lower_bound(Alignments.
begin(), Alignments.
end(), Pair,
424 const std::pair<unsigned, uint32_t> &RHS) {
425 return std::tie(LHS.AlignType, LHS.TypeBitWidth) <
426 std::tie(RHS.first, RHS.second);
431 DataLayout::setAlignment(
AlignTypeEnum align_type,
unsigned abi_align,
432 unsigned pref_align,
uint32_t bit_width) {
433 if (!isUInt<24>(bit_width))
444 if (pref_align < abi_align)
446 "Preferred alignment cannot be less than the ABI alignment");
449 if (I != Alignments.
end() &&
450 I->AlignType == (
unsigned)align_type && I->TypeBitWidth == bit_width) {
452 I->ABIAlign = abi_align;
453 I->PrefAlign = pref_align;
457 pref_align, bit_width));
469 void DataLayout::setPointerAlignment(
uint32_t AddrSpace,
unsigned ABIAlign,
472 if (PrefAlign < ABIAlign)
474 "Preferred alignment cannot be less than the ABI alignment");
477 if (I == Pointers.
end() || I->AddressSpace != AddrSpace) {
481 I->ABIAlign = ABIAlign;
482 I->PrefAlign = PrefAlign;
483 I->TypeByteWidth = TypeByteWidth;
489 unsigned DataLayout::getAlignmentInfo(
AlignTypeEnum AlignType,
496 if (I != Alignments.
end() && I->AlignType == (
unsigned)AlignType &&
498 return ABIInfo ? I->ABIAlign : I->PrefAlign;
502 if (I != Alignments.
begin()) {
505 return ABIInfo ? I->ABIAlign : I->PrefAlign;
511 Align *= cast<VectorType>(Ty)->getNumElements();
529 class StructLayoutMap {
531 LayoutInfoTy LayoutInfo;
536 for (
const auto &I : LayoutInfo) {
538 Value->~StructLayout();
544 return LayoutInfo[STy];
550 void DataLayout::clear() {
551 LegalIntWidths.
clear();
554 delete static_cast<StructLayoutMap *
>(LayoutMap);
564 LayoutMap =
new StructLayoutMap();
566 StructLayoutMap *STM =
static_cast<StructLayoutMap*
>(LayoutMap);
587 if (I == Pointers.
end() || I->AddressSpace != AS) {
588 I = findPointerLowerBound(0);
589 assert(I->AddressSpace == 0);
596 if (I == Pointers.
end() || I->AddressSpace != AS) {
597 I = findPointerLowerBound(0);
598 assert(I->AddressSpace == 0);
605 if (I == Pointers.
end() || I->AddressSpace != AS) {
606 I = findPointerLowerBound(0);
607 assert(I->AddressSpace == 0);
609 return I->TypeByteWidth;
614 "This should only be called with a pointer or pointer vector type");
627 unsigned DataLayout::getAlignment(
Type *Ty,
bool abi_or_pref)
const {
630 assert(Ty->
isSized() &&
"Cannot getTypeInfo() on a type that is unsized!");
638 unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
644 return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
648 if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
653 unsigned Align = getAlignmentInfo(
AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
681 return getAlignment(Ty,
true);
687 return getAlignmentInfo(
INTEGER_ALIGN, BitWidth,
true,
nullptr);
691 return getAlignment(Ty,
false);
696 assert(!(Align & (Align-1)) &&
"Alignment is not a power of two!");
701 unsigned AddressSpace)
const {
707 "Expected a pointer or pointer vector type.");
710 if (
VectorType *VecTy = dyn_cast<VectorType>(Ty))
716 for (
unsigned LegalIntWidth : LegalIntWidths)
717 if (Width <= LegalIntWidth)
723 auto Max = std::max_element(LegalIntWidths.
begin(), LegalIntWidths.
end());
724 return Max != LegalIntWidths.
end() ? *Max : 0;
734 for (; GTI != GTE; ++GTI) {
738 unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
747 if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
762 if (GVAlignment >= Alignment) {
763 Alignment = GVAlignment;
764 }
else if (GVAlignment != 0) {
769 if (Alignment < 16) {
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
Type * getIndexedType() const
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
typename SuperClass::const_iterator const_iterator
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
Type * getValueType() const
unsigned getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
gep_type_iterator gep_type_end(const User *GEP)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
unsigned getAlignment() const
static std::pair< StringRef, StringRef > split(StringRef Str, char Separator)
Checked version of split, to ensure mandatory subparts.
4: 80-bit floating point type (X87)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
1: 16-bit floating point type
bool operator==(const DataLayout &Other) const
static const char * getManglingComponent(const Triple &T)
bool isOSWindows() const
Tests whether the OS is Windows.
StructType * getStructTypeOrNull() const
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
unsigned getPreferredTypeAlignmentShift(Type *Ty) const
Returns the preferred alignment for the specified type, returned as log2 of the value (a shift amount...
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
static unsigned getInt(StringRef R)
Get an unsigned integer, including error checks.
Class to represent struct types.
Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
unsigned getAlignment() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
TypeID getTypeID() const
Return the type id for the type.
static LayoutAlignElem get(AlignTypeEnum align_type, unsigned abi_align, unsigned pref_align, uint32_t bit_width)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static const LayoutAlignElem DefaultAlignments[]
Layout pointer alignment element.
uint64_t getElementOffset(unsigned Idx) const
11: Arbitrary bit width integers
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Type * getElementType(unsigned N) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
6: 128-bit floating point type (two 64-bits, PowerPC)
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
Class to represent integer types.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
bool operator==(const LayoutAlignElem &rhs) const
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Triple - Helper class for working with autoconf configuration names.
unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global, returned in log form.
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 getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
16: SIMD 'packed' format, or other vector type
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static const char * Separator
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Class to represent vector types.
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool isIntegerTy() const
True if this is an instance of IntegerType.
typename SuperClass::iterator iterator
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
bool operator==(const PointerAlignElem &rhs) const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
Value * getOperand() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Layout alignment element.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned AlignType
Alignment type from AlignTypeEnum.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
constexpr bool isUInt< 16 >(uint64_t x)
static unsigned inBytes(unsigned Bits)
Convert bits into bytes. Assert if not a byte width multiple.
3: 64-bit floating point type
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
StringRef - Represent a constant reference to a string, i.e.
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
9: MMX vectors (64 bits, X86 specific)
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
unsigned getNumElements() const
Random access to the elements.
static PointerAlignElem get(uint32_t AddressSpace, unsigned ABIAlign, unsigned PrefAlign, uint32_t TypeByteWidth)
Initializer.
void init(const Module *M)
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
5: 128-bit floating point type (112-bit mantissa)
gep_type_iterator gep_type_begin(const User *GEP)