15 #ifndef LLVM_SUPPORT_ARRAYRECYCLER_H
16 #define LLVM_SUPPORT_ARRAYRECYCLER_H
23 class BumpPtrAllocator;
30 template<class T, size_t Align = AlignOf<T>::Alignment>
43 T *pop(
unsigned Idx) {
44 if (Idx >= Bucket.
size())
46 FreeList *Entry = Bucket[Idx];
49 Bucket[Idx] = Entry->Next;
50 return reinterpret_cast<T*
>(Entry);
54 void push(
unsigned Idx,
T *Ptr) {
55 assert(Ptr &&
"Cannot recycle NULL pointer");
56 assert(
sizeof(
T) >=
sizeof(FreeList) &&
"Objects are too small");
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);
T * allocate(Capacity Cap, AllocatorType &Allocator)
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.
void clear(AllocatorType &Allocator)
unsigned Log2_64_Ceil(uint64_t Value)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
void clear(BumpPtrAllocator &)
void deallocate(Capacity Cap, T *Ptr)