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; }
83 bool isDynamic()
const {
return (DynAllocId != std::nullopt); }
84 bool isDead()
const {
return AccessFlags & DeadFlag; }
86 unsigned getSize()
const {
return Desc->getAllocSize() + MDSize; }
109 return reinterpret_cast<std::byte *
>(
this) +
sizeof(
Block);
112 return reinterpret_cast<const std::byte *
>(
this) +
sizeof(
Block);
115 template <
typename T>
const T &
deref()
const {
116 return *
reinterpret_cast<const T *
>(
data());
118 template <
typename T>
T &
deref() {
return *
reinterpret_cast<T *
>(
data()); }
121 assert(
sizeof(
T) == MDSize);
122 return *
reinterpret_cast<T *
>(
rawData());
130 assert(!IsInitialized);
136 assert(!IsInitialized);
138 Desc->CtorFn(
this,
data(), Desc->IsConst, Desc->IsMutable,
142 IsInitialized =
true;
147 assert(IsInitialized);
149 Desc->DtorFn(
this,
data(), Desc);
150 IsInitialized =
false;
154 void dump(llvm::raw_ostream &OS)
const;
165 Block(
unsigned EvalID,
const Descriptor *Desc,
unsigned MDSize,
bool IsExtern,
166 bool IsStatic,
bool IsWeak,
bool IsDead)
167 : Desc(Desc), EvalID(EvalID), MDSize(MDSize), IsStatic(IsStatic) {
169 AccessFlags |= (ExternFlag * IsExtern);
170 AccessFlags |= (DeadFlag * IsDead);
171 AccessFlags |= (WeakFlag * IsWeak);
175 void setDynAllocId(
unsigned ID) { DynAllocId = ID; }
182 void removePointer(
Pointer *P);
185 bool hasPointer(
const Pointer *P)
const;
189 const Descriptor *Desc;
194 const unsigned EvalID = ~0u;
202 bool IsStatic =
false;
205 bool IsInitialized =
false;
218 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.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_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.