22 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
24 NativePointers.push_back(Ptr);
30 return NativePointers[Idx];
34 assert(Idx < Globals.size());
35 return Pointer(Globals[Idx]->block());
39 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
43 std::optional<unsigned> Index;
45 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
53 GlobalIndices[VD] = *Index;
59 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
70 GlobalIndices[VD] = *Idx;
80 D = VD->getFirstDecl();
84 It != DummyVariables.end())
89 if (
const auto *E = D.
asExpr()) {
93 IsWeak = VD->isWeak();
108 Desc = allocateDescriptor(D);
115 unsigned I = Globals.size();
119 true,
false, IsWeak,
true);
120 G->block()->invokeCtor();
121 assert(G->block()->isDummy());
123 Globals.push_back(G);
129 bool IsConstexprUnknown) {
130 bool IsStatic, IsExtern;
131 bool IsWeak = VD->
isWeak();
132 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
134 IsExtern = Var->hasExternalStorage();
147 IsWeak, IsConstexprUnknown,
Init);
151 Global *NewGlobal = Globals[*Idx];
152 GlobalIndices[VD] = *Idx;
158 if (
auto DummyIt = DummyVariables.find(Redecl);
159 DummyIt != DummyVariables.end()) {
160 Global *Dummy = Globals[DummyIt->second];
162 Globals[DummyIt->second] = NewGlobal;
163 DummyVariables.erase(DummyIt);
169 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
175 Block *RedeclBlock = Globals[Iter->second]->block();
180 if (RedeclBlock != NewGlobal->block())
183 Globals[Iter->second] = NewGlobal;
196 GlobalIndices[E] = *Idx;
203 bool IsExtern,
bool IsWeak,
204 bool IsConstexprUnknown,
215 const bool IsTemporary = D.
isExpr();
229 unsigned I = Globals.size();
234 G->block()->invokeCtor();
240 Globals.push_back(G);
248 auto It = Funcs.find(F);
249 return It == Funcs.end() ?
nullptr : It->second.get();
264 auto [It, Inserted] = Records.try_emplace(RD);
269 unsigned BaseSize = 0;
271 unsigned VirtSize = 0;
274 auto GetBaseDesc = [
this](
const RecordDecl *BD,
278 return allocateDescriptor(BD, BR,
false,
false,
283 Record::BaseList Bases;
284 Record::VirtualBaseList VirtBases;
285 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
286 Bases.reserve(CD->getNumBases());
288 if (Spec.isVirtual())
292 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
302 Bases.emplace_back(BD, Desc, BR, BaseSize);
307 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
315 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
321 Record::FieldList Fields;
323 bool HasPtrField =
false;
325 FD = FD->getFirstDecl();
336 const bool IsMutable = FD->isMutable();
341 false, IsMutable, IsVolatile);
342 HasPtrField = HasPtrField || (
T ==
PT_Ptr);
351 Desc = allocateDescriptor(FD);
353 Fields.emplace_back(FD, Desc, BaseSize);
357 Record *R =
new (Allocator)
358 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
359 VirtSize, BaseSize, HasPtrField);
365 bool IsConst,
bool IsTemporary,
366 bool IsMutable,
bool IsVolatile,
371 return allocateDescriptor(D,
Record, IsConst, IsTemporary, IsMutable,
373 return allocateDescriptor(D);
380 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
381 size_t NumElems = CAT->getZExtSize();
388 return allocateDescriptor(D, CAT, *
T, NumElems, IsConst, IsTemporary,
389 IsMutable, IsVolatile);
398 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
400 return allocateDescriptor(D, Ty, ElemDesc, NumElems, IsConst, IsTemporary,
409 return allocateDescriptor(D, *
T, IsConst, IsTemporary,
416 return allocateDescriptor(D, Desc, IsTemporary,
423 const Type *InnerTy = AT->getValueType().getTypePtr();
429 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
433 return allocateDescriptor(D, CT, *ElemTy, 2, IsConst, IsTemporary,
434 IsMutable, IsVolatile);
439 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
443 return allocateDescriptor(D, VT, *ElemTy, VT->getNumElements(), IsConst,
444 IsTemporary, IsMutable, IsVolatile);
449 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
453 return allocateDescriptor(D, MT, *ElemTy, MT->getNumElementsFlattened(),
454 IsConst, 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
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,...
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.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template parameter object.
The base class of the type hierarchy.
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.
static constexpr uint8_t GlobalMD
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.
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init, bool IsConstexprUnknown=false)
Creates a global and returns its index.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
Descriptor * createDescriptor(DeclOrExpr D, PrimType T, const Type *SourceTy=nullptr, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false, bool IsVolatile=false)
Creates a descriptor for a primitive type.
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
unsigned getOrCreateDummy(DeclOrExpr D, bool IsConstexprUnknown=false)
Returns or creates a dummy value for unknown declarations.
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.
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.
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.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
const ValueDecl * asValueDecl() const
const VarDecl * asVarDecl() const
const Expr * asExpr() const
const void * getOpaqueValue() const
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 unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
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.