Ignore:
Timestamp:
Oct 5, 2014, 10:30:15 PM (5 years ago)
Author:
nmedfort
Message:

Removed string based CC lookup in CC Compiler.

File:
1 edited

Legend:

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

    r4214 r4215  
    3333CC_Compiler::CC_Compiler(CodeGenState & cg, const Encoding encoding, const std::string basis_pattern, const std::string gensym_pattern)
    3434: mCG(cg)
     35, mBasisBit(encoding.getBits())
    3536, mEncoding(encoding)
    3637, mGenSymPattern(gensym_pattern)
    3738, mBasisPattern(basis_pattern)
    3839{
    39     for (int i = 0; i < mEncoding.getBits(); i++)
    40     {
    41         Var * basisVar = getBasisVar(i);
    42         Expression* expr = new Expression();
    43         expr->expr_string  =  basisVar->getName();
    44         expr->pablo_expr = basisVar;
    45         mCommon_Expression_Map.insert(make_pair(basisVar->getName(), expr));
    46     }
     40    for (int i = 0; i < mEncoding.getBits(); i++) {
     41        mBasisBit[i] = mCG.createVar(mBasisPattern + std::to_string((mEncoding.getBits() - 1) - i));
     42        mCG.push_back(mBasisBit[i]);
     43    }
     44}
     45
     46inline Var * CC_Compiler::getBasisVar(const int i) const {
     47    return mBasisBit[i];
    4748}
    4849
     
    7576}
    7677
    77 Expression * CC_Compiler::add_assignment(std::string varname, Expression* expr)
    78 {   
    79     //Add the new mapping to the list of pablo statements:
    80     mCG.push_back(mCG.createAssign(varname, expr->pablo_expr));
    81 
    82     //Add the new mapping to the common expression map:
    83     std::string key_value = expr->expr_string;
    84     Expression* mapped_value = new Expression();
    85     mapped_value->expr_string = varname;
    86     mapped_value->pablo_expr = mCG.createVar(varname);
    87     return mCommon_Expression_Map.insert(std::make_pair(key_value, mapped_value)).first->second;
    88 }
    89 
    90 Expression * CC_Compiler::expr_to_variable(Expression * expr) {
    91     MapIterator itr = mCommon_Expression_Map.find(expr->expr_string);
    92     if (itr != mCommon_Expression_Map.end()) {
    93         return itr->second;
    94     }
    95     else {
    96         return add_assignment(mCG.ssa(mGenSymPattern), expr);
    97     }
    98 }
    99 
    10078void CC_Compiler::process_re(const RE * re) {
    10179    if (const Alt * alt = dyn_cast<const Alt>(re)) {
     
    11795}
    11896
    119 void CC_Compiler::process(const CC * cc)
    120 {
    121     add_assignment(cc->getName(), expr2pabloe(charset_expr(cc)));
    122 }
    123 
     97inline void CC_Compiler::process(const CC * cc) {
     98    if (mComputedSet.insert(cc->getName()).second) {
     99        //Add the new mapping to the list of pablo statements:
     100        mCG.push_back(mCG.createAssign(cc->getName(), charset_expr(cc)));
     101    }
     102}
    124103
    125104PabloE* CC_Compiler::bit_pattern_expr(int pattern, int selected_bits)
     
    309288}
    310289
    311 Expression* CC_Compiler::expr2pabloe(PabloE* expr) {
    312     /*
    313       Translate a Pablo Expression into three-address code using
    314       the code generator object CC_CodeGenObject.
    315     */
    316 
    317     Expression* retExpr = new Expression();
    318 
    319     if (All * all = dyn_cast<All>(expr))
    320     {
    321         if (all->getValue() == 1)
    322         {
    323             retExpr->expr_string = "All(1)";
    324         }
    325         else if (all->getValue() == 0)
    326         {
    327             retExpr->expr_string = "All(0)";
    328         }
    329     }
    330     else if (Var * var = dyn_cast<Var>(expr))
    331     {
    332             retExpr->expr_string = var->getName();
    333     }
    334     else if (Not * pe_not = dyn_cast<Not>(expr))
    335     {
    336         Expression* ret = expr_to_variable(expr2pabloe(pe_not->getExpr()));
    337         retExpr->expr_string =  "~" + ret->expr_string;
    338     }
    339     else if(Or * pe_or = dyn_cast<Or>(expr))
    340     {
    341         Expression* ret1 = expr_to_variable(expr2pabloe(pe_or->getExpr1()));
    342         Expression* ret2 = expr_to_variable(expr2pabloe(pe_or->getExpr2()));
    343         retExpr->expr_string = "(" + ret1->expr_string + "|" + ret2->expr_string + ")";
    344     }
    345     else if (Xor * pe_xor = dyn_cast<Xor>(expr))
    346     {
    347         Expression* ret1 = expr_to_variable(expr2pabloe(pe_xor->getExpr1()));
    348         Expression* ret2 = expr_to_variable(expr2pabloe(pe_xor->getExpr2()));
    349         retExpr->expr_string = "(" + ret1->expr_string + "^" + ret2->expr_string + ")";
    350     }
    351     else if (And * pe_and = dyn_cast<And>(expr))
    352     {
    353         if (Not * pe_not = dyn_cast<Not>(pe_and->getExpr1()))
    354         {
    355             Expression* ret1 = expr_to_variable(expr2pabloe(pe_not->getExpr()));
    356             Expression* ret2 = expr_to_variable(expr2pabloe(pe_and->getExpr2()));
    357             retExpr->expr_string = "(" + ret2->expr_string + "&~" + ret1->expr_string + ")";
    358         }
    359         else if (Not * pe_not = dyn_cast<Not>(pe_and->getExpr2()))
    360         {
    361             Expression* ret1 = expr_to_variable(expr2pabloe(pe_and->getExpr1()));
    362             Expression* ret2 = expr_to_variable(expr2pabloe(pe_not->getExpr()));
    363             retExpr->expr_string = "(" + ret1->expr_string  + "&~" + ret2->expr_string + ")";
    364         }
    365         else
    366         {
    367             Expression* ret1 = expr_to_variable(expr2pabloe(pe_and->getExpr1()));
    368             Expression* ret2 = expr_to_variable(expr2pabloe(pe_and->getExpr2()));
    369             retExpr->expr_string = "(" + ret1->expr_string + "&" + ret2->expr_string + ")";
    370         }
    371     }
    372     else if (Sel * pe_sel = dyn_cast<Sel>(expr))
    373     {
    374         Expression* ret_sel = expr_to_variable(expr2pabloe(pe_sel->getCondition()));
    375         Expression* ret_true = expr_to_variable(expr2pabloe(pe_sel->getTrueExpr()));
    376         Expression* ret_false = expr_to_variable(expr2pabloe(pe_sel->getFalseExpr()));
    377         retExpr->expr_string = "((" + ret_sel->expr_string + "&" + ret_true->expr_string + ")|(~("
    378             + ret_sel->expr_string + ")&" + ret_false->expr_string + ")";       
    379     }
    380     retExpr->pablo_expr = expr;
    381     return retExpr;
    382 }
    383 
    384 inline Var * CC_Compiler::getBasisVar(const int i) const {
    385     return mCG.createVar(mBasisPattern + std::to_string((mEncoding.getBits() - 1) - i));
    386 }
    387 
    388290} // end of namespace cc
Note: See TracChangeset for help on using the changeset viewer.