Changeset 4220


Ignore:
Timestamp:
Oct 7, 2014, 12:10:04 PM (4 years ago)
Author:
nmedfort
Message:

Some revisions to the LLVM_Generator; renamed it to PabloCompiler?.

Location:
icGREP/icgrep-devel/icgrep
Files:
2 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4212 r4220  
    5555add_library(PabloADT pablo/pe_advance.cpp pablo/pe_all.cpp pablo/pe_and.cpp pablo/pe_call.cpp pablo/pe_charclass.cpp  pablo/pe_matchstar.cpp pablo/pe_scanthru.cpp pablo/pe_not.cpp  pablo/pe_or.cpp  pablo/pe_pabloe.cpp  pablo/pe_sel.cpp  pablo/pe_var.cpp  pablo/pe_xor.cpp pablo/ps_assign.cpp  pablo/ps_if.cpp  pablo/codegenstate.cpp  pablo/symbol_generator.cpp pablo/ps_while.cpp pablo/printer_pablos.cpp)
    5656add_library(RegExpADT re/re_alt.cpp re/re_cc.cpp re/re_end.cpp re/re_name.cpp re/re_parser.cpp re/re_re.cpp re/re_rep.cpp re/re_seq.cpp re/re_start.cpp re/parsefailure.cpp re/re_reducer.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp)
    57 add_library(CCADT cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
     57add_library(CCADT cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h)
    5858
    5959include_directories("${PROJECT_SOURCE_DIR}")
     
    6666
    6767# add the executable
    68 add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp compiler.cpp)
     68add_executable(icgrep icgrep.cpp llvm_gen.cpp compiler.cpp)
    6969
    7070target_link_libraries (CCADT PabloADT)
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4217 r4220  
    3131namespace cc {
    3232
    33 CC_Compiler::CC_Compiler(CodeGenState & cg, const Encoding encoding, const std::string basis_pattern, const std::string gensym_pattern)
     33CC_Compiler::CC_Compiler(PabloBlock & cg, const Encoding encoding, const std::string basis_pattern, const std::string gensym_pattern)
    3434: mCG(cg)
    3535, mBasisBit(encoding.getBits())
     
    4040    for (int i = 0; i < mEncoding.getBits(); i++) {
    4141        mBasisBit[i] = mCG.createVar(mBasisPattern + std::to_string((mEncoding.getBits() - 1) - i));
    42         mCG.push_back(mBasisBit[i]);
    4342    }
    4443}
     
    6564                    if (++j != seq->end()) {
    6665                        marker = mCG.createAdvance(sym);
    67                         mCG.push_back(marker);
    6866                        continue;
    6967                    }
    70                     mCG.push_back(mCG.createAssign(seq->getName(), sym));
     68                    mCG.createAssign(seq->getName(), sym);
    7169                    break;
    7270                }
     
    9896    if (mComputedSet.insert(cc->getName()).second) {
    9997        //Add the new mapping to the list of pablo statements:
    100         mCG.push_back(mCG.createAssign(cc->getName(), charset_expr(cc)));
    101     }
    102 }
    103 
    104 PabloE * CC_Compiler::bit_pattern_expr(int pattern, int selected_bits)
     98        mCG.createAssign(cc->getName(), charset_expr(cc));
     99    }
     100}
     101
     102PabloE * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits)
    105103{
    106104    if (selected_bits == 0) {
     
    180178}
    181179
    182 PabloE * CC_Compiler::GE_Range(int N, int n) {
     180PabloE * CC_Compiler::GE_Range(const unsigned N, const unsigned n) {
    183181    if (N == 0)
    184182    {
     
    195193    else if (N >= 1)
    196194    {
    197         int hi_bit = n & (1 << (N-1));
     195        int hi_bit = n & (1 << (N - 1));
    198196        int lo_bits = n - hi_bit;
    199         PabloE* lo_range = GE_Range(N-1, lo_bits);
     197        PabloE * lo_range = GE_Range(N - 1, lo_bits);
    200198        if (hi_bit == 0)
    201199        {
     
    219217}
    220218
    221 PabloE * CC_Compiler::LE_Range(int N, int n)
     219PabloE * CC_Compiler::LE_Range(const unsigned N, const unsigned n)
    222220{
    223221    /*
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4215 r4220  
    2222public:
    2323
    24     CC_Compiler(pablo::CodeGenState & cg, const Encoding encoding, const std::string basis_pattern = "basis", const std::string gensym_pattern = "temp");
     24    CC_Compiler(pablo::PabloBlock & cg, const Encoding encoding, const std::string basis_pattern = "basis", const std::string gensym_pattern = "temp");
    2525
    2626    void compile(const REMap & re_map);
     
    3333    void process_re(const re::RE *re);
    3434    pablo::Var * getBasisVar(const int n) const;
    35     pablo::PabloE * bit_pattern_expr(int pattern, int selected_bits);
     35    pablo::PabloE * bit_pattern_expr(const unsigned pattern, unsigned selected_bits);
    3636    pablo::PabloE * char_test_expr(const re::CodePointType ch);
    3737    pablo::PabloE * make_range(const re::CodePointType n1, const re::CodePointType n2);
    38     pablo::PabloE * GE_Range(int N, int n);
    39     pablo::PabloE * LE_Range(int N, int n);
     38    pablo::PabloE * GE_Range(const unsigned N, const unsigned n);
     39    pablo::PabloE * LE_Range(const unsigned N, const unsigned n);
    4040    pablo::PabloE * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi);
    4141    pablo::PabloE * charset_expr(const re::CC *cc);
    4242    void process(const re::CC *cc);
    4343
    44     pablo::CodeGenState &       mCG;
     44    pablo::PabloBlock &         mCG;
    4545    std::vector<pablo::Var *>   mBasisBit;
    4646    const Encoding              mEncoding;
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4210 r4220  
    126126
    127127    SymbolGenerator symgen;
    128     CodeGenState cg(symgen);
     128    PabloBlock main(symgen);
    129129
    130     CC_Compiler cc_compiler(cg, encoding);
     130    CC_Compiler cc_compiler(main, encoding);
    131131    cc_compiler.compile(re_map);
    132132    #ifdef DEBUG_PRINT_PBIX_AST
     
    137137    #endif
    138138
    139     RE_Compiler pbix_compiler(cg, name_map);
     139    RE_Compiler pbix_compiler(main, name_map);
    140140    pbix_compiler.compile(re_ast);
    141141    #ifdef DEBUG_PRINT_PBIX_AST
     
    146146    #endif
    147147
    148     LLVM_Generator irgen(name_map, cc_compiler.getBasisPattern(), encoding.getBits());
     148    PabloCompiler irgen(name_map, cc_compiler.getBasisPattern(), encoding.getBits());
    149149    unsigned long long cycles = 0;
    150150    double timer = 0;
     
    155155    }
    156156
    157     LLVM_Gen_RetVal retVal = irgen.Generate_LLVMIR(cg);
     157    LLVM_Gen_RetVal retVal = irgen.compile(main);
    158158    if (show_compile_time)
    159159    {
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r4215 r4220  
    2323llvm_gen.cpp
    2424llvm_gen.h
    25 llvm_gen_helper.cpp
    26 llvm_gen_helper.h
    2725parsefailure.cpp
    2826parsefailure.h
     
    186184pablo/printer_pablos.cpp
    187185pablo/printer_pablos.h
     186CMakeLists.txt
  • icGREP/icgrep-devel/icgrep/llvm_gen.cpp

    r4218 r4220  
    6161#undef CREATE_GENERAL_CODE_CATEGORY
    6262
    63 LLVM_Generator::LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits)
     63PabloCompiler::PabloCompiler(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits)
    6464: m_name_map(name_map)
    65 , mCalleeMap(nullptr)
    6665, mBasisBitPattern(basis_pattern)
    6766, mBits(bits)
     
    7069}
    7170
    72 LLVM_Generator::~LLVM_Generator()
     71PabloCompiler::~PabloCompiler()
    7372{
    7473    delete mMod;
     
    106105}
    107106
    108 LLVM_Gen_RetVal LLVM_Generator::Generate_LLVMIR(const CodeGenState & cg_state)
     107LLVM_Gen_RetVal PabloCompiler::compile(const PabloBlock & cg_state)
    109108{
    110109    //Create the module.
     
    139138    //Create the carry queue.
    140139    mCarryQueueIdx = 0;
    141     mCarryQueueSize += LLVM_Generator_Helper::CarryCount_PabloStatements(cg_state.expressions());
    142140    mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunc_process_block,0);
    143141
     
    157155
    158156    //Generate the IR instructions for the function.
    159     SetReturnMarker(Generate_PabloStatements(cg_state.expressions()), 0);
     157    SetReturnMarker(compileStatements(cg_state.expressions()), 0);
    160158    SetReturnMarker(GetMarker(m_name_map.find("LineFeed")->second), 1);
     159
     160    mCarryQueueSize = mCarryQueueIdx;
    161161
    162162    //Terminate the block
    163163    ReturnInst::Create(mMod->getContext(), mBasicBlock);
    164164
    165     #ifndef NDEBUG
    166165    //Create a verifier.  The verifier will print an error message if our module is malformed in any way.
    167166    #ifdef USE_LLVM_3_5
     
    171170    verifyModule(*mMod, PrintMessageAction);
    172171    #endif
    173     #endif
    174172
    175173    //Un-comment this line in order to display the IR that has been generated by this module.
     
    192190
    193191    fpm.add(createPromoteMemoryToRegisterPass()); //Transform to SSA form.
    194 
    195192    fpm.add(createBasicAliasAnalysisPass());      //Provide basic AliasAnalysis support for GVN. (Global Value Numbering)
    196193    fpm.add(createCFGSimplificationPass());       //Simplify the control flow graph.
     
    216213}
    217214
    218 void LLVM_Generator::DefineTypes()
     215void PabloCompiler::DefineTypes()
    219216{
    220217    //The BitBlock vector.
     
    279276}
    280277
    281 void LLVM_Generator::DeclareFunctions()
     278void PabloCompiler::DeclareFunctions()
    282279{
    283280    //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
     
    368365}
    369366
    370 void LLVM_Generator::DeclareCallFunctions(const ExpressionList & stmts) {
     367void PabloCompiler::DeclareCallFunctions(const ExpressionList & stmts) {
    371368    for (const PabloE * stmt : stmts) {
    372369        if (const Assign * an = dyn_cast<const Assign>(stmt)) {
     
    374371        }
    375372        else if (const If * ifstmt = dyn_cast<const If>(stmt)) {
    376             DeclareCallFunctions(ifstmt->getExpr());
    377             DeclareCallFunctions(ifstmt->getPSList());
     373            DeclareCallFunctions(ifstmt->getCondition());
     374            DeclareCallFunctions(ifstmt->getBody());
    378375        }
    379376        else if (const While * whl = dyn_cast<const While>(stmt)) {
    380377            DeclareCallFunctions(whl->getCondition());
    381             DeclareCallFunctions(whl->getPSList());
    382         }
    383     }
    384 }
    385 
    386 void LLVM_Generator::DeclareCallFunctions(const PabloE * expr)
     378            DeclareCallFunctions(whl->getBody());
     379        }
     380    }
     381}
     382
     383void PabloCompiler::DeclareCallFunctions(const PabloE * expr)
    387384{
    388385    if (const Call * pablo_call = dyn_cast<const Call>(expr))
    389386    {
    390         std::string callee = "__get_category_" + pablo_call->getCallee();
    391         if (mMarkerMap.find(callee) == mMarkerMap.end())
     387        const std::string callee = pablo_call->getCallee();
     388        if (mCalleeMap.find(callee) == mCalleeMap.end())
    392389        {
    393             if (mCalleeMap == nullptr) {
    394                 mCalleeMap = new CalleeMapType();
    395                 #define ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(SUFFIX) \
    396                     mCalleeMap->insert(std::make_pair(#SUFFIX, (void *)&__get_category_##SUFFIX));
    397                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Cc)
    398                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Cf)
    399                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Cn)
    400                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Co)
    401                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Cs)
    402                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Ll)
    403                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Lm)
    404                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Lo)
    405                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Lt)
    406                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Lu)
    407                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Mc)
    408                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Me)
    409                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Mn)
    410                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Nd)
    411                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Nl)
    412                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(No)
    413                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Pc)
    414                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Pd)
    415                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Pe)
    416                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Pf)
    417                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Pi)
    418                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Po)
    419                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Ps)
    420                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Sc)
    421                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Sk)
    422                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Sm)
    423                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(So)
    424                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Zl)
    425                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Zp)
    426                 ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP(Zs)
    427                 #undef ADD_GENERAL_CODE_CATEGORY_CALL_TO_MAP
     390            void * callee_ptr = nullptr;
     391            #define CHECK_GENERAL_CODE_CATEGORY(SUFFIX) \
     392                if (callee == #SUFFIX) { \
     393                    callee_ptr = (void*)&__get_category_##SUFFIX; \
     394                } else
     395            CHECK_GENERAL_CODE_CATEGORY(Cc)
     396            CHECK_GENERAL_CODE_CATEGORY(Cf)
     397            CHECK_GENERAL_CODE_CATEGORY(Cn)
     398            CHECK_GENERAL_CODE_CATEGORY(Co)
     399            CHECK_GENERAL_CODE_CATEGORY(Cs)
     400            CHECK_GENERAL_CODE_CATEGORY(Ll)
     401            CHECK_GENERAL_CODE_CATEGORY(Lm)
     402            CHECK_GENERAL_CODE_CATEGORY(Lo)
     403            CHECK_GENERAL_CODE_CATEGORY(Lt)
     404            CHECK_GENERAL_CODE_CATEGORY(Lu)
     405            CHECK_GENERAL_CODE_CATEGORY(Mc)
     406            CHECK_GENERAL_CODE_CATEGORY(Me)
     407            CHECK_GENERAL_CODE_CATEGORY(Mn)
     408            CHECK_GENERAL_CODE_CATEGORY(Nd)
     409            CHECK_GENERAL_CODE_CATEGORY(Nl)
     410            CHECK_GENERAL_CODE_CATEGORY(No)
     411            CHECK_GENERAL_CODE_CATEGORY(Pc)
     412            CHECK_GENERAL_CODE_CATEGORY(Pd)
     413            CHECK_GENERAL_CODE_CATEGORY(Pe)
     414            CHECK_GENERAL_CODE_CATEGORY(Pf)
     415            CHECK_GENERAL_CODE_CATEGORY(Pi)
     416            CHECK_GENERAL_CODE_CATEGORY(Po)
     417            CHECK_GENERAL_CODE_CATEGORY(Ps)
     418            CHECK_GENERAL_CODE_CATEGORY(Sc)
     419            CHECK_GENERAL_CODE_CATEGORY(Sk)
     420            CHECK_GENERAL_CODE_CATEGORY(Sm)
     421            CHECK_GENERAL_CODE_CATEGORY(So)
     422            CHECK_GENERAL_CODE_CATEGORY(Zl)
     423            CHECK_GENERAL_CODE_CATEGORY(Zp)
     424            CHECK_GENERAL_CODE_CATEGORY(Zs) {};
     425            #undef CHECK_GENERAL_CODE_CATEGORY
     426            if (callee_ptr == nullptr) {
     427                throw std::runtime_error("Unknown unicode category \"" + callee + "\"");
    428428            }
    429             Value* func_get_unicode_category = mMod->getOrInsertFunction(callee, mXi64Vect, mBasisBitsInputPtr, NULL);
    430             void * addr = mCalleeMap->find(pablo_call->getCallee())->second;
    431             if (addr == nullptr) {
    432                 throw std::runtime_error("Unknown Unicode Category \"" + callee + "\"");
     429            Value * get_unicode_category = mMod->getOrInsertFunction("__get_category_" + callee, mXi64Vect, mBasisBitsInputPtr, NULL);
     430            if (get_unicode_category == nullptr) {
     431                throw std::runtime_error("Could not create static method call for unicode category \"" + callee + "\"");
    433432            }
    434             mExecutionEngine->addGlobalMapping(cast<GlobalValue>(func_get_unicode_category), addr);
    435             mMarkerMap.insert(make_pair(callee, func_get_unicode_category));
     433            mExecutionEngine->addGlobalMapping(cast<GlobalValue>(get_unicode_category), callee_ptr);
     434            mCalleeMap.insert(std::make_pair(callee, get_unicode_category));
    436435        }
    437436    }
     
    458457    else if (const Advance * adv = dyn_cast<const Advance>(expr))
    459458    {
     459        ++mCarryQueueSize;
    460460        DeclareCallFunctions(adv->getExpr());
    461461    }
    462462    else if (const MatchStar * mstar = dyn_cast<const MatchStar>(expr))
    463463    {
     464        ++mCarryQueueSize;
    464465        DeclareCallFunctions(mstar->getExpr1());
    465466        DeclareCallFunctions(mstar->getExpr2());
     
    467468    else if (const ScanThru * sthru = dyn_cast<const ScanThru>(expr))
    468469    {
     470        ++mCarryQueueSize;
    469471        DeclareCallFunctions(sthru->getScanFrom());
    470472        DeclareCallFunctions(sthru->getScanThru());
     
    472474}
    473475
    474 void LLVM_Generator::MakeLLVMModule()
     476void PabloCompiler::MakeLLVMModule()
    475477{
    476478    mMod = new Module("icgrep", getGlobalContext());
     
    478480}
    479481
    480 Value* LLVM_Generator::GetMarker(const std::string & name)
     482Value* PabloCompiler::GetMarker(const std::string & name)
    481483{
    482484    IRBuilder<> b(mBasicBlock);
     
    490492}
    491493
    492 void LLVM_Generator::SetReturnMarker(Value * marker, const unsigned output_idx)
     494void PabloCompiler::SetReturnMarker(Value * marker, const unsigned output_idx)
    493495{
    494496    IRBuilder<> b(mBasicBlock);
     
    501503
    502504
    503 Value * LLVM_Generator::Generate_PabloStatements(const ExpressionList & stmts) {
     505Value * PabloCompiler::compileStatements(const ExpressionList & stmts) {
    504506    Value * retVal = nullptr;
    505507    for (PabloE * statement : stmts) {
    506         retVal = Generate_PabloS(statement);
     508        retVal = compileStatement(statement);
    507509    }
    508510    return retVal;
    509511}
    510512
    511 Value * LLVM_Generator::Generate_PabloS(const PabloE *stmt)
     513Value * PabloCompiler::compileStatement(PabloE * stmt)
    512514{
    513515    Value * retVal = nullptr;
    514 
    515516    if (const Assign * assign = dyn_cast<const Assign>(stmt))
    516517    {
     
    519520        Value * marker = GetMarker(assign->getName());
    520521
    521         b.CreateStore(Generate_PabloE(assign->getExpr()), marker);
     522        b.CreateStore(compileExpression(assign->getExpr()), marker);
    522523
    523524        retVal = marker;
     
    531532        int if_start_idx = mCarryQueueIdx;
    532533
    533         Value* if_test_value = Generate_PabloE(ifstmt->getExpr());
     534        Value* if_test_value = compileExpression(ifstmt->getCondition());
    534535
    535536        /* Generate the statements into the if body block, and also determine the
     
    539540        mBasicBlock = ifBodyBlock;
    540541
    541         Value *  returnMarker = Generate_PabloStatements(ifstmt->getPSList());
     542        Value *  returnMarker = compileStatements(ifstmt->getBody());
    542543
    543544        int if_end_idx = mCarryQueueIdx;
     
    578579
    579580        //With this call to the while body we will account for all of the carry in values.
    580         Value * returnMarker = Generate_PabloStatements(whl->getPSList());
     581        Value * returnMarker = compileStatements(whl->getBody());
    581582
    582583        BasicBlock*  whileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunc_process_block, 0);
     
    589590        IRBuilder<> b_cond(whileCondBlock);
    590591
    591         Value* expression_marker_value = Generate_PabloE(whl->getCondition());
     592        Value* expression_marker_value = compileExpression(whl->getCondition());
    592593        Value* int_tobool1 = genBitBlockAny(expression_marker_value);
    593594
     
    609610        mptr_carry_q = ptr_while_carry_q;
    610611
    611         returnMarker = Generate_PabloStatements(whl->getPSList());
     612        returnMarker = compileStatements(whl->getBody());
    612613
    613614        IRBuilder<> b_wb2(mBasicBlock);
     
    627628        retVal = returnMarker;
    628629    }
    629 
    630630    return retVal;
    631631}
    632632
    633 Value* LLVM_Generator::Generate_PabloE(const PabloE * expr)
    634 {
    635     Value* retVal = 0;
     633Value * PabloCompiler::compileExpression(PabloE * expr)
     634{
     635    Value * retVal = nullptr;
    636636    IRBuilder<> b(mBasicBlock);
    637637    if (const All* all = dyn_cast<All>(expr))
     
    644644    {
    645645        //Call the callee once and store the result in the marker map.
    646         auto f = mMarkerMap.find(call->getCallee());
    647         if (f == mMarkerMap.end()) {
    648             std::map<std::string, Value*>::iterator itFuncGet = mMarkerMap.find("__get_category_" + call->getCallee());
     646        auto mi = mMarkerMap.find(call->getCallee());
     647        if (mi == mMarkerMap.end()) {
     648            auto ci = mCalleeMap.find(call->getCallee());
     649            if (ci == mCalleeMap.end()) {
     650                throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee() + "\"");
     651            }
    649652            Value* basis_bits_struct = b.CreateLoad(mBasisBitsAddr);
    650             Value* unicode_category = b.CreateCall(itFuncGet->second, basis_bits_struct);
     653            Value* unicode_category = b.CreateCall(ci->second, basis_bits_struct);
    651654            Value* ptr = b.CreateAlloca(mXi64Vect);
    652655            b.CreateStore(unicode_category, ptr);
    653             f = mMarkerMap.insert(make_pair(call->getCallee(), ptr)).first;
    654         }
    655         retVal = b.CreateLoad(f->second);
     656            mi = mMarkerMap.insert(std::make_pair(call->getCallee(), ptr)).first;
     657        }
     658        retVal = b.CreateLoad(mi->second);
    656659    }
    657660    else if (const Var * var = dyn_cast<Var>(expr))
     
    661664    else if (const And * pablo_and = dyn_cast<And>(expr))
    662665    {
    663         retVal = b.CreateAnd(Generate_PabloE(pablo_and->getExpr1()), Generate_PabloE(pablo_and->getExpr2()), "and");
     666        retVal = b.CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
    664667    }
    665668    else if (const Or * pablo_or = dyn_cast<Or>(expr))
    666669    {
    667         retVal = b.CreateOr(Generate_PabloE(pablo_or->getExpr1()), Generate_PabloE(pablo_or->getExpr2()), "or");
     670        retVal = b.CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
    668671    }
    669672    else if (const Sel * pablo_sel = dyn_cast<Sel>(expr))
    670673    {
    671         Value* ifMask = Generate_PabloE(pablo_sel->getCondition());
    672         Value* and_if_true_result = b.CreateAnd(ifMask, Generate_PabloE(pablo_sel->getTrueExpr()));
    673         Value* and_if_false_result = b.CreateAnd(genNot(ifMask), Generate_PabloE(pablo_sel->getFalseExpr()));
     674        Value* ifMask = compileExpression(pablo_sel->getCondition());
     675        Value* and_if_true_result = b.CreateAnd(ifMask, compileExpression(pablo_sel->getTrueExpr()));
     676        Value* and_if_false_result = b.CreateAnd(genNot(ifMask), compileExpression(pablo_sel->getFalseExpr()));
    674677        retVal = b.CreateOr(and_if_true_result, and_if_false_result);
    675678    }
    676679    else if (const Not * pablo_not = dyn_cast<Not>(expr))
    677680    {
    678         Value* expr_value = Generate_PabloE(pablo_not->getExpr());
     681        Value* expr_value = compileExpression(pablo_not->getExpr());
    679682        retVal = b.CreateXor(expr_value, mConst_Aggregate_Xi64_neg1, "not");
    680683    }
     
    685688    else if (const Advance * adv = dyn_cast<Advance>(expr))
    686689    {
    687         Value* strm_value = Generate_PabloE(adv->getExpr());
     690        Value* strm_value = compileExpression(adv->getExpr());
    688691        retVal = genAdvanceWithCarry(strm_value);
    689692    }
    690693    else if (const MatchStar * mstar = dyn_cast<MatchStar>(expr))
    691694    {
    692         Value* marker_expr = Generate_PabloE(mstar->getExpr1());
    693         Value* cc_expr = Generate_PabloE(mstar->getExpr2());
     695        Value* marker_expr = compileExpression(mstar->getExpr1());
     696        Value* cc_expr = compileExpression(mstar->getExpr2());
    694697        Value* marker_and_cc = b.CreateAnd(marker_expr, cc_expr);
    695698        retVal = b.CreateOr(b.CreateXor(genAddWithCarry(marker_and_cc, cc_expr), cc_expr), marker_expr, "matchstar");
     
    697700    else if (const ScanThru * sthru = dyn_cast<ScanThru>(expr))
    698701    {
    699         Value* marker_expr = Generate_PabloE(sthru->getScanFrom());
    700         Value* cc_expr = Generate_PabloE(sthru->getScanThru());
     702        Value* marker_expr = compileExpression(sthru->getScanFrom());
     703        Value* cc_expr = compileExpression(sthru->getScanThru());
    701704        retVal = b.CreateAnd(genAddWithCarry(marker_expr, cc_expr), genNot(cc_expr), "scanthru_rslt");
    702705    }
     706    expr->setCompiledValue(retVal);
    703707    return retVal;
    704708}
     
    729733#endif
    730734
    731 Value* LLVM_Generator::genAddWithCarry(Value* e1, Value* e2) {
     735Value* PabloCompiler::genAddWithCarry(Value* e1, Value* e2) {
    732736    IRBuilder<> b(mBasicBlock);
    733737
     
    778782}
    779783
    780 Value* LLVM_Generator::genCarryInLoad(Value* ptr_carry_q, int n) {
     784Value* PabloCompiler::genCarryInLoad(Value* ptr_carry_q, int n) {
    781785    IRBuilder<> b(mBasicBlock);
    782786    Value* carryq_idx = b.getInt64(n);
     
    785789}
    786790
    787 Value* LLVM_Generator::genCarryOutStore(Value* carryout, Value* ptr_carry_q, int n ) {
     791Value* PabloCompiler::genCarryOutStore(Value* carryout, Value* ptr_carry_q, int n ) {
    788792    IRBuilder<> b(mBasicBlock);
    789793    Value* carryq_idx = b.getInt64(n);
     
    792796}
    793797
    794 Value* LLVM_Generator::genBitBlockAny(Value* e) {
     798Value* PabloCompiler::genBitBlockAny(Value* e) {
    795799    IRBuilder<> b(mBasicBlock);
    796800    Value* cast_marker_value_1 = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     
    798802}
    799803
    800 Value* LLVM_Generator::genShiftHighbitToLow(Value* e, const Twine &namehint) {
     804Value* PabloCompiler::genShiftHighbitToLow(Value* e, const Twine &namehint) {
    801805    IRBuilder<> b(mBasicBlock);
    802806    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     
    804808}
    805809
    806 Value* LLVM_Generator::genShiftLeft64(Value* e, const Twine &namehint) {
     810Value* PabloCompiler::genShiftLeft64(Value* e, const Twine &namehint) {
    807811    IRBuilder<> b(mBasicBlock);
    808812    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     
    810814}
    811815
    812 Value* LLVM_Generator::genNot(Value* e, const Twine &namehint) {
     816Value* PabloCompiler::genNot(Value* e, const Twine &namehint) {
    813817    IRBuilder<> b(mBasicBlock);
    814818    return b.CreateXor(e, mConst_Aggregate_Xi64_neg1, namehint);
    815819}
    816820
    817 Value* LLVM_Generator::genAdvanceWithCarry(Value* strm_value) {
     821Value* PabloCompiler::genAdvanceWithCarry(Value* strm_value) {
    818822    IRBuilder<> b(mBasicBlock);
    819823#if (BLOCK_SIZE == 128)
  • icGREP/icgrep-devel/icgrep/llvm_gen.h

    r4218 r4220  
    1616#include <pablo/codegenstate.h>
    1717#include <pablo/pe_pabloe.h>
    18 #include "llvm_gen_helper.h"
    1918#include "unicode_categories.h"
    2019//#include "unicode_categories-flat.h"
     
    2322#include <string>
    2423#include <list>
    25 #include <unordered_map>
    2624#include <map>
    2725#include <algorithm>
     
    8785};
    8886
    89 class LLVM_Generator {
    90     typedef std::unordered_map<std::string, void *> CalleeMapType;
     87class PabloCompiler {
    9188public:
    92     LLVM_Generator(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
    93     ~LLVM_Generator();
    94     LLVM_Gen_RetVal Generate_LLVMIR(const CodeGenState & cg_state);
     89    PabloCompiler(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
     90    ~PabloCompiler();
     91    LLVM_Gen_RetVal compile(const PabloBlock & cg_state);
    9592private:
    9693    void MakeLLVMModule();
     
    104101    Value * GetMarker(const std::string & name);
    105102
    106     Value * Generate_PabloStatements(const ExpressionList & stmts);
    107     Value * Generate_PabloS(const PabloE * stmt);
     103    Value * compileStatements(const ExpressionList & stmts);
     104    Value * compileStatement(PabloE *stmt);
    108105
    109     Value* Generate_PabloE(const PabloE * expr);
     106    Value* compileExpression(PabloE * expr);
    110107    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
    111108    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
     
    124121    Module*                             mMod;
    125122    BasicBlock*                         mBasicBlock;
    126     CalleeMapType *                     mCalleeMap;
    127123    ExecutionEngine*                    mExecutionEngine;
    128124
    129     VectorType*  mXi64Vect;
    130     PointerType* mXi64Vect_Ptr1;
     125    VectorType*                         mXi64Vect;
     126    PointerType*                        mXi64Vect_Ptr1;
    131127
    132     VectorType* mXi128Vect;
     128    VectorType*                         mXi128Vect;
    133129
    134     PointerType* mBasisBitsInputPtr;
    135     PointerType* mOutputPtr;
     130    PointerType*                        mBasisBitsInputPtr;
     131    PointerType*                        mOutputPtr;
    136132
    137     std::map<std::string, Value*> mMarkerMap;
     133    std::map<std::string, Value*>       mCalleeMap;
     134    std::map<std::string, Value*>       mMarkerMap;
    138135
    139     int         mCarryQueueIdx;
    140     Value*      mptr_carry_q;
     136    int                                 mCarryQueueIdx;
     137    Value*                              mptr_carry_q;
    141138
    142     int         mCarryQueueSize;
     139    int                                 mCarryQueueSize;
    143140
    144     ConstantInt*           mConst_int64_neg1;
    145     ConstantAggregateZero* mConst_Aggregate_Xi64_0;
    146     Constant*              mConst_Aggregate_Xi64_neg1;
     141    ConstantInt*                        mConst_int64_neg1;
     142    ConstantAggregateZero*              mConst_Aggregate_Xi64_0;
     143    Constant*                           mConst_Aggregate_Xi64_neg1;
    147144
    148     FunctionType* mFuncTy_0;
    149     Function*     mFunc_process_block;
    150     Function*     mFunc_llvm_uadd_with_overflow;
     145    FunctionType*                       mFuncTy_0;
     146    Function*                           mFunc_process_block;
     147    Function*                           mFunc_llvm_uadd_with_overflow;
    151148
    152     Constant*     mFunc_print_register;
    153     Constant*     mFunc_test_getCategory;
    154     Constant*     mFunc_get_unicode_category;
    155     Value*     mFunc_get_unicode_category_Nd;
     149    Constant*                           mFunc_print_register;
     150    Constant*                           mFunc_test_getCategory;
     151    Constant*                           mFunc_get_unicode_category;
     152    Value*                              mFunc_get_unicode_category_Nd;
    156153
    157     AllocaInst*  mBasisBitsAddr;
    158     AllocaInst*  mPtr_carry_q_addr;
    159     AllocaInst*  mPtr_output_addr;
     154    AllocaInst*                         mBasisBitsAddr;
     155    AllocaInst*                         mPtr_carry_q_addr;
     156    AllocaInst*                         mPtr_output_addr;
    160157};
    161158
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4214 r4220  
    1111/// UNARY CREATE FUNCTIONS
    1212
    13 Advance * CodeGenState::createAdvance(PabloE * expr) {
     13Advance * PabloBlock::createAdvance(PabloE * expr) {
    1414    return mUnary.findOrMake<Advance>(PabloE::ClassTypeId::Advance, expr);
    1515}
    1616
    17 Call * CodeGenState::createCall(const std::string name) {
     17Call * PabloBlock::createCall(const std::string name) {
    1818    return mUnary.findOrMake<Call>(PabloE::ClassTypeId::Call, mSymbolGenerator[name]);
    1919}
    2020
    21 CharClass * CodeGenState::createCharClass(const std::string name) {
     21CharClass * PabloBlock::createCharClass(const std::string name) {
    2222    return mUnary.findOrMake<CharClass>(PabloE::ClassTypeId::CharClass, mSymbolGenerator[name]);
    2323}
    2424
    25 PabloE * CodeGenState::createNot(PabloE * expr) {
     25PabloE * PabloBlock::createNot(PabloE * expr) {
    2626    return mUnary.findOrCall<OptimizeNot>(PabloE::ClassTypeId::Not, expr);
    2727}
    2828
    29 Var * CodeGenState::createVar(const std::string name) {
     29Var * PabloBlock::createVar(const std::string name) {
    3030    return mUnary.findOrMake<Var>(PabloE::ClassTypeId::Var, mSymbolGenerator[name]);
    3131}
    3232
    33 Var * CodeGenState::createVar(Assign * assign) {
     33Var * PabloBlock::createVar(Assign * assign) {
    3434    return mUnary.findOrMake<Var>(PabloE::ClassTypeId::Var, const_cast<String *>(assign->mName));
    3535}
     
    3737/// BINARY CREATE FUNCTIONS
    3838
    39 PabloE * CodeGenState::createAnd(PabloE * expr1, PabloE * expr2) {
     39PabloE * PabloBlock::createAnd(PabloE * expr1, PabloE * expr2) {
    4040    if (expr1 < expr2) {
    4141        std::swap(expr1, expr2);
     
    4444}
    4545
    46 Assign * CodeGenState::createAssign(const std::string name, PabloE * expr) {
    47     return mBinary.findOrMake<Assign>(PabloE::ClassTypeId::Assign, mSymbolGenerator[name], expr);
     46Assign * PabloBlock::createAssign(const std::string name, PabloE * expr) {
     47    Assign * assign = mBinary.findOrMake<Assign>(PabloE::ClassTypeId::Assign, mSymbolGenerator[name], expr);
     48    mStatements.push_back(assign);
     49    return assign;
    4850}
    4951
    50 MatchStar * CodeGenState::createMatchStar(PabloE * expr1, PabloE * expr2) {
     52MatchStar * PabloBlock::createMatchStar(PabloE * expr1, PabloE * expr2) {
    5153    return mBinary.findOrMake<MatchStar>(PabloE::ClassTypeId::MatchStar, expr1, expr2);
    5254}
    5355
    54 PabloE * CodeGenState::createOr(PabloE * expr1, PabloE * expr2) {
     56PabloE * PabloBlock::createOr(PabloE * expr1, PabloE * expr2) {
    5557    if (expr1 < expr2) {
    5658        std::swap(expr1, expr2);
     
    5961}
    6062
    61 ScanThru * CodeGenState::createScanThru(PabloE * from, PabloE * thru) {
     63ScanThru * PabloBlock::createScanThru(PabloE * from, PabloE * thru) {
    6264    return mBinary.findOrMake<ScanThru>(PabloE::ClassTypeId::ScanThru, from, thru);
    6365}
    6466
    65 PabloE * CodeGenState::createXor(PabloE * expr1, PabloE * expr2) {
     67PabloE * PabloBlock::createXor(PabloE * expr1, PabloE * expr2) {
    6668    if (expr1 < expr2) {
    6769        std::swap(expr1, expr2);
     
    7274/// TERNARY CREATE FUNCTION
    7375
    74 PabloE *CodeGenState::createSel(PabloE * condition, PabloE * trueExpr, PabloE * falseExpr) {
     76PabloE *PabloBlock::createSel(PabloE * condition, PabloE * trueExpr, PabloE * falseExpr) {
    7577    return mTernary.findOrCall<OptimizeSel>(PabloE::ClassTypeId::Sel, condition, trueExpr, falseExpr);
    7678}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4217 r4220  
    3535namespace pablo {
    3636
    37 struct CodeGenState {
     37struct PabloBlock {
    3838
    39     CodeGenState(SymbolGenerator & symgen)
     39    PabloBlock(SymbolGenerator & symgen)
    4040    : mSymbolGenerator(symgen)
    4141    , mAll{{new All(0), new All(1)}}
     
    4747    }
    4848
    49     CodeGenState(CodeGenState & cg)
     49    PabloBlock(PabloBlock & cg)
    5050    : mSymbolGenerator(cg.mSymbolGenerator)
    5151    , mAll(cg.mAll) // inherit the original "All" variables for simplicity
     
    9191    PabloE * createSel(PabloE * condition, PabloE * trueExpr, PabloE * falseExpr);
    9292
    93     inline If * createIf(PabloE * condition, CodeGenState && body) {
    94         return new If(condition, std::move(body.mExpressions));
     93    inline If * createIf(PabloE * condition, PabloBlock && body) {
     94        If * statement = new If(condition, std::move(body.mStatements));
     95        mStatements.push_back(statement);
     96        return statement;
    9597    }
    9698
    97     inline While * createWhile(PabloE * cond, CodeGenState && body) {
    98         return new While(cond, std::move(body.mExpressions));
     99    inline While * createWhile(PabloE * cond, PabloBlock && body) {
     100        While * statement = new While(cond, std::move(body.mStatements));
     101        mStatements.push_back(statement);
     102        return statement;
    99103    }
    100104
     
    104108        typedef std::tuple<PabloE::ClassTypeId, Args...> Key;
    105109
    106         inline ExpressionMap(MapType * predecessor, CodeGenState * parent)
     110        inline ExpressionMap(MapType * predecessor, PabloBlock * parent)
    107111        : mPredecessor(predecessor)
    108112        , mCodeGenState(*parent)
     
    131135            }
    132136            Functor mf(mCodeGenState);
    133             PabloE * expr = mf(args...);
     137            PabloE * expr = mf(args...);           
    134138            mMap.insert(std::make_pair(std::move(key), expr));
    135139            return expr;
     
    159163    private:
    160164        MapType * const         mPredecessor;
    161         CodeGenState &          mCodeGenState;
     165        PabloBlock &            mCodeGenState;
    162166        std::map<Key, PabloE *> mMap;
    163167    };
    164 
    165     inline void push_back(PabloE * expr) {
    166         mExpressions.push_back(expr);
    167     }
    168168
    169169    inline std::string ssa(std::string prefix) { // Static Single-Assignment
     
    172172
    173173    inline const ExpressionList & expressions() const {
    174         return mExpressions;
     174        return mStatements;
    175175    }
    176176
     
    181181    ExpressionMap<PabloE *, PabloE *>               mBinary;
    182182    ExpressionMap<PabloE *, PabloE *, PabloE *>     mTernary;
    183     ExpressionList                                  mExpressions;
     183    ExpressionList                                  mStatements;
    184184};
    185185
  • icGREP/icgrep-devel/icgrep/pablo/pe_advance.h

    r4215 r4220  
    1313
    1414class Advance : public PabloE {
    15     friend Advance * makeAdvance(PabloE * expr);
    16     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1716public:
    1817    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_all.h

    r4215 r4220  
    1313
    1414class All : public PabloE {
    15     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1616public:
    1717    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_and.h

    r4215 r4220  
    1212namespace pablo {
    1313
    14 struct CodeGenState;
     14struct PabloBlock;
    1515
    1616class And : public PabloE {
    1717    friend struct OptimizeAnd;
    18     friend struct CodeGenState;
     18    friend struct PabloBlock;
    1919public:
    2020    static inline bool classof(const PabloE * e) {
     
    4646
    4747struct OptimizeAnd {
    48     inline OptimizeAnd(CodeGenState & cg) : cg(cg) {}
     48    inline OptimizeAnd(PabloBlock & cg) : cg(cg) {}
    4949    PabloE * operator()(PabloE * expr1, PabloE * expr2);
    5050private:
    51     CodeGenState & cg;
     51    PabloBlock & cg;
    5252};
    5353
  • icGREP/icgrep-devel/icgrep/pablo/pe_call.h

    r4215 r4220  
    88
    99class Call : public PabloE {
    10     friend struct CodeGenState;
     10    friend struct PabloBlock;
    1111public:
    1212    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_charclass.h

    r4215 r4220  
    1414
    1515class CharClass : public PabloE {
    16     friend struct CodeGenState;
     16    friend struct PabloBlock;
    1717public:
    1818    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_matchstar.h

    r4215 r4220  
    1313
    1414class MatchStar : public PabloE {
    15     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1616public:
    1717    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_not.h

    r4215 r4220  
    1212namespace pablo {
    1313
    14 struct CodeGenState;
     14struct PabloBlock;
    1515
    1616class Not : public PabloE {
    1717    friend struct OptimizeNot;
    18     friend struct CodeGenState;
     18    friend struct PabloBlock;
    1919public:
    2020    static inline bool classof(const PabloE * e) {
     
    4040
    4141struct OptimizeNot {
    42     inline OptimizeNot(CodeGenState & cg) : cg(cg) {}
     42    inline OptimizeNot(PabloBlock & cg) : cg(cg) {}
    4343    PabloE * operator()(PabloE * expr);
    4444private:
    45     CodeGenState & cg;
     45    PabloBlock & cg;
    4646
    4747};
  • icGREP/icgrep-devel/icgrep/pablo/pe_or.h

    r4215 r4220  
    1212namespace pablo {
    1313
    14 struct CodeGenState;
     14struct PabloBlock;
    1515
    1616class Or : public PabloE {
    1717    friend struct OptimizeOr;
    18     friend struct CodeGenState;
     18    friend struct PabloBlock;
    1919public:
    2020    static inline bool classof(const PabloE * e) {
     
    4646
    4747struct OptimizeOr {
    48     inline OptimizeOr(CodeGenState & cg) : cg(cg) {}
     48    inline OptimizeOr(PabloBlock & cg) : cg(cg) {}
    4949    PabloE * operator()(PabloE * expr1, PabloE * expr2);
    5050private:
    51     CodeGenState & cg;
     51    PabloBlock & cg;
    5252};
    5353
  • icGREP/icgrep-devel/icgrep/pablo/pe_pabloe.h

    r4215 r4220  
    99
    1010#include <llvm/Support/Casting.h>
     11#include <llvm/IR/Value.h>
    1112#include <list>
    1213
     
    1516namespace pablo {
    1617
    17 class PabloE
    18 {
     18class PabloE {
    1919public:
    2020    enum class ClassTypeId : unsigned {
     
    4040    }
    4141    virtual ~PabloE() = 0;
     42
     43    inline Value * getCompiledValue() const {
     44        return mCompiledValue;
     45    }
     46
     47    inline void setCompiledValue(Value * value) {
     48        mCompiledValue = value;
     49    }
    4250protected:
    4351    inline PabloE(const ClassTypeId id)
    44     : mClassTypeId(id) {
     52    : mClassTypeId(id)
     53    , mCompiledValue(nullptr) {
    4554
    4655    }
    4756private:
    48     const ClassTypeId mClassTypeId;
     57    const ClassTypeId   mClassTypeId;
     58    Value *             mCompiledValue;
    4959};
    5060
  • icGREP/icgrep-devel/icgrep/pablo/pe_scanthru.h

    r4215 r4220  
    1313
    1414class ScanThru : public  PabloE {
    15     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1616public:
    1717    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_sel.h

    r4215 r4220  
    1212namespace pablo {
    1313
    14 struct CodeGenState;
     14struct PabloBlock;
    1515
    1616class Sel : public PabloE {
    1717    friend struct OptimizeSel;
    18     friend struct CodeGenState;
     18    friend struct PabloBlock;
    1919public:
    2020    static inline bool classof(const PabloE * e) {
     
    5151
    5252struct OptimizeSel {
    53     inline OptimizeSel(CodeGenState & cg) : cg(cg) {}
     53    inline OptimizeSel(PabloBlock & cg) : cg(cg) {}
    5454    PabloE * operator()(PabloE * if_expr, PabloE * t_expr, PabloE * f_expr);
    5555private:
    56     CodeGenState & cg;
     56    PabloBlock & cg;
    5757};
    5858
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r4215 r4220  
    1515
    1616class Var : public PabloE {
    17     friend struct CodeGenState;
     17    friend struct PabloBlock;
    1818public:
    1919    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_xor.h

    r4215 r4220  
    1212namespace pablo {
    1313
    14 struct CodeGenState;
     14struct PabloBlock;
    1515
    1616class Xor : public PabloE {
    1717    friend struct OptimizeXor;
    18     friend struct CodeGenState;
     18    friend struct PabloBlock;
    1919public:
    2020    static inline bool classof(const PabloE * e) {
     
    4646
    4747struct OptimizeXor {
    48     inline OptimizeXor(CodeGenState & cg) : cg(cg) {}
     48    inline OptimizeXor(PabloBlock & cg) : cg(cg) {}
    4949    PabloE * operator()(PabloE * expr1, PabloE * expr2);
    5050private:
    51     CodeGenState & cg;
     51    PabloBlock & cg;
    5252};
    5353
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4215 r4220  
    3838using namespace pablo;
    3939
    40 std::string StatementPrinter::PrintStmts(const CodeGenState & cg_state)
     40std::string StatementPrinter::PrintStmts(const PabloBlock & cg_state)
    4141{
    4242    std::string strOut = "[";
     
    7878    else if (const If * ifstmt = dyn_cast<const If>(stmt))
    7979    {
    80         retVal = "If(" + ShowPabloE(ifstmt->getExpr()) + ", " + Print_PB_PabloStmts(ifstmt->getPSList(), retVal) + ")";
     80        retVal = "If(" + ShowPabloE(ifstmt->getCondition()) + ", " + Print_PB_PabloStmts(ifstmt->getBody(), retVal) + ")";
    8181    }
    8282    else if (const While * whl = dyn_cast<const While>(stmt))
    8383    {
    84         retVal = "While(" + ShowPabloE(whl->getCondition()) + ", " + Print_PB_PabloStmts(whl->getPSList(), retVal) + ")";
     84        retVal = "While(" + ShowPabloE(whl->getCondition()) + ", " + Print_PB_PabloStmts(whl->getBody(), retVal) + ")";
    8585    }
    8686    else retVal = "UNKNOWN_STATEMENT_TYPE!!!";
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.h

    r4215 r4220  
    1212
    1313namespace pablo {
    14     class CodeGenState;
     14    class PabloBlock;
    1515}
    1616
    1717class StatementPrinter {
    1818public:
    19     static std::string PrintStmts(const pablo::CodeGenState & cg_state);
     19    static std::string PrintStmts(const pablo::PabloBlock & cg_state);
    2020    static std::string Print_CC_PabloStmts(const pablo::ExpressionList & stmts);
    2121    static std::string Print_PB_PabloStmts(const pablo::ExpressionList & stmts, std::string strOut);
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4215 r4220  
    1414
    1515class Assign : public PabloE {
    16     friend struct CodeGenState;
     16    friend struct PabloBlock;
    1717public:
    1818    static inline bool classof(const PabloE * e) {
  • icGREP/icgrep-devel/icgrep/pablo/ps_if.h

    r4215 r4220  
    1313
    1414class If : public PabloE {
    15     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1616public:
    1717    static inline bool classof(const PabloE * e) {
     
    2323    virtual ~If() {
    2424    }
    25     inline PabloE * getExpr() const {
     25    inline PabloE * getCondition() const {
    2626        return mExpr;
    2727    }
    28     inline const ExpressionList & getPSList() const {
     28    inline const ExpressionList & getBody() const {
    2929        return mPSList;
    3030    }
  • icGREP/icgrep-devel/icgrep/pablo/ps_while.h

    r4216 r4220  
    1313
    1414class While : public PabloE {
    15     friend struct CodeGenState;
     15    friend struct PabloBlock;
    1616public:
    1717    static inline bool classof(const PabloE * e) {
     
    2626        return mExpr;
    2727    }
    28     inline const ExpressionList & getPSList() const {
     28    inline const ExpressionList & getBody() const {
    2929        return mPSList;
    3030    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4217 r4220  
    4242namespace re {
    4343
    44 RE_Compiler::RE_Compiler(CodeGenState & baseCG, std::map<std::string, std::string> name_map)
     44RE_Compiler::RE_Compiler(PabloBlock & baseCG, std::map<std::string, std::string> name_map)
    4545: mCG(baseCG)
    4646, m_name_map(name_map)
     
    4949}
    5050
    51 void RE_Compiler::compile(RE * re, CodeGenState & cg) {
     51void RE_Compiler::compile(RE * re, PabloBlock & cg) {
    5252
    5353    if (hasUnicode(re)) {
     
    6060        PabloE * u8pfx4 = cg.createVar(m_name_map.find("UTF8-Prefix4")->second);
    6161        PabloE * u8pfx = cg.createOr(cg.createOr(u8pfx2, u8pfx3), u8pfx4);
    62         cg.push_back(cg.createAssign(gs_initial, cg.createOr(u8pfx, u8single)));
     62        cg.createAssign(gs_initial, cg.createOr(u8pfx, u8single));
    6363
    6464        //Set the 'internal.nonfinal' bit stream for the utf-8 multi-byte encoding.
     
    6767        //#define USE_IF_FOR_NONFINAL
    6868        #ifdef USE_IF_FOR_NONFINAL
    69         cg.push_back(make_assign(gs_nonfinal, make_all(0)));
     69        cg.createAssign(gs_nonfinal, make_all(0));
    7070        #endif
    7171        PabloE * u8scope32 = cg.createAdvance(u8pfx3);
     
    7777        cg.createIf(u8pfx, std::move(it));
    7878        #else
    79         PabloE * assign_non_final = cg.createAssign(gs_nonfinal, cg.createOr(cg.createOr(u8pfx, u8scope32), cg.createOr(u8scope42, u8scope43)));
    80         cg.push_back(assign_non_final);
     79        cg.createAssign(gs_nonfinal, cg.createOr(cg.createOr(u8pfx, u8scope32), cg.createOr(u8scope42, u8scope43)));
    8180        #endif
    8281    }
    8382
    8483    PabloE * start_marker = cg.createAll(1);
    85     cg.push_back(start_marker);
    8684    PabloE * result = process(re, start_marker, cg);
    8785
    8886    //These three lines are specifically for grep.
    89     Assign * final = cg.createAssign(cg.ssa("marker"), cg.createAnd(cg.createMatchStar(cg.createVarIfAssign(result),
    90         cg.createNot(cg.createVar(m_name_map.find("LineFeed")->second))), cg.createVar(m_name_map.find("LineFeed")->second)));
    91     cg.push_back(final);
    92 }
    93 
    94 
    95 PabloE * RE_Compiler::process(RE * re, PabloE * target, CodeGenState & cg) {
     87    cg.createAssign(cg.ssa("marker"), cg.createAnd(cg.createMatchStar(cg.createVarIfAssign(result),
     88                    cg.createNot(cg.createVar(m_name_map.find("LineFeed")->second))), cg.createVar(m_name_map.find("LineFeed")->second)));
     89}
     90
     91
     92PabloE * RE_Compiler::process(RE * re, PabloE * target, PabloBlock & cg) {
    9693    if (Name * name = dyn_cast<Name>(re)) {
    9794        target = process(name, target, cg);
     
    108105    else if (isa<Start>(re)) {
    109106        target = cg.createAnd(cg.createVarIfAssign(target), cg.createNot(cg.createAdvance(cg.createNot(cg.createCharClass(m_name_map.find("LineFeed")->second)))));
    110         cg.push_back(target);
    111107    }
    112108    else if (isa<End>(re)) {
    113109        target = cg.createAnd(cg.createVarIfAssign(target), cg.createCharClass(m_name_map.find("LineFeed")->second));
    114         cg.push_back(target);
    115     }
    116 
    117     return target;
    118 }
    119 
    120 inline PabloE * RE_Compiler::process(Name * name, PabloE * target, CodeGenState & cg) {
     110    }
     111
     112    return target;
     113}
     114
     115inline PabloE * RE_Compiler::process(Name * name, PabloE * target, PabloBlock & cg) {
    121116    PabloE * markerExpr = cg.createVarIfAssign(target);
    122117    if (name->getType() != Name::Type::FixedLength) {
     
    136131                                cg.createCharClass(m_name_map.find("nonfinal")->second)));
    137132    }
    138     target = cg.createAssign(cg.ssa("marker"), cg.createAdvance(cg.createAnd(cc, markerExpr)));
    139     cg.push_back(target);
    140     return target;
    141 }
    142 
    143 inline PabloE * RE_Compiler::process(Seq * seq, PabloE * target, CodeGenState & cg) {
     133    return cg.createAssign(cg.ssa("marker"), cg.createAdvance(cg.createAnd(cc, markerExpr)));
     134}
     135
     136inline PabloE * RE_Compiler::process(Seq * seq, PabloE * target, PabloBlock & cg) {
    144137    for (RE * re : *seq) {
    145138        target = process(re, target, cg);
    146139    }
    147     cg.push_back(target);
    148     return target;
    149 }
    150 
    151 inline PabloE * RE_Compiler::process(Alt * alt, PabloE * target, CodeGenState & cg) {
     140    return target;
     141}
     142
     143inline PabloE * RE_Compiler::process(Alt * alt, PabloE * target, PabloBlock & cg) {
    152144    if (alt->empty()) {
    153145        target = cg.createAll(0); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
     
    161153            target = cg.createOr(target, other);
    162154        }
    163         cg.push_back(target);
    164155    }   
    165156    return target;
    166157}
    167158
    168 inline PabloE * RE_Compiler::process(Rep * rep, PabloE * target, CodeGenState & cg) {
     159inline PabloE * RE_Compiler::process(Rep * rep, PabloE * target, PabloBlock & cg) {
    169160    if (rep->getUB() == Rep::UNBOUNDED_REP) {
    170161        target = processUnboundedRep(rep->getRE(), rep->getLB(), target, cg);
     
    176167}
    177168
    178 inline PabloE * RE_Compiler::processUnboundedRep(RE * repeated, int lb, PabloE * target, CodeGenState & cg) {
     169inline PabloE * RE_Compiler::processUnboundedRep(RE * repeated, int lb, PabloE * target, PabloBlock & cg) {
    179170    while (lb-- != 0) {
    180171        target = process(repeated, target, cg);
     
    210201        Assign * while_accum = cg.createAssign(cg.ssa("while_accum"), target);
    211202
    212         CodeGenState wt(cg);
    213 
     203        PabloBlock wt(cg);
    214204        PabloE * accum = cg.createVarIfAssign(process(repeated, while_test, wt));
    215 
    216         cg.push_back(while_test);
    217         cg.push_back(while_accum);
    218 
    219205        Var * var_while_test = cg.createVar(while_accum);
    220 
    221         wt.push_back(cg.createAssign(while_test->getName(), cg.createAnd(accum, cg.createNot(var_while_test))));
    222 
    223         target = cg.createAssign(while_accum->getName(), cg.createOr(var_while_test, accum));
    224 
    225         wt.push_back(target);
    226         cg.push_back(cg.createWhile(cg.createVar(while_test), std::move(wt)));
     206        wt.createAssign(while_test->getName(), wt.createAnd(accum, wt.createNot(var_while_test)));
     207        target = wt.createAssign(while_accum->getName(), wt.createOr(var_while_test, accum));
     208        cg.createWhile(cg.createVar(while_test), std::move(wt));
    227209    }   
    228210    return target;
    229211}
    230212
    231 inline PabloE * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, PabloE * target, CodeGenState & cg) {
     213inline PabloE * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, PabloE * target, PabloBlock & cg) {
    232214    ub -= lb;
    233215    while(lb-- != 0) {
     
    238220        target = cg.createOr(cg.createVarIfAssign(target), cg.createVarIfAssign(alt));
    239221    }
    240     cg.push_back(target);
    241222    return target;
    242223}
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4214 r4220  
    1919public:
    2020
    21     RE_Compiler(pablo::CodeGenState & baseCG, std::map<std::string, std::string> name_map);
     21    RE_Compiler(pablo::PabloBlock & baseCG, std::map<std::string, std::string> name_map);
    2222
    2323    inline void compile(RE * re) {
     
    2727private:
    2828
    29     void compile(RE * re, pablo::CodeGenState & cg);
     29    void compile(RE * re, pablo::PabloBlock & cg);
    3030
    31     pablo::PabloE * process(RE * re, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    32     pablo::PabloE * process(Alt * alt, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    33     pablo::PabloE * process(Seq * seq, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    34     pablo::PabloE * process(Rep * rep, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    35     pablo::PabloE * processUnboundedRep(RE * repeated, int lb, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    36     pablo::PabloE * processBoundedRep(RE * repeated, int lb, int ub, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    37     pablo::PabloE * process(Name * name, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     31    pablo::PabloE * process(RE * re, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     32    pablo::PabloE * process(Alt * alt, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     33    pablo::PabloE * process(Seq * seq, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     34    pablo::PabloE * process(Rep * rep, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     35    pablo::PabloE * processUnboundedRep(RE * repeated, int lb, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     36    pablo::PabloE * processBoundedRep(RE * repeated, int lb, int ub, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     37    pablo::PabloE * process(Name * name, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    3838
    3939    static bool hasUnicode(const RE *re);
    4040
    41     pablo::CodeGenState &                      mCG;
     41    pablo::PabloBlock &                      mCG;
    4242    std::map<std::string, std::string>  m_name_map;
    4343};
Note: See TracChangeset for help on using the changeset viewer.