Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Thu Jul 17 2025 12:28:13 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp