clang 23.0.0git
Program.cpp
Go to the documentation of this file.
1//===--- Program.cpp - Bytecode for the constexpr VM ------------*- C++ -*-===//
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#include "Program.h"
10#include "Char.h"
11#include "Context.h"
12#include "Function.h"
13#include "Integral.h"
14#include "PrimType.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclCXX.h"
18
19using namespace clang;
20using namespace clang::interp;
21
22unsigned Program::getOrCreateNativePointer(const void *Ptr) {
23 auto [It, Inserted] =
24 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
25 if (Inserted)
26 NativePointers.push_back(Ptr);
27
28 return It->second;
29}
30
31const void *Program::getNativePointer(unsigned Idx) const {
32 return NativePointers[Idx];
33}
34
36 const size_t CharWidth = S->getCharByteWidth();
37 const size_t BitWidth = CharWidth * Ctx.getCharBit();
38 unsigned StringLength = S->getLength();
39
40 OptPrimType CharType =
41 Ctx.classify(S->getType()->castAsArrayTypeUnsafe()->getElementType());
42 assert(CharType);
43
44 if (!Base)
45 Base = S;
46
47 // Create a descriptor for the string.
48 Descriptor *Desc = allocateDescriptor(Base, *CharType, Descriptor::GlobalMD,
49 StringLength + 1,
50 /*IsConst=*/true,
51 /*isTemporary=*/false,
52 /*isMutable=*/false);
53
54 // Allocate storage for the string.
55 // The byte length does not include the null terminator.
56 unsigned GlobalIndex = Globals.size();
57 unsigned Sz = Desc->getAllocSize();
58 auto *G = new (Allocator, Sz) Global(Ctx.getEvalID(), Desc, /*IsStatic=*/true,
59 /*IsExtern=*/false);
60 G->block()->invokeCtor();
61
62 new (G->block()->rawData())
64 Globals.push_back(G);
65
66 const Pointer Ptr(G->block());
67 if (CharWidth == 1) {
68 std::memcpy(&Ptr.elem<char>(0), S->getString().data(), StringLength);
69 } else {
70 // Construct the string in storage.
71 for (unsigned I = 0; I <= StringLength; ++I) {
72 uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
74 Ptr.elem<T>(I) = T::from(CodePoint, BitWidth););
75 }
76 }
78
79 return GlobalIndex;
80}
81
82Pointer Program::getPtrGlobal(unsigned Idx) const {
83 assert(Idx < Globals.size());
84 return Pointer(Globals[Idx]->block());
85}
86
88 if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
89 return It->second;
90
91 // Find any previous declarations which were already evaluated.
92 std::optional<unsigned> Index;
93 for (const Decl *P = VD->getPreviousDecl(); P; P = P->getPreviousDecl()) {
94 if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
95 Index = It->second;
96 break;
97 }
98 }
99
100 // Map the decl to the existing index.
101 if (Index)
102 GlobalIndices[VD] = *Index;
103
104 return std::nullopt;
105}
106
108 if (auto It = GlobalIndices.find(E); It != GlobalIndices.end())
109 return It->second;
110 return std::nullopt;
111}
112
114 const Expr *Init) {
115 if (auto Idx = getGlobal(VD))
116 return Idx;
117
118 if (auto Idx = createGlobal(VD, Init)) {
119 GlobalIndices[VD] = *Idx;
120 return Idx;
121 }
122 return std::nullopt;
123}
124
126 assert(D);
127 // Dedup blocks since they are immutable and pointers cannot be compared.
128 if (auto It = DummyVariables.find(D.getOpaqueValue());
129 It != DummyVariables.end())
130 return It->second;
131
132 QualType QT;
133 bool IsWeak = false;
134 if (const auto *E = dyn_cast<const Expr *>(D)) {
135 QT = E->getType();
136 } else {
137 const auto *VD = cast<ValueDecl>(cast<const Decl *>(D));
138 IsWeak = VD->isWeak();
139 QT = VD->getType();
140 if (QT->isPointerOrReferenceType())
141 QT = QT->getPointeeType();
142 }
143 assert(!QT.isNull());
144
145 Descriptor *Desc;
146 if (OptPrimType T = Ctx.classify(QT))
147 Desc = createDescriptor(D, *T, /*SourceTy=*/nullptr, std::nullopt,
148 /*IsConst=*/QT.isConstQualified());
149 else
150 Desc = createDescriptor(D, QT.getTypePtr(), std::nullopt,
151 /*IsConst=*/QT.isConstQualified());
152 if (!Desc)
153 Desc = allocateDescriptor(D);
154
155 assert(Desc);
156
157 // Allocate a block for storage.
158 unsigned I = Globals.size();
159
160 auto *G = new (Allocator, Desc->getAllocSize())
161 Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
162 /*IsExtern=*/false, IsWeak, /*IsDummy=*/true);
163 G->block()->invokeCtor();
164 assert(G->block()->isDummy());
165
166 Globals.push_back(G);
167 DummyVariables[D.getOpaqueValue()] = I;
168 return I;
169}
170
172 bool IsStatic, IsExtern;
173 bool IsWeak = VD->isWeak();
174 if (const auto *Var = dyn_cast<VarDecl>(VD)) {
176 IsExtern = Var->hasExternalStorage();
179 IsStatic = true;
180 IsExtern = false;
181 } else {
182 IsStatic = false;
183 IsExtern = true;
184 }
185
186 // Register all previous declarations as well. For extern blocks, just replace
187 // the index with the new variable.
188 UnsignedOrNone Idx =
189 createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init);
190 if (!Idx)
191 return std::nullopt;
192
193 Global *NewGlobal = Globals[*Idx];
194 // Note that this loop has one iteration where Redecl == VD.
195 for (const Decl *Redecl : VD->redecls()) {
196
197 // If this redecl was registered as a dummy variable, it is now a proper
198 // global variable and points to the block we just created.
199 if (auto DummyIt = DummyVariables.find(Redecl);
200 DummyIt != DummyVariables.end()) {
201 Global *Dummy = Globals[DummyIt->second];
202 Dummy->block()->movePointersTo(NewGlobal->block());
203 Globals[DummyIt->second] = NewGlobal;
204 DummyVariables.erase(DummyIt);
205 }
206 // If the redeclaration hasn't been registered yet at all, we just set its
207 // global index to Idx. If it has been registered yet, it might have
208 // pointers pointing to it and we need to transfer those pointers to the new
209 // block.
210 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
211 if (Inserted) {
212 GlobalIndices[Redecl] = *Idx;
213 continue;
214 }
215
216 if (Redecl != VD) {
217 if (Block *RedeclBlock = Globals[Iter->second]->block();
218 RedeclBlock->isExtern()) {
219
220 // All pointers pointing to the previous extern decl now point to the
221 // new decl.
222 // A previous iteration might've already fixed up the pointers for this
223 // global.
224 if (RedeclBlock != NewGlobal->block())
225 RedeclBlock->movePointersTo(NewGlobal->block());
226
227 Globals[Iter->second] = NewGlobal;
228 }
229 }
230 Iter->second = *Idx;
231 }
232
233 return *Idx;
234}
235
237 if (auto Idx = getGlobal(E))
238 return Idx;
239 if (auto Idx = createGlobal(E, ExprType, /*IsStatic=*/true,
240 /*IsExtern=*/false, /*IsWeak=*/false)) {
241 GlobalIndices[E] = *Idx;
242 return *Idx;
243 }
244 return std::nullopt;
245}
246
248 bool IsStatic, bool IsExtern, bool IsWeak,
249 const Expr *Init) {
250 // Create a descriptor for the global.
251 Descriptor *Desc;
252 const bool IsConst = Ty.isConstQualified();
253 const bool IsTemporary = D.dyn_cast<const Expr *>();
254 const bool IsVolatile = Ty.isVolatileQualified();
255 if (OptPrimType T = Ctx.classify(Ty))
256 Desc = createDescriptor(D, *T, nullptr, Descriptor::GlobalMD, IsConst,
257 IsTemporary, /*IsMutable=*/false, IsVolatile);
258 else
259 Desc = createDescriptor(D, Ty.getTypePtr(), Descriptor::GlobalMD, IsConst,
260 IsTemporary, /*IsMutable=*/false, IsVolatile);
261
262 if (!Desc)
263 return std::nullopt;
264
265 // Allocate a block for storage.
266 unsigned I = Globals.size();
267
268 auto *G = new (Allocator, Desc->getAllocSize()) Global(
269 Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
270 G->block()->invokeCtor();
271
272 // Initialize GlobalInlineDescriptor fields.
273 auto *GD = new (G->block()->rawData()) GlobalInlineDescriptor();
274 if (!Init)
275 GD->InitState = GlobalInitState::NoInitializer;
276 Globals.push_back(G);
277
278 return I;
279}
280
282 F = F->getCanonicalDecl();
283 assert(F);
284 auto It = Funcs.find(F);
285 return It == Funcs.end() ? nullptr : It->second.get();
286}
287
289 // Use the actual definition as a key.
290 RD = RD->getDefinition();
291 if (!RD)
292 return nullptr;
293
294 if (!RD->isCompleteDefinition())
295 return nullptr;
296
297 // Return an existing record if available. Otherwise, we insert nullptr now
298 // and replace that later, so recursive calls to this function with the same
299 // RecordDecl don't run into infinite recursion.
300 auto [It, Inserted] = Records.try_emplace(RD);
301 if (!Inserted)
302 return It->second;
303
304 // Number of bytes required by fields and base classes.
305 unsigned BaseSize = 0;
306 // Number of bytes required by virtual base.
307 unsigned VirtSize = 0;
308
309 // Helper to get a base descriptor.
310 auto GetBaseDesc = [this](const RecordDecl *BD,
311 const Record *BR) -> const Descriptor * {
312 if (!BR)
313 return nullptr;
314 return allocateDescriptor(BD, BR, std::nullopt, /*IsConst=*/false,
315 /*IsTemporary=*/false,
316 /*IsMutable=*/false, /*IsVolatile=*/false);
317 };
318
319 // Reserve space for base classes.
320 Record::BaseList Bases;
321 Record::VirtualBaseList VirtBases;
322 if (const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
323 Bases.reserve(CD->getNumBases());
324 for (const CXXBaseSpecifier &Spec : CD->bases()) {
325 if (Spec.isVirtual())
326 continue;
327
328 // In error cases, the base might not be a RecordType.
329 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
330 if (!BD)
331 return nullptr;
332 const Record *BR = getOrCreateRecord(BD);
333
334 const Descriptor *Desc = GetBaseDesc(BD, BR);
335 if (!Desc)
336 return nullptr;
337
338 BaseSize += align(sizeof(InlineDescriptor));
339 Bases.emplace_back(BD, Desc, BR, BaseSize);
340 BaseSize += align(BR->getSize());
341 }
342
343 for (const CXXBaseSpecifier &Spec : CD->vbases()) {
344 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
345 const Record *BR = getOrCreateRecord(BD);
346
347 const Descriptor *Desc = GetBaseDesc(BD, BR);
348 if (!Desc)
349 return nullptr;
350
351 VirtSize += align(sizeof(InlineDescriptor));
352 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
353 VirtSize += align(BR->getSize());
354 }
355 }
356
357 // Reserve space for fields.
358 Record::FieldList Fields;
359 Fields.reserve(RD->getNumFields());
360 bool HasPtrField = false;
361 for (const FieldDecl *FD : RD->fields()) {
362 FD = FD->getFirstDecl();
363 // Note that we DO create fields and descriptors
364 // for unnamed bitfields here, even though we later ignore
365 // them everywhere. That's so the FieldDecl's getFieldIndex() matches.
366
367 // Reserve space for the field's descriptor and the offset.
368 BaseSize += align(sizeof(InlineDescriptor));
369
370 // Classify the field and add its metadata.
371 QualType FT = FD->getType();
372 const bool IsConst = FT.isConstQualified();
373 const bool IsMutable = FD->isMutable();
374 const bool IsVolatile = FT.isVolatileQualified();
375 const Descriptor *Desc;
376 if (OptPrimType T = Ctx.classify(FT)) {
377 Desc = createDescriptor(FD, *T, nullptr, std::nullopt, IsConst,
378 /*IsTemporary=*/false, IsMutable, IsVolatile);
379 HasPtrField = HasPtrField || (T == PT_Ptr);
380 } else if ((Desc = createDescriptor(
381 FD, FT.getTypePtr(), std::nullopt, IsConst,
382 /*IsTemporary=*/false, IsMutable, IsVolatile))) {
383 HasPtrField =
384 HasPtrField ||
385 (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) ||
386 (Desc->ElemRecord && Desc->ElemRecord->hasPtrField());
387 } else {
388 Desc = allocateDescriptor(FD);
389 }
390 Fields.emplace_back(FD, Desc, BaseSize);
391 BaseSize += align(Desc->getAllocSize());
392 }
393
394 Record *R = new (Allocator)
395 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
396 VirtSize, BaseSize, HasPtrField);
397 Records[RD] = R;
398 return R;
399}
400
403 bool IsConst, bool IsTemporary,
404 bool IsMutable, bool IsVolatile,
405 const Expr *Init) {
406 // Classes and structures.
407 if (const auto *RD = Ty->getAsRecordDecl()) {
408 if (const auto *Record = getOrCreateRecord(RD))
409 return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
410 IsMutable, IsVolatile);
411 return allocateDescriptor(D, MDSize);
412 }
413
414 // Arrays.
415 if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
417 // Array of well-known bounds.
418 if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
419 size_t NumElems = CAT->getZExtSize();
420 if (OptPrimType T = Ctx.classify(ElemTy)) {
421 // Arrays of primitives.
422 unsigned ElemSize = primSize(*T);
423 if ((Descriptor::MaxArrayElemBytes / ElemSize) < NumElems) {
424 return nullptr;
425 }
426 return allocateDescriptor(D, *T, MDSize, NumElems, IsConst, IsTemporary,
427 IsMutable);
428 }
429 // Arrays of composites. In this case, the array is a list of pointers,
430 // followed by the actual elements.
431 const Descriptor *ElemDesc = createDescriptor(
432 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
433 if (!ElemDesc)
434 return nullptr;
435 unsigned ElemSize = ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
436 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
437 return nullptr;
438 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
439 IsTemporary, IsMutable);
440 }
441
442 // Array of unknown bounds - cannot be accessed and pointer arithmetic
443 // is forbidden on pointers to such objects.
446 if (OptPrimType T = Ctx.classify(ElemTy)) {
447 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
449 }
450 const Descriptor *Desc = createDescriptor(
451 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
452 if (!Desc)
453 return nullptr;
454 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
456 }
457 }
458
459 // Atomic types.
460 if (const auto *AT = Ty->getAs<AtomicType>()) {
461 const Type *InnerTy = AT->getValueType().getTypePtr();
462 return createDescriptor(D, InnerTy, MDSize, IsConst, IsTemporary,
463 IsMutable);
464 }
465
466 // Complex types - represented as arrays of elements.
467 if (const auto *CT = Ty->getAs<ComplexType>()) {
468 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
469 if (!ElemTy)
470 return nullptr;
471
472 return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
473 IsMutable);
474 }
475
476 // Same with vector types.
477 if (const auto *VT = Ty->getAs<VectorType>()) {
478 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
479 if (!ElemTy)
480 return nullptr;
481
482 return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
483 IsTemporary, IsMutable);
484 }
485
486 // Same with constant matrix types.
487 if (const auto *MT = Ty->getAs<ConstantMatrixType>()) {
488 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
489 if (!ElemTy)
490 return nullptr;
491
492 return allocateDescriptor(D, *ElemTy, MDSize, MT->getNumElementsFlattened(),
493 IsConst, IsTemporary, IsMutable);
494 }
495
496 return nullptr;
497}
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Record Record
Definition MachO.h:31
#define INT_TYPE_SWITCH_NO_BOOL(Expr, B)
Definition PrimType.h:279
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3777
QualType getElementType() const
Definition TypeBase.h:3789
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3330
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4442
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition DeclBase.h:1074
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition DeclBase.h:1062
This represents one expression.
Definition Expr.h:112
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3175
Represents a function declaration or definition.
Definition Decl.h:2015
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3713
A global _GUID constant.
Definition DeclCXX.h:4414
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8520
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8436
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8509
Represents a struct/union/class.
Definition Decl.h:4342
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4558
field_range fields() const
Definition Decl.h:4545
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4526
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
unsigned getLength() const
Definition Expr.h:1912
uint32_t getCodeUnit(size_t i) const
Definition Expr.h:1885
StringRef getString() const
Definition Expr.h:1870
unsigned getCharByteWidth() const
Definition Expr.h:1913
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3833
A template parameter object.
The base class of the type hierarchy.
Definition TypeBase.h:1871
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9342
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9319
bool isPointerOrReferenceType() const
Definition TypeBase.h:8677
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9266
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4471
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition Decl.cpp:5547
Represents a GCC generic vector type.
Definition TypeBase.h:4230
A memory block, either on the stack or in the heap.
Definition InterpBlock.h:44
bool isExtern() const
Checks if the block is extern.
Definition InterpBlock.h:77
void movePointersTo(Block *B)
Move all pointers from this block to.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
Definition Context.h:151
OptPrimType classify(QualType T) const
Classifies a type.
Definition Context.cpp:408
unsigned getEvalID() const
Definition Context.h:166
Bytecode function.
Definition Function.h:99
A pointer to a memory block, live or dead.
Definition Pointer.h:97
void initializeAllElements() const
Initialize all elements of a primitive array at once.
Definition Pointer.cpp:582
T & elem(unsigned I) const
Dereferences the element at index I.
Definition Pointer.h:703
Function * getFunction(const FunctionDecl *F)
Returns a function.
Definition Program.cpp:281
Block * getGlobal(unsigned Idx)
Returns the value of a global.
Definition Program.h:73
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
Definition Program.cpp:113
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
Definition Program.cpp:22
Pointer getPtrGlobal(unsigned Idx) const
Returns a pointer to a global.
Definition Program.cpp:82
unsigned getOrCreateDummy(const DeclTy &D)
Returns or creates a dummy value for unknown declarations.
Definition Program.cpp:125
const void * getNativePointer(unsigned Idx) const
Returns the value of a marshalled native pointer.
Definition Program.cpp:31
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init)
Creates a global and returns its index.
Definition Program.cpp:171
Descriptor * createDescriptor(const DeclTy &D, PrimType T, const Type *SourceTy=nullptr, Descriptor::MetadataSize MDSize=std::nullopt, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false, bool IsVolatile=false)
Creates a descriptor for a primitive type.
Definition Program.h:121
unsigned createGlobalString(const StringLiteral *S, const Expr *Base=nullptr)
Emits a string literal among global data.
Definition Program.cpp:35
UnsignedOrNone getCurrentDecl() const
Returns the current declaration ID.
Definition Program.h:161
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Definition Program.cpp:288
Structure/Class descriptor.
Definition Record.h:25
bool hasPtrField() const
If this record (or any of its bases) contains a field of type PT_Ptr.
Definition Record.h:83
unsigned getSize() const
Returns the size of the record.
Definition Record.h:73
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition Descriptor.h:29
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Definition PrimType.h:201
bool Init(InterpState &S, CodePtr OpPC)
Definition Interp.h:2283
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
Definition PrimType.cpp:24
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
Definition Address.h:327
Token to denote structures of unknown size.
Definition Descriptor.h:141
Describes a memory block created by an allocation site.
Definition Descriptor.h:122
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Definition Descriptor.h:247
static constexpr MetadataSize GlobalMD
Definition Descriptor.h:145
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
Definition Descriptor.h:148
std::optional< unsigned > MetadataSize
Definition Descriptor.h:143
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Definition Descriptor.h:264
PrimType getPrimType() const
Definition Descriptor.h:241
const Record *const ElemRecord
Pointer to the record, if block contains records.
Definition Descriptor.h:153
Descriptor used for global variables.
Definition Descriptor.h:50
Inline descriptor embedded in structures and arrays.
Definition Descriptor.h:67