Ignore:
Timestamp:
Apr 8, 2017, 12:56:07 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for object cache. Minor optimization of FunctionTypeBuilder?.

File:
1 edited

Legend:

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

    r5398 r5399  
    206206
    207207
    208 Function * editdPipeline(Module * m, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
    209    
     208void editdPipeline(ParabixDriver & pxDriver, const std::vector<std::string> & patterns) {
     209   
     210    IDISA::IDISA_Builder * const iBuilder = pxDriver.getIDISA_Builder();
     211    Module * const m = iBuilder->getModule();
    210212    Type * const sizeTy = iBuilder->getSizeTy();
    211213    Type * const voidTy = iBuilder->getVoidTy();
     
    214216    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, sizeTy, nullptr));
    215217    main->setCallingConv(CallingConv::C);
    216     Function::arg_iterator args = main->arg_begin();
    217    
     218    auto args = main->arg_begin();
    218219    Value * const inputStream = &*(args++);
    219220    inputStream->setName("input");
    220221    Value * const fileSize = &*(args++);
    221222    fileSize->setName("fileSize");
    222    
     223    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
     224
     225
    223226    ExternalFileBuffer ChStream(iBuilder, iBuilder->getStreamSetTy(4));
    224227    SingleBlockBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(editDistance + 1));
    225228
    226229    MMapSourceKernel mmapK(iBuilder);
    227     std::unique_ptr<Module> mmapM = mmapK.createKernelModule({}, {&ChStream});
    228230    mmapK.setInitialArguments({fileSize});
    229    
     231    pxDriver.addKernelCall(mmapK, {}, {&ChStream});
     232
    230233    PabloKernel editdk(iBuilder, "editd",
    231234                        {Binding{iBuilder->getStreamSetTy(4), "pat"}},
    232235                        {Binding{iBuilder->getStreamSetTy(editDistance + 1), "E"}});
    233236
    234     buildPatternKernel(editdk, iBuilder, patterns);
    235 
    236     kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    237    
    238     std::unique_ptr<Module> editdM = editdk.createKernelModule({&ChStream}, {&MatchResults});
    239     std::unique_ptr<Module> scanM = editdScanK.createKernelModule({&MatchResults}, {});               
    240    
    241     mmapK.addKernelDeclarations(m);
    242     editdk.addKernelDeclarations(m);
    243     editdScanK.addKernelDeclarations(m);
    244 
    245     iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
    246 
    247237    ChStream.setStreamSetBuffer(inputStream);
    248238    MatchResults.allocateBuffer();
    249    
    250     generatePipelineLoop(iBuilder, {&mmapK, &editdk, &editdScanK});
     239
     240    buildPatternKernel(editdk, iBuilder, patterns);
     241    pxDriver.addKernelCall(editdk, {&ChStream}, {&MatchResults});
     242
     243    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
     244    pxDriver.addKernelCall(editdScanK, {&MatchResults}, {});
    251245       
     246    pxDriver.generatePipelineIR();
     247
    252248    iBuilder->CreateRetVoid();
    253    
    254     Linker L(*m);
    255     L.linkInModule(std::move(mmapM));
    256     L.linkInModule(std::move(editdM));
    257     L.linkInModule(std::move(scanM));
    258    
    259     return main;
     249
     250    pxDriver.JITcompileMain();
     251    pxDriver.linkAndFinalize();
    260252}
    261253
     
    280272}
    281273
    282 //
    283 // Handler for errors reported through llvm::report_fatal_error.  Report
    284 // and signal error code 2 (grep convention).
    285 //
    286 static void error_handler(void *UserData, const std::string &Message, bool GenCrashDiag) {
    287     throw std::runtime_error(Message);
    288 }
    289 
    290 
    291274void preprocessPipeline(ParabixDriver & pxDriver) {
    292 
    293     llvm::install_fatal_error_handler(&error_handler);
    294275
    295276    IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     
    342323    iBuilder->CreateRetVoid();
    343324
    344     errs() << "JitCompileMain()\n";
    345 
    346325    pxDriver.JITcompileMain();
    347 
    348     errs() << "linkAndFinalize()\n";
    349 
    350326    pxDriver.linkAndFinalize();
    351 
    352     errs() << "done\n";
    353327}
    354328
     
    369343typedef void (*editdFunctionType)(char * byte_data, size_t filesize);
    370344
    371 editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {
    372                            
     345editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {                           
    373346    LLVMContext TheContext;
    374347    Module * M = new Module("editd", TheContext);
    375     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    376 
    377     llvm::Function * main_IR = editdPipeline(M, idb, patterns);
    378 
    379     ExecutionEngine * editdEngine = JIT_to_ExecutionEngine(M);
    380    
    381     editdEngine->finalizeObject();
    382 
     348    IDISA::IDISA_Builder * const idb = IDISA::GetIDISA_Builder(M);
     349    ParabixDriver pxDriver(idb);
     350    editdPipeline(pxDriver, patterns);
     351    auto f = reinterpret_cast<editdFunctionType>(pxDriver.getPointerToMain());
    383352    delete idb;
    384     return reinterpret_cast<editdFunctionType>(editdEngine->getPointerToFunction(main_IR));
     353    return f;
    385354}
    386355
Note: See TracChangeset for help on using the changeset viewer.