24template <
typename T>
static constexpr bool needsCtor() {
25 if constexpr (std::is_same_v<T, Integral<8, true>> ||
26 std::is_same_v<T, Integral<8, false>> ||
27 std::is_same_v<T, Integral<16, true>> ||
28 std::is_same_v<T, Integral<16, false>> ||
29 std::is_same_v<T, Integral<32, true>> ||
30 std::is_same_v<T, Integral<32, false>> ||
31 std::is_same_v<T, Integral<64, true>> ||
32 std::is_same_v<T, Integral<64, false>> ||
33 std::is_same_v<T, Boolean>)
40static void ctorTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
49 reinterpret_cast<T *
>(Ptr)->~T();
60 new (&
reinterpret_cast<T *
>(Ptr)[I]) T();
73 reinterpret_cast<T *
>(Ptr)[I].~T();
79 bool IsMutable,
bool IsVolatile,
bool IsActive,
82 const unsigned ElemSize =
85 unsigned ElemOffset = 0;
86 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
87 auto *ElemPtr = Ptr + ElemOffset;
93 Desc->IsInitialized =
true;
95 Desc->IsActive = IsActive;
96 Desc->IsConst = IsConst || D->
IsConst;
97 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
98 Desc->InUnion = InUnion;
99 Desc->IsArrayElement =
true;
100 Desc->IsVolatile = IsVolatile;
103 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
104 Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsVolatile, IsActive,
105 Desc->InUnion || SD->isUnion(), D->
ElemDesc);
112 const unsigned ElemSize =
115 unsigned ElemOffset = 0;
118 "a composite array without an elem dtor shouldn't have a dtor itself");
119 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
120 auto *ElemPtr = Ptr + ElemOffset;
122 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
128 bool IsVolatile,
bool IsActive,
bool IsUnionField,
129 bool InUnion,
const Descriptor *D,
unsigned FieldOffset) {
131 Desc->
Offset = FieldOffset;
133 Desc->IsInitialized = D->
IsArray;
134 Desc->IsBase =
false;
135 Desc->IsActive = IsActive && !IsUnionField;
136 Desc->InUnion = InUnion;
137 Desc->IsConst = IsConst || D->
IsConst;
138 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
139 Desc->IsVolatile = IsVolatile || D->
IsVolatile;
141 Desc->IsConstInMutable = Desc->IsConst && IsMutable;
144 Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable,
145 Desc->IsVolatile, Desc->IsActive, InUnion || D->
isUnion(), D);
149 bool IsVolatile,
bool IsActive,
bool InUnion,
151 bool IsVirtualBase) {
157 Desc->
Offset = FieldOffset;
159 Desc->IsInitialized = D->
IsArray;
161 Desc->IsVirtualBase = IsVirtualBase;
162 Desc->IsActive = IsActive && !InUnion;
163 Desc->IsConst = IsConst || D->
IsConst;
164 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
165 Desc->InUnion = InUnion;
166 Desc->IsVolatile =
false;
169 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
170 InUnion,
V.Desc,
V.Offset,
false);
172 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
173 InUnion, InUnion, F.Desc, F.Offset);
177 bool IsVolatile,
bool IsActive,
bool InUnion,
180 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
184 bool IsUnionField = D->
isUnion();
185 initField(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, IsUnionField,
186 InUnion || IsUnionField, F.Desc, F.Offset);
189 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
195 unsigned FieldOffset) {
197 Fn(B, Ptr + FieldOffset, D);
201 unsigned FieldOffset) {
222 for (
const auto &B : R->bases()) {
227 for (
const auto &F : R->fields()) {
232 for (
const auto &
V : R->virtual_bases()) {
254 llvm_unreachable(
"Unhandled PrimType");
272 llvm_unreachable(
"Unhandled PrimType");
277 llvm_unreachable(
"unknown Expr");
282 llvm_unreachable(
"unknown Expr");
289 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)), Size(ElemSize),
290 MDSize(MD.value_or(0)), AllocSize(
align(Size + MDSize)),
PrimT(
Type),
294 assert(AllocSize >= Size);
295 assert(Source &&
"Missing source");
302 : Source(D), ElemSize(
primSize(
Type)), Size(ElemSize * NumElems),
303 MDSize(MD.value_or(0)),
308 assert(Source &&
"Missing source");
315 : Source(D), ElemSize(
primSize(
Type)), Size(UnknownSizeMark),
316 MDSize(MD.value_or(0)),
321 assert(Source &&
"Missing source");
329 : Source(D), SourceType(SourceTy),
331 Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
332 AllocSize(
std::
max<
size_t>(alignof(void *), Size) + MDSize),
336 assert(Source &&
"Missing source");
343 Size(UnknownSizeMark), MDSize(MD.value_or(0)),
347 assert(Source &&
"Missing source");
354 : Source(D), ElemSize(
std::
max<
size_t>(alignof(void *), R->getFullSize())),
355 Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
359 assert(Source &&
"Missing source");
364 : Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
367 assert(Source &&
"Missing source");
375 if (
const auto *T = dyn_cast_if_present<TypeDecl>(
asDecl()))
376 return T->getASTContext().getTypeDeclType(T);
384 if (
const auto *E =
asExpr())
386 llvm_unreachable(
"Invalid descriptor type");
393 T = AT->getValueType();
394 if (T->isPointerOrReferenceType())
395 T = T->getPointeeType();
397 if (
const auto *AT = T->getAsArrayTypeUnsafe()) {
401 while (T->isArrayType())
402 T = T->getAsArrayTypeUnsafe()->getElementType();
405 return AT->getElementType();
408 return CT->getElementType();
410 return CT->getElementType();
424 if (
const auto *E =
asExpr()) {
426 return MakeArrayType(E->getType()->getPointeeType());
429 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
430 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
431 ME->getMethodDecl()->getName() ==
"allocate")
432 return MakeArrayType(E->getType()->getPointeeType());
440 if (
const auto *E =
asExpr()) {
442 return E->getType()->getPointeeType();
445 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
446 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
447 ME->getMethodDecl()->getName() ==
"allocate")
448 return E->getType()->getPointeeType();
456 if (
auto *D = dyn_cast<const Decl *>(Source))
457 return D->getLocation();
458 if (
auto *E = dyn_cast<const Expr *>(Source))
459 return E->getExprLoc();
460 llvm_unreachable(
"Invalid descriptor type");
464 if (
const auto *D = dyn_cast<const Decl *>(Source))
466 if (
const auto *E = dyn_cast<const Expr *>(Source))
468 llvm_unreachable(
"Invalid descriptor type");
static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D)
static void dtorTy(Block *, std::byte *Ptr, const Descriptor *)
static BlockCtorFn getCtorArrayPrim(PrimType Type)
static void destroyField(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool IsUnionField, bool InUnion, const Descriptor *D, unsigned FieldOffset)
static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D)
static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool, bool, bool, const Descriptor *)
static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D)
static void destroyBase(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
static constexpr bool needsCtor()
static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D)
static BlockCtorFn getCtorPrim(PrimType T)
static bool needsRecordDtor(const Record *R)
Whether a record needs its descriptor dtor function called.
static BlockDtorFn getDtorArrayPrim(PrimType Type)
static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool, bool, const Descriptor *D)
static BlockDtorFn getDtorPrim(PrimType T)
static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D)
static void initBase(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D, unsigned FieldOffset, bool IsVirtualBase)
Defines the clang::Expr interface and subclasses for C++ expressions.
#define TYPE_SWITCH(Expr, B)
__DEVICE__ int max(int __a, int __b)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
CanQualType getCanonicalTagType(const TagDecl *TD) const
Complex values, per C99 6.2.5p11.
ASTContext & getASTContext() const LLVM_READONLY
A (possibly-)qualified type.
Represents a struct/union/class.
Encodes a location in the source.
The base class of the type hierarchy.
Represents a GCC generic vector type.
A memory block, either on the stack or in the heap.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
llvm::iterator_range< const_virtual_iter > virtual_bases() const
llvm::iterator_range< const_base_iter > bases() const
llvm::iterator_range< const_field_iter > fields() const
Describes the statement/declaration an opcode was generated from.
void(*)(Block *Storage, std::byte *FieldPtr, const Descriptor *FieldDesc) BlockDtorFn
Invoked when a block is destroyed.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
bool NE(InterpState &S, CodePtr OpPC)
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.
void(*)(Block *Storage, std::byte *FieldPtr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *FieldDesc) BlockCtorFn
Invoked whenever a block is created.
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',...
Token to denote structures of unknown size.
Describes a memory block created by an allocation site.
const bool IsConst
Flag indicating if the block is mutable.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
const OptPrimType PrimT
The primitive type this descriptor was created for, or the primitive element type in case this is a p...
const ValueDecl * asValueDecl() const
const BlockCtorFn CtorFn
Storage management methods.
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
const Decl * asDecl() const
const Descriptor *const ElemDesc
Descriptor of the array element.
SourceInfo getLoc() const
Descriptor(const DeclTy &D, const Type *SourceTy, PrimType Type, MetadataSize MD, bool IsConst, bool IsTemporary, bool IsMutable, bool IsVolatile)
Allocates a descriptor for a primitive.
SourceLocation getLocation() const
const bool IsMutable
Flag indicating if a field is mutable.
QualType getDataType(const ASTContext &Ctx) const
std::optional< unsigned > MetadataSize
const bool IsArray
Flag indicating if the block is an array.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
QualType getDataElemType() const
bool isRecord() const
Checks if the descriptor is of a record.
const bool IsTemporary
Flag indicating if the block is a temporary.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isUnion() const
Checks if the descriptor is of a union.
const Expr * asExpr() const
bool isArray() const
Checks if the descriptor is of an array.
A pointer-sized struct we use to allocate into data storage.
void deleteInitMap()
Delete the InitMap if one exists.
Inline descriptor embedded in structures and arrays.
unsigned Offset
Offset inside the structure/array.