13#ifndef LLVM_CLANG_AST_INTERP_BLOCK_H
14#define LLVM_CLANG_AST_INTERP_BLOCK_H
17#include "llvm/Support/raw_ostream.h"
46 static constexpr uint8_t ExternFlag = 1 << 0;
47 static constexpr uint8_t DeadFlag = 1 << 1;
48 static constexpr uint8_t WeakFlag = 1 << 2;
49 static constexpr uint8_t DummyFlag = 1 << 3;
54 bool IsStatic =
false,
bool IsExtern =
false,
bool IsWeak =
false,
56 : Desc(Desc), DeclID(DeclID), EvalID(EvalID), IsStatic(IsStatic) {
58 AccessFlags |= (ExternFlag * IsExtern);
59 AccessFlags |= (WeakFlag * IsWeak);
60 AccessFlags |= (DummyFlag * IsDummy);
64 bool IsExtern =
false,
bool IsWeak =
false,
bool IsDummy =
false)
65 : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) {
67 AccessFlags |= (ExternFlag * IsExtern);
68 AccessFlags |= (WeakFlag * IsWeak);
69 AccessFlags |= (DummyFlag * IsDummy);
77 bool isExtern()
const {
return AccessFlags & ExternFlag; }
82 bool isWeak()
const {
return AccessFlags & WeakFlag; }
83 bool isDynamic()
const {
return (DynAllocId != std::nullopt); }
84 bool isDummy()
const {
return AccessFlags & DummyFlag; }
85 bool isDead()
const {
return AccessFlags & DeadFlag; }
87 unsigned getSize()
const {
return Desc->getAllocSize(); }
104 size_t DataOffset = Desc->getMetadataSize();
107 const std::byte *
data()
const {
109 size_t DataOffset = Desc->getMetadataSize();
116 return reinterpret_cast<std::byte *
>(
this) +
sizeof(
Block);
119 return reinterpret_cast<const std::byte *
>(
this) +
sizeof(
Block);
122 template <
typename T>
const T &
deref()
const {
123 return *
reinterpret_cast<const T *
>(
data());
125 template <
typename T> T &
deref() {
return *
reinterpret_cast<T *
>(
data()); }
129 return *
reinterpret_cast<T *
>(
rawData());
137 assert(!IsInitialized);
138 std::memset(
rawData(), 0, Desc->getAllocSize());
143 assert(!IsInitialized);
145 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
149 IsInitialized =
true;
154 assert(IsInitialized);
156 Desc->DtorFn(
this,
data(), Desc);
157 IsInitialized =
false;
161 void dump(llvm::raw_ostream &OS)
const;
172 Block(
unsigned EvalID,
const Descriptor *Desc,
bool IsExtern,
bool IsStatic,
173 bool IsWeak,
bool IsDummy,
bool IsDead)
174 : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) {
176 AccessFlags |= (ExternFlag * IsExtern);
177 AccessFlags |= (DeadFlag * IsDead);
178 AccessFlags |= (WeakFlag * IsWeak);
179 AccessFlags |= (DummyFlag * IsDummy);
183 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
190 void removePointer(
Pointer *P);
193 bool hasPointer(
const Pointer *P)
const;
197 const Descriptor *Desc;
202 const unsigned EvalID = ~0u;
204 bool IsStatic =
false;
207 bool IsInitialized =
false;
224 std::byte *
data() {
return B.data(); }
A memory block, either on the stack or in the heap.
unsigned getSize() const
Returns the size of the block.
void invokeDtor()
Invokes the Destructor.
bool isExtern() const
Checks if the block is extern.
void invokeCtorNoMemset()
The same, but won't memset() the memory first to zero.
std::byte * data()
Returns a pointer to the stored data.
const Descriptor * getDescriptor() const
Returns the block's descriptor.
Block(unsigned EvalID, const Descriptor *Desc, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false, bool IsDummy=false)
const std::byte * rawData() const
void movePointersTo(Block *B)
Move all pointers from this block to.
void invokeCtor()
Invokes the constructor.
bool isStatic() const
Checks if the block has static storage duration.
const T & getBlockDesc() const
Block(unsigned EvalID, UnsignedOrNone DeclID, const Descriptor *Desc, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false, bool IsDummy=false)
Creates a new block.
friend class DynamicAllocator
bool isTemporary() const
Checks if the block is temporary.
std::byte * rawData()
Returns a pointer to the raw data, including metadata.
const std::byte * data() const
bool isInitialized() const
Returns whether the data of this block has been initialized via invoking the Ctor func.
UnsignedOrNone getDeclID() const
Returns the declaration ID.
unsigned getEvalID() const
The Evaluation ID this block was created in.
bool isAccessible() const
bool hasPointers() const
Checks if the block has any live pointers.
void removePointers()
Make all pointers that currently point to this block point to nullptr.
Descriptor for a dead block.
std::byte * data()
Returns a pointer to the stored data.
DeadBlock(DeadBlock *&Root, Block *Blk)
Copies the block.
A pointer to a memory block, live or dead.
PrimType
Enumeration of the primitive types of the VM.
The JSON file list parser is used to communicate input to InstallAPI.
OptionalUnsigned< unsigned > UnsignedOrNone
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
Describes a memory block created by an allocation site.