25template <
typename T>
static constexpr bool needsCtor() {
26 if constexpr (std::is_same_v<T, Char<true>> ||
27 std::is_same_v<T, Char<false>> ||
28 std::is_same_v<T, Integral<16, true>> ||
29 std::is_same_v<T, Integral<16, false>> ||
30 std::is_same_v<T, Integral<32, true>> ||
31 std::is_same_v<T, Integral<32, false>> ||
32 std::is_same_v<T, Integral<64, true>> ||
33 std::is_same_v<T, Integral<64, false>> ||
34 std::is_same_v<T, Integral<64, false>> ||
35 std::is_same_v<T, IntegralAP<false>> ||
36 std::is_same_v<T, IntegralAP<true>> ||
37 std::is_same_v<T, Floating> || std::is_same_v<T, Boolean>)
44static void ctorTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
53 reinterpret_cast<T *
>(Ptr)->~T();
64 new (&
reinterpret_cast<T *
>(Ptr)[I]) T();
77 reinterpret_cast<T *
>(Ptr)[I].~T();
83 bool IsMutable,
bool IsVolatile,
bool IsActive,
86 const unsigned ElemSize =
89 unsigned ElemOffset = 0;
90 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
91 auto *ElemPtr = Ptr + ElemOffset;
97 Desc->IsInitialized =
true;
99 Desc->IsActive = IsActive;
100 Desc->IsConst = IsConst || D->
IsConst;
101 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
102 Desc->InUnion = InUnion;
103 Desc->IsArrayElement =
true;
104 Desc->IsVolatile = IsVolatile;
107 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
108 Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsVolatile, IsActive,
109 Desc->InUnion || SD->isUnion(), D->
ElemDesc);
116 const unsigned ElemSize =
119 unsigned ElemOffset = 0;
122 "a composite array without an elem dtor shouldn't have a dtor itself");
123 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
124 auto *ElemPtr = Ptr + ElemOffset;
126 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
132 bool IsVolatile,
bool IsActive,
bool IsUnionField,
133 bool InUnion,
const Descriptor *D,
unsigned FieldOffset) {
135 Desc->
Offset = FieldOffset;
137 Desc->IsInitialized = D->
IsArray;
138 Desc->IsBase =
false;
139 Desc->IsActive = IsActive && !IsUnionField;
140 Desc->InUnion = InUnion;
141 Desc->IsConst = IsConst || D->
IsConst;
142 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
143 Desc->IsVolatile = IsVolatile || D->
IsVolatile;
145 Desc->IsConstInMutable = Desc->IsConst && IsMutable;
152 Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable,
153 Desc->IsVolatile, Desc->IsActive, InUnion || D->
isUnion(), D);
157 bool IsVolatile,
bool IsActive,
bool InUnion,
159 bool IsVirtualBase) {
165 Desc->
Offset = FieldOffset;
167 Desc->IsInitialized = D->
IsArray;
169 Desc->IsVirtualBase = IsVirtualBase;
170 Desc->IsActive = IsActive && !InUnion;
171 Desc->IsConst = IsConst || D->
IsConst;
172 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
173 Desc->InUnion = InUnion;
174 Desc->IsVolatile =
false;
177 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
178 InUnion,
V.Desc,
V.Offset,
false);
180 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
181 InUnion, InUnion, F.Desc, F.Offset);
185 bool IsVolatile,
bool IsActive,
bool InUnion,
188 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
192 bool IsUnionField = D->
isUnion();
193 initField(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, IsUnionField,
194 InUnion || IsUnionField, F.Desc, F.Offset);
197 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
203 unsigned FieldOffset) {
205 Fn(B, Ptr + FieldOffset, D);
209 unsigned FieldOffset) {
230 for (
const auto &B : R->bases()) {
235 for (
const auto &F : R->fields()) {
240 for (
const auto &
V : R->virtual_bases()) {
256 llvm_unreachable(
"Unhandled PrimType");
268 llvm_unreachable(
"Unhandled PrimType");
274 llvm_unreachable(
"unknown Expr");
279 llvm_unreachable(
"unknown Expr");
286 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)), Size(ElemSize),
287 MDSize(MD.value_or(0)), AllocSize(
align(Size + MDSize)),
PrimT(
Type),
291 assert(AllocSize >= Size);
292 assert(Source &&
"Missing source");
299 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)),
300 Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
305 assert(Source &&
"Missing source");
312 : Source(D), ElemSize(
primSize(
Type)), Size(UnknownSizeMark),
313 MDSize(MD.value_or(0)),
318 assert(Source &&
"Missing source");
326 : Source(D), SourceType(SourceTy),
328 Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
329 AllocSize(
std::
max<
size_t>(alignof(void *), Size) + MDSize),
333 assert(Source &&
"Missing source");
340 Size(UnknownSizeMark), MDSize(MD.value_or(0)),
344 assert(Source &&
"Missing source");
351 : Source(D), ElemSize(
std::
max<
size_t>(alignof(void *), R->getFullSize())),
352 Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
356 assert(Source &&
"Missing source");
361 : Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
364 assert(Source &&
"Missing source");
371 if (
const auto *T = dyn_cast_if_present<TypeDecl>(
asDecl()))
372 return T->getASTContext().getTypeDeclType(T);
379 std::nullopt, RD,
false);
385 if (
const auto *E =
asExpr()) {
387 return E->getType()->getPointeeType();
390 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
391 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
392 ME->getMethodDecl()->getName() ==
"allocate")
393 return E->getType()->getPointeeType();
400 llvm_unreachable(
"Invalid descriptor type");
407 T = AT->getValueType();
408 if (T->isPointerOrReferenceType())
409 T = T->getPointeeType();
411 if (
const auto *AT = T->getAsArrayTypeUnsafe()) {
415 while (T->isArrayType())
416 T = T->getAsArrayTypeUnsafe()->getElementType();
419 return AT->getElementType();
422 return CT->getElementType();
424 return CT->getElementType();
438 if (
const auto *E =
asExpr()) {
440 return MakeArrayType(E->getType()->getPointeeType());
443 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
444 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
445 ME->getMethodDecl()->getName() ==
"allocate")
446 return MakeArrayType(E->getType()->getPointeeType());
454 if (
auto *D = dyn_cast<const Decl *>(Source))
455 return D->getLocation();
456 if (
auto *E = dyn_cast<const Expr *>(Source))
457 return E->getExprLoc();
458 llvm_unreachable(
"Invalid descriptor type");
462 if (
const auto *D = dyn_cast<const Decl *>(Source))
464 if (
const auto *E = dyn_cast<const Expr *>(Source))
466 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 FIXED_SIZE_INT_TYPE_SWITCH(Expr, B)
#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.
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
Complex values, per C99 6.2.5p11.
ASTContext & getASTContext() const LLVM_READONLY
A (possibly-)qualified type.
QualType withConst() const
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.
constexpr bool isIntegerOrBoolType(PrimType T)
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',...
@ None
No keyword precedes the qualified type name.
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.
unsigned getElemDataSize() const
Returns the element data size, i.e.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
PrimType getPrimType() 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.