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 LLVM_ABI static const char *getManglingComponent(const Triple &T);
307
308 /// Returns true if the specified type fits in a native integer type
309 /// supported by the CPU.
310 ///
311 /// For example, if the CPU only supports i32 as a native integer type, then
312 /// i27 fits in a legal integer type but i45 does not.
313 bool fitsInLegalInteger(unsigned Width) const {
314 for (unsigned LegalIntWidth : LegalIntWidths)
315 if (Width <= LegalIntWidth)
316 return true;
317 return false;
318 }
319
320 /// Layout pointer alignment
321 LLVM_ABI Align getPointerABIAlignment(unsigned AS) const;
322
323 /// Return target's alignment for stack-based pointers
324 /// FIXME: The defaults need to be removed once all of
325 /// the backends/clients are updated.
326 LLVM_ABI Align getPointerPrefAlignment(unsigned AS = 0) const;
327
328 /// The pointer representation size in bytes, rounded up to a whole number of
329 /// bytes. The difference between this function and getAddressSize() is that
330 /// this one returns the size of the entire pointer representation (including
331 /// metadata bits for fat pointers) and the latter only returns the number of
332 /// address bits.
333 /// \sa DataLayout::getAddressSizeInBits
334 /// FIXME: The defaults need to be removed once all of
335 /// the backends/clients are updated.
336 LLVM_ABI unsigned getPointerSize(unsigned AS = 0) const;
337
338 /// The index size in bytes used for address calculation, rounded up to a
339 /// whole number of bytes. This not only defines the size used in
340 /// getelementptr operations, but also the size of addresses in this \p AS.
341 /// For example, a 64-bit CHERI-enabled target has 128-bit pointers of which
342 /// only 64 are used to represent the address and the remaining ones are used
343 /// for metadata such as bounds and access permissions. In this case
344 /// getPointerSize() returns 16, but getIndexSize() returns 8.
345 /// To help with code understanding, the alias getAddressSize() can be used
346 /// instead of getIndexSize() to clarify that an address width is needed.
347 LLVM_ABI unsigned getIndexSize(unsigned AS) const;
348
349 /// The integral size of a pointer in a given address space in bytes, which
350 /// is defined to be the same as getIndexSize(). This exists as a separate
351 /// function to make it clearer when reading code that the size of an address
352 /// is being requested. While targets exist where index size and the
353 /// underlying address width are not identical (e.g. AMDGPU fat pointers with
354 /// 48-bit addresses and 32-bit offsets indexing), there is currently no need
355 /// to differentiate these properties in LLVM.
356 /// \sa DataLayout::getIndexSize
357 /// \sa DataLayout::getAddressSizeInBits
358 unsigned getAddressSize(unsigned AS) const { return getIndexSize(AS); }
359
360 /// Return the address spaces containing non-integral pointers. Pointers in
361 /// this address space don't have a well-defined bitwise representation.
363 SmallVector<unsigned, 8> AddrSpaces;
364 for (const PointerSpec &PS : PointerSpecs) {
365 if (PS.IsNonIntegral)
366 AddrSpaces.push_back(PS.AddrSpace);
367 }
368 return AddrSpaces;
369 }
370
371 bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
372 return getPointerSpec(AddrSpace).IsNonIntegral;
373 }
374
378
380 auto *PTy = dyn_cast<PointerType>(Ty);
381 return PTy && isNonIntegralPointerType(PTy);
382 }
383
384 /// The size in bits of the pointer representation in a given address space.
385 /// This is not necessarily the same as the integer address of a pointer (e.g.
386 /// for fat pointers).
387 /// \sa DataLayout::getAddressSizeInBits()
388 /// FIXME: The defaults need to be removed once all of
389 /// the backends/clients are updated.
390 unsigned getPointerSizeInBits(unsigned AS = 0) const {
391 return getPointerSpec(AS).BitWidth;
392 }
393
394 /// The size in bits of indices used for address calculation in getelementptr
395 /// and for addresses in the given AS. See getIndexSize() for more
396 /// information.
397 /// \sa DataLayout::getAddressSizeInBits()
398 unsigned getIndexSizeInBits(unsigned AS) const {
399 return getPointerSpec(AS).IndexBitWidth;
400 }
401
402 /// The size in bits of an address in for the given AS. This is defined to
403 /// return the same value as getIndexSizeInBits() since there is currently no
404 /// target that requires these two properties to have different values. See
405 /// getIndexSize() for more information.
406 /// \sa DataLayout::getIndexSizeInBits()
407 unsigned getAddressSizeInBits(unsigned AS) const {
408 return getIndexSizeInBits(AS);
409 }
410
411 /// The pointer representation size in bits for this type. If this function is
412 /// called with a pointer type, then the type size of the pointer is returned.
413 /// If this function is called with a vector of pointers, then the type size
414 /// of the pointer is returned. This should only be called with a pointer or
415 /// vector of pointers.
416 LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const;
417
418 /// The size in bits of the index used in GEP calculation for this type.
419 /// The function should be called with pointer or vector of pointers type.
420 /// This is defined to return the same value as getAddressSizeInBits(),
421 /// but separate functions exist for code clarity.
422 LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const;
423
424 /// The size in bits of an address for this type.
425 /// This is defined to return the same value as getIndexTypeSizeInBits(),
426 /// but separate functions exist for code clarity.
427 unsigned getAddressSizeInBits(Type *Ty) const {
428 return getIndexTypeSizeInBits(Ty);
429 }
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 StoreSizeInBits = getTypeStoreSizeInBits(Ty);
470 return {StoreSizeInBits.getKnownMinValue() / 8,
471 StoreSizeInBits.isScalable()};
472 }
473
474 /// Returns the maximum number of bits that may be overwritten by
475 /// storing the specified type; always a multiple of 8.
476 ///
477 /// If Ty is a scalable vector type, the scalable property will be set and
478 /// the runtime size will be a positive integer multiple of the base size.
479 ///
480 /// For example, returns 40 for i36 and 80 for x86_fp80.
482 TypeSize BaseSize = getTypeSizeInBits(Ty);
483 uint64_t AlignedSizeInBits =
484 alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
485 return {AlignedSizeInBits, BaseSize.isScalable()};
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.
504 TypeSize getTypeAllocSize(Type *Ty) const;
505
506 /// Returns the offset in bits between successive objects of the
507 /// specified type, including alignment padding; always a multiple of 8.
508 ///
509 /// If Ty is a scalable vector type, the scalable property will be set and
510 /// the runtime size will be a positive integer multiple of the base size.
511 ///
512 /// This is the amount that alloca reserves for this type. For example,
513 /// returns 96 or 128 for x86_fp80, depending on alignment.
515 return 8 * getTypeAllocSize(Ty);
516 }
517
518 /// Returns the minimum ABI-required alignment for the specified type.
520
521 /// Helper function to return `Alignment` if it's set or the result of
522 /// `getABITypeAlign(Ty)`, in any case the result is a valid alignment.
524 Type *Ty) const {
525 return Alignment ? *Alignment : getABITypeAlign(Ty);
526 }
527
528 /// Returns the minimum ABI-required alignment for an integer type of
529 /// the specified bitwidth.
531 return getIntegerAlignment(BitWidth, /* abi_or_pref */ true);
532 }
533
534 /// Returns the preferred stack/global alignment for the specified
535 /// type.
536 ///
537 /// This is always at least as good as the ABI alignment.
539
540 /// Returns an integer type with size at least as big as that of a
541 /// pointer in the given address space.
543 unsigned AddressSpace = 0) const;
544
545 /// Returns an integer (vector of integer) type with size at least as
546 /// big as that of a pointer of the given pointer (vector of pointer) type.
548
549 /// Returns the smallest integer type with size at least as big as
550 /// Width bits.
552 unsigned Width = 0) const;
553
554 /// Returns the largest legal integer type, or null if none are set.
556 unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
557 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
558 }
559
560 /// Returns the size of largest legal integer type size, or 0 if none
561 /// are set.
563
564 /// Returns the type of a GEP index in \p AddressSpace.
565 /// If it was not specified explicitly, it will be the integer type of the
566 /// pointer width - IntPtrType.
568 unsigned AddressSpace) const;
569 /// Returns the type of an address in \p AddressSpace
573
574 /// Returns the type of a GEP index.
575 /// If it was not specified explicitly, it will be the integer type of the
576 /// pointer width - IntPtrType.
577 LLVM_ABI Type *getIndexType(Type *PtrTy) const;
578 /// Returns the type of an address in \p AddressSpace
579 Type *getAddressType(Type *PtrTy) const { return getIndexType(PtrTy); }
580
581 /// Returns the offset from the beginning of the type for the specified
582 /// indices.
583 ///
584 /// Note that this takes the element type, not the pointer type.
585 /// This is used to implement getelementptr.
586 LLVM_ABI int64_t getIndexedOffsetInType(Type *ElemTy,
587 ArrayRef<Value *> Indices) const;
588
589 /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
590 /// the result element type and Offset to be the residual offset.
592 APInt &Offset) const;
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 LLVM_ABI std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy,
599 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.
606
607 /// Returns the preferred alignment of the specified global.
608 ///
609 /// This includes an explicitly requested alignment (if the global has one).
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 : private TrailingObjects<StructLayout, TypeSize> {
624 friend TrailingObjects;
625
626 TypeSize StructSize;
627 Align StructAlignment;
628 unsigned IsPadded : 1;
629 unsigned NumElements : 31;
630
631public:
632 TypeSize getSizeInBytes() const { return StructSize; }
633
634 TypeSize getSizeInBits() const { return 8 * StructSize; }
635
636 Align getAlignment() const { return StructAlignment; }
637
638 /// Returns whether the struct has padding or not between its fields.
639 /// NB: Padding in nested element is not taken into account.
640 bool hasPadding() const { return IsPadded; }
641
642 /// Given a valid byte offset into the structure, returns the structure
643 /// index that contains it.
644 LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const;
645
649
651 return getTrailingObjects(NumElements);
652 }
653
654 TypeSize getElementOffset(unsigned Idx) const {
655 assert(Idx < NumElements && "Invalid element idx!");
656 return getMemberOffsets()[Idx];
657 }
658
659 TypeSize getElementOffsetInBits(unsigned Idx) const {
660 return getElementOffset(Idx) * 8;
661 }
662
663private:
664 friend class DataLayout; // Only DataLayout can create this class
665
666 StructLayout(StructType *ST, const DataLayout &DL);
667};
668
669// The implementation of this method is provided inline as it is particularly
670// well suited to constant folding when called on a specific Type subclass.
672 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
673 switch (Ty->getTypeID()) {
674 case Type::LabelTyID:
677 return TypeSize::getFixed(
678 getPointerSizeInBits(Ty->getPointerAddressSpace()));
679 case Type::ArrayTyID: {
680 ArrayType *ATy = cast<ArrayType>(Ty);
681 return ATy->getNumElements() *
683 }
684 case Type::StructTyID:
685 // Get the layout annotation... which is lazily created on demand.
688 return TypeSize::getFixed(Ty->getIntegerBitWidth());
689 case Type::HalfTyID:
690 case Type::BFloatTyID:
691 return TypeSize::getFixed(16);
692 case Type::FloatTyID:
693 return TypeSize::getFixed(32);
694 case Type::DoubleTyID:
695 return TypeSize::getFixed(64);
697 case Type::FP128TyID:
698 return TypeSize::getFixed(128);
700 return TypeSize::getFixed(8192);
701 // In memory objects this is always aligned to a higher boundary, but
702 // only 80 bits contain information.
704 return TypeSize::getFixed(80);
707 VectorType *VTy = cast<VectorType>(Ty);
708 auto EltCnt = VTy->getElementCount();
709 uint64_t MinBits = EltCnt.getKnownMinValue() *
711 return TypeSize(MinBits, EltCnt.isScalable());
712 }
713 case Type::TargetExtTyID: {
714 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
715 return getTypeSizeInBits(LayoutTy);
716 }
717 default:
718 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
719 }
720}
721
722} // end namespace llvm
723
724#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
#define T
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:492
bool hasLinkerPrivateGlobalPrefix() const
Definition DataLayout.h:262
static LLVM_ABI const char * getManglingComponent(const Triple &T)
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:390
bool isNonIntegralPointerType(Type *Ty) const
Definition DataLayout.h:379
@ 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:579
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:481
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:407
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:530
IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of an address in AddressSpace.
Definition DataLayout.h:570
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:427
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:431
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:371
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:313
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:375
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:398
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition DataLayout.h:555
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:671
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: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:514
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:358
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:523
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:362
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:623
TypeSize getSizeInBytes() const
Definition DataLayout.h:632
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition DataLayout.h:640
MutableArrayRef< TypeSize > getMemberOffsets()
Definition DataLayout.h:646
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:654
friend class DataLayout
Definition DataLayout.h:664
ArrayRef< TypeSize > getMemberOffsets() const
Definition DataLayout.h:650
TypeSize getSizeInBits() const
Definition DataLayout.h:634
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition DataLayout.h:659
Align getAlignment() const
Definition DataLayout.h:636
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:498
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:1899
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