LLVM 17.0.0git
DataLayout.cpp
Go to the documentation of this file.
1//===- DataLayout.cpp - Data size & alignment routines ---------------------==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines layout properties related to datatype size/offset/alignment
10// information.
11//
12// This structure should be created once, filled in if the defaults are not
13// correct and then passed around by const&. None of the members functions
14// require modification to the object.
15//
16//===----------------------------------------------------------------------===//
17
18#include "llvm/IR/DataLayout.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/IR/Constants.h"
25#include "llvm/IR/Module.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 assert(!ST->isOpaque() && "Cannot get layout of opaque structs");
50 StructSize = 0;
51 IsPadded = false;
52 NumElements = ST->getNumElements();
53
54 // Loop over each of the elements, placing them in memory.
55 for (unsigned i = 0, e = NumElements; i != e; ++i) {
56 Type *Ty = ST->getElementType(i);
57 const Align TyAlign = ST->isPacked() ? Align(1) : DL.getABITypeAlign(Ty);
58
59 // Add padding if necessary to align the data element properly.
60 if (!isAligned(TyAlign, StructSize)) {
61 IsPadded = true;
62 StructSize = alignTo(StructSize, TyAlign);
63 }
64
65 // Keep track of maximum alignment constraint.
66 StructAlignment = std::max(TyAlign, StructAlignment);
67
68 getMemberOffsets()[i] = StructSize;
69 // Consume space for this data item
70 StructSize += DL.getTypeAllocSize(Ty).getFixedValue();
71 }
72
73 // Add padding to the end of the struct so that it could be put in an array
74 // and all array elements would be aligned correctly.
75 if (!isAligned(StructAlignment, StructSize)) {
76 IsPadded = true;
77 StructSize = alignTo(StructSize, StructAlignment);
78 }
79}
80
81/// getElementContainingOffset - Given a valid offset into the structure,
82/// return the structure index that contains it.
84 ArrayRef<uint64_t> MemberOffsets = getMemberOffsets();
85 auto SI = llvm::upper_bound(MemberOffsets, Offset);
86 assert(SI != MemberOffsets.begin() && "Offset not in structure type!");
87 --SI;
88 assert(*SI <= Offset && "upper_bound didn't work");
89 assert((SI == MemberOffsets.begin() || *(SI - 1) <= Offset) &&
90 (SI + 1 == MemberOffsets.end() || *(SI + 1) > Offset) &&
91 "Upper bound didn't work!");
92
93 // Multiple fields can have the same offset if any of them are zero sized.
94 // For example, in { i32, [0 x i32], i32 }, searching for offset 4 will stop
95 // at the i32 element, because it is the last element at that offset. This is
96 // the right one to return, because anything after it will have a higher
97 // offset, implying that this element is non-empty.
98 return SI - MemberOffsets.begin();
99}
100
101//===----------------------------------------------------------------------===//
102// LayoutAlignElem, LayoutAlign support
103//===----------------------------------------------------------------------===//
104
107 assert(ABIAlign <= PrefAlign && "Preferred alignment worse than ABI!");
108 LayoutAlignElem retval;
109 retval.ABIAlign = ABIAlign;
110 retval.PrefAlign = PrefAlign;
111 retval.TypeBitWidth = BitWidth;
112 return retval;
113}
114
116 return ABIAlign == rhs.ABIAlign && PrefAlign == rhs.PrefAlign &&
118}
119
120//===----------------------------------------------------------------------===//
121// PointerAlignElem, PointerAlign support
122//===----------------------------------------------------------------------===//
123
125 Align ABIAlign, Align PrefAlign,
126 uint32_t TypeBitWidth,
127 uint32_t IndexBitWidth) {
128 assert(ABIAlign <= PrefAlign && "Preferred alignment worse than ABI!");
129 PointerAlignElem retval;
130 retval.AddressSpace = AddressSpace;
131 retval.ABIAlign = ABIAlign;
132 retval.PrefAlign = PrefAlign;
133 retval.TypeBitWidth = TypeBitWidth;
135 return retval;
136}
137
138bool
140 return (ABIAlign == rhs.ABIAlign && AddressSpace == rhs.AddressSpace &&
141 PrefAlign == rhs.PrefAlign && TypeBitWidth == rhs.TypeBitWidth &&
143}
144
145//===----------------------------------------------------------------------===//
146// DataLayout Class Implementation
147//===----------------------------------------------------------------------===//
148
150 if (T.isOSBinFormatGOFF())
151 return "-m:l";
152 if (T.isOSBinFormatMachO())
153 return "-m:o";
154 if (T.isOSWindows() && T.isOSBinFormatCOFF())
155 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
156 if (T.isOSBinFormatXCOFF())
157 return "-m:a";
158 return "-m:e";
159}
160
161static const std::pair<AlignTypeEnum, LayoutAlignElem> DefaultAlignments[] = {
162 {INTEGER_ALIGN, {1, Align(1), Align(1)}}, // i1
163 {INTEGER_ALIGN, {8, Align(1), Align(1)}}, // i8
164 {INTEGER_ALIGN, {16, Align(2), Align(2)}}, // i16
165 {INTEGER_ALIGN, {32, Align(4), Align(4)}}, // i32
166 {INTEGER_ALIGN, {64, Align(4), Align(8)}}, // i64
167 {FLOAT_ALIGN, {16, Align(2), Align(2)}}, // half, bfloat
168 {FLOAT_ALIGN, {32, Align(4), Align(4)}}, // float
169 {FLOAT_ALIGN, {64, Align(8), Align(8)}}, // double
170 {FLOAT_ALIGN, {128, Align(16), Align(16)}}, // ppcf128, quad, ...
171 {VECTOR_ALIGN, {64, Align(8), Align(8)}}, // v2i32, v1i64, ...
172 {VECTOR_ALIGN, {128, Align(16), Align(16)}}, // v16i8, v8i16, v4i32, ...
173};
174
176 clear();
177
178 LayoutMap = nullptr;
179 BigEndian = false;
180 AllocaAddrSpace = 0;
181 StackNaturalAlign.reset();
182 ProgramAddrSpace = 0;
183 DefaultGlobalsAddrSpace = 0;
184 FunctionPtrAlign.reset();
185 TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
186 ManglingMode = MM_None;
187 NonIntegralAddressSpaces.clear();
188 StructAlignment = LayoutAlignElem::get(Align(1), Align(8), 0);
189
190 // Default alignments
191 for (const auto &[Kind, Layout] : DefaultAlignments) {
192 if (Error Err = setAlignment(Kind, Layout.ABIAlign, Layout.PrefAlign,
193 Layout.TypeBitWidth))
194 return report_fatal_error(std::move(Err));
195 }
196 if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64))
197 return report_fatal_error(std::move(Err));
198
199 if (Error Err = parseSpecifier(Desc))
200 return report_fatal_error(std::move(Err));
201}
202
204 DataLayout Layout("");
205 if (Error Err = Layout.parseSpecifier(LayoutDescription))
206 return std::move(Err);
207 return Layout;
208}
209
210static Error reportError(const Twine &Message) {
211 return createStringError(inconvertibleErrorCode(), Message);
212}
213
214/// Checked version of split, to ensure mandatory subparts.
215static Error split(StringRef Str, char Separator,
216 std::pair<StringRef, StringRef> &Split) {
217 assert(!Str.empty() && "parse error, string can't be empty here");
218 Split = Str.split(Separator);
219 if (Split.second.empty() && Split.first != Str)
220 return reportError("Trailing separator in datalayout string");
221 if (!Split.second.empty() && Split.first.empty())
222 return reportError("Expected token before separator in datalayout string");
223 return Error::success();
224}
225
226/// Get an unsigned integer, including error checks.
227template <typename IntTy> static Error getInt(StringRef R, IntTy &Result) {
228 bool error = R.getAsInteger(10, Result); (void)error;
229 if (error)
230 return reportError("not a number, or does not fit in an unsigned int");
231 return Error::success();
232}
233
234/// Get an unsigned integer representing the number of bits and convert it into
235/// bytes. Error out of not a byte width multiple.
236template <typename IntTy>
237static Error getIntInBytes(StringRef R, IntTy &Result) {
238 if (Error Err = getInt<IntTy>(R, Result))
239 return Err;
240 if (Result % 8)
241 return reportError("number of bits must be a byte width multiple");
242 Result /= 8;
243 return Error::success();
244}
245
246static Error getAddrSpace(StringRef R, unsigned &AddrSpace) {
247 if (Error Err = getInt(R, AddrSpace))
248 return Err;
249 if (!isUInt<24>(AddrSpace))
250 return reportError("Invalid address space, must be a 24-bit integer");
251 return Error::success();
252}
253
254Error DataLayout::parseSpecifier(StringRef Desc) {
255 StringRepresentation = std::string(Desc);
256 while (!Desc.empty()) {
257 // Split at '-'.
258 std::pair<StringRef, StringRef> Split;
259 if (Error Err = ::split(Desc, '-', Split))
260 return Err;
261 Desc = Split.second;
262
263 // Split at ':'.
264 if (Error Err = ::split(Split.first, ':', Split))
265 return Err;
266
267 // Aliases used below.
268 StringRef &Tok = Split.first; // Current token.
269 StringRef &Rest = Split.second; // The rest of the string.
270
271 if (Tok == "ni") {
272 do {
273 if (Error Err = ::split(Rest, ':', Split))
274 return Err;
275 Rest = Split.second;
276 unsigned AS;
277 if (Error Err = getInt(Split.first, AS))
278 return Err;
279 if (AS == 0)
280 return reportError("Address space 0 can never be non-integral");
281 NonIntegralAddressSpaces.push_back(AS);
282 } while (!Rest.empty());
283
284 continue;
285 }
286
287 char Specifier = Tok.front();
288 Tok = Tok.substr(1);
289
290 switch (Specifier) {
291 case 's':
292 // Deprecated, but ignoring here to preserve loading older textual llvm
293 // ASM file
294 break;
295 case 'E':
296 BigEndian = true;
297 break;
298 case 'e':
299 BigEndian = false;
300 break;
301 case 'p': {
302 // Address space.
303 unsigned AddrSpace = 0;
304 if (!Tok.empty())
305 if (Error Err = getInt(Tok, AddrSpace))
306 return Err;
307 if (!isUInt<24>(AddrSpace))
308 return reportError("Invalid address space, must be a 24-bit integer");
309
310 // Size.
311 if (Rest.empty())
312 return reportError(
313 "Missing size specification for pointer in datalayout string");
314 if (Error Err = ::split(Rest, ':', Split))
315 return Err;
316 unsigned PointerMemSize;
317 if (Error Err = getInt(Tok, PointerMemSize))
318 return Err;
319 if (!PointerMemSize)
320 return reportError("Invalid pointer size of 0 bytes");
321
322 // ABI alignment.
323 if (Rest.empty())
324 return reportError(
325 "Missing alignment specification for pointer in datalayout string");
326 if (Error Err = ::split(Rest, ':', Split))
327 return Err;
328 unsigned PointerABIAlign;
329 if (Error Err = getIntInBytes(Tok, PointerABIAlign))
330 return Err;
331 if (!isPowerOf2_64(PointerABIAlign))
332 return reportError("Pointer ABI alignment must be a power of 2");
333
334 // Size of index used in GEP for address calculation.
335 // The parameter is optional. By default it is equal to size of pointer.
336 unsigned IndexSize = PointerMemSize;
337
338 // Preferred alignment.
339 unsigned PointerPrefAlign = PointerABIAlign;
340 if (!Rest.empty()) {
341 if (Error Err = ::split(Rest, ':', Split))
342 return Err;
343 if (Error Err = getIntInBytes(Tok, PointerPrefAlign))
344 return Err;
345 if (!isPowerOf2_64(PointerPrefAlign))
346 return reportError(
347 "Pointer preferred alignment must be a power of 2");
348
349 // Now read the index. It is the second optional parameter here.
350 if (!Rest.empty()) {
351 if (Error Err = ::split(Rest, ':', Split))
352 return Err;
353 if (Error Err = getInt(Tok, IndexSize))
354 return Err;
355 if (!IndexSize)
356 return reportError("Invalid index size of 0 bytes");
357 }
358 }
359 if (Error Err = setPointerAlignmentInBits(
360 AddrSpace, assumeAligned(PointerABIAlign),
361 assumeAligned(PointerPrefAlign), PointerMemSize, IndexSize))
362 return Err;
363 break;
364 }
365 case 'i':
366 case 'v':
367 case 'f':
368 case 'a': {
369 AlignTypeEnum AlignType;
370 switch (Specifier) {
371 default: llvm_unreachable("Unexpected specifier!");
372 case 'i': AlignType = INTEGER_ALIGN; break;
373 case 'v': AlignType = VECTOR_ALIGN; break;
374 case 'f': AlignType = FLOAT_ALIGN; break;
375 case 'a': AlignType = AGGREGATE_ALIGN; break;
376 }
377
378 // Bit size.
379 unsigned Size = 0;
380 if (!Tok.empty())
381 if (Error Err = getInt(Tok, Size))
382 return Err;
383
384 if (AlignType == AGGREGATE_ALIGN && Size != 0)
385 return reportError(
386 "Sized aggregate specification in datalayout string");
387
388 // ABI alignment.
389 if (Rest.empty())
390 return reportError(
391 "Missing alignment specification in datalayout string");
392 if (Error Err = ::split(Rest, ':', Split))
393 return Err;
394 unsigned ABIAlign;
395 if (Error Err = getIntInBytes(Tok, ABIAlign))
396 return Err;
397 if (AlignType != AGGREGATE_ALIGN && !ABIAlign)
398 return reportError(
399 "ABI alignment specification must be >0 for non-aggregate types");
400
401 if (!isUInt<16>(ABIAlign))
402 return reportError("Invalid ABI alignment, must be a 16bit integer");
403 if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign))
404 return reportError("Invalid ABI alignment, must be a power of 2");
405 if (AlignType == INTEGER_ALIGN && Size == 8 && ABIAlign != 1)
406 return reportError(
407 "Invalid ABI alignment, i8 must be naturally aligned");
408
409 // Preferred alignment.
410 unsigned PrefAlign = ABIAlign;
411 if (!Rest.empty()) {
412 if (Error Err = ::split(Rest, ':', Split))
413 return Err;
414 if (Error Err = getIntInBytes(Tok, PrefAlign))
415 return Err;
416 }
417
418 if (!isUInt<16>(PrefAlign))
419 return reportError(
420 "Invalid preferred alignment, must be a 16bit integer");
421 if (PrefAlign != 0 && !isPowerOf2_64(PrefAlign))
422 return reportError("Invalid preferred alignment, must be a power of 2");
423
424 if (Error Err = setAlignment(AlignType, assumeAligned(ABIAlign),
425 assumeAligned(PrefAlign), Size))
426 return Err;
427
428 break;
429 }
430 case 'n': // Native integer types.
431 while (true) {
432 unsigned Width;
433 if (Error Err = getInt(Tok, Width))
434 return Err;
435 if (Width == 0)
436 return reportError(
437 "Zero width native integer type in datalayout string");
438 LegalIntWidths.push_back(Width);
439 if (Rest.empty())
440 break;
441 if (Error Err = ::split(Rest, ':', Split))
442 return Err;
443 }
444 break;
445 case 'S': { // Stack natural alignment.
446 uint64_t Alignment;
447 if (Error Err = getIntInBytes(Tok, Alignment))
448 return Err;
449 if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
450 return reportError("Alignment is neither 0 nor a power of 2");
451 StackNaturalAlign = MaybeAlign(Alignment);
452 break;
453 }
454 case 'F': {
455 switch (Tok.front()) {
456 case 'i':
457 TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
458 break;
459 case 'n':
460 TheFunctionPtrAlignType = FunctionPtrAlignType::MultipleOfFunctionAlign;
461 break;
462 default:
463 return reportError("Unknown function pointer alignment type in "
464 "datalayout string");
465 }
466 Tok = Tok.substr(1);
467 uint64_t Alignment;
468 if (Error Err = getIntInBytes(Tok, Alignment))
469 return Err;
470 if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment))
471 return reportError("Alignment is neither 0 nor a power of 2");
472 FunctionPtrAlign = MaybeAlign(Alignment);
473 break;
474 }
475 case 'P': { // Function address space.
476 if (Error Err = getAddrSpace(Tok, ProgramAddrSpace))
477 return Err;
478 break;
479 }
480 case 'A': { // Default stack/alloca address space.
481 if (Error Err = getAddrSpace(Tok, AllocaAddrSpace))
482 return Err;
483 break;
484 }
485 case 'G': { // Default address space for global variables.
486 if (Error Err = getAddrSpace(Tok, DefaultGlobalsAddrSpace))
487 return Err;
488 break;
489 }
490 case 'm':
491 if (!Tok.empty())
492 return reportError("Unexpected trailing characters after mangling "
493 "specifier in datalayout string");
494 if (Rest.empty())
495 return reportError("Expected mangling specifier in datalayout string");
496 if (Rest.size() > 1)
497 return reportError("Unknown mangling specifier in datalayout string");
498 switch(Rest[0]) {
499 default:
500 return reportError("Unknown mangling in datalayout string");
501 case 'e':
502 ManglingMode = MM_ELF;
503 break;
504 case 'l':
505 ManglingMode = MM_GOFF;
506 break;
507 case 'o':
508 ManglingMode = MM_MachO;
509 break;
510 case 'm':
511 ManglingMode = MM_Mips;
512 break;
513 case 'w':
514 ManglingMode = MM_WinCOFF;
515 break;
516 case 'x':
517 ManglingMode = MM_WinCOFFX86;
518 break;
519 case 'a':
520 ManglingMode = MM_XCOFF;
521 break;
522 }
523 break;
524 default:
525 return reportError("Unknown specifier in datalayout string");
526 break;
527 }
528 }
529
530 return Error::success();
531}
532
534 init(M);
535}
536
537void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
538
540 bool Ret = BigEndian == Other.BigEndian &&
541 AllocaAddrSpace == Other.AllocaAddrSpace &&
542 StackNaturalAlign == Other.StackNaturalAlign &&
543 ProgramAddrSpace == Other.ProgramAddrSpace &&
544 DefaultGlobalsAddrSpace == Other.DefaultGlobalsAddrSpace &&
545 FunctionPtrAlign == Other.FunctionPtrAlign &&
546 TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType &&
547 ManglingMode == Other.ManglingMode &&
548 LegalIntWidths == Other.LegalIntWidths &&
549 IntAlignments == Other.IntAlignments &&
550 FloatAlignments == Other.FloatAlignments &&
551 VectorAlignments == Other.VectorAlignments &&
552 StructAlignment == Other.StructAlignment &&
553 Pointers == Other.Pointers;
554 // Note: getStringRepresentation() might differs, it is not canonicalized
555 return Ret;
556}
557
561 return partition_point(Alignments, [BitWidth](const LayoutAlignElem &E) {
562 return E.TypeBitWidth < BitWidth;
563 });
564}
565
566Error DataLayout::setAlignment(AlignTypeEnum AlignType, Align ABIAlign,
567 Align PrefAlign, uint32_t BitWidth) {
568 // AlignmentsTy::ABIAlign and AlignmentsTy::PrefAlign were once stored as
569 // uint16_t, it is unclear if there are requirements for alignment to be less
570 // than 2^16 other than storage. In the meantime we leave the restriction as
571 // an assert. See D67400 for context.
572 assert(Log2(ABIAlign) < 16 && Log2(PrefAlign) < 16 && "Alignment too big");
573 if (!isUInt<24>(BitWidth))
574 return reportError("Invalid bit width, must be a 24-bit integer");
575 if (PrefAlign < ABIAlign)
576 return reportError(
577 "Preferred alignment cannot be less than the ABI alignment");
578
580 switch (AlignType) {
581 case AGGREGATE_ALIGN:
582 StructAlignment.ABIAlign = ABIAlign;
583 StructAlignment.PrefAlign = PrefAlign;
584 return Error::success();
585 case INTEGER_ALIGN:
586 Alignments = &IntAlignments;
587 break;
588 case FLOAT_ALIGN:
589 Alignments = &FloatAlignments;
590 break;
591 case VECTOR_ALIGN:
592 Alignments = &VectorAlignments;
593 break;
594 }
595
596 auto I = partition_point(*Alignments, [BitWidth](const LayoutAlignElem &E) {
597 return E.TypeBitWidth < BitWidth;
598 });
599 if (I != Alignments->end() && I->TypeBitWidth == BitWidth) {
600 // Update the abi, preferred alignments.
601 I->ABIAlign = ABIAlign;
602 I->PrefAlign = PrefAlign;
603 } else {
604 // Insert before I to keep the vector sorted.
605 Alignments->insert(I, LayoutAlignElem::get(ABIAlign, PrefAlign, BitWidth));
606 }
607 return Error::success();
608}
609
610const PointerAlignElem &
611DataLayout::getPointerAlignElem(uint32_t AddressSpace) const {
612 if (AddressSpace != 0) {
613 auto I = lower_bound(Pointers, AddressSpace,
615 return A.AddressSpace < AddressSpace;
616 });
617 if (I != Pointers.end() && I->AddressSpace == AddressSpace)
618 return *I;
619 }
620
621 assert(Pointers[0].AddressSpace == 0);
622 return Pointers[0];
623}
624
625Error DataLayout::setPointerAlignmentInBits(uint32_t AddrSpace, Align ABIAlign,
626 Align PrefAlign,
627 uint32_t TypeBitWidth,
628 uint32_t IndexBitWidth) {
629 if (PrefAlign < ABIAlign)
630 return reportError(
631 "Preferred alignment cannot be less than the ABI alignment");
632
633 auto I = lower_bound(Pointers, AddrSpace,
635 return A.AddressSpace < AddressSpace;
636 });
637 if (I == Pointers.end() || I->AddressSpace != AddrSpace) {
638 Pointers.insert(I,
639 PointerAlignElem::getInBits(AddrSpace, ABIAlign, PrefAlign,
640 TypeBitWidth, IndexBitWidth));
641 } else {
642 I->ABIAlign = ABIAlign;
643 I->PrefAlign = PrefAlign;
644 I->TypeBitWidth = TypeBitWidth;
645 I->IndexBitWidth = IndexBitWidth;
646 }
647 return Error::success();
648}
649
650Align DataLayout::getIntegerAlignment(uint32_t BitWidth,
651 bool abi_or_pref) const {
652 auto I = findAlignmentLowerBound(IntAlignments, BitWidth);
653 // If we don't have an exact match, use alignment of next larger integer
654 // type. If there is none, use alignment of largest integer type by going
655 // back one element.
656 if (I == IntAlignments.end())
657 --I;
658 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
659}
660
661namespace {
662
663class StructLayoutMap {
664 using LayoutInfoTy = DenseMap<StructType*, StructLayout*>;
665 LayoutInfoTy LayoutInfo;
666
667public:
668 ~StructLayoutMap() {
669 // Remove any layouts.
670 for (const auto &I : LayoutInfo) {
671 StructLayout *Value = I.second;
672 Value->~StructLayout();
673 free(Value);
674 }
675 }
676
677 StructLayout *&operator[](StructType *STy) {
678 return LayoutInfo[STy];
679 }
680};
681
682} // end anonymous namespace
683
684void DataLayout::clear() {
685 LegalIntWidths.clear();
686 IntAlignments.clear();
687 FloatAlignments.clear();
688 VectorAlignments.clear();
689 Pointers.clear();
690 delete static_cast<StructLayoutMap *>(LayoutMap);
691 LayoutMap = nullptr;
692}
693
695 clear();
696}
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<uint64_t>(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 getPointerAlignElem(AS).ABIAlign;
722}
723
725 return getPointerAlignElem(AS).PrefAlign;
726}
727
728unsigned DataLayout::getPointerSize(unsigned AS) const {
729 return divideCeil(getPointerAlignElem(AS).TypeBitWidth, 8);
730}
731
733 unsigned MaxIndexSize = 0;
734 for (auto &P : Pointers)
735 MaxIndexSize =
736 std::max(MaxIndexSize, (unsigned)divideCeil(P.TypeBitWidth, 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(getPointerAlignElem(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 =
789 abi_or_pref ? StructAlignment.ABIAlign : StructAlignment.PrefAlign;
790 return std::max(Align, Layout->getAlignment());
791 }
793 return getIntegerAlignment(Ty->getIntegerBitWidth(), abi_or_pref);
794 case Type::HalfTyID:
795 case Type::BFloatTyID:
796 case Type::FloatTyID:
797 case Type::DoubleTyID:
798 // PPC_FP128TyID and FP128TyID have different data contents, but the
799 // same size and alignment, so they look the same here.
801 case Type::FP128TyID:
802 case Type::X86_FP80TyID: {
804 auto I = findAlignmentLowerBound(FloatAlignments, BitWidth);
805 if (I != FloatAlignments.end() && I->TypeBitWidth == BitWidth)
806 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
807
808 // If we still couldn't find a reasonable default alignment, fall back
809 // to a simple heuristic that the alignment is the first power of two
810 // greater-or-equal to the store size of the type. This is a reasonable
811 // approximation of reality, and if the user wanted something less
812 // less conservative, they should have specified it explicitly in the data
813 // layout.
814 return Align(PowerOf2Ceil(BitWidth / 8));
815 }
820 auto I = findAlignmentLowerBound(VectorAlignments, BitWidth);
821 if (I != VectorAlignments.end() && I->TypeBitWidth == BitWidth)
822 return abi_or_pref ? I->ABIAlign : I->PrefAlign;
823
824 // By default, use natural alignment for vector types. This is consistent
825 // with what clang and llvm-gcc do.
826 //
827 // We're only calculating a natural alignment, so it doesn't have to be
828 // based on the full size for scalable vectors. Using the minimum element
829 // count should be enough here.
830 return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinValue()));
831 }
833 return Align(64);
834 case Type::TargetExtTyID: {
835 Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
836 return getAlignment(LayoutTy, abi_or_pref);
837 }
838 default:
839 llvm_unreachable("Bad type for getAlignment!!!");
840 }
841}
842
843/// TODO: Remove this function once the transition to Align is over.
845 return getABITypeAlign(Ty).value();
846}
847
849 return getAlignment(Ty, true);
850}
851
852/// TODO: Remove this function once the transition to Align is over.
854 return getPrefTypeAlign(Ty).value();
855}
856
858 return getAlignment(Ty, false);
859}
860
862 unsigned AddressSpace) const {
864}
865
868 "Expected a pointer or pointer vector type.");
869 unsigned NumBits = getPointerTypeSizeInBits(Ty);
870 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
871 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
872 return VectorType::get(IntTy, VecTy);
873 return IntTy;
874}
875
877 for (unsigned LegalIntWidth : LegalIntWidths)
878 if (Width <= LegalIntWidth)
879 return Type::getIntNTy(C, LegalIntWidth);
880 return nullptr;
881}
882
884 auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
885 return Max != LegalIntWidths.end() ? *Max : 0;
886}
887
889 unsigned AddressSpace) const {
891}
892
895 "Expected a pointer or pointer vector type.");
896 unsigned NumBits = getIndexTypeSizeInBits(Ty);
897 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
898 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
899 return VectorType::get(IntTy, VecTy);
900 return IntTy;
901}
902
904 ArrayRef<Value *> Indices) const {
905 int64_t Result = 0;
906
908 GTI = gep_type_begin(ElemTy, Indices),
909 GTE = gep_type_end(ElemTy, Indices);
910 for (; GTI != GTE; ++GTI) {
911 Value *Idx = GTI.getOperand();
912 if (StructType *STy = GTI.getStructTypeOrNull()) {
913 assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx");
914 unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
915
916 // Get structure layout information...
917 const StructLayout *Layout = getStructLayout(STy);
918
919 // Add in the offset, as calculated by the structure layout info...
920 Result += Layout->getElementOffset(FieldNo);
921 } else {
922 // Get the array index and the size of each array element.
923 if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
924 Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType());
925 }
926 }
927
928 return Result;
929}
930
932 // Skip over scalable or zero size elements. Also skip element sizes larger
933 // than the positive index space, because the arithmetic below may not be
934 // correct in that case.
935 unsigned BitWidth = Offset.getBitWidth();
936 if (ElemSize.isScalable() || ElemSize == 0 ||
937 !isUIntN(BitWidth - 1, ElemSize)) {
938 return APInt::getZero(BitWidth);
939 }
940
941 APInt Index = Offset.sdiv(ElemSize);
942 Offset -= Index * ElemSize;
943 if (Offset.isNegative()) {
944 // Prefer a positive remaining offset to allow struct indexing.
945 --Index;
946 Offset += ElemSize;
947 assert(Offset.isNonNegative() && "Remaining offset shouldn't be negative");
948 }
949 return Index;
950}
951
952std::optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
953 APInt &Offset) const {
954 if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
955 ElemTy = ArrTy->getElementType();
956 return getElementIndex(getTypeAllocSize(ElemTy), Offset);
957 }
958
959 if (isa<VectorType>(ElemTy)) {
960 // Vector GEPs are partially broken (e.g. for overaligned element types),
961 // and may be forbidden in the future, so avoid generating GEPs into
962 // vectors. See https://discourse.llvm.org/t/67497
963 return std::nullopt;
964 }
965
966 if (auto *STy = dyn_cast<StructType>(ElemTy)) {
967 const StructLayout *SL = getStructLayout(STy);
968 uint64_t IntOffset = Offset.getZExtValue();
969 if (IntOffset >= SL->getSizeInBytes())
970 return std::nullopt;
971
972 unsigned Index = SL->getElementContainingOffset(IntOffset);
974 ElemTy = STy->getElementType(Index);
975 return APInt(32, Index);
976 }
977
978 // Non-aggregate type.
979 return std::nullopt;
980}
981
983 APInt &Offset) const {
984 assert(ElemTy->isSized() && "Element type must be sized");
985 SmallVector<APInt> Indices;
987 while (Offset != 0) {
988 std::optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
989 if (!Index)
990 break;
991 Indices.push_back(*Index);
992 }
993
994 return Indices;
995}
996
997/// getPreferredAlign - Return the preferred alignment of the specified global.
998/// This includes an explicitly requested alignment (if the global has one).
1000 MaybeAlign GVAlignment = GV->getAlign();
1001 // If a section is specified, always precisely honor explicit alignment,
1002 // so we don't insert padding into a section we don't control.
1003 if (GVAlignment && GV->hasSection())
1004 return *GVAlignment;
1005
1006 // If no explicit alignment is specified, compute the alignment based on
1007 // the IR type. If an alignment is specified, increase it to match the ABI
1008 // alignment of the IR type.
1009 //
1010 // FIXME: Not sure it makes sense to use the alignment of the type if
1011 // there's already an explicit alignment specification.
1012 Type *ElemType = GV->getValueType();
1013 Align Alignment = getPrefTypeAlign(ElemType);
1014 if (GVAlignment) {
1015 if (*GVAlignment >= Alignment)
1016 Alignment = *GVAlignment;
1017 else
1018 Alignment = std::max(*GVAlignment, getABITypeAlign(ElemType));
1019 }
1020
1021 // If no explicit alignment is specified, and the global is large, increase
1022 // the alignment to 16.
1023 // FIXME: Why 16, specifically?
1024 if (GV->hasInitializer() && !GVAlignment) {
1025 if (Alignment < Align(16)) {
1026 // If the global is not external, see if it is large. If so, give it a
1027 // larger alignment.
1028 if (getTypeSizeInBits(ElemType) > 128)
1029 Alignment = Align(16); // 16-byte alignment.
1030 }
1031 }
1032 return Alignment;
1033}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static Error reportError(StringRef Message)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:227
static APInt getElementIndex(TypeSize ElemSize, APInt &Offset)
Definition: DataLayout.cpp:931
static Error getIntInBytes(StringRef R, IntTy &Result)
Get an unsigned integer representing the number of bits and convert it into bytes.
Definition: DataLayout.cpp:237
static SmallVectorImpl< LayoutAlignElem >::const_iterator findAlignmentLowerBound(const SmallVectorImpl< LayoutAlignElem > &Alignments, uint32_t BitWidth)
Definition: DataLayout.cpp:559
static Error getAddrSpace(StringRef R, unsigned &AddrSpace)
Definition: DataLayout.cpp:246
static Error split(StringRef Str, char Separator, std::pair< StringRef, StringRef > &Split)
Checked version of split, to ensure mandatory subparts.
Definition: DataLayout.cpp:215
static const std::pair< AlignTypeEnum, LayoutAlignElem > DefaultAlignments[]
Definition: DataLayout.cpp:161
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'.
Module.h This file contains the declarations for the Module class.
#define P(N)
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define error(X)
Class for arbitrary precision integers.
Definition: APInt.h:75
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:177
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:152
iterator begin() const
Definition: ArrayRef.h:151
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
uint64_t getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:853
static const char * getManglingComponent(const Triple &T)
Definition: DataLayout.cpp:149
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:406
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:982
unsigned getLargestLegalIntTypeSizeInBits() const
Returns the size of largest legal integer type size, or 0 if none are set.
Definition: DataLayout.cpp:883
void init(const Module *M)
Definition: DataLayout.cpp:537
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(StringRef LayoutDescription)
Constructs a DataLayout from a specification string. See reset().
Definition: DataLayout.h:193
static Expected< DataLayout > parse(StringRef LayoutDescription)
Parse a data layout string and return the layout.
Definition: DataLayout.cpp:203
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:861
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:848
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
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:175
uint64_t getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:844
IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
Definition: DataLayout.cpp:888
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:500
std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const
Get single GEP index to access Offset inside ElemTy.
Definition: DataLayout.cpp:952
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:876
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition: DataLayout.cpp:999
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:416
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:674
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:468
bool operator==(const DataLayout &Other) const
Definition: DataLayout.cpp:539
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:903
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:857
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
Tagged union holding either a T or a Error.
Definition: Error.h:470
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:79
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:109
Type * getValueType() const
Definition: GlobalValue.h:292
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:331
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:582
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:809
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
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:558
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:623
MutableArrayRef< uint64_t > getMemberOffsets()
Definition: DataLayout.h:644
uint64_t getSizeInBytes() const
Definition: DataLayout.h:630
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:653
Align getAlignment() const
Definition: DataLayout.h:634
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
Definition: DataLayout.cpp:83
Class to represent struct types.
Definition: DerivedTypes.h:213
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:327
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getIntegerBitWidth() const
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
@ ArrayTyID
Arrays.
Definition: Type.h:75
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
@ TargetExtTyID
Target extension type.
Definition: Type.h:79
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
@ LabelTyID
Labels.
Definition: Type.h:64
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ StructTyID
Structures.
Definition: Type.h:74
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
@ 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:73
@ 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:304
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:264
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:350
LLVM Value Representation.
Definition: Value.h:74
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:688
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:182
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:166
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:163
#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:31
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition: MathExtras.h:522
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:256
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:79
AddressSpace
Definition: NVPTXBaseInfo.h:21
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:2076
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:297
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:2051
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1246
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition: MathExtras.h:469
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
Definition: MemAlloc.h:25
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:2038
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:184
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
AlignTypeEnum
Enum used to categorize the alignment types stored by LayoutAlignElem.
Definition: DataLayout.h:54
@ FLOAT_ALIGN
Definition: DataLayout.h:57
@ VECTOR_ALIGN
Definition: DataLayout.h:56
@ INTEGER_ALIGN
Definition: DataLayout.h:55
@ AGGREGATE_ALIGN
Definition: DataLayout.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
Layout alignment element.
Definition: DataLayout.h:72
static LayoutAlignElem get(Align ABIAlign, Align PrefAlign, uint32_t BitWidth)
Definition: DataLayout.cpp:105
bool operator==(const LayoutAlignElem &rhs) const
Definition: DataLayout.cpp:115
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Layout pointer alignment element.
Definition: DataLayout.h:89
bool operator==(const PointerAlignElem &rhs) const
Definition: DataLayout.cpp:139
static PointerAlignElem getInBits(uint32_t AddressSpace, Align ABIAlign, Align PrefAlign, uint32_t TypeBitWidth, uint32_t IndexBitWidth)
Initializer.
Definition: DataLayout.cpp:124