Ignore:
Timestamp:
Oct 19, 2017, 8:06:18 AM (22 months ago)
Author:
cameron
Message:

Modularization progress

File:
1 edited

Legend:

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

    r5697 r5698  
    7070}
    7171   
     72    //
     73    //  Default Report Match:  lines are emitted with whatever line terminators are found in the
     74    //  input.  However, if the final line is not terminated, a new line is appended.
    7275   
    7376    void NonNormalizingReportMatch::accumulate_match (const size_t lineNum, char * line_start, char * line_end) {
     
    138141    const int32_t fd = open(fileName.c_str(), O_RDONLY);
    139142    if (LLVM_UNLIKELY(fd == -1)) {
    140         if (!NoMessagesFlag  && !(Mode == QuietMode)) {
     143        if (!NoMessagesFlag) {
    141144            if (errno == EACCES) {
    142145                resultAccums[fileIdx]->mResultStr << "icgrep: " << fileName << ": Permission denied.\n";
     
    152155    }
    153156    if (stat(fileName.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
    154         if (!NoMessagesFlag  && !(Mode == QuietMode)) {
     157        if (!NoMessagesFlag) {
    155158            resultAccums[fileIdx]->mResultStr << "icgrep: " << fileName << ": Is a directory.\n";
    156159        }
     
    233236
    234237   
    235 std::pair<StreamSetBuffer *, StreamSetBuffer *> grepPipeline(Driver * grepDriver, std::vector<re::RE *> & REs, const GrepModeType grepMode, StreamSetBuffer * ByteStream) {
     238std::pair<StreamSetBuffer *, StreamSetBuffer *> grepPipeline(Driver * grepDriver, std::vector<re::RE *> & REs, StreamSetBuffer * ByteStream) {
    236239    auto & idb = grepDriver->getBuilder();
    237240    const unsigned segmentSize = codegen::SegmentSize;
     
    306309}
    307310
    308 void GrepEngine::grepCodeGen(std::vector<re::RE *> REs, const GrepModeType grepMode) {
    309 
    310     assert (mGrepDriver == nullptr);
    311     mGrepDriver = new ParabixDriver("engine");
    312     auto & idb = mGrepDriver->getBuilder();
    313     Module * M = idb->getModule();
    314 
    315     const unsigned segmentSize = codegen::SegmentSize;
    316     const unsigned encodingBits = 8;
    317 
    318     Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
    319     mainFunc->setCallingConv(CallingConv::C);
    320     idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    321     auto args = mainFunc->arg_begin();
    322 
    323     Value * const fileDescriptor = &*(args++);
    324     fileDescriptor->setName("fileDescriptor");
    325     Value * match_accumulator = &*(args++);
    326     match_accumulator->setName("match_accumulator");
    327 
    328     StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits)));
    329     kernel::Kernel * sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::FDSourceKernel>(idb, segmentSize));
    330     sourceK->setInitialArguments({fileDescriptor});
    331     mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    332    
    333     StreamSetBuffer * LineBreakStream;
    334     StreamSetBuffer * Matches;
    335     std::tie(LineBreakStream, Matches) = grepPipeline(mGrepDriver, REs, grepMode, ByteStream);
    336    
    337     if (grepMode == NormalMode) {
     311    void GrepEngine::grepCodeGen(std::vector<re::RE *> REs) {
     312       
     313        assert (mGrepDriver == nullptr);
     314        mGrepDriver = new ParabixDriver("engine");
     315        auto & idb = mGrepDriver->getBuilder();
     316        Module * M = idb->getModule();
     317       
     318        const unsigned segmentSize = codegen::SegmentSize;
     319        const unsigned encodingBits = 8;
     320       
     321        Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
     322        mainFunc->setCallingConv(CallingConv::C);
     323        idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     324        auto args = mainFunc->arg_begin();
     325       
     326        Value * const fileDescriptor = &*(args++);
     327        fileDescriptor->setName("fileDescriptor");
     328        Value * match_accumulator = &*(args++);
     329        match_accumulator->setName("match_accumulator");
     330       
     331        StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits)));
     332        kernel::Kernel * sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::FDSourceKernel>(idb, segmentSize));
     333        sourceK->setInitialArguments({fileDescriptor});
     334        mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
     335       
     336        StreamSetBuffer * LineBreakStream;
     337        StreamSetBuffer * Matches;
     338        std::tie(LineBreakStream, Matches) = grepPipeline(mGrepDriver, REs, ByteStream);
     339       
    338340        kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb));
    339341        scanMatchK->setInitialArguments({match_accumulator});
     
    341343        mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
    342344        mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
    343 
     345       
    344346       
    345347        mGrepDriver->generatePipelineIR();
    346348        mGrepDriver->deallocateBuffers();
    347 
     349       
    348350        idb->CreateRet(idb->getInt64(0));
    349     } else {
     351        mGrepDriver->finalizeObject();
     352    }
     353   
     354    void CountOnlyGrepEngine::grepCodeGen(std::vector<re::RE *> REs) {
     355       
     356        assert (mGrepDriver == nullptr);
     357        mGrepDriver = new ParabixDriver("engine");
     358        auto & idb = mGrepDriver->getBuilder();
     359        Module * M = idb->getModule();
     360       
     361        const unsigned segmentSize = codegen::SegmentSize;
     362        const unsigned encodingBits = 8;
     363       
     364        Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
     365        mainFunc->setCallingConv(CallingConv::C);
     366        idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     367        auto args = mainFunc->arg_begin();
     368       
     369        Value * const fileDescriptor = &*(args++);
     370        fileDescriptor->setName("fileDescriptor");
     371        Value * match_accumulator = &*(args++);
     372        match_accumulator->setName("match_accumulator");
     373       
     374        StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits)));
     375        kernel::Kernel * sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::FDSourceKernel>(idb, segmentSize));
     376        sourceK->setInitialArguments({fileDescriptor});
     377        mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
     378       
     379        StreamSetBuffer * LineBreakStream;
     380        StreamSetBuffer * Matches;
     381        std::tie(LineBreakStream, Matches) = grepPipeline(mGrepDriver, REs, ByteStream);
     382       
    350383        kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::PopcountKernel>(idb));
    351384        mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
     
    356389        mGrepDriver->deallocateBuffers();
    357390        idb->CreateRet(matchedLineCount);
    358     }
    359     mGrepDriver->finalizeObject();
    360 }
    361 
     391        mGrepDriver->finalizeObject();
     392    }
     393   
    362394
    363395GrepEngine::~GrepEngine() {
Note: See TracChangeset for help on using the changeset viewer.