Movatterモバイル変換


[0]ホーム

URL:


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"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/IR/DerivedTypes.h"
28#include "llvm/IR/Type.h"
29#include "llvm/Support/Alignment.h"
30#include "llvm/Support/Casting.h"
31#include "llvm/Support/Compiler.h"
32#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/MathExtras.h"
34#include "llvm/Support/TrailingObjects.h"
35#include "llvm/Support/TypeSize.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.
42usingLLVMTargetDataRef =structLLVMOpaqueTargetData *;
43
44namespacellvm {
45
46classGlobalVariable;
47classLLVMContext;
48classStructLayout;
49classTriple;
50classValue;
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.
63classDataLayout {
64public:
65 /// Primitive type specification.
66structPrimitiveSpec {
67uint32_tBitWidth;
68AlignABIAlign;
69AlignPrefAlign;
70
71booloperator==(constPrimitiveSpec &Other)const;
72 };
73
74 /// Pointer type specification.
75structPointerSpec {
76uint32_tAddrSpace;
77uint32_tBitWidth;
78AlignABIAlign;
79AlignPrefAlign;
80uint32_tIndexBitWidth;
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).
85boolIsNonIntegral;
86booloperator==(constPointerSpec &Other)const;
87 };
88
89enum classFunctionPtrAlignType {
90 /// The function pointer alignment is independent of the function alignment.
91Independent,
92 /// The function pointer alignment is a multiple of the function alignment.
93MultipleOfFunctionAlign,
94 };
95private:
96bool BigEndian =false;
97
98unsigned AllocaAddrSpace = 0;
99unsigned ProgramAddrSpace = 0;
100unsigned DefaultGlobalsAddrSpace = 0;
101
102MaybeAlign StackNaturalAlign;
103MaybeAlign FunctionPtrAlign;
104FunctionPtrAlignType TheFunctionPtrAlignType =
105FunctionPtrAlignType::Independent;
106
107enum 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.
138mutablevoid *LayoutMap =nullptr;
139
140 /// Sets or updates the specification for the given primitive type.
141void setPrimitiveSpec(char Specifier,uint32_tBitWidth, 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.
146const PointerSpec &getPointerSpec(uint32_t AddrSpace)const;
147
148 /// Sets or updates the specification for pointer in the given address space.
149void setPointerSpec(uint32_t AddrSpace,uint32_tBitWidth, Align ABIAlign,
150 Align PrefAlign,uint32_t IndexBitWidth,
151bool IsNonIntegral);
152
153 /// Internal helper to get alignment for integer of given bitwidth.
154 Align getIntegerAlignment(uint32_tBitWidth,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.
177DataLayout();
178
179 /// Constructs a DataLayout from a specification string.
180 /// WARNING: Aborts execution if the string is malformed. Use parse() instead.
181explicitDataLayout(StringRef LayoutString);
182
183DataLayout(constDataLayout &DL) { *this =DL; }
184
185~DataLayout();// Not virtual, do not subclass this class
186
187DataLayout &operator=(constDataLayout &Other);
188
189bool operator==(constDataLayout &Other)const;
190booloperator!=(constDataLayout &Other) const{return !(*this ==Other); }
191
192 /// Parse a data layout string and return the layout. Return an error
193 /// description on failure.
194staticExpected<DataLayout>parse(StringRef LayoutString);
195
196 /// Layout endianness...
197boolisLittleEndian() const{return !BigEndian; }
198boolisBigEndian() 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.
205const std::string &getStringRepresentation() const{
206return StringRepresentation;
207 }
208
209 /// Test if the DataLayout was constructed from an empty string.
210boolisDefault() 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.
219boolisLegalInteger(uint64_t Width) const{
220returnllvm::is_contained(LegalIntWidths, Width);
221 }
222
223boolisIllegalInteger(uint64_t Width) const{return !isLegalInteger(Width); }
224
225 /// Returns the natural stack alignment, or MaybeAlign() if one wasn't
226 /// specified.
227MaybeAligngetStackAlignment() const{return StackNaturalAlign; }
228
229unsignedgetAllocaAddrSpace() const{return AllocaAddrSpace; }
230
231PointerType *getAllocaPtrType(LLVMContext &Ctx) const{
232returnPointerType::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
238MaybeAligngetFunctionPtrAlign() const{return FunctionPtrAlign; }
239
240 /// Return the type of function pointer alignment.
241 /// \see getFunctionPtrAlign
242FunctionPtrAlignTypegetFunctionPtrAlignType() const{
243return TheFunctionPtrAlignType;
244 }
245
246unsignedgetProgramAddressSpace() const{return ProgramAddrSpace; }
247unsignedgetDefaultGlobalsAddressSpace() const{
248return DefaultGlobalsAddrSpace;
249 }
250
251boolhasMicrosoftFastStdCallMangling() const{
252return 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.
257booldoNotMangleLeadingQuestionMark() const{
258return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
259 }
260
261boolhasLinkerPrivateGlobalPrefix() const{return ManglingMode == MM_MachO; }
262
263StringRefgetLinkerPrivateGlobalPrefix() const{
264if (ManglingMode == MM_MachO)
265return"l";
266return"";
267 }
268
269chargetGlobalPrefix() const{
270switch (ManglingMode) {
271case MM_None:
272case MM_ELF:
273case MM_GOFF:
274case MM_Mips:
275case MM_WinCOFF:
276case MM_XCOFF:
277return'\0';
278case MM_MachO:
279case MM_WinCOFFX86:
280return'_';
281 }
282llvm_unreachable("invalid mangling mode");
283 }
284
285StringRefgetPrivateGlobalPrefix() const{
286switch (ManglingMode) {
287case MM_None:
288return"";
289case MM_ELF:
290case MM_WinCOFF:
291return".L";
292case MM_GOFF:
293return"L#";
294case MM_Mips:
295return"$";
296case MM_MachO:
297case MM_WinCOFFX86:
298return"L";
299case MM_XCOFF:
300return"L..";
301 }
302llvm_unreachable("invalid mangling mode");
303 }
304
305staticconstchar *getManglingComponent(constTriple &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.
312boolfitsInLegalInteger(unsigned Width) const{
313for (unsigned LegalIntWidth : LegalIntWidths)
314if (Width <= LegalIntWidth)
315returntrue;
316returnfalse;
317 }
318
319 /// Layout pointer alignment
320AligngetPointerABIAlignment(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.
325AligngetPointerPrefAlignment(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.
331unsignedgetPointerSize(unsigned AS = 0)const;
332
333// Index size in bytes used for address calculation,
334 /// rounded up to a whole number of bytes.
335unsignedgetIndexSize(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.
339SmallVector<unsigned, 8>getNonIntegralAddressSpaces() const{
340SmallVector<unsigned, 8> AddrSpaces;
341for (constPointerSpec &PS : PointerSpecs) {
342if (PS.IsNonIntegral)
343 AddrSpaces.push_back(PS.AddrSpace);
344 }
345return AddrSpaces;
346 }
347
348boolisNonIntegralAddressSpace(unsigned AddrSpace) const{
349return getPointerSpec(AddrSpace).IsNonIntegral;
350 }
351
352boolisNonIntegralPointerType(PointerType *PT) const{
353returnisNonIntegralAddressSpace(PT->getAddressSpace());
354 }
355
356boolisNonIntegralPointerType(Type *Ty) const{
357auto *PTy = dyn_cast<PointerType>(Ty);
358return 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.
364unsignedgetPointerSizeInBits(unsigned AS = 0) const{
365return getPointerSpec(AS).BitWidth;
366 }
367
368 /// Size in bits of index used for address calculation in getelementptr.
369unsignedgetIndexSizeInBits(unsigned AS) const{
370return 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.
378unsignedgetPointerTypeSizeInBits(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.
382unsignedgetIndexTypeSizeInBits(Type *Ty)const;
383
384unsignedgetPointerTypeSize(Type *Ty) const{
385returngetPointerTypeSizeInBits(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).
412TypeSizegetTypeSizeInBits(Type *Ty)const;
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.
421TypeSizegetTypeStoreSize(Type *Ty) const{
422TypeSize StoreSizeInBits =getTypeStoreSizeInBits(Ty);
423return {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.
434TypeSizegetTypeStoreSizeInBits(Type *Ty) const{
435TypeSize BaseSize =getTypeSizeInBits(Ty);
436uint64_t AlignedSizeInBits =
437alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
438return {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.
445booltypeSizeEqualsStoreSize(Type *Ty) const{
446returngetTypeSizeInBits(Ty) ==getTypeStoreSizeInBits(Ty);
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.
457TypeSizegetTypeAllocSize(Type *Ty) const{
458// Round up to the next alignment boundary.
459returnalignTo(getTypeStoreSize(Ty),getABITypeAlign(Ty).value());
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.
470TypeSizegetTypeAllocSizeInBits(Type *Ty) const{
471return 8 *getTypeAllocSize(Ty);
472 }
473
474 /// Returns the minimum ABI-required alignment for the specified type.
475AligngetABITypeAlign(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.
479inlineAligngetValueOrABITypeAlignment(MaybeAlign Alignment,
480Type *Ty) const{
481return Alignment ? *Alignment :getABITypeAlign(Ty);
482 }
483
484 /// Returns the minimum ABI-required alignment for an integer type of
485 /// the specified bitwidth.
486AligngetABIIntegerTypeAlignment(unsignedBitWidth) const{
487return 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.
494AligngetPrefTypeAlign(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.
498IntegerType *getIntPtrType(LLVMContext &C,unsignedAddressSpace = 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.
502Type *getIntPtrType(Type *)const;
503
504 /// Returns the smallest integer type with size at least as big as
505 /// Width bits.
506Type *getSmallestLegalIntType(LLVMContext &C,unsigned Width = 0)const;
507
508 /// Returns the largest legal integer type, or null if none are set.
509Type *getLargestLegalIntType(LLVMContext &C) const{
510unsigned LargestSize =getLargestLegalIntTypeSizeInBits();
511return (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.
516unsignedgetLargestLegalIntTypeSizeInBits()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.
521IntegerType *getIndexType(LLVMContext &C,unsignedAddressSpace)const;
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.
526Type *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_tgetIndexedOffsetInType(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.
537SmallVector<APInt>getGEPIndicesForOffset(Type *&ElemTy,APInt &Offset)const;
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.
549constStructLayout *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).
554AligngetPreferredAlign(constGlobalVariable *GV)const;
555};
556
557inlineDataLayout *unwrap(LLVMTargetDataRefP) {
558returnreinterpret_cast<DataLayout *>(P);
559}
560
561inlineLLVMTargetDataRefwrap(constDataLayout *P) {
562returnreinterpret_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.
567classStructLayout final :publicTrailingObjects<StructLayout, TypeSize> {
568TypeSize StructSize;
569Align StructAlignment;
570unsigned IsPadded : 1;
571unsigned NumElements : 31;
572
573public:
574TypeSizegetSizeInBytes() const{return StructSize; }
575
576TypeSizegetSizeInBits() const{return 8 * StructSize; }
577
578AligngetAlignment() 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.
582boolhasPadding() const{return IsPadded; }
583
584 /// Given a valid byte offset into the structure, returns the structure
585 /// index that contains it.
586unsignedgetElementContainingOffset(uint64_t FixedOffset)const;
587
588MutableArrayRef<TypeSize>getMemberOffsets() {
589returnllvm::MutableArrayRef(getTrailingObjects<TypeSize>(), NumElements);
590 }
591
592ArrayRef<TypeSize>getMemberOffsets() const{
593returnllvm::ArrayRef(getTrailingObjects<TypeSize>(), NumElements);
594 }
595
596TypeSizegetElementOffset(unsignedIdx) const{
597assert(Idx < NumElements &&"Invalid element idx!");
598returngetMemberOffsets()[Idx];
599 }
600
601TypeSizegetElementOffsetInBits(unsignedIdx) const{
602returngetElementOffset(Idx) * 8;
603 }
604
605private:
606friendclassDataLayout;// Only DataLayout can create this class
607
608StructLayout(StructType *ST,constDataLayout &DL);
609
610size_t numTrailingObjects(OverloadToken<TypeSize>) const{
611return 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.
617inlineTypeSizeDataLayout::getTypeSizeInBits(Type *Ty) const{
618assert(Ty->isSized() &&"Cannot getTypeInfo() on a type that is unsized!");
619switch (Ty->getTypeID()) {
620caseType::LabelTyID:
621returnTypeSize::getFixed(getPointerSizeInBits(0));
622caseType::PointerTyID:
623returnTypeSize::getFixed(
624getPointerSizeInBits(Ty->getPointerAddressSpace()));
625caseType::ArrayTyID: {
626ArrayType *ATy = cast<ArrayType>(Ty);
627return ATy->getNumElements() *
628getTypeAllocSizeInBits(ATy->getElementType());
629 }
630caseType::StructTyID:
631// Get the layout annotation... which is lazily created on demand.
632returngetStructLayout(cast<StructType>(Ty))->getSizeInBits();
633caseType::IntegerTyID:
634returnTypeSize::getFixed(Ty->getIntegerBitWidth());
635caseType::HalfTyID:
636caseType::BFloatTyID:
637returnTypeSize::getFixed(16);
638caseType::FloatTyID:
639returnTypeSize::getFixed(32);
640caseType::DoubleTyID:
641returnTypeSize::getFixed(64);
642caseType::PPC_FP128TyID:
643caseType::FP128TyID:
644returnTypeSize::getFixed(128);
645caseType::X86_AMXTyID:
646returnTypeSize::getFixed(8192);
647// In memory objects this is always aligned to a higher boundary, but
648// only 80 bits contain information.
649caseType::X86_FP80TyID:
650returnTypeSize::getFixed(80);
651caseType::FixedVectorTyID:
652caseType::ScalableVectorTyID: {
653VectorType *VTy = cast<VectorType>(Ty);
654auto EltCnt = VTy->getElementCount();
655uint64_t MinBits = EltCnt.getKnownMinValue() *
656getTypeSizeInBits(VTy->getElementType()).getFixedValue();
657returnTypeSize(MinBits, EltCnt.isScalable());
658 }
659caseType::TargetExtTyID: {
660Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
661returngetTypeSizeInBits(LayoutTy);
662 }
663default:
664llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
665 }
666}
667
668}// end namespace llvm
669
670#endif// LLVM_IR_DATALAYOUT_H
APInt.h
This file implements a class to represent arbitrary precision integral constant values and operations...
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
Alignment.h
ArrayRef.h
Casting.h
Compiler.h
Idx
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
Definition:DeadArgumentElimination.cpp:353
value
Given that RA is a live value
Definition:DeadArgumentElimination.cpp:716
DerivedTypes.h
Type.h
MathExtras.h
P
#define P(N)
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
SmallVector.h
This file defines the SmallVector class.
StringRef.h
TrailingObjects.h
This header defines support for implementing classes that have some trailing object (or arrays of obj...
TypeSize.h
T
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayType
Class to represent array types.
Definition:DerivedTypes.h:395
llvm::ArrayType::getNumElements
uint64_t getNumElements() const
Definition:DerivedTypes.h:407
llvm::ArrayType::getElementType
Type * getElementType() const
Definition:DerivedTypes.h:408
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DataLayout::getProgramAddressSpace
unsigned getProgramAddressSpace() const
Definition:DataLayout.h:246
llvm::DataLayout::typeSizeEqualsStoreSize
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type.
Definition:DataLayout.h:445
llvm::DataLayout::hasLinkerPrivateGlobalPrefix
bool hasLinkerPrivateGlobalPrefix() const
Definition:DataLayout.h:261
llvm::DataLayout::getManglingComponent
static const char * getManglingComponent(const Triple &T)
Definition:DataLayout.cpp:176
llvm::DataLayout::getLinkerPrivateGlobalPrefix
StringRef getLinkerPrivateGlobalPrefix() const
Definition:DataLayout.h:263
llvm::DataLayout::getPointerSizeInBits
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
llvm::DataLayout::isNonIntegralPointerType
bool isNonIntegralPointerType(Type *Ty) const
Definition:DataLayout.h:356
llvm::DataLayout::FunctionPtrAlignType
FunctionPtrAlignType
Definition:DataLayout.h:89
llvm::DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
llvm::DataLayout::FunctionPtrAlignType::Independent
@ Independent
The function pointer alignment is independent of the function alignment.
llvm::DataLayout::getGEPIndicesForOffset
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
Definition:DataLayout.cpp:971
llvm::DataLayout::isLittleEndian
bool isLittleEndian() const
Layout endianness...
Definition:DataLayout.h:197
llvm::DataLayout::isDefault
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition:DataLayout.h:210
llvm::DataLayout::getTypeStoreSizeInBits
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
llvm::DataLayout::getLargestLegalIntTypeSizeInBits
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition:DataLayout.cpp:873
llvm::DataLayout::isLegalInteger
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
llvm::DataLayout::getDefaultGlobalsAddressSpace
unsigned getDefaultGlobalsAddressSpace() const
Definition:DataLayout.h:247
llvm::DataLayout::getFunctionPtrAlignType
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition:DataLayout.h:242
llvm::DataLayout::getABIIntegerTypeAlignment
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition:DataLayout.h:486
llvm::DataLayout::doNotMangleLeadingQuestionMark
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition:DataLayout.h:257
llvm::DataLayout::getIndexSize
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
Definition:DataLayout.cpp:750
llvm::DataLayout::getStructLayout
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
llvm::DataLayout::DataLayout
DataLayout()
Constructs a DataLayout with default values.
Definition:DataLayout.cpp:214
llvm::DataLayout::getIntPtrType
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
llvm::DataLayout::getPointerTypeSize
unsigned getPointerTypeSize(Type *Ty) const
Definition:DataLayout.h:384
llvm::DataLayout::getABITypeAlign
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition:DataLayout.cpp:843
llvm::DataLayout::isNonIntegralAddressSpace
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition:DataLayout.h:348
llvm::DataLayout::isIllegalInteger
bool isIllegalInteger(uint64_t Width) const
Definition:DataLayout.h:223
llvm::DataLayout::getIndexTypeSizeInBits
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Definition:DataLayout.cpp:754
llvm::DataLayout::getAllocaPtrType
PointerType * getAllocaPtrType(LLVMContext &Ctx) const
Definition:DataLayout.h:231
llvm::DataLayout::getPointerTypeSizeInBits
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition:DataLayout.cpp:743
llvm::DataLayout::isBigEndian
bool isBigEndian() const
Definition:DataLayout.h:198
llvm::DataLayout::getStackAlignment
MaybeAlign getStackAlignment() const
Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.
Definition:DataLayout.h:227
llvm::DataLayout::getAllocaAddrSpace
unsigned getAllocaAddrSpace() const
Definition:DataLayout.h:229
llvm::DataLayout::operator=
DataLayout & operator=(const DataLayout &Other)
Definition:DataLayout.cpp:225
llvm::DataLayout::getIndexType
IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
Definition:DataLayout.cpp:878
llvm::DataLayout::getTypeAllocSize
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition:DataLayout.h:457
llvm::DataLayout::getGEPIndexForOffset
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition:DataLayout.cpp:941
llvm::DataLayout::getSmallestLegalIntType
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
llvm::DataLayout::getPreferredAlign
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition:DataLayout.cpp:988
llvm::DataLayout::fitsInLegalInteger
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
llvm::DataLayout::hasMicrosoftFastStdCallMangling
bool hasMicrosoftFastStdCallMangling() const
Definition:DataLayout.h:251
llvm::DataLayout::~DataLayout
~DataLayout()
Definition:DataLayout.cpp:707
llvm::DataLayout::getPointerSize
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size in bytes, rounded up to a whole number of bytes.
Definition:DataLayout.cpp:739
llvm::DataLayout::isNonIntegralPointerType
bool isNonIntegralPointerType(PointerType *PT) const
Definition:DataLayout.h:352
llvm::DataLayout::getPointerPrefAlignment
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
llvm::DataLayout::getIndexSizeInBits
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition:DataLayout.h:369
llvm::DataLayout::getLargestLegalIntType
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition:DataLayout.h:509
llvm::DataLayout::getPrivateGlobalPrefix
StringRef getPrivateGlobalPrefix() const
Definition:DataLayout.h:285
llvm::DataLayout::getFunctionPtrAlign
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
llvm::DataLayout::getTypeSizeInBits
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition:DataLayout.h:617
llvm::DataLayout::getTypeStoreSize
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition:DataLayout.h:421
llvm::DataLayout::operator!=
bool operator!=(const DataLayout &Other) const
Definition:DataLayout.h:190
llvm::DataLayout::DataLayout
DataLayout(const DataLayout &DL)
Definition:DataLayout.h:183
llvm::DataLayout::getTypeAllocSizeInBits
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition:DataLayout.h:470
llvm::DataLayout::getGlobalPrefix
char getGlobalPrefix() const
Definition:DataLayout.h:269
llvm::DataLayout::getIndexedOffsetInType
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
llvm::DataLayout::getStringRepresentation
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition:DataLayout.h:205
llvm::DataLayout::getValueOrABITypeAlignment
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
llvm::DataLayout::getPointerABIAlignment
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition:DataLayout.cpp:731
llvm::DataLayout::getPrefTypeAlign
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition:DataLayout.cpp:847
llvm::DataLayout::getNonIntegralAddressSpaces
SmallVector< unsigned, 8 > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition:DataLayout.h:339
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::GlobalVariable
Definition:GlobalVariable.h:39
llvm::IntegerType
Class to represent integer types.
Definition:DerivedTypes.h:42
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition:ArrayRef.h:310
llvm::PointerType
Class to represent pointers.
Definition:DerivedTypes.h:670
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition:DerivedTypes.h:703
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StructLayout
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition:DataLayout.h:567
llvm::StructLayout::getSizeInBytes
TypeSize getSizeInBytes() const
Definition:DataLayout.h:574
llvm::StructLayout::hasPadding
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition:DataLayout.h:582
llvm::StructLayout::getMemberOffsets
MutableArrayRef< TypeSize > getMemberOffsets()
Definition:DataLayout.h:588
llvm::StructLayout::getElementContainingOffset
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
llvm::StructLayout::getElementOffset
TypeSize getElementOffset(unsigned Idx) const
Definition:DataLayout.h:596
llvm::StructLayout::getMemberOffsets
ArrayRef< TypeSize > getMemberOffsets() const
Definition:DataLayout.h:592
llvm::StructLayout::getSizeInBits
TypeSize getSizeInBits() const
Definition:DataLayout.h:576
llvm::StructLayout::getElementOffsetInBits
TypeSize getElementOffsetInBits(unsigned Idx) const
Definition:DataLayout.h:601
llvm::StructLayout::getAlignment
Align getAlignment() const
Definition:DataLayout.h:578
llvm::StructType
Class to represent struct types.
Definition:DerivedTypes.h:218
llvm::TrailingObjects
See the file comment for details on the usage of the TrailingObjects type.
Definition:TrailingObjects.h:216
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::TypeSize
Definition:TypeSize.h:334
llvm::TypeSize::getFixed
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition:TypeSize.h:345
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::getIntegerBitWidth
unsigned getIntegerBitWidth() const
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
llvm::Type::X86_AMXTyID
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition:Type.h:66
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition:Type.h:74
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition:Type.h:56
llvm::Type::TargetExtTyID
@ TargetExtTyID
Target extension type.
Definition:Type.h:78
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition:Type.h:76
llvm::Type::LabelTyID
@ LabelTyID
Labels.
Definition:Type.h:64
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition:Type.h:58
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition:Type.h:73
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition:Type.h:70
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition:Type.h:75
llvm::Type::BFloatTyID
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition:Type.h:57
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition:Type.h:59
llvm::Type::X86_FP80TyID
@ X86_FP80TyID
80-bit floating point type (X87)
Definition:Type.h:60
llvm::Type::PPC_FP128TyID
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition:Type.h:62
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition:Type.h:72
llvm::Type::FP128TyID
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition:Type.h:61
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition:Type.h:310
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition:Type.h:136
llvm::VectorType
Base class of all SIMD vector types.
Definition:DerivedTypes.h:427
llvm::VectorType::getElementCount
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition:DerivedTypes.h:665
llvm::VectorType::getElementType
Type * getElementType() const
Definition:DerivedTypes.h:460
llvm::details::FixedOrScalableQuantity::getFixedValue
constexpr ScalarTy getFixedValue() const
Definition:TypeSize.h:202
llvm::details::FixedOrScalableQuantity::isScalable
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition:TypeSize.h:171
llvm::details::FixedOrScalableQuantity::getKnownMinValue
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition:TypeSize.h:168
uint32_t
uint64_t
LLVMTargetDataRef
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition:Target.h:37
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::NVPTXAS::AddressSpace
AddressSpace
Definition:NVPTXAddrSpace.h:20
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::alignToPowerOf2
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Definition:MathExtras.h:503
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition:Attributes.h:335
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition:Alignment.h:155
llvm::BitWidth
constexpr unsigned BitWidth
Definition:BitmaskEnum.h:217
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition:Attributes.h:330
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition:STLExtras.h:1903
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::DataLayout::PointerSpec
Pointer type specification.
Definition:DataLayout.h:75
llvm::DataLayout::PointerSpec::AddrSpace
uint32_t AddrSpace
Definition:DataLayout.h:76
llvm::DataLayout::PointerSpec::operator==
bool operator==(const PointerSpec &Other) const
Definition:DataLayout.cpp:151
llvm::DataLayout::PointerSpec::ABIAlign
Align ABIAlign
Definition:DataLayout.h:78
llvm::DataLayout::PointerSpec::BitWidth
uint32_t BitWidth
Definition:DataLayout.h:77
llvm::DataLayout::PointerSpec::PrefAlign
Align PrefAlign
Definition:DataLayout.h:79
llvm::DataLayout::PointerSpec::IsNonIntegral
bool IsNonIntegral
Pointers in this address space don't have a well-defined bitwise representation (e....
Definition:DataLayout.h:85
llvm::DataLayout::PointerSpec::IndexBitWidth
uint32_t IndexBitWidth
Definition:DataLayout.h:80
llvm::DataLayout::PrimitiveSpec
Primitive type specification.
Definition:DataLayout.h:66
llvm::DataLayout::PrimitiveSpec::PrefAlign
Align PrefAlign
Definition:DataLayout.h:69
llvm::DataLayout::PrimitiveSpec::operator==
bool operator==(const PrimitiveSpec &Other) const
Definition:DataLayout.cpp:146
llvm::DataLayout::PrimitiveSpec::ABIAlign
Align ABIAlign
Definition:DataLayout.h:68
llvm::DataLayout::PrimitiveSpec::BitWidth
uint32_t BitWidth
Definition:DataLayout.h:67
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition:Alignment.h:117
parse
Definition:regcomp.c:192

Generated on Thu Jul 17 2025 10:03:16 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp