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];
51 Bucket[Idx] = Entry->Next;
53 return reinterpret_cast<T*
>(Entry);
57 void push(
unsigned Idx,
T *Ptr) {
58 assert(Ptr &&
"Cannot recycle NULL pointer");
59 FreeList *Entry =
reinterpret_cast<FreeList*
>(Ptr);
60 if (Idx >= Bucket.
size())
61 Bucket.
resize(
size_t(Idx) + 1);
62 Entry->Next = Bucket[Idx];
99 assert(Bucket.
empty() &&
"Non-empty ArrayRecycler deleted!");
104 template<
class AllocatorType>
107 while (
T *Ptr = pop(Bucket.
size() - 1))
108 Allocator.Deallocate(Ptr);
125 template<
class AllocatorType>
128 if (
T *Ptr = pop(Cap.getBucket()))
131 return static_cast<T*
>(Allocator.Allocate(
sizeof(
T)*Cap.getSize(),
Align));
139 push(Cap.getBucket(), Ptr);
#define __asan_poison_memory_region(p, size)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This class represents lattice values for constants.
T * allocate(Capacity Cap, AllocatorType &Allocator)
Allocate an array of at least the requested capacity.
Capacity getNext() const
Get the next larger capacity.
#define __asan_unpoison_memory_region(p, size)
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.
unsigned getBucket() const
Get the bucket number for this capacity.
#define __msan_allocated_memory(p, size)
Allocate memory in an ever growing pool, as if by bump-pointer.
static Capacity get(size_t N)
Get the capacity of an array that can hold at least N elements.
void clear(AllocatorType &Allocator)
Release all the tracked allocations to the allocator.
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
size_t getSize() const
Get the number of elements in an array with this capacity.
LLVM_NODISCARD bool empty() 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.