LLVM: include/llvm/Support/Recycler.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_SUPPORT_RECYCLER_H
15#define LLVM_SUPPORT_RECYCLER_H
16
21#include
22#include <type_traits>
23
24namespace llvm {
25
26
27
28
30 size_t FreeListSize);
31
32
33
34
35
36template <class T, size_t Size = sizeof(T), size_t Align = alignof(T)>
38 struct FreeNode {
39 FreeNode *Next;
40 };
41
42
43 FreeNode *FreeList = nullptr;
44
45 FreeNode *pop_val() {
46 auto *Val = FreeList;
48 FreeList = FreeList->Next;
50 return Val;
51 }
52
53 void push(FreeNode *N) {
54 N->Next = FreeList;
55 FreeList = N;
57 }
58
59public:
61
62
63
64 assert(!FreeList && "Non-empty recycler deleted!");
65 }
68 : FreeList(std::exchange(Other.FreeList, nullptr)) {}
70
71
72
73
74 template
76 if constexpr (std::is_same_v<std::decay_t,
78
79
80 FreeList = nullptr;
81 } else {
82 while (FreeList) {
83 T *t = reinterpret_cast<T *>(pop_val());
85 }
86 }
87 }
88
89 template<class SubClass, class AllocatorType>
91 static_assert(alignof(SubClass) <= Align,
92 "Recycler allocation alignment is less than object align!");
93 static_assert(sizeof(SubClass) <= Size,
94 "Recycler allocation size is less than object size!");
95 static_assert(Size >= sizeof(FreeNode) &&
96 "Recycler allocation size must be at least sizeof(FreeNode)");
97 return FreeList ? reinterpret_cast<SubClass *>(pop_val())
99 }
100
101 template
105
106 template<class SubClass, class AllocatorType>
107 void Deallocate(AllocatorType & , SubClass* Element) {
108 push(reinterpret_cast<FreeNode *>(Element));
109 }
110
112};
113
114template <class T, size_t Size, size_t Align>
116 size_t S = 0;
117 for (auto *I = FreeList; I; I = I->Next)
118 ++S;
120}
121
122}
123
124#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
#define __asan_poison_memory_region(p, size)
#define __asan_unpoison_memory_region(p, size)
#define __msan_allocated_memory(p, size)
void PrintStats()
Definition Recycler.h:115
void clear(AllocatorType &Allocator)
clear - Release all the tracked allocations to the allocator.
Definition Recycler.h:75
Recycler(Recycler &&Other)
Definition Recycler.h:67
~Recycler()
Definition Recycler.h:60
void Deallocate(AllocatorType &, SubClass *Element)
Definition Recycler.h:107
Recycler(const Recycler &)=delete
SubClass * Allocate(AllocatorType &Allocator)
Definition Recycler.h:90
T * Allocate(AllocatorType &Allocator)
Definition Recycler.h:102
This file defines classes to implement an intrusive doubly linked list class (i.e.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize)
PrintRecyclingAllocatorStats - Helper for RecyclingAllocator for printing statistics.
FunctionAddr VTableAddr Next
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.