clang: lib/AST/ByteCode/Descriptor.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_CLANG_AST_INTERP_DESCRIPTOR_H

14#define LLVM_CLANG_AST_INTERP_DESCRIPTOR_H

15

19

28

29using DeclTy = llvm::PointerUnion<const Decl *, const Expr *>;

30using InitMapPtr = std::optional<std::pair<bool, std::shared_ptr>>;

31

32

33

34

36 bool IsMutable, bool IsVolatile, bool IsActive,

37 bool InUnion, const Descriptor *FieldDesc);

38

39

40

43

49

50

55

60

61

62

63

64

65

66

68

70

71

72

73 LLVM_PREFERRED_TYPE(bool)

75

76

77

78

79 LLVM_PREFERRED_TYPE(bool)

81

82 LLVM_PREFERRED_TYPE(bool)

84

85 LLVM_PREFERRED_TYPE(bool)

87

88 LLVM_PREFERRED_TYPE(bool)

90

91 LLVM_PREFERRED_TYPE(bool)

93

94 LLVM_PREFERRED_TYPE(bool)

96

97

98 LLVM_PREFERRED_TYPE(bool)

100

101 LLVM_PREFERRED_TYPE(bool)

103 LLVM_PREFERRED_TYPE(bool)

105

107

109

115

116 void dump() const { dump(llvm::errs()); }

117 void dump(llvm::raw_ostream &OS) const;

118};

119static_assert(sizeof(GlobalInlineDescriptor) != sizeof(InlineDescriptor), "");

120

121

123private:

124

126 const Type *SourceType = nullptr;

127

128 const unsigned ElemSize;

129

130 const unsigned Size;

131

132 const unsigned MDSize;

133

134 const unsigned AllocSize;

135

136

137 static constexpr unsigned UnknownSizeMark = (unsigned)-1;

138

139public:

140

142

146

147

149 std::numeric_limits<decltype(AllocSize)>::max() - sizeof(InitMapPtr) -

151

152

154

156

157

158

160

162

164

167

170

171

174

175

179

180

183

184

187

188

192

193

196

197

200

201

203

209

210 const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }

211 const Expr *asExpr() const { return dyn_cast<const Expr *>(Source); }

213

215 return dyn_cast_if_present(asDecl());

216 }

217

219 return dyn_cast_if_present(asDecl());

220 }

221

223 return dyn_cast_if_present(asDecl());

224 }

225

227 return dyn_cast_if_present(asDecl());

228 }

229

230

235

240

241

243

245

247

248

252

253

255

257

259

261

262

264

265

267

269

271

272

274

275 void dump() const;

276 void dump(llvm::raw_ostream &OS) const;

277 void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const;

278};

279

280

282private:

283

284 using T = uint64_t;

285

286 static constexpr uint64_t PER_FIELD = sizeof(T) * CHAR_BIT;

287

288public:

289

290 explicit InitMap(unsigned N);

291

292private:

294

295

296 T *data() { return Data.get(); }

297 const T *data() const { return Data.get(); }

298

299

300 bool initializeElement(unsigned I);

301

302

303 bool isElementInitialized(unsigned I) const;

304

305 static constexpr size_t numFields(unsigned N) {

306 return (N + PER_FIELD - 1) / PER_FIELD;

307 }

308

309 unsigned UninitFields;

310 std::unique_ptr<T[]> Data;

311};

312

313}

314}

315

316#endif

__DEVICE__ int max(int __a, int __b)

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Decl - This represents one declaration (or definition), e.g.

This represents one expression.

Represents a member of a struct/union/class.

A (possibly-)qualified type.

Represents a struct/union/class.

Encodes a location in the source.

The base class of the type hierarchy.

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

Represents a variable declaration or definition.

A memory block, either on the stack or in the heap.

Structure/Class descriptor.

Describes the statement/declaration an opcode was generated from.

Lifetime

Definition Descriptor.h:56

@ Ended

Definition Descriptor.h:58

@ Started

Definition Descriptor.h:57

void(*)(Block *Storage, std::byte *FieldPtr, const Descriptor *FieldDesc) BlockDtorFn

Invoked when a block is destroyed.

Definition Descriptor.h:41

llvm::PointerUnion< const Decl *, const Expr * > DeclTy

Definition Descriptor.h:29

GlobalInitState

Definition Descriptor.h:44

@ NoInitializer

Definition Descriptor.h:46

@ Initialized

Definition Descriptor.h:45

@ InitializerFailed

Definition Descriptor.h:47

constexpr size_t align(size_t Size)

Aligns a size to the pointer alignment.

PrimType

Enumeration of the primitive types of the VM.

std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr

Definition Descriptor.h:30

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.

Definition Descriptor.h:35

The JSON file list parser is used to communicate input to InstallAPI.

raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)

const FunctionProtoType * T

Token to denote structures of unknown size.

Definition Descriptor.h:141

Describes a memory block created by an allocation site.

Definition Descriptor.h:122

const bool IsConst

Flag indicating if the block is mutable.

Definition Descriptor.h:161

const bool IsVolatile

Definition Descriptor.h:166

unsigned getAllocSize() const

Returns the allocated size, including metadata.

Definition Descriptor.h:242

unsigned getNumElems() const

Returns the number of elements stored in the block.

Definition Descriptor.h:249

unsigned getSize() const

Returns the size of the object without metadata.

Definition Descriptor.h:231

void dumpFull(unsigned Offset=0, unsigned Indent=0) const

Dump descriptor, including all valid offsets.

bool isPrimitive() const

Checks if the descriptor is of a primitive.

Definition Descriptor.h:263

QualType getElemQualType() const

const RecordDecl * asRecordDecl() const

Definition Descriptor.h:226

bool hasTrivialDtor() const

Whether variables of this descriptor need their destructor called or not.

bool isCompositeArray() const

Checks if the descriptor is of an array of composites.

Definition Descriptor.h:256

const BlockDtorFn DtorFn

Definition Descriptor.h:173

const OptPrimType PrimT

The primitive type this descriptor was created for, or the primitive element type in case this is a p...

Definition Descriptor.h:159

static constexpr MetadataSize GlobalMD

Definition Descriptor.h:145

const ValueDecl * asValueDecl() const

Definition Descriptor.h:214

const BlockCtorFn CtorFn

Storage management methods.

Definition Descriptor.h:172

static constexpr unsigned MaxArrayElemBytes

Maximum number of bytes to be used for array elements.

Definition Descriptor.h:148

const DeclTy & getSource() const

Definition Descriptor.h:212

const Decl * asDecl() const

Definition Descriptor.h:210

const Descriptor *const ElemDesc

Descriptor of the array element.

Definition Descriptor.h:155

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.

unsigned getMetadataSize() const

Returns the size of the metadata.

Definition Descriptor.h:246

SourceLocation getLocation() const

const bool IsMutable

Flag indicating if a field is mutable.

Definition Descriptor.h:163

static constexpr MetadataSize InlineDescMD

Definition Descriptor.h:144

QualType getDataType(const ASTContext &Ctx) const

std::optional< unsigned > MetadataSize

Definition Descriptor.h:143

bool isUnknownSizeArray() const

Checks if the descriptor is of an array of unknown size.

Definition Descriptor.h:260

unsigned getElemSize() const

returns the size of an element when the structure is viewed as an array.

Definition Descriptor.h:244

const bool IsArray

Flag indicating if the block is an array.

Definition Descriptor.h:168

bool isPrimitiveArray() const

Checks if the descriptor is of an array of primitives.

Definition Descriptor.h:254

bool IsConstexprUnknown

Definition Descriptor.h:169

bool isZeroSizeArray() const

Checks if the descriptor is of an array of zero size.

Definition Descriptor.h:258

const FieldDecl * asFieldDecl() const

Definition Descriptor.h:222

const VarDecl * asVarDecl() const

Definition Descriptor.h:218

PrimType getPrimType() const

Definition Descriptor.h:236

bool isRecord() const

Checks if the descriptor is of a record.

Definition Descriptor.h:268

const bool IsTemporary

Flag indicating if the block is a temporary.

Definition Descriptor.h:165

const Record *const ElemRecord

Pointer to the record, if block contains records.

Definition Descriptor.h:153

bool isUnion() const

Checks if the descriptor is of a union.

const Expr * asExpr() const

Definition Descriptor.h:211

bool isArray() const

Checks if the descriptor is of an array.

Definition Descriptor.h:266

Descriptor used for global variables.

Definition Descriptor.h:51

GlobalInitState InitState

Definition Descriptor.h:52

Bitfield tracking the initialisation status of elements of primitive arrays.

Definition Descriptor.h:281

friend class Pointer

Definition Descriptor.h:293

InitMap(unsigned N)

Initializes the map with no fields set.

Inline descriptor embedded in structures and arrays.

Definition Descriptor.h:67

unsigned IsActive

Flag indicating if the field is the active member of a union.

Definition Descriptor.h:89

unsigned IsConstInMutable

Flag indicating if this field is a const field nested in a mutable parent field.

Definition Descriptor.h:99

Lifetime LifeState

Definition Descriptor.h:106

unsigned IsVolatile

Definition Descriptor.h:104

unsigned IsBase

Flag indicating if the field is an embedded base class.

Definition Descriptor.h:83

const Descriptor * Desc

Definition Descriptor.h:108

unsigned IsVirtualBase

Flag inidcating if the field is a virtual base class.

Definition Descriptor.h:86

unsigned InUnion

Flag indicating if this field is in a union (even if nested).

Definition Descriptor.h:92

unsigned Offset

Offset inside the structure/array.

Definition Descriptor.h:69

unsigned IsInitialized

For primitive fields, it indicates if the field was initialized.

Definition Descriptor.h:80

void dump() const

Definition Descriptor.h:116

unsigned IsConst

Flag indicating if the storage is constant or not.

Definition Descriptor.h:74

unsigned IsArrayElement

Flag indicating if the field is an element of a composite array.

Definition Descriptor.h:102

unsigned IsFieldMutable

Flag indicating if the field is mutable (if in a record).

Definition Descriptor.h:95

InlineDescriptor(const Descriptor *D)

Definition Descriptor.h:110