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;
64 bool IsConstexprUnknown) {
65 bool IsStatic, IsExtern;
66 bool IsWeak = VD->
isWeak();
67 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
69 IsExtern = Var->hasExternalStorage();
82 IsWeak, IsConstexprUnknown,
Init);
86 Global *NewGlobal = Globals[*Idx];
87 GlobalIndices[VD] = *Idx;
95 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
101 Block *RedeclBlock = Globals[Iter->second]->block();
106 if (RedeclBlock != NewGlobal->block())
109 Globals[Iter->second] = NewGlobal;
122 GlobalIndices[E] = *Idx;
129 bool IsExtern,
bool IsWeak,
130 bool IsConstexprUnknown,
141 const bool IsTemporary = D.
isExpr();
155 unsigned I = Globals.size();
160 G->block()->invokeCtor();
166 Globals.push_back(G);
174 auto It = Funcs.find(F);
175 return It == Funcs.end() ?
nullptr : It->second;
190 auto [It, Inserted] = Records.try_emplace(RD);
195 unsigned BaseSize = 0;
197 unsigned VirtSize = 0;
200 auto GetBaseDesc = [
this](
const RecordDecl *BD,
204 return allocateDescriptor(BD, BR,
false,
false,
208 bool HasPtrField =
false;
210 unsigned NumBases = 0;
211 Record::Base *Bases =
nullptr;
212 unsigned NumVBases = 0;
213 Record::Base *VBases =
nullptr;
214 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
215 NumBases = CD->getNumBases();
222 assert(I <= NumBases);
223 if (Spec.isVirtual())
227 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
237 new (&Bases[I]) Record::Base(BD, Desc, BR, BaseSize);
246 NumVBases = CD->getNumVBases();
250 assert(I <= NumVBases);
251 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
259 new (&VBases[I]) Record::Base(BD, Desc, BR, VirtSize);
264 assert(I == NumVBases);
269 Record::Field *Fields =
nullptr;
274 FD = FD->getFirstDecl();
285 const bool IsMutable = FD->isMutable();
291 false, IsMutable, IsVolatile);
292 HasPtrField = HasPtrField || (
T ==
PT_Ptr);
301 Desc = allocateDescriptor(FD);
304 new (&Fields[I]) Record::Field(FD, Desc, BaseSize,
T);
310 for (
unsigned I = 0; I != NumVBases; ++I)
311 VBases[I].Offset += BaseSize;
313 Record *R =
new (Allocator)
314 Record(RD, {Bases, NumBases}, {Fields, NumFields}, {VBases, NumVBases},
315 VirtSize, BaseSize, HasPtrField);
321 bool IsConst,
bool IsTemporary,
322 bool IsMutable,
bool IsVolatile,
327 return allocateDescriptor(D,
Record, IsConst, IsTemporary, IsMutable,
329 return allocateDescriptor(D);
336 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
337 size_t NumElems = CAT->getZExtSize();
344 return allocateDescriptor(D, CAT, *
T, NumElems, IsConst, IsTemporary,
345 IsMutable, IsVolatile);
354 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
356 return allocateDescriptor(D, Ty, ElemDesc, NumElems, IsConst, IsTemporary,
365 return allocateDescriptor(D, *
T, IsConst, IsTemporary,
372 return allocateDescriptor(D, Desc, IsTemporary,
379 const Type *InnerTy = AT->getValueType().getTypePtr();
385 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
389 return allocateDescriptor(D, CT, *ElemTy, 2, IsConst, IsTemporary,
390 IsMutable, IsVolatile);
395 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
399 return allocateDescriptor(D, VT, *ElemTy, VT->getNumElements(), IsConst,
400 IsTemporary, IsMutable, IsVolatile);
405 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
409 return allocateDescriptor(D, MT, *ElemTy, MT->getNumElementsFlattened(),
410 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.
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.
void * Allocate(size_t Size, unsigned Align=8) const
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.
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
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.