Ignore:
Timestamp:
Jul 16, 2015, 3:46:58 PM (4 years ago)
Author:
nmedfort
Message:

First attempt to add arguments to Call objects. Currently non-functioning in Pablo_Compiler.

File:
1 edited

Legend:

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

    r4646 r4681  
    22#define EXPRESSION_MAP_HPP
    33
     4#include <pablo/pabloAST.h>
     5#include <llvm/ADT/ArrayRef.h>
    46#include <map>
    5 #include <tuple>
    6 #include <pablo/pabloAST.h>
    77
    88namespace pablo {
    99
    1010template<typename... Args>
    11 struct ExpressionMap {
     11struct FixedArgMap {
    1212    enum {N = sizeof...(Args)};
    13     typedef ExpressionMap<Args...> Type;
     13    typedef FixedArgMap<Args...> Type;
    1414    typedef std::tuple<PabloAST::ClassTypeId, Args...> Key;
    1515    friend struct ExpressionTable;
    1616
    17     explicit ExpressionMap(Type * predecessor = nullptr) : mPredecessor(predecessor) { }
     17    explicit FixedArgMap(Type * predecessor = nullptr) : mPredecessor(predecessor) { }
    1818
    19     explicit ExpressionMap(Type && other) noexcept
     19    explicit FixedArgMap(Type && other) noexcept
    2020    : mPredecessor(other.mPredecessor)
    2121    , mMap(std::move(other.mMap)) {
     
    2323    }
    2424
    25     ExpressionMap & operator=(Type && other) {
     25    FixedArgMap & operator=(Type && other) {
    2626        mPredecessor = other.mPredecessor;
    2727        mMap = std::move(other.mMap);
     
    5353    inline bool erase(const PabloAST::ClassTypeId type, Args... args) {
    5454        Key key = std::make_tuple(type, args...);
    55         auto itr = mMap.find(key);
    56         if (itr == mMap.end()) {
    57             return mPredecessor ? mPredecessor->erase(type, args...) : false;
     55        for (Type * obj = this; obj; obj = obj->mPredecessor) {
     56            auto itr = obj->mMap.find(key);
     57            if (itr != mMap.end()) {
     58                obj->mMap.erase(itr);
     59                return true;
     60            }
    5861        }
    59         mMap.erase(itr);
    60         return true;
     62        return false;
    6163    }
    6264
    6365    inline PabloAST * find(const PabloAST::ClassTypeId type, Args... args) const {
    64         Key key = std::make_tuple(type, args...);
    65         return find(key);
     66        return find(std::make_tuple(type, args...));
    6667    }
    6768
     
    8889
    8990private:
    90     const Type *                mPredecessor;
     91    Type *                      mPredecessor;
    9192    std::map<Key, PabloAST *>   mMap;
    9293};
    9394
    94 
    9595struct ExpressionTable {
    9696
    97     explicit ExpressionTable(const ExpressionTable * predecessor = nullptr) noexcept {
     97    explicit ExpressionTable(ExpressionTable * predecessor = nullptr) noexcept {
    9898        if (predecessor) {
    9999            mUnary.mPredecessor = &(predecessor->mUnary);
    100100            mBinary.mPredecessor = &(predecessor->mBinary);
    101101            mTernary.mPredecessor = &(predecessor->mTernary);
     102            mUnaryVariable.mPredecessor = &(predecessor->mUnaryVariable);
    102103        }
    103104    }
     
    108109    : mUnary(std::move(other.mUnary))
    109110    , mBinary(std::move(other.mBinary))
    110     , mTernary(std::move(other.mTernary)) {
     111    , mTernary(std::move(other.mTernary))
     112    , mUnaryVariable(std::move(other.mUnaryVariable)) {
    111113
    112114    }
     
    116118        mBinary = std::move(other.mBinary);
    117119        mTernary = std::move(other.mTernary);
     120        mUnaryVariable = std::move(other.mUnaryVariable);
    118121        return *this;
    119122    }
     
    123126    inline PabloAST * findUnaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr, Params... params) {
    124127        return mUnary.findOrCall(std::move(functor), type, expr, std::forward<Params>(params)...);
     128    }
     129
     130    template <class Functor, typename... Params>
     131    inline PabloAST * findUnaryVariableOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr, const std::vector<PabloAST *> & args, Params... params) {
     132        return mUnaryVariable.findOrCall(std::move(functor), type, expr, args, std::forward<Params>(params)...);
    125133    }
    126134
     
    135143    }
    136144
     145
    137146    std::pair<PabloAST *, bool> findOrAdd(Statement * stmt) {
    138147        switch (stmt->getClassTypeId()) {           
    139             case PabloAST::ClassTypeId::Assign:
    140             case PabloAST::ClassTypeId::Call:
     148            case PabloAST::ClassTypeId::Assign:           
    141149            case PabloAST::ClassTypeId::Var:
    142150            case PabloAST::ClassTypeId::Not:
     
    156164            case PabloAST::ClassTypeId::Sel:
    157165                return mTernary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1), stmt->getOperand(2));
     166            case PabloAST::ClassTypeId::Call:
     167                // temporarily ignored
    158168            default:
    159169                return std::make_pair(stmt, true);
     
    163173
    164174private:
    165     ExpressionMap<PabloAST *>                           mUnary;
    166     ExpressionMap<PabloAST *, PabloAST *>               mBinary;
    167     ExpressionMap<PabloAST *, PabloAST *, PabloAST *>   mTernary;
     175    FixedArgMap<PabloAST *>                                     mUnary;
     176    FixedArgMap<PabloAST *, PabloAST *>                         mBinary;
     177    FixedArgMap<PabloAST *, PabloAST *, PabloAST *>             mTernary;
     178    FixedArgMap<PabloAST *, const std::vector<PabloAST *> &>    mUnaryVariable;
    168179};
    169180
Note: See TracChangeset for help on using the changeset viewer.