BumpPtrAllocator that implement allocations that return a properly
typed pointer. For BumpPtrAllocator, the allocated memory is
automatically aligned to the minimum alignment of the type (as
calculated by llvm::AlignOf::Alignment).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43087
91177308-0d34-0410-b5e6-
96231b3b80d8
#ifndef LLVM_SUPPORT_ALLOCATOR_H
#define LLVM_SUPPORT_ALLOCATOR_H
+#include "llvm/Support/AlignOf.h"
#include <cstdlib>
namespace llvm {
void Reset() {}
void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
+
+ template <typename T>
+ T* Allocate() { return reinterpret_cast<T*>(malloc(sizeof(T))); }
+
void Deallocate(void *Ptr) { free(Ptr); }
void PrintStats() const {}
};
void Reset();
void *Allocate(unsigned Size, unsigned Alignment);
+
+ template <typename T>
+ T* Allocate() {
+ return reinterpret_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
+ }
+
+
void Deallocate(void *Ptr) {}
void PrintStats() const;
};