Changeset 5482


Ignore:
Timestamp:
May 31, 2017, 5:33:06 AM (23 months ago)
Author:
cameron
Message:

Minor clean-up

File:
1 edited

Legend:

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

    r5481 r5482  
    335335    Type * const int32Ty = idb->getInt32Ty();
    336336
    337     Function * mainFunc = nullptr;
    338     Value * fileIdx = nullptr;
    339     StreamSetBuffer * ByteStream = nullptr;
    340337    kernel::Kernel * sourceK = nullptr;
    341338   
    342339    size_t MatchLimit = ((grepMode == QuietMode) | (grepMode == FilesWithMatch) | (grepMode == FilesWithoutMatch)) ? 1 : MaxCountFlag;
    343340
    344     if (grepSource == GrepSource::Internal) {
    345 
    346         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, idb->getInt8PtrTy(), int64Ty, int32Ty, nullptr));
    347         mainFunc->setCallingConv(CallingConv::C);
    348         idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    349         auto args = mainFunc->arg_begin();
    350 
    351         Value * const buffer = &*(args++);
    352         buffer->setName("buffer");
    353 
    354         Value * length = &*(args++);
    355         length->setName("length");
    356         length = idb->CreateZExtOrTrunc(length, idb->getSizeTy());
    357 
    358         fileIdx = &*(args++);
    359         fileIdx->setName("fileIdx");
    360 
    361         ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
    362 
    363         sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy(), segmentSize));
    364         sourceK->setInitialArguments({buffer, length});
    365 
    366     } else {
    367 
    368         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, idb->getInt32Ty(), int32Ty, nullptr));
    369         mainFunc->setCallingConv(CallingConv::C);
    370         idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    371         auto args = mainFunc->arg_begin();
    372 
    373         Value * const fileDescriptor = &*(args++);
    374         fileDescriptor->setName("fileDescriptor");
    375         fileIdx = &*(args++);
    376         fileIdx->setName("fileIdx");
    377 
    378         ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
    379 
    380         if (grepSource == GrepSource::File) {
    381             sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MMapSourceKernel>(idb, segmentSize));
    382             sourceK->setInitialArguments({fileDescriptor});
    383         } else { // if (grepSource == GrepSource::StdIn) {
    384             sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::ReadSourceKernel>(idb, segmentSize));
    385             sourceK->setInitialArguments({idb->getInt32(STDIN_FILENO)});
    386         }
     341    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, idb->getInt32Ty(), int32Ty, nullptr));
     342    mainFunc->setCallingConv(CallingConv::C);
     343    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     344    auto args = mainFunc->arg_begin();
     345
     346    Value * const fileDescriptor = &*(args++);
     347    fileDescriptor->setName("fileDescriptor");
     348    Value * fileIdx = &*(args++);
     349    fileIdx->setName("fileIdx");
     350
     351    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
     352
     353    if (grepSource == GrepSource::File) {
     354        sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MMapSourceKernel>(idb, segmentSize));
     355        sourceK->setInitialArguments({fileDescriptor});
     356    } else { // if (grepSource == GrepSource::StdIn) {
     357        sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::ReadSourceKernel>(idb, segmentSize));
     358        sourceK->setInitialArguments({idb->getInt32(STDIN_FILENO)});
    387359    }
    388360
     
    427399        mGrepDriver->makeKernelCall(untilK, {AllMatches}, {MergedResults});
    428400    }
    429     if (grepMode != NormalMode) {
     401    if (grepMode == NormalMode) {
     402        kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::Normal, encodingBits));
     403        scanMatchK->setInitialArguments({fileIdx});
     404        mGrepDriver->makeKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
     405        if (UTF_16) {
     406            mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
     407        } else {
     408            mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
     409        }
     410        mGrepDriver->generatePipelineIR();
     411        idb->CreateRet(idb->getInt64(0));
     412    } else {
    430413        kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::MatchCount>(idb));
    431414        mGrepDriver->makeKernelCall(matchCountK, {MergedResults}, {});
     
    435418        matchedLineCount = idb->CreateZExt(matchedLineCount, int64Ty);
    436419        idb->CreateRet(matchedLineCount);
    437     } else {
    438         kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::Normal, encodingBits));
    439         scanMatchK->setInitialArguments({fileIdx});
    440         mGrepDriver->makeKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
    441         if (UTF_16) {
    442             mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
    443         } else {
    444             mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
    445         }
    446         mGrepDriver->generatePipelineIR();
    447         idb->CreateRet(idb->getInt64(0));
    448420    }
    449421    mGrepDriver->finalizeObject();
Note: See TracChangeset for help on using the changeset viewer.