Ignore:
Timestamp:
Jan 13, 2018, 11:57:43 AM (14 months ago)
Author:
nmedfort
Message:

Pablo support for byte comparisions; LineFeed? kernel processes byte streams directly. Some clean up of PabloBuilder? functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r5710 r5828  
    1515    friend struct ExpressionTable;
    1616
    17     explicit FixedArgMap(Type * predecessor = nullptr) : mPredecessor(predecessor) { }
     17    explicit FixedArgMap(Type * predecessor = nullptr) noexcept
     18    : mPredecessor(predecessor) {
     19
     20    }
    1821
    1922    explicit FixedArgMap(Type && other) noexcept
     
    2326    }
    2427
    25     FixedArgMap & operator=(Type && other) {
     28    FixedArgMap & operator=(Type && other) noexcept {
    2629        mPredecessor = other.mPredecessor;
    2730        mMap = std::move(other.mMap);
     
    3033
    3134    template <class Functor, typename... Params>
    32     PabloAST * findOrCall(Functor && functor, const PabloAST::ClassTypeId type, Args... args, Params... params) {
    33         Key key = std::make_tuple(type, args...);
     35    PabloAST * findOrCall(Functor && functor, const PabloAST::ClassTypeId typeId, Args... args, Params... params) noexcept {
     36        Key key = std::make_tuple(typeId, args...);
    3437        PabloAST * const f = find(key);
    3538        if (f) {
     
    4144    }
    4245
    43     std::pair<PabloAST *, bool> findOrAdd(PabloAST * object, const PabloAST::ClassTypeId type, Args... args) {
    44         Key key = std::make_tuple(type, args...);
     46    std::pair<PabloAST *, bool> findOrAdd(PabloAST * object, const PabloAST::ClassTypeId typeId, Args... args) noexcept {
     47        Key key = std::make_tuple(typeId, args...);
    4548        PabloAST * const entry = find(key);
    4649        if (entry) {
     
    5154    }
    5255
    53     bool erase(const PabloAST::ClassTypeId type, Args... args) {
     56    bool erase(const PabloAST::ClassTypeId type, Args... args) noexcept {
    5457        Key key = std::make_tuple(type, args...);
    5558        for (Type * obj = this; obj; obj = obj->mPredecessor) {
     
    6366    }
    6467
    65     inline PabloAST * find(const PabloAST::ClassTypeId type, Args... args) const {
     68    inline PabloAST * find(const PabloAST::ClassTypeId type, Args... args) const noexcept {
    6669        return find(std::make_tuple(type, args...));
    6770    }
     
    9396};
    9497
    95 
    96 struct VarArgMap {
    97 
    98     friend struct ExpressionTable;
    99 
    100     using Allocator = SlabAllocator<const PabloAST *>;
    101 
    102     struct Key {
    103 
    104         inline Key(PabloAST::ClassTypeId type, const PabloAST * arg1, const std::vector<PabloAST *> & args, Allocator & allocator)
    105         : mType(type)
    106         , mArgs(1 + args.size())
    107         , mArg(allocator.allocate(mArgs)) {
    108             unsigned i = 1;
    109             mArg[0] = arg1;
    110             for (PabloAST * arg : args) {
    111                 mArg[i++] = arg;
    112             }
    113         }
    114 
    115         inline Key(PabloAST::ClassTypeId type, const Variadic * stmt, Allocator & allocator)
    116         : mType(type)
    117         , mArgs(stmt->getNumOperands())
    118         , mArg(allocator.allocate(mArgs)) {
    119             unsigned i = 0;
    120             for (PabloAST * arg : *stmt) {
    121                 mArg[i++] = arg;
    122             }
    123         }
    124 
    125         inline Key(const Key & key) = default;
    126 
    127         inline Key(Key && key) = default;
    128 
    129         inline bool operator < (const Key & other) const {
    130             if (mType != other.mType) {
    131                 return mType < other.mType;
    132             } else if (mArgs != other.mArgs) {
    133                 return mArgs < other.mArgs;
    134             }
    135             for (unsigned i = 0; i != mArgs; ++i) {
    136                 if (mArg[i] != other.mArg[i]) {
    137                     return mArg[i] < other.mArg[i];
    138                 }
    139             }
    140             return false;
    141         }
    142 
    143         const PabloAST::ClassTypeId   mType;
    144         const unsigned                mArgs;
    145         const PabloAST **             mArg;
    146     };
    147 
    148     using Map = std::map<Key, PabloAST *>;
    149 
    150     explicit VarArgMap(VarArgMap * predecessor = nullptr)
    151     : mPredecessor(predecessor) {
    152 
    153     }
    154 
    155     explicit VarArgMap(VarArgMap && other) noexcept
    156     : mPredecessor(other.mPredecessor)
    157     , mMap(std::move(other.mMap)) {
    158 
    159     }
    160 
    161     VarArgMap & operator=(VarArgMap && other) {
    162         mPredecessor = other.mPredecessor;
    163         mMap = std::move(other.mMap);
    164         return *this;
    165     }
    166 
    167     template <class Functor, typename... Params>
    168     PabloAST * findOrCall(Functor && functor, const PabloAST::ClassTypeId type, const PabloAST * arg1, const std::vector<PabloAST *> & args, Params... params) {
    169         Key key(type, arg1, args, mAllocator);
    170         PabloAST * const f = find(key);
    171         if (f) {
    172             mAllocator.deallocate(key.mArg);
    173             return f;
    174         }
    175         PabloAST * const object = functor(args, std::forward<Params>(params)...);
    176         mMap.insert(std::make_pair(std::move(key), object));
    177         return object;
    178     }
    179 
    180     std::pair<PabloAST *, bool> findOrAdd(Variadic * object, const PabloAST::ClassTypeId type) {
    181         Key key(type, object, mAllocator);
    182         PabloAST * const entry = find(key);
    183         if (entry) {
    184             mAllocator.deallocate(key.mArg);
    185             return std::make_pair(entry, false);
    186         }
    187         mMap.insert(std::make_pair(std::move(key), object));
    188         return std::make_pair(object, true);
    189     }
    190 
    191 private:
    192 
    193     PabloAST * find(const Key & key) const {
    194         // check this map to see if we have it
    195         auto itr = mMap.find(key);
    196         if (itr != mMap.end()) {
    197             return itr->second;
    198         } else { // check any previous maps to see if it exists
    199             auto * pred = mPredecessor;
    200             while (pred) {
    201                 itr = pred->mMap.find(key);
    202                 if (itr == pred->mMap.end()) {
    203                     pred = pred->mPredecessor;
    204                     continue;
    205                 }
    206                 return itr->second;
    207             }
    208         }
    209         return nullptr;
    210     }
    211 
    212 private:
    213     VarArgMap *     mPredecessor;
    214     Map             mMap;
    215     Allocator       mAllocator;
    216 };
    217 
    21898struct ExpressionTable {
    21999
     
    223103            mBinary.mPredecessor = &(predecessor->mBinary);
    224104            mTernary.mPredecessor = &(predecessor->mTernary);
    225             mVariadic.mPredecessor = &(predecessor->mVariadic);
    226105        }
    227106    }
     
    232111    : mUnary(std::move(other.mUnary))
    233112    , mBinary(std::move(other.mBinary))
    234     , mTernary(std::move(other.mTernary))
    235     , mVariadic(std::move(other.mVariadic)) {
     113    , mTernary(std::move(other.mTernary)) {
    236114
    237115    }
    238116
    239     ExpressionTable & operator=(ExpressionTable && other) {
     117    ExpressionTable & operator=(ExpressionTable && other) noexcept {
    240118        mUnary = std::move(other.mUnary);
    241119        mBinary = std::move(other.mBinary);
    242120        mTernary = std::move(other.mTernary);
    243         mVariadic = std::move(other.mVariadic);
    244121        return *this;
    245122    }
    246123
    247124    template <class Functor, typename... Params>
    248     inline PabloAST * findUnaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr, Params... params) {
    249         return mUnary.findOrCall(std::move(functor), type,  expr , std::forward<Params>(params)...);
     125    inline PabloAST * findUnaryOrCall(Functor && functor, const PabloAST::ClassTypeId typeId, void * expr, Params... params) noexcept {
     126        return mUnary.findOrCall(std::move(functor), typeId, expr, std::forward<Params>(params)...);
    250127    }
    251128
    252129    template <class Functor, typename... Params>
    253     inline PabloAST * findBinaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr1, PabloAST * expr2, Params... params) {
    254         return mBinary.findOrCall(std::move(functor), type, expr1, expr2, std::forward<Params>(params)...);
     130    inline PabloAST * findBinaryOrCall(Functor && functor, const PabloAST::ClassTypeId typeId, void * expr1, void * expr2, Params... params) noexcept {
     131        return mBinary.findOrCall(std::move(functor), typeId, expr1, expr2, std::forward<Params>(params)...);
    255132    }
    256133
    257134    template <class Functor, typename... Params>
    258     inline PabloAST * findTernaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr1, PabloAST * expr2, PabloAST * expr3, Params... params) {
    259         return mTernary.findOrCall(std::move(functor), type, expr1, expr2, expr3, std::forward<Params>(params)...);
     135    inline PabloAST * findTernaryOrCall(Functor && functor, const PabloAST::ClassTypeId typeId, void * expr1, void * expr2, void * expr3, Params... params) noexcept {
     136        return mTernary.findOrCall(std::move(functor), typeId, expr1, expr2, expr3, std::forward<Params>(params)...);
    260137    }
    261138
    262     template <class Functor, typename... Params>
    263     inline PabloAST * findVariadicOrCall(Functor && functor, const PabloAST::ClassTypeId type, const PabloAST * arg1, const std::vector<PabloAST *> & args, Params... params) {
    264         return mVariadic.findOrCall(std::move(functor), type, arg1, args, std::forward<Params>(params)...);
    265     }
    266 
    267     std::pair<PabloAST *, bool> findOrAdd(Statement * stmt) {
     139    std::pair<PabloAST *, bool> findOrAdd(Statement * stmt) noexcept {
    268140        switch (stmt->getClassTypeId()) {                     
    269141            case PabloAST::ClassTypeId::Var:
    270142            case PabloAST::ClassTypeId::Not:
    271             case PabloAST::ClassTypeId::Count:
     143            case PabloAST::ClassTypeId::Count:           
    272144                return mUnary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0));
    273145            case PabloAST::ClassTypeId::And:
    274146            case PabloAST::ClassTypeId::Or:
    275147            case PabloAST::ClassTypeId::Xor:
    276                 return mVariadic.findOrAdd(llvm::cast<Variadic>(stmt), stmt->getClassTypeId());
    277148            case PabloAST::ClassTypeId::Advance:
    278149            case PabloAST::ClassTypeId::ScanThru:
     
    280151            case PabloAST::ClassTypeId::Assign:
    281152            case PabloAST::ClassTypeId::Extract:
    282                 return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1));
     153            return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1));
     154            case PabloAST::ClassTypeId::Fill:
     155                return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getType());
    283156            case PabloAST::ClassTypeId::Sel:
    284157            case PabloAST::ClassTypeId::IndexedAdvance:
     
    289162    }
    290163
    291 
    292164private:
    293     FixedArgMap<PabloAST *>                             mUnary;
    294     FixedArgMap<PabloAST *, PabloAST *>                 mBinary;
    295     FixedArgMap<PabloAST *, PabloAST *, PabloAST *>     mTernary;
    296     VarArgMap                                           mVariadic;
     165    FixedArgMap<void *>                   mUnary;
     166    FixedArgMap<void *, void *>           mBinary;
     167    FixedArgMap<void *, void *, void *>   mTernary;
    297168};
    298169
Note: See TracChangeset for help on using the changeset viewer.