Ignore:
Timestamp:
Dec 19, 2016, 2:39:35 PM (3 years ago)
Author:
nmedfort
Message:

Multi-threading support for PabloAST / PabloCompiler?. Requires unique LLVM Context / Module for each thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5227 r5230  
    3838public:
    3939
    40     using Allocator = SlabAllocator<u_int8_t>;
    41     using VectorAllocator = SlabAllocator<PabloAST *>;
    42     using Users = std::vector<PabloAST *, VectorAllocator>;
     40    using Allocator = SlabAllocator<PabloAST *>;
     41    using Users = std::vector<PabloAST *, Allocator>;
    4342    using user_iterator = Users::iterator;
    4443    using const_user_iterator = Users::const_iterator;
     
    149148    }
    150149
    151     void * operator new (std::size_t size) noexcept {
    152         return mAllocator.allocate(size);
    153     }
    154 
    155     void operator delete (void * ptr) {
    156         mAllocator.deallocate(static_cast<Allocator::value_type *>(ptr));
    157     }
     150    void * operator new (std::size_t size, Allocator & allocator) noexcept {
     151        return allocator.allocate<uint8_t>(size);
     152    }
     153
     154//    void operator delete (void * ptr) {
     155//        mAllocator.deallocate(static_cast<Allocator::value_type *>(ptr));
     156//    }
    158157
    159158    void print(raw_ostream & O) const;
    160159
    161160protected:
    162     inline PabloAST(const ClassTypeId id, Type * const type, const String * name)
     161    inline PabloAST(const ClassTypeId id, Type * const type, const String * name, Allocator & allocator)
    163162    : mClassTypeId(id)
    164163    , mType(type)
    165164    , mName(name)
    166     , mUsers(mVectorAllocator)
    167     {
     165    , mUsers(allocator) {
    168166
    169167    }
     
    172170    virtual ~PabloAST() {
    173171        mUsers.clear();
    174     }   
    175     static Allocator        mAllocator;
    176     static VectorAllocator  mVectorAllocator;
     172    }       
    177173private:
    178174    const ClassTypeId       mClassTypeId;
     
    239235    virtual ~Statement() {}
    240236protected:
    241     explicit Statement(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name)
    242     : PabloAST(id, type, name)
     237    explicit Statement(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name, Allocator & allocator)
     238    : PabloAST(id, type, name, allocator)
    243239    , mNext(nullptr)
    244240    , mPrev(nullptr)
    245241    , mParent(nullptr)
    246242    , mOperands(operands.size())
    247     , mOperand(reinterpret_cast<PabloAST**>(mAllocator.allocate(mOperands * sizeof(PabloAST *)))) {
     243    , mOperand(allocator.allocate(mOperands)) {
    248244        unsigned i = 0;
    249245        for (PabloAST * const value : operands) {
     
    254250        }
    255251    }
    256     explicit Statement(const ClassTypeId id, Type * const type, const unsigned reserved, const String * const name)
    257     : PabloAST(id, type, name)
     252    explicit Statement(const ClassTypeId id, Type * const type, const unsigned reserved, const String * const name, Allocator & allocator)
     253    : PabloAST(id, type, name, allocator)
    258254    , mNext(nullptr)
    259255    , mPrev(nullptr)
    260256    , mParent(nullptr)
    261257    , mOperands(0)
    262     , mOperand(reinterpret_cast<PabloAST**>(mAllocator.allocate(reserved * sizeof(PabloAST *)))) {
     258    , mOperand(allocator.allocate(mOperands)) {
    263259        std::memset(mOperand, 0, reserved * sizeof(PabloAST *));
    264260    }
    265261    template<typename iterator>
    266     explicit Statement(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * const name)
    267     : PabloAST(id, type, name)
     262    explicit Statement(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * const name, Allocator & allocator)
     263    : PabloAST(id, type, name, allocator)
    268264    , mNext(nullptr)
    269265    , mPrev(nullptr)
    270266    , mParent(nullptr)
    271267    , mOperands(std::distance(begin, end))
    272     , mOperand(reinterpret_cast<PabloAST**>(mAllocator.allocate(mOperands * sizeof(PabloAST *)))) {
     268    , mOperand(allocator.allocate(mOperands)) {
    273269        unsigned i = 0;
    274270        for (auto value = begin; value != end; ++value, ++i) {
     
    348344
    349345protected:
    350     explicit Variadic(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name)
    351     : Statement(id, type, operands, name)
    352     , mCapacity(operands.size()) {
    353 
    354     }
    355     explicit Variadic(const ClassTypeId id, Type * const type, const unsigned reserved, const String * name)
    356     : Statement(id, type, reserved, name)
    357     , mCapacity(reserved) {
     346    explicit Variadic(const ClassTypeId id, Type * const type, std::initializer_list<PabloAST *> operands, const String * const name, Allocator & allocator)
     347    : Statement(id, type, operands, name, allocator)
     348    , mCapacity(operands.size())
     349    , mAllocator(allocator) {
     350
     351    }
     352    explicit Variadic(const ClassTypeId id, Type * const type, const unsigned reserved, const String * name, Allocator & allocator)
     353    : Statement(id, type, reserved, name, allocator)
     354    , mCapacity(reserved)
     355    , mAllocator(allocator) {
    358356
    359357    }
    360358    template<typename iterator>
    361     explicit Variadic(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * name)
    362     : Statement(id, type, begin, end, name)
    363     , mCapacity(std::distance(begin, end)) {
     359    explicit Variadic(const ClassTypeId id, Type * const type, iterator begin, iterator end, const String * name, Allocator & allocator)
     360    : Statement(id, type, begin, end, name, allocator)
     361    , mCapacity(std::distance(begin, end))
     362    , mAllocator(allocator) {
    364363
    365364    }
    366365private:
    367366    unsigned        mCapacity;
     367    Allocator &     mAllocator;
    368368};
    369369
Note: See TracChangeset for help on using the changeset viewer.