21 for (
auto &Iter : AllocationSites) {
22 auto &AllocSite = Iter.second;
23 for (
auto &
Alloc : AllocSite.Allocations) {
32 AllocationSites.clear();
36 size_t NumElements,
unsigned EvalID,
41 allocateDescriptor(Source,
nullptr,
T, NumElements,
false,
45 return allocate(D, EvalID, AllocForm);
49 size_t NumElements,
unsigned EvalID,
55 ElementDesc->
asExpr(),
nullptr, ElementDesc, NumElements,
57 return allocate(D, EvalID, AllocForm);
67 llvm::erase_if(DeadAllocations, [](Allocation &
Alloc) ->
bool {
68 return !
Alloc.block()->hasPointers();
71 auto Memory = std::make_unique<std::byte[]>(
75 B->invokeCtorNoMemset();
81 ID->IsFieldMutable =
false;
83 ID->IsInitialized =
false;
84 ID->IsVolatile =
false;
92 if (
auto It = AllocationSites.find(D->
asExpr());
93 It != AllocationSites.end()) {
94 It->second.Allocations.emplace_back(std::move(Memory));
95 B->setDynAllocId(It->second.NumAllocs);
96 ++It->second.NumAllocs;
98 AllocationSites.insert(
99 {D->
asExpr(), AllocationSite(std::move(Memory), AllocForm)});
102 assert(B->isDynamic());
107 const Block *BlockToDelete) {
108 auto It = AllocationSites.find(Source);
109 if (It == AllocationSites.end())
112 auto &Site = It->second;
113 assert(!Site.empty());
116 auto *AllocIt = llvm::find_if(Site.Allocations, [&](
const Allocation &A) {
117 return BlockToDelete == A.block();
122 if (AllocIt == Site.Allocations.end())
125 Block *B = AllocIt->block();
137 B->AccessFlags |= Block::DeadFlag;
138 DeadAllocations.push_back(std::move(*AllocIt));
139 Site.Allocations.erase(AllocIt);
141 if (Site.size() == 0)
142 AllocationSites.erase(It);
147 Site.Allocations.erase(AllocIt);
149 AllocationSites.erase(It);
This represents one expression.
A memory block, either on the stack or in the heap.
void invokeDtor()
Invokes the Destructor.
static constexpr uint8_t InlineDescMD
bool isInitialized() const
Returns whether the data of this block has been initialized via invoking the Ctor func.
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.
Block * allocate(const Descriptor *D, unsigned EvalID, Form AllocForm)
Allocate ONE element of the given descriptor.
bool deallocate(const Expr *Source, const Block *BlockToDelete)
Deallocate the given source+block combination.
PrimType
Enumeration of the primitive types of the VM.
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
Describes a memory block created by an allocation site.
const bool IsConst
Flag indicating if the block is mutable.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
bool isCompositeArray() const
Checks if the descriptor is of an array of composites.
const Expr * asExpr() const
Inline descriptor embedded in structures and arrays.