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());
140 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
144 IsInitialized =
true;
149 assert(IsInitialized);
151 Desc->DtorFn(
this,
data(), Desc);
152 IsInitialized =
false;
156 void dump(llvm::raw_ostream &OS)
const;
167 Block(
unsigned EvalID,
const Descriptor *Desc,
bool IsExtern,
bool IsStatic,
168 bool IsWeak,
bool IsDummy,
bool IsDead)
169 : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) {
171 AccessFlags |= (ExternFlag * IsExtern);
172 AccessFlags |= (DeadFlag * IsDead);
173 AccessFlags |= (WeakFlag * IsWeak);
174 AccessFlags |= (DummyFlag * IsDummy);
178 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
185 void removePointer(
Pointer *P);
188 bool hasPointer(
const Pointer *P)
const;
192 const Descriptor *Desc;
197 const unsigned EvalID = ~0u;
199 bool IsStatic =
false;
202 bool IsInitialized =
false;
206 uint8_t AccessFlags = 0;
219 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.
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.
Describes a memory block created by an allocation site.