21 assert(Idx < Globals.size());
23 Block *B = Globals[Idx]->block();
36 return Pointer(Globals[Idx]->block());
45 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
49 std::optional<unsigned> Index;
51 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
59 GlobalIndices[VD] = *Index;
65 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
76 GlobalIndices[VD] = *Idx;
83 bool IsConstexprUnknown) {
84 bool IsStatic, IsExtern;
85 bool IsWeak = VD->
isWeak();
86 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
88 IsExtern = Var->hasExternalStorage();
101 IsWeak, IsConstexprUnknown,
Init);
105 Global *NewGlobal = Globals[*Idx];
106 GlobalIndices[VD] = *Idx;
114 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
120 Block *RedeclBlock = Globals[Iter->second]->block();
125 if (RedeclBlock != NewGlobal->block())
128 Globals[Iter->second] = NewGlobal;
141 GlobalIndices[E] = *Idx;
148 bool IsExtern,
bool IsWeak,
149 bool IsConstexprUnknown,
160 const bool IsTemporary = D.
isExpr();
174 unsigned I = Globals.size();
179 G->block()->invokeCtor();
185 Globals.push_back(G);
193 auto It = Funcs.find(F);
194 return It == Funcs.end() ?
nullptr : It->second;
209 auto [It, Inserted] = Records.try_emplace(RD);
214 unsigned BaseSize = 0;
216 unsigned VirtSize = 0;
219 auto GetBaseDesc = [
this](
const RecordDecl *BD,
223 return allocateDescriptor(BD, BR,
false,
false,
227 bool HasPtrField =
false;
229 unsigned NumBases = 0;
230 Record::Base *Bases =
nullptr;
231 unsigned NumVBases = 0;
232 Record::Base *VBases =
nullptr;
233 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
234 NumBases = CD->getNumBases();
241 assert(I <= NumBases);
242 if (Spec.isVirtual())
246 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
256 new (&Bases[I]) Record::Base(BD, Desc, BR, BaseSize);
265 NumVBases = CD->getNumVBases();
269 assert(I <= NumVBases);
270 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
278 new (&VBases[I]) Record::Base(BD, Desc, BR, VirtSize);
283 assert(I == NumVBases);
288 Record::Field *Fields =
nullptr;
293 FD = FD->getFirstDecl();
304 const bool IsMutable = FD->isMutable();
310 false, IsMutable, IsVolatile);
311 HasPtrField = HasPtrField || (
T ==
PT_Ptr);
320 Desc = allocateDescriptor(FD);
323 new (&Fields[I]) Record::Field(FD, Desc, BaseSize,
T);
329 for (
unsigned I = 0; I != NumVBases; ++I)
330 VBases[I].Offset += BaseSize;
332 Record *R =
new (Allocator)
333 Record(RD, {Bases, NumBases}, {Fields, NumFields}, {VBases, NumVBases},
334 VirtSize, BaseSize, HasPtrField);
340 bool IsConst,
bool IsTemporary,
341 bool IsMutable,
bool IsVolatile,
346 return allocateDescriptor(D,
Record, IsConst, IsTemporary, IsMutable,
348 return allocateDescriptor(D);
355 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
356 size_t NumElems = CAT->getZExtSize();
363 return allocateDescriptor(D, CAT, *
T, NumElems, IsConst, IsTemporary,
364 IsMutable, IsVolatile);
373 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
375 return allocateDescriptor(D, Ty, ElemDesc, NumElems, IsConst, IsTemporary,
384 return allocateDescriptor(D, *
T, IsConst, IsTemporary,
391 return allocateDescriptor(D, Desc, IsTemporary,
398 const Type *InnerTy = AT->getValueType().getTypePtr();
404 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
408 return allocateDescriptor(D, CT, *ElemTy, 2, IsConst, IsTemporary,
409 IsMutable, IsVolatile);
414 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
418 return allocateDescriptor(D, VT, *ElemTy, VT->getNumElements(), IsConst,
419 IsTemporary, IsMutable, IsVolatile);
424 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
428 return allocateDescriptor(D, MT, *ElemTy, MT->getNumElementsFlattened(),
429 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.
bool isValueDependent() const
Determines whether the value of this expression depends on.
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 variable declaration or definition.
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Represents a GCC generic vector type.
A memory block, either on the stack or in the heap.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
static constexpr uint8_t GlobalMD
void movePointersTo(Block *B)
Move all pointers from this block to.
unsigned getMetadataSize() const
Returns the size of the metadata.
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.
const VarDecl * asVarDecl() const
PrimType getPrimType() const
const Record *const ElemRecord
Pointer to the record, if block contains records.
Descriptor used for global variables.
GlobalInitState InitState
Inline descriptor embedded in structures and arrays.