Changeset 4268


Ignore:
Timestamp:
Oct 24, 2014, 1:35:16 PM (4 years ago)
Author:
nmedfort
Message:

Generalized the writing of output variables by adding a 'flag' to the Assign nodes.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4253 r4268  
    100100    #ifdef DEBUG_PRINT_PBIX_AST
    101101    //Print to the terminal the AST that was generated by the character class compiler.
    102     std::cerr << "Pablo CC AST:" << std::endl << StatementPrinter::Print_CC_PabloStmts(main.expressions()) << std::endl;
     102    std::cerr << "Pablo CC AST:" << std::endl << StatementPrinter::Print_CC_PabloStmts(main.statements()) << std::endl;
    103103    #endif
    104104
     
    107107    #ifdef DEBUG_PRINT_PBIX_AST
    108108    //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    109     std::cerr << "Final Pablo AST:" << StatementPrinter::Print_CC_PabloStmts(main.expressions()) << ")" << std::endl;
     109    std::cerr << "Final Pablo AST:" << StatementPrinter::Print_CC_PabloStmts(main.statements()) << ")" << std::endl;
    110110    #endif
    111111
    112     PabloCompiler pablo_compiler(nameMap, cc_compiler.getBasisBitVars(), encoding.getBits());
     112    PabloCompiler pablo_compiler(cc_compiler.getBasisBitVars(), encoding.getBits());
    113113    unsigned long long cycles = 0;
    114114    double timer = 0;
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r4255 r4268  
    222222pablo/symbol_generator.h
    223223re/re_diff.h
     224pablo/analysis/useanalysis.cpp
     225pablo/analysis/useanalysis.h
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r4198 r4268  
    33cc
    44pablo
     5pablo/analysis
  • icGREP/icgrep-devel/icgrep/pablo/analysis/useanalysis.cpp

    r4266 r4268  
    55void UseAnalysis::optimize(PabloBlock & block) {
    66    UseAnalysis analyzer;
    7     analyzer.traverse(analyzer.mRoot, block.expressions());
     7    analyzer.traverse(analyzer.mRoot, block.statements());
    88
    99}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4266 r4268  
    7575    Call * createCall(const std::string name);
    7676
    77     inline Assign * createAssign(const std::string prefix, PabloAST * expr, const bool isOutput = false) {
     77    inline Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1) {
    7878        // TODO: should this test whether we've somehow created a var for this prior to
    7979        // making the assignment?
    80         Assign * assign = new Assign(mSymbolGenerator.get_ssa(prefix), expr, isOutput);
     80        Assign * assign = new Assign(mSymbolGenerator.get_ssa(prefix), expr, outputIndex);
    8181        mStatements.push_back(assign);
    8282        return assign;
     
    196196    };
    197197
    198     inline const StatementList & expressions() const {
     198    inline const StatementList & statements() const {
    199199        return mStatements;
    200200    }
     
    207207    ExpressionMap<PabloAST *, PabloAST *>               mBinary;
    208208    ExpressionMap<PabloAST *, PabloAST *, PabloAST *>   mTernary;
    209     StatementList                                      mStatements;
     209    StatementList                                       mStatements;
    210210};
    211211
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4267 r4268  
    7474namespace pablo {
    7575
    76 PabloCompiler::PabloCompiler(const cc::CC_NameMap & nameMap, const BasisBitVars & basisBitVars, int bits)
     76PabloCompiler::PabloCompiler(const BasisBitVars & basisBitVars, int bits)
    7777: mBits(bits)
    7878, mBasisBitVars(basisBitVars)
     
    9393, mBasisBitsAddr(nullptr)
    9494, mOutputAddrPtr(nullptr)
    95 , mNameMap(nameMap)
    9695{
    9796    //Create the jit execution engine.up
     
    149148{
    150149    mCarryQueueSize = 0;
    151     DeclareCallFunctions(pb.expressions());
     150    DeclareCallFunctions(pb.statements());
    152151    mCarryQueueVector.resize(mCarryQueueSize);
    153152
     
    176175
    177176    //Generate the IR instructions for the function.
    178     Value * result = compileStatements(pb.expressions());
    179     SetReturnMarker(result, 0); // matches
    180     const String * lf = mNameMap["LineFeed"]->getVar()->getName();
    181     SetReturnMarker(mMarkerMap.find(lf)->second, 1); // line feeds
     177    compileStatements(pb.statements());
    182178
    183179    assert (mCarryQueueIdx == mCarryQueueSize);
     
    485481}
    486482
    487 inline Value* PabloCompiler::GetMarker(const String * name) {
    488     auto itr = mMarkerMap.find(name);
    489     if (itr == mMarkerMap.end()) {
    490         IRBuilder<> b(mBasicBlock);
    491         itr = mMarkerMap.insert(std::make_pair(name, b.CreateAlloca(mXi64Vect))).first;
    492     }
    493     return itr->second;
    494 }
    495 
    496 void PabloCompiler::SetReturnMarker(Value * marker, const unsigned index) {
    497     IRBuilder<> b(mBasicBlock);
    498     if (marker->getType()->isPointerTy()) {
    499         marker = b.CreateAlignedLoad(marker, BLOCK_SIZE/8, false);
    500     }
    501     Value* indices[] = {b.getInt64(0), b.getInt32(index)};
    502     Value* gep = b.CreateGEP(mOutputAddrPtr, indices);
    503     b.CreateAlignedStore(marker, gep, BLOCK_SIZE/8, false);
    504 }
    505 
    506 
    507483Value * PabloCompiler::compileStatements(const StatementList & stmts) {
    508484    Value * retVal = nullptr;
     
    520496        Value* expr = compileExpression(assign->getExpr());
    521497        mMarkerMap[assign->getName()] = expr;
     498        if (unlikely(assign->isOutputAssignment())) {
     499            SetOutputValue(expr, assign->getOutputIndex());
     500        }
    522501        retVal = expr;
    523502    }
     
    611590        BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
    612591
    613         // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. Do not
    614         // assume it is the same one in which we entered the function with.
     592        // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. It
     593        // may not be same one that we entered the function with.
    615594        IRBuilder<> bEntry(mBasicBlock);
    616595        bEntry.CreateBr(whileCondBlock);
     
    897876}
    898877
    899 }
     878void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
     879    IRBuilder<> b(mBasicBlock);
     880    if (marker->getType()->isPointerTy()) {
     881        marker = b.CreateAlignedLoad(marker, BLOCK_SIZE/8, false);
     882    }
     883    Value* indices[] = {b.getInt64(0), b.getInt32(index)};
     884    Value* gep = b.CreateGEP(mOutputAddrPtr, indices);
     885    b.CreateAlignedStore(marker, gep, BLOCK_SIZE/8, false);
     886}
     887
     888}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4264 r4268  
    8989public:
    9090    typedef cc::CC_Compiler::BasisBitVars BasisBitVars;
    91     PabloCompiler(const cc::CC_NameMap & nameMap, const BasisBitVars & basisBitVars, int bits);
     91    PabloCompiler(const BasisBitVars & basisBitVars, int bits);
    9292    ~PabloCompiler();
    9393    LLVM_Gen_RetVal compile(PabloBlock & pb);
     
    9797    void DeclareCallFunctions(const StatementList & stmts);
    9898    void DeclareCallFunctions(const PabloAST * expr);
    99     void SetReturnMarker(Value * marker, const unsigned index);
    100 
    101     Value* GetMarker(const String *name);
     99    void SetOutputValue(Value * marker, const unsigned index);
    102100
    103101    Value* compileStatements(const StatementList & stmts);
     
    147145
    148146    StringToValueMap                    mCalleeMap;
    149 
    150     const cc::CC_NameMap &              mNameMap;
    151147};
    152148
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4264 r4268  
    4545    strOut += "],[";
    4646
    47     strOut += Print_PB_PabloStmts(cg_state.expressions());
     47    strOut += Print_PB_PabloStmts(cg_state.statements());
    4848
    4949    strOut = strOut.substr(0, strOut.length() - 1);
     
    7272{
    7373    if (const Assign * an = dyn_cast<const Assign>(stmt)) {
    74         return "Assign('" + an->getName()->str() + "', " + ShowPabloAST(an->getExpr()) + "),";
     74        std::string result = "Assign('" + an->getName()->str() + "', " + ShowPabloAST(an->getExpr());
     75        if (an->isOutputAssignment()) {
     76            result += ", Output=" + std::to_string(an->getOutputIndex());
     77        }
     78        return result + "),";
    7579    }
    7680    else if (const Next * next = dyn_cast<const Next>(stmt)) {
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4266 r4268  
    3030        return mExpr;
    3131    }
    32     inline bool isOutput() const {
    33         return mIsOutput;
     32    inline bool isOutputAssignment() const {
     33        return mOutputIndex >= 0;
     34    }
     35    inline int getOutputIndex() const {
     36        return mOutputIndex;
    3437    }
    3538protected:
    36     Assign(PabloAST * name, PabloAST * expr, const bool isOutput)
     39    Assign(PabloAST * name, PabloAST * expr, const int outputIndex)
    3740    : PabloAST(ClassTypeId::Assign)
    3841    , mName(cast<String>(name))
    3942    , mExpr(expr)
    40     , mIsOutput(isOutput)
     43    , mOutputIndex(outputIndex)
    4144    {
    4245
     
    4548    String * const          mName;
    4649    PabloAST * const        mExpr;
    47     const bool              mIsOutput;
     50    const int               mOutputIndex;
    4851};
    4952
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4267 r4268  
    7676
    7777    //These three lines are specifically for grep.
    78     pb.createAssign("matches", pb.createAnd(pb.createMatchStar(pb.createVar(result), pb.createNot(mLineFeed)), mLineFeed), true);
     78    pb.createAssign("matches", pb.createAnd(pb.createMatchStar(pb.createVar(result), pb.createNot(mLineFeed)), mLineFeed), 0);
     79    pb.createAssign("lf", mLineFeed, 1);
    7980}
    8081
Note: See TracChangeset for help on using the changeset viewer.