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 for (
Pointer *Ptr = RedeclBlock->Pointers; Ptr; Ptr = Ptr->
BS.
Next) {
230 RedeclBlock->removePointer(Ptr);
231 Ptr->BS.Pointee = NewGlobal->block();
232 NewGlobal->block()->addPointer(Ptr);
247 GlobalIndices[E] = *Idx;
254 bool IsStatic,
bool IsExtern,
bool IsWeak,
259 const bool IsTemporary = D.dyn_cast<
const Expr *>();
263 IsTemporary,
false, IsVolatile);
266 IsTemporary,
false, IsVolatile);
272 unsigned I = Globals.size();
276 G->block()->invokeCtor();
282 Globals.push_back(G);
290 auto It = Funcs.find(F);
291 return It == Funcs.end() ?
nullptr : It->second.get();
306 auto [It, Inserted] = Records.try_emplace(RD);
311 unsigned BaseSize = 0;
313 unsigned VirtSize = 0;
316 auto GetBaseDesc = [
this](
const RecordDecl *BD,
320 return allocateDescriptor(BD, BR, std::nullopt,
false,
326 Record::BaseList Bases;
327 Record::VirtualBaseList VirtBases;
328 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
330 if (Spec.isVirtual())
334 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
344 Bases.push_back({BD, BaseSize, Desc, BR});
349 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
357 VirtBases.push_back({BD, VirtSize, Desc, BR});
363 Record::FieldList Fields;
365 FD = FD->getFirstDecl();
376 const bool IsMutable = FD->isMutable();
381 false, IsMutable, IsVolatile);
384 false, IsMutable, IsVolatile);
388 Fields.push_back({FD, BaseSize, Desc});
392 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
393 std::move(VirtBases), VirtSize, BaseSize);
400 bool IsConst,
bool IsTemporary,
401 bool IsMutable,
bool IsVolatile,
407 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
408 IsMutable, IsVolatile);
409 return allocateDescriptor(D, MDSize);
416 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
417 size_t NumElems = CAT->getZExtSize();
421 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
424 return allocateDescriptor(D, *
T, MDSize, NumElems, IsConst, IsTemporary,
430 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
434 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
436 return allocateDescriptor(D, Ty, ElemDesc, MDSize, NumElems, IsConst,
437 IsTemporary, IsMutable);
445 return allocateDescriptor(D, *
T, MDSize, IsConst, IsTemporary,
449 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
452 return allocateDescriptor(D, Desc, MDSize, IsTemporary,
459 const Type *InnerTy = AT->getValueType().getTypePtr();
466 OptPrimType ElemTy = Ctx.classify(CT->getElementType());
470 return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
476 OptPrimType ElemTy = Ctx.classify(VT->getElementType());
480 return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
481 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)
Pointer * Next
Next link in the pointer chain.
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.