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;
55 unsigned MDSize = 0,
bool IsStatic =
false,
bool IsExtern =
false,
57 : Desc(Desc), DeclID(DeclID), EvalID(EvalID), MDSize(MDSize),
60 AccessFlags |= (ExternFlag * IsExtern);
61 AccessFlags |= (WeakFlag * IsWeak);
65 bool IsStatic =
false,
bool IsExtern =
false,
bool IsWeak =
false)
66 : Desc(Desc), EvalID(EvalID), MDSize(MDSize), IsStatic(IsStatic) {
68 AccessFlags |= (ExternFlag * IsExtern);
69 AccessFlags |= (WeakFlag * IsWeak);
77 bool isExtern()
const {
return AccessFlags & ExternFlag; }
82 bool isWeak()
const {
return AccessFlags & WeakFlag; }
84 bool Result = (DynAllocId != std::nullopt);
85 assert((
Result == Desc->isDynAlloc()) &&
86 "Inconsistent block/descriptor dynamic alloc state");
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 IsDead)
172 : Desc(Desc), EvalID(EvalID), MDSize(MDSize), IsStatic(IsStatic) {
174 AccessFlags |= (ExternFlag * IsExtern);
175 AccessFlags |= (DeadFlag * IsDead);
176 AccessFlags |= (WeakFlag * IsWeak);
180 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
187 void removePointer(
Pointer *P);
190 bool hasPointer(
const Pointer *P)
const;
194 const Descriptor *Desc;
199 const unsigned EvalID = ~0u;
203 uint8_t AccessFlags = 0;
205 const uint8_t MDSize = 0;
207 bool IsStatic =
false;
210 bool IsInitialized =
false;
223 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.
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, const Descriptor *Desc, unsigned MDSize=0, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false)
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.
Block(unsigned EvalID, UnsignedOrNone DeclID, const Descriptor *Desc, unsigned MDSize=0, bool IsStatic=false, bool IsExtern=false, bool IsWeak=false)
Creates a new block.
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 uint8_t
Describes a memory block created by an allocation site.
Descriptor used for global variables.
Inline descriptor embedded in structures and arrays.