13#ifndef LLVM_CLANG_AST_INTERP_BLOCK_H
14#define LLVM_CLANG_AST_INTERP_BLOCK_H
17#include "llvm/Support/raw_ostream.h"
45 static constexpr uint8_t ExternFlag = 1 << 0;
46 static constexpr uint8_t DeadFlag = 1 << 1;
47 static constexpr uint8_t WeakFlag = 1 << 2;
48 static constexpr uint8_t DummyFlag = 1 << 3;
56 unsigned MDSize = 0,
bool IsStatic =
false,
bool IsExtern =
false,
57 bool IsWeak =
false,
bool IsDummy =
false)
58 : Desc(Desc), DeclID(DeclID), EvalID(EvalID), MDSize(MDSize),
61 AccessFlags |= (ExternFlag * IsExtern);
62 AccessFlags |= (WeakFlag * IsWeak);
63 AccessFlags |= (DummyFlag * IsDummy);
67 bool IsStatic =
false,
bool IsExtern =
false,
bool IsWeak =
false,
69 : Desc(Desc), EvalID(EvalID), MDSize(MDSize), IsStatic(IsStatic) {
71 AccessFlags |= (ExternFlag * IsExtern);
72 AccessFlags |= (WeakFlag * IsWeak);
73 AccessFlags |= (DummyFlag * IsDummy);
81 bool isExtern()
const {
return AccessFlags & ExternFlag; }
86 bool isWeak()
const {
return AccessFlags & WeakFlag; }
87 bool isDynamic()
const {
return (DynAllocId != std::nullopt); }
88 bool isDummy()
const {
return AccessFlags & DummyFlag; }
89 bool isDead()
const {
return AccessFlags & DeadFlag; }
91 unsigned getSize()
const {
return Desc->getAllocSize() + MDSize; }
114 return reinterpret_cast<std::byte *
>(
this) +
sizeof(
Block);
117 return reinterpret_cast<const std::byte *
>(
this) +
sizeof(
Block);
120 template <
typename T>
const T &
deref()
const {
121 return *
reinterpret_cast<const T *
>(
data());
123 template <
typename T>
T &
deref() {
return *
reinterpret_cast<T *
>(
data()); }
126 assert(
sizeof(
T) == MDSize);
127 return *
reinterpret_cast<T *
>(
rawData());
135 assert(!IsInitialized);
141 assert(!IsInitialized);
143 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
147 IsInitialized =
true;
152 assert(IsInitialized);
154 Desc->DtorFn(
this,
data(), Desc);
155 IsInitialized =
false;
159 void dump(llvm::raw_ostream &OS)
const;
170 Block(
unsigned EvalID,
const Descriptor *Desc,
unsigned MDSize,
bool IsExtern,
171 bool IsStatic,
bool IsWeak,
bool IsDummy,
bool IsDead)
172 : Desc(Desc), EvalID(EvalID), MDSize(MDSize), IsStatic(IsStatic) {
174 AccessFlags |= (ExternFlag * IsExtern);
175 AccessFlags |= (DeadFlag * IsDead);
176 AccessFlags |= (WeakFlag * IsWeak);
177 AccessFlags |= (DummyFlag * IsDummy);
181 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
188 void removePointer(
Pointer *P);
191 bool hasPointer(
const Pointer *P)
const;
195 const Descriptor *Desc;
200 const unsigned EvalID = ~0u;
208 bool IsStatic =
false;
211 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, including metadata.
Block(unsigned EvalID, const Descriptor *Desc, unsigned MDSize=0, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false, bool IsDummy=false)
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.
static constexpr uint8_t InlineDescMD
const std::byte * rawData() const
static constexpr uint8_t GlobalMD
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.
unsigned getMetadataSize() const
Returns the size of the metadata.
const T & getBlockDesc() const
friend class DynamicAllocator
Block(unsigned EvalID, UnsignedOrNone DeclID, const Descriptor *Desc, unsigned MDSize=0, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false, bool IsDummy=false)
Creates a new block.
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.
Top level wrappers for InstallAPI frontend operations.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
Describes a memory block created by an allocation site.
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.