Changeset 4526


Ignore:
Timestamp:
Feb 27, 2015, 2:15:31 PM (4 years ago)
Author:
nmedfort
Message:

Slab allocator now uses a single BumpPtrAllocator?.

Location:
icGREP/icgrep-devel/icgrep
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4523 r4526  
    174174    try {
    175175        CompiledPabloFunction retVal = pablo_compiler.compile(main);
    176         RE::release_memory();
    177         PabloAST::release_memory();
    178        
     176        releaseSlabAllocatorMemory();
    179177        return retVal;
    180178    }
    181     catch (std::runtime_error e)
    182     {
     179    catch (std::runtime_error e) {
     180        releaseSlabAllocatorMemory();
    183181        std::cerr << "Runtime error: " << e.what() << std::endl;
    184182        exit(1);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4510 r4526  
    6363    }
    6464
    65     inline static void release_memory() {
    66         mAllocator.release_memory();
    67     }
    68 
    6965    inline user_iterator user_begin() {
    7066        return mUsers.begin();
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r4516 r4526  
    5858        return mClassTypeId;
    5959    }
    60     inline static void release_memory() {
    61         mVectorAllocator.release_memory();
    62         mAllocator.release_memory();
    63     }
    6460    typedef std::initializer_list<RE *> InitializerList;
    6561protected:
  • icGREP/icgrep-devel/icgrep/slab_allocator.h

    r4525 r4526  
    44#include <llvm/Support/Allocator.h>
    55
     6namespace {
     7
     8using LLVMAllocator = llvm::BumpPtrAllocator;
     9
     10class __BumpPtrAllocatorProxy {
     11public:
     12    template <typename T>
     13    static inline T * Allocate(const size_t n) {
     14        return mAllocator.Allocate<T>(n);
     15    }
     16    template <typename T>
     17    static inline void Deallocate(const T * pointer) {
     18        mAllocator.Deallocate(pointer);
     19    }
     20    static inline void Reset() {
     21        #ifndef NDEBUG
     22        mAllocator.PrintStats();
     23        #endif
     24        mAllocator.Reset();
     25    }
     26    static LLVMAllocator & get_allocator() {
     27        return mAllocator;
     28    }
     29private:
     30    static llvm::BumpPtrAllocator mAllocator;
     31};
     32
     33LLVMAllocator __BumpPtrAllocatorProxy::mAllocator;
     34
     35}
     36
    637template <typename T>
    738class SlabAllocator {
    839public:
    940
    10     using LLVMAllocator = llvm::BumpPtrAllocator;
    1141    using value_type = T;
    12     using pointer = T*;
    13     using const_pointer = const T*;
    14     using reference = T&;
    15     using const_reference = const T&;
     42    using pointer = value_type*;
     43    using const_pointer = const value_type*;
     44    using reference = value_type&;
     45    using const_reference = const value_type&;
    1646    using size_type = std::size_t;
    1747    using difference_type = std::ptrdiff_t;
     
    2353
    2454    inline pointer allocate(size_type n, const_pointer = nullptr) noexcept {
    25         return reinterpret_cast<pointer>(mAllocator.Allocate(n * sizeof(T), sizeof(T)));
     55        return mAllocator.Allocate<T>(n);
    2656    }
    2757
    2858    inline void deallocate(pointer p, size_type n) noexcept {
    29         mAllocator.Deallocate(p);
     59        mAllocator.Deallocate<T>(p);
    3060    }
    3161
     
    3464    }
    3565
    36     inline void release_memory() {
    37         mAllocator.Reset();
    38     }
    39 
    40     static inline LLVMAllocator & get_allocator() {
    41         return mAllocator;
     66    inline LLVMAllocator & get_allocator() {
     67        return mAllocator.get_allocator();
    4268    }
    4369
     
    4975    template <class U> inline SlabAllocator (const std::allocator<U>&) noexcept {}
    5076    inline ~SlabAllocator() { }
    51 
    5277private:
    53     static LLVMAllocator mAllocator;
     78    __BumpPtrAllocatorProxy mAllocator;
    5479};
    5580
    56 template <typename T>
    57 llvm::BumpPtrAllocator SlabAllocator<T>::mAllocator;
     81inline void releaseSlabAllocatorMemory() {
     82    __BumpPtrAllocatorProxy::Reset();
     83}
    5884
    5985#endif // SLAB_ALLOCATOR_H
Note: See TracChangeset for help on using the changeset viewer.