Changeset 4643


Ignore:
Timestamp:
Jul 6, 2015, 5:56:51 PM (4 years ago)
Author:
nmedfort
Message:

Simplified While structure. Next nodes are in the AST again but are treated like independent variable assignments; they're only associated with their original Assign by including them in the While instruction.

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

Legend:

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

    r4641 r4643  
    9494Next * PabloBlock::createNext(Assign * assign, PabloAST * expr) {
    9595    assert (assign && expr);
    96     assert (assign->getName());
    97     std::string name = assign->getName()->to_string() + "'";
    98     return new Next(assign, createAssign(std::move(name), expr), this);
     96    return insertAtInsertionPoint(new Next(assign, expr, this));
    9997}
    10098
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4641 r4643  
    415415}
    416416
    417 void PabloCompiler::compileBlock(PabloBlock & blk) {
    418     mPabloBlock = & blk;
    419     for (const Statement * statement : blk) {
     417void PabloCompiler::compileBlock(PabloBlock & block) {
     418    mPabloBlock = █
     419    for (const Statement * statement : block) {
    420420        compileStatement(statement);
    421421    }
    422     mPabloBlock = blk.getParent();
     422    mPabloBlock = block.getParent();
    423423}
    424424
     
    634634
    635635
    636 void PabloCompiler::compileStatement(const Statement * stmt)
    637 {
     636void PabloCompiler::compileStatement(const Statement * stmt) {
     637    Value * expr = nullptr;
    638638    if (const Assign * assign = dyn_cast<const Assign>(stmt)) {
    639         Value * expr = compileExpression(assign->getExpr());
     639        expr = compileExpression(assign->getExpr());
    640640        if (DumpTrace) {
    641641            genPrintRegister(assign->getName()->to_string(), expr);
    642642        }
    643         mMarkerMap[assign] = expr;
    644643        if (LLVM_UNLIKELY(assign->isOutputAssignment())) {
    645644            SetOutputValue(expr, assign->getOutputIndex());
     
    647646    }
    648647    else if (const Next * next = dyn_cast<const Next>(stmt)) {
    649         Value * expr = compileExpression(next->getExpr());
     648        expr = compileExpression(next->getExpr());
    650649        if (TraceNext) {
    651             genPrintRegister(next->getInitial()->getName()->to_string(), expr);
    652         }
    653         mMarkerMap[next->getInitial()] = expr;
    654     }
    655     else if (const If * ifStatement = dyn_cast<const If>(stmt))
    656     {
     650            genPrintRegister(next->getName()->to_string(), expr);
     651        }
     652    }
     653    else if (const If * ifStatement = dyn_cast<const If>(stmt)) {
    657654        compileIf(ifStatement);
    658     }
    659     else if (const While * whileStatement = dyn_cast<const While>(stmt))
    660     {
     655        return;
     656    }
     657    else if (const While * whileStatement = dyn_cast<const While>(stmt)) {
    661658        compileWhile(whileStatement);
     659        return;
    662660    }
    663661    else if (const Call* call = dyn_cast<Call>(stmt)) {
    664662        //Call the callee once and store the result in the marker map.
    665         auto mi = mMarkerMap.find(call);
    666         if (mi == mMarkerMap.end()) {
    667             auto ci = mCalleeMap.find(call->getCallee());
    668             if (LLVM_UNLIKELY(ci == mCalleeMap.end())) {
    669                 throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    670             }
    671             mi = mMarkerMap.insert(std::make_pair(call, mBuilder->CreateCall(ci->second, mBasisBitsAddr))).first;
    672         }
    673         // return mi->second;
     663        if (mMarkerMap.count(call) != 0) {
     664            return;
     665        }
     666        auto ci = mCalleeMap.find(call->getCallee());
     667        if (LLVM_UNLIKELY(ci == mCalleeMap.end())) {
     668            throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
     669        }
     670        expr = mBuilder->CreateCall(ci->second, mBasisBitsAddr);
    674671    }
    675672    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
    676         Value * expr = mBuilder->CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
     673        expr = mBuilder->CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
    677674        if (DumpTrace) {
    678675            genPrintRegister(stmt->getName()->to_string(), expr);
    679676        }
    680         mMarkerMap[pablo_and] = expr;
    681         // return expr;
    682677    }
    683678    else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
    684         Value * expr = mBuilder->CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
     679        expr = mBuilder->CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
    685680        if (DumpTrace) {
    686681            genPrintRegister(stmt->getName()->to_string(), expr);
    687682        }
    688         mMarkerMap[pablo_or] = expr;
    689         // return expr;
    690683    }
    691684    else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
    692         Value * expr = mBuilder->CreateXor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()), "xor");
    693         mMarkerMap[pablo_xor] = expr;
    694         // return expr;
     685        expr = mBuilder->CreateXor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()), "xor");
    695686    }
    696687    else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
     
    698689        Value* ifTrue = mBuilder->CreateAnd(ifMask, compileExpression(sel->getTrueExpr()));
    699690        Value* ifFalse = mBuilder->CreateAnd(genNot(ifMask), compileExpression(sel->getFalseExpr()));
    700         Value * expr = mBuilder->CreateOr(ifTrue, ifFalse);
     691        expr = mBuilder->CreateOr(ifTrue, ifFalse);
    701692        if (DumpTrace) {
    702693            genPrintRegister(stmt->getName()->to_string(), expr);
    703694        }
    704         mMarkerMap[sel] = expr;
    705         // return expr;
    706695    }
    707696    else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
    708         Value * expr = genNot(compileExpression(pablo_not->getExpr()));
     697        expr = genNot(compileExpression(pablo_not->getExpr()));
    709698        if (DumpTrace) {
    710699            genPrintRegister(stmt->getName()->to_string(), expr);
    711700        }
    712         mMarkerMap[pablo_not] = expr;
    713         // return expr;
    714701    }
    715702    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
    716         Value* strm_value = compileExpression(adv->getExpr());
     703        Value* value = compileExpression(adv->getExpr());
    717704        int shift = adv->getAdvanceAmount();
    718705        unsigned advance_index = adv->getLocalAdvanceIndex();
    719         Value * expr = genAdvanceWithCarry(strm_value, shift, advance_index);
     706        expr = genAdvanceWithCarry(value, shift, advance_index);
    720707        if (DumpTrace) {
    721708            genPrintRegister(stmt->getName()->to_string(), expr);
    722709        }
    723         mMarkerMap[adv] = expr;
    724         // return expr;
    725     }
    726     else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt))
    727     {
     710    }
     711    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
    728712        Value * marker = compileExpression(mstar->getMarker());
    729713        Value * cc = compileExpression(mstar->getCharClass());
    730714        Value * marker_and_cc = mBuilder->CreateAnd(marker, cc);
    731715        unsigned carry_index = mstar->getLocalCarryIndex();
    732         Value * expr = mBuilder->CreateOr(mBuilder->CreateXor(genAddWithCarry(marker_and_cc, cc, carry_index), cc), marker, "matchstar");
     716        expr = mBuilder->CreateOr(mBuilder->CreateXor(genAddWithCarry(marker_and_cc, cc, carry_index), cc), marker, "matchstar");
    733717        if (DumpTrace) {
    734718            genPrintRegister(stmt->getName()->to_string(), expr);
    735719        }
    736         mMarkerMap[mstar] = expr;
    737         // return expr;
    738     }
    739     else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt))
    740     {
     720    }
     721    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
    741722        Value * marker_expr = compileExpression(sthru->getScanFrom());
    742723        Value * cc_expr = compileExpression(sthru->getScanThru());
    743724        unsigned carry_index = sthru->getLocalCarryIndex();
    744         Value * expr = mBuilder->CreateAnd(genAddWithCarry(marker_expr, cc_expr, carry_index), genNot(cc_expr), "scanthru");
     725        expr = mBuilder->CreateAnd(genAddWithCarry(marker_expr, cc_expr, carry_index), genNot(cc_expr), "scanthru");
    745726        if (DumpTrace) {
    746727            genPrintRegister(stmt->getName()->to_string(), expr);
    747728        }
    748         mMarkerMap[sthru] = expr;
    749         // return expr;
    750729    }
    751730    else {
     
    754733        throw std::runtime_error("Unrecognized Pablo Statement! can't compile.");
    755734    }
     735    mMarkerMap[stmt] = expr;
    756736}
    757737
     
    763743        return mZeroInitializer;
    764744    }
    765     else if (const Next * next = dyn_cast<Next>(expr)) {
    766         expr = next->getInitial();
    767     }
    768745    auto f = mMarkerMap.find(expr);
    769     if (f == mMarkerMap.end()) {
     746    if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
    770747        std::string o;
    771748        llvm::raw_string_ostream str(o);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4640 r4643  
    108108
    109109    void genPrintRegister(std::string regName, Value * bitblockValue);
    110     void compileBlock(PabloBlock & blk);
     110    void compileBlock(PabloBlock & block);
    111111    void compileStatement(const Statement * stmt);
    112112    void compileIf(const If * ifStmt);
  • icGREP/icgrep-devel/icgrep/pablo/pe_next.h

    r4641 r4643  
    88
    99namespace pablo {
    10 
    11 class Assign;
    1210
    1311class Next : public Statement {
     
    2119    }
    2220    inline const Assign * getInitial() const {
    23         return cast<const Assign>(getOperand(0));
     21        return cast<const Assign>(getOperand(1));
    2422    }
    2523    inline PabloAST * getExpr() const {
    26         return getOperand(1);
     24        return getOperand(0);
    2725    }
    2826    virtual ~Next() {}
    2927protected:
    30     Next(PabloAST * initial, PabloAST * expr, PabloBlock * parent)
    31     : Statement(ClassTypeId::Next, {cast<Assign>(initial), cast<Assign>(expr)}, cast<Assign>(initial)->getName(), parent) {
     28    explicit Next(PabloAST * initial, PabloAST * expr, PabloBlock * parent)
     29    : Statement(ClassTypeId::Next, {expr, cast<Assign>(initial)}, cast<Assign>(initial)->getName(), parent) {
    3230        this->addUser(initial);
    3331    }
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4611 r4643  
    7575    }
    7676    else if (const Next * next = dyn_cast<const Next>(stmt)) {       
    77         strm << "Next(" << next->getName() << ") = ";
     77        strm << next->getName() << "' = ";
    7878        print(next->getExpr(), strm);
    7979    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4642 r4643  
    513513        mLoopVariants.push_back(nextPending);
    514514        mLoopVariants.push_back(nextStarAccum);
    515         mWhileTest = pb.createOr(mWhileTest, nextPending->getExpr());
     515        mWhileTest = pb.createOr(mWhileTest, nextPending);
    516516        mStarDepth--;
    517517       
    518         return makeMarker(InitialPostPositionByte, pb.createAssign("unbounded", pb.createOr(base, nextStarAccum->getExpr())));
     518        return makeMarker(InitialPostPositionByte, pb.createAssign("unbounded", pb.createOr(base, nextStarAccum)));
    519519    }   
    520520    else {
     
    530530        Next * nextWhilePending = wb.createNext(whilePending, wb.createAnd(loopComputation, wb.createNot(whileAccum)));
    531531        Next * nextWhileAccum = wb.createNext(whileAccum, wb.createOr(loopComputation, whileAccum));
    532         Next * nextWhileTest = wb.createNext(whileTest, wb.createOr(mWhileTest, nextWhilePending->getExpr()));
     532        Next * nextWhileTest = wb.createNext(whileTest, wb.createOr(mWhileTest, nextWhilePending));
    533533        mLoopVariants.push_back(nextWhilePending);
    534534        mLoopVariants.push_back(nextWhileAccum);
     
    537537        mStarDepth--;
    538538        mLoopVariants.clear();
    539         return makeMarker(InitialPostPositionByte, pb.createAssign("unbounded", nextWhileAccum->getExpr()));
     539        return makeMarker(InitialPostPositionByte, pb.createAssign("unbounded", nextWhileAccum));
    540540    }   
    541541} // end of namespace re
Note: See TracChangeset for help on using the changeset viewer.