LLVM  4.0.0
DataLayout.h
Go to the documentation of this file.
1 //===--------- llvm/DataLayout.h - Data size & alignment info ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines layout properties related to datatype size/offset/alignment
11 // information. It uses lazy annotations to cache information about how
12 // structure types are laid out and used.
13 //
14 // This structure should be created once, filled in if the defaults are not
15 // correct and then passed around by const&. None of the members functions
16 // require modification to the object.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_IR_DATALAYOUT_H
21 #define LLVM_IR_DATALAYOUT_H
22 
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/IR/DerivedTypes.h"
26 #include "llvm/IR/Type.h"
27 #include "llvm/Pass.h"
28 #include "llvm/Support/DataTypes.h"
29 
30 // This needs to be outside of the namespace, to avoid conflict with llvm-c
31 // decl.
32 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
33 
34 namespace llvm {
35 
36 class Value;
37 class StructType;
38 class StructLayout;
39 class Triple;
40 class GlobalVariable;
41 class LLVMContext;
42 template<typename T>
43 class ArrayRef;
44 
45 /// Enum used to categorize the alignment types stored by LayoutAlignElem
49  VECTOR_ALIGN = 'v',
50  FLOAT_ALIGN = 'f',
52 };
53 
54 // FIXME: Currently the DataLayout string carries a "preferred alignment"
55 // for types. As the DataLayout is module/global, this should likely be
56 // sunk down to an FTTI element that is queried rather than a global
57 // preference.
58 
59 /// \brief Layout alignment element.
60 ///
61 /// Stores the alignment data associated with a given alignment type (integer,
62 /// vector, float) and type bit width.
63 ///
64 /// \note The unusual order of elements in the structure attempts to reduce
65 /// padding and make the structure slightly more cache friendly.
67  /// \brief Alignment type from \c AlignTypeEnum
68  unsigned AlignType : 8;
69  unsigned TypeBitWidth : 24;
70  unsigned ABIAlign : 16;
71  unsigned PrefAlign : 16;
72 
73  static LayoutAlignElem get(AlignTypeEnum align_type, unsigned abi_align,
74  unsigned pref_align, uint32_t bit_width);
75  bool operator==(const LayoutAlignElem &rhs) const;
76 };
77 
78 /// \brief Layout pointer alignment element.
79 ///
80 /// Stores the alignment data associated with a given pointer and address space.
81 ///
82 /// \note The unusual order of elements in the structure attempts to reduce
83 /// padding and make the structure slightly more cache friendly.
85  unsigned ABIAlign;
86  unsigned PrefAlign;
89 
90  /// Initializer
91  static PointerAlignElem get(uint32_t AddressSpace, unsigned ABIAlign,
92  unsigned PrefAlign, uint32_t TypeByteWidth);
93  bool operator==(const PointerAlignElem &rhs) const;
94 };
95 
96 /// \brief A parsed version of the target data layout string in and methods for
97 /// querying it.
98 ///
99 /// The target data layout string is specified *by the target* - a frontend
100 /// generating LLVM IR is required to generate the right target data for the
101 /// target being codegen'd to.
102 class DataLayout {
103 private:
104  /// Defaults to false.
105  bool BigEndian;
106 
107  unsigned StackNaturalAlign;
108 
109  enum ManglingModeT {
110  MM_None,
111  MM_ELF,
112  MM_MachO,
113  MM_WinCOFF,
114  MM_WinCOFFX86,
115  MM_Mips
116  };
117  ManglingModeT ManglingMode;
118 
119  SmallVector<unsigned char, 8> LegalIntWidths;
120 
121  /// \brief Primitive type alignment data.
123 
124  /// \brief The string representation used to create this DataLayout
125  std::string StringRepresentation;
126 
128  PointersTy Pointers;
129 
131  findPointerLowerBound(uint32_t AddressSpace) const {
132  return const_cast<DataLayout *>(this)->findPointerLowerBound(AddressSpace);
133  }
134 
135  PointersTy::iterator findPointerLowerBound(uint32_t AddressSpace);
136 
137  /// This member is a signal that a requested alignment type and bit width were
138  /// not found in the SmallVector.
139  static const LayoutAlignElem InvalidAlignmentElem;
140 
141  /// This member is a signal that a requested pointer type and bit width were
142  /// not found in the DenseSet.
143  static const PointerAlignElem InvalidPointerElem;
144 
145  // The StructType -> StructLayout map.
146  mutable void *LayoutMap;
147 
148  /// Pointers in these address spaces are non-integral, and don't have a
149  /// well-defined bitwise representation.
150  SmallVector<unsigned, 8> NonIntegralAddressSpaces;
151 
152  void setAlignment(AlignTypeEnum align_type, unsigned abi_align,
153  unsigned pref_align, uint32_t bit_width);
154  unsigned getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
155  bool ABIAlign, Type *Ty) const;
156  void setPointerAlignment(uint32_t AddrSpace, unsigned ABIAlign,
157  unsigned PrefAlign, uint32_t TypeByteWidth);
158 
159  /// Internal helper method that returns requested alignment for type.
160  unsigned getAlignment(Type *Ty, bool abi_or_pref) const;
161 
162  /// \brief Valid alignment predicate.
163  ///
164  /// Predicate that tests a LayoutAlignElem reference returned by get() against
165  /// InvalidAlignmentElem.
166  bool validAlignment(const LayoutAlignElem &align) const {
167  return &align != &InvalidAlignmentElem;
168  }
169 
170  /// \brief Valid pointer predicate.
171  ///
172  /// Predicate that tests a PointerAlignElem reference returned by get()
173  /// against \c InvalidPointerElem.
174  bool validPointer(const PointerAlignElem &align) const {
175  return &align != &InvalidPointerElem;
176  }
177 
178  /// Parses a target data specification string. Assert if the string is
179  /// malformed.
180  void parseSpecifier(StringRef LayoutDescription);
181 
182  // Free all internal data structures.
183  void clear();
184 
185 public:
186  /// Constructs a DataLayout from a specification string. See reset().
187  explicit DataLayout(StringRef LayoutDescription) : LayoutMap(nullptr) {
188  reset(LayoutDescription);
189  }
190 
191  /// Initialize target data from properties stored in the module.
192  explicit DataLayout(const Module *M);
193 
194  void init(const Module *M);
195 
196  DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
197 
199  clear();
200  StringRepresentation = DL.StringRepresentation;
201  BigEndian = DL.isBigEndian();
202  StackNaturalAlign = DL.StackNaturalAlign;
203  ManglingMode = DL.ManglingMode;
204  LegalIntWidths = DL.LegalIntWidths;
205  Alignments = DL.Alignments;
206  Pointers = DL.Pointers;
207  NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces;
208  return *this;
209  }
210 
211  bool operator==(const DataLayout &Other) const;
212  bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
213 
214  ~DataLayout(); // Not virtual, do not subclass this class
215 
216  /// Parse a data layout string (with fallback to default values).
217  void reset(StringRef LayoutDescription);
218 
219  /// Layout endianness...
220  bool isLittleEndian() const { return !BigEndian; }
221  bool isBigEndian() const { return BigEndian; }
222 
223  /// \brief Returns the string representation of the DataLayout.
224  ///
225  /// This representation is in the same format accepted by the string
226  /// constructor above. This should not be used to compare two DataLayout as
227  /// different string can represent the same layout.
228  const std::string &getStringRepresentation() const {
229  return StringRepresentation;
230  }
231 
232  /// \brief Test if the DataLayout was constructed from an empty string.
233  bool isDefault() const { return StringRepresentation.empty(); }
234 
235  /// \brief Returns true if the specified type is known to be a native integer
236  /// type supported by the CPU.
237  ///
238  /// For example, i64 is not native on most 32-bit CPUs and i37 is not native
239  /// on any known one. This returns false if the integer width is not legal.
240  ///
241  /// The width is specified in bits.
242  bool isLegalInteger(uint64_t Width) const {
243  for (unsigned LegalIntWidth : LegalIntWidths)
244  if (LegalIntWidth == Width)
245  return true;
246  return false;
247  }
248 
249  bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
250 
251  /// Returns true if the given alignment exceeds the natural stack alignment.
252  bool exceedsNaturalStackAlignment(unsigned Align) const {
253  return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
254  }
255 
256  unsigned getStackAlignment() const { return StackNaturalAlign; }
257 
259  return ManglingMode == MM_WinCOFFX86;
260  }
261 
262  bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; }
263 
265  if (ManglingMode == MM_MachO)
266  return "l";
267  return "";
268  }
269 
270  char getGlobalPrefix() const {
271  switch (ManglingMode) {
272  case MM_None:
273  case MM_ELF:
274  case MM_Mips:
275  case MM_WinCOFF:
276  return '\0';
277  case MM_MachO:
278  case MM_WinCOFFX86:
279  return '_';
280  }
281  llvm_unreachable("invalid mangling mode");
282  }
283 
285  switch (ManglingMode) {
286  case MM_None:
287  return "";
288  case MM_ELF:
289  case MM_WinCOFF:
290  return ".L";
291  case MM_Mips:
292  return "$";
293  case MM_MachO:
294  case MM_WinCOFFX86:
295  return "L";
296  }
297  llvm_unreachable("invalid mangling mode");
298  }
299 
300  static const char *getManglingComponent(const Triple &T);
301 
302  /// \brief Returns true if the specified type fits in a native integer type
303  /// supported by the CPU.
304  ///
305  /// For example, if the CPU only supports i32 as a native integer type, then
306  /// i27 fits in a legal integer type but i45 does not.
307  bool fitsInLegalInteger(unsigned Width) const {
308  for (unsigned LegalIntWidth : LegalIntWidths)
309  if (Width <= LegalIntWidth)
310  return true;
311  return false;
312  }
313 
314  /// Layout pointer alignment
315  /// FIXME: The defaults need to be removed once all of
316  /// the backends/clients are updated.
317  unsigned getPointerABIAlignment(unsigned AS = 0) const;
318 
319  /// Return target's alignment for stack-based pointers
320  /// FIXME: The defaults need to be removed once all of
321  /// the backends/clients are updated.
322  unsigned getPointerPrefAlignment(unsigned AS = 0) const;
323 
324  /// Layout pointer size
325  /// FIXME: The defaults need to be removed once all of
326  /// the backends/clients are updated.
327  unsigned getPointerSize(unsigned AS = 0) const;
328 
329  /// Return the address spaces containing non-integral pointers. Pointers in
330  /// this address space don't have a well-defined bitwise representation.
332  return NonIntegralAddressSpaces;
333  }
334 
336  ArrayRef<unsigned> NonIntegralSpaces = getNonIntegralAddressSpaces();
337  return find(NonIntegralSpaces, PT->getAddressSpace()) !=
338  NonIntegralSpaces.end();
339  }
340 
341  bool isNonIntegralPointerType(Type *Ty) const {
342  auto *PTy = dyn_cast<PointerType>(Ty);
343  return PTy && isNonIntegralPointerType(PTy);
344  }
345 
346  /// Layout pointer size, in bits
347  /// FIXME: The defaults need to be removed once all of
348  /// the backends/clients are updated.
349  unsigned getPointerSizeInBits(unsigned AS = 0) const {
350  return getPointerSize(AS) * 8;
351  }
352 
353  /// Layout pointer size, in bits, based on the type. If this function is
354  /// called with a pointer type, then the type size of the pointer is returned.
355  /// If this function is called with a vector of pointers, then the type size
356  /// of the pointer is returned. This should only be called with a pointer or
357  /// vector of pointers.
358  unsigned getPointerTypeSizeInBits(Type *) const;
359 
360  unsigned getPointerTypeSize(Type *Ty) const {
361  return getPointerTypeSizeInBits(Ty) / 8;
362  }
363 
364  /// Size examples:
365  ///
366  /// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
367  /// ---- ---------- --------------- ---------------
368  /// i1 1 8 8
369  /// i8 8 8 8
370  /// i19 19 24 32
371  /// i32 32 32 32
372  /// i100 100 104 128
373  /// i128 128 128 128
374  /// Float 32 32 32
375  /// Double 64 64 64
376  /// X86_FP80 80 80 96
377  ///
378  /// [*] The alloc size depends on the alignment, and thus on the target.
379  /// These values are for x86-32 linux.
380 
381  /// \brief Returns the number of bits necessary to hold the specified type.
382  ///
383  /// For example, returns 36 for i36 and 80 for x86_fp80. The type passed must
384  /// have a size (Type::isSized() must return true).
385  uint64_t getTypeSizeInBits(Type *Ty) const;
386 
387  /// \brief Returns the maximum number of bytes that may be overwritten by
388  /// storing the specified type.
389  ///
390  /// For example, returns 5 for i36 and 10 for x86_fp80.
391  uint64_t getTypeStoreSize(Type *Ty) const {
392  return (getTypeSizeInBits(Ty) + 7) / 8;
393  }
394 
395  /// \brief Returns the maximum number of bits that may be overwritten by
396  /// storing the specified type; always a multiple of 8.
397  ///
398  /// For example, returns 40 for i36 and 80 for x86_fp80.
399  uint64_t getTypeStoreSizeInBits(Type *Ty) const {
400  return 8 * getTypeStoreSize(Ty);
401  }
402 
403  /// \brief Returns the offset in bytes between successive objects of the
404  /// specified type, including alignment padding.
405  ///
406  /// This is the amount that alloca reserves for this type. For example,
407  /// returns 12 or 16 for x86_fp80, depending on alignment.
408  uint64_t getTypeAllocSize(Type *Ty) const {
409  // Round up to the next alignment boundary.
411  }
412 
413  /// \brief Returns the offset in bits between successive objects of the
414  /// specified type, including alignment padding; always a multiple of 8.
415  ///
416  /// This is the amount that alloca reserves for this type. For example,
417  /// returns 96 or 128 for x86_fp80, depending on alignment.
418  uint64_t getTypeAllocSizeInBits(Type *Ty) const {
419  return 8 * getTypeAllocSize(Ty);
420  }
421 
422  /// \brief Returns the minimum ABI-required alignment for the specified type.
423  unsigned getABITypeAlignment(Type *Ty) const;
424 
425  /// \brief Returns the minimum ABI-required alignment for an integer type of
426  /// the specified bitwidth.
427  unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const;
428 
429  /// \brief Returns the preferred stack/global alignment for the specified
430  /// type.
431  ///
432  /// This is always at least as good as the ABI alignment.
433  unsigned getPrefTypeAlignment(Type *Ty) const;
434 
435  /// \brief Returns the preferred alignment for the specified type, returned as
436  /// log2 of the value (a shift amount).
437  unsigned getPreferredTypeAlignmentShift(Type *Ty) const;
438 
439  /// \brief Returns an integer type with size at least as big as that of a
440  /// pointer in the given address space.
441  IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const;
442 
443  /// \brief Returns an integer (vector of integer) type with size at least as
444  /// big as that of a pointer of the given pointer (vector of pointer) type.
445  Type *getIntPtrType(Type *) const;
446 
447  /// \brief Returns the smallest integer type with size at least as big as
448  /// Width bits.
449  Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const;
450 
451  /// \brief Returns the largest legal integer type, or null if none are set.
453  unsigned LargestSize = getLargestLegalIntTypeSizeInBits();
454  return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);
455  }
456 
457  /// \brief Returns the size of largest legal integer type size, or 0 if none
458  /// are set.
459  unsigned getLargestLegalIntTypeSizeInBits() const;
460 
461  /// \brief Returns the offset from the beginning of the type for the specified
462  /// indices.
463  ///
464  /// Note that this takes the element type, not the pointer type.
465  /// This is used to implement getelementptr.
466  int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
467 
468  /// \brief Returns a StructLayout object, indicating the alignment of the
469  /// struct, its size, and the offsets of its fields.
470  ///
471  /// Note that this information is lazily cached.
472  const StructLayout *getStructLayout(StructType *Ty) const;
473 
474  /// \brief Returns the preferred alignment of the specified global.
475  ///
476  /// This includes an explicitly requested alignment (if the global has one).
477  unsigned getPreferredAlignment(const GlobalVariable *GV) const;
478 
479  /// \brief Returns the preferred alignment of the specified global, returned
480  /// in log form.
481  ///
482  /// This includes an explicitly requested alignment (if the global has one).
483  unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
484 };
485 
487  return reinterpret_cast<DataLayout *>(P);
488 }
489 
491  return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
492 }
493 
494 /// Used to lazily calculate structure layout information for a target machine,
495 /// based on the DataLayout structure.
497  uint64_t StructSize;
498  unsigned StructAlignment;
499  unsigned IsPadded : 1;
500  unsigned NumElements : 31;
501  uint64_t MemberOffsets[1]; // variable sized array!
502 public:
503  uint64_t getSizeInBytes() const { return StructSize; }
504 
505  uint64_t getSizeInBits() const { return 8 * StructSize; }
506 
507  unsigned getAlignment() const { return StructAlignment; }
508 
509  /// Returns whether the struct has padding or not between its fields.
510  /// NB: Padding in nested element is not taken into account.
511  bool hasPadding() const { return IsPadded; }
512 
513  /// \brief Given a valid byte offset into the structure, returns the structure
514  /// index that contains it.
515  unsigned getElementContainingOffset(uint64_t Offset) const;
516 
517  uint64_t getElementOffset(unsigned Idx) const {
518  assert(Idx < NumElements && "Invalid element idx!");
519  return MemberOffsets[Idx];
520  }
521 
522  uint64_t getElementOffsetInBits(unsigned Idx) const {
523  return getElementOffset(Idx) * 8;
524  }
525 
526 private:
527  friend class DataLayout; // Only DataLayout can create this class
528  StructLayout(StructType *ST, const DataLayout &DL);
529 };
530 
531 // The implementation of this method is provided inline as it is particularly
532 // well suited to constant folding when called on a specific Type subclass.
533 inline uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
534  assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
535  switch (Ty->getTypeID()) {
536  case Type::LabelTyID:
537  return getPointerSizeInBits(0);
538  case Type::PointerTyID:
540  case Type::ArrayTyID: {
541  ArrayType *ATy = cast<ArrayType>(Ty);
542  return ATy->getNumElements() *
544  }
545  case Type::StructTyID:
546  // Get the layout annotation... which is lazily created on demand.
547  return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
548  case Type::IntegerTyID:
549  return Ty->getIntegerBitWidth();
550  case Type::HalfTyID:
551  return 16;
552  case Type::FloatTyID:
553  return 32;
554  case Type::DoubleTyID:
555  case Type::X86_MMXTyID:
556  return 64;
557  case Type::PPC_FP128TyID:
558  case Type::FP128TyID:
559  return 128;
560  // In memory objects this is always aligned to a higher boundary, but
561  // only 80 bits contain information.
562  case Type::X86_FP80TyID:
563  return 80;
564  case Type::VectorTyID: {
565  VectorType *VTy = cast<VectorType>(Ty);
566  return VTy->getNumElements() * getTypeSizeInBits(VTy->getElementType());
567  }
568  default:
569  llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
570  }
571 }
572 
573 } // End llvm namespace
574 
575 #endif
7: Labels
Definition: Type.h:63
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:284
bool hasPadding() const
Returns whether the struct has padding or not between its fields.
Definition: DataLayout.h:511
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:178
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:335
uint64_t getSizeInBits() const
Definition: DataLayout.h:505
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Definition: DataLayout.h:46
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:264
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
2: 32-bit floating point type
Definition: Type.h:58
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:617
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:699
iterator end() const
Definition: ArrayRef.h:130
unsigned 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:599
unsigned getStackAlignment() const
Definition: DataLayout.h:256
unsigned getAlignment() const
Definition: DataLayout.h:507
13: Structures
Definition: Type.h:72
4: 80-bit floating point type (X87)
Definition: Type.h:60
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:664
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:471
1: 16-bit floating point type
Definition: Type.h:57
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition: DataLayout.h:233
bool operator==(const DataLayout &Other) const
Definition: DataLayout.cpp:401
15: Pointers
Definition: Type.h:74
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:155
char getGlobalPrefix() const
Definition: DataLayout.h:270
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:418
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:360
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:496
bool hasMicrosoftFastStdCallMangling() const
Definition: DataLayout.h:258
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:566
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:191
unsigned getPreferredTypeAlignmentShift(Type *Ty) const
Returns the preferred alignment for the specified type, returned as log2 of the value (a shift amount...
Definition: DataLayout.cpp:703
unsigned getPointerABIAlignment(unsigned AS=0) const
Layout pointer alignment FIXME: The defaults need to be removed once all of the backends/clients are ...
Definition: DataLayout.cpp:590
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:228
Class to represent struct types.
Definition: DerivedTypes.h:199
DataLayout(const DataLayout &DL)
Definition: DataLayout.h:196
DataLayout & operator=(const DataLayout &DL)
Definition: DataLayout.h:198
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:724
Class to represent array types.
Definition: DerivedTypes.h:345
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:220
Type * getElementType() const
Definition: DerivedTypes.h:336
Class to represent pointers.
Definition: DerivedTypes.h:443
Layout pointer alignment element.
Definition: DataLayout.h:84
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:517
uint64_t getElementOffsetInBits(unsigned Idx) const
Definition: DataLayout.h:522
11: Arbitrary bit width integers
Definition: Type.h:70
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:254
#define P(N)
unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.cpp:695
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
uint64_t 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:399
bool isIllegalInteger(uint64_t Width) const
Definition: DataLayout.h:249
uint32_t Offset
uint64_t getNumElements() const
Definition: DerivedTypes.h:335
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
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:736
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:96
Class to represent integer types.
Definition: DerivedTypes.h:39
Type * getLargestLegalIntType(LLVMContext &C) const
Returns the largest legal integer type, or null if none are set.
Definition: DataLayout.h:452
bool operator==(const LayoutAlignElem &rhs) const
Definition: DataLayout.cpp:114
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:767
bool operator!=(const DataLayout &Other) const
Definition: DataLayout.h:212
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global, returned in log form.
Definition: DataLayout.cpp:791
14: Arrays
Definition: Type.h:73
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:709
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:689
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU...
Definition: DataLayout.h:307
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:757
16: SIMD 'packed' format, or other vector type
Definition: Type.h:75
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:408
bool isNonIntegralPointerType(Type *Ty) const
Definition: DataLayout.h:341
AddressSpace
Definition: NVPTXBaseInfo.h:22
uint64_t getSizeInBytes() const
Definition: DataLayout.h:503
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:173
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
Definition: DataLayout.cpp:79
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Class to represent vector types.
Definition: DerivedTypes.h:369
bool exceedsNaturalStackAlignment(unsigned Align) const
Returns true if the given alignment exceeds the natural stack alignment.
Definition: DataLayout.h:252
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
Definition: DataLayout.h:187
bool operator==(const PointerAlignElem &rhs) const
Definition: DataLayout.cpp:141
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:186
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:262
Layout alignment element.
Definition: DataLayout.h:66
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:349
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:287
unsigned AlignType
Alignment type from AlignTypeEnum.
Definition: DataLayout.h:68
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:391
3: 64-bit floating point type
Definition: Type.h:59
ArrayRef< unsigned > getNonIntegralAddressSpaces() const
Return the address spaces containing non-integral pointers.
Definition: DataLayout.h:331
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:533
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:731
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:242
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:65
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:608
bool isBigEndian() const
Definition: DataLayout.h:221
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:479
void init(const Module *M)
Definition: DataLayout.cpp:399
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:32
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61