15 #ifndef LLVM_SUPPORT_ARRAYRECYCLER_H
16 #define LLVM_SUPPORT_ARRAYRECYCLER_H
29 template<class T, size_t Align = AlignOf<T>::Alignment>
38 static_assert(
sizeof(
T) >=
sizeof(FreeList),
"Objects are too small");
45 T *pop(
unsigned Idx) {
46 if (Idx >= Bucket.
size())
48 FreeList *Entry = Bucket[Idx];
51 Bucket[Idx] = Entry->Next;
52 return reinterpret_cast<T*
>(Entry);
56 void push(
unsigned Idx,
T *Ptr) {
57 assert(Ptr &&
"Cannot recycle NULL pointer");
58 FreeList *Entry =
reinterpret_cast<FreeList*
>(Ptr);
59 if (Idx >= Bucket.
size())
60 Bucket.
resize(
size_t(Idx) + 1);
61 Entry->Next = Bucket[Idx];
72 explicit Capacity(uint8_t idx) : Index(idx) {}
83 size_t getSize()
const {
return size_t(1u) << Index; }
97 assert(Bucket.
empty() &&
"Non-empty ArrayRecycler deleted!");
102 template<
class AllocatorType>
103 void clear(AllocatorType &Allocator) {
105 while (
T *Ptr = pop(Bucket.
size() - 1))
106 Allocator.Deallocate(Ptr);
123 template<
class AllocatorType>
126 if (
T *Ptr = pop(Cap.getBucket()))
129 return static_cast<T*
>(Allocator.Allocate(
sizeof(
T)*Cap.getSize(),
Align));
137 push(Cap.getBucket(), Ptr);
AlignOf - A templated class that contains an enum value representing the alignment of the template ar...
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.
bool LLVM_ATTRIBUTE_UNUSED_RESULT 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.
Capacity getNext() const
Get the next larger capacity.
void clear(AllocatorType &Allocator)
Release all the tracked allocations to the allocator.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
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...
void clear(BumpPtrAllocator &)
Special case for BumpPtrAllocator which has an empty Deallocate() function.
void deallocate(Capacity Cap, T *Ptr)
Deallocate an array with the specified Capacity.