21 assert(Idx < Globals.size());
22 return Pointer(Globals[Idx]->block());
26 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
30 std::optional<unsigned> Index;
32 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
40 GlobalIndices[VD] = *Index;
46 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
57 GlobalIndices[VD] = *Idx;
67 D = VD->getFirstDecl();
71 It != DummyVariables.end())
76 if (
const auto *E = D.
asExpr()) {
80 IsWeak = VD->isWeak();
97 Desc = allocateDescriptor(D);
104 unsigned I = Globals.size();
108 true,
false, IsWeak,
true);
109 G->block()->invokeCtor();
110 assert(G->block()->isDummy());
112 Globals.push_back(G);
118 bool IsConstexprUnknown) {
119 bool IsStatic, IsExtern;
120 bool IsWeak = VD->
isWeak();
121 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
123 IsExtern = Var->hasExternalStorage();
136 IsWeak, IsConstexprUnknown,
Init);
140 Global *NewGlobal = Globals[*Idx];
141 GlobalIndices[VD] = *Idx;
147 if (
auto DummyIt = DummyVariables.find(Redecl);
148 DummyIt != DummyVariables.end()) {
149 Global *Dummy = Globals[DummyIt->second];
151 Globals[DummyIt->second] = NewGlobal;
152 DummyVariables.erase(DummyIt);
158 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
164 Block *RedeclBlock = Globals[Iter->second]->block();
169 if (RedeclBlock != NewGlobal->block())
172 Globals[Iter->second] = NewGlobal;
185 GlobalIndices[E] = *Idx;
192 bool IsExtern,
bool IsWeak,
193 bool IsConstexprUnknown,
204 const bool IsTemporary = D.
isExpr();
218 unsigned I = Globals.size();
223 G->block()->invokeCtor();
229 Globals.push_back(G);
237 auto It = Funcs.find(F);
238 return It == Funcs.end() ?
nullptr : It->second;
253 auto [It, Inserted] = Records.try_emplace(RD);
258 unsigned BaseSize = 0;
260 unsigned VirtSize = 0;
263 auto GetBaseDesc = [
this](
const RecordDecl *BD,
267 return allocateDescriptor(BD, BR,
false,
false,
272 Record::BaseList Bases;
273 Record::VirtualBaseList VirtBases;
274 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
275 Bases.reserve(CD->getNumBases());
277 if (Spec.isVirtual())
281 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
291 Bases.emplace_back(BD, Desc, BR, BaseSize);
296 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
304 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
310 Record::FieldList Fields;
312 bool HasPtrField =
false;
314 FD = FD->getFirstDecl();
325 const bool IsMutable = FD->isMutable();
331 false, IsMutable, IsVolatile);
332 HasPtrField = HasPtrField || (
T ==
PT_Ptr);
341 Desc = allocateDescriptor(FD);
343 Fields.emplace_back(FD, Desc, BaseSize,
T);
347 Record *R =
new (Allocator)
348 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
349 VirtSize, BaseSize, HasPtrField);
355 bool IsConst,
bool IsTemporary,
356 bool IsMutable,
bool IsVolatile,
361 return allocateDescriptor(D,
Record, IsConst, IsTemporary, IsMutable,
363 return allocateDescriptor(D);
370 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
371 size_t NumElems = CAT->getZExtSize();
378 return allocateDescriptor(D, CAT, *
T, NumElems, IsConst, IsTemporary,
379 IsMutable, IsVolatile);
388 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
390 return allocateDescriptor(D, Ty, ElemDesc, NumElems, IsConst, IsTemporary,
399 return allocateDescriptor(D, *
T, IsConst, IsTemporary,
406 return allocateDescriptor(D, Desc, IsTemporary,
413 const Type *InnerTy = AT->getValueType().getTypePtr();
419 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
423 return allocateDescriptor(D, CT, *ElemTy, 2, IsConst, IsTemporary,
424 IsMutable, IsVolatile);
429 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
433 return allocateDescriptor(D, VT, *ElemTy, VT->getNumElements(), IsConst,
434 IsTemporary, IsMutable, IsVolatile);
439 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
443 return allocateDescriptor(D, MT, *ElemTy, MT->getNumElementsFlattened(),
444 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.
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.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
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.
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.
Pointer getPtrGlobal(unsigned Idx) const
Returns a pointer to a global.
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.