Ignore:
Timestamp:
Jan 7, 2015, 3:40:23 PM (4 years ago)
Author:
nmedfort
Message:

Changes to support 3-operand form for all instructions. CSE disabled but partially redundant now.

File:
1 edited

Legend:

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

    r4404 r4410  
    3333#include <array>
    3434#include <tuple>
     35#include <pablo/printer_pablos.h>
    3536
    3637namespace pablo {
     
    5859    }
    5960
    60     PabloAST * createCall(const std::string name);
     61    Call * createCall(const std::string name);
    6162
    6263    Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1)  {
     
    6465        // unique until we prove it has no Next node associated with it. But the Assign node must be created
    6566        // before the Next node. Should we create a "Constant" flag for this?
    66         Assign * assign = new Assign(mSymbolGenerator->get_ssa(prefix), expr, outputIndex, this);
     67        Assign * assign = new Assign(expr, outputIndex, mSymbolGenerator->make(prefix), this);
    6768        push_back(assign);
    6869        return assign;
    6970    }
    7071
    71     Var * createVar(const std::string name);
    72 
    73     Var * createVar(Assign * assign);
    74 
    75     Var * createVar(Next * next);
    76 
    77     inline PabloAST * createVar(PabloAST * const input) {
    78         switch (input->getClassTypeId()) {
    79             case PabloAST::ClassTypeId::Assign:
    80                 return createVar(cast<Assign>(input));
    81             case PabloAST::ClassTypeId::Next:
    82                 return createVar(cast<Next>(input));
    83             default:
    84                 return input;
    85         }
     72    Var * createVar(const std::string);
     73
     74    PabloAST * createVar(const PabloAST * const) {
     75        throw std::runtime_error("Var objects should only refer to external Vars (i.e., input basis bit streams). Use Assign object directly.");
    8676    }
    8777
     
    10191
    10292    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr);
     93
     94    And * createAndImm(PabloAST * expr1, PabloAST * expr2);
     95
     96    Not * createNotImm(PabloAST * expr);
     97
     98    Or * createOrImm(PabloAST * expr1, PabloAST * expr2);
     99
     100    Xor * createXorImm(PabloAST * expr1, PabloAST * expr2);
     101
     102    Sel * createSelImm(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr);
    103103
    104104    inline If * createIf(PabloAST * condition, std::vector<Assign *> && definedVars, PabloBlock & body) {
     
    120120        typedef std::tuple<PabloAST::ClassTypeId, Args...> Key;
    121121
    122         inline ExpressionMap(MapType * predecessor, PabloBlock * parent)
     122        inline ExpressionMap(MapType * predecessor)
    123123        : mPredecessor(predecessor)
    124         , mCurrentBlock(*parent)
    125124        {
    126125
     
    134133                return std::make_pair(cast<Type>(f), false);
    135134            }
    136             Type * const expr = new Type(std::forward<Args>(args)..., std::forward<Params>(params)...);
     135            PabloAST * const expr = new Type(std::forward<Args>(args)..., std::forward<Params>(params)...);
    137136            insert(std::move(key), expr);
    138             return std::make_pair(expr, true);
    139         }
    140 
     137            return std::make_pair(cast<Type>(expr), isa<Statement>(expr));
     138        }
    141139
    142140        template <class Functor, typename... Params>
    143         inline std::pair<PabloAST *, bool> findOrCall(const PabloAST::ClassTypeId type, Args... args, Params... params) {
     141        inline PabloAST * findOrCall(const PabloAST::ClassTypeId type, Args... args, Params... params) {
    144142            Key key = std::make_tuple(type, args...);
    145143            PabloAST * const f = find(key);
    146144            if (f) {
    147                 return std::make_pair(f, false);
    148             }
    149             Functor mf(mCurrentBlock);
     145                return f;
     146            }
     147            Functor mf;
    150148            PabloAST * const expr = mf(std::forward<Args>(args)..., std::forward<Params>(params)...);
    151149            insert(std::move(key), expr);
    152             return std::make_pair(expr, true);
     150            return expr;
    153151        }
    154152
     
    178176    private:
    179177        MapType * const             mPredecessor;
    180         PabloBlock &                mCurrentBlock;
    181178        std::map<Key, PabloAST *>   mMap;
    182179    };
     
    188185    inline const StatementList & statements() const {
    189186        return *this;
     187    }
     188    inline String * getName(const std::string name) const {
     189        return mSymbolGenerator->get(name);
     190    }
     191    inline String * makeName(const std::string prefix) const {
     192        return mSymbolGenerator->make(prefix);
    190193    }
    191194protected:
     
    194197    , mOnes(new Ones())
    195198    , mSymbolGenerator(new SymbolGenerator())
    196     , mUnary(nullptr, this)
    197     , mUnaryWithInt(nullptr, this)
    198     , mBinary(nullptr, this)
    199     , mTernary(nullptr, this)
     199    , mUnary(nullptr)
     200    , mUnaryWithInt(nullptr)
     201    , mBinary(nullptr)
     202    , mTernary(nullptr)
    200203    {
    201204
     
    206209    , mOnes(predecessor->mOnes) // inherit the original "Ones" variable for simplicity
    207210    , mSymbolGenerator(predecessor->mSymbolGenerator)
    208     , mUnary(&(predecessor->mUnary), this)
    209     , mUnaryWithInt(&(predecessor->mUnaryWithInt), this)
    210     , mBinary(&(predecessor->mBinary), this)
    211     , mTernary(&(predecessor->mTernary), this)
     211    , mUnary(&(predecessor->mUnary))
     212    , mUnaryWithInt(&(predecessor->mUnaryWithInt))
     213    , mBinary(&(predecessor->mBinary))
     214    , mTernary(&(predecessor->mTernary))
    212215    {
    213216
     
    217220        return PabloAST::mAllocator.allocate(size);
    218221    }
     222
     223    template<typename Type>
     224    inline Type appendIfNew(std::pair<Type, bool> retVal) {
     225        if (std::get<1>(retVal)) {
     226            push_back(cast<Statement>(std::get<0>(retVal)));
     227        }
     228        return std::get<0>(retVal);
     229    }
     230
    219231private:       
    220232    Zeroes * const                                      mZeroes;
Note: See TracChangeset for help on using the changeset viewer.