Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.cpp

    r5172 r5202  
    4343
    4444
    45 std::vector<Assign *> optimizer(std::string patt, std::vector<pablo::Var *> basisBits, std::vector<std::vector<Assign*>>  & e, int i, PabloAST * cond, PabloBuilder & pb, int dist, int stepSize){
     45void optimizer(const std::string & patt, PabloAST * basisBits[], std::vector<std::vector<PabloAST *>> & e, unsigned i, PabloAST * cond, PabloBuilder & main, PabloBuilder & pb, int dist, int stepSize){
    4646    PabloBuilder it = PabloBuilder::Create(pb);
    47     std::vector<Assign *> var_list;
     47
     48    Zeroes * zeroes = pb.createZeroes();
     49
    4850    for(int n = 0; n < stepSize; n++){
    49         // PabloAST * name = cast<Name>(seq->at(i))->getCompiled();
    50         int pi = (patt[i] >> 1) & 0x3;
    51         PabloAST * name = basisBits[pi];       
     51
     52        PabloAST * name = basisBits[(patt[i] >> 1) & 0x3];
    5253       
    53         e[i][0] = it.createAssign(make_e(i,0), it.createAnd(it.createAdvance(e[i-1][0],1), name));
    54         for(int j = 1; j <= dist; j++){ 
    55             auto tmp1 = it.createAssign("tmp1", it.createAnd(it.createAdvance(e[i-1][j],1), name));
    56             auto tmp2 = it.createAssign("tmp2", it.createAnd(it.createAdvance(e[i-1][j-1],1), it.createNot(name)));
    57             auto tmp3 = it.createAssign("tmp3", it.createOr(it.createAdvance(e[i][j-1],1), e[i-1][j-1]));
    58             e[i][j] = it.createAssign(make_e(i,j), it.createOr(it.createOr(tmp1,tmp2),tmp3));
     54        e[i][0] = it.createAnd(it.createAdvance(e[i - 1][0], 1), name, make_e(i, 0));
     55        for(int j = 1; j <= dist; j++){
     56            auto tmp1 = it.createAnd(it.createAdvance(e[i-1][j],1), name);
     57            auto tmp2 = it.createAnd(it.createAdvance(e[i-1][j-1],1), it.createNot(name));
     58            auto tmp3 = it.createOr(it.createAdvance(e[i][j-1],1), e[i-1][j-1]);
     59            e[i][j] = it.createOr(it.createOr(tmp1, tmp2), tmp3, make_e(i, j));
    5960        }
    6061       
    6162        i++;
    62         if(i >= patt.length()) break;
     63        if (i >= patt.length()) break;
    6364    }
    64     i--; 
    6565
    66     if(i < patt.length()-1){
    67         var_list = optimizer(patt, basisBits, e, i+1, e[i][dist], it, dist, stepSize);
     66    if (i < patt.length()) {
     67       optimizer(patt, basisBits, e, i, e[i - 1][dist], main, it, dist, stepSize);
     68    } else {
     69        const auto i = patt.length() - 1;
     70        for(int j = 0; j <= dist; j++){
     71            auto eij = main.createVar("m" + std::to_string(j), zeroes);
     72            it.createAssign(eij, e[i][j]);
     73            e[i][j] = eij;
     74        }
    6875    }
    6976
    70     for(int j = 0; j <= dist; j++){
    71         var_list.push_back(e[i][j]);
    72     }
    73 
    74     std::vector<Assign *> new_var_list = var_list;
    75     pb.createIf(cond, std::move(var_list), it);
    76     return new_var_list;
     77    pb.createIf(cond, it);
    7778}
    7879
    79 void Pattern_Compiler::compile(std::vector<std::string> patts, PabloBuilder & pb, std::vector<pablo::Var *> basisBits, int dist, int optPosition, int stepSize) {
    80     std::vector<std::vector<Assign*>> e(patts[0].length()*2, std::vector<Assign*>(dist+1));
    81     std::vector<PabloAST*> E(dist+1);
    82     int i = 0;
    83     int pi = 0;
     80void Pattern_Compiler::compile(const std::vector<std::string> & patts, PabloBuilder & pb, PabloAST * basisBits[], int dist, unsigned optPosition, int stepSize) {
     81    std::vector<std::vector<PabloAST *>> e(patts[0].length() * 2, std::vector<PabloAST *>(dist+1));
     82    std::vector<PabloAST*> E(dist + 1);
    8483
    8584    for(int d=0; d<=dist; d++){
     
    8786    }
    8887
    89     for(int r=0; r< patts.size(); r++){
    90         std::string patt = patts[r];
    91         pi = (patt[0] >> 1) & 0x3;
    92         PabloAST * name = basisBits[pi];
     88    for(unsigned r = 0; r < patts.size(); r++){
     89        const std::string & patt = patts[r];
    9390
    94         e[0][0] = pb.createAssign(make_e(0, 0), name);
     91        PabloAST * name = basisBits[(patt[0] >> 1) & 0x3];
     92
     93        e[0][0] = name;
    9594        for(int j = 1; j <= dist; j++){
    96           e[0][j] = pb.createAssign(make_e(0, j), pb.createOnes());
     95          e[0][j] = pb.createOnes();
    9796        }
    9897
    99         i++;
    100         while (i < patt.length()) {
    101             pi = (patt[i] >> 1) & 0x3;
    102             name = basisBits[pi];
     98        unsigned i = 1;
     99        while (i < patt.length() && i < optPosition) {
    103100
    104             e[i][0] = pb.createAssign(make_e(i,0), pb.createAnd(pb.createAdvance(e[i-1][0],1), name));
     101            name = basisBits[(patt[i] >> 1) & 0x3];
     102
     103            e[i][0] = pb.createAnd(pb.createAdvance(e[i-1][0], 1), name, make_e(i, 0));
    105104            for(int j = 1; j <= dist; j++){     
    106                 auto tmp1 = pb.createAssign("tmp1", pb.createAnd(pb.createAdvance(e[i-1][j],1), name));
    107                 auto tmp2 = pb.createAssign("tmp2", pb.createAnd(pb.createAdvance(e[i-1][j-1],1), pb.createNot(name)));
    108                 auto tmp3 = pb.createAssign("tmp3", pb.createOr(pb.createAdvance(e[i][j-1],1), e[i-1][j-1]));
    109                 e[i][j] = pb.createAssign(make_e(i,j), pb.createOr(pb.createOr(tmp1,tmp2),tmp3));
     105                auto tmp1 = pb.createAnd(pb.createAdvance(e[i-1][j],1), name);
     106                auto tmp2 = pb.createAnd(pb.createAdvance(e[i-1][j-1],1), pb.createNot(name));
     107                auto tmp3 = pb.createOr(pb.createAdvance(e[i][j-1],1), e[i-1][j-1]);
     108                e[i][j] = pb.createOr(pb.createOr(tmp1,tmp2),tmp3, make_e(i, j));
    110109            }
    111110           
    112111            i++;
    113             if(i >= optPosition) break;
    114112        }
    115113
    116114        //Optimize from optPosition
    117         if(i >= optPosition){
    118             optimizer(patt, basisBits, e, i, e[i-1][dist], pb, dist, stepSize);
     115        if (i >= optPosition) {
     116            optimizer(patt, basisBits, e, i, e[i-1][dist], pb, pb, dist, stepSize);
    119117        }
    120118
    121         E[0] = pb.createOr(E[0], e[patt.length()-1][0]);
     119        E[0] = pb.createOr(E[0], e[patt.length() - 1][0]);
    122120        for(int d=1; d<=dist; d++){
    123121            E[d] = pb.createOr(E[d], pb.createAnd(e[patt.length()-1][d], pb.createNot(e[patt.length()-1][d-1])));
    124122        }
    125123
    126         i = 0;
    127124    }
     125
     126    Var * output = mFunction.addResult("E", getStreamTy(1, dist + 1));
     127
    128128    for(int d=0; d<=dist; d++){
    129         mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
     129        pb.createAssign(pb.createExtract(output, d), E[d]);
     130        // mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
    130131    }
    131132}
Note: See TracChangeset for help on using the changeset viewer.