X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FAllocator.h;h=a58b9db27faafc3b4aa58adb3c5ae9f75eb17ee7;hb=2a22004f6857c57dc483ea6180f0e1f86854bd13;hp=4c848788c73dd2abae3f2f3275938a36251a5006;hpb=8f51a62b41a425f7fe262ff20cee835129ecc072;p=oota-llvm.git diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index 4c848788c73..a58b9db27fa 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -15,9 +15,12 @@ #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 #include #include +#include namespace llvm { @@ -131,6 +134,7 @@ class BumpPtrAllocator { static MallocSlabAllocator DefaultSlabAllocator; public: + typedef void (*DTorFunction)(void*); BumpPtrAllocator(size_t size = 4096, size_t threshold = 4096, SlabAllocator &allocator = DefaultSlabAllocator); ~BumpPtrAllocator(); @@ -139,6 +143,11 @@ public: /// 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); @@ -175,4 +184,22 @@ public: } // 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