LLVM 22.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 = llvm::upper_bound(MemberOffsets, Offset,
100 [](TypeSize LHS, TypeSize RHS) -> bool {
101 return TypeSize::isKnownLT(LHS, RHS);
102 });
103 assert(SI != MemberOffsets.begin() && "Offset not in structure type!");
104 --SI;
105 assert(TypeSize::isKnownLE(*SI, Offset) && "upper_bound didn't work");
106 assert(
107 (SI == MemberOffsets.begin() || TypeSize::isKnownLE(*(SI - 1), Offset)) &&
108 (SI + 1 == MemberOffsets.end() ||
109 TypeSize::isKnownGT(*(SI + 1), Offset)) &&
110 "Upper bound didn't work!");
111
112 // Multiple fields can have the same offset if any of them are zero sized.
113 // For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop
114 // at the i32 element, because it is the last element at that offset. This is
115 // the right one to return, because anything after it will have a higher
116 // offset, implying that this element is non-empty.
117 return SI - MemberOffsets.begin();
118}
119
120namespace {
121
122class StructLayoutMap {
123 using LayoutInfoTy = DenseMap<StructType *, StructLayout *>;
124 LayoutInfoTy LayoutInfo;
125
126public:
127 ~StructLayoutMap() {
128 // Remove any layouts.
129 for (const auto &I : LayoutInfo) {
130 StructLayout *Value = I.second;
131 Value->~StructLayout();
132 free(Value);
133 }
134 }
135
136 StructLayout *&operator[](StructType *STy) { return LayoutInfo[STy]; }
137};
138
139} // end anonymous namespace
140
141//===----------------------------------------------------------------------===//
142// DataLayout Class Implementation
143//===----------------------------------------------------------------------===//
144
146 return BitWidth == Other.BitWidth && ABIAlign == Other.ABIAlign &&
147 PrefAlign == Other.PrefAlign;
148}
149
151 return AddrSpace == Other.AddrSpace && BitWidth == Other.BitWidth &&
152 ABIAlign == Other.ABIAlign && PrefAlign == Other.PrefAlign &&
153 IndexBitWidth == Other.IndexBitWidth &&
154 IsNonIntegral == Other.IsNonIntegral;
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 {8, Align::Constant<1>(), Align::Constant<1>()}, // i8:8:8
191 {16, Align::Constant<2>(), Align::Constant<2>()}, // i16:16:16
192 {32, Align::Constant<4>(), Align::Constant<4>()}, // i32:32:32
193 {64, Align::Constant<4>(), Align::Constant<8>()}, // i64:32:64
194};
196 {16, Align::Constant<2>(), Align::Constant<2>()}, // f16:16:16
197 {32, Align::Constant<4>(), Align::Constant<4>()}, // f32:32:32
198 {64, Align::Constant<8>(), Align::Constant<8>()}, // f64:64:64
199 {128, Align::Constant<16>(), Align::Constant<16>()}, // f128:128:128
200};
202 {64, Align::Constant<8>(), Align::Constant<8>()}, // v64:64:64
203 {128, Align::Constant<16>(), Align::Constant<16>()}, // v128:128:128
204};
205
206// Default pointer type specifications.
208 // p0:64:64:64:64
209 {0, 64, Align::Constant<8>(), Align::Constant<8>(), 64, false},
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 return *this;
243}
244
246 // NOTE: StringRepresentation might differ, it is not canonicalized.
247 return BigEndian == Other.BigEndian &&
248 AllocaAddrSpace == Other.AllocaAddrSpace &&
249 ProgramAddrSpace == Other.ProgramAddrSpace &&
250 DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
251 StackNaturalAlign == Other.StackNaturalAlign &&
252 FunctionPtrAlign == Other.FunctionPtrAlign &&
253 TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
254 ManglingMode == Other.ManglingMode &&
255 LegalIntWidths == Other.LegalIntWidths && IntSpecs == Other.IntSpecs &&
256 FloatSpecs == Other.FloatSpecs && VectorSpecs == Other.VectorSpecs &&
257 PointerSpecs == Other.PointerSpecs &&
258 StructABIAlignment == Other.StructABIAlignment &&
259 StructPrefAlignment == Other.StructPrefAlignment;
260}
261
263 DataLayout Layout;
264 if (Error Err = Layout.parseLayoutString(LayoutString))
265 return std::move(Err);
266 return Layout;
267}
268
270 return createStringError("malformed specification, must be of the form \"" +
271 Format + "\"");
272}
273
274/// Attempts to parse an address space component of a specification.
275static Error parseAddrSpace(StringRef Str, unsigned &AddrSpace) {
276 if (Str.empty())
277 return createStringError("address space component cannot be empty");
278
279 if (!to_integer(Str, AddrSpace, 10) || !isUInt<24>(AddrSpace))
280 return createStringError("address space must be a 24-bit integer");
281
282 return Error::success();
283}
284
285/// Attempts to parse a size component of a specification.
286static Error parseSize(StringRef Str, unsigned &BitWidth,
287 StringRef Name = "size") {
288 if (Str.empty())
289 return createStringError(Name + " component cannot be empty");
290
291 if (!to_integer(Str, BitWidth, 10) || BitWidth == 0 || !isUInt<24>(BitWidth))
292 return createStringError(Name + " must be a non-zero 24-bit integer");
293
294 return Error::success();
295}
296
297/// Attempts to parse an alignment component of a specification.
298///
299/// On success, returns the value converted to byte amount in \p Alignment.
300/// If the value is zero and \p AllowZero is true, \p Alignment is set to one.
301///
302/// Return an error in a number of cases:
303/// - \p Str is empty or contains characters other than decimal digits;
304/// - the value is zero and \p AllowZero is false;
305/// - the value is too large;
306/// - the value is not a multiple of the byte width;
307/// - the value converted to byte amount is not not a power of two.
308static Error parseAlignment(StringRef Str, Align &Alignment, StringRef Name,
309 bool AllowZero = false) {
310 if (Str.empty())
311 return createStringError(Name + " alignment component cannot be empty");
312
313 unsigned Value;
314 if (!to_integer(Str, Value, 10) || !isUInt<16>(Value))
315 return createStringError(Name + " alignment must be a 16-bit integer");
316
317 if (Value == 0) {
318 if (!AllowZero)
319 return createStringError(Name + " alignment must be non-zero");
320 Alignment = Align(1);
321 return Error::success();
322 }
323
324 constexpr unsigned ByteWidth = 8;
325 if (Value % ByteWidth || !isPowerOf2_32(Value / ByteWidth))
326 return createStringError(
327 Name + " alignment must be a power of two times the byte width");
328
329 Alignment = Align(Value / ByteWidth);
330 return Error::success();
331}
332
333Error DataLayout::parsePrimitiveSpec(StringRef Spec) {
334 // [ifv]<size>:<abi>[:<pref>]
335 SmallVector<StringRef, 3> Components;
336 char Specifier = Spec.front();
337 assert(Specifier == 'i' || Specifier == 'f' || Specifier == 'v');
338 Spec.drop_front().split(Components, ':');
339
340 if (Components.size() < 2 || Components.size() > 3)
341 return createSpecFormatError(Twine(Specifier) + "<size>:<abi>[:<pref>]");
342
343 // Size. Required, cannot be zero.
344 unsigned BitWidth;
345 if (Error Err = parseSize(Components[0], BitWidth))
346 return Err;
347
348 // ABI alignment.
349 Align ABIAlign;
350 if (Error Err = parseAlignment(Components[1], ABIAlign, "ABI"))
351 return Err;
352
353 if (Specifier == 'i' && BitWidth == 8 && ABIAlign != 1)
354 return createStringError("i8 must be 8-bit aligned");
355
356 // Preferred alignment. Optional, defaults to the ABI alignment.
357 Align PrefAlign = ABIAlign;
358 if (Components.size() > 2)
359 if (Error Err = parseAlignment(Components[2], PrefAlign, "preferred"))
360 return Err;
361
362 if (PrefAlign < ABIAlign)
363 return createStringError(
364 "preferred alignment cannot be less than the ABI alignment");
365
366 setPrimitiveSpec(Specifier, BitWidth, ABIAlign, PrefAlign);
367 return Error::success();
368}
369
370Error DataLayout::parseAggregateSpec(StringRef Spec) {
371 // a<size>:<abi>[:<pref>]
372 SmallVector<StringRef, 3> Components;
373 assert(Spec.front() == 'a');
374 Spec.drop_front().split(Components, ':');
375
376 if (Components.size() < 2 || Components.size() > 3)
377 return createSpecFormatError("a:<abi>[:<pref>]");
378
379 // According to LangRef, <size> component must be absent altogether.
380 // For backward compatibility, allow it to be specified, but require
381 // it to be zero.
382 if (!Components[0].empty()) {
383 unsigned BitWidth;
384 if (!to_integer(Components[0], BitWidth, 10) || BitWidth != 0)
385 return createStringError("size must be zero");
386 }
387
388 // ABI alignment. Required. Can be zero, meaning use one byte alignment.
389 Align ABIAlign;
390 if (Error Err =
391 parseAlignment(Components[1], ABIAlign, "ABI", /*AllowZero=*/true))
392 return Err;
393
394 // Preferred alignment. Optional, defaults to the ABI alignment.
395 Align PrefAlign = ABIAlign;
396 if (Components.size() > 2)
397 if (Error Err = parseAlignment(Components[2], PrefAlign, "preferred"))
398 return Err;
399
400 if (PrefAlign < ABIAlign)
401 return createStringError(
402 "preferred alignment cannot be less than the ABI alignment");
403
404 StructABIAlignment = ABIAlign;
405 StructPrefAlignment = PrefAlign;
406 return Error::success();
407}
408
409Error DataLayout::parsePointerSpec(StringRef Spec) {
410 // p[<n>]:<size>:<abi>[:<pref>[:<idx>]]
411 SmallVector<StringRef, 5> Components;
412 assert(Spec.front() == 'p');
413 Spec.drop_front().split(Components, ':');
414
415 if (Components.size() < 3 || Components.size() > 5)
416 return createSpecFormatError("p[<n>]:<size>:<abi>[:<pref>[:<idx>]]");
417
418 // Address space. Optional, defaults to 0.
419 unsigned AddrSpace = 0;
420 if (!Components[0].empty())
421 if (Error Err = parseAddrSpace(Components[0], AddrSpace))
422 return Err;
423
424 // Size. Required, cannot be zero.
425 unsigned BitWidth;
426 if (Error Err = parseSize(Components[1], BitWidth, "pointer size"))
427 return Err;
428
429 // ABI alignment. Required, cannot be zero.
430 Align ABIAlign;
431 if (Error Err = parseAlignment(Components[2], ABIAlign, "ABI"))
432 return Err;
433
434 // Preferred alignment. Optional, defaults to the ABI alignment.
435 // Cannot be zero.
436 Align PrefAlign = ABIAlign;
437 if (Components.size() > 3)
438 if (Error Err = parseAlignment(Components[3], PrefAlign, "preferred"))
439 return Err;
440
441 if (PrefAlign < ABIAlign)
442 return createStringError(
443 "preferred alignment cannot be less than the ABI alignment");
444
445 // Index size. Optional, defaults to pointer size. Cannot be zero.
446 unsigned IndexBitWidth = BitWidth;
447 if (Components.size() > 4)
448 if (Error Err = parseSize(Components[4], IndexBitWidth, "index size"))
449 return Err;
450
451 if (IndexBitWidth > BitWidth)
452 return createStringError(
453 "index size cannot be larger than the pointer size");
454
455 setPointerSpec(AddrSpace, BitWidth, ABIAlign, PrefAlign, IndexBitWidth,
456 false);
457 return Error::success();
458}
459
460Error DataLayout::parseSpecification(
461 StringRef Spec, SmallVectorImpl<unsigned> &NonIntegralAddressSpaces) {
462 // The "ni" specifier is the only two-character specifier. Handle it first.
463 if (Spec.starts_with("ni")) {
464 // ni:<address space>[:<address space>]...
465 StringRef Rest = Spec.drop_front(2);
466
467 // Drop the first ':', then split the rest of the string the usual way.
468 if (!Rest.consume_front(":"))
469 return createSpecFormatError("ni:<address space>[:<address space>]...");
470
471 for (StringRef Str : split(Rest, ':')) {
472 unsigned AddrSpace;
473 if (Error Err = parseAddrSpace(Str, AddrSpace))
474 return Err;
475 if (AddrSpace == 0)
476 return createStringError("address space 0 cannot be non-integral");
477 NonIntegralAddressSpaces.push_back(AddrSpace);
478 }
479 return Error::success();
480 }
481
482 // The rest of the specifiers are single-character.
483 assert(!Spec.empty() && "Empty specification is handled by the caller");
484 char Specifier = Spec.front();
485
486 if (Specifier == 'i' || Specifier == 'f' || Specifier == 'v')
487 return parsePrimitiveSpec(Spec);
488
489 if (Specifier == 'a')
490 return parseAggregateSpec(Spec);
491
492 if (Specifier == 'p')
493 return parsePointerSpec(Spec);
494
495 StringRef Rest = Spec.drop_front();
496 switch (Specifier) {
497 case 's':
498 // Deprecated, but ignoring here to preserve loading older textual llvm
499 // ASM file
500 break;
501 case 'e':
502 case 'E':
503 if (!Rest.empty())
504 return createStringError(
505 "malformed specification, must be just 'e' or 'E'");
506 BigEndian = Specifier == 'E';
507 break;
508 case 'n': // Native integer types.
509 // n<size>[:<size>]...
510 for (StringRef Str : split(Rest, ':')) {
511 unsigned BitWidth;
512 if (Error Err = parseSize(Str, BitWidth))
513 return Err;
514 LegalIntWidths.push_back(BitWidth);
515 }
516 break;
517 case 'S': { // Stack natural alignment.
518 // S<size>
519 if (Rest.empty())
520 return createSpecFormatError("S<size>");
521 Align Alignment;
522 if (Error Err = parseAlignment(Rest, Alignment, "stack natural"))
523 return Err;
524 StackNaturalAlign = Alignment;
525 break;
526 }
527 case 'F': {
528 // F<type><abi>
529 if (Rest.empty())
530 return createSpecFormatError("F<type><abi>");
531 char Type = Rest.front();
532 Rest = Rest.drop_front();
533 switch (Type) {
534 case 'i':
535 TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
536 break;
537 case 'n':
538 TheFunctionPtrAlignType = FunctionPtrAlignType::MultipleOfFunctionAlign;
539 break;
540 default:
541 return createStringError("unknown function pointer alignment type '" +
542 Twine(Type) + "'");
543 }
544 Align Alignment;
545 if (Error Err = parseAlignment(Rest, Alignment, "ABI"))
546 return Err;
547 FunctionPtrAlign = Alignment;
548 break;
549 }
550 case 'P': { // Function address space.
551 if (Rest.empty())
552 return createSpecFormatError("P<address space>");
553 if (Error Err = parseAddrSpace(Rest, ProgramAddrSpace))
554 return Err;
555 break;
556 }
557 case 'A': { // Default stack/alloca address space.
558 if (Rest.empty())
559 return createSpecFormatError("A<address space>");
560 if (Error Err = parseAddrSpace(Rest, AllocaAddrSpace))
561 return Err;
562 break;
563 }
564 case 'G': { // Default address space for global variables.
565 if (Rest.empty())
566 return createSpecFormatError("G<address space>");
567 if (Error Err = parseAddrSpace(Rest, DefaultGlobalsAddrSpace))
568 return Err;
569 break;
570 }
571 case 'm':
572 if (!Rest.consume_front(":") || Rest.empty())
573 return createSpecFormatError("m:<mangling>");
574 if (Rest.size() > 1)
575 return createStringError("unknown mangling mode");
576 switch (Rest[0]) {
577 default:
578 return createStringError("unknown mangling mode");
579 case 'e':
580 ManglingMode = MM_ELF;
581 break;
582 case 'l':
583 ManglingMode = MM_GOFF;
584 break;
585 case 'o':
586 ManglingMode = MM_MachO;
587 break;
588 case 'm':
589 ManglingMode = MM_Mips;
590 break;
591 case 'w':
592 ManglingMode = MM_WinCOFF;
593 break;
594 case 'x':
595 ManglingMode = MM_WinCOFFX86;
596 break;
597 case 'a':
598 ManglingMode = MM_XCOFF;
599 break;
600 }
601 break;
602 default:
603 return createStringError("unknown specifier '" + Twine(Specifier) + "'");
604 }
605
606 return Error::success();
607}
608
609Error DataLayout::parseLayoutString(StringRef LayoutString) {
610 StringRepresentation = std::string(LayoutString);
611
612 if (LayoutString.empty())
613 return Error::success();
614
615 // Split the data layout string into specifications separated by '-' and
616 // parse each specification individually, updating internal data structures.
617 SmallVector<unsigned, 8> NonIntegralAddressSpaces;
618 for (StringRef Spec : split(LayoutString, '-')) {
619 if (Spec.empty())
620 return createStringError("empty specification is not allowed");
621 if (Error Err = parseSpecification(Spec, NonIntegralAddressSpaces))
622 return Err;
623 }
624 // Mark all address spaces that were qualified as non-integral now. This has
625 // to be done later since the non-integral property is not part of the data
626 // layout pointer specification.
627 for (unsigned AS : NonIntegralAddressSpaces) {
628 // If there is no special spec for a given AS, getPointerSpec(AS) returns
629 // the spec for AS0, and we then update that to mark it non-integral.
630 const PointerSpec &PS = getPointerSpec(AS);
631 setPointerSpec(AS, PS.BitWidth, PS.ABIAlign, PS.PrefAlign, PS.IndexBitWidth,
632 true);
633 }
634
635 return Error::success();
636}
637
638void DataLayout::setPrimitiveSpec(char Specifier, uint32_t BitWidth,
639 Align ABIAlign, Align PrefAlign) {
640 SmallVectorImpl<PrimitiveSpec> *Specs;
641 switch (Specifier) {
642 default:
643 llvm_unreachable("Unexpected specifier");
644 case 'i':
645 Specs = &IntSpecs;
646 break;
647 case 'f':
648 Specs = &FloatSpecs;
649 break;
650 case 'v':
651 Specs = &VectorSpecs;
652 break;
653 }
654
655 auto I = lower_bound(*Specs, BitWidth, LessPrimitiveBitWidth());
656 if (I != Specs->end() && I->BitWidth == BitWidth) {
657 // Update the abi, preferred alignments.
658 I->ABIAlign = ABIAlign;
659 I->PrefAlign = PrefAlign;
660 } else {
661 // Insert before I to keep the vector sorted.
662 Specs->insert(I, PrimitiveSpec{BitWidth, ABIAlign, PrefAlign});
663 }
664}
665
667DataLayout::getPointerSpec(uint32_t AddrSpace) const {
668 if (AddrSpace != 0) {
669 auto I = lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
670 if (I != PointerSpecs.end() && I->AddrSpace == AddrSpace)
671 return *I;
672 }
673
674 assert(PointerSpecs[0].AddrSpace == 0);
675 return PointerSpecs[0];
676}
677
678void DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth,
679 Align ABIAlign, Align PrefAlign,
680 uint32_t IndexBitWidth, bool IsNonIntegral) {
681 auto I = lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace());
682 if (I == PointerSpecs.end() || I->AddrSpace != AddrSpace) {
683 PointerSpecs.insert(I, PointerSpec{AddrSpace, BitWidth, ABIAlign, PrefAlign,
684 IndexBitWidth, IsNonIntegral});
685 } else {
686 I->BitWidth = BitWidth;
687 I->ABIAlign = ABIAlign;
688 I->PrefAlign = PrefAlign;
689 I->IndexBitWidth = IndexBitWidth;
690 I->IsNonIntegral = IsNonIntegral;
691 }
692}
693
694Align DataLayout::getIntegerAlignment(uint32_t BitWidth,
695 bool abi_or_pref) const {
696 auto I = IntSpecs.begin();
697 for (; I != IntSpecs.end(); ++I) {
698 if (I->BitWidth >= BitWidth)
699 break;
700 }
701
702 // If we don't have an exact match, use alignment of next larger integer
703 // type. If there is none, use alignment of largest integer type by going
704 // back one element.
705 if (I == IntSpecs.end())
706 --I;
707 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
708}
709
710DataLayout::~DataLayout() { delete static_cast<StructLayoutMap *>(LayoutMap); }
711
713 if (!LayoutMap)
714 LayoutMap = new StructLayoutMap();
715
716 StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
717 StructLayout *&SL = (*STM)[Ty];
718 if (SL) return SL;
719
720 // Otherwise, create the struct layout. Because it is variable length, we
721 // malloc it, then use placement new.
723 StructLayout::totalSizeToAlloc<TypeSize>(Ty->getNumElements()));
724
725 // Set SL before calling StructLayout's ctor. The ctor could cause other
726 // entries to be added to TheMap, invalidating our reference.
727 SL = L;
728
729 new (L) StructLayout(Ty, *this);
730
731 return L;
732}
733
735 return getPointerSpec(AS).ABIAlign;
736}
737
739 return getPointerSpec(AS).PrefAlign;
740}
741
742unsigned DataLayout::getPointerSize(unsigned AS) const {
743 return divideCeil(getPointerSpec(AS).BitWidth, 8);
744}
745
747 assert(Ty->isPtrOrPtrVectorTy() &&
748 "This should only be called with a pointer or pointer vector type");
749 Ty = Ty->getScalarType();
751}
752
753unsigned DataLayout::getIndexSize(unsigned AS) const {
754 return divideCeil(getPointerSpec(AS).IndexBitWidth, 8);
755}
756
758 assert(Ty->isPtrOrPtrVectorTy() &&
759 "This should only be called with a pointer or pointer vector type");
760 Ty = Ty->getScalarType();
762}
763
764/*!
765 \param abi_or_pref Flag that determines which alignment is returned. true
766 returns the ABI alignment, false returns the preferred alignment.
767 \param Ty The underlying type for which alignment is determined.
768
769 Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
770 == false) for the requested type \a Ty.
771 */
772Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
773 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
774 switch (Ty->getTypeID()) {
775 // Early escape for the non-numeric types.
776 case Type::LabelTyID:
777 return abi_or_pref ? getPointerABIAlignment(0) : getPointerPrefAlignment(0);
778 case Type::PointerTyID: {
779 unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
780 return abi_or_pref ? getPointerABIAlignment(AS)
782 }
783 case Type::ArrayTyID:
784 return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
785
786 case Type::StructTyID: {
787 // Packed structure types always have an ABI alignment of one.
788 if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
789 return Align(1);
790
791 // Get the layout annotation... which is lazily created on demand.
792 const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
793 const Align Align = abi_or_pref ? StructABIAlignment : StructPrefAlignment;
794 return std::max(Align, Layout->getAlignment());
795 }
797 return getIntegerAlignment(Ty->getIntegerBitWidth(), abi_or_pref);
798 case Type::HalfTyID:
799 case Type::BFloatTyID:
800 case Type::FloatTyID:
801 case Type::DoubleTyID:
802 // PPC_FP128TyID and FP128TyID have different data contents, but the
803 // same size and alignment, so they look the same here.
805 case Type::FP128TyID:
806 case Type::X86_FP80TyID: {
808 auto I = lower_bound(FloatSpecs, BitWidth, LessPrimitiveBitWidth());
809 if (I != FloatSpecs.end() && I->BitWidth == BitWidth)
810 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
811
812 // If we still couldn't find a reasonable default alignment, fall back
813 // to a simple heuristic that the alignment is the first power of two
814 // greater-or-equal to the store size of the type. This is a reasonable
815 // approximation of reality, and if the user wanted something less
816 // less conservative, they should have specified it explicitly in the data
817 // layout.
818 return Align(PowerOf2Ceil(BitWidth / 8));
819 }
823 auto I = lower_bound(VectorSpecs, BitWidth, LessPrimitiveBitWidth());
824 if (I != VectorSpecs.end() && I->BitWidth == BitWidth)
825 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
826
827 // By default, use natural alignment for vector types. This is consistent
828 // with what clang and llvm-gcc do.
829 //
830 // We're only calculating a natural alignment, so it doesn't have to be
831 // based on the full size for scalable vectors. Using the minimum element
832 // count should be enough here.
833 return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinValue()));
834 }
836 return Align(64);
837 case Type::TargetExtTyID: {
838 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
839 return getAlignment(LayoutTy, abi_or_pref);
840 }
841 default:
842 llvm_unreachable("Bad type for getAlignment!!!");
843 }
844}
845
847 switch (Ty->getTypeID()) {
848 case Type::ArrayTyID: {
849 // The alignment of the array is the alignment of the element, so there
850 // is no need for further adjustment.
851 auto *ATy = cast<ArrayType>(Ty);
852 return ATy->getNumElements() * getTypeAllocSize(ATy->getElementType());
853 }
854 case Type::StructTyID: {
855 const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
856 TypeSize Size = Layout->getSizeInBytes();
857
858 if (cast<StructType>(Ty)->isPacked())
859 return Size;
860
861 Align A = std::max(StructABIAlignment, Layout->getAlignment());
862 return alignTo(Size, A.value());
863 }
864 case Type::IntegerTyID: {
865 unsigned BitWidth = Ty->getIntegerBitWidth();
867 Align A = getIntegerAlignment(BitWidth, /*ABI=*/true);
868 return alignTo(Size, A.value());
869 }
870 case Type::PointerTyID: {
871 unsigned AS = Ty->getPointerAddressSpace();
873 return alignTo(Size, getPointerABIAlignment(AS).value());
874 }
875 case Type::TargetExtTyID: {
876 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
877 return getTypeAllocSize(LayoutTy);
878 }
879 default:
880 return alignTo(getTypeStoreSize(Ty), getABITypeAlign(Ty).value());
881 }
882}
883
885 return getAlignment(Ty, true);
886}
887
889 return getAlignment(Ty, false);
890}
891
896
898 assert(Ty->isPtrOrPtrVectorTy() &&
899 "Expected a pointer or pointer vector type.");
900 unsigned NumBits = getPointerTypeSizeInBits(Ty);
901 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
902 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
903 return VectorType::get(IntTy, VecTy);
904 return IntTy;
905}
906
908 for (unsigned LegalIntWidth : LegalIntWidths)
909 if (Width <= LegalIntWidth)
910 return Type::getIntNTy(C, LegalIntWidth);
911 return nullptr;
912}
913
915 auto Max = llvm::max_element(LegalIntWidths);
916 return Max != LegalIntWidths.end() ? *Max : 0;
917}
918
923
925 assert(Ty->isPtrOrPtrVectorTy() &&
926 "Expected a pointer or pointer vector type.");
927 unsigned NumBits = getIndexTypeSizeInBits(Ty);
928 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
929 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
930 return VectorType::get(IntTy, VecTy);
931 return IntTy;
932}
933
935 ArrayRef<Value *> Indices) const {
936 int64_t Result = 0;
937
939 GTI = gep_type_begin(ElemTy, Indices),
940 GTE = gep_type_end(ElemTy, Indices);
941 for (; GTI != GTE; ++GTI) {
942 Value *Idx = GTI.getOperand();
943 if (StructType *STy = GTI.getStructTypeOrNull()) {
944 assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx");
945 unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
946
947 // Get structure layout information...
948 const StructLayout *Layout = getStructLayout(STy);
949
950 // Add in the offset, as calculated by the structure layout info...
951 Result += Layout->getElementOffset(FieldNo);
952 } else {
953 if (int64_t ArrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
954 Result += ArrayIdx * GTI.getSequentialElementStride(*this);
955 }
956 }
957
958 return Result;
959}
960
962 // Skip over scalable or zero size elements. Also skip element sizes larger
963 // than the positive index space, because the arithmetic below may not be
964 // correct in that case.
965 unsigned BitWidth = Offset.getBitWidth();
966 if (ElemSize.isScalable() || ElemSize == 0 ||
967 !isUIntN(BitWidth - 1, ElemSize)) {
968 return APInt::getZero(BitWidth);
969 }
970
971 uint64_t FixedElemSize = ElemSize.getFixedValue();
972 APInt Index = Offset.sdiv(FixedElemSize);
973 Offset -= Index * FixedElemSize;
974 if (Offset.isNegative()) {
975 // Prefer a positive remaining offset to allow struct indexing.
976 --Index;
977 Offset += FixedElemSize;
978 assert(Offset.isNonNegative() && "Remaining offset shouldn't be negative");
979 }
980 return Index;
981}
982
983std::optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
984 APInt &Offset) const {
985 if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
986 ElemTy = ArrTy->getElementType();
987 return getElementIndex(getTypeAllocSize(ElemTy), Offset);
988 }
989
990 if (isa<VectorType>(ElemTy)) {
991 // Vector GEPs are partially broken (e.g. for overaligned element types),
992 // and may be forbidden in the future, so avoid generating GEPs into
993 // vectors. See https://discourse.llvm.org/t/67497
994 return std::nullopt;
995 }
996
997 if (auto *STy = dyn_cast<StructType>(ElemTy)) {
998 const StructLayout *SL = getStructLayout(STy);
999 uint64_t IntOffset = Offset.getZExtValue();
1000 if (IntOffset >= SL->getSizeInBytes())
1001 return std::nullopt;
1002
1003 unsigned Index = SL->getElementContainingOffset(IntOffset);
1004 Offset -= SL->getElementOffset(Index);
1005 ElemTy = STy->getElementType(Index);
1006 return APInt(32, Index);
1007 }
1008
1009 // Non-aggregate type.
1010 return std::nullopt;
1011}
1012
1014 APInt &Offset) const {
1015 assert(ElemTy->isSized() && "Element type must be sized");
1016 SmallVector<APInt> Indices;
1018 while (Offset != 0) {
1019 std::optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
1020 if (!Index)
1021 break;
1022 Indices.push_back(*Index);
1023 }
1024
1025 return Indices;
1026}
1027
1028/// getPreferredAlign - Return the preferred alignment of the specified global.
1029/// This includes an explicitly requested alignment (if the global has one).
1031 MaybeAlign GVAlignment = GV->getAlign();
1032 // If a section is specified, always precisely honor explicit alignment,
1033 // so we don't insert padding into a section we don't control.
1034 if (GVAlignment && GV->hasSection())
1035 return *GVAlignment;
1036
1037 // If no explicit alignment is specified, compute the alignment based on
1038 // the IR type. If an alignment is specified, increase it to match the ABI
1039 // alignment of the IR type.
1040 //
1041 // FIXME: Not sure it makes sense to use the alignment of the type if
1042 // there's already an explicit alignment specification.
1043 Type *ElemType = GV->getValueType();
1044 Align Alignment = getPrefTypeAlign(ElemType);
1045 if (GVAlignment) {
1046 if (*GVAlignment >= Alignment)
1047 Alignment = *GVAlignment;
1048 else
1049 Alignment = std::max(*GVAlignment, getABITypeAlign(ElemType));
1050 }
1051
1052 // If no explicit alignment is specified, and the global is large, increase
1053 // the alignment to 16.
1054 // FIXME: Why 16, specifically?
1055 if (GV->hasInitializer() && !GVAlignment) {
1056 if (Alignment < Align(16)) {
1057 // If the global is not external, see if it is large. If so, give it a
1058 // larger alignment.
1059 if (getTypeSizeInBits(ElemType) > 128)
1060 Alignment = Align(16); // 16-byte alignment.
1061 }
1062 }
1063 return Alignment;
1064}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Error parseSize(StringRef Str, unsigned &BitWidth, StringRef Name="size")
Attempts to parse a size component of a specification.
static APInt getElementIndex(TypeSize ElemSize, APInt &Offset)
static Error parseAddrSpace(StringRef Str, unsigned &AddrSpace)
Attempts to parse an address space component of a specification.
static Error createSpecFormatError(Twine Format)
static Error parseAlignment(StringRef Str, Align &Alignment, StringRef Name, bool AllowZero=false)
Attempts to parse an alignment component of a specification.
constexpr DataLayout::PrimitiveSpec DefaultFloatSpecs[]
constexpr DataLayout::PrimitiveSpec DefaultVectorSpecs[]
constexpr DataLayout::PointerSpec DefaultPointerSpecs[]
constexpr DataLayout::PrimitiveSpec DefaultIntSpecs[]
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:58
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
#define T
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
This file contains some functions that are useful when dealing with strings.
static uint32_t getAlignment(const MCSectionCOFF &Sec)
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:200
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:136
iterator begin() const
Definition ArrayRef.h:135
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
static LLVM_ABI const char * getManglingComponent(const Triple &T)
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
Definition DataLayout.h:390
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
Definition DataLayout.h:93
@ Independent
The function pointer alignment is independent of the function alignment.
Definition DataLayout.h:91
LLVM_ABI SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const
Get GEP indices to access Offset inside ElemTy.
LLVM_ABI unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
LLVM_ABI unsigned getIndexSize(unsigned AS) const
The index size in bytes used for address calculation, rounded up to a whole number of bytes.
LLVM_ABI const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
LLVM_ABI DataLayout()
Constructs a DataLayout with default values.
LLVM_ABI 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.
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const
The size in bits of the index used in GEP calculation for this type.
LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const
The pointer representation size in bits for this type.
LLVM_ABI DataLayout & operator=(const DataLayout &Other)
LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
LLVM_ABI std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
LLVM_ABI Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const
Returns the smallest integer type with size at least as big as Width bits.
LLVM_ABI Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
LLVM_ABI ~DataLayout()
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
LLVM_ABI Align getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
unsigned getIndexSizeInBits(unsigned AS) const
The size in bits of indices used for address calculation in getelementptr and for addresses in the gi...
Definition DataLayout.h:398
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition DataLayout.h:671
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition DataLayout.h:468
LLVM_ABI bool operator==(const DataLayout &Other) const
LLVM_ABI int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
LLVM_ABI Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
LLVM_ABI Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
static LLVM_ABI Expected< DataLayout > parse(StringRef LayoutString)
Parse a data layout string and return the layout.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
bool hasSection() const
Check if this global has a custom object file section.
Type * getValueType() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:319
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:710
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:269
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:151
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:619
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:154
char front() const
front - Get the first character in the string.
Definition StringRef.h:157
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:645
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition DataLayout.h:623
TypeSize getSizeInBytes() const
Definition DataLayout.h:632
MutableArrayRef< TypeSize > getMemberOffsets()
Definition DataLayout.h:646
LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
TypeSize getElementOffset(unsigned Idx) const
Definition DataLayout.h:654
Align getAlignment() const
Definition DataLayout.h:636
Class to represent struct types.
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
Definition TypeSize.h:346
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI 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
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:301
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:230
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:216
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:223
TypeSize getSequentialElementStride(const DataLayout &DL) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
constexpr double e
Definition MathExtras.h:47
bool empty() const
Definition BasicBlock.h:101
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition Alignment.h:145
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:252
gep_type_iterator gep_type_end(const User *GEP)
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:2009
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition MathExtras.h:390
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:288
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:198
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
Definition MemAlloc.h:25
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:399
@ Other
Any other memory.
Definition ModRef.h:68
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:1996
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)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2032
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
gep_type_iterator gep_type_begin(const User *GEP)
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static constexpr Align Constant()
Allow constructions of constexpr Align.
Definition Alignment.h:96
Pointer type specification.
Definition DataLayout.h:75
LLVM_ABI bool operator==(const PointerSpec &Other) const
bool IsNonIntegral
Pointers in this address space don't have a well-defined bitwise representation (e....
Definition DataLayout.h:85
Primitive type specification.
Definition DataLayout.h:66
LLVM_ABI bool operator==(const PrimitiveSpec &Other) const
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:117