Changeset 4443 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jan 25, 2015, 4:11:26 PM (5 years ago)
Author:
nmedfort
Message:

Temporary check in.

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
1 added
7 edited

Legend:

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

    r4432 r4443  
    77namespace pablo {
    88
    9 class Builder {
     9class PabloBuilder {
    1010public:
    11     PabloAST * createAdvance(PabloAST * expr, const int shiftAmount);
     11
     12    inline static PabloBlock & Create() {
     13        return *(new PabloBlock());
     14    }
     15
     16    inline static PabloBlock & Create(PabloBlock & predecessor) {
     17        return *(new PabloBlock(&predecessor));
     18    }
     19
    1220
    1321    inline Zeroes * createZeroes() const {
     
    1725    inline Ones * createOnes() const {
    1826        return mPb->createOnes();
     27    }
     28
     29    Var * createVar(const std::string name) {
     30        return createVar(mPb->getName(name));
     31    }
     32
     33    Var * createVar(String * name);
     34
     35    PabloAST * createVar(const PabloAST * const) {
     36        throw std::runtime_error("Var objects should only refer to external Vars (i.e., input basis bit streams). Use Assign objects directly.");
    1937    }
    2038
     
    2745    Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1);
    2846
    29     Var * createVar(const std::string name) {
    30         return createVar(mPb->getName(name));
     47    inline PabloAST * createAdvance(PabloAST * expr, const int shiftAmount) {
     48        if (shiftAmount == 0) {
     49            return expr;
     50        }
     51        return createAdvance(expr, mPb->getInteger(shiftAmount));
    3152    }
    3253
    33     Var * createVar(String * name);
    34 
    35     PabloAST * createVar(const PabloAST * const) {
    36         throw std::runtime_error("Var objects should only refer to external Vars (i.e., input basis bit streams). Use Assign objects directly.");
    37     }
     54    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount);
    3855
    3956    Next * createNext(Assign * assign, PabloAST * expr);
     
    5370    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr);
    5471
    55     If * createIf(PabloAST * condition, std::vector<Assign *> && definedVars, PabloBlock & body);
     72    inline If * createIf(PabloAST * condition, std::vector<Assign *> && definedVars, PabloBlock & body) {
     73        mPb->createIf(condition, std::move(definedVars), body);
     74    }
    5675
    57     While * createWhile(PabloAST * cond, PabloBlock & body);
     76    inline While * createWhile(PabloAST * condition, PabloBlock & body) {
     77        mPb->createWhile(condition, body);
     78    }
    5879
    5980private:
    6081
    61     PabloBlock * mPb;
    62 
     82    PabloBlock *        mPb;
     83    ExpressionTable     mExprTable;
    6384};
    6485
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4438 r4443  
    4242        return expr;
    4343    }
    44     return insertAtInsertionPoint(new Advance(expr, mSymbolGenerator->getInteger(shiftAmount), makeName("advance"), this));
     44    return insertAtInsertionPoint(new Advance(expr, getInteger(shiftAmount), makeName("advance"), this));
    4545}
    4646
     
    4949        return renameNonNamedNode(expr, std::move(prefix));
    5050    }   
    51     return insertAtInsertionPoint(new Advance(expr, mSymbolGenerator->getInteger(shiftAmount), makeName(prefix, false), this));
     51    return insertAtInsertionPoint(new Advance(expr, getInteger(shiftAmount), makeName(prefix, false), this));
    5252}
    5353
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4438 r4443  
    162162    }
    163163
     164    inline Integer * getInteger(Integer::integer_t value) {
     165        return mSymbolGenerator->getInteger(value);
     166    }
     167
    164168    virtual ~PabloBlock();
    165169
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r4432 r4443  
    2020    }
    2121
    22     inline std::pair<PabloAST *, bool> insert(PabloAST * object, const PabloAST::ClassTypeId type, Args... args) {
     22    template <class Functor, typename... Params>
     23    inline PabloAST * findOrCall(Functor && functor, const PabloAST::ClassTypeId type, Args... args, Params... params) {
     24        Key key = std::make_tuple(type, args...);
     25        PabloAST * const f = find(key);
     26        if (f) {
     27            return f;
     28        }
     29        PabloAST * const object = functor(std::forward<Args>(args)..., std::forward<Params>(params)...);
     30        mMap.insert(std::make_pair(std::move(key), object));
     31        return object;
     32    }
     33
     34    inline std::pair<PabloAST *, bool> findOrAdd(PabloAST * object, const PabloAST::ClassTypeId type, Args... args) {
    2335        Key key = std::make_tuple(type, args...);
    2436        PabloAST * const entry = find(key);
     
    89101    }
    90102
    91     std::pair<PabloAST *, bool> insert(Statement * stmt) {
     103    template <class Functor, typename... Params>
     104    inline PabloAST * findUnaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr, Params... params) {
     105        return mUnary.findOrCall(std::move(functor), type, expr, std::forward<Params>(params)...);
     106    }
     107
     108    template <class Functor, typename... Params>
     109    inline PabloAST * findBinaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr1, PabloAST * expr2, Params... params) {
     110        return mBinary.findOrCall(std::move(functor), type, expr1, expr2, std::forward<Params>(params)...);
     111    }
     112
     113    template <class Functor, typename... Params>
     114    inline PabloAST * findTernaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr1, PabloAST * expr2, PabloAST * expr3, Params... params) {
     115        return mTernary.findOrCall(std::move(functor), type, expr1, expr2, expr3, std::forward<Params>(params)...);
     116    }
     117
     118    std::pair<PabloAST *, bool> findOrAdd(Statement * stmt) {
    92119        switch (stmt->getClassTypeId()) {           
    93120            case PabloAST::ClassTypeId::Assign:
     
    95122            case PabloAST::ClassTypeId::Var:
    96123            case PabloAST::ClassTypeId::Not:
    97                 return mUnary.insert(stmt, stmt->getClassTypeId(), stmt->getOperand(0));
     124                return mUnary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0));
    98125            case PabloAST::ClassTypeId::And:
    99126            case PabloAST::ClassTypeId::Or:
     
    107134            case PabloAST::ClassTypeId::MatchStar:
    108135            case PabloAST::ClassTypeId::Next:
    109                 return mBinary.insert(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1));
     136                return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1));
    110137            case PabloAST::ClassTypeId::Sel:
    111                 return mTernary.insert(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1), stmt->getOperand(2));
     138                return mTernary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1), stmt->getOperand(2));
    112139            default:
    113140                return std::make_pair(stmt, true);
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4434 r4443  
    113113            // as any having the same type and operands. If so, we can replace its users with the prior statement.
    114114            // and erase this statement from the AST
    115             const auto f = encountered.insert(stmt);
     115            const auto f = encountered.findOrAdd(stmt);
    116116            if (!std::get<1>(f)) {
    117117                stmt = stmt->replaceWith(std::get<0>(f));
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4433 r4443  
    8282void PabloAST::replaceAllUsesWith(PabloAST * expr) {
    8383    assert (expr);
    84     while (!mUsers.empty()) {
    85         PabloAST * user = mUsers.pop_back_val();
     84    Users Q;
     85    Q.swap(mUsers);
     86    for (PabloAST * user : Q) {
    8687        if (isa<Statement>(user)) {
    8788            cast<Statement>(user)->replaceUsesOfWith(this, expr);
    8889        }
    8990    }
     91    Q.clear();
    9092}
    9193
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4438 r4443  
    1010#include <llvm/Support/Casting.h>
    1111#include <llvm/Support/Compiler.h>
    12 #include <llvm/ADT/SetVector.h>
     12#include <boost/container/flat_set.hpp>
    1313#include <slab_allocator.h>
    1414#include <iterator>
     
    3131public:
    3232
    33     using Users = SetVector<PabloAST *>;
     33    using Users = boost::container::flat_set<PabloAST *>;
    3434    using user_iterator = Users::iterator;
     35    using const_user_iterator = Users::const_iterator;
    3536
    3637    typedef SlabAllocator<PabloAST *> Allocator;
     
    6465    }
    6566
    66     inline user_iterator user_begin() const {
     67    inline user_iterator user_begin() {
    6768        return mUsers.begin();
    6869    }
    6970
    70     inline user_iterator user_end() const {
     71    inline user_iterator user_end() {
    7172        return mUsers.end();
     73    }
     74
     75    inline const_user_iterator user_begin() const {
     76        return mUsers.cbegin();
     77    }
     78
     79    inline const_user_iterator user_end() const {
     80        return mUsers.cend();
    7281    }
    7382
     
    101110    inline void removeUser(PabloAST * user) {
    102111        assert (user);
    103         mUsers.remove(user);
     112        auto pos = mUsers.find(user);
     113        if (LLVM_UNLIKELY(pos == mUsers.end())) {
     114            return;
     115        }
     116        mUsers.erase(pos);
    104117    }
    105118    virtual ~PabloAST() {
Note: See TracChangeset for help on using the changeset viewer.