diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index 5eccbccbfc2..4da7acefb68 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -61,6 +61,23 @@ public: return static_cast(this)->Allocate(Size, Alignment); } + /// \brief Deallocate \a Ptr to \a Size bytes of memory allocated by this + /// allocator. + void Deallocate(const void *Ptr) { +#ifdef __clang__ + static_assert(static_cast( + &AllocatorBase::Deallocate) != + static_cast( + &DerivedT::Deallocate), + "Class derives from AllocatorBase without implementing the " + "core Deallocate(void *) overload!"); +#endif + return static_cast(this)->Deallocate(Ptr); + } + + // The rest of these methods are helpers that redirect to one of the above + // core methods. + /// \brief Allocate space for one object without constructing it. template T *Allocate() { return static_cast(Allocate(sizeof(T), AlignOf::Alignment)); @@ -78,6 +95,16 @@ public: size_t EltSize = (sizeof(T) + Alignment - 1) & (-Alignment); return static_cast(Allocate(Num * EltSize, Alignment)); } + + /// \brief Deallocate space for one object without destroying it. + template void Deallocate(T *Ptr) { + Deallocate(static_cast(Ptr)); + } + + /// \brief Allocate space for an array of objects without constructing them. + template void Deallocate(T *Ptr, size_t /*Num*/) { + Deallocate(static_cast(Ptr)); + } }; class MallocAllocator : public AllocatorBase { @@ -94,6 +121,9 @@ public: void Deallocate(const void *Ptr) { free(const_cast(Ptr)); } + // Pull in base class overloads. + using AllocatorBase::Deallocate; + void PrintStats() const {} }; @@ -226,6 +256,9 @@ public: void Deallocate(const void * /*Ptr*/) {} + // Pull in base class overloads. + using AllocatorBase::Deallocate; + size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); } size_t getTotalMemory() const {