LLVM 19.0.0git
DataLayout.h
Go to the documentation of this file.
1//===- llvm/DataLayout.h - Data size & alignment info -----------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines layout properties related to datatype size/offset/alignment
10// information. It uses lazy annotations to cache information about how
11// structure types are laid out and used.
12//
13// This structure should be created once, filled in if the defaults are not
14// correct and then passed around by const&. None of the members functions
15// require modification to the object.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_IR_DATALAYOUT_H
20#define LLVM_IR_DATALAYOUT_H
21
22#include "llvm/ADT/APInt.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/STLExtras.h"
26#include "llvm/ADT/StringRef.h"
28#include "llvm/IR/Type.h"
36#include <cassert>
37#include <cstdint>
38#include <string>
39
40// This needs to be outside of the namespace, to avoid conflict with llvm-c
41// decl.
42using LLVMTargetDataRef = struct LLVMOpaqueTargetData *;
43
44namespace llvm {
45
46class GlobalVariable;
47class LLVMContext;
48class Module;
49class StructLayout;
50class Triple;
51class Value;
52
53/// Enum used to categorize the alignment types stored by LayoutAlignElem
58 AGGREGATE_ALIGN = 'a'
59};
60
61// FIXME: Currently the DataLayout string carries a "preferred alignment"
62// for types. As the DataLayout is module/global, this should likely be
63// sunk down to an FTTI element that is queried rather than a global
64// preference.
65
66/// Layout alignment element.
67///
68/// Stores the alignment data associated with a given type bit width.
69///
70/// \note The unusual order of elements in the structure attempts to reduce
71/// padding and make the structure slightly more cache friendly.
76
79
80 bool operator==(const LayoutAlignElem &rhs) const;
81};
82
83/// Layout pointer alignment element.
84///
85/// Stores the alignment data associated with a given pointer and address space.
86///
87/// \note The unusual order of elements in the structure attempts to reduce
88/// padding and make the structure slightly more cache friendly.
95
96 /// Initializer
100
101 bool operator==(const PointerAlignElem &rhs) const;
102};
103
104/// A parsed version of the target data layout string in and methods for
105/// querying it.
106///
107/// The target data layout string is specified *by the target* - a frontend
108/// generating LLVM IR is required to generate the right target data for the
109/// target being codegen'd to.
111public:
113 /// The function pointer alignment is independent of the function alignment.
115 /// The function pointer alignment is a multiple of the function alignment.
117 };
118private:
119 /// Defaults to false.
120 bool BigEndian;
121
122 unsigned AllocaAddrSpace;
123 MaybeAlign StackNaturalAlign;
124 unsigned ProgramAddrSpace;
125 unsigned DefaultGlobalsAddrSpace;
126
127 MaybeAlign FunctionPtrAlign;
128 FunctionPtrAlignType TheFunctionPtrAlignType;
129
130 enum ManglingModeT {
131 MM_None,
132 MM_ELF,
133 MM_MachO,
134 MM_WinCOFF,
135 MM_WinCOFFX86,
136 MM_GOFF,
137 MM_Mips,
138 MM_XCOFF
139 };
140 ManglingModeT ManglingMode;
141
142 SmallVector<unsigned char, 8> LegalIntWidths;
143
144 /// Primitive type alignment data. This is sorted by type and bit
145 /// width during construction.
146 using AlignmentsTy = SmallVector<LayoutAlignElem, 4>;
147 AlignmentsTy IntAlignments;
148 AlignmentsTy FloatAlignments;
149 AlignmentsTy VectorAlignments;
150 LayoutAlignElem StructAlignment;
151
152 /// The string representation used to create this DataLayout
153 std::string StringRepresentation;
154
155 using PointersTy = SmallVector<PointerAlignElem, 8>;
156 PointersTy Pointers;
157
158 const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const;
159
160 // The StructType -> StructLayout map.
161 mutable void *LayoutMap = nullptr;
162
163 /// Pointers in these address spaces are non-integral, and don't have a
164 /// well-defined bitwise representation.
165 SmallVector<unsigned, 8> NonIntegralAddressSpaces;
166
167 /// Attempts to set the alignment of the given type. Returns an error
168 /// description on failure.
169 Error setAlignment(AlignTypeEnum AlignType, Align ABIAlign, Align PrefAlign,
171
172 /// Attempts to set the alignment of a pointer in the given address space.
173 /// Returns an error description on failure.
174 Error setPointerAlignmentInBits(uint32_t AddrSpace, Align ABIAlign,
175 Align PrefAlign, uint32_t TypeBitWidth,
176 uint32_t IndexBitWidth);
177
178 /// Internal helper to get alignment for integer of given bitwidth.
179 Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
180
181 /// Internal helper method that returns requested alignment for type.
182 Align getAlignment(Type *Ty, bool abi_or_pref) const;
183
184 /// Attempts to parse a target data specification string and reports an error
185 /// if the string is malformed.
186 Error parseSpecifier(StringRef Desc);
187
188 // Free all internal data structures.
189 void clear();
190
191public:
192 /// Constructs a DataLayout from a specification string. See reset().
193 explicit DataLayout(StringRef LayoutDescription) {
194 reset(LayoutDescription);
195 }
196
197 /// Initialize target data from properties stored in the module.
198 explicit DataLayout(const Module *M);
199
200 DataLayout(const DataLayout &DL) { *this = DL; }
201
202 ~DataLayout(); // Not virtual, do not subclass this class
203
205 clear();
206 StringRepresentation = DL.StringRepresentation;
207 BigEndian = DL.isBigEndian();
208 AllocaAddrSpace = DL.AllocaAddrSpace;
209 StackNaturalAlign = DL.StackNaturalAlign;
210 FunctionPtrAlign = DL.FunctionPtrAlign;
211 TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType;
212 ProgramAddrSpace = DL.ProgramAddrSpace;
213 DefaultGlobalsAddrSpace = DL.DefaultGlobalsAddrSpace;
214 ManglingMode = DL.ManglingMode;
215 LegalIntWidths = DL.LegalIntWidths;
216 IntAlignments = DL.IntAlignments;
217 FloatAlignments = DL.FloatAlignments;
218 VectorAlignments = DL.VectorAlignments;
219 StructAlignment = DL.StructAlignment;
220 Pointers = DL.Pointers;
221 NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces;
222 return *this;
223 }
224
225 bool operator==(const DataLayout &Other) const;
226 bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
227
228 void init(const Module *M);
229
230 /// Parse a data layout string (with fallback to default values).
231 void reset(StringRef LayoutDescription);
232
233 /// Parse a data layout string and return the layout. Return an error
234 /// description on failure.
235 static Expected<DataLayout> parse(StringRef LayoutDescription);
236
237 /// Layout endianness...
238 bool isLittleEndian() const { return !BigEndian; }
239 bool isBigEndian() const { return BigEndian; }
240
241 /// Returns the string representation of the DataLayout.
242 ///
243 /// This representation is in the same format accepted by the string
244 /// constructor above. This should not be used to compare two DataLayout as
245 /// different string can represent the same layout.
246 const std::string &getStringRepresentation() const {
247 return StringRepresentation;
248 }
249
250 /// Test if the DataLayout was constructed from an empty string.
251 bool isDefault() const { return StringRepresentation.empty(); }
252
253 /// Returns true if the specified type is known to be a native integer
254 /// type supported by the CPU.
255 ///
256 /// For example, i64 is not native on most 32-bit CPUs and i37 is not native
257 /// on any known one. This returns false if the integer width is not legal.
258 ///
259 /// The width is specified in bits.
260 bool isLegalInteger(uint64_t Width) const {
261 return llvm::is_contained(LegalIntWidths, Width);
262 }
263
264 bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
265
266 /// Returns true if the given alignment exceeds the natural stack alignment.
267 bool exceedsNaturalStackAlignment(Align Alignment) const {
268 return StackNaturalAlign && (Alignment > *StackNaturalAlign);
269 }
270
272 assert(StackNaturalAlign && "StackNaturalAlign must be defined");
273 return *StackNaturalAlign;
274 }
275
276 unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
277
279 return PointerType::get(Ctx, AllocaAddrSpace);
280 }
281
282 /// Returns the alignment of function pointers, which may or may not be
283 /// related to the alignment of functions.
284 /// \see getFunctionPtrAlignType
285 MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
286
287 /// Return the type of function pointer alignment.
288 /// \see getFunctionPtrAlign
290 return TheFunctionPtrAlignType;
291 }
292
293 unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
295 return DefaultGlobalsAddrSpace;
296 }
297
299 return ManglingMode == MM_WinCOFFX86;
300 }
301
302 /// Returns true if symbols with leading question marks should not receive IR
303 /// mangling. True for Windows mangling modes.
305 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
306 }
307
308 bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
309
311 if (ManglingMode == MM_MachO)
312 return "l";
313 return "";
314 }
315
316 char getGlobalPrefix() const {
317 switch (ManglingMode) {
318 case MM_None:
319 case MM_ELF:
320 case MM_GOFF:
321 case MM_Mips:
322 case MM_WinCOFF:
323 case MM_XCOFF:
324 return '\0';
325 case MM_MachO:
326 case MM_WinCOFFX86:
327 return '_';
328 }
329 llvm_unreachable("invalid mangling mode");
330 }
331
333 switch (ManglingMode) {
334 case MM_None:
335 return "";
336 case MM_ELF:
337 case MM_WinCOFF:
338 return ".L";
339 case MM_GOFF:
340 return "@";
341 case MM_Mips:
342 return "$";
343 case MM_MachO:
344 case MM_WinCOFFX86:
345 return "L";
346 case MM_XCOFF:
347 return "L..";
348 }
349 llvm_unreachable("invalid mangling mode");
350 }
351
352 static const char *getManglingComponent(const Triple &T);
353
354 /// Returns true if the specified type fits in a native integer type
355 /// supported by the CPU.
356 ///
357 /// For example, if the CPU only supports i32 as a native integer type, then
358 /// i27 fits in a legal integer type but i45 does not.
359 bool fitsInLegalInteger(unsigned Width) const {
360 for (unsigned LegalIntWidth : LegalIntWidths)
361 if (Width <= LegalIntWidth)
362 return true;
363 return false;
364 }
365
366 /// Layout pointer alignment
367 Align getPointerABIAlignment(unsigned AS) const;
368
369 /// Return target's alignment for stack-based pointers
370 /// FIXME: The defaults need to be removed once all of
371 /// the backends/clients are updated.
372 Align getPointerPrefAlignment(unsigned AS = 0) const;
373
374 /// Layout pointer size in bytes, rounded up to a whole
375 /// number of bytes.
376 /// FIXME: The defaults need to be removed once all of
377 /// the backends/clients are updated.
378 unsigned getPointerSize(unsigned AS = 0) const;
379
380 /// Returns the maximum index size over all address spaces.
381 unsigned getMaxIndexSize() const;
382
383 // Index size in bytes used for address calculation,
384 /// rounded up to a whole number of bytes.
385 unsigned getIndexSize(unsigned AS) const;
386
387 /// Return the address spaces containing non-integral pointers. Pointers in
388 /// this address space don't have a well-defined bitwise representation.
390 return NonIntegralAddressSpaces;
391 }
392
393 bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
395 return is_contained(NonIntegralSpaces, AddrSpace);
396 }
397
400 }
401
403 auto *PTy = dyn_cast<PointerType>(Ty);
404 return PTy && isNonIntegralPointerType(PTy);
405 }
406
407 /// Layout pointer size, in bits
408 /// FIXME: The defaults need to be removed once all of
409 /// the backends/clients are updated.
410 unsigned getPointerSizeInBits(unsigned AS = 0) const {
411 return getPointerAlignElem(AS).TypeBitWidth;
412 }
413
414 /// Returns the maximum index size over all address spaces.
415 unsigned getMaxIndexSizeInBits() const {
416 return getMaxIndexSize() * 8;
417 }
418
419 /// Size in bits of index used for address calculation in getelementptr.
420 unsigned getIndexSizeInBits(unsigned AS) const {
421 return getPointerAlignElem(AS).IndexBitWidth;
422 }
423
424 /// Layout pointer size, in bits, based on the type. If this function is
425 /// called with a pointer type, then the type size of the pointer is returned.
426 /// If this function is called with a vector of pointers, then the type size
427 /// of the pointer is returned. This should only be called with a pointer or
428 /// vector of pointers.
429 unsigned getPointerTypeSizeInBits(Type *) const;
430
431 /// Layout size of the index used in GEP calculation.
432 /// The function should be called with pointer or vector of pointers type.
433 unsigned getIndexTypeSizeInBits(Type *Ty) const;
434
435 unsigned getPointerTypeSize(Type *Ty) const {
436 return getPointerTypeSizeInBits(Ty) / 8;
437 }
438
439 /// Size examples:
440 ///
441 /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
442 /// ---- ---------- --------------- ---------------
443 /// i1 1 8 8
444 /// i8 8 8 8
445 /// i19 19 24 32
446 /// i32 32 32 32
447 /// i100 100 104 128
448 /// i128 128 128 128
449 /// Float 32 32 32
450 /// Double 64 64 64
451 /// X86_FP80 80 80 96
452 ///
453 /// [*] The alloc size depends on the alignment, and thus on the target.
454 /// These values are for x86-32 linux.
455
456 /// Returns the number of bits necessary to hold the specified type.
457 ///
458 /// If Ty is a scalable vector type, the scalable property will be set and
459 /// the runtime size will be a positive integer multiple of the base size.
460 ///
461 /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
462 /// have a size (Type::isSized() must return true).
464
465 /// Returns the maximum number of bytes that may be overwritten by
466 /// storing the specified type.
467 ///
468 /// If Ty is a scalable vector type, the scalable property will be set and
469 /// the runtime size will be a positive integer multiple of the base size.
470 ///
471 /// For example, returns 5 for i36 and 10 for x86_fp80.
473 TypeSize BaseSize = getTypeSizeInBits(Ty);
474 return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
475 }
476
477 /// Returns the maximum number of bits that may be overwritten by
478 /// storing the specified type; always a multiple of 8.
479 ///
480 /// If Ty is a scalable vector type, the scalable property will be set and
481 /// the runtime size will be a positive integer multiple of the base size.
482 ///
483 /// For example, returns 40 for i36 and 80 for x86_fp80.
485 return 8 * getTypeStoreSize(Ty);
486 }
487
488 /// Returns true if no extra padding bits are needed when storing the
489 /// specified type.
490 ///
491 /// For example, returns false for i19 that has a 24-bit store size.
494 }
495
496 /// Returns the offset in bytes between successive objects of the
497 /// specified type, including alignment padding.
498 ///
499 /// If Ty is a scalable vector type, the scalable property will be set and
500 /// the runtime size will be a positive integer multiple of the base size.
501 ///
502 /// This is the amount that alloca reserves for this type. For example,
503 /// returns 12 or 16 for x86_fp80, depending on alignment.
505 // Round up to the next alignment boundary.
507 }
508
509 /// Returns the offset in bits between successive objects of the
510 /// specified type, including alignment padding; always a multiple of 8.
511 ///
512 /// If Ty is a scalable vector type, the scalable property will be set and
513 /// the runtime size will be a positive integer multiple of the base size.
514 ///
515 /// This is the amount that alloca reserves for this type. For example,
516 /// returns 96 or 128 for x86_fp80, depending on alignment.
518 return 8 * getTypeAllocSize(Ty);
519 }
520
521 /// Returns the minimum ABI-required alignment for the specified type.
522 Align getABITypeAlign(Type *Ty) const;
523
524 /// Helper function to return `Alignment` if it's set or the result of
525 /// `getABITypeAlign(Ty)`, in any case the result is a valid alignment.
527 Type *Ty) const {
528 return Alignment ? *Alignment : getABITypeAlign(Ty);
529 }
530
531 /// Returns the minimum ABI-required alignment for an integer type of
532 /// the specified bitwidth.
534 return getIntegerAlignment(BitWidth, /* abi_or_pref */ true);
535 }
536
537 /// Returns the preferred stack/global alignment for the specified
538 /// type.
539 ///
540 /// This is always at least as good as the ABI alignment.
541 /// FIXME: Deprecate this function once migration to Align is over.
542 LLVM_DEPRECATED("use getPrefTypeAlign instead", "getPrefTypeAlign")
544
545 /// Returns the preferred stack/global alignment for the specified
546 /// type.
547 ///
548 /// This is always at least as good as the ABI alignment.
550
551 /// Returns an integer type with size at least as big as that of a
552 /// pointer in the given address space.
554
555 /// Returns an integer (vector of integer) type with size at least as
556 /// big as that of a pointer of the given pointer (vector of pointer) type.
558
559 /// Returns the smallest integer type with size at least as big as
560 /// Width bits.
561 Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const;
562
563 /// Returns the largest legal integer type, or null if none are set.
565 unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
566 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
567 }
568
569 /// Returns the size of largest legal integer type size, or 0 if none
570 /// are set.
571 unsigned getLargestLegalIntTypeSizeInBits() const;
572
573 /// Returns the type of a GEP index in AddressSpace.
574 /// If it was not specified explicitly, it will be the integer type of the
575 /// pointer width - IntPtrType.
577
578 /// Returns the type of a GEP index.
579 /// If it was not specified explicitly, it will be the integer type of the
580 /// pointer width - IntPtrType.
581 Type *getIndexType(Type *PtrTy) const;
582
583 /// Returns the offset from the beginning of the type for the specified
584 /// indices.
585 ///
586 /// Note that this takes the element type, not the pointer type.
587 /// This is used to implement getelementptr.
588 int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
589
590 /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
591 /// the result element type and Offset to be the residual offset.
593
594 /// Get single GEP index to access Offset inside ElemTy. Returns std::nullopt
595 /// if index cannot be computed, e.g. because the type is not an aggregate.
596 /// ElemTy is updated to be the result element type and Offset to be the
597 /// residual offset.
598 std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const;
599
600 /// Returns a StructLayout object, indicating the alignment of the
601 /// struct, its size, and the offsets of its fields.
602 ///
603 /// Note that this information is lazily cached.
604 const StructLayout *getStructLayout(StructType *Ty) const;
605
606 /// Returns the preferred alignment of the specified global.
607 ///
608 /// This includes an explicitly requested alignment (if the global has one).
609 Align getPreferredAlign(const GlobalVariable *GV) const;
610};
611
613 return reinterpret_cast<DataLayout *>(P);
614}
615
617 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
618}
619
620/// Used to lazily calculate structure layout information for a target machine,
621/// based on the DataLayout structure.
622class StructLayout final : public TrailingObjects<StructLayout, TypeSize> {
623 TypeSize StructSize;
624 Align StructAlignment;
625 unsigned IsPadded : 1;
626 unsigned NumElements : 31;
627
628public:
629 TypeSize getSizeInBytes() const { return StructSize; }
630
631 TypeSize getSizeInBits() const { return 8 * StructSize; }
632
633 Align getAlignment() const { return StructAlignment; }
634
635 /// Returns whether the struct has padding or not between its fields.
636 /// NB: Padding in nested element is not taken into account.
637 bool hasPadding() const { return IsPadded; }
638
639 /// Given a valid byte offset into the structure, returns the structure
640 /// index that contains it.
641 unsigned getElementContainingOffset(uint64_t FixedOffset) const;
642
644 return llvm::MutableArrayRef(getTrailingObjects<TypeSize>(), NumElements);
645 }
646
648 return llvm::ArrayRef(getTrailingObjects<TypeSize>(), NumElements);
649 }
650
651 TypeSize getElementOffset(unsigned Idx) const {
652 assert(Idx < NumElements && "Invalid element idx!");
653 return getMemberOffsets()[Idx];
654 }
655
657 return getElementOffset(Idx) * 8;
658 }
659
660private:
661 friend class DataLayout; // Only DataLayout can create this class
662
664
665 size_t numTrailingObjects(OverloadToken<TypeSize>) const {
666 return NumElements;
667 }
668};
669
670// The implementation of this method is provided inline as it is particularly
671// well suited to constant folding when called on a specific Type subclass.
673 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
674 switch (Ty->getTypeID()) {
675 case Type::LabelTyID:
678 return TypeSize::getFixed(
680 case Type::ArrayTyID: {
681 ArrayType *ATy = cast<ArrayType>(Ty);
682 return ATy->getNumElements() *
684 }
685 case Type::StructTyID:
686 // Get the layout annotation... which is lazily created on demand.
687 return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
690 case Type::HalfTyID:
691 case Type::BFloatTyID:
692 return TypeSize::getFixed(16);
693 case Type::FloatTyID:
694 return TypeSize::getFixed(32);
695 case Type::DoubleTyID:
697 return TypeSize::getFixed(64);
699 case Type::FP128TyID:
700 return TypeSize::getFixed(128);
702 return TypeSize::getFixed(8192);
703 // In memory objects this is always aligned to a higher boundary, but
704 // only 80 bits contain information.
706 return TypeSize::getFixed(80);
709 VectorType *VTy = cast<VectorType>(Ty);
710 auto EltCnt = VTy->getElementCount();
711 uint64_t MinBits = EltCnt.getKnownMinValue() *
713 return TypeSize(MinBits, EltCnt.isScalable());
714 }
715 case Type::TargetExtTyID: {
716 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
717 return getTypeSizeInBits(LayoutTy);
718 }
719 default:
720 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
721 }
722}
723
724} // end namespace llvm
725
726#endif // LLVM_IR_DATALAYOUT_H
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:157
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
Given that RA is a live value
Machine Check Debug Module
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
This header defines support for implementing classes that have some trailing object (or arrays of obj...
Class for arbitrary precision integers.
Definition: APInt.h:76
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Class to represent array types.
Definition: DerivedTypes.h:371
uint64_t getNumElements() const
Definition: DerivedTypes.h:383
Type * getElementType() const
Definition: DerivedTypes.h:384
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:293
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition: DataLayout.h:492
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:870
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:308
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:169
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:310
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition: DataLayout.h:410
unsigned getMaxIndexSize() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.cpp:754
bool isNonIntegralPointerType(Type *Ty) const
Definition: DataLayout.h:402
@ 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.
Definition: DataLayout.cpp:998
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:238
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition: DataLayout.h:251
unsigned getMaxIndexSizeInBits() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.h:415
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:484
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:900
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:260
unsigned getDefaultGlobalsAddressSpace() const
Definition: DataLayout.h:294
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition: DataLayout.h:289
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.h:533
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition: DataLayout.h:304
void init(const Module *M)
Definition: DataLayout.cpp:557
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
Definition: DataLayout.cpp:770
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:720
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
Definition: DataLayout.h:193
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.
Definition: DataLayout.cpp:878
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:435
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:865
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition: DataLayout.h:393
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition: DataLayout.h:389
bool isIllegalInteger(uint64_t Width) const
Definition: DataLayout.h:264
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Definition: DataLayout.cpp:774
PointerType * getAllocaPtrType(LLVMContext &Ctx) const
Definition: DataLayout.h:278
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:763
bool exceedsNaturalStackAlignment(Align Alignment) const
Returns true if the given alignment exceeds the natural stack alignment.
Definition: DataLayout.h:267
bool isBigEndian() const
Definition: DataLayout.h:239
Align getStackAlignment() const
Definition: DataLayout.h:271
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:195
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:276
IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
Definition: DataLayout.cpp:905
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:504
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition: DataLayout.cpp:968
Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
Definition: DataLayout.cpp:893
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:359
bool hasMicrosoftFastStdCallMangling() const
Definition: DataLayout.h:298
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:750
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:398
Align getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
Definition: DataLayout.cpp:746
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition: DataLayout.h:420
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition: DataLayout.h:564
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:332
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition: DataLayout.h:285
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:672
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:472
bool operator!=(const DataLayout &Other) const
Definition: DataLayout.h:226
DataLayout(const DataLayout &DL)
Definition: DataLayout.h:200
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:517
char getGlobalPrefix() const
Definition: DataLayout.h:316
bool operator==(const DataLayout &Other) const
Definition: DataLayout.cpp:559
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
Definition: DataLayout.cpp:920
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:246
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:526
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:742
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:874
DataLayout & operator=(const DataLayout &DL)
Definition: DataLayout.h:204
Tagged union holding either a T or a Error.
Definition: Error.h:474
Class to represent integer types.
Definition: DerivedTypes.h:40
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
Class to represent pointers.
Definition: DerivedTypes.h:646
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:679
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:622
TypeSize getSizeInBytes() const
Definition: DataLayout.h:629
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition: DataLayout.h:637
MutableArrayRef< TypeSize > getMemberOffsets()
Definition: DataLayout.h:643
unsigned getElementContainingOffset(uint64_t FixedOffset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
Definition: DataLayout.cpp:92
TypeSize getElementOffset(unsigned Idx) const
Definition: DataLayout.h:651
ArrayRef< TypeSize > getMemberOffsets() const
Definition: DataLayout.h:647
TypeSize getSizeInBits() const
Definition: DataLayout.h:631
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition: DataLayout.h:656
Align getAlignment() const
Definition: DataLayout.h:633
Class to represent struct types.
Definition: DerivedTypes.h:216
See the file comment for details on the usage of the TrailingObjects type.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:332
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getIntegerBitWidth() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
@ ArrayTyID
Arrays.
Definition: Type.h:75
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
@ TargetExtTyID
Target extension type.
Definition: Type.h:79
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
@ LabelTyID
Labels.
Definition: Type.h:64
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ StructTyID
Structures.
Definition: Type.h:74
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
@ PointerTyID
Pointers.
Definition: Type.h:73
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
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.
Definition: Type.h:302
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:641
Type * getElementType() const
Definition: DerivedTypes.h:436
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:187
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:37
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:417
AddressSpace
Definition: NVPTXBaseInfo.h:21
Op::Description Desc
@ Other
Any other memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:287
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:282
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1888
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Definition: DataLayout.h:54
@ FLOAT_ALIGN
Definition: DataLayout.h:57
@ VECTOR_ALIGN
Definition: DataLayout.h:56
@ INTEGER_ALIGN
Definition: DataLayout.h:55
@ AGGREGATE_ALIGN
Definition: DataLayout.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Layout alignment element.
Definition: DataLayout.h:72
static LayoutAlignElem get(Align ABIAlign, Align PrefAlign, uint32_t BitWidth)
Definition: DataLayout.cpp:125
bool operator==(const LayoutAlignElem &rhs) const
Definition: DataLayout.cpp:135
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Layout pointer alignment element.
Definition: DataLayout.h:89
bool operator==(const PointerAlignElem &rhs) const
Definition: DataLayout.cpp:159
static PointerAlignElem getInBits(uint32_t AddressSpace, Align ABIAlign, Align PrefAlign, uint32_t TypeBitWidth, uint32_t IndexBitWidth)
Initializer.
Definition: DataLayout.cpp:144
Definition: regcomp.c:192