Changeset 4681 for icGREP


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.

Location:
icGREP/icgrep-devel/icgrep
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4680 r4681  
    3535        Var * var = mBuilder.createVar(prefix + std::to_string(i));
    3636        function.setParameter(i, var);
    37         mBasisBit[encoding.getBits() - i - 1] = var;
     37        mBasisBit[i] = var;
    3838    }
    3939}
     
    269269
    270270inline Var * CC_Compiler::getBasisVar(const int i) const {
    271     return mBasisBit[i];
     271    return mBasisBit[mEncoding.getBits() - i - 1];
    272272}
    273273
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4657 r4681  
    4242
    4343    pablo::PabloBuilder & getBuilder();
     44
     45    const std::vector<pablo::Var *> & getBasisBits() {
     46        return mBasisBit;
     47    }
    4448
    4549private:
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4680 r4681  
    145145    }
    146146   
    147     RE_Compiler re_compiler(cc_compiler);
     147    RE_Compiler re_compiler(function, cc_compiler);
    148148    re_compiler.initializeRequiredStreams();
    149     re_compiler.finalizeMatchResult(function, re_compiler.compile(re_ast));
     149    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast));
    150150
    151151    if (PrintCompiledREcode) {
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r4680 r4681  
    2727PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    2828
     29#define MAKE_UNARY_VARIABLE(NAME, TYPE, ARGS...) \
     30struct __##NAME { \
     31    inline PabloAST * operator()(PabloAST * arg, const std::vector<PabloAST *> & args) { \
     32        return mPb->NAME(arg, args); \
     33    } \
     34    inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
     35private: \
     36    PabloBlock * mPb; \
     37}; \
     38__##NAME functor(mPb); \
     39PabloAST * result = mExprTable.findUnaryVariableOrCall(std::move(functor), TYPE, ARGS)
     40
     41
    2942#define MAKE_BINARY(NAME, TYPE, ARGS...) \
    3043struct __##NAME { \
     
    7588PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    7689
    77 
    78 Call * PabloBuilder::createCall(Prototype * prototype) {
    79     MAKE_UNARY(createCall, PabloAST::ClassTypeId::Call, prototype);
     90#define MAKE_VARIABLE(NAME, TYPE, ARGS) \
     91struct __##NAME { \
     92    inline PabloAST * operator()(PabloAST * arg) { \
     93        return mPb->NAME(arg); \
     94    } \
     95    inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
     96private: \
     97    PabloBlock * mPb; \
     98}; \
     99__##NAME functor(mPb); \
     100PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
     101
     102
     103Call * PabloBuilder::createCall(Prototype * prototype, const std::vector<Var *> & args) {
     104    if (args.size() != cast<Prototype>(prototype)->getNumOfParameters()) {
     105        throw std::runtime_error("Invalid number of arguments passed into Call object!");
     106    }
     107    MAKE_UNARY_VARIABLE(createCall, PabloAST::ClassTypeId::Call, prototype, reinterpret_cast<const std::vector<PabloAST *> &>(args));
    80108    return cast<Call>(result);
    81109}
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4680 r4681  
    5151    }
    5252
    53     Call * createCall(Prototype * prototype);
     53    Call * createCall(Prototype * prototype, const std::vector<Var *> & vars);
    5454
    5555    Assign * createAssign(const std::string && prefix, PabloAST * expr) {
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4680 r4681  
    7272}
    7373
    74 Call * PabloBlock::createCall(PabloAST * prototype) {
     74Call * PabloBlock::createCall(PabloAST * prototype, const std::vector<PabloAST *> & args) {
    7575    assert (prototype);
     76    if (prototype == nullptr) {
     77        throw std::runtime_error("Call object cannot be created with a Null prototype!");
     78    }
     79    if (args.size() != cast<Prototype>(prototype)->getNumOfParameters()) {
     80        throw std::runtime_error("Invalid number of arguments passed into Call object!");
     81    }
    7682    return insertAtInsertionPoint(new Call(prototype));
    7783}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4680 r4681  
    3030#include <pablo/ps_while.h>
    3131#include <pablo/function.h>
     32#include <llvm/ADT/ArrayRef.h>
    3233#include <stdexcept>
    3334
     
    7677    }
    7778
    78     inline Call * createCall(Prototype * prototype) {
    79         return createCall(prototype);
     79    inline Call * createCall(Prototype * prototype, const std::vector<Var *> & args) {
     80        return createCall(prototype, reinterpret_cast<const std::vector<PabloAST *> &>(args));
    8081    }
    8182
     
    186187private:
    187188
    188     Call * createCall(PabloAST * prototype);
     189    Call * createCall(PabloAST * prototype, const std::vector<PabloAST *> & args);
    189190
    190191    Var * createVar(PabloAST * name);
  • 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
  • icGREP/icgrep-devel/icgrep/pablo/pe_call.h

    r4680 r4681  
    1717    }
    1818    virtual ~Call() { }
     19
     20    inline const Prototype * getPrototype() const {
     21        return cast<Prototype>(getOperand(0));
     22    }
    1923    inline const String * getCallee() const {
    20         return cast<Prototype>(getOperand(0))->getName();
     24        return getPrototype()->getName();
    2125    }
    2226    inline void setLocalCarryIndex(const unsigned idx) {
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4657 r4681  
    9292        print(whl->getBody(), indent + "  ", strm);
    9393    }
    94     else if (const Call * pablo_call = dyn_cast<const Call>(stmt)) {
    95         print(pablo_call, strm);
    96         strm << " = " << pablo_call->getCallee() << "()";
     94    else if (const Call * call = dyn_cast<const Call>(stmt)) {
     95        strm << " = " << call->getCallee() << "()";
    9796    }
    9897    else if (const And * pablo_and = dyn_cast<const And>(stmt)) {
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4680 r4681  
    4949}
    5050
    51 RE_Compiler::RE_Compiler(cc::CC_Compiler & ccCompiler)
     51RE_Compiler::RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler)
    5252: mCCCompiler(ccCompiler)
    5353, mLineFeed(nullptr)
     
    6262, mPB(*ccCompiler.getBuilder().getPabloBlock(), ccCompiler.getBuilder())
    6363, mUCDCompiler(ccCompiler)
     64, mFunction(function)
    6465{
    6566
     
    175176}
    176177
    177 void RE_Compiler::finalizeMatchResult(PabloFunction & function, MarkerType match_result) {
     178void RE_Compiler::finalizeMatchResult(MarkerType match_result) {
    178179    //These three lines are specifically for grep.
    179180    PabloAST * lb = UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed;
    180181    PabloAST * v = markerVar(match_result);
    181     function.setResult(0, mPB.createAssign("matches", mPB.createAnd(mPB.createMatchStar(v, mPB.createNot(lb)), lb)));
    182     function.setResult(1, mPB.createAssign("lf", mPB.createAnd(lb, mPB.createNot(mCRLF))));
     182    mFunction.setResult(0, mPB.createAssign("matches", mPB.createAnd(mPB.createMatchStar(v, mPB.createNot(lb)), lb)));
     183    mFunction.setResult(1, mPB.createAssign("lf", mPB.createAnd(lb, mPB.createNot(mCRLF))));
    183184}
    184185
     
    275276    else if (name->getType() == Name::Type::UnicodeProperty) {
    276277        if (UsePregeneratedUnicode()) {
    277             var = pb.createCall(Prototype::Create(name->getFunctionName(), 8, 1, 0));
     278            var = pb.createCall(Prototype::Create(name->getFunctionName(), 8, 1, 0), mCCCompiler.getBasisBits());
    278279        }
    279280        else {
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4657 r4681  
    5959public:
    6060
    61     RE_Compiler(cc::CC_Compiler & ccCompiler);
     61    RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler);
    6262    void initializeRequiredStreams();
    63     void finalizeMatchResult(pablo::PabloFunction & function, MarkerType match_result);
     63    void finalizeMatchResult(MarkerType match_result);
    6464    MarkerType compile(RE * re) {
    6565        return compile(re, mPB);
     
    105105    pablo::PabloBuilder                             mPB;
    106106    UCD::UCDCompiler                                mUCDCompiler;
     107    pablo::PabloFunction &                          mFunction;
    107108};
    108109
Note: See TracChangeset for help on using the changeset viewer.