LLVM  16.0.0git
DataLayout.cpp
Go to the documentation of this file.
1 //===- DataLayout.cpp - Data size & alignment routines ---------------------==//
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.
11 //
12 // This structure should be created once, filled in if the defaults are not
13 // correct and then passed around by const&. None of the members functions
14 // require modification to the object.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/GlobalVariable.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/IR/Type.h"
28 #include "llvm/IR/Value.h"
29 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Error.h"
33 #include "llvm/Support/MemAlloc.h"
34 #include "llvm/Support/TypeSize.h"
35 #include <algorithm>
36 #include <cassert>
37 #include <cstdint>
38 #include <cstdlib>
39 #include <new>
40 #include <utility>
41 
42 using namespace llvm;
43 
44 //===----------------------------------------------------------------------===//
45 // Support for StructLayout
46 //===----------------------------------------------------------------------===//
47 
48 StructLayout::StructLayout(StructType *ST, const DataLayout &DL) {
49  assert(!ST->isOpaque() && "Cannot get layout of opaque structs");
50  StructSize = 0;
51  IsPadded = false;
52  NumElements = ST->getNumElements();
53 
54  // Loop over each of the elements, placing them in memory.
55  for (unsigned i = 0, e = NumElements; i != e; ++i) {
56  Type *Ty = ST->getElementType(i);
57  const Align TyAlign = ST->isPacked() ? Align(1) : DL.getABITypeAlign(Ty);
58 
59  // Add padding if necessary to align the data element properly.
60  if (!isAligned(TyAlign, StructSize)) {
61  IsPadded = true;
62  StructSize = alignTo(StructSize, TyAlign);
63  }
64 
65  // Keep track of maximum alignment constraint.
66  StructAlignment = std::max(TyAlign, StructAlignment);
67 
68  getMemberOffsets()[i] = StructSize;
69  // Consume space for this data item
70  StructSize += DL.getTypeAllocSize(Ty).getFixedValue();
71  }
72 
73  // Add padding to the end of the struct so that it could be put in an array
74  // and all array elements would be aligned correctly.
75  if (!isAligned(StructAlignment, StructSize)) {
76  IsPadded = true;
77  StructSize = alignTo(StructSize, StructAlignment);
78  }
79 }
80 
81 /// getElementContainingOffset - Given a valid offset into the structure,
82 /// return the structure index that contains it.
84  ArrayRef<uint64_t> MemberOffsets = getMemberOffsets();
85  auto SI = llvm::upper_bound(MemberOffsets, Offset);
86  assert(SI != MemberOffsets.begin() && "Offset not in structure type!");
87  --SI;
88  assert(*SI <= Offset && "upper_bound didn't work");
89  assert((SI == MemberOffsets.begin() || *(SI - 1) <= Offset) &&
90  (SI + 1 == MemberOffsets.end() || *(SI + 1) > Offset) &&
91  "Upper bound didn't work!");
92 
93  // Multiple fields can have the same offset if any of them are zero sized.
94  // For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop
95  // at the i32 element, because it is the last element at that offset. This is
96  // the right one to return, because anything after it will have a higher
97  // offset, implying that this element is non-empty.
98  return SI - MemberOffsets.begin();
99 }
100 
101 //===----------------------------------------------------------------------===//
102 // LayoutAlignElem, LayoutAlign support
103 //===----------------------------------------------------------------------===//
104 
106  Align pref_align, uint32_t bit_width) {
107  assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
108  LayoutAlignElem retval;
109  retval.AlignType = align_type;
110  retval.ABIAlign = abi_align;
111  retval.PrefAlign = pref_align;
112  retval.TypeBitWidth = bit_width;
113  return retval;
114 }
115 
116 bool
118  return (AlignType == rhs.AlignType
119  && ABIAlign == rhs.ABIAlign
120  && PrefAlign == rhs.PrefAlign
121  && TypeBitWidth == rhs.TypeBitWidth);
122 }
123 
124 //===----------------------------------------------------------------------===//
125 // PointerAlignElem, PointerAlign support
126 //===----------------------------------------------------------------------===//
127 
129  Align ABIAlign, Align PrefAlign,
130  uint32_t TypeBitWidth,
131  uint32_t IndexBitWidth) {
132  assert(ABIAlign <= PrefAlign && "Preferred alignment worse than ABI!");
133  PointerAlignElem retval;
134  retval.AddressSpace = AddressSpace;
135  retval.ABIAlign = ABIAlign;
136  retval.PrefAlign = PrefAlign;
137  retval.TypeBitWidth = TypeBitWidth;
138  retval.IndexBitWidth = IndexBitWidth;
139  return retval;
140 }
141 
142 bool
144  return (ABIAlign == rhs.ABIAlign && AddressSpace == rhs.AddressSpace &&
145  PrefAlign == rhs.PrefAlign && TypeBitWidth == rhs.TypeBitWidth &&
147 }
148 
149 //===----------------------------------------------------------------------===//
150 // DataLayout Class Implementation
151 //===----------------------------------------------------------------------===//
152 
154  if (T.isOSBinFormatGOFF())
155  return "-m:l";
156  if (T.isOSBinFormatMachO())
157  return "-m:o";
158  if (T.isOSWindows() && T.isOSBinFormatCOFF())
159  return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
160  if (T.isOSBinFormatXCOFF())
161  return "-m:a";
162  return "-m:e";
163 }
164 
166  {INTEGER_ALIGN, 1, Align(1), Align(1)}, // i1
167  {INTEGER_ALIGN, 8, Align(1), Align(1)}, // i8
168  {INTEGER_ALIGN, 16, Align(2), Align(2)}, // i16
169  {INTEGER_ALIGN, 32, Align(4), Align(4)}, // i32
170  {INTEGER_ALIGN, 64, Align(4), Align(8)}, // i64
171  {FLOAT_ALIGN, 16, Align(2), Align(2)}, // half, bfloat
172  {FLOAT_ALIGN, 32, Align(4), Align(4)}, // float
173  {FLOAT_ALIGN, 64, Align(8), Align(8)}, // double
174  {FLOAT_ALIGN, 128, Align(16), Align(16)}, // ppcf128, quad, ...
175  {VECTOR_ALIGN, 64, Align(8), Align(8)}, // v2i32, v1i64, ...
176  {VECTOR_ALIGN, 128, Align(16), Align(16)}, // v16i8, v8i16, v4i32, ...
177  {AGGREGATE_ALIGN, 0, Align(1), Align(8)} // struct
178 };
179 
181  clear();
182 
183  LayoutMap = nullptr;
184  BigEndian = false;
185  AllocaAddrSpace = 0;
186  StackNaturalAlign.reset();
187  ProgramAddrSpace = 0;
188  DefaultGlobalsAddrSpace = 0;
189  FunctionPtrAlign.reset();
190  TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
191  ManglingMode = MM_None;
192  NonIntegralAddressSpaces.clear();
193 
194  // Default alignments
195  for (const LayoutAlignElem &E : DefaultAlignments) {
196  if (Error Err = setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign,
197  E.PrefAlign, E.TypeBitWidth))
198  return report_fatal_error(std::move(Err));
199  }
200  if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64))
201  return report_fatal_error(std::move(Err));
202 
203  if (Error Err = parseSpecifier(Desc))
204  return report_fatal_error(std::move(Err));
205 }
206 
208  DataLayout Layout("");
209  if (Error Err = Layout.parseSpecifier(LayoutDescription))
210  return std::move(Err);
211  return Layout;
212 }
213 
214 static Error reportError(const Twine &Message) {
215  return createStringError(inconvertibleErrorCode(), Message);
216 }
217 
218 /// Checked version of split, to ensure mandatory subparts.
219 static Error split(StringRef Str, char Separator,
220  std::pair<StringRef, StringRef> &Split) {
221  assert(!Str.empty() && "parse error, string can't be empty here");
222  Split = Str.split(Separator);
223  if (Split.second.empty() && Split.first != Str)
224  return reportError("Trailing separator in datalayout string");
225  if (!Split.second.empty() && Split.first.empty())
226  return reportError("Expected token before separator in datalayout string");
227  return Error::success();
228 }
229 
230 /// Get an unsigned integer, including error checks.
231 template <typename IntTy> static Error getInt(StringRef R, IntTy &Result) {
232  bool error = R.getAsInteger(10, Result); (void)error;
233  if (error)
234  return reportError("not a number, or does not fit in an unsigned int");
235  return Error::success();
236 }
237 
238 /// Get an unsigned integer representing the number of bits and convert it into
239 /// bytes. Error out of not a byte width multiple.
240 template <typename IntTy>
241 static Error getIntInBytes(StringRef R, IntTy &Result) {
242  if (Error Err = getInt<IntTy>(R, Result))
243  return Err;
244  if (Result % 8)
245  return reportError("number of bits must be a byte width multiple");
246  Result /= 8;
247  return Error::success();
248 }
249 
250 static Error getAddrSpace(StringRef R, unsigned &AddrSpace) {
251  if (Error Err = getInt(R, AddrSpace))
252  return Err;
253  if (!isUInt<24>(AddrSpace))
254  return reportError("Invalid address space, must be a 24-bit integer");
255  return Error::success();
256 }
257 
258 Error DataLayout::parseSpecifier(StringRef Desc) {
259  StringRepresentation = std::string(Desc);
260  while (!Desc.empty()) {
261  // Split at '-'.
262  std::pair<StringRef, StringRef> Split;
263  if (Error Err = ::split(Desc, '-', Split))
264  return Err;
265  Desc = Split.second;
266 
267  // Split at ':'.
268  if (Error Err = ::split(Split.first, ':', Split))
269  return Err;
270 
271  // Aliases used below.
272  StringRef &Tok = Split.first; // Current token.
273  StringRef &Rest = Split.second; // The rest of the string.
274 
275  if (Tok == "ni") {
276  do {
277  if (Error Err = ::split(Rest, ':', Split))
278  return Err;
279  Rest = Split.second;
280  unsigned AS;
281  if (Error Err = getInt(Split.first, AS))
282  return Err;
283  if (AS == 0)
284  return reportError("Address space 0 can never be non-integral");
285  NonIntegralAddressSpaces.push_back(AS);
286  } while (!Rest.empty());
287 
288  continue;
289  }
290 
291  char Specifier = Tok.front();
292  Tok = Tok.substr(1);
293 
294  switch (Specifier) {
295  case 's':
296  // Deprecated, but ignoring here to preserve loading older textual llvm
297  // ASM file
298  break;
299  case 'E':
300  BigEndian = true;
301  break;
302  case 'e':
303  BigEndian = false;
304  break;
305  case 'p': {
306  // Address space.
307  unsigned AddrSpace = 0;
308  if (!Tok.empty())
309  if (Error Err = getInt(Tok, AddrSpace))
310  return Err;
311  if (!isUInt<24>(AddrSpace))
312  return reportError("Invalid address space, must be a 24bit integer");
313 
314  // Size.
315  if (Rest.empty())
316  return reportError(
317  "Missing size specification for pointer in datalayout string");
318  if (Error Err = ::split(Rest, ':', Split))
319  return Err;
320  unsigned PointerMemSize;
321  if (Error Err = getInt(Tok, PointerMemSize))
322  return Err;
323  if (!PointerMemSize)
324  return reportError("Invalid pointer size of 0 bytes");
325 
326  // ABI alignment.
327  if (Rest.empty())
328  return reportError(
329  "Missing alignment specification for pointer in datalayout string");
330  if (Error Err = ::split(Rest, ':', Split))
331  return Err;
332  unsigned PointerABIAlign;
333  if (Error Err = getIntInBytes(Tok, PointerABIAlign))
334  return Err;
335  if (!isPowerOf2_64(PointerABIAlign))
336  return reportError("Pointer ABI alignment must be a power of 2");
337 
338  // Size of index used in GEP for address calculation.
339  // The parameter is optional. By default it is equal to size of pointer.
340  unsigned IndexSize = PointerMemSize;
341 
342  // Preferred alignment.
343  unsigned PointerPrefAlign = PointerABIAlign;
344  if (!Rest.empty()) {
345  if (Error Err = ::split(Rest, ':', Split))
346  return Err;
347  if (Error Err = getIntInBytes(Tok, PointerPrefAlign))
348  return Err;
349  if (!isPowerOf2_64(PointerPrefAlign))
350  return reportError(
351  "Pointer preferred alignment must be a power of 2");
352 
353  // Now read the index. It is the second optional parameter here.
354  if (!Rest.empty()) {
355  if (Error Err = ::split(Rest, ':', Split))
356  return Err;
357  if (Error Err = getInt(Tok, IndexSize))
358  return Err;
359  if (!IndexSize)
360  return reportError("Invalid index size of 0 bytes");
361  }
362  }
363  if (Error Err = setPointerAlignmentInBits(
364  AddrSpace, assumeAligned(PointerABIAlign),
365  assumeAligned(PointerPrefAlign), PointerMemSize, IndexSize))
366  return Err;
367  break;
368  }
369  case 'i':
370  case 'v':
371  case 'f':
372  case 'a': {
373  AlignTypeEnum AlignType;
374  switch (Specifier) {
375  default: llvm_unreachable("Unexpected specifier!");
376  case 'i': AlignType = INTEGER_ALIGN; break;
377  case 'v': AlignType = VECTOR_ALIGN; break;
378  case 'f': AlignType = FLOAT_ALIGN; break;
379  case 'a': AlignType = AGGREGATE_ALIGN; break;
380  }
381 
382  // Bit size.
383  unsigned Size = 0;
384  if (!Tok.empty())
385  if (Error Err = getInt(Tok, Size))
386  return Err;
387 
388  if (AlignType == AGGREGATE_ALIGN && Size != 0)
389  return reportError(
390  "Sized aggregate specification in datalayout string");
391 
392  // ABI alignment.
393  if (Rest.empty())
394  return reportError(
395  "Missing alignment specification in datalayout string");
396  if (Error Err = ::split(Rest, ':', Split))
397  return Err;
398  unsigned ABIAlign;
399  if (Error Err = getIntInBytes(Tok, ABIAlign))
400  return Err;
401  if (AlignType != AGGREGATE_ALIGN && !ABIAlign)
402  return reportError(
403  "ABI alignment specification must be >0 for non-aggregate types");
404 
405  if (!isUInt<16>(ABIAlign))
406  return reportError("Invalid ABI alignment, must be a 16bit integer");
407  if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign))
408  return reportError("Invalid ABI alignment, must be a power of 2");
409 
410  // Preferred alignment.
411  unsigned PrefAlign = ABIAlign;
412  if (!Rest.empty()) {
413  if (Error Err = ::split(Rest, ':', Split))
414  return Err;
415  if (Error Err = getIntInBytes(Tok, PrefAlign))
416  return Err;
417  }
418 
419  if (!isUInt<16>(PrefAlign))
420  return reportError(
421  "Invalid preferred alignment, must be a 16bit integer");
422  if (PrefAlign != 0 && !isPowerOf2_64(PrefAlign))
423  return reportError("Invalid preferred alignment, must be a power of 2");
424 
425  if (Error Err = setAlignment(AlignType, assumeAligned(ABIAlign),
426  assumeAligned(PrefAlign), Size))
427  return Err;
428 
429  break;
430  }
431  case 'n': // Native integer types.
432  while (true) {
433  unsigned Width;
434  if (Error Err = getInt(Tok, Width))
435  return Err;
436  if (Width == 0)
437  return reportError(
438  "Zero width native integer type in datalayout string");
439  LegalIntWidths.push_back(Width);
440  if (Rest.empty())
441  break;
442  if (Error Err = ::split(Rest, ':', Split))
443  return Err;
444  }
445  break;
446  case 'S': { // Stack natural alignment.
447  uint64_t Alignment;
448  if (Error Err = getIntInBytes(Tok, Alignment))
449  return Err;
450  if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
451  return reportError("Alignment is neither 0 nor a power of 2");
452  StackNaturalAlign = MaybeAlign(Alignment);
453  break;
454  }
455  case 'F': {
456  switch (Tok.front()) {
457  case 'i':
458  TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
459  break;
460  case 'n':
461  TheFunctionPtrAlignType = FunctionPtrAlignType::MultipleOfFunctionAlign;
462  break;
463  default:
464  return reportError("Unknown function pointer alignment type in "
465  "datalayout string");
466  }
467  Tok = Tok.substr(1);
468  uint64_t Alignment;
469  if (Error Err = getIntInBytes(Tok, Alignment))
470  return Err;
471  if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
472  return reportError("Alignment is neither 0 nor a power of 2");
473  FunctionPtrAlign = MaybeAlign(Alignment);
474  break;
475  }
476  case 'P': { // Function address space.
477  if (Error Err = getAddrSpace(Tok, ProgramAddrSpace))
478  return Err;
479  break;
480  }
481  case 'A': { // Default stack/alloca address space.
482  if (Error Err = getAddrSpace(Tok, AllocaAddrSpace))
483  return Err;
484  break;
485  }
486  case 'G': { // Default address space for global variables.
487  if (Error Err = getAddrSpace(Tok, DefaultGlobalsAddrSpace))
488  return Err;
489  break;
490  }
491  case 'm':
492  if (!Tok.empty())
493  return reportError("Unexpected trailing characters after mangling "
494  "specifier in datalayout string");
495  if (Rest.empty())
496  return reportError("Expected mangling specifier in datalayout string");
497  if (Rest.size() > 1)
498  return reportError("Unknown mangling specifier in datalayout string");
499  switch(Rest[0]) {
500  default:
501  return reportError("Unknown mangling in datalayout string");
502  case 'e':
503  ManglingMode = MM_ELF;
504  break;
505  case 'l':
506  ManglingMode = MM_GOFF;
507  break;
508  case 'o':
509  ManglingMode = MM_MachO;
510  break;
511  case 'm':
512  ManglingMode = MM_Mips;
513  break;
514  case 'w':
515  ManglingMode = MM_WinCOFF;
516  break;
517  case 'x':
518  ManglingMode = MM_WinCOFFX86;
519  break;
520  case 'a':
521  ManglingMode = MM_XCOFF;
522  break;
523  }
524  break;
525  default:
526  return reportError("Unknown specifier in datalayout string");
527  break;
528  }
529  }
530 
531  return Error::success();
532 }
533 
535  init(M);
536 }
537 
538 void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
539 
540 bool DataLayout::operator==(const DataLayout &Other) const {
541  bool Ret = BigEndian == Other.BigEndian &&
542  AllocaAddrSpace == Other.AllocaAddrSpace &&
543  StackNaturalAlign == Other.StackNaturalAlign &&
544  ProgramAddrSpace == Other.ProgramAddrSpace &&
545  DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
546  FunctionPtrAlign == Other.FunctionPtrAlign &&
547  TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
548  ManglingMode == Other.ManglingMode &&
549  LegalIntWidths == Other.LegalIntWidths &&
550  Alignments == Other.Alignments && Pointers == Other.Pointers;
551  // Note: getStringRepresentation() might differs, it is not canonicalized
552  return Ret;
553 }
554 
556 DataLayout::findAlignmentLowerBound(AlignTypeEnum AlignType,
557  uint32_t BitWidth) {
558  auto Pair = std::make_pair((unsigned)AlignType, BitWidth);
559  return partition_point(Alignments, [=](const LayoutAlignElem &E) {
560  return std::make_pair(E.AlignType, E.TypeBitWidth) < Pair;
561  });
562 }
563 
564 Error DataLayout::setAlignment(AlignTypeEnum align_type, Align abi_align,
565  Align pref_align, uint32_t bit_width) {
566  // AlignmentsTy::ABIAlign and AlignmentsTy::PrefAlign were once stored as
567  // uint16_t, it is unclear if there are requirements for alignment to be less
568  // than 2^16 other than storage. In the meantime we leave the restriction as
569  // an assert. See D67400 for context.
570  assert(Log2(abi_align) < 16 && Log2(pref_align) < 16 && "Alignment too big");
571  if (!isUInt<24>(bit_width))
572  return reportError("Invalid bit width, must be a 24bit integer");
573  if (pref_align < abi_align)
574  return reportError(
575  "Preferred alignment cannot be less than the ABI alignment");
576 
577  AlignmentsTy::iterator I = findAlignmentLowerBound(align_type, bit_width);
578  if (I != Alignments.end() &&
579  I->AlignType == (unsigned)align_type && I->TypeBitWidth == bit_width) {
580  // Update the abi, preferred alignments.
581  I->ABIAlign = abi_align;
582  I->PrefAlign = pref_align;
583  } else {
584  // Insert before I to keep the vector sorted.
585  Alignments.insert(I, LayoutAlignElem::get(align_type, abi_align,
586  pref_align, bit_width));
587  }
588  return Error::success();
589 }
590 
591 const PointerAlignElem &
592 DataLayout::getPointerAlignElem(uint32_t AddressSpace) const {
593  if (AddressSpace != 0) {
594  auto I = lower_bound(Pointers, AddressSpace,
595  [](const PointerAlignElem &A, uint32_t AddressSpace) {
596  return A.AddressSpace < AddressSpace;
597  });
598  if (I != Pointers.end() && I->AddressSpace == AddressSpace)
599  return *I;
600  }
601 
602  assert(Pointers[0].AddressSpace == 0);
603  return Pointers[0];
604 }
605 
606 Error DataLayout::setPointerAlignmentInBits(uint32_t AddrSpace, Align ABIAlign,
607  Align PrefAlign,
608  uint32_t TypeBitWidth,
609  uint32_t IndexBitWidth) {
610  if (PrefAlign < ABIAlign)
611  return reportError(
612  "Preferred alignment cannot be less than the ABI alignment");
613 
614  auto I = lower_bound(Pointers, AddrSpace,
615  [](const PointerAlignElem &A, uint32_t AddressSpace) {
616  return A.AddressSpace < AddressSpace;
617  });
618  if (I == Pointers.end() || I->AddressSpace != AddrSpace) {
619  Pointers.insert(I,
620  PointerAlignElem::getInBits(AddrSpace, ABIAlign, PrefAlign,
621  TypeBitWidth, IndexBitWidth));
622  } else {
623  I->ABIAlign = ABIAlign;
624  I->PrefAlign = PrefAlign;
625  I->TypeBitWidth = TypeBitWidth;
626  I->IndexBitWidth = IndexBitWidth;
627  }
628  return Error::success();
629 }
630 
631 Align DataLayout::getIntegerAlignment(uint32_t BitWidth,
632  bool abi_or_pref) const {
633  auto I = findAlignmentLowerBound(INTEGER_ALIGN, BitWidth);
634  // If we don't have an exact match, use alignment of next larger integer
635  // type. If there is none, use alignment of largest integer type by going
636  // back one element.
637  if (I == Alignments.end() || I->AlignType != INTEGER_ALIGN)
638  --I;
639  assert(I->AlignType == INTEGER_ALIGN && "Must be integer alignment");
640  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
641 }
642 
643 namespace {
644 
645 class StructLayoutMap {
646  using LayoutInfoTy = DenseMap<StructType*, StructLayout*>;
647  LayoutInfoTy LayoutInfo;
648 
649 public:
650  ~StructLayoutMap() {
651  // Remove any layouts.
652  for (const auto &I : LayoutInfo) {
653  StructLayout *Value = I.second;
654  Value->~StructLayout();
655  free(Value);
656  }
657  }
658 
659  StructLayout *&operator[](StructType *STy) {
660  return LayoutInfo[STy];
661  }
662 };
663 
664 } // end anonymous namespace
665 
666 void DataLayout::clear() {
667  LegalIntWidths.clear();
668  Alignments.clear();
669  Pointers.clear();
670  delete static_cast<StructLayoutMap *>(LayoutMap);
671  LayoutMap = nullptr;
672 }
673 
675  clear();
676 }
677 
679  if (!LayoutMap)
680  LayoutMap = new StructLayoutMap();
681 
682  StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
683  StructLayout *&SL = (*STM)[Ty];
684  if (SL) return SL;
685 
686  // Otherwise, create the struct layout. Because it is variable length, we
687  // malloc it, then use placement new.
689  StructLayout::totalSizeToAlloc<uint64_t>(Ty->getNumElements()));
690 
691  // Set SL before calling StructLayout's ctor. The ctor could cause other
692  // entries to be added to TheMap, invalidating our reference.
693  SL = L;
694 
695  new (L) StructLayout(Ty, *this);
696 
697  return L;
698 }
699 
701  return getPointerAlignElem(AS).ABIAlign;
702 }
703 
705  return getPointerAlignElem(AS).PrefAlign;
706 }
707 
708 unsigned DataLayout::getPointerSize(unsigned AS) const {
709  return divideCeil(getPointerAlignElem(AS).TypeBitWidth, 8);
710 }
711 
712 unsigned DataLayout::getMaxIndexSize() const {
713  unsigned MaxIndexSize = 0;
714  for (auto &P : Pointers)
715  MaxIndexSize =
716  std::max(MaxIndexSize, (unsigned)divideCeil(P.TypeBitWidth, 8));
717 
718  return MaxIndexSize;
719 }
720 
722  assert(Ty->isPtrOrPtrVectorTy() &&
723  "This should only be called with a pointer or pointer vector type");
724  Ty = Ty->getScalarType();
725  return getPointerSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
726 }
727 
728 unsigned DataLayout::getIndexSize(unsigned AS) const {
729  return divideCeil(getPointerAlignElem(AS).IndexBitWidth, 8);
730 }
731 
733  assert(Ty->isPtrOrPtrVectorTy() &&
734  "This should only be called with a pointer or pointer vector type");
735  Ty = Ty->getScalarType();
736  return getIndexSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
737 }
738 
739 /*!
740  \param abi_or_pref Flag that determines which alignment is returned. true
741  returns the ABI alignment, false returns the preferred alignment.
742  \param Ty The underlying type for which alignment is determined.
743 
744  Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
745  == false) for the requested type \a Ty.
746  */
747 Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
748  assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
749  switch (Ty->getTypeID()) {
750  // Early escape for the non-numeric types.
751  case Type::LabelTyID:
752  return abi_or_pref ? getPointerABIAlignment(0) : getPointerPrefAlignment(0);
753  case Type::PointerTyID: {
754  unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
755  return abi_or_pref ? getPointerABIAlignment(AS)
757  }
758  case Type::ArrayTyID:
759  return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
760 
761  case Type::StructTyID: {
762  // Packed structure types always have an ABI alignment of one.
763  if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
764  return Align(1);
765 
766  // Get the layout annotation... which is lazily created on demand.
767  const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
768  const LayoutAlignElem &AggregateAlign = Alignments[0];
769  assert(AggregateAlign.AlignType == AGGREGATE_ALIGN &&
770  "Aggregate alignment must be first alignment entry");
771  const Align Align =
772  abi_or_pref ? AggregateAlign.ABIAlign : AggregateAlign.PrefAlign;
773  return std::max(Align, Layout->getAlignment());
774  }
775  case Type::IntegerTyID:
776  return getIntegerAlignment(Ty->getIntegerBitWidth(), abi_or_pref);
777  case Type::HalfTyID:
778  case Type::BFloatTyID:
779  case Type::FloatTyID:
780  case Type::DoubleTyID:
781  // PPC_FP128TyID and FP128TyID have different data contents, but the
782  // same size and alignment, so they look the same here.
783  case Type::PPC_FP128TyID:
784  case Type::FP128TyID:
785  case Type::X86_FP80TyID: {
786  unsigned BitWidth = getTypeSizeInBits(Ty).getFixedSize();
787  auto I = findAlignmentLowerBound(FLOAT_ALIGN, BitWidth);
788  if (I != Alignments.end() && I->AlignType == FLOAT_ALIGN &&
789  I->TypeBitWidth == BitWidth)
790  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
791 
792  // If we still couldn't find a reasonable default alignment, fall back
793  // to a simple heuristic that the alignment is the first power of two
794  // greater-or-equal to the store size of the type. This is a reasonable
795  // approximation of reality, and if the user wanted something less
796  // less conservative, they should have specified it explicitly in the data
797  // layout.
798  return Align(PowerOf2Ceil(BitWidth / 8));
799  }
800  case Type::X86_MMXTyID:
803  unsigned BitWidth = getTypeSizeInBits(Ty).getKnownMinSize();
804  auto I = findAlignmentLowerBound(VECTOR_ALIGN, BitWidth);
805  if (I != Alignments.end() && I->AlignType == VECTOR_ALIGN &&
806  I->TypeBitWidth == BitWidth)
807  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
808 
809  // By default, use natural alignment for vector types. This is consistent
810  // with what clang and llvm-gcc do.
811  //
812  // We're only calculating a natural alignment, so it doesn't have to be
813  // based on the full size for scalable vectors. Using the minimum element
814  // count should be enough here.
815  return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinSize()));
816  }
817  case Type::X86_AMXTyID:
818  return Align(64);
819  default:
820  llvm_unreachable("Bad type for getAlignment!!!");
821  }
822 }
823 
824 /// TODO: Remove this function once the transition to Align is over.
826  return getABITypeAlign(Ty).value();
827 }
828 
830  return getAlignment(Ty, true);
831 }
832 
833 /// TODO: Remove this function once the transition to Align is over.
835  return getPrefTypeAlign(Ty).value();
836 }
837 
839  return getAlignment(Ty, false);
840 }
841 
843  unsigned AddressSpace) const {
845 }
846 
848  assert(Ty->isPtrOrPtrVectorTy() &&
849  "Expected a pointer or pointer vector type.");
850  unsigned NumBits = getPointerTypeSizeInBits(Ty);
851  IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
852  if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
853  return VectorType::get(IntTy, VecTy);
854  return IntTy;
855 }
856 
858  for (unsigned LegalIntWidth : LegalIntWidths)
859  if (Width <= LegalIntWidth)
860  return Type::getIntNTy(C, LegalIntWidth);
861  return nullptr;
862 }
863 
865  auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
866  return Max != LegalIntWidths.end() ? *Max : 0;
867 }
868 
870  assert(Ty->isPtrOrPtrVectorTy() &&
871  "Expected a pointer or pointer vector type.");
872  unsigned NumBits = getIndexTypeSizeInBits(Ty);
873  IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
874  if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
875  return VectorType::get(IntTy, VecTy);
876  return IntTy;
877 }
878 
880  ArrayRef<Value *> Indices) const {
881  int64_t Result = 0;
882 
884  GTI = gep_type_begin(ElemTy, Indices),
885  GTE = gep_type_end(ElemTy, Indices);
886  for (; GTI != GTE; ++GTI) {
887  Value *Idx = GTI.getOperand();
888  if (StructType *STy = GTI.getStructTypeOrNull()) {
889  assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx");
890  unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
891 
892  // Get structure layout information...
893  const StructLayout *Layout = getStructLayout(STy);
894 
895  // Add in the offset, as calculated by the structure layout info...
896  Result += Layout->getElementOffset(FieldNo);
897  } else {
898  // Get the array index and the size of each array element.
899  if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
900  Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType());
901  }
902  }
903 
904  return Result;
905 }
906 
907 static APInt getElementIndex(TypeSize ElemSize, APInt &Offset) {
908  // Skip over scalable or zero size elements. Also skip element sizes larger
909  // than the positive index space, because the arithmetic below may not be
910  // correct in that case.
911  unsigned BitWidth = Offset.getBitWidth();
912  if (ElemSize.isScalable() || ElemSize == 0 ||
913  !isUIntN(BitWidth - 1, ElemSize)) {
914  return APInt::getZero(BitWidth);
915  }
916 
917  APInt Index = Offset.sdiv(ElemSize);
918  Offset -= Index * ElemSize;
919  if (Offset.isNegative()) {
920  // Prefer a positive remaining offset to allow struct indexing.
921  --Index;
922  Offset += ElemSize;
923  assert(Offset.isNonNegative() && "Remaining offset shouldn't be negative");
924  }
925  return Index;
926 }
927 
929  APInt &Offset) const {
930  if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
931  ElemTy = ArrTy->getElementType();
932  return getElementIndex(getTypeAllocSize(ElemTy), Offset);
933  }
934 
935  if (auto *VecTy = dyn_cast<VectorType>(ElemTy)) {
936  ElemTy = VecTy->getElementType();
937  unsigned ElemSizeInBits = getTypeSizeInBits(ElemTy).getFixedSize();
938  // GEPs over non-multiple of 8 size vector elements are invalid.
939  if (ElemSizeInBits % 8 != 0)
940  return std::nullopt;
941 
942  return getElementIndex(TypeSize::Fixed(ElemSizeInBits / 8), Offset);
943  }
944 
945  if (auto *STy = dyn_cast<StructType>(ElemTy)) {
946  const StructLayout *SL = getStructLayout(STy);
947  uint64_t IntOffset = Offset.getZExtValue();
948  if (IntOffset >= SL->getSizeInBytes())
949  return std::nullopt;
950 
951  unsigned Index = SL->getElementContainingOffset(IntOffset);
952  Offset -= SL->getElementOffset(Index);
953  ElemTy = STy->getElementType(Index);
954  return APInt(32, Index);
955  }
956 
957  // Non-aggregate type.
958  return std::nullopt;
959 }
960 
962  APInt &Offset) const {
963  assert(ElemTy->isSized() && "Element type must be sized");
964  SmallVector<APInt> Indices;
965  Indices.push_back(getElementIndex(getTypeAllocSize(ElemTy), Offset));
966  while (Offset != 0) {
967  Optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
968  if (!Index)
969  break;
970  Indices.push_back(*Index);
971  }
972 
973  return Indices;
974 }
975 
976 /// getPreferredAlign - Return the preferred alignment of the specified global.
977 /// This includes an explicitly requested alignment (if the global has one).
979  MaybeAlign GVAlignment = GV->getAlign();
980  // If a section is specified, always precisely honor explicit alignment,
981  // so we don't insert padding into a section we don't control.
982  if (GVAlignment && GV->hasSection())
983  return *GVAlignment;
984 
985  // If no explicit alignment is specified, compute the alignment based on
986  // the IR type. If an alignment is specified, increase it to match the ABI
987  // alignment of the IR type.
988  //
989  // FIXME: Not sure it makes sense to use the alignment of the type if
990  // there's already an explicit alignment specification.
991  Type *ElemType = GV->getValueType();
992  Align Alignment = getPrefTypeAlign(ElemType);
993  if (GVAlignment) {
994  if (*GVAlignment >= Alignment)
995  Alignment = *GVAlignment;
996  else
997  Alignment = std::max(*GVAlignment, getABITypeAlign(ElemType));
998  }
999 
1000  // If no explicit alignment is specified, and the global is large, increase
1001  // the alignment to 16.
1002  // FIXME: Why 16, specifically?
1003  if (GV->hasInitializer() && !GVAlignment) {
1004  if (Alignment < Align(16)) {
1005  // If the global is not external, see if it is large. If so, give it a
1006  // larger alignment.
1007  if (getTypeSizeInBits(ElemType) > 128)
1008  Alignment = Align(16); // 16-byte alignment.
1009  }
1010  }
1011  return Alignment;
1012 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
i
i
Definition: README.txt:29
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:156
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition: Type.h:75
llvm::PointerAlignElem::AddressSpace
uint32_t AddressSpace
Definition: DataLayout.h:96
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
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:283
llvm::isAligned
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition: Alignment.h:146
MathExtras.h
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::upper_bound
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1935
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::PointerAlignElem::IndexBitWidth
uint32_t IndexBitWidth
Definition: DataLayout.h:97
llvm::DataLayout::getIndexTypeSizeInBits
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Definition: DataLayout.cpp:732
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::generic_gep_type_iterator
Definition: GetElementPtrTypeIterator.h:31
llvm::DataLayout::getPreferredAlign
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:978
llvm::TypeSize::getFixedSize
ScalarTy getFixedSize() const
Definition: TypeSize.h:444
T
llvm::StringRef::front
char front() const
front - Get the first character in the string.
Definition: StringRef.h:140
llvm::PointerAlignElem
Layout pointer alignment element.
Definition: DataLayout.h:92
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1922
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::DataLayout::FunctionPtrAlignType::Independent
@ Independent
The function pointer alignment is independent of the function alignment.
llvm::DataLayout::getTypeSizeInBits
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:673
llvm::Triple::x86
@ x86
Definition: Triple.h:85
GetElementPtrTypeIterator.h
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:328
TypeSize.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::GlobalObject::getAlign
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:79
llvm::DataLayout::getPointerTypeSizeInBits
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:721
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:474
llvm::StructLayout::getMemberOffsets
MutableArrayRef< uint64_t > getMemberOffsets()
Definition: DataLayout.h:643
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:704
ErrorHandling.h
llvm::PointerAlignElem::TypeBitWidth
uint32_t TypeBitWidth
Definition: DataLayout.h:95
getIntInBytes
static Error getIntInBytes(StringRef R, IntTy &Result)
Get an unsigned integer representing the number of bits and convert it into bytes.
Definition: DataLayout.cpp:241
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::Type::X86_AMXTyID
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
Error.h
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:678
split
static Error split(StringRef Str, char Separator, std::pair< StringRef, StringRef > &Split)
Checked version of split, to ensure mandatory subparts.
Definition: DataLayout.cpp:219
llvm::DataLayout::getIndexType
Type * getIndexType(Type *PtrTy) const
Returns the type of a GEP index.
Definition: DataLayout.cpp:869
getAddrSpace
static Error getAddrSpace(StringRef R, unsigned &AddrSpace)
Definition: DataLayout.cpp:250
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
Module.h
llvm::DataLayout::getManglingComponent
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:153
error
#define error(X)
Definition: SymbolRecordMapping.cpp:14
llvm::Optional
Definition: APInt.h:33
llvm::AlignTypeEnum
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Definition: DataLayout.h:53
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
getInt
static Error getInt(StringRef R, IntTy &Result)
Get an unsigned integer, including error checks.
Definition: DataLayout.cpp:231
llvm::PowerOf2Ceil
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition: MathExtras.h:630
llvm::gep_type_begin
gep_type_iterator gep_type_begin(const User *GEP)
Definition: GetElementPtrTypeIterator.h:123
llvm::LinearPolySize::isScalable
bool isScalable() const
Returns whether the size is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:298
llvm::DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
llvm::APInt::getZero
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:177
llvm::DataLayout::getGEPIndexForOffset
Optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition: DataLayout.cpp:928
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:91
llvm::logicalview::LVOutputKind::Split
@ Split
llvm::gep_type_end
gep_type_iterator gep_type_end(const User *GEP)
Definition: GetElementPtrTypeIterator.h:130
llvm::AVR::getAddressSpace
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:64
llvm::DataLayout::getIndexSizeInBits
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition: DataLayout.h:422
llvm::PointerAlignElem::getInBits
static PointerAlignElem getInBits(uint32_t AddressSpace, Align ABIAlign, Align PrefAlign, uint32_t TypeBitWidth, uint32_t IndexBitWidth)
Initializer.
Definition: DataLayout.cpp:128
Constants.h
llvm::LayoutAlignElem::ABIAlign
Align ABIAlign
Definition: DataLayout.h:77
llvm::DataLayout::getABITypeAlignment
uint64_t getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:825
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:209
SI
@ SI
Definition: SIInstrInfo.cpp:7966
llvm::generic_gep_type_iterator::getOperand
Value * getOperand() const
Definition: GetElementPtrTypeIterator.h:76
llvm::StringRef::substr
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:564
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::TypeSize::Fixed
static TypeSize Fixed(ScalarTy MinVal)
Definition: TypeSize.h:441
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:422
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::DataLayout::getABITypeAlign
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:829
llvm::LayoutAlignElem
Layout alignment element.
Definition: DataLayout.h:73
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
llvm::DataLayout::getLargestLegalIntTypeSizeInBits
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:864
llvm::LayoutAlignElem::PrefAlign
Align PrefAlign
Definition: DataLayout.h:78
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition: Type.h:73
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::DataLayout::getIndexSize
unsigned getIndexSize(unsigned AS) const
rounded up to a whole number of bytes.
Definition: DataLayout.cpp:728
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::generic_gep_type_iterator::getStructTypeOrNull
StructType * getStructTypeOrNull() const
Definition: GetElementPtrTypeIterator.h:116
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::Type::BFloatTyID
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
llvm::INTEGER_ALIGN
@ INTEGER_ALIGN
Definition: DataLayout.h:55
MemAlloc.h
llvm::Type::getIntegerBitWidth
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:97
Type.h
llvm::DataLayout::init
void init(const Module *M)
Definition: DataLayout.cpp:538
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:210
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
llvm::DataLayout::getPrefTypeAlign
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:838
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
getElementIndex
static APInt getElementIndex(TypeSize ElemSize, APInt &Offset)
Definition: DataLayout.cpp:907
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:103
llvm::PointerAlignElem::ABIAlign
Align ABIAlign
Definition: DataLayout.h:93
llvm::divideCeil
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:683
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
llvm::DataLayout::~DataLayout
~DataLayout()
Definition: DataLayout.cpp:674
llvm::StructLayout
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:622
uint64_t
llvm::Optional::reset
void reset()
Definition: Optional.h:275
llvm::PointerAlignElem::PrefAlign
Align PrefAlign
Definition: DataLayout.h:94
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:879
llvm::FLOAT_ALIGN
@ FLOAT_ALIGN
Definition: DataLayout.h:57
llvm::Type::X86_MMXTyID
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
llvm::DataLayout::getMaxIndexSize
unsigned getMaxIndexSize() const
Returns the maximum index size over all address spaces.
Definition: DataLayout.cpp:712
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::assumeAligned
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
Definition: Alignment.h:111
llvm::DenseMap
Definition: DenseMap.h:714
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::StructLayout::getElementContainingOffset
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
Definition: DataLayout.cpp:83
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DataLayout::parse
static Expected< DataLayout > parse(StringRef LayoutDescription)
Parse a data layout string and return the layout.
Definition: DataLayout.cpp:207
llvm::DataLayout::getPrefTypeAlignment
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:834
llvm::DataLayout::getPointerABIAlignment
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:700
llvm::generic_gep_type_iterator::getIndexedType
Type * getIndexedType() const
Definition: GetElementPtrTypeIterator.h:70
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:66
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
Triple.h
llvm::Type::FP128TyID
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
llvm::ArrayRef< uint64_t >
DataLayout.h
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
llvm::Type::PPC_FP128TyID
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::StructLayout::getSizeInBytes
uint64_t getSizeInBytes() const
Definition: DataLayout.h:629
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
uint32_t
llvm::VECTOR_ALIGN
@ VECTOR_ALIGN
Definition: DataLayout.h:56
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Type::isPtrOrPtrVectorTy
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:243
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::StructType::getNumElements
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:327
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:857
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
llvm::partition_point
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:1960
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:842
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1238
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:243
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::LayoutAlignElem::operator==
bool operator==(const LayoutAlignElem &rhs) const
Definition: DataLayout.cpp:117
llvm::StructLayout::getElementOffset
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:652
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::AGGREGATE_ALIGN
@ AGGREGATE_ALIGN
Definition: DataLayout.h:58
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::PointerAlignElem::operator==
bool operator==(const PointerAlignElem &rhs) const
Definition: DataLayout.cpp:143
GlobalVariable.h
llvm::TypeSize
Definition: TypeSize.h:435
Casting.h
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:614
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:433
llvm::Type::LabelTyID
@ LabelTyID
Labels.
Definition: Type.h:64
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition: Type.h:74
llvm::DataLayout::DataLayout
DataLayout(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
Definition: DataLayout.h:202
DefaultAlignments
static const LayoutAlignElem DefaultAlignments[]
Definition: DataLayout.cpp:165
llvm::DataLayout::getGEPIndicesForOffset
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
Definition: DataLayout.cpp:961
llvm::SmallVectorImpl< LayoutAlignElem >::iterator
typename SuperClass::iterator iterator
Definition: SmallVector.h:581
llvm::LayoutAlignElem::get
static LayoutAlignElem get(AlignTypeEnum align_type, Align abi_align, Align pref_align, uint32_t bit_width)
Definition: DataLayout.cpp:105
llvm::DataLayout::operator==
bool operator==(const DataLayout &Other) const
Definition: DataLayout.cpp:540
llvm::LayoutAlignElem::AlignType
unsigned AlignType
Alignment type from AlignTypeEnum.
Definition: DataLayout.h:75
llvm::LayoutAlignElem::TypeBitWidth
unsigned TypeBitWidth
Definition: DataLayout.h:76
llvm::DataLayout::reset
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:180
llvm::TypeSize::getKnownMinSize
ScalarTy getKnownMinSize() const
Definition: TypeSize.h:445
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
DerivedTypes.h
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:292
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:412
llvm::IntegerType::get
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
llvm::StructLayout::getAlignment
Align getAlignment() const
Definition: DataLayout.h:633
reportError
static Error reportError(const Twine &Message)
Definition: DataLayout.cpp:214
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:463
Value.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::safe_malloc
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
Definition: MemAlloc.h:25
llvm::VectorType::get
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:668
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
llvm::Type::X86_FP80TyID
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
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:708
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1251
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:809
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:506