15 #ifndef LLVM_SUPPORT_ARRAYRECYCLER_H
16 #define LLVM_SUPPORT_ARRAYRECYCLER_H
36 static_assert(Align >=
alignof(FreeList),
"Object underaligned");
37 static_assert(
sizeof(
T) >=
sizeof(FreeList),
"Objects are too small");
44 T *pop(
unsigned Idx) {
45 if (Idx >= Bucket.
size())
47 FreeList *Entry = Bucket[Idx];
50 Bucket[Idx] = Entry->Next;
51 return reinterpret_cast<T*
>(Entry);
55 void push(
unsigned Idx,
T *
Ptr) {
56 assert(Ptr &&
"Cannot recycle NULL pointer");
57 FreeList *Entry =
reinterpret_cast<FreeList*
>(
Ptr);
58 if (Idx >= Bucket.
size())
59 Bucket.
resize(
size_t(Idx) + 1);
60 Entry->Next = Bucket[Idx];
71 explicit Capacity(uint8_t idx) : Index(idx) {}
82 size_t getSize()
const {
return size_t(1u) << Index; }
96 assert(Bucket.
empty() &&
"Non-empty ArrayRecycler deleted!");
101 template<
class AllocatorType>
104 while (
T *Ptr = pop(Bucket.
size() - 1))
105 Allocator.Deallocate(Ptr);
122 template<
class AllocatorType>
125 if (
T *Ptr = pop(Cap.getBucket()))
128 return static_cast<T*
>(Allocator.Allocate(
sizeof(
T)*Cap.getSize(), Align));
136 push(Cap.getBucket(),
Ptr);
T * allocate(Capacity Cap, AllocatorType &Allocator)
Allocate an array of at least the requested capacity.
Recycle small arrays allocated from a BumpPtrAllocator.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
The size of an allocated array is represented by a Capacity instance.
LLVM_NODISCARD bool empty() const
unsigned getBucket() const
Get the bucket number for this capacity.
size_t getSize() const
Get the number of elements in an array with this capacity.
Allocate memory in an ever growing pool, as if by bump-pointer.
Greedy Register Allocator
Capacity getNext() const
Get the next larger capacity.
void clear(AllocatorType &Allocator)
Release all the tracked allocations to the allocator.
unsigned Log2_64_Ceil(uint64_t Value)
Log2_64_Ceil - This function returns the ceil log base 2 of the specified value, 64 if the value is z...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void clear(BumpPtrAllocator &)
Special case for BumpPtrAllocator which has an empty Deallocate() function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void deallocate(Capacity Cap, T *Ptr)
Deallocate an array with the specified Capacity.