15 #ifndef LLVM_SUPPORT_RECYCLER_H
16 #define LLVM_SUPPORT_RECYCLER_H
34 template <
class T,
size_t Size = sizeof(T),
size_t Align = alignof(T)>
41 FreeNode *FreeList =
nullptr;
45 FreeList = FreeList->Next;
49 void push(FreeNode *
N) {
59 assert(!FreeList &&
"Non-empty recycler deleted!");
65 template<
class AllocatorType>
68 T *
t =
reinterpret_cast<T *
>(pop_val());
69 Allocator.Deallocate(t);
80 template<
class SubClass,
class AllocatorType>
82 static_assert(
alignof(SubClass) <= Align,
83 "Recycler allocation alignment is less than object align!");
84 static_assert(
sizeof(SubClass) <= Size,
85 "Recycler allocation size is less than object size!");
86 return FreeList ?
reinterpret_cast<SubClass *
>(pop_val())
87 : static_cast<SubClass *>(Allocator.Allocate(Size, Align));
90 template<
class AllocatorType>
95 template<
class SubClass,
class AllocatorType>
97 push(reinterpret_cast<FreeNode *>(Element));
103 template <
class T,
size_t Size,
size_t Align>
106 for (
auto *
I = FreeList;
I;
I =
I->Next)
void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize)
PrintRecyclingAllocatorStats - Helper for RecyclingAllocator for printing statistics.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void clear(BumpPtrAllocator &)
Special case for BumpPtrAllocator which has an empty Deallocate() function.
SubClass * Allocate(AllocatorType &Allocator)
Allocate memory in an ever growing pool, as if by bump-pointer.
Greedy Register Allocator
T * Allocate(AllocatorType &Allocator)
Recycler - This class manages a linked-list of deallocated nodes and facilitates reusing deallocated ...
void Deallocate(AllocatorType &, SubClass *Element)
void clear(AllocatorType &Allocator)
clear - Release all the tracked allocations to the allocator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())