#define LLVM_SUPPORT_ALLOCATOR_H
#include "llvm/Support/AlignOf.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MathExtras.h"
+#include "llvm/System/DataTypes.h"
+#include <algorithm>
#include <cassert>
#include <cstdlib>
+#include <cstddef>
namespace llvm {
static MallocSlabAllocator DefaultSlabAllocator;
public:
+ typedef void (*DTorFunction)(void*);
BumpPtrAllocator(size_t size = 4096, size_t threshold = 4096,
SlabAllocator &allocator = DefaultSlabAllocator);
~BumpPtrAllocator();
/// to the beginning of it, freeing all memory allocated so far.
void Reset();
+ /// Reset - like Reset(), but call DTorFunction for each allocated
+ /// object. This assumes that all objects allocated with this allocator
+ /// had the same size and alignment specified here.
+ void Reset(size_t Size, size_t Alignment, DTorFunction DTor);
+
/// Allocate - Allocate space at the specified alignment.
///
void *Allocate(size_t Size, size_t Alignment);
} // end namespace llvm
+inline void *operator new(size_t Size, llvm::BumpPtrAllocator &Allocator) {
+ struct S {
+ char c;
+#ifdef __GNUC__
+ char x __attribute__((aligned));
+#else
+ union {
+ double D;
+ long double LD;
+ long long L;
+ void *P;
+ } x;
+#endif
+ };
+ return Allocator.Allocate(Size, std::min((size_t)llvm::NextPowerOf2(Size),
+ offsetof(S, x)));
+}
+
#endif // LLVM_SUPPORT_ALLOCATOR_H