9#ifndef LLVM_CLANG_AST_INTERP_DYNAMIC_ALLOCATOR_H
10#define LLVM_CLANG_AST_INTERP_DYNAMIC_ALLOCATOR_H
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/iterator_range.h"
16#include "llvm/Support/Allocator.h"
35 enum class Form : uint8_t {
43 std::unique_ptr<std::byte[]> Memory;
44 Allocation(std::unique_ptr<std::byte[]> Memory)
45 : Memory(
std::move(Memory)) {}
46 Block *block()
const {
return reinterpret_cast<Block *
>(Memory.get()); }
49 struct AllocationSite {
51 unsigned NumAllocs = 0;
54 AllocationSite(std::unique_ptr<std::byte[]> Memory,
Form AllocForm)
55 : AllocForm(AllocForm) {
56 Allocations.push_back({std::move(Memory)});
60 size_t size()
const {
return Allocations.size(); }
61 bool empty()
const {
return Allocations.empty(); }
76 unsigned EvalID,
Form AllocForm);
89 if (
auto It = AllocationSites.find(Source); It != AllocationSites.end())
90 return It->second.AllocForm;
96 llvm::DenseMap<const Expr *, AllocationSite>::const_iterator;
98 return llvm::make_range(AllocationSites.begin(), AllocationSites.end());
104 llvm::DenseMap<const Expr *, AllocationSite> AllocationSites;
109 using PoolAllocTy = llvm::BumpPtrAllocator;
110 PoolAllocTy DescAllocator;
113 template <
typename... Ts>
Descriptor *allocateDescriptor(Ts &&...Args) {
114 return new (DescAllocator)
Descriptor(std::forward<Ts>(Args)...);
This represents one expression.
A memory block, either on the stack or in the heap.
Manages dynamic memory allocations done during bytecode interpretation.
bool deallocate(const Expr *Source, const Block *BlockToDelete, InterpState &S)
Deallocate the given source+block combination.
llvm::iterator_range< const_virtual_iter > allocation_sites() const
DynamicAllocator(DynamicAllocator &&)=delete
std::optional< Form > getAllocationForm(const Expr *Source) const
Checks whether the allocation done at the given source is an array allocation.
llvm::DenseMap< const Expr *, AllocationSite >::const_iterator const_virtual_iter
Allocation site iterator.
DynamicAllocator()=default
Block * allocate(const Descriptor *D, unsigned EvalID, Form AllocForm)
Allocate ONE element of the given descriptor.
bool hasAllocations() const
DynamicAllocator(DynamicAllocator &)=delete
PrimType
Enumeration of the primitive types of the VM.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Describes a memory block created by an allocation site.