23 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
25 NativePointers.push_back(Ptr);
31 return NativePointers[Idx];
36 const size_t BitWidth = CharWidth * Ctx.getCharBit();
55 unsigned GlobalIndex = Globals.size();
57 auto *G =
new (Allocator, Sz)
Global(Ctx.getEvalID(), Desc,
true,
59 G->block()->invokeCtor();
61 new (G->block()->rawData())
67 std::memcpy(&Ptr.
elem<
char>(0), S->
getString().data(), StringLength);
70 for (
unsigned I = 0; I <= StringLength; ++I) {
71 uint32_t CodePoint = I == StringLength ? 0 : S->
getCodeUnit(I);
73 Ptr.
elem<
T>(I) = T::from(CodePoint, BitWidth););
82 assert(Idx < Globals.size());
83 return Pointer(Globals[Idx]->block());
87 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
91 std::optional<unsigned> Index;
93 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
101 GlobalIndices[VD] = *Index;
107 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
118 GlobalIndices[VD] = *Idx;
127 if (
auto It = DummyVariables.find(D.getOpaqueValue());
128 It != DummyVariables.end())
133 if (
const auto *E = dyn_cast<const Expr *>(D)) {
137 IsWeak = VD->isWeak();
152 Desc = allocateDescriptor(D);
157 unsigned I = Globals.size();
161 false, IsWeak,
true);
162 G->block()->invokeCtor();
163 assert(G->block()->isDummy());
165 Globals.push_back(G);
166 DummyVariables[D.getOpaqueValue()] = I;
171 bool IsStatic, IsExtern;
172 bool IsWeak = VD->
isWeak();
173 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
175 IsExtern = Var->hasExternalStorage();
192 Global *NewGlobal = Globals[*Idx];
198 if (
auto DummyIt = DummyVariables.find(Redecl);
199 DummyIt != DummyVariables.end()) {
200 Global *Dummy = Globals[DummyIt->second];
202 Globals[DummyIt->second] = NewGlobal;
203 DummyVariables.erase(DummyIt);
209 auto [Iter, Inserted] = GlobalIndices.try_emplace(Redecl);
211 GlobalIndices[Redecl] = *Idx;
216 if (
Block *RedeclBlock = Globals[Iter->second]->block();
223 if (RedeclBlock != NewGlobal->block())
224 RedeclBlock->movePointersTo(NewGlobal->block());
226 Globals[Iter->second] = NewGlobal;
240 GlobalIndices[E] = *Idx;
247 bool IsStatic,
bool IsExtern,
bool IsWeak,
252 const bool IsTemporary = D.dyn_cast<
const Expr *>();
256 IsTemporary,
false, IsVolatile);
259 IsTemporary,
false, IsVolatile);
265 unsigned I = Globals.size();
269 G->block()->invokeCtor();
275 Globals.push_back(G);
283 auto It = Funcs.find(F);
284 return It == Funcs.end() ?
nullptr : It->second.get();
299 auto [It, Inserted] = Records.try_emplace(RD);
304 unsigned BaseSize = 0;
306 unsigned VirtSize = 0;
309 auto GetBaseDesc = [
this](
const RecordDecl *BD,
313 return allocateDescriptor(BD, BR, std::nullopt,
false,
319 Record::BaseList Bases;
320 Record::VirtualBaseList VirtBases;
321 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
323 if (Spec.isVirtual())
327 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
337 Bases.push_back({BD, BaseSize, Desc, BR});
342 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
350 VirtBases.push_back({BD, VirtSize, Desc, BR});
356 Record::FieldList Fields;
358 FD = FD->getFirstDecl();
369 const bool IsMutable = FD->isMutable();
374 false, IsMutable, IsVolatile);
377 false, IsMutable, IsVolatile);
381 Fields.push_back({FD, BaseSize, Desc});
385 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
386 std::move(VirtBases), VirtSize, BaseSize);
393 bool IsConst,
bool IsTemporary,
394 bool IsMutable,
bool IsVolatile,
400 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
401 IsMutable, IsVolatile);
402 return allocateDescriptor(D, MDSize);
409 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
410 size_t NumElems = CAT->getZExtSize();
414 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
417 return allocateDescriptor(D, *
T, MDSize, NumElems, IsConst, IsTemporary,
423 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
427 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
429 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
430 IsTemporary, IsMutable);
438 return allocateDescriptor(D, *
T, MDSize, IsConst, IsTemporary,
442 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
445 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
452 const Type *InnerTy = AT->getValueType().getTypePtr();
459 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
463 return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
469 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
473 return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
474 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.
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.
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.
const void * getNativePointer(unsigned Idx)
Returns the value of a marshalled native pointer.
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.
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.
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',...
const FunctionProtoType * T
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
std::optional< unsigned > MetadataSize
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.