[llvm] r206267 - [Allocator] Finally, finish nuking the redundant code that led me here

Chandler Carruth chandlerc at gmail.com
Tue Apr 15 02:44:10 PDT 2014


Author: chandlerc
Date: Tue Apr 15 04:44:09 2014
New Revision: 206267

URL: http://llvm.org/viewvc/llvm-project?rev=206267&view=rev
Log:
[Allocator] Finally, finish nuking the redundant code that led me here
by removing the MallocSlabAllocator entirely and just using
MallocAllocator directly. This makes all off these allocators expose and
utilize the same core interface.

The only ugly part of this is that it exposes the fact that the JIT
allocator has no real handling of alignment, any more than the malloc
allocator does. =/ It would be nice to fix both of these to support
alignments, and then to leverage that in the BumpPtrAllocator to do less
over allocation in order to manually align pointers. But, that's another
patch for another day. This patch has no functional impact, it just
removes the somewhat meaningless wrapper around MallocAllocator.

Modified:
    llvm/trunk/include/llvm/Support/Allocator.h
    llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
    llvm/trunk/unittests/Support/AllocatorTest.cpp

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=206267&r1=206266&r2=206267&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Tue Apr 15 04:44:09 2014
@@ -135,19 +135,6 @@ public:
   void PrintStats() const {}
 };
 
-/// MallocSlabAllocator - The default slab allocator for the bump allocator
-/// is an adapter class for MallocAllocator that just forwards the method
-/// calls and translates the arguments.
-class MallocSlabAllocator {
-  /// Allocator - The underlying allocator that we forward to.
-  ///
-  MallocAllocator Allocator;
-
-public:
-  void *Allocate(size_t Size) { return Allocator.Allocate(Size, 0); }
-  void Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab, Size); }
-};
-
 namespace detail {
 
 // We call out to an external function to actually print the message as the
@@ -167,10 +154,10 @@ void printBumpPtrAllocatorStats(unsigned
 /// Note that this also has a threshold for forcing allocations above a certain
 /// size into their own slab.
 ///
-/// The BumpPtrAllocatorImpl template defaults to using a MallocSlabAllocator
+/// The BumpPtrAllocatorImpl template defaults to using a MallocAllocator
 /// object, which wraps malloc, to allocate memory, but it can be changed to
 /// use a custom allocator.
-template <typename AllocatorT = MallocSlabAllocator, size_t SlabSize = 4096,
+template <typename AllocatorT = MallocAllocator, size_t SlabSize = 4096,
           size_t SizeThreshold = SlabSize>
 class BumpPtrAllocatorImpl
     : public AllocatorBase<
@@ -241,7 +228,7 @@ public:
     // If Size is really big, allocate a separate slab for it.
     size_t PaddedSize = Size + Alignment - 1;
     if (PaddedSize > SizeThreshold) {
-      void *NewSlab = Allocator.Allocate(PaddedSize);
+      void *NewSlab = Allocator.Allocate(PaddedSize, 0);
       CustomSizedSlabs.push_back(std::make_pair(NewSlab, PaddedSize));
 
       Ptr = alignPtr((char *)NewSlab, Alignment);
@@ -319,7 +306,7 @@ private:
   void StartNewSlab() {
     size_t AllocatedSlabSize = computeSlabSize(Slabs.size());
 
-    void *NewSlab = Allocator.Allocate(AllocatedSlabSize);
+    void *NewSlab = Allocator.Allocate(AllocatedSlabSize, 0);
     Slabs.push_back(NewSlab);
     CurPtr = (char *)(NewSlab);
     End = ((char *)NewSlab) + AllocatedSlabSize;

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=206267&r1=206266&r2=206267&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Tue Apr 15 04:44:09 2014
@@ -269,11 +269,11 @@ namespace {
 
   class DefaultJITMemoryManager;
 
-  class JITSlabAllocator {
+  class JITAllocator {
     DefaultJITMemoryManager &JMM;
   public:
-    JITSlabAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
-    void *Allocate(size_t Size);
+    JITAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
+    void *Allocate(size_t Size, size_t /*Alignment*/);
     void Deallocate(void *Slab, size_t Size);
   };
 
@@ -312,9 +312,9 @@ namespace {
     // Memory slabs allocated by the JIT.  We refer to them as slabs so we don't
     // confuse them with the blocks of memory described above.
     std::vector<sys::MemoryBlock> CodeSlabs;
-    BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
+    BumpPtrAllocatorImpl<JITAllocator, DefaultSlabSize,
                          DefaultSizeThreshold> StubAllocator;
-    BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
+    BumpPtrAllocatorImpl<JITAllocator, DefaultSlabSize,
                          DefaultSizeThreshold> DataAllocator;
 
     // Circular list of free blocks.
@@ -568,12 +568,12 @@ namespace {
   };
 }
 
-void *JITSlabAllocator::Allocate(size_t Size) {
+void *JITAllocator::Allocate(size_t Size, size_t /*Alignment*/) {
   sys::MemoryBlock B = JMM.allocateNewSlab(Size);
   return B.base();
 }
 
-void JITSlabAllocator::Deallocate(void *Slab, size_t Size) {
+void JITAllocator::Deallocate(void *Slab, size_t Size) {
   sys::MemoryBlock B(Slab, Size);
   sys::Memory::ReleaseRWX(B);
 }

Modified: llvm/trunk/unittests/Support/AllocatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/AllocatorTest.cpp?rev=206267&r1=206266&r2=206267&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/AllocatorTest.cpp (original)
+++ llvm/trunk/unittests/Support/AllocatorTest.cpp Tue Apr 15 04:44:09 2014
@@ -108,7 +108,7 @@ class MockSlabAllocator {
 public:
   ~MockSlabAllocator() { }
 
-  void *Allocate(size_t Size) {
+  void *Allocate(size_t Size, size_t /*Alignment*/) {
     // Allocate space for the alignment, the slab, and a void* that goes right
     // before the slab.
     size_t Alignment = 4096;





More information about the llvm-commits mailing list