23 auto It = NativePointerIndices.find(Ptr);
24 if (It != NativePointerIndices.end())
27 unsigned Idx = NativePointers.size();
28 NativePointers.push_back(Ptr);
29 NativePointerIndices[Ptr] = Idx;
34 return NativePointers[Idx];
38 const size_t CharWidth = S->getCharByteWidth();
39 const size_t BitWidth = CharWidth * Ctx.
getCharBit();
53 llvm_unreachable(
"unsupported character width");
58 allocateDescriptor(S, CharType, std::nullopt, S->getLength() + 1,
65 unsigned I = Globals.size();
67 auto *G =
new (Allocator, Sz) Global(Desc,
true,
69 G->block()->invokeCtor();
74 for (
unsigned I = 0, N = S->getLength(); I <= N; ++I) {
76 const uint32_t CodePoint = I == N ? 0 : S->getCodeUnit(I);
80 Field.deref<T>() = T::from(CodePoint, BitWidth);
85 Field.deref<T>() = T::from(CodePoint, BitWidth);
90 Field.deref<T>() = T::from(CodePoint, BitWidth);
94 llvm_unreachable(
"unsupported character type");
101 assert(Idx < Globals.size());
102 return Pointer(Globals[Idx]->block());
106 auto It = GlobalIndices.find(VD);
107 if (It != GlobalIndices.end())
111 std::optional<unsigned> Index;
112 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl()) {
113 auto It = GlobalIndices.find(
P);
114 if (It != GlobalIndices.end()) {
122 GlobalIndices[VD] = *Index;
135 GlobalIndices[VD] = *Idx;
143 if (
auto It = DummyParams.find(VD); It != DummyParams.end())
147 Descriptor *Desc = allocateDescriptor(VD, std::nullopt);
149 unsigned I = Globals.size();
153 G->block()->invokeCtor();
155 Globals.push_back(G);
164 if (
const auto *Var = dyn_cast<VarDecl>(VD)) {
166 IsExtern = !Var->getAnyInitializer();
167 }
else if (isa<UnnamedGlobalConstantDecl>(VD)) {
175 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl())
176 GlobalIndices[
P] = *Idx;
192 const bool IsTemporary = D.dyn_cast<
const Expr *>();
203 unsigned I = Globals.size();
207 G->block()->invokeCtor();
209 Globals.push_back(G);
217 auto It = Funcs.find(F);
218 return It == Funcs.end() ? nullptr : It->second.get();
228 if (
auto It = Records.find(RD); It != Records.end())
234 Records.insert({RD,
nullptr});
237 unsigned BaseSize = 0;
239 unsigned VirtSize = 0;
245 return allocateDescriptor(BD, BR, std::nullopt,
false,
253 if (
auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
255 if (Spec.isVirtual())
262 Bases.push_back({BD, BaseSize, Desc, BR});
275 VirtBases.push_back({BD, VirtSize, Desc, BR});
292 const bool IsMutable = FD->isMutable();
294 if (std::optional<PrimType> T = Ctx.
classify(FT)) {
303 Fields.push_back({FD, BaseSize, Desc});
307 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
308 std::move(VirtBases), VirtSize, BaseSize);
315 bool IsConst,
bool IsTemporary,
320 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
328 if (
auto CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
329 size_t NumElems = CAT->getSize().getZExtValue();
330 if (std::optional<PrimType> T = Ctx.
classify(ElemTy)) {
333 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
336 return allocateDescriptor(D, *T, MDSize, NumElems, IsConst, IsTemporary,
342 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
347 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
349 return allocateDescriptor(D, ElemDesc, MDSize, NumElems, IsConst,
350 IsTemporary, IsMutable);
356 if (isa<IncompleteArrayType>(
ArrayType)) {
357 if (std::optional<PrimType> T = Ctx.
classify(ElemTy)) {
358 return allocateDescriptor(D, *T, IsTemporary,
362 IsConst, IsTemporary);
365 return allocateDescriptor(D, Desc, IsTemporary,
373 const Type *InnerTy = AT->getValueType().getTypePtr();
381 return allocateDescriptor(D, ElemTy, MDSize, 2, IsConst, IsTemporary,
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
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.
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.
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.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StringLiteral - This represents a string literal expression, e.g.
The base class of the type hierarchy.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
const T * getAs() const
Member-template getAs<specific type>'.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
unsigned getCharBit() const
Returns CHAR_BIT.
static bool shouldBeGloballyIndexed(const ValueDecl *VD)
Returns whether we should create a global variable for the given ValueDecl.
std::optional< PrimType > classify(QualType T) const
Classifies an expression.
A pointer to a memory block, live or dead.
Pointer narrow() const
Restricts the scope of an array element pointer.
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside an array.
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.
const void * getNativePointer(unsigned Idx)
Returns the value of a marshalled native pointer.
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, Descriptor::MetadataSize MDSize=std::nullopt, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
unsigned createGlobalString(const StringLiteral *S)
Emits a string literal among global data.
std::optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
Pointer getPtrGlobal(unsigned Idx)
Returns a pointer to a global.
std::optional< unsigned > getOrCreateDummy(const ValueDecl *VD)
Returns or creates a dummy value for unknown declarations.
std::optional< unsigned > createGlobal(const ValueDecl *VD, const Expr *E)
Creates a global and returns its index.
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
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.
std::optional< unsigned > MetadataSize
Inline descriptor embedded in structures and arrays.
Mapping from primitive types to their representation.