summaryrefslogtreecommitdiff
path: root/include/llvm/Support/Allocator.h
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-15 08:59:52 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-15 08:59:52 +0000
commit47b284ce3539ef216e0ab994f4b7d762cfb1c69a (patch)
tree6111d2fb0d403c8d94d6889e729b6d509574f0ed /include/llvm/Support/Allocator.h
parent2727dbcc3766108eca20f48f249aaa87c5a566a2 (diff)
downloadllvm-47b284ce3539ef216e0ab994f4b7d762cfb1c69a.tar.gz
llvm-47b284ce3539ef216e0ab994f4b7d762cfb1c69a.tar.bz2
llvm-47b284ce3539ef216e0ab994f4b7d762cfb1c69a.tar.xz
[Allocator] Pass the size to the deallocation function. This, on some
allocation libraries, may allow more efficient allocation and deallocation. It at least makes the interface implementable by the JIT memory manager. However, this highlights problematic overloading between the void* and the T* deallocation functions. I'm looking into a better way to do this, but as it happens, it comes up rarely in the codebase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206265 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/Allocator.h')
-rw-r--r--include/llvm/Support/Allocator.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h
index 617ab9fd7a..5565c1ccf1 100644
--- a/include/llvm/Support/Allocator.h
+++ b/include/llvm/Support/Allocator.h
@@ -63,16 +63,16 @@ public:
/// \brief Deallocate \a Ptr to \a Size bytes of memory allocated by this
/// allocator.
- void Deallocate(const void *Ptr) {
+ void Deallocate(const void *Ptr, size_t Size) {
#ifdef __clang__
- static_assert(static_cast<void (AllocatorBase::*)(const void *)>(
+ static_assert(static_cast<void (AllocatorBase::*)(const void *, size_t)>(
&AllocatorBase::Deallocate) !=
- static_cast<void (DerivedT::*)(const void *)>(
+ static_cast<void (DerivedT::*)(const void *, size_t)>(
&DerivedT::Deallocate),
"Class derives from AllocatorBase without implementing the "
"core Deallocate(void *) overload!");
#endif
- return static_cast<DerivedT *>(this)->Deallocate(Ptr);
+ return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size);
}
// The rest of these methods are helpers that redirect to one of the above
@@ -101,15 +101,15 @@ public:
typename std::enable_if<
!std::is_same<typename std::remove_cv<T>::type, void>::value, void>::type
Deallocate(T *Ptr) {
- Deallocate(static_cast<const void *>(Ptr));
+ Deallocate(static_cast<const void *>(Ptr), sizeof(T));
}
/// \brief Allocate space for an array of objects without constructing them.
template <typename T>
typename std::enable_if<
!std::is_same<typename std::remove_cv<T>::type, void>::value, void>::type
- Deallocate(T *Ptr, size_t /*Num*/) {
- Deallocate(static_cast<const void *>(Ptr));
+ Deallocate(T *Ptr, size_t Num) {
+ Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T));
}
};
@@ -125,7 +125,9 @@ public:
// Pull in base class overloads.
using AllocatorBase<MallocAllocator>::Allocate;
- void Deallocate(const void *Ptr) { free(const_cast<void *>(Ptr)); }
+ void Deallocate(const void *Ptr, size_t /*Size*/) {
+ free(const_cast<void *>(Ptr));
+ }
// Pull in base class overloads.
using AllocatorBase<MallocAllocator>::Deallocate;
@@ -143,7 +145,7 @@ class MallocSlabAllocator {
public:
void *Allocate(size_t Size) { return Allocator.Allocate(Size, 0); }
- void Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab); }
+ void Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab, Size); }
};
namespace detail {
@@ -260,7 +262,7 @@ public:
// Pull in base class overloads.
using AllocatorBase<BumpPtrAllocatorImpl>::Allocate;
- void Deallocate(const void * /*Ptr*/) {}
+ void Deallocate(const void * /*Ptr*/, size_t /*Size*/) {}
// Pull in base class overloads.
using AllocatorBase<BumpPtrAllocatorImpl>::Deallocate;