23 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
25 NativePointers.push_back(Ptr);
31 return NativePointers[Idx];
36 const size_t BitWidth = CharWidth * Ctx.getCharBit();
51 llvm_unreachable(
"unsupported character width");
66 unsigned GlobalIndex = Globals.size();
68 auto *G =
new (Allocator, Sz)
Global(Ctx.getEvalID(), Desc,
true,
70 G->block()->invokeCtor();
72 new (G->block()->rawData())
78 std::memcpy(&Ptr.
elem<
char>(0), S->
getString().data(), StringLength);
81 for (
unsigned I = 0; I <= StringLength; ++I) {
82 const uint32_t CodePoint = I == StringLength ? 0 : S->
getCodeUnit(I);
86 Ptr.
elem<
T>(I) = T::from(CodePoint, BitWidth);
91 Ptr.
elem<
T>(I) = T::from(CodePoint, BitWidth);
96 Ptr.
elem<
T>(I) = T::from(CodePoint, BitWidth);
100 llvm_unreachable(
"unsupported character type");
110 assert(Idx < Globals.size());
111 return Pointer(Globals[Idx]->block());
115 if (
auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
119 std::optional<unsigned> Index;
121 if (
auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
129 GlobalIndices[VD] = *Index;
135 if (
auto It = GlobalIndices.find(E); It != GlobalIndices.end())
146 GlobalIndices[VD] = *Idx;
155 if (
auto It = DummyVariables.find(D.getOpaqueValue());
156 It != DummyVariables.end())
161 if (
const auto *E = dyn_cast<const Expr *>(D)) {
165 IsWeak = VD->isWeak();
180 Desc = allocateDescriptor(D);
185 unsigned I = Globals.size();
189 false, IsWeak,
true);
190 G->block()->invokeCtor();
191 assert(G->block()->isDummy());
193 Globals.push_back(G);
194 DummyVariables[D.getOpaqueValue()] = I;
199 bool IsStatic, IsExtern;
200 bool IsWeak = VD->
isWeak();
201 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
203 IsExtern = Var->hasExternalStorage();
220 Global *NewGlobal = Globals[*Idx];
222 unsigned &PIdx = GlobalIndices[Redecl];
224 if (
Block *RedeclBlock = Globals[PIdx]->block();
226 Globals[PIdx] = NewGlobal;
229 RedeclBlock->movePointersTo(NewGlobal->block());
243 GlobalIndices[E] = *Idx;
250 bool IsStatic,
bool IsExtern,
bool IsWeak,
255 const bool IsTemporary = D.dyn_cast<
const Expr *>();
259 IsTemporary,
false, IsVolatile);
262 IsTemporary,
false, IsVolatile);
268 unsigned I = Globals.size();
272 G->block()->invokeCtor();
278 Globals.push_back(G);
286 auto It = Funcs.find(F);
287 return It == Funcs.end() ?
nullptr : It->second.get();
302 auto [It, Inserted] = Records.try_emplace(RD);
307 unsigned BaseSize = 0;
309 unsigned VirtSize = 0;
312 auto GetBaseDesc = [
this](
const RecordDecl *BD,
316 return allocateDescriptor(BD, BR, std::nullopt,
false,
322 Record::BaseList Bases;
323 Record::VirtualBaseList VirtBases;
324 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
326 if (Spec.isVirtual())
330 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
340 Bases.push_back({BD, BaseSize, Desc, BR});
345 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
353 VirtBases.push_back({BD, VirtSize, Desc, BR});
359 Record::FieldList Fields;
361 FD = FD->getFirstDecl();
372 const bool IsMutable = FD->isMutable();
377 false, IsMutable, IsVolatile);
380 false, IsMutable, IsVolatile);
384 Fields.push_back({FD, BaseSize, Desc});
388 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
389 std::move(VirtBases), VirtSize, BaseSize);
396 bool IsConst,
bool IsTemporary,
397 bool IsMutable,
bool IsVolatile,
403 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
404 IsMutable, IsVolatile);
405 return allocateDescriptor(D, MDSize);
412 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
413 size_t NumElems = CAT->getZExtSize();
417 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
420 return allocateDescriptor(D, *
T, MDSize, NumElems, IsConst, IsTemporary,
426 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
430 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
432 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
433 IsTemporary, IsMutable);
441 return allocateDescriptor(D, *
T, MDSize, IsConst, IsTemporary,
445 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
448 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
455 const Type *InnerTy = AT->getValueType().getTypePtr();
462 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
466 return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
472 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
476 return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
477 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
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.
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.
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.
PrimType
Enumeration of the primitive types of the VM.
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.
Mapping from primitive types to their representation.