clang 24.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(DeclTy D, bool IsConstexprUnknown) {
128 assert(D);
129
130 if (const auto *VD = dyn_cast_if_present<VarDecl>(dyn_cast<const Decl *>(D)))
131 D = VD->getFirstDecl();
132
133 // Dedup blocks since they are immutable and pointers cannot be compared.
134 if (auto It = DummyVariables.find(D.getOpaqueValue());
135 It != DummyVariables.end())
136 return It->second;
137
138 QualType QT;
139 bool IsWeak = false;
140 if (const auto *E = dyn_cast<const Expr *>(D)) {
141 QT = E->getType();
142 } else {
143 const auto *VD = cast<ValueDecl>(cast<const Decl *>(D));
144 IsWeak = VD->isWeak();
145 QT = VD->getType();
146 if (QT->isPointerOrReferenceType())
147 QT = QT->getPointeeType();
148 }
149 assert(!QT.isNull());
150
151 Descriptor *Desc;
152 if (OptPrimType T = Ctx.classify(QT))
153 Desc = createDescriptor(D, *T, /*SourceTy=*/nullptr, std::nullopt,
154 /*IsConst=*/QT.isConstQualified());
155 else
156 Desc = createDescriptor(D, QT.getTypePtr(), std::nullopt,
157 /*IsConst=*/QT.isConstQualified());
158 if (!Desc)
159 Desc = allocateDescriptor(D);
160
161 Desc->IsConstexprUnknown = IsConstexprUnknown;
162
163 assert(Desc);
164
165 // Allocate a block for storage.
166 unsigned I = Globals.size();
167
168 auto *G = new (Allocator, Desc->getAllocSize())
169 Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
170 /*IsExtern=*/false, IsWeak, /*IsDummy=*/true);
171 G->block()->invokeCtor();
172 assert(G->block()->isDummy());
173
174 Globals.push_back(G);
175 DummyVariables[D.getOpaqueValue()] = I;
176 return I;
177}
178
180 bool IsConstexprUnknown) {
181 bool IsStatic, IsExtern;
182 bool IsWeak = VD->isWeak();
183 if (const auto *Var = dyn_cast<VarDecl>(VD)) {
185 IsExtern = Var->hasExternalStorage();
188 IsStatic = true;
189 IsExtern = false;
190 } else {
191 IsStatic = false;
192 IsExtern = true;
193 }
194
195 // Register all previous declarations as well. For extern blocks, just replace
196 // the index with the new variable.
197 UnsignedOrNone Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern,
198 IsWeak, IsConstexprUnknown, Init);
199 if (!Idx)
200 return std::nullopt;
201
202 Global *NewGlobal = Globals[*Idx];
203 GlobalIndices[VD] = *Idx;
204
205 for (const Decl *Redecl = VD->getPreviousDecl(); Redecl;
206 Redecl = Redecl->getPreviousDecl()) {
207 // If this redecl was registered as a dummy variable, it is now a proper
208 // global variable and points to the block we just created.
209 if (auto DummyIt = DummyVariables.find(Redecl);
210 DummyIt != DummyVariables.end()) {
211 Global *Dummy = Globals[DummyIt->second];
212 Dummy->block()->movePointersTo(NewGlobal->block());
213 Globals[DummyIt->second] = NewGlobal;
214 DummyVariables.erase(DummyIt);
215 }
216 // If the redeclaration hasn't been registered yet at all, we just set its
217 // global index to Idx. If it has been registered yet, it might have
218 // pointers pointing to it and we need to transfer those pointers to the new
219 // block.
220 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
221 if (Inserted) {
222 GlobalIndices[Redecl] = *Idx;
223 continue;
224 }
225
226 Block *RedeclBlock = Globals[Iter->second]->block();
227 // All pointers pointing to the previous extern decl now point to the
228 // new decl.
229 // A previous iteration might've already fixed up the pointers for this
230 // global.
231 if (RedeclBlock != NewGlobal->block())
232 RedeclBlock->movePointersTo(NewGlobal->block());
233
234 Globals[Iter->second] = NewGlobal;
235 Iter->second = *Idx;
236 }
237
238 return *Idx;
239}
240
242 if (auto Idx = getGlobal(E))
243 return Idx;
244 if (auto Idx = createGlobal(E, ExprType, /*IsStatic=*/true,
245 /*IsExtern=*/false, /*IsWeak=*/false,
246 /*IsConstexprUnknown=*/false)) {
247 GlobalIndices[E] = *Idx;
248 return *Idx;
249 }
250 return std::nullopt;
251}
252
254 bool IsStatic, bool IsExtern, bool IsWeak,
255 bool IsConstexprUnknown,
256 const Expr *Init) {
257 // Since this global variable is constexpr-unknown and a reference, register
258 // the pointee type instead. When referencing the variable, the pointer will
259 // then be of the pointee type instead of just PT_Ptr.
260 if (Ty->isReferenceType() && IsConstexprUnknown)
261 Ty = Ty->getPointeeType();
262
263 // Create a descriptor for the global.
264 Descriptor *Desc;
265 const bool IsConst = Ty.isConstQualified();
266 const bool IsTemporary = D.dyn_cast<const Expr *>();
267 const bool IsVolatile = Ty.isVolatileQualified();
268 if (OptPrimType T = Ctx.classify(Ty))
269 Desc = createDescriptor(D, *T, nullptr, Descriptor::GlobalMD, IsConst,
270 IsTemporary, /*IsMutable=*/false, IsVolatile);
271 else
272 Desc = createDescriptor(D, Ty.getTypePtr(), Descriptor::GlobalMD, IsConst,
273 IsTemporary, /*IsMutable=*/false, IsVolatile);
274
275 if (!Desc)
276 return std::nullopt;
277 Desc->IsConstexprUnknown = IsConstexprUnknown;
278
279 // Allocate a block for storage.
280 unsigned I = Globals.size();
281
282 auto *G = new (Allocator, Desc->getAllocSize()) Global(
283 Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
284 G->block()->invokeCtor();
285
286 // Initialize GlobalInlineDescriptor fields.
287 auto *GD = new (G->block()->rawData()) GlobalInlineDescriptor();
288 if (!Init)
289 GD->InitState = GlobalInitState::NoInitializer;
290 Globals.push_back(G);
291
292 return I;
293}
294
296 F = F->getCanonicalDecl();
297 assert(F);
298 auto It = Funcs.find(F);
299 return It == Funcs.end() ? nullptr : It->second.get();
300}
301
303 // Use the actual definition as a key.
304 RD = RD->getDefinition();
305 if (!RD)
306 return nullptr;
307
308 if (!RD->isCompleteDefinition())
309 return nullptr;
310
311 // Return an existing record if available. Otherwise, we insert nullptr now
312 // and replace that later, so recursive calls to this function with the same
313 // RecordDecl don't run into infinite recursion.
314 auto [It, Inserted] = Records.try_emplace(RD);
315 if (!Inserted)
316 return It->second;
317
318 // Number of bytes required by fields and base classes.
319 unsigned BaseSize = 0;
320 // Number of bytes required by virtual base.
321 unsigned VirtSize = 0;
322
323 // Helper to get a base descriptor.
324 auto GetBaseDesc = [this](const RecordDecl *BD,
325 const Record *BR) -> const Descriptor * {
326 if (!BR)
327 return nullptr;
328 return allocateDescriptor(BD, BR, std::nullopt, /*IsConst=*/false,
329 /*IsTemporary=*/false,
330 /*IsMutable=*/false, /*IsVolatile=*/false);
331 };
332
333 // Reserve space for base classes.
334 Record::BaseList Bases;
335 Record::VirtualBaseList VirtBases;
336 if (const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
337 Bases.reserve(CD->getNumBases());
338 for (const CXXBaseSpecifier &Spec : CD->bases()) {
339 if (Spec.isVirtual())
340 continue;
341
342 // In error cases, the base might not be a RecordType.
343 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
344 if (!BD)
345 return nullptr;
346 const Record *BR = getOrCreateRecord(BD);
347
348 const Descriptor *Desc = GetBaseDesc(BD, BR);
349 if (!Desc)
350 return nullptr;
351
352 BaseSize += align(sizeof(InlineDescriptor));
353 Bases.emplace_back(BD, Desc, BR, BaseSize);
354 BaseSize += align(BR->getSize());
355 }
356
357 for (const CXXBaseSpecifier &Spec : CD->vbases()) {
358 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
359 const Record *BR = getOrCreateRecord(BD);
360
361 const Descriptor *Desc = GetBaseDesc(BD, BR);
362 if (!Desc)
363 return nullptr;
364
365 VirtSize += align(sizeof(InlineDescriptor));
366 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
367 VirtSize += align(BR->getSize());
368 }
369 }
370
371 // Reserve space for fields.
372 Record::FieldList Fields;
373 Fields.reserve(RD->getNumFields());
374 bool HasPtrField = false;
375 for (const FieldDecl *FD : RD->fields()) {
376 FD = FD->getFirstDecl();
377 // Note that we DO create fields and descriptors
378 // for unnamed bitfields here, even though we later ignore
379 // them everywhere. That's so the FieldDecl's getFieldIndex() matches.
380
381 // Reserve space for the field's descriptor and the offset.
382 BaseSize += align(sizeof(InlineDescriptor));
383
384 // Classify the field and add its metadata.
385 QualType FT = FD->getType();
386 const bool IsConst = FT.isConstQualified();
387 const bool IsMutable = FD->isMutable();
388 const bool IsVolatile = FT.isVolatileQualified();
389 const Descriptor *Desc;
390 if (OptPrimType T = Ctx.classify(FT)) {
391 Desc = createDescriptor(FD, *T, nullptr, std::nullopt, IsConst,
392 /*IsTemporary=*/false, IsMutable, IsVolatile);
393 HasPtrField = HasPtrField || (T == PT_Ptr);
394 } else if ((Desc = createDescriptor(
395 FD, FT.getTypePtr(), std::nullopt, IsConst,
396 /*IsTemporary=*/false, IsMutable, IsVolatile))) {
397 HasPtrField =
398 HasPtrField ||
399 (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) ||
400 (Desc->ElemRecord && Desc->ElemRecord->hasPtrField());
401 } else {
402 Desc = allocateDescriptor(FD);
403 }
404 Fields.emplace_back(FD, Desc, BaseSize);
405 BaseSize += align(Desc->getAllocSize());
406 }
407
408 Record *R = new (Allocator)
409 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
410 VirtSize, BaseSize, HasPtrField);
411 Records[RD] = R;
412 return R;
413}
414
417 bool IsConst, bool IsTemporary,
418 bool IsMutable, bool IsVolatile,
419 const Expr *Init) {
420 // Classes and structures.
421 if (const auto *RD = Ty->getAsRecordDecl()) {
422 if (const auto *Record = getOrCreateRecord(RD))
423 return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
424 IsMutable, IsVolatile);
425 return allocateDescriptor(D, MDSize);
426 }
427
428 // Arrays.
429 if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
431 // Array of well-known bounds.
432 if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
433 size_t NumElems = CAT->getZExtSize();
434 if (OptPrimType T = Ctx.classify(ElemTy)) {
435 // Arrays of primitives.
436 unsigned ElemSize = primSize(*T);
437 if ((Descriptor::MaxArrayElemBytes / ElemSize) < NumElems) {
438 return nullptr;
439 }
440 return allocateDescriptor(D, CAT, *T, MDSize, NumElems, IsConst,
441 IsTemporary, IsMutable, IsVolatile);
442 }
443 // Arrays of composites. In this case, the array is a list of pointers,
444 // followed by the actual elements.
445 const Descriptor *ElemDesc = createDescriptor(
446 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
447 if (!ElemDesc)
448 return nullptr;
449 unsigned ElemSize = ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
450 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
451 return nullptr;
452 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
453 IsTemporary, IsMutable);
454 }
455
456 // Array of unknown bounds - cannot be accessed and pointer arithmetic
457 // is forbidden on pointers to such objects.
460 if (OptPrimType T = Ctx.classify(ElemTy)) {
461 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
463 }
464 const Descriptor *Desc = createDescriptor(
465 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
466 if (!Desc)
467 return nullptr;
468 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
470 }
471 }
472
473 // Atomic types.
474 if (const auto *AT = Ty->getAs<AtomicType>()) {
475 const Type *InnerTy = AT->getValueType().getTypePtr();
476 return createDescriptor(D, InnerTy, MDSize, IsConst, IsTemporary,
477 IsMutable);
478 }
479
480 // Complex types - represented as arrays of elements.
481 if (const auto *CT = Ty->getAs<ComplexType>()) {
482 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
483 if (!ElemTy)
484 return nullptr;
485
486 return allocateDescriptor(D, CT, *ElemTy, MDSize, 2, IsConst, IsTemporary,
487 IsMutable, IsVolatile);
488 }
489
490 // Same with vector types.
491 if (const auto *VT = Ty->getAs<VectorType>()) {
492 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
493 if (!ElemTy)
494 return nullptr;
495
496 return allocateDescriptor(D, VT, *ElemTy, MDSize, VT->getNumElements(),
497 IsConst, IsTemporary, IsMutable, IsVolatile);
498 }
499
500 // Same with constant matrix types.
501 if (const auto *MT = Ty->getAs<ConstantMatrixType>()) {
502 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
503 if (!ElemTy)
504 return nullptr;
505
506 return allocateDescriptor(D, MT, *ElemTy, MDSize,
507 MT->getNumElementsFlattened(), IsConst,
508 IsTemporary, IsMutable, IsVolatile);
509 }
510
511 return nullptr;
512}
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:3821
QualType getElementType() const
Definition TypeBase.h:3833
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3340
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4486
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
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:3204
Represents a function declaration or definition.
Definition Decl.h:2029
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3725
A global _GUID constant.
Definition DeclCXX.h:4424
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8573
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8489
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8562
Represents a struct/union/class.
Definition Decl.h:4369
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4585
field_range fields() const
Definition Decl.h:4572
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4553
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:3862
A template parameter object.
The base class of the type hierarchy.
Definition TypeBase.h:1876
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9395
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isReferenceType() const
Definition TypeBase.h:8750
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:9372
bool isPointerOrReferenceType() const
Definition TypeBase.h:8730
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9319
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4481
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:5579
Represents a GCC generic vector type.
Definition TypeBase.h:4274
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:165
OptPrimType classify(QualType T) const
Classifies a type.
Definition Context.cpp:464
unsigned getEvalID() const
Definition Context.h:180
Bytecode function.
Definition Function.h:99
A pointer to a memory block, live or dead.
Definition Pointer.h:405
void initializeAllElements() const
Initialize all elements of a primitive array at once.
Definition Pointer.cpp:694
T & elem(unsigned I) const
Dereferences the element at index I.
Definition Pointer.h:887
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init, bool IsConstexprUnknown=false)
Creates a global and returns its index.
Definition Program.cpp:179
Function * getFunction(const FunctionDecl *F)
Returns a function.
Definition Program.cpp:295
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
unsigned getOrCreateDummy(DeclTy D, bool IsConstexprUnknown=false)
Returns or creates a dummy value for unknown declarations.
Definition Program.cpp:127
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:302
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:2400
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
const FunctionProtoType * T
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