LLVM 22.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 StructLayout;
49class Triple;
50class Value;
51
52// FIXME: Currently the DataLayout string carries a "preferred alignment"
53// for types. As the DataLayout is module/global, this should likely be
54// sunk down to an FTTI element that is queried rather than a global
55// preference.
56
57/// A parsed version of the target data layout string in and methods for
58/// querying it.
59///
60/// The target data layout string is specified *by the target* - a frontend
61/// generating LLVM IR is required to generate the right target data for the
62/// target being codegen'd to.
64public:
65 /// Primitive type specification.
73
74 /// Pointer type specification.
75 struct PointerSpec {
81 /// Pointers in this address space don't have a well-defined bitwise
82 /// representation (e.g. may be relocated by a copying garbage collector).
83 /// Additionally, they may also be non-integral (i.e. containing additional
84 /// metadata such as bounds information/permissions).
86 LLVM_ABI bool operator==(const PointerSpec &Other) const;
87 };
88
90 /// The function pointer alignment is independent of the function alignment.
92 /// The function pointer alignment is a multiple of the function alignment.
94 };
95
96private:
97 bool BigEndian = false;
98
99 unsigned AllocaAddrSpace = 0;
100 unsigned ProgramAddrSpace = 0;
101 unsigned DefaultGlobalsAddrSpace = 0;
102
103 MaybeAlign StackNaturalAlign;
104 MaybeAlign FunctionPtrAlign;
105 FunctionPtrAlignType TheFunctionPtrAlignType =
107
108 enum ManglingModeT {
109 MM_None,
110 MM_ELF,
111 MM_MachO,
112 MM_WinCOFF,
113 MM_WinCOFFX86,
114 MM_GOFF,
115 MM_Mips,
116 MM_XCOFF
117 };
118 ManglingModeT ManglingMode = MM_None;
119
120 // FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
121 SmallVector<unsigned char, 8> LegalIntWidths;
122
123 /// Primitive type specifications. Sorted and uniqued by type bit width.
127
128 /// Pointer type specifications. Sorted and uniqued by address space number.
129 SmallVector<PointerSpec, 8> PointerSpecs;
130
131 /// The string representation used to create this DataLayout
132 std::string StringRepresentation;
133
134 /// Struct type ABI and preferred alignments. The default spec is "a:8:64".
135 Align StructABIAlignment = Align::Constant<1>();
136 Align StructPrefAlignment = Align::Constant<8>();
137
138 // The StructType -> StructLayout map.
139 mutable void *LayoutMap = nullptr;
140
141 /// Sets or updates the specification for the given primitive type.
142 void setPrimitiveSpec(char Specifier, uint32_t BitWidth, Align ABIAlign,
143 Align PrefAlign);
144
145 /// Searches for a pointer specification that matches the given address space.
146 /// Returns the default address space specification if not found.
147 LLVM_ABI const PointerSpec &getPointerSpec(uint32_t AddrSpace) const;
148
149 /// Sets or updates the specification for pointer in the given address space.
150 void setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth, Align ABIAlign,
151 Align PrefAlign, uint32_t IndexBitWidth,
152 bool IsNonIntegral);
153
154 /// Internal helper to get alignment for integer of given bitwidth.
155 LLVM_ABI Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
156
157 /// Internal helper method that returns requested alignment for type.
158 Align getAlignment(Type *Ty, bool abi_or_pref) const;
159
160 /// Attempts to parse primitive specification ('i', 'f', or 'v').
161 Error parsePrimitiveSpec(StringRef Spec);
162
163 /// Attempts to parse aggregate specification ('a').
164 Error parseAggregateSpec(StringRef Spec);
165
166 /// Attempts to parse pointer specification ('p').
167 Error parsePointerSpec(StringRef Spec);
168
169 /// Attempts to parse a single specification.
170 Error parseSpecification(StringRef Spec,
171 SmallVectorImpl<unsigned> &NonIntegralAddressSpaces);
172
173 /// Attempts to parse a data layout string.
174 Error parseLayoutString(StringRef LayoutString);
175
176public:
177 /// Constructs a DataLayout with default values.
179
180 /// Constructs a DataLayout from a specification string.
181 /// WARNING: Aborts execution if the string is malformed. Use parse() instead.
182 LLVM_ABI explicit DataLayout(StringRef LayoutString);
183
184 DataLayout(const DataLayout &DL) { *this = DL; }
185
186 LLVM_ABI ~DataLayout(); // Not virtual, do not subclass this class
187
189
190 LLVM_ABI bool operator==(const DataLayout &Other) const;
191 bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
192
193 /// Parse a data layout string and return the layout. Return an error
194 /// description on failure.
195 LLVM_ABI static Expected<DataLayout> parse(StringRef LayoutString);
196
197 /// Layout endianness...
198 bool isLittleEndian() const { return !BigEndian; }
199 bool isBigEndian() const { return BigEndian; }
200
201 /// Returns the string representation of the DataLayout.
202 ///
203 /// This representation is in the same format accepted by the string
204 /// constructor above. This should not be used to compare two DataLayout as
205 /// different string can represent the same layout.
206 const std::string &getStringRepresentation() const {
207 return StringRepresentation;
208 }
209
210 /// Test if the DataLayout was constructed from an empty string.
211 bool isDefault() const { return StringRepresentation.empty(); }
212
213 /// Returns true if the specified type is known to be a native integer
214 /// type supported by the CPU.
215 ///
216 /// For example, i64 is not native on most 32-bit CPUs and i37 is not native
217 /// on any known one. This returns false if the integer width is not legal.
218 ///
219 /// The width is specified in bits.
220 bool isLegalInteger(uint64_t Width) const {
221 return llvm::is_contained(LegalIntWidths, Width);
222 }
223
224 bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
225
226 /// Returns the natural stack alignment, or MaybeAlign() if one wasn't
227 /// specified.
228 MaybeAlign getStackAlignment() const { return StackNaturalAlign; }
229
230 unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
231
233 return PointerType::get(Ctx, AllocaAddrSpace);
234 }
235
236 /// Returns the alignment of function pointers, which may or may not be
237 /// related to the alignment of functions.
238 /// \see getFunctionPtrAlignType
239 MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
240
241 /// Return the type of function pointer alignment.
242 /// \see getFunctionPtrAlign
244 return TheFunctionPtrAlignType;
245 }
246
247 unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
249 return DefaultGlobalsAddrSpace;
250 }
251
253 return ManglingMode == MM_WinCOFFX86;
254 }
255
256 /// Returns true if symbols with leading question marks should not receive IR
257 /// mangling. True for Windows mangling modes.
259 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
260 }
261
262 bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
263
265 if (ManglingMode == MM_MachO)
266 return "l";
267 return "";
268 }
269
270 char getGlobalPrefix() const {
271 switch (ManglingMode) {
272 case MM_None:
273 case MM_ELF:
274 case MM_GOFF:
275 case MM_Mips:
276 case MM_WinCOFF:
277 case MM_XCOFF:
278 return '\0';
279 case MM_MachO:
280 case MM_WinCOFFX86:
281 return '_';
282 }
283 llvm_unreachable("invalid mangling mode");
284 }
285
287 switch (ManglingMode) {
288 case MM_None:
289 return "";
290 case MM_ELF:
291 case MM_WinCOFF:
292 return ".L";
293 case MM_GOFF:
294 return "L#";
295 case MM_Mips:
296 return "$";
297 case MM_MachO:
298 case MM_WinCOFFX86:
299 return "L";
300 case MM_XCOFF:
301 return "L..";
302 }
303 llvm_unreachable("invalid mangling mode");
304 }
305
306 /// Returns true if the specified type fits in a native integer type
307 /// supported by the CPU.
308 ///
309 /// For example, if the CPU only supports i32 as a native integer type, then
310 /// i27 fits in a legal integer type but i45 does not.
311 bool fitsInLegalInteger(unsigned Width) const {
312 for (unsigned LegalIntWidth : LegalIntWidths)
313 if (Width <= LegalIntWidth)
314 return true;
315 return false;
316 }
317
318 /// Layout pointer alignment
319 LLVM_ABI Align getPointerABIAlignment(unsigned AS) const;
320
321 /// Return target's alignment for stack-based pointers
322 /// FIXME: The defaults need to be removed once all of
323 /// the backends/clients are updated.
324 LLVM_ABI Align getPointerPrefAlignment(unsigned AS = 0) const;
325
326 /// The pointer representation size in bytes, rounded up to a whole number of
327 /// bytes. The difference between this function and getAddressSize() is that
328 /// this one returns the size of the entire pointer representation (including
329 /// metadata bits for fat pointers) and the latter only returns the number of
330 /// address bits.
331 /// \sa DataLayout::getAddressSizeInBits
332 /// FIXME: The defaults need to be removed once all of
333 /// the backends/clients are updated.
334 LLVM_ABI unsigned getPointerSize(unsigned AS = 0) const;
335
336 /// The index size in bytes used for address calculation, rounded up to a
337 /// whole number of bytes. This not only defines the size used in
338 /// getelementptr operations, but also the size of addresses in this \p AS.
339 /// For example, a 64-bit CHERI-enabled target has 128-bit pointers of which
340 /// only 64 are used to represent the address and the remaining ones are used
341 /// for metadata such as bounds and access permissions. In this case
342 /// getPointerSize() returns 16, but getIndexSize() returns 8.
343 /// To help with code understanding, the alias getAddressSize() can be used
344 /// instead of getIndexSize() to clarify that an address width is needed.
345 LLVM_ABI unsigned getIndexSize(unsigned AS) const;
346
347 /// The integral size of a pointer in a given address space in bytes, which
348 /// is defined to be the same as getIndexSize(). This exists as a separate
349 /// function to make it clearer when reading code that the size of an address
350 /// is being requested. While targets exist where index size and the
351 /// underlying address width are not identical (e.g. AMDGPU fat pointers with
352 /// 48-bit addresses and 32-bit offsets indexing), there is currently no need
353 /// to differentiate these properties in LLVM.
354 /// \sa DataLayout::getIndexSize
355 /// \sa DataLayout::getAddressSizeInBits
356 unsigned getAddressSize(unsigned AS) const { return getIndexSize(AS); }
357
358 /// Return the address spaces containing non-integral pointers. Pointers in
359 /// this address space don't have a well-defined bitwise representation.
361 SmallVector<unsigned, 8> AddrSpaces;
362 for (const PointerSpec &PS : PointerSpecs) {
363 if (PS.IsNonIntegral)
364 AddrSpaces.push_back(PS.AddrSpace);
365 }
366 return AddrSpaces;
367 }
368
369 bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
370 return getPointerSpec(AddrSpace).IsNonIntegral;
371 }
372
376
378 auto *PTy = dyn_cast<PointerType>(Ty);
379 return PTy && isNonIntegralPointerType(PTy);
380 }
381
382 /// The size in bits of the pointer representation in a given address space.
383 /// This is not necessarily the same as the integer address of a pointer (e.g.
384 /// for fat pointers).
385 /// \sa DataLayout::getAddressSizeInBits()
386 /// FIXME: The defaults need to be removed once all of
387 /// the backends/clients are updated.
388 unsigned getPointerSizeInBits(unsigned AS = 0) const {
389 return getPointerSpec(AS).BitWidth;
390 }
391
392 /// The size in bits of indices used for address calculation in getelementptr
393 /// and for addresses in the given AS. See getIndexSize() for more
394 /// information.
395 /// \sa DataLayout::getAddressSizeInBits()
396 unsigned getIndexSizeInBits(unsigned AS) const {
397 return getPointerSpec(AS).IndexBitWidth;
398 }
399
400 /// The size in bits of an address in for the given AS. This is defined to
401 /// return the same value as getIndexSizeInBits() since there is currently no
402 /// target that requires these two properties to have different values. See
403 /// getIndexSize() for more information.
404 /// \sa DataLayout::getIndexSizeInBits()
405 unsigned getAddressSizeInBits(unsigned AS) const {
406 return getIndexSizeInBits(AS);
407 }
408
409 /// The pointer representation size in bits for this type. If this function is
410 /// called with a pointer type, then the type size of the pointer is returned.
411 /// If this function is called with a vector of pointers, then the type size
412 /// of the pointer is returned. This should only be called with a pointer or
413 /// vector of pointers.
414 LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const;
415
416 /// The size in bits of the index used in GEP calculation for this type.
417 /// The function should be called with pointer or vector of pointers type.
418 /// This is defined to return the same value as getAddressSizeInBits(),
419 /// but separate functions exist for code clarity.
420 LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const;
421
422 /// The size in bits of an address for this type.
423 /// This is defined to return the same value as getIndexTypeSizeInBits(),
424 /// but separate functions exist for code clarity.
425 unsigned getAddressSizeInBits(Type *Ty) const {
426 return getIndexTypeSizeInBits(Ty);
427 }
428
429 unsigned getPointerTypeSize(Type *Ty) const {
430 return getPointerTypeSizeInBits(Ty) / 8;
431 }
432
433 /// Size examples:
434 ///
435 /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
436 /// ---- ---------- --------------- ---------------
437 /// i1 1 8 8
438 /// i8 8 8 8
439 /// i19 19 24 32
440 /// i32 32 32 32
441 /// i100 100 104 128
442 /// i128 128 128 128
443 /// Float 32 32 32
444 /// Double 64 64 64
445 /// X86_FP80 80 80 96
446 ///
447 /// [*] The alloc size depends on the alignment, and thus on the target.
448 /// These values are for x86-32 linux.
449
450 /// Returns the number of bits necessary to hold the specified type.
451 ///
452 /// If Ty is a scalable vector type, the scalable property will be set and
453 /// the runtime size will be a positive integer multiple of the base size.
454 ///
455 /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
456 /// have a size (Type::isSized() must return true).
458
459 /// Returns the maximum number of bytes that may be overwritten by
460 /// storing the specified type.
461 ///
462 /// If Ty is a scalable vector type, the scalable property will be set and
463 /// the runtime size will be a positive integer multiple of the base size.
464 ///
465 /// For example, returns 5 for i36 and 10 for x86_fp80.
467 TypeSize StoreSizeInBits = getTypeStoreSizeInBits(Ty);
468 return {StoreSizeInBits.getKnownMinValue() / 8,
469 StoreSizeInBits.isScalable()};
470 }
471
472 /// Returns the maximum number of bits that may be overwritten by
473 /// storing the specified type; always a multiple of 8.
474 ///
475 /// If Ty is a scalable vector type, the scalable property will be set and
476 /// the runtime size will be a positive integer multiple of the base size.
477 ///
478 /// For example, returns 40 for i36 and 80 for x86_fp80.
480 TypeSize BaseSize = getTypeSizeInBits(Ty);
481 uint64_t AlignedSizeInBits =
482 alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
483 return {AlignedSizeInBits, BaseSize.isScalable()};
484 }
485
486 /// Returns true if no extra padding bits are needed when storing the
487 /// specified type.
488 ///
489 /// For example, returns false for i19 that has a 24-bit store size.
492 }
493
494 /// Returns the offset in bytes between successive objects of the
495 /// specified type, including alignment padding.
496 ///
497 /// If Ty is a scalable vector type, the scalable property will be set and
498 /// the runtime size will be a positive integer multiple of the base size.
499 ///
500 /// This is the amount that alloca reserves for this type. For example,
501 /// returns 12 or 16 for x86_fp80, depending on alignment.
502 TypeSize getTypeAllocSize(Type *Ty) const;
503
504 /// Returns the offset in bits between successive objects of the
505 /// specified type, including alignment padding; always a multiple of 8.
506 ///
507 /// If Ty is a scalable vector type, the scalable property will be set and
508 /// the runtime size will be a positive integer multiple of the base size.
509 ///
510 /// This is the amount that alloca reserves for this type. For example,
511 /// returns 96 or 128 for x86_fp80, depending on alignment.
513 return 8 * getTypeAllocSize(Ty);
514 }
515
516 /// Returns the minimum ABI-required alignment for the specified type.
518
519 /// Helper function to return `Alignment` if it's set or the result of
520 /// `getABITypeAlign(Ty)`, in any case the result is a valid alignment.
522 Type *Ty) const {
523 return Alignment ? *Alignment : getABITypeAlign(Ty);
524 }
525
526 /// Returns the minimum ABI-required alignment for an integer type of
527 /// the specified bitwidth.
529 return getIntegerAlignment(BitWidth, /* abi_or_pref */ true);
530 }
531
532 /// Returns the preferred stack/global alignment for the specified
533 /// type.
534 ///
535 /// This is always at least as good as the ABI alignment.
537
538 /// Returns an integer type with size at least as big as that of a
539 /// pointer in the given address space.
541 unsigned AddressSpace = 0) const;
542
543 /// Returns an integer (vector of integer) type with size at least as
544 /// big as that of a pointer of the given pointer (vector of pointer) type.
546
547 /// Returns the smallest integer type with size at least as big as
548 /// Width bits.
550 unsigned Width = 0) const;
551
552 /// Returns the largest legal integer type, or null if none are set.
554 unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
555 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
556 }
557
558 /// Returns the size of largest legal integer type size, or 0 if none
559 /// are set.
561
562 /// Returns the type of a GEP index in \p AddressSpace.
563 /// If it was not specified explicitly, it will be the integer type of the
564 /// pointer width - IntPtrType.
566 unsigned AddressSpace) const;
567 /// Returns the type of an address in \p AddressSpace
571
572 /// Returns the type of a GEP index.
573 /// If it was not specified explicitly, it will be the integer type of the
574 /// pointer width - IntPtrType.
575 LLVM_ABI Type *getIndexType(Type *PtrTy) const;
576 /// Returns the type of an address in \p AddressSpace
577 Type *getAddressType(Type *PtrTy) const { return getIndexType(PtrTy); }
578
579 /// Returns the offset from the beginning of the type for the specified
580 /// indices.
581 ///
582 /// Note that this takes the element type, not the pointer type.
583 /// This is used to implement getelementptr.
584 LLVM_ABI int64_t getIndexedOffsetInType(Type *ElemTy,
585 ArrayRef<Value *> Indices) const;
586
587 /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
588 /// the result element type and Offset to be the residual offset.
590 APInt &Offset) const;
591
592 /// Get single GEP index to access Offset inside ElemTy. Returns std::nullopt
593 /// if index cannot be computed, e.g. because the type is not an aggregate.
594 /// ElemTy is updated to be the result element type and Offset to be the
595 /// residual offset.
596 LLVM_ABI std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy,
597 APInt &Offset) const;
598
599 /// Returns a StructLayout object, indicating the alignment of the
600 /// struct, its size, and the offsets of its fields.
601 ///
602 /// Note that this information is lazily cached.
604
605 /// Returns the preferred alignment of the specified global.
606 ///
607 /// This includes an explicitly requested alignment (if the global has one).
609};
610
612 return reinterpret_cast<DataLayout *>(P);
613}
614
616 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
617}
618
619/// Used to lazily calculate structure layout information for a target machine,
620/// based on the DataLayout structure.
621class StructLayout final : private TrailingObjects<StructLayout, TypeSize> {
622 friend TrailingObjects;
623
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 LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const;
643
647
649 return getTrailingObjects(NumElements);
650 }
651
652 TypeSize getElementOffset(unsigned Idx) const {
653 assert(Idx < NumElements && "Invalid element idx!");
654 return getMemberOffsets()[Idx];
655 }
656
657 TypeSize getElementOffsetInBits(unsigned Idx) const {
658 return getElementOffset(Idx) * 8;
659 }
660
661private:
662 friend class DataLayout; // Only DataLayout can create this class
663
664 StructLayout(StructType *ST, const DataLayout &DL);
665};
666
667// The implementation of this method is provided inline as it is particularly
668// well suited to constant folding when called on a specific Type subclass.
670 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
671 switch (Ty->getTypeID()) {
672 case Type::LabelTyID:
675 return TypeSize::getFixed(
676 getPointerSizeInBits(Ty->getPointerAddressSpace()));
677 case Type::ArrayTyID: {
678 ArrayType *ATy = cast<ArrayType>(Ty);
679 return ATy->getNumElements() *
681 }
682 case Type::StructTyID:
683 // Get the layout annotation... which is lazily created on demand.
686 return TypeSize::getFixed(Ty->getIntegerBitWidth());
687 case Type::HalfTyID:
688 case Type::BFloatTyID:
689 return TypeSize::getFixed(16);
690 case Type::FloatTyID:
691 return TypeSize::getFixed(32);
692 case Type::DoubleTyID:
693 return TypeSize::getFixed(64);
695 case Type::FP128TyID:
696 return TypeSize::getFixed(128);
698 return TypeSize::getFixed(8192);
699 // In memory objects this is always aligned to a higher boundary, but
700 // only 80 bits contain information.
702 return TypeSize::getFixed(80);
705 VectorType *VTy = cast<VectorType>(Ty);
706 auto EltCnt = VTy->getElementCount();
707 uint64_t MinBits = EltCnt.getKnownMinValue() *
709 return TypeSize(MinBits, EltCnt.isScalable());
710 }
711 case Type::TargetExtTyID: {
712 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
713 return getTypeSizeInBits(LayoutTy);
714 }
715 default:
716 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
717 }
718}
719
720} // end namespace llvm
721
722#endif // LLVM_IR_DATALAYOUT_H
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
#define LLVM_ABI
Definition Compiler.h:213
const uint64_t BitWidth
#define P(N)
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...
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Class for arbitrary precision integers.
Definition APInt.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
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:247
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition DataLayout.h:490
bool hasLinkerPrivateGlobalPrefix() const
Definition DataLayout.h:262
StringRef getLinkerPrivateGlobalPrefix() const
Definition DataLayout.h:264
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
Definition DataLayout.h:388
bool isNonIntegralPointerType(Type *Ty) const
Definition DataLayout.h:377
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
Definition DataLayout.h:93
@ Independent
The function pointer alignment is independent of the function alignment.
Definition DataLayout.h:91
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:198
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition DataLayout.h:211
Type * getAddressType(Type *PtrTy) const
Returns the type of an address in AddressSpace.
Definition DataLayout.h:577
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:479
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:405
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:220
unsigned getDefaultGlobalsAddressSpace() const
Definition DataLayout.h:248
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition DataLayout.h:243
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition DataLayout.h:528
IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of an address in AddressSpace.
Definition DataLayout.h:568
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition DataLayout.h:258
LLVM_ABI unsigned getIndexSize(unsigned AS) const
The index size in bytes used for address calculation, rounded up to a whole number of bytes.
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.
unsigned getAddressSizeInBits(Type *Ty) const
The size in bits of an address for this type.
Definition DataLayout.h:425
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:429
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition DataLayout.h:369
bool isIllegalInteger(uint64_t Width) const
Definition DataLayout.h:224
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:232
LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const
The pointer representation size in bits for this type.
bool isBigEndian() const
Definition DataLayout.h:199
MaybeAlign getStackAlignment() const
Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.
Definition DataLayout.h:228
unsigned getAllocaAddrSpace() const
Definition DataLayout.h:230
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.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
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:311
bool hasMicrosoftFastStdCallMangling() const
Definition DataLayout.h:252
LLVM_ABI ~DataLayout()
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:373
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:396
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition DataLayout.h:553
StringRef getPrivateGlobalPrefix() const
Definition DataLayout.h:286
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition DataLayout.h:239
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition DataLayout.h:669
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition DataLayout.h:466
bool operator!=(const DataLayout &Other) const
Definition DataLayout.h:191
DataLayout(const DataLayout &DL)
Definition DataLayout.h:184
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition DataLayout.h:512
char getGlobalPrefix() const
Definition DataLayout.h:270
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:206
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:356
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:521
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.
SmallVector< unsigned, 8 > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition DataLayout.h:360
Tagged union holding either a T or a Error.
Definition Error.h:485
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:303
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.
Definition StringRef.h:55
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition DataLayout.h:621
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
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:652
friend class DataLayout
Definition DataLayout.h:662
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.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition Type.h:66
@ ArrayTyID
Arrays.
Definition Type.h:74
@ HalfTyID
16-bit floating point type
Definition Type.h:56
@ TargetExtTyID
Target extension type.
Definition Type.h:78
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition Type.h:76
@ LabelTyID
Labels.
Definition Type.h:64
@ FloatTyID
32-bit floating point type
Definition Type.h:58
@ StructTyID
Structures.
Definition Type.h:73
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:70
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition Type.h:75
@ 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:72
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:61
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:301
LLVM Value Representation.
Definition Value.h:75
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
Definition TypeSize.h:200
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition Target.h:38
#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.
@ Offset
Definition DWP.cpp:477
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Definition MathExtras.h:504
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Other
Any other memory.
Definition ModRef.h:68
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:351
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:346
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1879
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static constexpr Align Constant()
Allow constructions of constexpr Align.
Definition Alignment.h:96
Pointer type specification.
Definition DataLayout.h:75
LLVM_ABI bool operator==(const PointerSpec &Other) const
bool IsNonIntegral
Pointers in this address space don't have a well-defined bitwise representation (e....
Definition DataLayout.h:85
Primitive type specification.
Definition DataLayout.h:66
LLVM_ABI bool operator==(const PrimitiveSpec &Other) const
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:117