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