LLVM  14.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 ABIAlign, Align PrefAlign,
129  uint32_t TypeBitWidth,
130  uint32_t IndexBitWidth) {
131  assert(ABIAlign <= PrefAlign && "Preferred alignment worse than ABI!");
132  PointerAlignElem retval;
133  retval.AddressSpace = AddressSpace;
134  retval.ABIAlign = ABIAlign;
135  retval.PrefAlign = PrefAlign;
136  retval.TypeBitWidth = TypeBitWidth;
137  retval.IndexBitWidth = IndexBitWidth;
138  return retval;
139 }
140 
141 bool
143  return (ABIAlign == rhs.ABIAlign && AddressSpace == rhs.AddressSpace &&
144  PrefAlign == rhs.PrefAlign && TypeBitWidth == rhs.TypeBitWidth &&
146 }
147 
148 //===----------------------------------------------------------------------===//
149 // DataLayout Class Implementation
150 //===----------------------------------------------------------------------===//
151 
153  if (T.isOSBinFormatGOFF())
154  return "-m:l";
155  if (T.isOSBinFormatMachO())
156  return "-m:o";
157  if (T.isOSWindows() && T.isOSBinFormatCOFF())
158  return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
159  if (T.isOSBinFormatXCOFF())
160  return "-m:a";
161  return "-m:e";
162 }
163 
165  {INTEGER_ALIGN, 1, Align(1), Align(1)}, // i1
166  {INTEGER_ALIGN, 8, Align(1), Align(1)}, // i8
167  {INTEGER_ALIGN, 16, Align(2), Align(2)}, // i16
168  {INTEGER_ALIGN, 32, Align(4), Align(4)}, // i32
169  {INTEGER_ALIGN, 64, Align(4), Align(8)}, // i64
170  {FLOAT_ALIGN, 16, Align(2), Align(2)}, // half, bfloat
171  {FLOAT_ALIGN, 32, Align(4), Align(4)}, // float
172  {FLOAT_ALIGN, 64, Align(8), Align(8)}, // double
173  {FLOAT_ALIGN, 128, Align(16), Align(16)}, // ppcf128, quad, ...
174  {VECTOR_ALIGN, 64, Align(8), Align(8)}, // v2i32, v1i64, ...
175  {VECTOR_ALIGN, 128, Align(16), Align(16)}, // v16i8, v8i16, v4i32, ...
176  {AGGREGATE_ALIGN, 0, Align(1), Align(8)} // struct
177 };
178 
180  clear();
181 
182  LayoutMap = nullptr;
183  BigEndian = false;
184  AllocaAddrSpace = 0;
185  StackNaturalAlign.reset();
186  ProgramAddrSpace = 0;
187  DefaultGlobalsAddrSpace = 0;
188  FunctionPtrAlign.reset();
189  TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
190  ManglingMode = MM_None;
191  NonIntegralAddressSpaces.clear();
192 
193  // Default alignments
194  for (const LayoutAlignElem &E : DefaultAlignments) {
195  if (Error Err = setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign,
196  E.PrefAlign, E.TypeBitWidth))
197  return report_fatal_error(std::move(Err));
198  }
199  if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64))
200  return report_fatal_error(std::move(Err));
201 
202  if (Error Err = parseSpecifier(Desc))
203  return report_fatal_error(std::move(Err));
204 }
205 
207  DataLayout Layout("");
208  if (Error Err = Layout.parseSpecifier(LayoutDescription))
209  return std::move(Err);
210  return Layout;
211 }
212 
213 static Error reportError(const Twine &Message) {
214  return createStringError(inconvertibleErrorCode(), Message);
215 }
216 
217 /// Checked version of split, to ensure mandatory subparts.
218 static Error split(StringRef Str, char Separator,
219  std::pair<StringRef, StringRef> &Split) {
220  assert(!Str.empty() && "parse error, string can't be empty here");
221  Split = Str.split(Separator);
222  if (Split.second.empty() && Split.first != Str)
223  return reportError("Trailing separator in datalayout string");
224  if (!Split.second.empty() && Split.first.empty())
225  return reportError("Expected token before separator in datalayout string");
226  return Error::success();
227 }
228 
229 /// Get an unsigned integer, including error checks.
230 template <typename IntTy> static Error getInt(StringRef R, IntTy &Result) {
231  bool error = R.getAsInteger(10, Result); (void)error;
232  if (error)
233  return reportError("not a number, or does not fit in an unsigned int");
234  return Error::success();
235 }
236 
237 /// Get an unsigned integer representing the number of bits and convert it into
238 /// bytes. Error out of not a byte width multiple.
239 template <typename IntTy>
240 static Error getIntInBytes(StringRef R, IntTy &Result) {
241  if (Error Err = getInt<IntTy>(R, Result))
242  return Err;
243  if (Result % 8)
244  return reportError("number of bits must be a byte width multiple");
245  Result /= 8;
246  return Error::success();
247 }
248 
249 static Error getAddrSpace(StringRef R, unsigned &AddrSpace) {
250  if (Error Err = getInt(R, AddrSpace))
251  return Err;
252  if (!isUInt<24>(AddrSpace))
253  return reportError("Invalid address space, must be a 24-bit integer");
254  return Error::success();
255 }
256 
257 Error DataLayout::parseSpecifier(StringRef Desc) {
258  StringRepresentation = std::string(Desc);
259  while (!Desc.empty()) {
260  // Split at '-'.
261  std::pair<StringRef, StringRef> Split;
262  if (Error Err = ::split(Desc, '-', Split))
263  return Err;
264  Desc = Split.second;
265 
266  // Split at ':'.
267  if (Error Err = ::split(Split.first, ':', Split))
268  return Err;
269 
270  // Aliases used below.
271  StringRef &Tok = Split.first; // Current token.
272  StringRef &Rest = Split.second; // The rest of the string.
273 
274  if (Tok == "ni") {
275  do {
276  if (Error Err = ::split(Rest, ':', Split))
277  return Err;
278  Rest = Split.second;
279  unsigned AS;
280  if (Error Err = getInt(Split.first, AS))
281  return Err;
282  if (AS == 0)
283  return reportError("Address space 0 can never be non-integral");
284  NonIntegralAddressSpaces.push_back(AS);
285  } while (!Rest.empty());
286 
287  continue;
288  }
289 
290  char Specifier = Tok.front();
291  Tok = Tok.substr(1);
292 
293  switch (Specifier) {
294  case 's':
295  // Deprecated, but ignoring here to preserve loading older textual llvm
296  // ASM file
297  break;
298  case 'E':
299  BigEndian = true;
300  break;
301  case 'e':
302  BigEndian = false;
303  break;
304  case 'p': {
305  // Address space.
306  unsigned AddrSpace = 0;
307  if (!Tok.empty())
308  if (Error Err = getInt(Tok, AddrSpace))
309  return Err;
310  if (!isUInt<24>(AddrSpace))
311  return reportError("Invalid address space, must be a 24bit integer");
312 
313  // Size.
314  if (Rest.empty())
315  return reportError(
316  "Missing size specification for pointer in datalayout string");
317  if (Error Err = ::split(Rest, ':', Split))
318  return Err;
319  unsigned PointerMemSize;
320  if (Error Err = getInt(Tok, PointerMemSize))
321  return Err;
322  if (!PointerMemSize)
323  return reportError("Invalid pointer size of 0 bytes");
324 
325  // ABI alignment.
326  if (Rest.empty())
327  return reportError(
328  "Missing alignment specification for pointer in datalayout string");
329  if (Error Err = ::split(Rest, ':', Split))
330  return Err;
331  unsigned PointerABIAlign;
332  if (Error Err = getIntInBytes(Tok, PointerABIAlign))
333  return Err;
334  if (!isPowerOf2_64(PointerABIAlign))
335  return reportError("Pointer ABI alignment must be a power of 2");
336 
337  // Size of index used in GEP for address calculation.
338  // The parameter is optional. By default it is equal to size of pointer.
339  unsigned IndexSize = PointerMemSize;
340 
341  // Preferred alignment.
342  unsigned PointerPrefAlign = PointerABIAlign;
343  if (!Rest.empty()) {
344  if (Error Err = ::split(Rest, ':', Split))
345  return Err;
346  if (Error Err = getIntInBytes(Tok, PointerPrefAlign))
347  return Err;
348  if (!isPowerOf2_64(PointerPrefAlign))
349  return reportError(
350  "Pointer preferred alignment must be a power of 2");
351 
352  // Now read the index. It is the second optional parameter here.
353  if (!Rest.empty()) {
354  if (Error Err = ::split(Rest, ':', Split))
355  return Err;
356  if (Error Err = getInt(Tok, IndexSize))
357  return Err;
358  if (!IndexSize)
359  return reportError("Invalid index size of 0 bytes");
360  }
361  }
362  if (Error Err = setPointerAlignmentInBits(
363  AddrSpace, assumeAligned(PointerABIAlign),
364  assumeAligned(PointerPrefAlign), PointerMemSize, IndexSize))
365  return Err;
366  break;
367  }
368  case 'i':
369  case 'v':
370  case 'f':
371  case 'a': {
372  AlignTypeEnum AlignType;
373  switch (Specifier) {
374  default: llvm_unreachable("Unexpected specifier!");
375  case 'i': AlignType = INTEGER_ALIGN; break;
376  case 'v': AlignType = VECTOR_ALIGN; break;
377  case 'f': AlignType = FLOAT_ALIGN; break;
378  case 'a': AlignType = AGGREGATE_ALIGN; break;
379  }
380 
381  // Bit size.
382  unsigned Size = 0;
383  if (!Tok.empty())
384  if (Error Err = getInt(Tok, Size))
385  return Err;
386 
387  if (AlignType == AGGREGATE_ALIGN && Size != 0)
388  return reportError(
389  "Sized aggregate specification in datalayout string");
390 
391  // ABI alignment.
392  if (Rest.empty())
393  return reportError(
394  "Missing alignment specification in datalayout string");
395  if (Error Err = ::split(Rest, ':', Split))
396  return Err;
397  unsigned ABIAlign;
398  if (Error Err = getIntInBytes(Tok, ABIAlign))
399  return Err;
400  if (AlignType != AGGREGATE_ALIGN && !ABIAlign)
401  return reportError(
402  "ABI alignment specification must be >0 for non-aggregate types");
403 
404  if (!isUInt<16>(ABIAlign))
405  return reportError("Invalid ABI alignment, must be a 16bit integer");
406  if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign))
407  return reportError("Invalid ABI alignment, must be a power of 2");
408 
409  // Preferred alignment.
410  unsigned PrefAlign = ABIAlign;
411  if (!Rest.empty()) {
412  if (Error Err = ::split(Rest, ':', Split))
413  return Err;
414  if (Error Err = getIntInBytes(Tok, PrefAlign))
415  return Err;
416  }
417 
418  if (!isUInt<16>(PrefAlign))
419  return reportError(
420  "Invalid preferred alignment, must be a 16bit integer");
421  if (PrefAlign != 0 && !isPowerOf2_64(PrefAlign))
422  return reportError("Invalid preferred alignment, must be a power of 2");
423 
424  if (Error Err = setAlignment(AlignType, assumeAligned(ABIAlign),
425  assumeAligned(PrefAlign), Size))
426  return Err;
427 
428  break;
429  }
430  case 'n': // Native integer types.
431  while (true) {
432  unsigned Width;
433  if (Error Err = getInt(Tok, Width))
434  return Err;
435  if (Width == 0)
436  return reportError(
437  "Zero width native integer type in datalayout string");
438  LegalIntWidths.push_back(Width);
439  if (Rest.empty())
440  break;
441  if (Error Err = ::split(Rest, ':', Split))
442  return Err;
443  }
444  break;
445  case 'S': { // Stack natural alignment.
446  uint64_t Alignment;
447  if (Error Err = getIntInBytes(Tok, Alignment))
448  return Err;
449  if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
450  return reportError("Alignment is neither 0 nor a power of 2");
451  StackNaturalAlign = MaybeAlign(Alignment);
452  break;
453  }
454  case 'F': {
455  switch (Tok.front()) {
456  case 'i':
457  TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
458  break;
459  case 'n':
460  TheFunctionPtrAlignType = FunctionPtrAlignType::MultipleOfFunctionAlign;
461  break;
462  default:
463  return reportError("Unknown function pointer alignment type in "
464  "datalayout string");
465  }
466  Tok = Tok.substr(1);
467  uint64_t Alignment;
468  if (Error Err = getIntInBytes(Tok, Alignment))
469  return Err;
470  if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
471  return reportError("Alignment is neither 0 nor a power of 2");
472  FunctionPtrAlign = MaybeAlign(Alignment);
473  break;
474  }
475  case 'P': { // Function address space.
476  if (Error Err = getAddrSpace(Tok, ProgramAddrSpace))
477  return Err;
478  break;
479  }
480  case 'A': { // Default stack/alloca address space.
481  if (Error Err = getAddrSpace(Tok, AllocaAddrSpace))
482  return Err;
483  break;
484  }
485  case 'G': { // Default address space for global variables.
486  if (Error Err = getAddrSpace(Tok, DefaultGlobalsAddrSpace))
487  return Err;
488  break;
489  }
490  case 'm':
491  if (!Tok.empty())
492  return reportError("Unexpected trailing characters after mangling "
493  "specifier in datalayout string");
494  if (Rest.empty())
495  return reportError("Expected mangling specifier in datalayout string");
496  if (Rest.size() > 1)
497  return reportError("Unknown mangling specifier in datalayout string");
498  switch(Rest[0]) {
499  default:
500  return reportError("Unknown mangling in datalayout string");
501  case 'e':
502  ManglingMode = MM_ELF;
503  break;
504  case 'l':
505  ManglingMode = MM_GOFF;
506  break;
507  case 'o':
508  ManglingMode = MM_MachO;
509  break;
510  case 'm':
511  ManglingMode = MM_Mips;
512  break;
513  case 'w':
514  ManglingMode = MM_WinCOFF;
515  break;
516  case 'x':
517  ManglingMode = MM_WinCOFFX86;
518  break;
519  case 'a':
520  ManglingMode = MM_XCOFF;
521  break;
522  }
523  break;
524  default:
525  return reportError("Unknown specifier in datalayout string");
526  break;
527  }
528  }
529 
530  return Error::success();
531 }
532 
534  init(M);
535 }
536 
537 void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
538 
539 bool DataLayout::operator==(const DataLayout &Other) const {
540  bool Ret = BigEndian == Other.BigEndian &&
541  AllocaAddrSpace == Other.AllocaAddrSpace &&
542  StackNaturalAlign == Other.StackNaturalAlign &&
543  ProgramAddrSpace == Other.ProgramAddrSpace &&
544  DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
545  FunctionPtrAlign == Other.FunctionPtrAlign &&
546  TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
547  ManglingMode == Other.ManglingMode &&
548  LegalIntWidths == Other.LegalIntWidths &&
549  Alignments == Other.Alignments && Pointers == Other.Pointers;
550  // Note: getStringRepresentation() might differs, it is not canonicalized
551  return Ret;
552 }
553 
555 DataLayout::findAlignmentLowerBound(AlignTypeEnum AlignType,
556  uint32_t BitWidth) {
557  auto Pair = std::make_pair((unsigned)AlignType, BitWidth);
558  return partition_point(Alignments, [=](const LayoutAlignElem &E) {
559  return std::make_pair(E.AlignType, E.TypeBitWidth) < Pair;
560  });
561 }
562 
563 Error DataLayout::setAlignment(AlignTypeEnum align_type, Align abi_align,
564  Align pref_align, uint32_t bit_width) {
565  // AlignmentsTy::ABIAlign and AlignmentsTy::PrefAlign were once stored as
566  // uint16_t, it is unclear if there are requirements for alignment to be less
567  // than 2^16 other than storage. In the meantime we leave the restriction as
568  // an assert. See D67400 for context.
569  assert(Log2(abi_align) < 16 && Log2(pref_align) < 16 && "Alignment too big");
570  if (!isUInt<24>(bit_width))
571  return reportError("Invalid bit width, must be a 24bit integer");
572  if (pref_align < abi_align)
573  return reportError(
574  "Preferred alignment cannot be less than the ABI alignment");
575 
576  AlignmentsTy::iterator I = findAlignmentLowerBound(align_type, bit_width);
577  if (I != Alignments.end() &&
578  I->AlignType == (unsigned)align_type && I->TypeBitWidth == bit_width) {
579  // Update the abi, preferred alignments.
580  I->ABIAlign = abi_align;
581  I->PrefAlign = pref_align;
582  } else {
583  // Insert before I to keep the vector sorted.
584  Alignments.insert(I, LayoutAlignElem::get(align_type, abi_align,
585  pref_align, bit_width));
586  }
587  return Error::success();
588 }
589 
590 const PointerAlignElem &
591 DataLayout::getPointerAlignElem(uint32_t AddressSpace) const {
592  if (AddressSpace != 0) {
593  auto I = lower_bound(Pointers, AddressSpace,
594  [](const PointerAlignElem &A, uint32_t AddressSpace) {
595  return A.AddressSpace < AddressSpace;
596  });
597  if (I != Pointers.end() && I->AddressSpace == AddressSpace)
598  return *I;
599  }
600 
601  assert(Pointers[0].AddressSpace == 0);
602  return Pointers[0];
603 }
604 
605 Error DataLayout::setPointerAlignmentInBits(uint32_t AddrSpace, Align ABIAlign,
606  Align PrefAlign,
607  uint32_t TypeBitWidth,
608  uint32_t IndexBitWidth) {
609  if (PrefAlign < ABIAlign)
610  return reportError(
611  "Preferred alignment cannot be less than the ABI alignment");
612 
613  auto I = lower_bound(Pointers, AddrSpace,
614  [](const PointerAlignElem &A, uint32_t AddressSpace) {
615  return A.AddressSpace < AddressSpace;
616  });
617  if (I == Pointers.end() || I->AddressSpace != AddrSpace) {
618  Pointers.insert(I,
619  PointerAlignElem::getInBits(AddrSpace, ABIAlign, PrefAlign,
620  TypeBitWidth, IndexBitWidth));
621  } else {
622  I->ABIAlign = ABIAlign;
623  I->PrefAlign = PrefAlign;
624  I->TypeBitWidth = TypeBitWidth;
625  I->IndexBitWidth = IndexBitWidth;
626  }
627  return Error::success();
628 }
629 
630 Align DataLayout::getIntegerAlignment(uint32_t BitWidth,
631  bool abi_or_pref) const {
632  auto I = findAlignmentLowerBound(INTEGER_ALIGN, BitWidth);
633  // If we don't have an exact match, use alignment of next larger integer
634  // type. If there is none, use alignment of largest integer type by going
635  // back one element.
636  if (I == Alignments.end() || I->AlignType != INTEGER_ALIGN)
637  --I;
638  assert(I->AlignType == INTEGER_ALIGN && "Must be integer alignment");
639  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
640 }
641 
642 namespace {
643 
644 class StructLayoutMap {
645  using LayoutInfoTy = DenseMap<StructType*, StructLayout*>;
646  LayoutInfoTy LayoutInfo;
647 
648 public:
649  ~StructLayoutMap() {
650  // Remove any layouts.
651  for (const auto &I : LayoutInfo) {
652  StructLayout *Value = I.second;
653  Value->~StructLayout();
654  free(Value);
655  }
656  }
657 
658  StructLayout *&operator[](StructType *STy) {
659  return LayoutInfo[STy];
660  }
661 };
662 
663 } // end anonymous namespace
664 
665 void DataLayout::clear() {
666  LegalIntWidths.clear();
667  Alignments.clear();
668  Pointers.clear();
669  delete static_cast<StructLayoutMap *>(LayoutMap);
670  LayoutMap = nullptr;
671 }
672 
674  clear();
675 }
676 
678  if (!LayoutMap)
679  LayoutMap = new StructLayoutMap();
680 
681  StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
682  StructLayout *&SL = (*STM)[Ty];
683  if (SL) return SL;
684 
685  // Otherwise, create the struct layout. Because it is variable length, we
686  // malloc it, then use placement new.
688  StructLayout::totalSizeToAlloc<uint64_t>(Ty->getNumElements()));
689 
690  // Set SL before calling StructLayout's ctor. The ctor could cause other
691  // entries to be added to TheMap, invalidating our reference.
692  SL = L;
693 
694  new (L) StructLayout(Ty, *this);
695 
696  return L;
697 }
698 
700  return getPointerAlignElem(AS).ABIAlign;
701 }
702 
704  return getPointerAlignElem(AS).PrefAlign;
705 }
706 
707 unsigned DataLayout::getPointerSize(unsigned AS) const {
708  return divideCeil(getPointerAlignElem(AS).TypeBitWidth, 8);
709 }
710 
711 unsigned DataLayout::getMaxIndexSize() const {
712  unsigned MaxIndexSize = 0;
713  for (auto &P : Pointers)
714  MaxIndexSize =
715  std::max(MaxIndexSize, (unsigned)divideCeil(P.TypeBitWidth, 8));
716 
717  return MaxIndexSize;
718 }
719 
721  assert(Ty->isPtrOrPtrVectorTy() &&
722  "This should only be called with a pointer or pointer vector type");
723  Ty = Ty->getScalarType();
724  return getPointerSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
725 }
726 
727 unsigned DataLayout::getIndexSize(unsigned AS) const {
728  return divideCeil(getPointerAlignElem(AS).IndexBitWidth, 8);
729 }
730 
732  assert(Ty->isPtrOrPtrVectorTy() &&
733  "This should only be called with a pointer or pointer vector type");
734  Ty = Ty->getScalarType();
735  return getIndexSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
736 }
737 
738 /*!
739  \param abi_or_pref Flag that determines which alignment is returned. true
740  returns the ABI alignment, false returns the preferred alignment.
741  \param Ty The underlying type for which alignment is determined.
742 
743  Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
744  == false) for the requested type \a Ty.
745  */
746 Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
747  assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
748  switch (Ty->getTypeID()) {
749  // Early escape for the non-numeric types.
750  case Type::LabelTyID:
751  return abi_or_pref ? getPointerABIAlignment(0) : getPointerPrefAlignment(0);
752  case Type::PointerTyID: {
753  unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
754  return abi_or_pref ? getPointerABIAlignment(AS)
756  }
757  case Type::ArrayTyID:
758  return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
759 
760  case Type::StructTyID: {
761  // Packed structure types always have an ABI alignment of one.
762  if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
763  return Align(1);
764 
765  // Get the layout annotation... which is lazily created on demand.
766  const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
767  const LayoutAlignElem &AggregateAlign = Alignments[0];
768  assert(AggregateAlign.AlignType == AGGREGATE_ALIGN &&
769  "Aggregate alignment must be first alignment entry");
770  const Align Align =
771  abi_or_pref ? AggregateAlign.ABIAlign : AggregateAlign.PrefAlign;
772  return std::max(Align, Layout->getAlignment());
773  }
774  case Type::IntegerTyID:
775  return getIntegerAlignment(Ty->getIntegerBitWidth(), abi_or_pref);
776  case Type::HalfTyID:
777  case Type::BFloatTyID:
778  case Type::FloatTyID:
779  case Type::DoubleTyID:
780  // PPC_FP128TyID and FP128TyID have different data contents, but the
781  // same size and alignment, so they look the same here.
782  case Type::PPC_FP128TyID:
783  case Type::FP128TyID:
784  case Type::X86_FP80TyID: {
785  unsigned BitWidth = getTypeSizeInBits(Ty).getFixedSize();
786  auto I = findAlignmentLowerBound(FLOAT_ALIGN, BitWidth);
787  if (I != Alignments.end() && I->AlignType == FLOAT_ALIGN &&
788  I->TypeBitWidth == BitWidth)
789  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
790 
791  // If we still couldn't find a reasonable default alignment, fall back
792  // to a simple heuristic that the alignment is the first power of two
793  // greater-or-equal to the store size of the type. This is a reasonable
794  // approximation of reality, and if the user wanted something less
795  // less conservative, they should have specified it explicitly in the data
796  // layout.
797  return Align(PowerOf2Ceil(BitWidth / 8));
798  }
799  case Type::X86_MMXTyID:
802  unsigned BitWidth = getTypeSizeInBits(Ty).getKnownMinSize();
803  auto I = findAlignmentLowerBound(VECTOR_ALIGN, BitWidth);
804  if (I != Alignments.end() && I->AlignType == VECTOR_ALIGN &&
805  I->TypeBitWidth == BitWidth)
806  return abi_or_pref ? I->ABIAlign : I->PrefAlign;
807 
808  // By default, use natural alignment for vector types. This is consistent
809  // with what clang and llvm-gcc do.
810  //
811  // We're only calculating a natural alignment, so it doesn't have to be
812  // based on the full size for scalable vectors. Using the minimum element
813  // count should be enough here.
814  return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinSize()));
815  }
816  case Type::X86_AMXTyID:
817  return Align(64);
818  default:
819  llvm_unreachable("Bad type for getAlignment!!!");
820  }
821 }
822 
823 /// TODO: Remove this function once the transition to Align is over.
825  return getABITypeAlign(Ty).value();
826 }
827 
829  return getAlignment(Ty, true);
830 }
831 
832 /// TODO: Remove this function once the transition to Align is over.
834  return getPrefTypeAlign(Ty).value();
835 }
836 
838  return getAlignment(Ty, false);
839 }
840 
842  unsigned AddressSpace) const {
844 }
845 
847  assert(Ty->isPtrOrPtrVectorTy() &&
848  "Expected a pointer or pointer vector type.");
849  unsigned NumBits = getPointerTypeSizeInBits(Ty);
850  IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
851  if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
852  return VectorType::get(IntTy, VecTy);
853  return IntTy;
854 }
855 
857  for (unsigned LegalIntWidth : LegalIntWidths)
858  if (Width <= LegalIntWidth)
859  return Type::getIntNTy(C, LegalIntWidth);
860  return nullptr;
861 }
862 
864  auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
865  return Max != LegalIntWidths.end() ? *Max : 0;
866 }
867 
869  assert(Ty->isPtrOrPtrVectorTy() &&
870  "Expected a pointer or pointer vector type.");
871  unsigned NumBits = getIndexTypeSizeInBits(Ty);
872  IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
873  if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
874  return VectorType::get(IntTy, VecTy);
875  return IntTy;
876 }
877 
879  ArrayRef<Value *> Indices) const {
880  int64_t Result = 0;
881 
883  GTI = gep_type_begin(ElemTy, Indices),
884  GTE = gep_type_end(ElemTy, Indices);
885  for (; GTI != GTE; ++GTI) {
886  Value *Idx = GTI.getOperand();
887  if (StructType *STy = GTI.getStructTypeOrNull()) {
888  assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx");
889  unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
890 
891  // Get structure layout information...
892  const StructLayout *Layout = getStructLayout(STy);
893 
894  // Add in the offset, as calculated by the structure layout info...
895  Result += Layout->getElementOffset(FieldNo);
896  } else {
897  // Get the array index and the size of each array element.
898  if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
899  Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType());
900  }
901  }
902 
903  return Result;
904 }
905 
907  // Skip over scalable or zero size elements. Also skip element sizes larger
908  // than the positive index space, because the arithmetic below may not be
909  // correct in that case.
910  unsigned BitWidth = Offset.getBitWidth();
911  if (ElemSize.isScalable() || ElemSize == 0 ||
912  !isUIntN(BitWidth - 1, ElemSize)) {
913  return APInt::getZero(BitWidth);
914  }
915 
916  APInt Index = Offset.sdiv(ElemSize);
917  Offset -= Index * ElemSize;
918  if (Offset.isNegative()) {
919  // Prefer a positive remaining offset to allow struct indexing.
920  --Index;
921  Offset += ElemSize;
922  assert(Offset.isNonNegative() && "Remaining offset shouldn't be negative");
923  }
924  return Index;
925 }
926 
928  APInt &Offset) const {
929  if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
930  ElemTy = ArrTy->getElementType();
931  return getElementIndex(getTypeAllocSize(ElemTy), Offset);
932  }
933 
934  if (auto *VecTy = dyn_cast<VectorType>(ElemTy)) {
935  ElemTy = VecTy->getElementType();
936  unsigned ElemSizeInBits = getTypeSizeInBits(ElemTy).getFixedSize();
937  // GEPs over non-multiple of 8 size vector elements are invalid.
938  if (ElemSizeInBits % 8 != 0)
939  return None;
940 
941  return getElementIndex(TypeSize::Fixed(ElemSizeInBits / 8), Offset);
942  }
943 
944  if (auto *STy = dyn_cast<StructType>(ElemTy)) {
945  const StructLayout *SL = getStructLayout(STy);
946  uint64_t IntOffset = Offset.getZExtValue();
947  if (IntOffset >= SL->getSizeInBytes())
948  return None;
949 
950  unsigned Index = SL->getElementContainingOffset(IntOffset);
951  Offset -= SL->getElementOffset(Index);
952  ElemTy = STy->getElementType(Index);
953  return APInt(32, Index);
954  }
955 
956  // Non-aggregate type.
957  return None;
958 }
959 
961  APInt &Offset) const {
962  assert(ElemTy->isSized() && "Element type must be sized");
963  SmallVector<APInt> Indices;
964  Indices.push_back(getElementIndex(getTypeAllocSize(ElemTy), Offset));
965  while (Offset != 0) {
967  if (!Index)
968  break;
969  Indices.push_back(*Index);
970  }
971 
972  return Indices;
973 }
974 
975 /// getPreferredAlign - Return the preferred alignment of the specified global.
976 /// This includes an explicitly requested alignment (if the global has one).
978  MaybeAlign GVAlignment = GV->getAlign();
979  // If a section is specified, always precisely honor explicit alignment,
980  // so we don't insert padding into a section we don't control.
981  if (GVAlignment && GV->hasSection())
982  return *GVAlignment;
983 
984  // If no explicit alignment is specified, compute the alignment based on
985  // the IR type. If an alignment is specified, increase it to match the ABI
986  // alignment of the IR type.
987  //
988  // FIXME: Not sure it makes sense to use the alignment of the type if
989  // there's already an explicit alignment specification.
990  Type *ElemType = GV->getValueType();
991  Align Alignment = getPrefTypeAlign(ElemType);
992  if (GVAlignment) {
993  if (*GVAlignment >= Alignment)
994  Alignment = *GVAlignment;
995  else
996  Alignment = std::max(*GVAlignment, getABITypeAlign(ElemType));
997  }
998 
999  // If no explicit alignment is specified, and the global is large, increase
1000  // the alignment to 16.
1001  // FIXME: Why 16, specifically?
1002  if (GV->hasInitializer() && !GVAlignment) {
1003  if (Alignment < Align(16)) {
1004  // If the global is not external, see if it is large. If so, give it a
1005  // larger alignment.
1006  if (getTypeSizeInBits(ElemType) > 128)
1007  Alignment = Align(16); // 16-byte alignment.
1008  }
1009  }
1010  return Alignment;
1011 }
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:148
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:263
llvm::isAligned
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition: Alignment.h:138
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: 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:1772
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:731
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:977
llvm::TypeSize::getFixedSize
ScalarTy getFixedSize() const
Definition: TypeSize.h:425
T
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:1759
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:82
GetElementPtrTypeIterator.h
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:308
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:1177
llvm::GlobalObject::getAlign
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:80
llvm::DataLayout::getPointerTypeSizeInBits
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:720
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:703
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:240
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
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:135
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:677
split
static Error split(StringRef Str, char Separator, std::pair< StringRef, StringRef > &Split)
Checked version of split, to ensure mandatory subparts.
Definition: DataLayout.cpp:218
llvm::DataLayout::getIndexType
Type * getIndexType(Type *PtrTy) const
Returns the type of a GEP index.
Definition: DataLayout.cpp:868
getAddrSpace
static Error getAddrSpace(StringRef R, unsigned &AddrSpace)
Definition: DataLayout.cpp:249
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:152
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
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
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:230
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:702
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:927
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:91
llvm::gep_type_end
gep_type_iterator gep_type_end(const User *GEP)
Definition: GetElementPtrTypeIterator.h:130
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:610
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:127
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:824
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:207
llvm::generic_gep_type_iterator::getOperand
Value * getOperand() const
Definition: GetElementPtrTypeIterator.h:76
llvm::TypeSize::Fixed
static TypeSize Fixed(ScalarTy MinVal)
Definition: TypeSize.h:422
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:455
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:828
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:143
llvm::DataLayout::getLargestLegalIntTypeSizeInBits
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:863
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:727
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::None
const NoneType None
Definition: None.h:23
llvm::INTEGER_ALIGN
@ INTEGER_ALIGN
Definition: DataLayout.h:55
llvm::Type::getIntegerBitWidth
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:97
Type.h
llvm::DataLayout::init
void init(const Module *M)
Definition: DataLayout.cpp:537
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:190
llvm::DataLayout::getPrefTypeAlign
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:837
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
getElementIndex
static APInt getElementIndex(TypeSize ElemSize, APInt &Offset)
Definition: DataLayout.cpp:906
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:104
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:742
llvm::isUInt< 16 >
constexpr bool isUInt< 16 >(uint64_t x)
Definition: MathExtras.h:408
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
llvm::DataLayout::~DataLayout
~DataLayout()
Definition: DataLayout.cpp:673
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:279
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:878
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:711
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:57
llvm::assumeAligned
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
Definition: Alignment.h:103
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:160
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: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:206
llvm::DataLayout::getPrefTypeAlignment
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:833
llvm::DataLayout::getPointerABIAlignment
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:699
SI
StandardInstrumentations SI(Debug, VerifyEach)
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:65
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:57
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:134
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:223
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:127
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:856
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
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:1797
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:841
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1241
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:245
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:652
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: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:157
llvm::PointerAlignElem::operator==
bool operator==(const PointerAlignElem &rhs) const
Definition: DataLayout.cpp:142
GlobalVariable.h
llvm::TypeSize
Definition: TypeSize.h:416
Casting.h
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:581
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:416
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:164
llvm::DataLayout::getGEPIndicesForOffset
SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
Definition: DataLayout.cpp:960
llvm::SmallVectorImpl< LayoutAlignElem >::iterator
typename SuperClass::iterator iterator
Definition: SmallVector.h:558
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:539
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
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:179
llvm::TypeSize::getKnownMinSize
ScalarTy getKnownMinSize() const
Definition: TypeSize.h:426
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
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: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:313
llvm::StructLayout::getAlignment
Align getAlignment() const
Definition: DataLayout.h:633
reportError
static Error reportError(const Twine &Message)
Definition: DataLayout.cpp:213
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:496
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:670
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:152
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:707
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1198
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:782
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