9#ifndef LLVM_SUPPORT_PERTHREADBUMPPTRALLOCATOR_H
10#define LLVM_SUPPORT_PERTHREADBUMPPTRALLOCATOR_H
33template <
typename AllocatorTy>
39 std::vector<std::unique_ptr<AllocatorTy>> Allocators;
44 :
S(
std::make_unique<State>()),
Id(
detail::claimPerThreadAllocatorId()) {}
75 static thread_local std::vector<AllocatorTy *> Cache;
78 AllocatorTy *&
A = Cache[
Id];
82 auto New = std::make_unique<AllocatorTy>();
84 std::lock_guard<std::mutex> Lock(
S->Mutex);
85 S->Allocators.push_back(std::move(New));
92 std::lock_guard<std::mutex> Lock(
S->Mutex);
93 return S->Allocators.size();
103 for (
const auto &
A :
S->Allocators)
109 size_t TotalMemory = 0;
110 for (
const auto &
A :
S->Allocators)
111 TotalMemory +=
A->getTotalMemory();
117 for (
const auto &
A :
S->Allocators)
118 A->setRedZoneSize(NewSize);
124 for (
const auto &
A :
S->Allocators) {
125 errs() <<
"\n Allocator " << Idx++ <<
"\n";
132 std::unique_ptr<State>
S;
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_UNLIKELY(EXPR)
CRTP base class providing obvious overloads for the core Allocate() methods of LLVM-style allocators.
PerThreadAllocator wraps a thread-unsafe allocator (e.g.
std::unique_ptr< State > S
size_t getNumberOfAllocators() const
Return the number of sub-allocators, i.e. threads that have allocated.
size_t getTotalMemory() const
Return total memory size used by all allocators.
void Deallocate(const void *Ptr, size_t Size, size_t Alignment)
Deallocate Ptr to Size bytes of memory allocated by this allocator.
void Reset()
Reset state of allocators.
void * Allocate(size_t Size, size_t Alignment)
Allocate Size bytes of Alignment aligned memory.
void PrintStats() const
Print statistic for each allocator.
AllocatorTy & getThreadLocalAllocator()
Return the calling thread's sub-allocator, creating it on first use.
void setRedZoneSize(size_t NewSize)
Set red zone for all allocators.
LLVM_ABI unsigned claimPerThreadAllocatorId()
Return a new process-unique PerThreadAllocator instance id.
PerThreadAllocator< BumpPtrAllocator > PerThreadBumpPtrAllocator
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Implement std::hash so that hash_code can be used in STL containers.