LLVM 17.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
278 /// Returns the alignment of function pointers, which may or may not be
279 /// related to the alignment of functions.
280 /// \see getFunctionPtrAlignType
281 MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
282
283 /// Return the type of function pointer alignment.
284 /// \see getFunctionPtrAlign
286 return TheFunctionPtrAlignType;
287 }
288
289 unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
291 return DefaultGlobalsAddrSpace;
292 }
293
295 return ManglingMode == MM_WinCOFFX86;
296 }
297
298 /// Returns true if symbols with leading question marks should not receive IR
299 /// mangling. True for Windows mangling modes.
301 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
302 }
303
304 bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
305
307 if (ManglingMode == MM_MachO)
308 return "l";
309 return "";
310 }
311
312 char getGlobalPrefix() const {
313 switch (ManglingMode) {
314 case MM_None:
315 case MM_ELF:
316 case MM_GOFF:
317 case MM_Mips:
318 case MM_WinCOFF:
319 case MM_XCOFF:
320 return '\0';
321 case MM_MachO:
322 case MM_WinCOFFX86:
323 return '_';
324 }
325 llvm_unreachable("invalid mangling mode");
326 }
327
329 switch (ManglingMode) {
330 case MM_None:
331 return "";
332 case MM_ELF:
333 case MM_WinCOFF:
334 return ".L";
335 case MM_GOFF:
336 return "@";
337 case MM_Mips:
338 return "$";
339 case MM_MachO:
340 case MM_WinCOFFX86:
341 return "L";
342 case MM_XCOFF:
343 return "L..";
344 }
345 llvm_unreachable("invalid mangling mode");
346 }
347
348 static const char *getManglingComponent(const Triple &T);
349
350 /// Returns true if the specified type fits in a native integer type
351 /// supported by the CPU.
352 ///
353 /// For example, if the CPU only supports i32 as a native integer type, then
354 /// i27 fits in a legal integer type but i45 does not.
355 bool fitsInLegalInteger(unsigned Width) const {
356 for (unsigned LegalIntWidth : LegalIntWidths)
357 if (Width <= LegalIntWidth)
358 return true;
359 return false;
360 }
361
362 /// Layout pointer alignment
363 Align getPointerABIAlignment(unsigned AS) const;
364
365 /// Return target's alignment for stack-based pointers
366 /// FIXME: The defaults need to be removed once all of
367 /// the backends/clients are updated.
368 Align getPointerPrefAlignment(unsigned AS = 0) const;
369
370 /// Layout pointer size in bytes, rounded up to a whole
371 /// number of bytes.
372 /// FIXME: The defaults need to be removed once all of
373 /// the backends/clients are updated.
374 unsigned getPointerSize(unsigned AS = 0) const;
375
376 /// Returns the maximum index size over all address spaces.
377 unsigned getMaxIndexSize() const;
378
379 // Index size in bytes used for address calculation,
380 /// rounded up to a whole number of bytes.
381 unsigned getIndexSize(unsigned AS) const;
382
383 /// Return the address spaces containing non-integral pointers. Pointers in
384 /// this address space don't have a well-defined bitwise representation.
386 return NonIntegralAddressSpaces;
387 }
388
389 bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
391 return is_contained(NonIntegralSpaces, AddrSpace);
392 }
393
396 }
397
399 auto *PTy = dyn_cast<PointerType>(Ty);
400 return PTy && isNonIntegralPointerType(PTy);
401 }
402
403 /// Layout pointer size, in bits
404 /// FIXME: The defaults need to be removed once all of
405 /// the backends/clients are updated.
406 unsigned getPointerSizeInBits(unsigned AS = 0) const {
407 return getPointerAlignElem(AS).TypeBitWidth;
408 }
409
410 /// Returns the maximum index size over all address spaces.
411 unsigned getMaxIndexSizeInBits() const {
412 return getMaxIndexSize() * 8;
413 }
414
415 /// Size in bits of index used for address calculation in getelementptr.
416 unsigned getIndexSizeInBits(unsigned AS) const {
417 return getPointerAlignElem(AS).IndexBitWidth;
418 }
419
420 /// Layout pointer size, in bits, based on the type. If this function is
421 /// called with a pointer type, then the type size of the pointer is returned.
422 /// If this function is called with a vector of pointers, then the type size
423 /// of the pointer is returned. This should only be called with a pointer or
424 /// vector of pointers.
425 unsigned getPointerTypeSizeInBits(Type *) const;
426
427 /// Layout size of the index used in GEP calculation.
428 /// The function should be called with pointer or vector of pointers type.
429 unsigned getIndexTypeSizeInBits(Type *Ty) const;
430
431 unsigned getPointerTypeSize(Type *Ty) const {
432 return getPointerTypeSizeInBits(Ty) / 8;
433 }
434
435 /// Size examples:
436 ///
437 /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
438 /// ---- ---------- --------------- ---------------
439 /// i1 1 8 8
440 /// i8 8 8 8
441 /// i19 19 24 32
442 /// i32 32 32 32
443 /// i100 100 104 128
444 /// i128 128 128 128
445 /// Float 32 32 32
446 /// Double 64 64 64
447 /// X86_FP80 80 80 96
448 ///
449 /// [*] The alloc size depends on the alignment, and thus on the target.
450 /// These values are for x86-32 linux.
451
452 /// Returns the number of bits necessary to hold the specified type.
453 ///
454 /// If Ty is a scalable vector type, the scalable property will be set and
455 /// the runtime size will be a positive integer multiple of the base size.
456 ///
457 /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
458 /// have a size (Type::isSized() must return true).
460
461 /// Returns the maximum number of bytes that may be overwritten by
462 /// storing the specified type.
463 ///
464 /// If Ty is a scalable vector type, the scalable property will be set and
465 /// the runtime size will be a positive integer multiple of the base size.
466 ///
467 /// For example, returns 5 for i36 and 10 for x86_fp80.
469 TypeSize BaseSize = getTypeSizeInBits(Ty);
470 return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
471 }
472
473 /// Returns the maximum number of bits that may be overwritten by
474 /// storing the specified type; always a multiple of 8.
475 ///
476 /// If Ty is a scalable vector type, the scalable property will be set and
477 /// the runtime size will be a positive integer multiple of the base size.
478 ///
479 /// For example, returns 40 for i36 and 80 for x86_fp80.
481 return 8 * getTypeStoreSize(Ty);
482 }
483
484 /// Returns true if no extra padding bits are needed when storing the
485 /// specified type.
486 ///
487 /// For example, returns false for i19 that has a 24-bit store size.
490 }
491
492 /// Returns the offset in bytes between successive objects of the
493 /// specified type, including alignment padding.
494 ///
495 /// If Ty is a scalable vector type, the scalable property will be set and
496 /// the runtime size will be a positive integer multiple of the base size.
497 ///
498 /// This is the amount that alloca reserves for this type. For example,
499 /// returns 12 or 16 for x86_fp80, depending on alignment.
501 // Round up to the next alignment boundary.
503 }
504
505 /// Returns the offset in bits between successive objects of the
506 /// specified type, including alignment padding; always a multiple of 8.
507 ///
508 /// If Ty is a scalable vector type, the scalable property will be set and
509 /// the runtime size will be a positive integer multiple of the base size.
510 ///
511 /// This is the amount that alloca reserves for this type. For example,
512 /// returns 96 or 128 for x86_fp80, depending on alignment.
514 return 8 * getTypeAllocSize(Ty);
515 }
516
517 /// Returns the minimum ABI-required alignment for the specified type.
518 /// FIXME: Deprecate this function once migration to Align is over.
519 LLVM_DEPRECATED("use getABITypeAlign instead", "getABITypeAlign")
521
522 /// Returns the minimum ABI-required alignment for the specified type.
524
525 /// Helper function to return `Alignment` if it's set or the result of
526 /// `getABITypeAlignment(Ty)`, in any case the result is a valid alignment.
528 Type *Ty) const {
529 return Alignment ? *Alignment : getABITypeAlign(Ty);
530 }
531
532 /// Returns the minimum ABI-required alignment for an integer type of
533 /// the specified bitwidth.
535 return getIntegerAlignment(BitWidth, /* abi_or_pref */ true);
536 }
537
538 /// Returns the preferred stack/global alignment for the specified
539 /// type.
540 ///
541 /// This is always at least as good as the ABI alignment.
542 /// FIXME: Deprecate this function once migration to Align is over.
543 LLVM_DEPRECATED("use getPrefTypeAlign instead", "getPrefTypeAlign")
545
546 /// Returns the preferred stack/global alignment for the specified
547 /// type.
548 ///
549 /// This is always at least as good as the ABI alignment.
551
552 /// Returns an integer type with size at least as big as that of a
553 /// pointer in the given address space.
555
556 /// Returns an integer (vector of integer) type with size at least as
557 /// big as that of a pointer of the given pointer (vector of pointer) type.
559
560 /// Returns the smallest integer type with size at least as big as
561 /// Width bits.
562 Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const;
563
564 /// Returns the largest legal integer type, or null if none are set.
566 unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
567 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
568 }
569
570 /// Returns the size of largest legal integer type size, or 0 if none
571 /// are set.
572 unsigned getLargestLegalIntTypeSizeInBits() const;
573
574 /// Returns the type of a GEP index in AddressSpace.
575 /// If it was not specified explicitly, it will be the integer type of the
576 /// pointer width - IntPtrType.
578
579 /// Returns the type of a GEP index.
580 /// If it was not specified explicitly, it will be the integer type of the
581 /// pointer width - IntPtrType.
582 Type *getIndexType(Type *PtrTy) const;
583
584 /// Returns the offset from the beginning of the type for the specified
585 /// indices.
586 ///
587 /// Note that this takes the element type, not the pointer type.
588 /// This is used to implement getelementptr.
589 int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
590
591 /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
592 /// the result element type and Offset to be the residual offset.
594
595 /// Get single GEP index to access Offset inside ElemTy. Returns std::nullopt
596 /// if index cannot be computed, e.g. because the type is not an aggregate.
597 /// ElemTy is updated to be the result element type and Offset to be the
598 /// residual offset.
599 std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const;
600
601 /// Returns a StructLayout object, indicating the alignment of the
602 /// struct, its size, and the offsets of its fields.
603 ///
604 /// Note that this information is lazily cached.
605 const StructLayout *getStructLayout(StructType *Ty) const;
606
607 /// Returns the preferred alignment of the specified global.
608 ///
609 /// This includes an explicitly requested alignment (if the global has one).
610 Align getPreferredAlign(const GlobalVariable *GV) const;
611};
612
614 return reinterpret_cast<DataLayout *>(P);
615}
616
618 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
619}
620
621/// Used to lazily calculate structure layout information for a target machine,
622/// based on the DataLayout structure.
623class StructLayout final : public TrailingObjects<StructLayout, TypeSize> {
624 TypeSize StructSize;
625 Align StructAlignment;
626 unsigned IsPadded : 1;
627 unsigned NumElements : 31;
628
629public:
630 TypeSize getSizeInBytes() const { return StructSize; }
631
632 TypeSize getSizeInBits() const { return 8 * StructSize; }
633
634 Align getAlignment() const { return StructAlignment; }
635
636 /// Returns whether the struct has padding or not between its fields.
637 /// NB: Padding in nested element is not taken into account.
638 bool hasPadding() const { return IsPadded; }
639
640 /// Given a valid byte offset into the structure, returns the structure
641 /// index that contains it.
642 unsigned getElementContainingOffset(uint64_t FixedOffset) const;
643
645 return llvm::MutableArrayRef(getTrailingObjects<TypeSize>(), NumElements);
646 }
647
649 return llvm::ArrayRef(getTrailingObjects<TypeSize>(), NumElements);
650 }
651
652 TypeSize getElementOffset(unsigned Idx) const {
653 assert(Idx < NumElements && "Invalid element idx!");
654 return getMemberOffsets()[Idx];
655 }
656
658 return getElementOffset(Idx) * 8;
659 }
660
661private:
662 friend class DataLayout; // Only DataLayout can create this class
663
665
666 size_t numTrailingObjects(OverloadToken<TypeSize>) const {
667 return NumElements;
668 }
669};
670
671// The implementation of this method is provided inline as it is particularly
672// well suited to constant folding when called on a specific Type subclass.
674 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
675 switch (Ty->getTypeID()) {
676 case Type::LabelTyID:
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::Fixed(16);
693 case Type::FloatTyID:
694 return TypeSize::Fixed(32);
695 case Type::DoubleTyID:
697 return TypeSize::Fixed(64);
699 case Type::FP128TyID:
700 return TypeSize::Fixed(128);
702 return TypeSize::Fixed(8192);
703 // In memory objects this is always aligned to a higher boundary, but
704 // only 80 bits contain information.
706 return TypeSize::Fixed(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...
always inline
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:145
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:75
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:368
uint64_t getNumElements() const
Definition: DerivedTypes.h:380
Type * getElementType() const
Definition: DerivedTypes.h:381
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:289
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition: DataLayout.h:488
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:873
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:304
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:169
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:306
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:406
unsigned getMaxIndexSize() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.cpp:752
bool isNonIntegralPointerType(Type *Ty) const
Definition: DataLayout.h:398
@ 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.
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:411
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:480
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:903
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:290
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition: DataLayout.h:285
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.h:534
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition: DataLayout.h:300
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:768
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:718
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:881
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:431
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:868
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition: DataLayout.h:389
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition: DataLayout.h:385
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:772
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:761
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
uint64_t getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:864
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:908
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:500
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition: DataLayout.cpp:972
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:896
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:355
bool hasMicrosoftFastStdCallMangling() const
Definition: DataLayout.h:294
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:748
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:394
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:744
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition: DataLayout.h:416
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition: DataLayout.h:565
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:328
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition: DataLayout.h:281
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:673
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:468
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:513
char getGlobalPrefix() const
Definition: DataLayout.h:312
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:923
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 getABITypeAlignment(Ty),...
Definition: DataLayout.h:527
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:740
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:877
DataLayout & operator=(const DataLayout &DL)
Definition: DataLayout.h:204
Tagged union holding either a T or a Error.
Definition: Error.h:470
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:305
Class to represent pointers.
Definition: DerivedTypes.h:643
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:693
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
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:623
TypeSize getSizeInBytes() const
Definition: DataLayout.h:630
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition: DataLayout.h:638
MutableArrayRef< TypeSize > getMemberOffsets()
Definition: DataLayout.h:644
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:652
ArrayRef< TypeSize > getMemberOffsets() const
Definition: DataLayout.h:648
TypeSize getSizeInBits() const
Definition: DataLayout.h:632
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition: DataLayout.h:657
Align getAlignment() const
Definition: DataLayout.h:634
Class to represent struct types.
Definition: DerivedTypes.h:213
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 Fixed(ScalarTy ExactSize)
Definition: TypeSize.h:331
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:400
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:638
Type * getElementType() const
Definition: DerivedTypes.h:433
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:182
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:166
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:163
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:440
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:522
AddressSpace
Definition: NVPTXBaseInfo.h:21
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:290
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:184
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:285
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1976
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