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
21namespace interp {
24class SourceInfo;
25struct InitMap;
26struct Descriptor;
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 IsActive, bool InUnion,
38
39
40
43
44
45
46
47
49 std::byte *DstFieldPtr,
51
56};
57
58
61};
63
64
65
66
67
68
69
71
73
74
75
76 LLVM_PREFERRED_TYPE(bool)
78
79
80
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
95 LLVM_PREFERRED_TYPE(bool)
96
97 LLVM_PREFERRED_TYPE(bool)
99
100 LLVM_PREFERRED_TYPE(bool)
102
104
109
110 void dump() const { dump(llvm::errs()); }
111 void dump(llvm::raw_ostream &OS) const;
112};
113static_assert(sizeof(GlobalInlineDescriptor) != sizeof(InlineDescriptor), "");
114
115
117private:
118
120
121 const unsigned ElemSize;
122
123 const unsigned Size;
124
125 const unsigned MDSize;
126
127 const unsigned AllocSize;
128
129
130 static constexpr unsigned UnknownSizeMark = (unsigned)-1;
131
132public:
133
135
139
140
142 std::numeric_limits<decltype(AllocSize)>::max() - sizeof(InitMapPtr) -
144
145
147
149
150
151
152 const std::optional PrimT = std::nullopt;
153
155
157
159
161
163
164
168
169
172
173
176
177
180
181
184
185
188
189
192
193
195
196
198
203
204 const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }
205 const Expr *asExpr() const { return dyn_cast<const Expr *>(Source); }
207
209 return dyn_cast_if_present(asDecl());
210 }
211
213 return dyn_cast_if_present(asDecl());
214 }
215
217 return dyn_cast_if_present(asDecl());
218 }
219
221 return dyn_cast_if_present(asDecl());
222 }
223
224
227 return Size;
228 }
229
233 }
234
235
237
239
241
242
245 }
246
247
249
251
253
255
256
258
259
261
263
265
267
268 void dump() const;
269 void dump(llvm::raw_ostream &OS) const;
270};
271
272
274private:
275
276 using T = uint64_t;
277
278 static constexpr uint64_t PER_FIELD = sizeof(T) * CHAR_BIT;
279
280public:
281
282 explicit InitMap(unsigned N);
283
284private:
286
287
288 T *data() { return Data.get(); }
289 const T *data() const { return Data.get(); }
290
291
292 bool initializeElement(unsigned I);
293
294
295 bool isElementInitialized(unsigned I) const;
296
297 static constexpr size_t numFields(unsigned N) {
298 return (N + PER_FIELD - 1) / PER_FIELD;
299 }
300
301 unsigned UninitFields;
302 std::unique_ptr<T[]> Data;
303};
304
305}
306}
307
308#endif
llvm::MachO::Record Record
__DEVICE__ int max(int __a, int __b)
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.
A pointer to a memory block, live or dead.
Structure/Class descriptor.
Describes the statement/declaration an opcode was generated from.
std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr
void(*)(Block *Storage, std::byte *FieldPtr, bool IsConst, bool IsMutable, bool IsActive, bool InUnion, const Descriptor *FieldDesc) BlockCtorFn
Invoked whenever a block is created.
void(*)(Block *Storage, std::byte *FieldPtr, const Descriptor *FieldDesc) BlockDtorFn
Invoked when a block is destroyed.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
PrimType
Enumeration of the primitive types of the VM.
void(*)(Block *Storage, std::byte *SrcFieldPtr, std::byte *DstFieldPtr, const Descriptor *FieldDesc) BlockMoveFn
Invoked when a block with pointers referencing it goes out of scope.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
The JSON file list parser is used to communicate input to InstallAPI.
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.
unsigned getSize() const
Returns the size of the object without metadata.
void makeDummy()
Make this descriptor a dummy descriptor.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
const RecordDecl * asRecordDecl() const
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
static constexpr MetadataSize GlobalMD
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 DeclTy & getSource() const
const Decl * asDecl() const
const Descriptor *const ElemDesc
Descriptor of the array element.
SourceInfo getLoc() const
bool isDummy() const
Checks if this is a dummy descriptor.
unsigned getMetadataSize() const
Returns the size of the metadata.
SourceLocation getLocation() const
const bool IsMutable
Flag indicating if a field is mutable.
static constexpr MetadataSize InlineDescMD
std::optional< unsigned > MetadataSize
bool isUnknownSizeArray() const
Checks if the descriptor is of an array of unknown size.
bool IsDummy
Flag indicating if this is a dummy descriptor.
unsigned getElemSize() const
returns the size of an element when the structure is viewed as an array.
const bool IsArray
Flag indicating if the block is an array.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
bool isZeroSizeArray() const
Checks if the descriptor is of an array of zero size.
const FieldDecl * asFieldDecl() const
const VarDecl * asVarDecl() const
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 std::optional< PrimType > PrimT
The primitive type this descriptor was created for, or the primitive element type in case this is a p...
const Expr * asExpr() const
bool isArray() const
Checks if the descriptor is of an array.
Descriptor used for global variables.
GlobalInitState InitState
Bitfield tracking the initialisation status of elements of primitive arrays.
Inline descriptor embedded in structures and arrays.
unsigned IsActive
Flag indicating if the field is the active member of a union.
unsigned IsBase
Flag indicating if the field is an embedded base class.
unsigned IsVirtualBase
Flag inidcating if the field is a virtual base class.
unsigned InUnion
Flat indicating if this field is in a union (even if nested).
unsigned Offset
Offset inside the structure/array.
unsigned IsInitialized
For primitive fields, it indicates if the field was initialized.
unsigned IsConst
Flag indicating if the storage is constant or not.
unsigned IsArrayElement
Flag indicating if the field is an element of a composite array.
unsigned IsFieldMutable
Flag indicating if the field is mutable (if in a record).