File indexing completed on 2026-05-10 08:44:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_SUPPORT_RECYCLINGALLOCATOR_H
0015 #define LLVM_SUPPORT_RECYCLINGALLOCATOR_H
0016
0017 #include "llvm/Support/Recycler.h"
0018
0019 namespace llvm {
0020
0021
0022
0023
0024 template <class AllocatorType, class T, size_t Size = sizeof(T),
0025 size_t Align = alignof(T)>
0026 class RecyclingAllocator {
0027 private:
0028
0029
0030 Recycler<T, Size, Align> Base;
0031
0032
0033
0034 AllocatorType Allocator;
0035
0036 public:
0037 ~RecyclingAllocator() { Base.clear(Allocator); }
0038
0039
0040
0041
0042 template<class SubClass>
0043 SubClass *Allocate() { return Base.template Allocate<SubClass>(Allocator); }
0044
0045 T *Allocate() { return Base.Allocate(Allocator); }
0046
0047
0048
0049
0050 template<class SubClass>
0051 void Deallocate(SubClass* E) { return Base.Deallocate(Allocator, E); }
0052
0053 void PrintStats() {
0054 Allocator.PrintStats();
0055 Base.PrintStats();
0056 }
0057 };
0058
0059 }
0060
0061 template<class AllocatorType, class T, size_t Size, size_t Align>
0062 inline void *operator new(size_t size,
0063 llvm::RecyclingAllocator<AllocatorType,
0064 T, Size, Align> &Allocator) {
0065 assert(size <= Size && "allocation size exceeded");
0066 return Allocator.Allocate();
0067 }
0068
0069 template<class AllocatorType, class T, size_t Size, size_t Align>
0070 inline void operator delete(void *E,
0071 llvm::RecyclingAllocator<AllocatorType,
0072 T, Size, Align> &A) {
0073 A.Deallocate(E);
0074 }
0075
0076 #endif