Ignore:
Timestamp:
Feb 23, 2016, 9:07:05 AM (3 years ago)
Author:
lindanl
Message:

new version using the kernels.

File:
1 edited

Legend:

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

    r4919 r4939  
    99#include <fstream>
    1010
    11 #include "basis_bits.h"
    1211#include "toolchain.h"
    1312#include "utf_encoding.h"
     
    2524#include <llvm/Support/Host.h>
    2625#include <llvm/IR/Verifier.h>
    27 #include <kernels/s2p_gen.h>
    28 #include <kernels/scanmatchgen.h>
    2926
    3027#include <re/re_re.h>
     
    3532#include <pablo/function.h>
    3633
    37 #include <iostream>
    38 
    39 #include <do_grep.h>
    40 #include <hrtime.h>
    41 
    42 #ifdef PRINT_TIMING_INFORMATION
    43 #include "papi_helper.hpp"
    44 #endif
     34#include "do_grep.h"
     35#include <kernels/pipeline.h>
    4536
    4637static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
    4738                                       "These options control the regular expression source.");
    4839
    49 static cl::OptionCategory bGrepOutputOptions("Output Options",
    50                                       "These options control the output.");
     40// static cl::OptionCategory bGrepOutputOptions("Output Options",
     41//                                       "These options control the output.");
    5142
    5243static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
    5344
    54 static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
    55 static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
    56 static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
     45// static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
     46// static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
     47// static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
    5748
    58 static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
    59 static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
     49// static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
     50// static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
    6051
    6152static cl::opt<bool> CaseInsensitive("i", cl::desc("Ignore case distinctions in the pattern and the file."), cl::cat(aRegexSourceOptions));
    62 static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
    63 static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
     53// static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
     54// static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
    6455
    6556static cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(aRegexSourceOptions));
     
    6758static cl::opt<std::string> IRFileName("precompiled", cl::desc("Use precompiled regular expression"), cl::value_desc("LLVM IR file"), cl::init(""), cl::cat(aRegexSourceOptions));
    6859
    69 using namespace llvm;
     60
    7061
    7162static unsigned firstInputFile = 1;  // Normal case when first positional arg is a regex.
     
    143134    cl::ParseCommandLineOptions(argc, argv);
    144135   
    145     Encoding encoding(Encoding::Type::UTF_8, 8);
    146 
    147     llvm::Function * icgrep_IR = nullptr;
    148    
    149136    Module * M = new Module("grepcode", getGlobalContext());
    150137   
    151138    IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
    152    
    153     gen_s2p_function(M, idb);
    154    
    155    
    156     generateScanBitBlockRoutine(M, idb, 64);
    157    
    158     if (IRFileName == "") {       
    159         re::RE * re_ast = get_icgrep_RE();
    160         re_ast = regular_expression_passes(encoding, re_ast);
    161        
    162         #ifdef PRINT_TIMING_INFORMATION
    163         const timestamp_t regex_compilation_start = read_cycle_counter();
    164         #endif
    165         pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
    166         #ifdef PRINT_TIMING_INFORMATION
    167         const timestamp_t regex_compilation_end = read_cycle_counter();
    168         std::cerr << "REGEX COMPILATION TIME: " << (regex_compilation_end - regex_compilation_start) << std::endl;
    169         #endif
    170139
    171         pablo_function_passes(function);
    172        
    173         pablo::PabloCompiler pablo_compiler(M, idb);
    174         try {
    175             icgrep_IR = pablo_compiler.compile(function);
    176             delete function;
    177             releaseSlabAllocatorMemory();
    178         } catch (std::runtime_error e) {
    179             delete function;
    180             releaseSlabAllocatorMemory();
    181             std::cerr << "Runtime error: " << e.what() << std::endl;
    182             exit(1);
    183         }
    184     } else {
    185         firstInputFile = 0;  // No regexp arguments; first positional argument is a file to process.
    186         SMDiagnostic ParseErr;
    187         M = parseIRFile(IRFileName, ParseErr, getGlobalContext()).release();
    188         if (!M) {
    189             throw std::runtime_error("Error in Parsing IR File " + IRFileName);
    190         }
    191         icgrep_IR = M->getFunction("process_block");
    192     }
    193     llvm::Function * s2p_IR = M->getFunction("s2p_block");
    194    
    195    // llvm::Function * scanRoutine = M->getFunction("scan_matches_in_bitblock");
    196    
    197     if (s2p_IR == nullptr) {
    198         std::cerr << "No s2p_IR!\n";
    199         exit(1);
    200     }
    201    
     140    PipelineBuilder pipelineBuilder(M, idb);
     141
     142    re::RE * re_ast = get_icgrep_RE();
     143    Encoding encoding(Encoding::Type::UTF_8, 8);
     144    re_ast = regular_expression_passes(encoding, re_ast);   
     145    pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
     146
     147    pipelineBuilder.CreateKernels(function, false);
     148
     149    pipelineBuilder.ExecuteKernels();
     150
     151    llvm::Function * main_IR = M->getFunction("Main");
    202152    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
    203153   
    204154    icgrep_Linking(M, engine);
    205155    verifyModule(*M, &dbgs());
    206    
    207     // Ensure everything is ready to go.
    208156    engine->finalizeObject();
    209    
    210     // TODO getPointerToFunction() is deprecated. Investigate getFunctionAddress(string name) instead.
    211     void * icgrep_init_carry_ptr = engine->getPointerToFunction(M->getFunction("process_block_initialize_carries"));
    212     void * icgrep_MCptr = engine->getPointerToFunction(icgrep_IR);
    213     void * s2p_MCptr = engine->getPointerToFunction(s2p_IR);
    214     // void * scan_MCptr = engine->getPointerToFunction(scanRoutine);
    215     if (s2p_MCptr == nullptr) {
    216         std::cerr << "No s2p_MCptr!\n";
    217         exit(1);
    218     }
    219157
    220     if (icgrep_MCptr) {
    221         GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr);
    222         //GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr, scan_MCptr);
    223         grepEngine.setCountOnlyOption(CountOnly);
    224         grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
    225         grepEngine.setShowLineNumberOption(ShowLineNumbers);
    226         if (inputFiles.size() > (firstInputFile + 1) || ShowFileNames) {
    227             grepEngine.setShowFileNameOption();
    228         }
    229         #ifdef PRINT_TIMING_INFORMATION
    230         papi::PapiCounter<4> papiCounters({PAPI_RES_STL, PAPI_STL_CCY, PAPI_FUL_CCY, PAPI_MEM_WCY});
    231         #endif
     158    void * main_MCptr = engine->getPointerToFunction(main_IR);
     159
     160    if(main_MCptr){
     161        GrepExecutor grepEngine(main_MCptr);
    232162        for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
    233             #ifdef PRINT_TIMING_INFORMATION
    234             papiCounters.start();
    235             const timestamp_t execution_start = read_cycle_counter();
    236             #endif
    237163            grepEngine.doGrep(inputFiles[i]);
    238             #ifdef PRINT_TIMING_INFORMATION
    239             const timestamp_t execution_end = read_cycle_counter();
    240             papiCounters.stop();
    241             std::cerr << "EXECUTION TIME: " << inputFiles[i] << ":" << "CYCLES|" << (execution_end - execution_start) << papiCounters << std::endl;
    242             #endif
    243164        }
    244165    }
     
    246167    //engine->freeMachineCodeForFunction(icgrep_IR); // Removed in LLVM 3.6. MC will be automatically freed in destructors.
    247168    delete engine;
    248     delete idb;
    249169
    250170    return 0;
Note: See TracChangeset for help on using the changeset viewer.