LLVM  10.0.0svn
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/ArrayRef.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/IR/DerivedTypes.h"
27 #include "llvm/IR/Type.h"
28 #include "llvm/Support/Casting.h"
31 #include "llvm/Support/Alignment.h"
32 #include "llvm/Support/TypeSize.h"
33 #include <cassert>
34 #include <cstdint>
35 #include <string>
36 
37 // This needs to be outside of the namespace, to avoid conflict with llvm-c
38 // decl.
39 using LLVMTargetDataRef = struct LLVMOpaqueTargetData *;
40 
41 namespace llvm {
42 
43 class GlobalVariable;
44 class LLVMContext;
45 class Module;
46 class StructLayout;
47 class Triple;
48 class Value;
49 
50 /// Enum used to categorize the alignment types stored by LayoutAlignElem
54  VECTOR_ALIGN = 'v',
55  FLOAT_ALIGN = 'f',
57 };
58 
59 // FIXME: Currently the DataLayout string carries a "preferred alignment"
60 // for types. As the DataLayout is module/global, this should likely be
61 // sunk down to an FTTI element that is queried rather than a global
62 // preference.
63 
64 /// Layout alignment element.
65 ///
66 /// Stores the alignment data associated with a given alignment type (integer,
67 /// vector, float) and type bit width.
68 ///
69 /// \note The unusual order of elements in the structure attempts to reduce
70 /// padding and make the structure slightly more cache friendly.
72  /// Alignment type from \c AlignTypeEnum
73  unsigned AlignType : 8;
74  unsigned TypeBitWidth : 24;
77 
78  static LayoutAlignElem get(AlignTypeEnum align_type, Align abi_align,
79  Align pref_align, uint32_t bit_width);
80 
81  bool operator==(const LayoutAlignElem &rhs) const;
82 };
83 
84 /// Layout pointer alignment element.
85 ///
86 /// Stores the alignment data associated with a given pointer and address space.
87 ///
88 /// \note The unusual order of elements in the structure attempts to reduce
89 /// padding and make the structure slightly more cache friendly.
96 
97  /// Initializer
99  Align PrefAlign, uint32_t TypeByteWidth,
100  uint32_t IndexWidth);
101 
102  bool operator==(const PointerAlignElem &rhs) const;
103 };
104 
105 /// A parsed version of the target data layout string in and methods for
106 /// querying it.
107 ///
108 /// The target data layout string is specified *by the target* - a frontend
109 /// generating LLVM IR is required to generate the right target data for the
110 /// target being codegen'd to.
111 class DataLayout {
112 public:
113  enum class FunctionPtrAlignType {
114  /// The function pointer alignment is independent of the function alignment.
115  Independent,
116  /// The function pointer alignment is a multiple of the function alignment.
117  MultipleOfFunctionAlign,
118  };
119 private:
120  /// Defaults to false.
121  bool BigEndian;
122 
123  unsigned AllocaAddrSpace;
124  MaybeAlign StackNaturalAlign;
125  unsigned ProgramAddrSpace;
126 
127  MaybeAlign FunctionPtrAlign;
128  FunctionPtrAlignType TheFunctionPtrAlignType;
129 
130  enum ManglingModeT {
131  MM_None,
132  MM_ELF,
133  MM_MachO,
134  MM_WinCOFF,
135  MM_WinCOFFX86,
136  MM_Mips
137  };
138  ManglingModeT ManglingMode;
139 
140  SmallVector<unsigned char, 8> LegalIntWidths;
141 
142  /// Primitive type alignment data. This is sorted by type and bit
143  /// width during construction.
145  AlignmentsTy Alignments;
146 
148  findAlignmentLowerBound(AlignTypeEnum AlignType, uint32_t BitWidth) const {
149  return const_cast<DataLayout *>(this)->findAlignmentLowerBound(AlignType,
150  BitWidth);
151  }
152 
154  findAlignmentLowerBound(AlignTypeEnum AlignType, uint32_t BitWidth);
155 
156  /// The string representation used to create this DataLayout
157  std::string StringRepresentation;
158 
160  PointersTy Pointers;
161 
163  findPointerLowerBound(uint32_t AddressSpace) const {
164  return const_cast<DataLayout *>(this)->findPointerLowerBound(AddressSpace);
165  }
166 
167  PointersTy::iterator findPointerLowerBound(uint32_t AddressSpace);
168 
169  // The StructType -> StructLayout map.
170  mutable void *LayoutMap = nullptr;
171 
172  /// Pointers in these address spaces are non-integral, and don't have a
173  /// well-defined bitwise representation.
174  SmallVector<unsigned, 8> NonIntegralAddressSpaces;
175 
176  void setAlignment(AlignTypeEnum align_type, Align abi_align, Align pref_align,
177  uint32_t bit_width);
178  Align getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
179  bool ABIAlign, Type *Ty) const;
180  void setPointerAlignment(uint32_t AddrSpace, Align ABIAlign, Align PrefAlign,
181  uint32_t TypeByteWidth, uint32_t IndexWidth);
182 
183  /// Internal helper method that returns requested alignment for type.
184  Align getAlignment(Type *Ty, bool abi_or_pref) const;
185 
186  /// Parses a target data specification string. Assert if the string is
187  /// malformed.
188  void parseSpecifier(StringRef LayoutDescription);
189 
190  // Free all internal data structures.
191  void clear();
192 
193 public:
194  /// Constructs a DataLayout from a specification string. See reset().
195  explicit DataLayout(StringRef LayoutDescription) {
196  reset(LayoutDescription);
197  }
198 
199  /// Initialize target data from properties stored in the module.
200  explicit DataLayout(const Module *M);
201 
202  DataLayout(const DataLayout &DL) { *this = DL; }
203 
204  ~DataLayout(); // Not virtual, do not subclass this class
205 
207  clear();
208  StringRepresentation = DL.StringRepresentation;
209  BigEndian = DL.isBigEndian();
210  AllocaAddrSpace = DL.AllocaAddrSpace;
211  StackNaturalAlign = DL.StackNaturalAlign;
212  FunctionPtrAlign = DL.FunctionPtrAlign;
213  TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType;
214  ProgramAddrSpace = DL.ProgramAddrSpace;
215  ManglingMode = DL.ManglingMode;
216  LegalIntWidths = DL.LegalIntWidths;
217  Alignments = DL.Alignments;
218  Pointers = DL.Pointers;
219  NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces;
220  return *this;
221  }
222 
223  bool operator==(const DataLayout &Other) const;
224  bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
225 
226  void init(const Module *M);
227 
228  /// Parse a data layout string (with fallback to default values).
229  void reset(StringRef LayoutDescription);
230 
231  /// Layout endianness...
232  bool isLittleEndian() const { return !BigEndian; }
233  bool isBigEndian() const { return BigEndian; }
234 
235  /// Returns the string representation of the DataLayout.
236  ///
237  /// This representation is in the same format accepted by the string
238  /// constructor above. This should not be used to compare two DataLayout as
239  /// different string can represent the same layout.
240  const std::string &getStringRepresentation() const {
241  return StringRepresentation;
242  }
243 
244  /// Test if the DataLayout was constructed from an empty string.
245  bool isDefault() const { return StringRepresentation.empty(); }
246 
247  /// Returns true if the specified type is known to be a native integer
248  /// type supported by the CPU.
249  ///
250  /// For example, i64 is not native on most 32-bit CPUs and i37 is not native
251  /// on any known one. This returns false if the integer width is not legal.
252  ///
253  /// The width is specified in bits.
254  bool isLegalInteger(uint64_t Width) const {
255  for (unsigned LegalIntWidth : LegalIntWidths)
256  if (LegalIntWidth == Width)
257  return true;
258  return false;
259  }
260 
261  bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
262 
263  /// Returns true if the given alignment exceeds the natural stack alignment.
264  bool exceedsNaturalStackAlignment(Align Alignment) const {
265  return StackNaturalAlign && (Alignment > StackNaturalAlign);
266  }
267 
269  assert(StackNaturalAlign && "StackNaturalAlign must be defined");
270  return *StackNaturalAlign;
271  }
272 
273  unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
274 
275  /// Returns the alignment of function pointers, which may or may not be
276  /// related to the alignment of functions.
277  /// \see getFunctionPtrAlignType
278  MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
279 
280  /// Return the type of function pointer alignment.
281  /// \see getFunctionPtrAlign
283  return TheFunctionPtrAlignType;
284  }
285 
286  unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
287 
289  return ManglingMode == MM_WinCOFFX86;
290  }
291 
292  /// Returns true if symbols with leading question marks should not receive IR
293  /// mangling. True for Windows mangling modes.
295  return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;
296  }
297 
298  bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
299 
301  if (ManglingMode == MM_MachO)
302  return "l";
303  return "";
304  }
305 
306  char getGlobalPrefix() const {
307  switch (ManglingMode) {
308  case MM_None:
309  case MM_ELF:
310  case MM_Mips:
311  case MM_WinCOFF:
312  return '\0';
313  case MM_MachO:
314  case MM_WinCOFFX86:
315  return '_';
316  }
317  llvm_unreachable("invalid mangling mode");
318  }
319 
321  switch (ManglingMode) {
322  case MM_None:
323  return "";
324  case MM_ELF:
325  case MM_WinCOFF:
326  return ".L";
327  case MM_Mips:
328  return "$";
329  case MM_MachO:
330  case MM_WinCOFFX86:
331  return "L";
332  }
333  llvm_unreachable("invalid mangling mode");
334  }
335 
336  static const char *getManglingComponent(const Triple &T);
337 
338  /// Returns true if the specified type fits in a native integer type
339  /// supported by the CPU.
340  ///
341  /// For example, if the CPU only supports i32 as a native integer type, then
342  /// i27 fits in a legal integer type but i45 does not.
343  bool fitsInLegalInteger(unsigned Width) const {
344  for (unsigned LegalIntWidth : LegalIntWidths)
345  if (Width <= LegalIntWidth)
346  return true;
347  return false;
348  }
349 
350  /// Layout pointer alignment
351  Align getPointerABIAlignment(unsigned AS) const;
352 
353  /// Return target's alignment for stack-based pointers
354  /// FIXME: The defaults need to be removed once all of
355  /// the backends/clients are updated.
356  Align getPointerPrefAlignment(unsigned AS = 0) const;
357 
358  /// Layout pointer size
359  /// FIXME: The defaults need to be removed once all of
360  /// the backends/clients are updated.
361  unsigned getPointerSize(unsigned AS = 0) const;
362 
363  /// Returns the maximum pointer size over all address spaces.
364  unsigned getMaxPointerSize() const;
365 
366  // Index size used for address calculation.
367  unsigned getIndexSize(unsigned AS) const;
368 
369  /// Return the address spaces containing non-integral pointers. Pointers in
370  /// this address space don't have a well-defined bitwise representation.
372  return NonIntegralAddressSpaces;
373  }
374 
375  bool isNonIntegralAddressSpace(unsigned AddrSpace) const {
376  ArrayRef<unsigned> NonIntegralSpaces = getNonIntegralAddressSpaces();
377  return find(NonIntegralSpaces, AddrSpace) != NonIntegralSpaces.end();
378  }
379 
381  return isNonIntegralAddressSpace(PT->getAddressSpace());
382  }
383 
384  bool isNonIntegralPointerType(Type *Ty) const {
385  auto *PTy = dyn_cast<PointerType>(Ty);
386  return PTy && isNonIntegralPointerType(PTy);
387  }
388 
389  /// Layout pointer size, in bits
390  /// FIXME: The defaults need to be removed once all of
391  /// the backends/clients are updated.
392  unsigned getPointerSizeInBits(unsigned AS = 0) const {
393  return getPointerSize(AS) * 8;
394  }
395 
396  /// Returns the maximum pointer size over all address spaces.
397  unsigned getMaxPointerSizeInBits() const {
398  return getMaxPointerSize() * 8;
399  }
400 
401  /// Size in bits of index used for address calculation in getelementptr.
402  unsigned getIndexSizeInBits(unsigned AS) const {
403  return getIndexSize(AS) * 8;
404  }
405 
406  /// Layout pointer size, in bits, based on the type. If this function is
407  /// called with a pointer type, then the type size of the pointer is returned.
408  /// If this function is called with a vector of pointers, then the type size
409  /// of the pointer is returned. This should only be called with a pointer or
410  /// vector of pointers.
411  unsigned getPointerTypeSizeInBits(Type *) const;
412 
413  /// Layout size of the index used in GEP calculation.
414  /// The function should be called with pointer or vector of pointers type.
415  unsigned getIndexTypeSizeInBits(Type *Ty) const;
416 
417  unsigned getPointerTypeSize(Type *Ty) const {
418  return getPointerTypeSizeInBits(Ty) / 8;
419  }
420 
421  /// Size examples:
422  ///
423  /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
424  /// ---- ---------- --------------- ---------------
425  /// i1 1 8 8
426  /// i8 8 8 8
427  /// i19 19 24 32
428  /// i32 32 32 32
429  /// i100 100 104 128
430  /// i128 128 128 128
431  /// Float 32 32 32
432  /// Double 64 64 64
433  /// X86_FP80 80 80 96
434  ///
435  /// [*] The alloc size depends on the alignment, and thus on the target.
436  /// These values are for x86-32 linux.
437 
438  /// Returns the number of bits necessary to hold the specified type.
439  ///
440  /// If Ty is a scalable vector type, the scalable property will be set and
441  /// the runtime size will be a positive integer multiple of the base size.
442  ///
443  /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
444  /// have a size (Type::isSized() must return true).
445  TypeSize getTypeSizeInBits(Type *Ty) const;
446 
447  /// Returns the maximum number of bytes that may be overwritten by
448  /// storing the specified type.
449  ///
450  /// If Ty is a scalable vector type, the scalable property will be set and
451  /// the runtime size will be a positive integer multiple of the base size.
452  ///
453  /// For example, returns 5 for i36 and 10 for x86_fp80.
455  TypeSize BaseSize = getTypeSizeInBits(Ty);
456  return { (BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable() };
457  }
458 
459  /// Returns the maximum number of bits that may be overwritten by
460  /// storing the specified type; always a multiple of 8.
461  ///
462  /// If Ty is a scalable vector type, the scalable property will be set and
463  /// the runtime size will be a positive integer multiple of the base size.
464  ///
465  /// For example, returns 40 for i36 and 80 for x86_fp80.
467  return 8 * getTypeStoreSize(Ty);
468  }
469 
470  /// Returns true if no extra padding bits are needed when storing the
471  /// specified type.
472  ///
473  /// For example, returns false for i19 that has a 24-bit store size.
474  bool typeSizeEqualsStoreSize(Type *Ty) const {
475  return getTypeSizeInBits(Ty) == getTypeStoreSizeInBits(Ty);
476  }
477 
478  /// Returns the offset in bytes between successive objects of the
479  /// specified type, including alignment padding.
480  ///
481  /// If Ty is a scalable vector type, the scalable property will be set and
482  /// the runtime size will be a positive integer multiple of the base size.
483  ///
484  /// This is the amount that alloca reserves for this type. For example,
485  /// returns 12 or 16 for x86_fp80, depending on alignment.
487  // Round up to the next alignment boundary.
488  return alignTo(getTypeStoreSize(Ty), getABITypeAlignment(Ty));
489  }
490 
491  /// Returns the offset in bits between successive objects of the
492  /// specified type, including alignment padding; always a multiple of 8.
493  ///
494  /// If Ty is a scalable vector type, the scalable property will be set and
495  /// the runtime size will be a positive integer multiple of the base size.
496  ///
497  /// This is the amount that alloca reserves for this type. For example,
498  /// returns 96 or 128 for x86_fp80, depending on alignment.
500  return 8 * getTypeAllocSize(Ty);
501  }
502 
503  /// Returns the minimum ABI-required alignment for the specified type.
504  unsigned getABITypeAlignment(Type *Ty) const;
505 
506  /// Helper function to return `Alignment` if it's set or the result of
507  /// `getABITypeAlignment(Ty)`, in any case the result is a valid alignment.
509  Type *Ty) const {
510  return Alignment ? *Alignment : Align(getABITypeAlignment(Ty));
511  }
512 
513  /// Returns the minimum ABI-required alignment for an integer type of
514  /// the specified bitwidth.
515  Align getABIIntegerTypeAlignment(unsigned BitWidth) const;
516 
517  /// Returns the preferred stack/global alignment for the specified
518  /// type.
519  ///
520  /// This is always at least as good as the ABI alignment.
521  unsigned getPrefTypeAlignment(Type *Ty) const;
522 
523  /// Returns an integer type with size at least as big as that of a
524  /// pointer in the given address space.
525  IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const;
526 
527  /// Returns an integer (vector of integer) type with size at least as
528  /// big as that of a pointer of the given pointer (vector of pointer) type.
529  Type *getIntPtrType(Type *) const;
530 
531  /// Returns the smallest integer type with size at least as big as
532  /// Width bits.
533  Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const;
534 
535  /// Returns the largest legal integer type, or null if none are set.
537  unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
538  return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
539  }
540 
541  /// Returns the size of largest legal integer type size, or 0 if none
542  /// are set.
543  unsigned getLargestLegalIntTypeSizeInBits() const;
544 
545  /// Returns the type of a GEP index.
546  /// If it was not specified explicitly, it will be the integer type of the
547  /// pointer width - IntPtrType.
548  Type *getIndexType(Type *PtrTy) const;
549 
550  /// Returns the offset from the beginning of the type for the specified
551  /// indices.
552  ///
553  /// Note that this takes the element type, not the pointer type.
554  /// This is used to implement getelementptr.
555  int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
556 
557  /// Returns a StructLayout object, indicating the alignment of the
558  /// struct, its size, and the offsets of its fields.
559  ///
560  /// Note that this information is lazily cached.
561  const StructLayout *getStructLayout(StructType *Ty) const;
562 
563  /// Returns the preferred alignment of the specified global.
564  ///
565  /// This includes an explicitly requested alignment (if the global has one).
566  unsigned getPreferredAlignment(const GlobalVariable *GV) const;
567 
568  /// Returns the preferred alignment of the specified global, returned
569  /// in log form.
570  ///
571  /// This includes an explicitly requested alignment (if the global has one).
572  unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
573 };
574 
576  return reinterpret_cast<DataLayout *>(P);
577 }
578 
580  return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
581 }
582 
583 /// Used to lazily calculate structure layout information for a target machine,
584 /// based on the DataLayout structure.
586  uint64_t StructSize;
587  Align StructAlignment;
588  unsigned IsPadded : 1;
589  unsigned NumElements : 31;
590  uint64_t MemberOffsets[1]; // variable sized array!
591 
592 public:
593  uint64_t getSizeInBytes() const { return StructSize; }
594 
595  uint64_t getSizeInBits() const { return 8 * StructSize; }
596 
597  Align getAlignment() const { return StructAlignment; }
598 
599  /// Returns whether the struct has padding or not between its fields.
600  /// NB: Padding in nested element is not taken into account.
601  bool hasPadding() const { return IsPadded; }
602 
603  /// Given a valid byte offset into the structure, returns the structure
604  /// index that contains it.
605  unsigned getElementContainingOffset(uint64_t Offset) const;
606 
607  uint64_t getElementOffset(unsigned Idx) const {
608  assert(Idx < NumElements && "Invalid element idx!");
609  return MemberOffsets[Idx];
610  }
611 
612  uint64_t getElementOffsetInBits(unsigned Idx) const {
613  return getElementOffset(Idx) * 8;
614  }
615 
616 private:
617  friend class DataLayout; // Only DataLayout can create this class
618 
619  StructLayout(StructType *ST, const DataLayout &DL);
620 };
621 
622 // The implementation of this method is provided inline as it is particularly
623 // well suited to constant folding when called on a specific Type subclass.
625  assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
626  switch (Ty->getTypeID()) {
627  case Type::LabelTyID:
628  return TypeSize::Fixed(getPointerSizeInBits(0));
629  case Type::PointerTyID:
630  return TypeSize::Fixed(getPointerSizeInBits(Ty->getPointerAddressSpace()));
631  case Type::ArrayTyID: {
632  ArrayType *ATy = cast<ArrayType>(Ty);
633  return ATy->getNumElements() *
634  getTypeAllocSizeInBits(ATy->getElementType());
635  }
636  case Type::StructTyID:
637  // Get the layout annotation... which is lazily created on demand.
638  return TypeSize::Fixed(
639  getStructLayout(cast<StructType>(Ty))->getSizeInBits());
640  case Type::IntegerTyID:
641  return TypeSize::Fixed(Ty->getIntegerBitWidth());
642  case Type::HalfTyID:
643  return TypeSize::Fixed(16);
644  case Type::FloatTyID:
645  return TypeSize::Fixed(32);
646  case Type::DoubleTyID:
647  case Type::X86_MMXTyID:
648  return TypeSize::Fixed(64);
649  case Type::PPC_FP128TyID:
650  case Type::FP128TyID:
651  return TypeSize::Fixed(128);
652  // In memory objects this is always aligned to a higher boundary, but
653  // only 80 bits contain information.
654  case Type::X86_FP80TyID:
655  return TypeSize::Fixed(80);
656  case Type::VectorTyID: {
657  VectorType *VTy = cast<VectorType>(Ty);
658  auto EltCnt = VTy->getElementCount();
659  uint64_t MinBits = EltCnt.Min *
660  getTypeSizeInBits(VTy->getElementType()).getFixedSize();
661  return TypeSize(MinBits, EltCnt.Scalable);
662  }
663  default:
664  llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
665  }
666 }
667 
668 } // end namespace llvm
669 
670 #endif // LLVM_IR_DATALAYOUT_H
uint64_t CallInst * C
7: Labels
Definition: Type.h:64
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool isScalable() const
Definition: TypeSize.h:137
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition: DataLayout.h:402
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:320
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Definition: DataLayout.h:51
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Align getStackAlignment() const
Definition: DataLayout.h:268
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:320
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:265
2: 32-bit floating point type
Definition: Type.h:59
bool operator!=(const DataLayout &Other) const
Definition: DataLayout.h:224
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:240
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:953
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:542
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
Definition: DataLayout.h:375
13: Structures
Definition: Type.h:73
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:392
4: 80-bit floating point type (X87)
Definition: Type.h:61
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:635
char getGlobalPrefix() const
Definition: DataLayout.h:306
1: 16-bit floating point type
Definition: Type.h:58
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:624
bool exceedsNaturalStackAlignment(Align Alignment) const
Returns true if the given alignment exceeds the natural stack alignment.
Definition: DataLayout.h:264
15: Pointers
Definition: Type.h:75
bool typeSizeEqualsStoreSize(Type *Ty) const
Returns true if no extra padding bits are needed when storing the specified type. ...
Definition: DataLayout.h:474
unsigned Min
Definition: TypeSize.h:25
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:300
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:466
FunctionPtrAlignType getFunctionPtrAlignType() const
Return the type of function pointer alignment.
Definition: DataLayout.h:282
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:273
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:585
static uint32_t getAlignment(const MCSectionCOFF &Sec)
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:39
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:204
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:138
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:417
Class to represent struct types.
Definition: DerivedTypes.h:238
uint64_t getElementOffsetInBits(unsigned Idx) const
Definition: DataLayout.h:612
DataLayout(const DataLayout &DL)
Definition: DataLayout.h:202
DataLayout & operator=(const DataLayout &DL)
Definition: DataLayout.h:206
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
Definition: DerivedTypes.h:398
uint64_t getSizeInBits() const
Definition: DataLayout.h:595
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:454
Class to represent array types.
Definition: DerivedTypes.h:408
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:232
bool isNonIntegralPointerType(Type *Ty) const
Definition: DataLayout.h:384
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it&#39;s set or the result of getABITypeAlignment(Ty), in any case the result is a valid alignment.
Definition: DataLayout.h:508
Class to represent pointers.
Definition: DerivedTypes.h:579
Layout pointer alignment element.
Definition: DataLayout.h:90
unsigned getMaxPointerSizeInBits() const
Returns the maximum pointer size over all address spaces.
Definition: DataLayout.h:397
11: Arbitrary bit width integers
Definition: Type.h:71
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition: DataLayout.h:536
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:63
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:607
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:298
Class to represent integer types.
Definition: DerivedTypes.h:40
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1186
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
14: Arrays
Definition: Type.h:74
16: SIMD &#39;packed&#39; format, or other vector type
Definition: Type.h:76
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:117
AddressSpace
Definition: NVPTXBaseInfo.h:21
iterator end() const
Definition: ArrayRef.h:137
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:254
uint64_t getSizeInBytes() const
Definition: DataLayout.h:593
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:184
bool hasMicrosoftFastStdCallMangling() const
Definition: DataLayout.h:288
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:286
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition: DataLayout.h:245
Class to represent vector types.
Definition: DerivedTypes.h:432
typename SuperClass::iterator iterator
Definition: SmallVector.h:319
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
Definition: DataLayout.h:195
static void clear(coro::Shape &Shape)
Definition: Coroutines.cpp:225
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:380
static constexpr TypeSize Fixed(uint64_t Size)
Definition: TypeSize.h:59
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:163
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:199
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:607
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:102
uint64_t getKnownMinSize() const
Definition: TypeSize.h:132
Layout alignment element.
Definition: DataLayout.h:71
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition: DataLayout.h:601
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition: DataLayout.h:371
unsigned AlignType
Alignment type from AlignTypeEnum.
Definition: DataLayout.h:73
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:499
3: 64-bit floating point type
Definition: Type.h:60
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MaybeAlign getFunctionPtrAlign() const
Returns the alignment of function pointers, which may or may not be related to the alignment of funct...
Definition: DataLayout.h:278
Type * getElementType() const
Definition: DerivedTypes.h:399
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
static unsigned getMaxPointerSize(const DataLayout &DL)
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU...
Definition: DataLayout.h:343
Align getAlignment() const
Definition: DataLayout.h:597
bool isIllegalInteger(uint64_t Width) const
Definition: DataLayout.h:261
bool operator==(const LayoutAlignElem &rhs) const
Definition: DataLayout.cpp:114
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
bool isBigEndian() const
Definition: DataLayout.h:233
bool doNotMangleLeadingQuestionMark() const
Returns true if symbols with leading question marks should not receive IR mangling.
Definition: DataLayout.h:294
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:62