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