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