14 #ifndef LLVM_SUPPORT_ALLOCATOR_H
15 #define LLVM_SUPPORT_ALLOCATOR_H
18 #include "llvm/Support/DataTypes.h"
43 return static_cast<T*
>(
malloc(
sizeof(
T)*Num));
100 size_t SizeThreshold;
124 size_t BytesAllocated;
129 static char *AlignPtr(
char *Ptr,
size_t Alignment);
137 void DeallocateSlabs(
MemSlab *Slab);
151 void *
Allocate(
size_t Size,
size_t Alignment);
155 template <
typename T>
162 template <
typename T>
169 template <
typename T>
172 size_t EltSize = (
sizeof(
T)+Alignment-1)&(-Alignment);
173 return static_cast<T*
>(
Allocate(Num * EltSize, Alignment));
189 template <
typename T>
194 : Allocator(size, threshold) {}
197 : Allocator(size, threshold, allocator) {}
207 MemSlab *Slab = Allocator.CurSlab;
209 char *End = Slab == Allocator.CurSlab ? Allocator.CurPtr :
210 (
char *)Slab + Slab->
Size;
211 for (
char *Ptr = (
char*)(Slab+1); Ptr < End; Ptr +=
sizeof(
T)) {
212 Ptr = Allocator.AlignPtr(Ptr, alignOf<T>());
213 if (Ptr +
sizeof(
T) <= End)
214 reinterpret_cast<T*
>(Ptr)->~
T();
245 #endif // LLVM_SUPPORT_ALLOCATOR_H
virtual void Deallocate(MemSlab *Slab)=0
T * Allocate(size_t Num, size_t Alignment)
void * Allocate(size_t Size, size_t)
void Deallocate(const void *)
virtual MemSlab * Allocate(size_t Size) LLVM_OVERRIDE
void Deallocate(const void *Ptr)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
SpecificBumpPtrAllocator(size_t size, size_t threshold, SlabAllocator &allocator)
T * Allocate(size_t num=1)
Allocate space for a specific count of elements.
~SpecificBumpPtrAllocator()
uint64_t NextPowerOf2(uint64_t A)
virtual MemSlab * Allocate(size_t Size)=0
SpecificBumpPtrAllocator(size_t size=4096, size_t threshold=4096)
unsigned GetNumSlabs() const
#define LLVM_DELETED_FUNCTION
void * Allocate(size_t Size, size_t Alignment)
virtual ~MallocSlabAllocator()
void *malloc(size_t size);
size_t getTotalMemory() const
Compute the total physical memory allocated by this allocator.
virtual void Deallocate(MemSlab *Slab) LLVM_OVERRIDE