LLVM: include/llvm/IR/DataLayout.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef LLVM_IR_DATALAYOUT_H
20#define LLVM_IR_DATALAYOUT_H
21
36#include
37#include
38#include
39
40
41
43
44namespace llvm {
45
51
52
53
54
55
56
57
58
59
60
61
62
64public:
65
73
74
80
81
82
83
84
86
87
88
90
91
92
93
96 };
97
104
105private:
106 bool BigEndian = false;
107
108 unsigned AllocaAddrSpace = 0;
109 unsigned ProgramAddrSpace = 0;
110 unsigned DefaultGlobalsAddrSpace = 0;
111
114 FunctionPtrAlignType TheFunctionPtrAlignType =
116
117 enum ManglingModeT {
118 MM_None,
119 MM_ELF,
120 MM_MachO,
121 MM_WinCOFF,
122 MM_WinCOFFX86,
123 MM_GOFF,
124 MM_Mips,
125 MM_XCOFF
126 };
127 ManglingModeT ManglingMode = MM_None;
128
129
130 SmallVector<unsigned char, 8> LegalIntWidths;
131
132
136
137
139
140
141 std::string StringRepresentation;
142
143
146
147
148 mutable void *LayoutMap = nullptr;
149
150
151 void setPrimitiveSpec(char Specifier, uint32_t BitWidth, Align ABIAlign,
152 Align PrefAlign);
153
154
155
156 LLVM_ABI const PointerSpec &getPointerSpec(uint32_t AddrSpace) const;
157
158
160 Align PrefAlign, uint32_t IndexBitWidth,
161 bool HasUnstableRepr, bool HasExternalState);
162
163
165
166
167 Align getAlignment(Type *Ty, bool abi_or_pref) const;
168
169
170 Error parsePrimitiveSpec(StringRef Spec);
171
172
173 Error parseAggregateSpec(StringRef Spec);
174
175
176 Error parsePointerSpec(StringRef Spec);
177
178
179 Error parseSpecification(StringRef Spec,
180 SmallVectorImpl &NonIntegralAddressSpaces);
181
182
183 Error parseLayoutString(StringRef LayoutString);
184
185public:
186
188
189
190
192
194
196
198
201
202
203
205
206
209
210
211
212
213
214
216 return StringRepresentation;
217 }
218
219
220 bool isDefault() const { return StringRepresentation.empty(); }
221
222
223
224
225
226
227
228
232
234
235
236
238
240
244
245
246
247
249
250
251
253 return TheFunctionPtrAlignType;
254 }
255
258 return DefaultGlobalsAddrSpace;
259 }
260
262 return ManglingMode == MM_WinCOFFX86;
263 }
264
265
266
268 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
269 }
270
272
274 if (ManglingMode == MM_MachO)
275 return "l";
276 return "";
277 }
278
280 switch (ManglingMode) {
281 case MM_None:
282 case MM_ELF:
283 case MM_GOFF:
284 case MM_Mips:
285 case MM_WinCOFF:
286 case MM_XCOFF:
287 return '\0';
288 case MM_MachO:
289 case MM_WinCOFFX86:
290 return '_';
291 }
293 }
294
296 switch (ManglingMode) {
297 case MM_None:
298 return "";
299 case MM_ELF:
300 case MM_WinCOFF:
301 return ".L";
302 case MM_GOFF:
303 return "L#";
304 case MM_Mips:
305 return "$";
306 case MM_MachO:
307 case MM_WinCOFFX86:
308 return "L";
309 case MM_XCOFF:
310 return "L..";
311 }
313 }
314
315
316
317
318
319
321 for (unsigned LegalIntWidth : LegalIntWidths)
322 if (Width <= LegalIntWidth)
323 return true;
324 return false;
325 }
326
327
329
330
331
332
334
335
336
337
338
339
340
341
342
344
345
346
347
348
349
350
351
352
353
355
356
357
358
359
360
361
362
363
364
366
367
368
371 for (const PointerSpec &PS : PointerSpecs) {
372 if (PS.HasUnstableRepresentation || PS.HasExternalState ||
373 PS.BitWidth != PS.IndexBitWidth)
374 AddrSpaces.push_back(PS.AddrSpace);
375 }
376 return AddrSpaces;
377 }
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
396 const auto &PS = getPointerSpec(AddrSpace);
397 return PS.BitWidth != PS.IndexBitWidth || PS.HasUnstableRepresentation ||
398 PS.HasExternalState;
399 }
400
401
402
403
404
405
407 return getPointerSpec(AddrSpace).HasUnstableRepresentation;
408 }
413
414
415
416
417
418
419
420
421
423 return getPointerSpec(AddrSpace).HasExternalState;
424 }
429
430
431
432
433
434
435
436
437
438
442
443
444
445
446
447
448
449
453
457
462
467
472
473
474
475
476
477
478
480 return getPointerSpec(AS).BitWidth;
481 }
482
483
484
485
486
488 return getPointerSpec(AS).IndexBitWidth;
489 }
490
491
492
493
494
495
499
500
501
502
503
504
506
507
508
509
510
512
513
514
515
519
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
549
550
551
552
553
554
555
556
562
563
564
565
566
567
568
569
574 return {AlignedSizeInBits, BaseSize.isScalable()};
575 }
576
577
578
579
580
584
585
586
587
588
589
590
591
592
594
595
596
597
598
599
600
601
602
606
607
609
610
611
613 Type *Ty) const {
615 }
616
617
618
620 return getIntegerAlignment(BitWidth, true);
621 }
622
623
624
625
626
628
629
630
633
634
635
637
638
639
641 unsigned Width = 0) const;
642
643
646 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
647 }
648
649
650
652
653
654
655
658
662
663
664
665
667
669
670
671
672
673
674
677
678
679
682
683
684
685
686
689
690
691
692
693
695
696
697
698
700};
701
705
709
710
711
712class StructLayout final : private TrailingObjects<StructLayout, TypeSize> {
713 friend TrailingObjects;
714
716 Align StructAlignment;
717 unsigned IsPadded : 1;
718 unsigned NumElements : 31;
719
720public:
722
724
726
727
728
730
731
732
734
738
742
744 assert(Idx < NumElements && "Invalid element idx!");
746 }
747
751
752private:
753 friend class DataLayout;
754
756};
757
758
759
761 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
762 switch (Ty->getTypeID()) {
772 }
774
790
791
798 uint64_t MinBits = EltCnt.getKnownMinValue() *
800 return TypeSize(MinBits, EltCnt.isScalable());
801 }
805 }
806 default:
807 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
808 }
809}
810
811}
812
813#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the SmallVector class.
This header defines support for implementing classes that have some trailing object (or arrays of obj...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent array types.
uint64_t getNumElements() const
Type * getElementType() const
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
unsigned getProgramAddressSpace() const
Definition DataLayout.h:256
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition DataLayout.h:581
bool hasLinkerPrivateGlobalPrefix() const
Definition DataLayout.h:271
bool hasExternalState(unsigned AddrSpace) const
Returns whether this address space has external state (implies having a non-integral pointer represen...
Definition DataLayout.h:422
StringRef getLinkerPrivateGlobalPrefix() const
Definition DataLayout.h:273
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
Definition DataLayout.h:479
bool isNonIntegralPointerType(Type *Ty) const
Definition DataLayout.h:458
FunctionPtrAlignType
Definition DataLayout.h:98
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
Definition DataLayout.h:102
@ Independent
The function pointer alignment is independent of the function alignment.
Definition DataLayout.h:100
LLVM_ABI SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
bool isLittleEndian() const
Layout endianness...
Definition DataLayout.h:207
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition DataLayout.h:220
Type * getAddressType(Type *PtrTy) const
Returns the type of an address in AddressSpace.
Definition DataLayout.h:668
TypeSize getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
Definition DataLayout.h:570
LLVM_ABI unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
unsigned getAddressSizeInBits(unsigned AS) const
The size in bits of an address in for the given AS.
Definition DataLayout.h:496
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU.
Definition DataLayout.h:229
unsigned getDefaultGlobalsAddressSpace() const
Definition DataLayout.h:257
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition DataLayout.h:252
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition DataLayout.h:619
IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of an address in AddressSpace.
Definition DataLayout.h:659
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition DataLayout.h:267
LLVM_ABI unsigned getIndexSize(unsigned AS) const
The index size in bytes used for address calculation, rounded up to a whole number of bytes.
bool mustNotIntroduceIntToPtr(unsigned AddrSpace) const
Returns whether passes must avoid introducing inttoptr instructions for this address space (unless th...
Definition DataLayout.h:439
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.
bool hasUnstableRepresentation(unsigned AddrSpace) const
Returns whether this address space has an "unstable" pointer representation.
Definition DataLayout.h:406
bool mustNotIntroduceIntToPtr(Type *Ty) const
Definition DataLayout.h:468
unsigned getAddressSizeInBits(Type *Ty) const
The size in bits of an address for this type.
Definition DataLayout.h:516
bool mustNotIntroducePtrToInt(Type *Ty) const
Definition DataLayout.h:463
LLVM_ABI IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space.
unsigned getPointerTypeSize(Type *Ty) const
Definition DataLayout.h:520
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Returns whether this address space has a non-integral pointer representation, i.e.
Definition DataLayout.h:395
bool isIllegalInteger(uint64_t Width) const
Definition DataLayout.h:233
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const
The size in bits of the index used in GEP calculation for this type.
PointerType * getAllocaPtrType(LLVMContext &Ctx) const
Definition DataLayout.h:241
LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const
The pointer representation size in bits for this type.
bool isBigEndian() const
Definition DataLayout.h:208
SmallVector< unsigned, 8 > getNonStandardAddressSpaces() const
Return the address spaces with special pointer semantics (such as being unstable or non-integral).
Definition DataLayout.h:369
MaybeAlign getStackAlignment() const
Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.
Definition DataLayout.h:237
unsigned getAllocaAddrSpace() const
Definition DataLayout.h:239
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...
bool mustNotIntroducePtrToInt(unsigned AddrSpace) const
Returns whether passes must avoid introducing ptrtoint instructions for this address space (unless th...
Definition DataLayout.h:450
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.
bool hasExternalState(Type *Ty) const
Definition DataLayout.h:425
LLVM_ABI Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU.
Definition DataLayout.h:320
bool hasMicrosoftFastStdCallMangling() const
Definition DataLayout.h:261
bool hasUnstableRepresentation(Type *Ty) const
Definition DataLayout.h:409
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
bool isNonIntegralPointerType(PointerType *PT) const
Definition DataLayout.h:454
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...
Definition DataLayout.h:487
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition DataLayout.h:644
StringRef getPrivateGlobalPrefix() const
Definition DataLayout.h:295
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition DataLayout.h:248
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition DataLayout.h:760
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition DataLayout.h:557
bool operator!=(const DataLayout &Other) const
Definition DataLayout.h:200
DataLayout(const DataLayout &DL)
Definition DataLayout.h:193
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition DataLayout.h:603
char getGlobalPrefix() const
Definition DataLayout.h:279
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.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition DataLayout.h:215
unsigned getAddressSize(unsigned AS) const
The integral size of a pointer in a given address space in bytes, which is defined to be the same as ...
Definition DataLayout.h:365
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlign(Ty),...
Definition DataLayout.h:612
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.
Tagged union holding either a T or a Error.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition DataLayout.h:712
TypeSize getSizeInBytes() const
Definition DataLayout.h:721
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition DataLayout.h:729
MutableArrayRef< TypeSize > getMemberOffsets()
Definition DataLayout.h:735
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
Definition DataLayout.h:743
friend class DataLayout
Definition DataLayout.h:753
ArrayRef< TypeSize > getMemberOffsets() const
Definition DataLayout.h:739
TypeSize getSizeInBits() const
Definition DataLayout.h:723
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition DataLayout.h:748
Align getAlignment() const
Definition DataLayout.h:725
Class to represent struct types.
const T * getTrailingObjects() const
Triple - Helper class for working with autoconf configuration names.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
@ 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 LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM Value Representation.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
struct LLVMOpaqueTargetData * LLVMTargetDataRef
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Attribute unwrap(LLVMAttributeRef Attr)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVMAttributeRef wrap(Attribute Attr)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static constexpr Align Constant()
Allow constructions of constexpr Align.
Pointer type specification.
Definition DataLayout.h:75
uint32_t AddrSpace
Definition DataLayout.h:76
bool HasUnstableRepresentation
Pointers in this address space don't have a well-defined bitwise representation (e....
Definition DataLayout.h:89
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...
Definition DataLayout.h:94
Align ABIAlign
Definition DataLayout.h:78
uint32_t BitWidth
Definition DataLayout.h:77
Align PrefAlign
Definition DataLayout.h:79
uint32_t IndexBitWidth
The index bit width also defines the address size in this address space.
Definition DataLayout.h:85
Primitive type specification.
Definition DataLayout.h:66
Align PrefAlign
Definition DataLayout.h:69
LLVM_ABI bool operator==(const PrimitiveSpec &Other) const
Align ABIAlign
Definition DataLayout.h:68
uint32_t BitWidth
Definition DataLayout.h:67
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.