24 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
26 NativePointers.push_back(Ptr);
32 return NativePointers[Idx];
37 const size_t BitWidth = CharWidth * Ctx.getCharBit();
56 unsigned GlobalIndex = Globals.size();
58 auto *G =
new (Allocator, Sz)
Global(Ctx.getEvalID(), Desc,
true,
60 G->block()->invokeCtor();
62 new (G->block()->rawData())
68 std::memcpy(&Ptr.
elem<
char>(0), S->
getString().data(), StringLength);
71 for (
unsigned I = 0; I <= StringLength; ++I) {
72 uint32_t CodePoint = I == StringLength ? 0 : S->
getCodeUnit(I);
74 Ptr.
elem<T>(I) = T::from(CodePoint, BitWidth););
83 assert(Idx < Globals.size());
84 return Pointer(Globals[Idx]->block());
88 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
92 std::optional<unsigned> Index;
94 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
102 GlobalIndices[VD] = *Index;
108 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
119 GlobalIndices[VD] = *Idx;
128 if (
auto It = DummyVariables.find(D.getOpaqueValue());
129 It != DummyVariables.end())
134 if (
const auto *E = dyn_cast<const Expr *>(D)) {
138 IsWeak = VD->isWeak();
153 Desc = allocateDescriptor(D);
158 unsigned I = Globals.size();
162 false, IsWeak,
true);
163 G->block()->invokeCtor();
164 assert(G->block()->isDummy());
166 Globals.push_back(G);
167 DummyVariables[D.getOpaqueValue()] = I;
172 bool IsStatic, IsExtern;
173 bool IsWeak = VD->
isWeak();
174 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
176 IsExtern = Var->hasExternalStorage();
193 Global *NewGlobal = Globals[*Idx];
199 if (
auto DummyIt = DummyVariables.find(Redecl);
200 DummyIt != DummyVariables.end()) {
201 Global *Dummy = Globals[DummyIt->second];
203 Globals[DummyIt->second] = NewGlobal;
204 DummyVariables.erase(DummyIt);
210 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
212 GlobalIndices[Redecl] = *Idx;
217 if (
Block *RedeclBlock = Globals[Iter->second]->block();
224 if (RedeclBlock != NewGlobal->block())
225 RedeclBlock->movePointersTo(NewGlobal->block());
227 Globals[Iter->second] = NewGlobal;
241 GlobalIndices[E] = *Idx;
248 bool IsStatic,
bool IsExtern,
bool IsWeak,
253 const bool IsTemporary = D.dyn_cast<
const Expr *>();
257 IsTemporary,
false, IsVolatile);
260 IsTemporary,
false, IsVolatile);
266 unsigned I = Globals.size();
270 G->block()->invokeCtor();
276 Globals.push_back(G);
284 auto It = Funcs.find(F);
285 return It == Funcs.end() ?
nullptr : It->second.get();
300 auto [It, Inserted] = Records.try_emplace(RD);
305 unsigned BaseSize = 0;
307 unsigned VirtSize = 0;
310 auto GetBaseDesc = [
this](
const RecordDecl *BD,
314 return allocateDescriptor(BD, BR, std::nullopt,
false,
320 Record::BaseList Bases;
321 Record::VirtualBaseList VirtBases;
322 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
323 Bases.reserve(CD->getNumBases());
325 if (Spec.isVirtual())
329 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
339 Bases.emplace_back(BD, Desc, BR, BaseSize);
344 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
352 VirtBases.emplace_back(BD, Desc, BR, VirtSize);
358 Record::FieldList Fields;
360 bool HasPtrField =
false;
362 FD = FD->getFirstDecl();
373 const bool IsMutable = FD->isMutable();
378 false, IsMutable, IsVolatile);
379 HasPtrField = HasPtrField || (T ==
PT_Ptr);
382 false, IsMutable, IsVolatile))) {
388 Desc = allocateDescriptor(FD);
390 Fields.emplace_back(FD, Desc, BaseSize);
394 Record *R =
new (Allocator)
395 Record(RD, std::move(Bases), std::move(Fields), std::move(VirtBases),
396 VirtSize, BaseSize, HasPtrField);
403 bool IsConst,
bool IsTemporary,
404 bool IsMutable,
bool IsVolatile,
409 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
410 IsMutable, IsVolatile);
411 return allocateDescriptor(D, MDSize);
418 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
419 size_t NumElems = CAT->getZExtSize();
426 return allocateDescriptor(D, *T, MDSize, NumElems, IsConst, IsTemporary,
432 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
436 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
438 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
439 IsTemporary, IsMutable);
447 return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary,
451 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
454 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
461 const Type *InnerTy = AT->getValueType().getTypePtr();
468 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
472 return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
478 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
482 return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
483 IsTemporary, IsMutable);
488 OptPrimType ElemTy = Ctx.classify(MT->getElementType());
492 return allocateDescriptor(D, *ElemTy, MDSize, MT->getNumElementsFlattened(),
493 IsConst, IsTemporary, IsMutable);
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.
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.
bool isExtern() const
Checks if the block is extern.
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.
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.
unsigned getOrCreateDummy(const DeclTy &D)
Returns or creates a dummy value for unknown declarations.
const void * getNativePointer(unsigned Idx) const
Returns the value of a marshalled native pointer.
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init)
Creates a global and returns its index.
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.