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);
119 return *
reinterpret_cast<const T *
>(
data());
124 assert(!IsInitialized);
125 std::memset(
rawData(), 0, Desc->getAllocSize());
127 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
131 IsInitialized =
true;
136 assert(IsInitialized);
138 Desc->DtorFn(
this,
data(), Desc);
139 IsInitialized =
false;
143 void dump(llvm::raw_ostream &OS)
const;
154 Block(
unsigned EvalID,
const Descriptor *Desc,
bool IsExtern,
bool IsStatic,
155 bool IsWeak,
bool IsDummy,
bool IsDead)
156 : Desc(Desc), EvalID(EvalID), IsStatic(IsStatic) {
158 AccessFlags |= (ExternFlag * IsExtern);
159 AccessFlags |= (DeadFlag * IsDead);
160 AccessFlags |= (WeakFlag * IsWeak);
161 AccessFlags |= (DummyFlag * IsDummy);
165 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
172 void removePointer(
Pointer *P);
175 bool hasPointer(
const Pointer *P)
const;
179 const Descriptor *Desc;
184 const unsigned EvalID = ~0u;
186 bool IsStatic =
false;
189 bool IsInitialized =
false;
193 uint8_t AccessFlags = 0;
206 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.