Ignore:
Timestamp:
Feb 29, 2016, 3:46:35 PM (3 years ago)
Author:
cameron
Message:

Refactor and encapsulate grep codegen/execution in GrepEngine?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4939 r4946  
    1919#include <UCD/resolve_properties.h>
    2020#include <UCD/CaseFolding_txt.h>
    21 #include <toolchain.h>
    22 #include "utf_encoding.h"
    23 #include <llvm/IR/Type.h>
    24 #include <pablo/pablo_compiler.h>
    25 #include <do_grep.h>
     21#include <grep_engine.h>
    2622#include <sstream>
    2723#include <algorithm>
    28 #include "../kernels/pipeline.h"
    29 #include "../toolchain.h"
    30 
    3124
    3225// It would probably be best to enforce that {}, [], () must always
     
    513506    return createName(std::move(canonicalize(start, mCursor.pos())));
    514507}
    515 /*
     508
    516509Name * RE_Parser::parseNamePatternExpression(){
    517510
     
    530523    // Embed the nameRE in ";.*$nameRE" to skip the codepoint field of Uname.txt
    531524    RE * embedded = makeSeq({mMemoizer.memoize(makeCC(0x3B)), makeRep(makeAny(), 0, Rep::UNBOUNDED_REP), nameRE});
    532     Encoding encoding(Encoding::Type::UTF_8, 8);
    533     embedded = regular_expression_passes(encoding, embedded);
    534 
    535     pablo::PabloFunction * const nameSearchFunction = re2pablo_compiler(encoding, embedded);
    536     pablo_function_passes(nameSearchFunction);
    537525   
    538     Module * M = new Module("NamePattern", getGlobalContext());
    539     IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
    540     gen_s2p_function(M, idb);
    541 
    542     pablo::PabloCompiler pablo_compiler(M, idb);
    543 
    544     llvm::Function * const nameSearchIR = pablo_compiler.compile(nameSearchFunction); // <- may throw error if parsing exception occurs.
    545     llvm::Function * s2p_IR = M->getFunction("s2p_block");
    546 
    547     llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);   
    548     icgrep_Linking(M, engine);
     526    GrepEngine engine;
     527    engine.grepCodeGen("NamePattern", embedded, true);
    549528   
    550     // Ensure everything is ready to go.
    551     engine->finalizeObject();
    552        
    553     void * icgrep_MCptr = engine->getPointerToFunction(nameSearchIR);
    554     void * s2p_MCptr = engine->getPointerToFunction(s2p_IR);
    555 
    556     CC * codepoints = nullptr;
    557     if (icgrep_MCptr) {
    558         void * icgrep_init_carry_ptr = engine->getPointerToFunction(nameSearchIR->getParent()->getFunction("process_block_initialize_carries"));
    559         GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr);
    560         grepEngine.setParseCodepointsOption();
    561         grepEngine.doGrep("../Uname.txt");
    562         codepoints = grepEngine.getParsedCodepoints();
    563         assert (codepoints);
    564     }
    565     delete engine;
    566     if (codepoints) {
    567         Name * const result = mMemoizer.memoize(codepoints);
    568         assert (*cast<CC>(result->getDefinition()) == *codepoints);
    569         return result;
    570     }
    571     return nullptr;
    572 }
    573 */
    574 Name * RE_Parser::parseNamePatternExpression(){
    575 
    576     ModeFlagSet outerFlags = fModeFlagSet;
    577     fModeFlagSet = 1;
    578 
    579     bool outerNested = fNested;
    580     fNested = true;
    581 
    582     RE * nameRE = parse_RE();
    583 
    584     // Reset outer parsing state.
    585     fModeFlagSet = outerFlags;
    586     fNested = outerNested;
    587 
    588     // Embed the nameRE in ";.*$nameRE" to skip the codepoint field of Uname.txt
    589     RE * embedded = makeSeq({mMemoizer.memoize(makeCC(0x3B)), makeRep(makeAny(), 0, Rep::UNBOUNDED_REP), nameRE});
    590     Encoding encoding(Encoding::Type::UTF_8, 8);
    591     embedded = regular_expression_passes(encoding, embedded);
    592 
    593     pablo::PabloFunction * const nameSearchFunction = re2pablo_compiler(encoding, embedded);
    594     pablo_function_passes(nameSearchFunction);
     529    CC * codepoints = engine.grepCodepoints("../Uname.txt");
    595530   
    596     Module * M = new Module("NamePattern", getGlobalContext());
    597     IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
    598    
    599     PipelineBuilder pipelineBuilder(M, idb);
    600     pipelineBuilder.CreateKernels(nameSearchFunction, true);
    601     pipelineBuilder.ExecuteKernels();
    602 
    603     llvm::Function * main_IR = M->getFunction("Main");
    604     llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
    605    
    606     icgrep_Linking(M, engine);
    607 
    608     engine->finalizeObject();
    609 
    610     void * main_MCptr = engine->getPointerToFunction(main_IR);
    611 
    612     CC * codepoints = nullptr;
    613     if(main_MCptr){
    614         GrepExecutor grepEngine(main_MCptr);
    615         setParsedCodePointSet();
    616         grepEngine.doGrep("../Uname.txt");
    617         codepoints = getParsedCodePointSet();
    618         assert (codepoints);
    619     }
    620        
    621     delete engine;
    622531    if (codepoints) {
    623532        Name * const result = mMemoizer.memoize(codepoints);
Note: See TracChangeset for help on using the changeset viewer.