24 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
26 NativePointers.push_back(Ptr);
32 return NativePointers[Idx];
37 const size_t BitWidth = CharWidth * Ctx.getCharBit();
58 unsigned GlobalIndex = Globals.size();
60 auto *G =
new (Allocator, Sz)
Global(Ctx.getEvalID(), Desc,
true,
62 G->block()->invokeCtor();
64 new (G->block()->rawData())
70 std::memcpy(&Ptr.
elem<
char>(0), S->
getString().data(), StringLength);
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););
85 assert(Idx < Globals.size());
86 return Pointer(Globals[Idx]->block());
90 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
94 std::optional<unsigned> Index;
96 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
104 GlobalIndices[VD] = *Index;
110 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
121 GlobalIndices[VD] = *Idx;
130 if (
auto It = DummyVariables.find(D.getOpaqueValue());
131 It != DummyVariables.end())
136 if (
const auto *E = dyn_cast<const Expr *>(D)) {
140 IsWeak = VD->isWeak();
155 Desc = allocateDescriptor(D);
162 unsigned I = Globals.size();
166 false, IsWeak,
true);
167 G->block()->invokeCtor();
168 assert(G->block()->isDummy());
170 Globals.push_back(G);
171 DummyVariables[D.getOpaqueValue()] = I;
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();
194 IsWeak, IsConstexprUnknown,
Init);
198 Global *NewGlobal = Globals[*Idx];
204 if (
auto DummyIt = DummyVariables.find(Redecl);
205 DummyIt != DummyVariables.end()) {
206 Global *Dummy = Globals[DummyIt->second];
208 Globals[DummyIt->second] = NewGlobal;
209 DummyVariables.erase(DummyIt);
215 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
217 GlobalIndices[Redecl] = *Idx;
222 Block *RedeclBlock = Globals[Iter->second]->block();
227 if (RedeclBlock != NewGlobal->block())
230 Globals[Iter->second] = NewGlobal;
244 GlobalIndices[E] = *Idx;
251 bool IsStatic,
bool IsExtern,
bool IsWeak,
252 bool IsConstexprUnknown,
263 const bool IsTemporary = D.dyn_cast<
const Expr *>();
267 IsTemporary,
false, IsVolatile);
270 IsTemporary,
false, IsVolatile);
277 unsigned I = Globals.size();
281 G->block()->invokeCtor();
287 Globals.push_back(G);
295 auto It = Funcs.find(F);
296 return It == Funcs.end() ?
nullptr : It->second.get();
311 auto [It, Inserted] = Records.try_emplace(RD);
316 unsigned BaseSize = 0;
318 unsigned VirtSize = 0;
321 auto GetBaseDesc = [
this](
const RecordDecl *BD,
325 return allocateDescriptor(BD, BR, std::nullopt,
false,
331 Record::BaseList Bases;
332 Record::VirtualBaseList VirtBases;
333 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
334 Bases.reserve(CD->getNumBases());
336 if (Spec.isVirtual())
340 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
350 Bases.emplace_back(BD, Desc, BR, BaseSize);
355 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
363 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
369 Record::FieldList Fields;
371 bool HasPtrField =
false;
373 FD = FD->getFirstDecl();
384 const bool IsMutable = FD->isMutable();
389 false, IsMutable, IsVolatile);
390 HasPtrField = HasPtrField || (T ==
PT_Ptr);
393 false, IsMutable, IsVolatile))) {
399 Desc = allocateDescriptor(FD);
401 Fields.emplace_back(FD, Desc, BaseSize);
405 Record *R =
new (Allocator)
406 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
407 VirtSize, BaseSize, HasPtrField);
414 bool IsConst,
bool IsTemporary,
415 bool IsMutable,
bool IsVolatile,
420 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
421 IsMutable, IsVolatile);
422 return allocateDescriptor(D, MDSize);
429 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
430 size_t NumElems = CAT->getZExtSize();
437 return allocateDescriptor(D, CAT, *T, MDSize, NumElems, IsConst,
438 IsTemporary, IsMutable, IsVolatile);
443 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
447 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
449 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
450 IsTemporary, IsMutable);
458 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
462 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
465 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
472 const Type *InnerTy = AT->getValueType().getTypePtr();
479 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
483 return allocateDescriptor(D, CT, *ElemTy, MDSize, 2, IsConst, IsTemporary,
484 IsMutable, IsVolatile);
489 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
493 return allocateDescriptor(D, VT, *ElemTy, MDSize, VT->getNumElements(),
494 IsConst, IsTemporary, IsMutable, IsVolatile);
499 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
503 return allocateDescriptor(D, MT, *ElemTy, MDSize,
504 MT->getNumElementsFlattened(), IsConst,
505 IsTemporary, IsMutable, IsVolatile);
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Record Record
#define INT_TYPE_SWITCH_NO_BOOL(Expr, B)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Represents a base class of a C++ class.
Complex values, per C99 6.2.5p11.
Represents a concrete matrix type with constant number of rows and columns.
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
uint32_t getCodeUnit(size_t i) const
StringRef getString() const
unsigned getCharByteWidth() const
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template parameter object.
The base class of the type hierarchy.
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAs() const
Member-template getAs<specific type>'.
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Represents a GCC generic vector type.
A memory block, either on the stack or in the heap.
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.
OptPrimType classify(QualType T) const
Classifies a type.
unsigned getEvalID() const
A pointer to a memory block, live or dead.
void initializeAllElements() const
Initialize all elements of a primitive array at once.
T & elem(unsigned I) const
Dereferences the element at index I.
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init, bool IsConstexprUnknown=false)
Creates a global and returns its index.
unsigned getOrCreateDummy(const DeclTy &D, bool IsConstexprUnknown=false)
Returns or creates a dummy value for unknown declarations.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
Pointer getPtrGlobal(unsigned Idx) const
Returns a pointer to a global.
const void * getNativePointer(unsigned Idx) const
Returns the value of a marshalled native pointer.
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.
unsigned createGlobalString(const StringLiteral *S, const Expr *Base=nullptr)
Emits a string literal among global data.
UnsignedOrNone getCurrentDecl() const
Returns the current declaration ID.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Structure/Class descriptor.
bool hasPtrField() const
If this record (or any of its bases) contains a field of type PT_Ptr.
unsigned getSize() const
Returns the size of the record.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
bool Init(InterpState &S, CodePtr OpPC)
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
OptionalUnsigned< unsigned > UnsignedOrNone
U cast(CodeGen::Address addr)
Token to denote structures of unknown size.
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
static constexpr MetadataSize GlobalMD
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
std::optional< unsigned > MetadataSize
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() const
const Record *const ElemRecord
Pointer to the record, if block contains records.
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.