LLVM 20.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.
70
71 bool operator==(const PrimitiveSpec &Other) const;
72 };
73
74 /// Pointer type specification.
75 struct PointerSpec {
81
82 bool operator==(const PointerSpec &Other) const;
83 };
84
86 /// The function pointer alignment is independent of the function alignment.
88 /// The function pointer alignment is a multiple of the function alignment.
90 };
91private:
92 bool BigEndian = false;
93
94 unsigned AllocaAddrSpace = 0;
95 unsigned ProgramAddrSpace = 0;
96 unsigned DefaultGlobalsAddrSpace = 0;
97
98 MaybeAlign StackNaturalAlign;
99 MaybeAlign FunctionPtrAlign;
100 FunctionPtrAlignType TheFunctionPtrAlignType =
102
103 enum ManglingModeT {
104 MM_None,
105 MM_ELF,
106 MM_MachO,
107 MM_WinCOFF,
108 MM_WinCOFFX86,
109 MM_GOFF,
110 MM_Mips,
111 MM_XCOFF
112 };
113 ManglingModeT ManglingMode = MM_None;
114
115 // FIXME: `unsigned char` truncates the value parsed by `parseSpecifier`.
116 SmallVector<unsigned char, 8> LegalIntWidths;
117
118 /// Primitive type specifications. Sorted and uniqued by type bit width.
119 SmallVector<PrimitiveSpec, 6> IntSpecs;
120 SmallVector<PrimitiveSpec, 4> FloatSpecs;
121 SmallVector<PrimitiveSpec, 10> VectorSpecs;
122
123 /// Pointer type specifications. Sorted and uniqued by address space number.
124 SmallVector<PointerSpec, 8> PointerSpecs;
125
126 /// The string representation used to create this DataLayout
127 std::string StringRepresentation;
128
129 /// Struct type ABI and preferred alignments. The default spec is "a:8:64".
130 Align StructABIAlignment = Align::Constant<1>();
131 Align StructPrefAlignment = Align::Constant<8>();
132
133 // The StructType -> StructLayout map.
134 mutable void *LayoutMap = nullptr;
135
136 /// Pointers in these address spaces are non-integral, and don't have a
137 /// well-defined bitwise representation.
138 SmallVector<unsigned, 8> NonIntegralAddressSpaces;
139
140 /// Sets or updates the specification for the given primitive type.
141 void setPrimitiveSpec(char Specifier, uint32_t BitWidth, Align ABIAlign,
142 Align PrefAlign);
143
144 /// Searches for a pointer specification that matches the given address space.
145 /// Returns the default address space specification if not found.
146 const PointerSpec &getPointerSpec(uint32_t AddrSpace) const;
147
148 /// Sets or updates the specification for pointer in the given address space.
149 void setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth, Align ABIAlign,
150 Align PrefAlign, uint32_t IndexBitWidth);
151
152 /// Internal helper to get alignment for integer of given bitwidth.
153 Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const;
154
155 /// Internal helper method that returns requested alignment for type.
156 Align getAlignment(Type *Ty, bool abi_or_pref) const;
157
158 /// Attempts to parse primitive specification ('i', 'f', or 'v').
159 Error parsePrimitiveSpec(StringRef Spec);
160
161 /// Attempts to parse aggregate specification ('a').
162 Error parseAggregateSpec(StringRef Spec);
163
164 /// Attempts to parse pointer specification ('p').
165 Error parsePointerSpec(StringRef Spec);
166
167 /// Attempts to parse a single specification.
168 Error parseSpecification(StringRef Spec);
169
170 /// Attempts to parse a data layout string.
171 Error parseLayoutString(StringRef LayoutString);
172
173public:
174 /// Constructs a DataLayout with default values.
175 DataLayout();
176
177 /// Constructs a DataLayout from a specification string.
178 /// WARNING: Aborts execution if the string is malformed. Use parse() instead.
179 explicit DataLayout(StringRef LayoutString);
180
181 DataLayout(const DataLayout &DL) { *this = DL; }
182
183 ~DataLayout(); // Not virtual, do not subclass this class
184
186
187 bool operator==(const DataLayout &Other) const;
188 bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
189
190 /// Parse a data layout string and return the layout. Return an error
191 /// description on failure.
192 static Expected<DataLayout> parse(StringRef LayoutString);
193
194 /// Layout endianness...
195 bool isLittleEndian() const { return !BigEndian; }
196 bool isBigEndian() const { return BigEndian; }
197
198 /// Returns the string representation of the DataLayout.
199 ///
200 /// This representation is in the same format accepted by the string
201 /// constructor above. This should not be used to compare two DataLayout as
202 /// different string can represent the same layout.
203 const std::string &getStringRepresentation() const {
204 return StringRepresentation;
205 }
206
207 /// Test if the DataLayout was constructed from an empty string.
208 bool isDefault() const { return StringRepresentation.empty(); }
209
210 /// Returns true if the specified type is known to be a native integer
211 /// type supported by the CPU.
212 ///
213 /// For example, i64 is not native on most 32-bit CPUs and i37 is not native
214 /// on any known one. This returns false if the integer width is not legal.
215 ///
216 /// The width is specified in bits.
217 bool isLegalInteger(uint64_t Width) const {
218 return llvm::is_contained(LegalIntWidths, Width);
219 }
220
221 bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
222
223 /// Returns true if the given alignment exceeds the natural stack alignment.
224 bool exceedsNaturalStackAlignment(Align Alignment) const {
225 return StackNaturalAlign && (Alignment > *StackNaturalAlign);
226 }
227
229 assert(StackNaturalAlign && "StackNaturalAlign must be defined");
230 return *StackNaturalAlign;
231 }
232
233 unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
234
236 return PointerType::get(Ctx, AllocaAddrSpace);
237 }
238
239 /// Returns the alignment of function pointers, which may or may not be
240 /// related to the alignment of functions.
241 /// \see getFunctionPtrAlignType
242 MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
243
244 /// Return the type of function pointer alignment.
245 /// \see getFunctionPtrAlign
247 return TheFunctionPtrAlignType;
248 }
249
250 unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
252 return DefaultGlobalsAddrSpace;
253 }
254
256 return ManglingMode == MM_WinCOFFX86;
257 }
258
259 /// Returns true if symbols with leading question marks should not receive IR
260 /// mangling. True for Windows mangling modes.
262 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
263 }
264
265 bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
266
268 if (ManglingMode == MM_MachO)
269 return "l";
270 return "";
271 }
272
273 char getGlobalPrefix() const {
274 switch (ManglingMode) {
275 case MM_None:
276 case MM_ELF:
277 case MM_GOFF:
278 case MM_Mips:
279 case MM_WinCOFF:
280 case MM_XCOFF:
281 return '\0';
282 case MM_MachO:
283 case MM_WinCOFFX86:
284 return '_';
285 }
286 llvm_unreachable("invalid mangling mode");
287 }
288
290 switch (ManglingMode) {
291 case MM_None:
292 return "";
293 case MM_ELF:
294 case MM_WinCOFF:
295 return ".L";
296 case MM_GOFF:
297 return "L#";
298 case MM_Mips:
299 return "$";
300 case MM_MachO:
301 case MM_WinCOFFX86:
302 return "L";
303 case MM_XCOFF:
304 return "L..";
305 }
306 llvm_unreachable("invalid mangling mode");
307 }
308
309 static const char *getManglingComponent(const Triple &T);
310
311 /// Returns true if the specified type fits in a native integer type
312 /// supported by the CPU.
313 ///
314 /// For example, if the CPU only supports i32 as a native integer type, then
315 /// i27 fits in a legal integer type but i45 does not.
316 bool fitsInLegalInteger(unsigned Width) const {
317 for (unsigned LegalIntWidth : LegalIntWidths)
318 if (Width <= LegalIntWidth)
319 return true;
320 return false;
321 }
322
323 /// Layout pointer alignment
324 Align getPointerABIAlignment(unsigned AS) const;
325
326 /// Return target's alignment for stack-based pointers
327 /// FIXME: The defaults need to be removed once all of
328 /// the backends/clients are updated.
329 Align getPointerPrefAlignment(unsigned AS = 0) const;
330
331 /// Layout pointer size in bytes, rounded up to a whole
332 /// number of bytes.
333 /// FIXME: The defaults need to be removed once all of
334 /// the backends/clients are updated.
335 unsigned getPointerSize(unsigned AS = 0) const;
336
337 /// Returns the maximum index size over all address spaces.
338 unsigned getMaxIndexSize() const;
339
340 // Index size in bytes used for address calculation,
341 /// rounded up to a whole number of bytes.
342 unsigned getIndexSize(unsigned AS) const;
343
344 /// Return the address spaces containing non-integral pointers. Pointers in
345 /// this address space don't have a well-defined bitwise representation.
347 return NonIntegralAddressSpaces;
348 }
349
350 bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
352 return is_contained(NonIntegralSpaces, AddrSpace);
353 }
354
357 }
358
360 auto *PTy = dyn_cast<PointerType>(Ty);
361 return PTy && isNonIntegralPointerType(PTy);
362 }
363
364 /// Layout pointer size, in bits
365 /// FIXME: The defaults need to be removed once all of
366 /// the backends/clients are updated.
367 unsigned getPointerSizeInBits(unsigned AS = 0) const {
368 return getPointerSpec(AS).BitWidth;
369 }
370
371 /// Returns the maximum index size over all address spaces.
372 unsigned getMaxIndexSizeInBits() const {
373 return getMaxIndexSize() * 8;
374 }
375
376 /// Size in bits of index used for address calculation in getelementptr.
377 unsigned getIndexSizeInBits(unsigned AS) const {
378 return getPointerSpec(AS).IndexBitWidth;
379 }
380
381 /// Layout pointer size, in bits, based on the type. If this function is
382 /// called with a pointer type, then the type size of the pointer is returned.
383 /// If this function is called with a vector of pointers, then the type size
384 /// of the pointer is returned. This should only be called with a pointer or
385 /// vector of pointers.
386 unsigned getPointerTypeSizeInBits(Type *) const;
387
388 /// Layout size of the index used in GEP calculation.
389 /// The function should be called with pointer or vector of pointers type.
390 unsigned getIndexTypeSizeInBits(Type *Ty) const;
391
392 unsigned getPointerTypeSize(Type *Ty) const {
393 return getPointerTypeSizeInBits(Ty) / 8;
394 }
395
396 /// Size examples:
397 ///
398 /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
399 /// ---- ---------- --------------- ---------------
400 /// i1 1 8 8
401 /// i8 8 8 8
402 /// i19 19 24 32
403 /// i32 32 32 32
404 /// i100 100 104 128
405 /// i128 128 128 128
406 /// Float 32 32 32
407 /// Double 64 64 64
408 /// X86_FP80 80 80 96
409 ///
410 /// [*] The alloc size depends on the alignment, and thus on the target.
411 /// These values are for x86-32 linux.
412
413 /// Returns the number of bits necessary to hold the specified type.
414 ///
415 /// If Ty is a scalable vector type, the scalable property will be set and
416 /// the runtime size will be a positive integer multiple of the base size.
417 ///
418 /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
419 /// have a size (Type::isSized() must return true).
421
422 /// Returns the maximum number of bytes that may be overwritten by
423 /// storing the specified type.
424 ///
425 /// If Ty is a scalable vector type, the scalable property will be set and
426 /// the runtime size will be a positive integer multiple of the base size.
427 ///
428 /// For example, returns 5 for i36 and 10 for x86_fp80.
430 TypeSize BaseSize = getTypeSizeInBits(Ty);
431 return {divideCeil(BaseSize.getKnownMinValue(), 8), BaseSize.isScalable()};
432 }
433
434 /// Returns the maximum number of bits that may be overwritten by
435 /// storing the specified type; always a multiple of 8.
436 ///
437 /// If Ty is a scalable vector type, the scalable property will be set and
438 /// the runtime size will be a positive integer multiple of the base size.
439 ///
440 /// For example, returns 40 for i36 and 80 for x86_fp80.
442 return 8 * getTypeStoreSize(Ty);
443 }
444
445 /// Returns true if no extra padding bits are needed when storing the
446 /// specified type.
447 ///
448 /// For example, returns false for i19 that has a 24-bit store size.
451 }
452
453 /// Returns the offset in bytes between successive objects of the
454 /// specified type, including alignment padding.
455 ///
456 /// If Ty is a scalable vector type, the scalable property will be set and
457 /// the runtime size will be a positive integer multiple of the base size.
458 ///
459 /// This is the amount that alloca reserves for this type. For example,
460 /// returns 12 or 16 for x86_fp80, depending on alignment.
462 // Round up to the next alignment boundary.
464 }
465
466 /// Returns the offset in bits between successive objects of the
467 /// specified type, including alignment padding; always a multiple of 8.
468 ///
469 /// If Ty is a scalable vector type, the scalable property will be set and
470 /// the runtime size will be a positive integer multiple of the base size.
471 ///
472 /// This is the amount that alloca reserves for this type. For example,
473 /// returns 96 or 128 for x86_fp80, depending on alignment.
475 return 8 * getTypeAllocSize(Ty);
476 }
477
478 /// Returns the minimum ABI-required alignment for the specified type.
479 Align getABITypeAlign(Type *Ty) const;
480
481 /// Helper function to return `Alignment` if it's set or the result of
482 /// `getABITypeAlign(Ty)`, in any case the result is a valid alignment.
484 Type *Ty) const {
485 return Alignment ? *Alignment : getABITypeAlign(Ty);
486 }
487
488 /// Returns the minimum ABI-required alignment for an integer type of
489 /// the specified bitwidth.
491 return getIntegerAlignment(BitWidth, /* abi_or_pref */ true);
492 }
493
494 /// Returns the preferred stack/global alignment for the specified
495 /// type.
496 ///
497 /// This is always at least as good as the ABI alignment.
498 Align getPrefTypeAlign(Type *Ty) const;
499
500 /// Returns an integer type with size at least as big as that of a
501 /// pointer in the given address space.
502 IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const;
503
504 /// Returns an integer (vector of integer) type with size at least as
505 /// big as that of a pointer of the given pointer (vector of pointer) type.
506 Type *getIntPtrType(Type *) const;
507
508 /// Returns the smallest integer type with size at least as big as
509 /// Width bits.
510 Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const;
511
512 /// Returns the largest legal integer type, or null if none are set.
514 unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
515 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
516 }
517
518 /// Returns the size of largest legal integer type size, or 0 if none
519 /// are set.
520 unsigned getLargestLegalIntTypeSizeInBits() const;
521
522 /// Returns the type of a GEP index in AddressSpace.
523 /// If it was not specified explicitly, it will be the integer type of the
524 /// pointer width - IntPtrType.
526
527 /// Returns the type of a GEP index.
528 /// If it was not specified explicitly, it will be the integer type of the
529 /// pointer width - IntPtrType.
530 Type *getIndexType(Type *PtrTy) const;
531
532 /// Returns the offset from the beginning of the type for the specified
533 /// indices.
534 ///
535 /// Note that this takes the element type, not the pointer type.
536 /// This is used to implement getelementptr.
537 int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
538
539 /// Get GEP indices to access Offset inside ElemTy. ElemTy is updated to be
540 /// the result element type and Offset to be the residual offset.
542
543 /// Get single GEP index to access Offset inside ElemTy. Returns std::nullopt
544 /// if index cannot be computed, e.g. because the type is not an aggregate.
545 /// ElemTy is updated to be the result element type and Offset to be the
546 /// residual offset.
547 std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const;
548
549 /// Returns a StructLayout object, indicating the alignment of the
550 /// struct, its size, and the offsets of its fields.
551 ///
552 /// Note that this information is lazily cached.
553 const StructLayout *getStructLayout(StructType *Ty) const;
554
555 /// Returns the preferred alignment of the specified global.
556 ///
557 /// This includes an explicitly requested alignment (if the global has one).
558 Align getPreferredAlign(const GlobalVariable *GV) const;
559};
560
562 return reinterpret_cast<DataLayout *>(P);
563}
564
566 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
567}
568
569/// Used to lazily calculate structure layout information for a target machine,
570/// based on the DataLayout structure.
571class StructLayout final : public TrailingObjects<StructLayout, TypeSize> {
572 TypeSize StructSize;
573 Align StructAlignment;
574 unsigned IsPadded : 1;
575 unsigned NumElements : 31;
576
577public:
578 TypeSize getSizeInBytes() const { return StructSize; }
579
580 TypeSize getSizeInBits() const { return 8 * StructSize; }
581
582 Align getAlignment() const { return StructAlignment; }
583
584 /// Returns whether the struct has padding or not between its fields.
585 /// NB: Padding in nested element is not taken into account.
586 bool hasPadding() const { return IsPadded; }
587
588 /// Given a valid byte offset into the structure, returns the structure
589 /// index that contains it.
590 unsigned getElementContainingOffset(uint64_t FixedOffset) const;
591
593 return llvm::MutableArrayRef(getTrailingObjects<TypeSize>(), NumElements);
594 }
595
597 return llvm::ArrayRef(getTrailingObjects<TypeSize>(), NumElements);
598 }
599
600 TypeSize getElementOffset(unsigned Idx) const {
601 assert(Idx < NumElements && "Invalid element idx!");
602 return getMemberOffsets()[Idx];
603 }
604
606 return getElementOffset(Idx) * 8;
607 }
608
609private:
610 friend class DataLayout; // Only DataLayout can create this class
611
613
614 size_t numTrailingObjects(OverloadToken<TypeSize>) const {
615 return NumElements;
616 }
617};
618
619// The implementation of this method is provided inline as it is particularly
620// well suited to constant folding when called on a specific Type subclass.
622 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
623 switch (Ty->getTypeID()) {
624 case Type::LabelTyID:
627 return TypeSize::getFixed(
629 case Type::ArrayTyID: {
630 ArrayType *ATy = cast<ArrayType>(Ty);
631 return ATy->getNumElements() *
633 }
634 case Type::StructTyID:
635 // Get the layout annotation... which is lazily created on demand.
636 return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
639 case Type::HalfTyID:
640 case Type::BFloatTyID:
641 return TypeSize::getFixed(16);
642 case Type::FloatTyID:
643 return TypeSize::getFixed(32);
644 case Type::DoubleTyID:
645 return TypeSize::getFixed(64);
647 case Type::FP128TyID:
648 return TypeSize::getFixed(128);
650 return TypeSize::getFixed(8192);
651 // In memory objects this is always aligned to a higher boundary, but
652 // only 80 bits contain information.
654 return TypeSize::getFixed(80);
657 VectorType *VTy = cast<VectorType>(Ty);
658 auto EltCnt = VTy->getElementCount();
659 uint64_t MinBits = EltCnt.getKnownMinValue() *
661 return TypeSize(MinBits, EltCnt.isScalable());
662 }
663 case Type::TargetExtTyID: {
664 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
665 return getTypeSizeInBits(LayoutTy);
666 }
667 default:
668 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
669 }
670}
671
672} // end namespace llvm
673
674#endif // LLVM_IR_DATALAYOUT_H
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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
#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: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.
Definition: DerivedTypes.h:371
uint64_t getNumElements() const
Definition: DerivedTypes.h:383
Type * getElementType() const
Definition: DerivedTypes.h:384
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:250
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition: DataLayout.h:449
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:265
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:175
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:267
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:367
unsigned getMaxIndexSize() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.cpp:729
bool isNonIntegralPointerType(Type *Ty) const
Definition: DataLayout.h:359
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
@ Independent
The function pointer alignment is independent of the function alignment.
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
Definition: DataLayout.cpp:966
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:195
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition: DataLayout.h:208
unsigned getMaxIndexSizeInBits() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.h:372
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:441
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:868
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:217
unsigned getDefaultGlobalsAddressSpace() const
Definition: DataLayout.h:251
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition: DataLayout.h:246
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.h:490
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition: DataLayout.h:261
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
Definition: DataLayout.cpp:745
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:695
DataLayout()
Constructs a DataLayout with default values.
Definition: DataLayout.cpp:212
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:846
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:392
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:838
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition: DataLayout.h:350
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition: DataLayout.h:346
bool isIllegalInteger(uint64_t Width) const
Definition: DataLayout.h:221
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Definition: DataLayout.cpp:749
PointerType * getAllocaPtrType(LLVMContext &Ctx) const
Definition: DataLayout.h:235
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:738
bool exceedsNaturalStackAlignment(Align Alignment) const
Returns true if the given alignment exceeds the natural stack alignment.
Definition: DataLayout.h:224
bool isBigEndian() const
Definition: DataLayout.h:196
Align getStackAlignment() const
Definition: DataLayout.h:228
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:233
DataLayout & operator=(const DataLayout &Other)
Definition: DataLayout.cpp:223
IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
Definition: DataLayout.cpp:873
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:461
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition: DataLayout.cpp:936
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:861
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:983
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU.
Definition: DataLayout.h:316
bool hasMicrosoftFastStdCallMangling() const
Definition: DataLayout.h:255
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:725
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:355
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:721
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition: DataLayout.h:377
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition: DataLayout.h:513
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:289
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition: DataLayout.h:242
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:621
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:429
bool operator!=(const DataLayout &Other) const
Definition: DataLayout.h:188
DataLayout(const DataLayout &DL)
Definition: DataLayout.h:181
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:474
char getGlobalPrefix() const
Definition: DataLayout.h:273
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:888
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:203
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:483
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:717
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:842
Tagged union holding either a T or a Error.
Definition: Error.h:481
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
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
Class to represent pointers.
Definition: DerivedTypes.h:646
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:679
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:571
TypeSize getSizeInBytes() const
Definition: DataLayout.h:578
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition: DataLayout.h:586
MutableArrayRef< TypeSize > getMemberOffsets()
Definition: DataLayout.h:592
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:600
ArrayRef< TypeSize > getMemberOffsets() const
Definition: DataLayout.h:596
TypeSize getSizeInBits() const
Definition: DataLayout.h:580
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition: DataLayout.h:605
Align getAlignment() const
Definition: DataLayout.h:582
Class to represent struct types.
Definition: DerivedTypes.h:216
See the file comment for details on the usage of the TrailingObjects type.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:345
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_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 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:298
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:641
Type * getElementType() const
Definition: DerivedTypes.h:436
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:202
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:37
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
AddressSpace
Definition: NVPTXBaseInfo.h:21
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:403
@ Other
Any other memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:320
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:315
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1886
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Pointer type specification.
Definition: DataLayout.h:75
bool operator==(const PointerSpec &Other) const
Definition: DataLayout.cpp:151
Primitive type specification.
Definition: DataLayout.h:66
bool operator==(const PrimitiveSpec &Other) const
Definition: DataLayout.cpp:146
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Definition: regcomp.c:192