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 // Create a descriptor for the global.
255 Descriptor *Desc;
256 const bool IsConst = Ty.isConstQualified();
257 const bool IsTemporary = D.dyn_cast<const Expr *>();
258 const bool IsVolatile = Ty.isVolatileQualified();
259 if (OptPrimType T = Ctx.classify(Ty))
260 Desc = createDescriptor(D, *T, nullptr, Descriptor::GlobalMD, IsConst,
261 IsTemporary, /*IsMutable=*/false, IsVolatile);
262 else
263 Desc = createDescriptor(D, Ty.getTypePtr(), Descriptor::GlobalMD, IsConst,
264 IsTemporary, /*IsMutable=*/false, IsVolatile);
265
266 if (!Desc)
267 return std::nullopt;
268 Desc->IsConstexprUnknown = IsConstexprUnknown;
269
270 // Allocate a block for storage.
271 unsigned I = Globals.size();
272
273 auto *G = new (Allocator, Desc->getAllocSize()) Global(
274 Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
275 G->block()->invokeCtor();
276
277 // Initialize GlobalInlineDescriptor fields.
278 auto *GD = new (G->block()->rawData()) GlobalInlineDescriptor();
279 if (!Init)
280 GD->InitState = GlobalInitState::NoInitializer;
281 Globals.push_back(G);
282
283 return I;
284}
285
287 F = F->getCanonicalDecl();
288 assert(F);
289 auto It = Funcs.find(F);
290 return It == Funcs.end() ? nullptr : It->second.get();
291}
292
294 // Use the actual definition as a key.
295 RD = RD->getDefinition();
296 if (!RD)
297 return nullptr;
298
299 if (!RD->isCompleteDefinition())
300 return nullptr;
301
302 // Return an existing record if available. Otherwise, we insert nullptr now
303 // and replace that later, so recursive calls to this function with the same
304 // RecordDecl don't run into infinite recursion.
305 auto [It, Inserted] = Records.try_emplace(RD);
306 if (!Inserted)
307 return It->second;
308
309 // Number of bytes required by fields and base classes.
310 unsigned BaseSize = 0;
311 // Number of bytes required by virtual base.
312 unsigned VirtSize = 0;
313
314 // Helper to get a base descriptor.
315 auto GetBaseDesc = [this](const RecordDecl *BD,
316 const Record *BR) -> const Descriptor * {
317 if (!BR)
318 return nullptr;
319 return allocateDescriptor(BD, BR, std::nullopt, /*IsConst=*/false,
320 /*IsTemporary=*/false,
321 /*IsMutable=*/false, /*IsVolatile=*/false);
322 };
323
324 // Reserve space for base classes.
325 Record::BaseList Bases;
326 Record::VirtualBaseList VirtBases;
327 if (const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
328 Bases.reserve(CD->getNumBases());
329 for (const CXXBaseSpecifier &Spec : CD->bases()) {
330 if (Spec.isVirtual())
331 continue;
332
333 // In error cases, the base might not be a RecordType.
334 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
335 if (!BD)
336 return nullptr;
337 const Record *BR = getOrCreateRecord(BD);
338
339 const Descriptor *Desc = GetBaseDesc(BD, BR);
340 if (!Desc)
341 return nullptr;
342
343 BaseSize += align(sizeof(InlineDescriptor));
344 Bases.emplace_back(BD, Desc, BR, BaseSize);
345 BaseSize += align(BR->getSize());
346 }
347
348 for (const CXXBaseSpecifier &Spec : CD->vbases()) {
349 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
350 const Record *BR = getOrCreateRecord(BD);
351
352 const Descriptor *Desc = GetBaseDesc(BD, BR);
353 if (!Desc)
354 return nullptr;
355
356 VirtSize += align(sizeof(InlineDescriptor));
357 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
358 VirtSize += align(BR->getSize());
359 }
360 }
361
362 // Reserve space for fields.
363 Record::FieldList Fields;
364 Fields.reserve(RD->getNumFields());
365 bool HasPtrField = false;
366 for (const FieldDecl *FD : RD->fields()) {
367 FD = FD->getFirstDecl();
368 // Note that we DO create fields and descriptors
369 // for unnamed bitfields here, even though we later ignore
370 // them everywhere. That's so the FieldDecl's getFieldIndex() matches.
371
372 // Reserve space for the field's descriptor and the offset.
373 BaseSize += align(sizeof(InlineDescriptor));
374
375 // Classify the field and add its metadata.
376 QualType FT = FD->getType();
377 const bool IsConst = FT.isConstQualified();
378 const bool IsMutable = FD->isMutable();
379 const bool IsVolatile = FT.isVolatileQualified();
380 const Descriptor *Desc;
381 if (OptPrimType T = Ctx.classify(FT)) {
382 Desc = createDescriptor(FD, *T, nullptr, std::nullopt, IsConst,
383 /*IsTemporary=*/false, IsMutable, IsVolatile);
384 HasPtrField = HasPtrField || (T == PT_Ptr);
385 } else if ((Desc = createDescriptor(
386 FD, FT.getTypePtr(), std::nullopt, IsConst,
387 /*IsTemporary=*/false, IsMutable, IsVolatile))) {
388 HasPtrField =
389 HasPtrField ||
390 (Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) ||
391 (Desc->ElemRecord && Desc->ElemRecord->hasPtrField());
392 } else {
393 Desc = allocateDescriptor(FD);
394 }
395 Fields.emplace_back(FD, Desc, BaseSize);
396 BaseSize += align(Desc->getAllocSize());
397 }
398
399 Record *R = new (Allocator)
400 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
401 VirtSize, BaseSize, HasPtrField);
402 Records[RD] = R;
403 return R;
404}
405
408 bool IsConst, bool IsTemporary,
409 bool IsMutable, bool IsVolatile,
410 const Expr *Init) {
411 // Classes and structures.
412 if (const auto *RD = Ty->getAsRecordDecl()) {
413 if (const auto *Record = getOrCreateRecord(RD))
414 return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
415 IsMutable, IsVolatile);
416 return allocateDescriptor(D, MDSize);
417 }
418
419 // Arrays.
420 if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
422 // Array of well-known bounds.
423 if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
424 size_t NumElems = CAT->getZExtSize();
425 if (OptPrimType T = Ctx.classify(ElemTy)) {
426 // Arrays of primitives.
427 unsigned ElemSize = primSize(*T);
428 if ((Descriptor::MaxArrayElemBytes / ElemSize) < NumElems) {
429 return nullptr;
430 }
431 return allocateDescriptor(D, CAT, *T, MDSize, NumElems, IsConst,
432 IsTemporary, IsMutable, IsVolatile);
433 }
434 // Arrays of composites. In this case, the array is a list of pointers,
435 // followed by the actual elements.
436 const Descriptor *ElemDesc = createDescriptor(
437 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
438 if (!ElemDesc)
439 return nullptr;
440 unsigned ElemSize = ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
441 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
442 return nullptr;
443 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
444 IsTemporary, IsMutable);
445 }
446
447 // Array of unknown bounds - cannot be accessed and pointer arithmetic
448 // is forbidden on pointers to such objects.
451 if (OptPrimType T = Ctx.classify(ElemTy)) {
452 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
454 }
455 const Descriptor *Desc = createDescriptor(
456 D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
457 if (!Desc)
458 return nullptr;
459 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
461 }
462 }
463
464 // Atomic types.
465 if (const auto *AT = Ty->getAs<AtomicType>()) {
466 const Type *InnerTy = AT->getValueType().getTypePtr();
467 return createDescriptor(D, InnerTy, MDSize, IsConst, IsTemporary,
468 IsMutable);
469 }
470
471 // Complex types - represented as arrays of elements.
472 if (const auto *CT = Ty->getAs<ComplexType>()) {
473 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
474 if (!ElemTy)
475 return nullptr;
476
477 return allocateDescriptor(D, CT, *ElemTy, MDSize, 2, IsConst, IsTemporary,
478 IsMutable, IsVolatile);
479 }
480
481 // Same with vector types.
482 if (const auto *VT = Ty->getAs<VectorType>()) {
483 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
484 if (!ElemTy)
485 return nullptr;
486
487 return allocateDescriptor(D, VT, *ElemTy, MDSize, VT->getNumElements(),
488 IsConst, IsTemporary, IsMutable, IsVolatile);
489 }
490
491 // Same with constant matrix types.
492 if (const auto *MT = Ty->getAs<ConstantMatrixType>()) {
493 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
494 if (!ElemTy)
495 return nullptr;
496
497 return allocateDescriptor(D, MT, *ElemTy, MDSize,
498 MT->getNumElementsFlattened(), IsConst,
499 IsTemporary, IsMutable, IsVolatile);
500 }
501
502 return nullptr;
503}
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:3784
QualType getElementType() const
Definition TypeBase.h:3796
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3337
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4449
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:3166
Represents a function declaration or definition.
Definition Decl.h:2018
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3722
A global _GUID constant.
Definition DeclCXX.h:4403
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8529
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:8445
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8518
Represents a struct/union/class.
Definition Decl.h:4331
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4547
field_range fields() const
Definition Decl.h:4534
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4515
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:3824
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:9351
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:9328
bool isPointerOrReferenceType() const
Definition TypeBase.h:8686
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9275
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4460
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:5602
Represents a GCC generic vector type.
Definition TypeBase.h:4237
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:154
OptPrimType classify(QualType T) const
Classifies a type.
Definition Context.cpp:424
unsigned getEvalID() const
Definition Context.h:169
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:595
T & elem(unsigned I) const
Dereferences the element at index I.
Definition Pointer.h:712
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:286
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:293
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:2329
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