13#ifndef LLVM_CLANG_AST_INTERP_BLOCK_H
14#define LLVM_CLANG_AST_INTERP_BLOCK_H
17#include "llvm/Support/raw_ostream.h"
28 static constexpr uint8_t
Extern = 1u << 0u;
29 static constexpr uint8_t
Dead = 1u << 1u;
30 static constexpr uint8_t
Weak = 1u << 2u;
74 : Desc(Desc), DescSize(Desc->
getAllocSize()), DeclID(DeclID),
79 : Desc(Desc), DescSize(Desc->
getAllocSize()), EvalID(EvalID),
96 llvm_unreachable(
"Unhandled Block kind");
112 bool Result = (DynAllocId != std::nullopt);
113 assert((
Result == Desc->isDynAlloc()) &&
114 "Inconsistent block/descriptor dynamic alloc state");
140 std::byte *
data() {
return rawData() + MDSize; }
141 const std::byte *
data()
const {
return rawData() + MDSize; }
143 template <
typename T>
const T &
deref()
const {
144 return *
reinterpret_cast<const T *
>(
data());
146 template <
typename T>
T &
deref() {
return *
reinterpret_cast<T *
>(
data()); }
151 if constexpr (std::is_same_v<T, GlobalInlineDescriptor>)
153 else if constexpr (std::is_same_v<T, LocalInlineDescriptor>)
154 assert(Kind ==
Local);
156 assert(Kind ==
None);
158 return *
reinterpret_cast<T *
>(rawData());
166 assert(!IsInitialized);
172 assert(!IsInitialized);
174 Desc->CtorFn(
data(), Desc->IsConst, Desc->IsMutable, Desc->IsVolatile,
177 IsInitialized =
true;
182 assert(IsInitialized);
184 Desc->DtorFn(
data(), Desc);
185 IsInitialized =
false;
189 void dump(llvm::raw_ostream &OS)
const;
199 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
206 void removePointer(
Pointer *P);
209 bool hasPointer(
const Pointer *P)
const;
213 void markDead() { Flags = Flags.
withDead(); }
217 std::byte *rawData() {
218 return reinterpret_cast<std::byte *
>(
this) +
sizeof(
Block);
220 const std::byte *rawData()
const {
221 return reinterpret_cast<const std::byte *
>(
this) +
sizeof(
Block);
225 const Descriptor *
const Desc;
229 const unsigned DescSize;
232 const unsigned EvalID = ~0u;
242 bool IsInitialized =
false;
255 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, excluding metadata.
static unsigned allocSize(const Descriptor *D, BlockKind K)
Number of bytes needed to allocate 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.
bool isConstexprUnknown() const
static constexpr unsigned getMetadataSize(BlockKind K)
void movePointersTo(Block *B)
Move all pointers from this block to.
void invokeCtor()
Invokes the constructor.
Block(unsigned EvalID, UnsignedOrNone DeclID, const Descriptor *Desc, BlockKind K, BlockFlags Flags=BlockFlags::empty())
Block(unsigned EvalID, const Descriptor *Desc, BlockKind K, BlockFlags Flags=BlockFlags::empty())
const T & getBlockDesc() const
friend class DynamicAllocator
unsigned getAllocSize() const
Returns the size of the block, including metadata.
bool isTemporary() const
Checks if the block is temporary.
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.
@ Result
The result type of a method or function.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 uint8_t
static constexpr uint8_t Dead
static constexpr uint8_t Weak
constexpr BlockFlags withDead(bool B=true) const
constexpr BlockFlags withExtern(bool B=true) const
static constexpr uint8_t Extern
static constexpr uint8_t ConstexprUnknown
constexpr BlockFlags withWeak(bool B=true) const
static constexpr BlockFlags empty()
constexpr BlockFlags(uint8_t V=0)
constexpr BlockFlags withConstexprUnknown(bool B=true) const
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Descriptor used for global variables.