23 NativePointerIndices.try_emplace(Ptr, NativePointers.size());
25 NativePointers.push_back(Ptr);
31 return NativePointers[Idx];
35 const size_t CharWidth = S->getCharByteWidth();
36 const size_t BitWidth = CharWidth * Ctx.
getCharBit();
37 unsigned StringLength = S->getLength();
51 llvm_unreachable(
"unsupported character width");
66 unsigned GlobalIndex = Globals.size();
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)) {
164 const auto *VD = cast<ValueDecl>(cast<const Decl *>(
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;
201 bool IsWeak = VD->
isWeak();
202 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
204 IsExtern = Var->hasExternalStorage();
216 std::optional<unsigned> Idx =
221 Global *NewGlobal = Globals[*Idx];
223 unsigned &PIdx = GlobalIndices[Redecl];
225 if (
Block *RedeclBlock = Globals[PIdx]->block();
226 RedeclBlock->isExtern()) {
227 Globals[PIdx] = NewGlobal;
230 for (
Pointer *Ptr = RedeclBlock->Pointers; Ptr; Ptr = Ptr->
BS.
Next) {
231 RedeclBlock->removePointer(Ptr);
232 Ptr->BS.Pointee = NewGlobal->block();
233 NewGlobal->block()->addPointer(Ptr);
248 GlobalIndices[
E] = *Idx;
260 const bool IsTemporary =
D.dyn_cast<
const Expr *>();
264 IsTemporary,
false, IsVolatile);
267 IsTemporary,
false, IsVolatile);
273 unsigned I = Globals.size();
277 G->block()->invokeCtor();
283 Globals.push_back(G);
291 auto It = Funcs.find(F);
292 return It == Funcs.end() ? nullptr : It->second.get();
307 auto [It, Inserted] =
Records.try_emplace(RD);
312 unsigned BaseSize = 0;
314 unsigned VirtSize = 0;
317 auto GetBaseDesc = [
this](
const RecordDecl *BD,
321 return allocateDescriptor(BD, BR, std::nullopt,
false,
327 Record::BaseList Bases;
328 Record::VirtualBaseList VirtBases;
329 if (
const auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
331 if (Spec.isVirtual())
335 const auto *BD = Spec.getType()->getAsCXXRecordDecl();
345 Bases.push_back({BD, BaseSize, Desc, BR});
350 const auto *BD = Spec.getType()->castAsCXXRecordDecl();
358 VirtBases.push_back({BD, VirtSize, Desc, BR});
364 Record::FieldList Fields;
366 FD = FD->getFirstDecl();
377 const bool IsMutable = FD->isMutable();
382 false, IsMutable, IsVolatile);
385 false, IsMutable, IsVolatile);
389 Fields.push_back({FD, BaseSize, Desc});
393 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
394 std::move(VirtBases), VirtSize, BaseSize);
401 bool IsConst,
bool IsTemporary,
402 bool IsMutable,
bool IsVolatile,
408 return allocateDescriptor(
D,
Record, MDSize, IsConst, IsTemporary,
409 IsMutable, IsVolatile);
410 return allocateDescriptor(
D, MDSize);
417 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
418 size_t NumElems = CAT->getZExtSize();
422 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
425 return allocateDescriptor(
D, *
T, MDSize, NumElems, IsConst, IsTemporary,
431 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
435 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
437 return allocateDescriptor(
D, Ty, ElemDesc, MDSize, NumElems, IsConst,
438 IsTemporary, IsMutable);
443 if (isa<IncompleteArrayType>(
ArrayType) ||
446 return allocateDescriptor(
D, *
T, MDSize, IsConst, IsTemporary,
450 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
453 return allocateDescriptor(
D, Desc, MDSize, IsTemporary,
460 const Type *InnerTy = AT->getValueType().getTypePtr();
471 return allocateDescriptor(
D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
481 return allocateDescriptor(
D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
482 IsTemporary, IsMutable);
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Records Records
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.
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.
unsigned getCharBit() const
Returns CHAR_BIT.
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.
std::optional< unsigned > getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
std::optional< unsigned > createGlobal(const ValueDecl *VD, const Expr *Init)
Creates a global and returns its index.
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.
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.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
PrimType
Enumeration of the primitive types of the VM.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
const FunctionProtoType * T
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.
GlobalInitState InitState
Inline descriptor embedded in structures and arrays.
Mapping from primitive types to their representation.