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 =
49 allocateDescriptor(Base, S->getType().getTypePtr(), *CharType,
50 Descriptor::GlobalMD, StringLength + 1,
51 /*IsConst=*/true,
52 /*isTemporary=*/false,
53 /*isMutable=*/false,
54 /*IsVolatile=*/false);
55
56 // Allocate storage for the string.
57 // The byte length does not include the null terminator.
58 unsigned GlobalIndex = Globals.size();
59 unsigned Sz = Desc->getAllocSize();
60 auto *G = new (Allocator, Sz) Global(Ctx.getEvalID(), Desc, /*IsStatic=*/true,
61 /*IsExtern=*/false);
62 G->block()->invokeCtor();
63
64 new (G->block()->rawData())
66 Globals.push_back(G);
67
68 const Pointer Ptr(G->block());
69 if (CharWidth == 1) {
70 std::memcpy(&Ptr.elem<char>(0), S->getString().data(), StringLength);
71 } else {
72 // Construct the string in storage.
73 for (unsigned I = 0; I <= StringLength; ++I) {
74 uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I);
76 Ptr.elem<T>(I) = T::from(CodePoint, BitWidth););
77 }
78 }
80
81 return GlobalIndex;
82}
83
84Pointer Program::getPtrGlobal(unsigned Idx) const {
85 assert(Idx < Globals.size());
86 return Pointer(Globals[Idx]->block());
87}
88
90 if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
91 return It->second;
92
93 // Find any previous declarations which were already evaluated.
94 std::optional<unsigned> Index;
95 for (const Decl *P = VD->getPreviousDecl(); P; P = P->getPreviousDecl()) {
96 if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
97 Index = It->second;
98 break;
99 }
100 }
101
102 // Map the decl to the existing index.
103 if (Index)
104 GlobalIndices[VD] = *Index;
105
106 return std::nullopt;
107}
108
110 if (auto It = GlobalIndices.find(E); It != GlobalIndices.end())
111 return It->second;
112 return std::nullopt;
113}
114
116 const Expr *Init) {
117 if (auto Idx = getGlobal(VD))
118 return Idx;
119
120 if (auto Idx = createGlobal(VD, Init)) {
121 GlobalIndices[VD] = *Idx;
122 return Idx;
123 }
124 return std::nullopt;
125}
126
127unsigned Program::getOrCreateDummy(const DeclTy &D, bool IsConstexprUnknown) {
128 assert(D);
129 // Dedup blocks since they are immutable and pointers cannot be compared.
130 if (auto It = DummyVariables.find(D.getOpaqueValue());
131 It != DummyVariables.end())
132 return It->second;
133
134 QualType QT;
135 bool IsWeak = false;
136 if (const auto *E = dyn_cast<const Expr *>(D)) {
137 QT = E->getType();
138 } else {
139 const auto *VD = cast<ValueDecl>(cast<const Decl *>(D));
140 IsWeak = VD->isWeak();
141 QT = VD->getType();
142 if (QT->isPointerOrReferenceType())
143 QT = QT->getPointeeType();
144 }
145 assert(!QT.isNull());
146
147 Descriptor *Desc;
148 if (OptPrimType T = Ctx.classify(QT))
149 Desc = createDescriptor(D, *T, /*SourceTy=*/nullptr, std::nullopt,
150 /*IsConst=*/QT.isConstQualified());
151 else
152 Desc = createDescriptor(D, QT.getTypePtr(), std::nullopt,
153 /*IsConst=*/QT.isConstQualified());
154 if (!Desc)
155 Desc = allocateDescriptor(D);
156
157 Desc->IsConstexprUnknown = IsConstexprUnknown;
158
159 assert(Desc);
160
161 // Allocate a block for storage.
162 unsigned I = Globals.size();
163
164 auto *G = new (Allocator, Desc->getAllocSize())
165 Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
166 /*IsExtern=*/false, IsWeak, /*IsDummy=*/true);
167 G->block()->invokeCtor();
168 assert(G->block()->isDummy());
169
170 Globals.push_back(G);
171 DummyVariables[D.getOpaqueValue()] = I;
172 return I;
173}
174
176 bool IsConstexprUnknown) {
177 bool IsStatic, IsExtern;
178 bool IsWeak = VD->isWeak();
179 if (const auto *Var = dyn_cast<VarDecl>(VD)) {
181 IsExtern = Var->hasExternalStorage();
184 IsStatic = true;
185 IsExtern = false;
186 } else {
187 IsStatic = false;
188 IsExtern = true;
189 }
190
191 // Register all previous declarations as well. For extern blocks, just replace
192 // the index with the new variable.
193 UnsignedOrNone Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern,
194 IsWeak, IsConstexprUnknown, Init);
195 if (!Idx)
196 return std::nullopt;
197
198 Global *NewGlobal = Globals[*Idx];
199 // Note that this loop has one iteration where Redecl == VD.
200 for (const Decl *Redecl : VD->redecls()) {
201
202 // If this redecl was registered as a dummy variable, it is now a proper
203 // global variable and points to the block we just created.
204 if (auto DummyIt = DummyVariables.find(Redecl);
205 DummyIt != DummyVariables.end()) {
206 Global *Dummy = Globals[DummyIt->second];
207 Dummy->block()->movePointersTo(NewGlobal->block());
208 Globals[DummyIt->second] = NewGlobal;
209 DummyVariables.erase(DummyIt);
210 }
211 // If the redeclaration hasn't been registered yet at all, we just set its
212 // global index to Idx. If it has been registered yet, it might have
213 // pointers pointing to it and we need to transfer those pointers to the new
214 // block.
215 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
216 if (Inserted) {
217 GlobalIndices[Redecl] = *Idx;
218 continue;
219 }
220
221 if (Redecl != VD) {
222 Block *RedeclBlock = Globals[Iter->second]->block();
223 // All pointers pointing to the previous extern decl now point to the
224 // new decl.
225 // A previous iteration might've already fixed up the pointers for this
226 // global.
227 if (RedeclBlock != NewGlobal->block())
228 RedeclBlock->movePointersTo(NewGlobal->block());
229
230 Globals[Iter->second] = NewGlobal;
231 }
232 Iter->second = *Idx;
233 }
234
235 return *Idx;
236}
237
239 if (auto Idx = getGlobal(E))
240 return Idx;
241 if (auto Idx = createGlobal(E, ExprType, /*IsStatic=*/true,
242 /*IsExtern=*/false, /*IsWeak=*/false,
243 /*IsConstexprUnknown=*/false)) {
244 GlobalIndices[E] = *Idx;
245 return *Idx;
246 }
247 return std::nullopt;
248}
249
251 bool IsStatic, bool IsExtern, bool IsWeak,
252 bool IsConstexprUnknown,
253 const Expr *Init) {
254 // Since this global variable is constexpr-unknown and a reference, register
255 // the pointee type instead. When referencing the variable, the pointer will
256 // then be of the pointee type instead of just PT_Ptr.
257 if (Ty->isReferenceType() && IsConstexprUnknown)
258 Ty = Ty->getPointeeType();
259
260 // Create a descriptor for the global.
261 Descriptor *Desc;
262 const bool IsConst = Ty.isConstQualified();
263 const bool IsTemporary = D.dyn_cast<const Expr *>();
264 const bool IsVolatile = Ty.isVolatileQualified();
265 if (OptPrimType T = Ctx.classify(Ty))
266 Desc = createDescriptor(D, *T, nullptr, Descriptor::GlobalMD, IsConst,
267 IsTemporary, /*IsMutable=*/false, IsVolatile);
268 else
269 Desc = createDescriptor(D, Ty.getTypePtr(), Descriptor::GlobalMD, IsConst,
270 IsTemporary, /*IsMutable=*/false, IsVolatile);
271
272 if (!Desc)
273 return std::nullopt;
274 Desc->IsConstexprUnknown = IsConstexprUnknown;
275
276 // Allocate a block for storage.
277 unsigned I = Globals.size();
278
279 auto *G = new (Allocator, Desc->getAllocSize()) Global(
280 Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
281 G->block()->invokeCtor();
282
283 // Initialize GlobalInlineDescriptor fields.
284 auto *GD = new (G->block()->rawData()) GlobalInlineDescriptor();
285 if (!Init)
286 GD->InitState = GlobalInitState::NoInitializer;
287 Globals.push_back(G);
288
289 return I;
290}
291
293 F = F->getCanonicalDecl();
294 assert(F);
295 auto It = Funcs.find(F);
296 return It == Funcs.end() ? nullptr : It->second.get();
297}
298
300 // Use the actual definition as a key.
301 RD = RD->getDefinition();
302 if (!RD)
303 return nullptr;
304
305 if (!RD->isCompleteDefinition())
306 return nullptr;
307
308 // Return an existing record if available. Otherwise, we insert nullptr now
309 // and replace that later, so recursive calls to this function with the same
310 // RecordDecl don't run into infinite recursion.
311 auto [It, Inserted] = Records.try_emplace(RD);
312 if (!Inserted)
313 return It->second;
314
315 // Number of bytes required by fields and base classes.
316 unsigned BaseSize = 0;
317 // Number of bytes required by virtual base.
318 unsigned VirtSize = 0;
319
320 // Helper to get a base descriptor.
321 auto GetBaseDesc = [this](const RecordDecl *BD,
322 const Record *BR) -> const Descriptor * {
323 if (!BR)
324 return nullptr;
325 return allocateDescriptor(BD, BR, std::nullopt, /*IsConst=*/false,
326 /*IsTemporary=*/false,
327 /*IsMutable=*/false, /*IsVolatile=*/false);
328 };
329
330 // Reserve space for base classes.
331 Record::BaseList Bases;
332 Record::VirtualBaseList VirtBases;
333 if (const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
334 Bases.reserve(CD->getNumBases());
335 for (const CXXBaseSpecifier &Spec : CD->bases()) {
336 if (Spec.isVirtual())
337 continue;
338
339 // In error cases, the base might not be a RecordType.
340 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
341 if (!BD)
342 return nullptr;
343 const Record *BR = getOrCreateRecord(BD);
344
345 const Descriptor *Desc = GetBaseDesc(BD, BR);
346 if (!Desc)
347 return nullptr;
348
349 BaseSize += align(sizeof(InlineDescriptor));
350 Bases.emplace_back(BD, Desc, BR, BaseSize);
351 BaseSize += align(BR->getSize());
352 }
353
354 for (const CXXBaseSpecifier &Spec : CD->vbases()) {
355 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
356 const Record *BR = getOrCreateRecord(BD);
357
358 const Descriptor *Desc = GetBaseDesc(BD, BR);
359 if (!Desc)
360 return nullptr;
361
362 VirtSize += align(sizeof(InlineDescriptor));
363 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
364 VirtSize += align(BR->getSize());
365 }
366 }
367
368 // Reserve space for fields.
369 Record::FieldList Fields;
370 Fields.reserve(RD->getNumFields());
371 bool HasPtrField = false;
372 for (const FieldDecl *FD : RD->fields()) {
373 FD = FD->getFirstDecl();
374 // Note that we DO create fields and descriptors
375 // for unnamed bitfields here, even though we later ignore
376 // them everywhere. That's so the FieldDecl's getFieldIndex() matches.
377
378 // Reserve space for the field's descriptor and the offset.
379 BaseSize += align(sizeof(InlineDescriptor));
380
381 // Classify the field and add its metadata.
382 QualType FT = FD->getType();
383 const bool IsConst = FT.isConstQualified();
384 const bool IsMutable = FD->isMutable();
385 const bool IsVolatile = FT.isVolatileQualified();
386 const Descriptor *Desc;
387 if (OptPrimType T = Ctx.classify(FT)) {
388 Desc = createDescriptor(FD, *T, nullptr, std::nullopt, IsConst,
389 /*IsTemporary=*/false, IsMutable, IsVolatile);
390 HasPtrField = HasPtrField || (T == PT_Ptr);
391 } else if ((Desc = createDescriptor(
392 FD, FT.getTypePtr(), std::nullopt, IsConst,
393 /*IsTemporary=*/false, IsMutable, IsVolatile))) {
394 HasPtrField =
395 HasPtrField ||
396 (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) ||
397 (Desc->ElemRecord && Desc->ElemRecord->hasPtrField());
398 } else {
399 Desc = allocateDescriptor(FD);
400 }
401 Fields.emplace_back(FD, Desc, BaseSize);
402 BaseSize += align(Desc->getAllocSize());
403 }
404
405 Record *R = new (Allocator)
406 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
407 VirtSize, BaseSize, HasPtrField);
408 Records[RD] = R;
409 return R;
410}
411
414 bool IsConst, bool IsTemporary,
415 bool IsMutable, bool IsVolatile,
416 const Expr *Init) {
417 // Classes and structures.
418 if (const auto *RD = Ty->getAsRecordDecl()) {
419 if (const auto *Record = getOrCreateRecord(RD))
420 return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
421 IsMutable, IsVolatile);
422 return allocateDescriptor(D, MDSize);
423 }
424
425 // Arrays.
426 if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
428 // Array of well-known bounds.
429 if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
430 size_t NumElems = CAT->getZExtSize();
431 if (OptPrimType T = Ctx.classify(ElemTy)) {
432 // Arrays of primitives.
433 unsigned ElemSize = primSize(*T);
434 if ((Descriptor::MaxArrayElemBytes / ElemSize) < NumElems) {
435 return nullptr;
436 }
437 return allocateDescriptor(D, CAT, *T, MDSize, NumElems, IsConst,
438 IsTemporary, IsMutable, IsVolatile);
439 }
440 // Arrays of composites. In this case, the array is a list of pointers,
441 // followed by the actual elements.
442 const Descriptor *ElemDesc = createDescriptor(
443 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
444 if (!ElemDesc)
445 return nullptr;
446 unsigned ElemSize = ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
447 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
448 return nullptr;
449 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
450 IsTemporary, IsMutable);
451 }
452
453 // Array of unknown bounds - cannot be accessed and pointer arithmetic
454 // is forbidden on pointers to such objects.
457 if (OptPrimType T = Ctx.classify(ElemTy)) {
458 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
460 }
461 const Descriptor *Desc = createDescriptor(
462 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
463 if (!Desc)
464 return nullptr;
465 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
467 }
468 }
469
470 // Atomic types.
471 if (const auto *AT = Ty->getAs<AtomicType>()) {
472 const Type *InnerTy = AT->getValueType().getTypePtr();
473 return createDescriptor(D, InnerTy, MDSize, IsConst, IsTemporary,
474 IsMutable);
475 }
476
477 // Complex types - represented as arrays of elements.
478 if (const auto *CT = Ty->getAs<ComplexType>()) {
479 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
480 if (!ElemTy)
481 return nullptr;
482
483 return allocateDescriptor(D, CT, *ElemTy, MDSize, 2, IsConst, IsTemporary,
484 IsMutable, IsVolatile);
485 }
486
487 // Same with vector types.
488 if (const auto *VT = Ty->getAs<VectorType>()) {
489 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
490 if (!ElemTy)
491 return nullptr;
492
493 return allocateDescriptor(D, VT, *ElemTy, MDSize, VT->getNumElements(),
494 IsConst, IsTemporary, IsMutable, IsVolatile);
495 }
496
497 // Same with constant matrix types.
498 if (const auto *MT = Ty->getAs<ConstantMatrixType>()) {
499 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
500 if (!ElemTy)
501 return nullptr;
502
503 return allocateDescriptor(D, MT, *ElemTy, MDSize,
504 MT->getNumElementsFlattened(), IsConst,
505 IsTemporary, IsMutable, IsVolatile);
506 }
507
508 return nullptr;
509}
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:3786
QualType getElementType() const
Definition TypeBase.h:3798
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3339
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4451
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:1078
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition DeclBase.h:1066
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:3191
Represents a function declaration or definition.
Definition Decl.h:2027
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3724
A global _GUID constant.
Definition DeclCXX.h:4416
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8531
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:8447
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8520
Represents a struct/union/class.
Definition Decl.h:4356
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4572
field_range fields() const
Definition Decl.h:4559
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4540
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1805
unsigned getLength() const
Definition Expr.h:1915
uint32_t getCodeUnit(size_t i) const
Definition Expr.h:1888
StringRef getString() const
Definition Expr.h:1873
unsigned getCharByteWidth() const
Definition Expr.h:1916
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3849
A template parameter object.
The base class of the type hierarchy.
Definition TypeBase.h:1875
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9353
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isReferenceType() const
Definition TypeBase.h:8708
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:9330
bool isPointerOrReferenceType() const
Definition TypeBase.h:8688
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9277
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4473
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:5578
Represents a GCC generic vector type.
Definition TypeBase.h:4239
A memory block, either on the stack or in the heap.
Definition InterpBlock.h:44
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:159
OptPrimType classify(QualType T) const
Classifies a type.
Definition Context.cpp:426
unsigned getEvalID() const
Definition Context.h:174
Bytecode function.
Definition Function.h:99
A pointer to a memory block, live or dead.
Definition Pointer.h:394
void initializeAllElements() const
Initialize all elements of a primitive array at once.
Definition Pointer.cpp:596
T & elem(unsigned I) const
Dereferences the element at index I.
Definition Pointer.h:876
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init, bool IsConstexprUnknown=false)
Creates a global and returns its index.
Definition Program.cpp:175
unsigned getOrCreateDummy(const DeclTy &D, bool IsConstexprUnknown=false)
Returns or creates a dummy value for unknown declarations.
Definition Program.cpp:127
Function * getFunction(const FunctionDecl *F)
Returns a function.
Definition Program.cpp:292
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:115
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:84
const void * getNativePointer(unsigned Idx) const
Returns the value of a marshalled native pointer.
Definition Program.cpp:31
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:122
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:162
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Definition Program.cpp:299
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:2382
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:142
Describes a memory block created by an allocation site.
Definition Descriptor.h:123
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Definition Descriptor.h:248
static constexpr MetadataSize GlobalMD
Definition Descriptor.h:146
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
Definition Descriptor.h:149
std::optional< unsigned > MetadataSize
Definition Descriptor.h:144
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Definition Descriptor.h:265
PrimType getPrimType() const
Definition Descriptor.h:242
const Record *const ElemRecord
Pointer to the record, if block contains records.
Definition Descriptor.h:154
Descriptor used for global variables.
Definition Descriptor.h:50
Inline descriptor embedded in structures and arrays.
Definition Descriptor.h:68