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(); }
100 size_t DataOffset = Desc->getMetadataSize();
103 const std::byte *
data()
const {
105 size_t DataOffset = Desc->getMetadataSize();
112 return reinterpret_cast<std::byte *
>(
this) +
sizeof(
Block);
115 return reinterpret_cast<const std::byte *
>(
this) +
sizeof(
Block);
118 template <
typename T>
const T &
deref()
const {
119 return *
reinterpret_cast<const T *
>(
data());
121 template <
typename T>
T &
deref() {
return *
reinterpret_cast<T *
>(
data()); }
125 assert(!IsInitialized);
126 std::memset(
rawData(), 0, Desc->getAllocSize());
128 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
132 IsInitialized =
true;
137 assert(IsInitialized);
139 Desc->DtorFn(
this,
data(), Desc);
140 IsInitialized =
false;
144 void dump(llvm::raw_ostream &OS)
const;
155 Block(
unsigned EvalID,
const Descriptor *Desc,
bool IsExtern,
bool IsStatic,
156 bool IsWeak,
bool IsDummy,
bool IsDead)
157 : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) {
159 AccessFlags |= (ExternFlag * IsExtern);
160 AccessFlags |= (DeadFlag * IsDead);
161 AccessFlags |= (WeakFlag * IsWeak);
162 AccessFlags |= (DummyFlag * IsDummy);
166 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
173 void removePointer(
Pointer *P);
176 bool hasPointer(
const Pointer *P)
const;
180 const Descriptor *Desc;
185 const unsigned EvalID = ~0u;
187 bool IsStatic =
false;
190 bool IsInitialized =
false;
194 uint8_t AccessFlags = 0;
207 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 invokeCtor()
Invokes the constructor.
bool isStatic() const
Checks if the block has static storage duration.
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.
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.
const FunctionProtoType * T
Describes a memory block created by an allocation site.