Changeset 5970


Ignore:
Timestamp:
Apr 15, 2018, 2:54:47 PM (5 days ago)
Author:
cameron
Message:

Optimization for no -exclude/-exclude case

File:
1 edited

Legend:

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

    r5969 r5970  
    2525#include <cc/alphabet.h>
    2626#include <re/re_cc.h>
     27#include <re/re_alt.h>
     28#include <re/re_end.h>
    2729#include <re/re_name.h>
    2830#include <re/casing.h>
     
    155157}
    156158
    157 MatchOnlyEngine::MatchOnlyEngine(bool showFilesWithMatch, bool useNullSeparators) :
    158     GrepEngine(), mRequiredCount(showFilesWithMatch) {
     159MatchOnlyEngine::MatchOnlyEngine(bool showFilesWithoutMatch, bool useNullSeparators) :
     160    GrepEngine(), mRequiredCount(showFilesWithoutMatch) {
    159161    mEngineKind = EngineKind::MatchOnly;
    160162    mFileSuffix = useNullSeparators ? std::string("\0", 1) : "\n";
    161163    mMoveMatchesToEOL = false;
    162164    mMaxCount = 1;
    163     mShowFileNames = true;
    164165}
    165166
     
    475476    mGrepDriver->deallocateBuffers();
    476477    idb->CreateRet(matchedLineCount);
    477    
    478478    mGrepDriver->finalizeObject();
    479479}
     
    766766        breakCC = re::makeByte(0x0A);
    767767    }
    768     if (matchingRE != nullptr) {
     768   
     769    bool excludeNothing = (excludedRE == nullptr) || (isa<re::Alt>(excludedRE) && cast<re::Alt>(excludedRE)->empty());
     770    bool matchAllLines = (matchingRE == nullptr) || isa<re::End>(matchingRE);
     771   
     772    if (!matchAllLines) {
    769773        matchingRE = resolveCaseInsensitiveMode(matchingRE, mCaseInsensitive);
    770774        matchingRE = regular_expression_passes(matchingRE);
     
    773777        matchingRE = toUTF8(matchingRE);
    774778    }
    775     if (excludedRE != nullptr) {
     779    if (!excludeNothing) {
    776780        excludedRE = resolveCaseInsensitiveMode(excludedRE, mCaseInsensitive);
    777781        excludedRE = regular_expression_passes(excludedRE);
     
    780784        excludedRE = toUTF8(excludedRE);
    781785    }
     786   
     787   
    782788    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getVoidTy(), idb->getInt8PtrTy(), idb->getSizeTy(), nullptr));
    783789    mainFunc->setCallingConv(CallingConv::C);
     
    793799    sourceK->setInitialArguments({buffer, length});
    794800    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    795     StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
    796     kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
    797     mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    798801   
    799802    StreamSetBuffer * RecordBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    800     std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
    801     kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::ParabixCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC}, 8);
    802     mGrepDriver->makeKernelCall(breakK, {BasisBits}, {RecordBreakStream});
    803    
    804    
    805     std::vector<std::string> externalStreamNames;
    806     StreamSetBuffer * MatchingRecords = nullptr;
    807     if (matchingRE != nullptr) {
    808         StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    809         kernel::Kernel * includeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, matchingRE, externalStreamNames);
    810         mGrepDriver->makeKernelCall(includeK, {BasisBits}, {MatchResults});
    811         MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    812         kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
    813         mGrepDriver->makeKernelCall(matchedLinesK, {MatchResults, RecordBreakStream}, {MatchingRecords});
    814     }
    815     if (excludedRE != nullptr) {
    816         StreamSetBuffer * ExcludedResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    817         kernel::Kernel * excludeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, excludedRE, externalStreamNames);
    818         mGrepDriver->makeKernelCall(excludeK, {BasisBits}, {ExcludedResults});
    819         StreamSetBuffer * ExcludedRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    820         kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
    821         mGrepDriver->makeKernelCall(matchedLinesK, {ExcludedResults, RecordBreakStream}, {ExcludedRecords});
    822 
    823         kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
    824         if (matchingRE != nullptr) {
    825             StreamSetBuffer * nonExcluded = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    826             mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {nonExcluded});
    827             StreamSetBuffer * included = MatchingRecords;
    828             MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    829             kernel::Kernel * streamsIntersectK = mGrepDriver->addKernelInstance<kernel::StreamsIntersect>(idb, 1, 2);
    830             mGrepDriver->makeKernelCall(streamsIntersectK, {included, nonExcluded}, {MatchingRecords});
    831         }
    832         else {
    833             MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    834             mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {MatchingRecords});
    835         }
    836     }
    837803    kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
    838804    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
    839     mGrepDriver->makeKernelCall(scanMatchK, {MatchingRecords, RecordBreakStream, ByteStream}, {});
     805
     806    if (matchAllLines && excludeNothing) {
     807        StreamSetBuffer * RecordBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     808        std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
     809        kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::DirectCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC});
     810        mGrepDriver->makeKernelCall(breakK, {ByteStream}, {RecordBreakStream});
     811        mGrepDriver->makeKernelCall(scanMatchK, {RecordBreakStream, RecordBreakStream, ByteStream}, {});
     812    } else {
     813       
     814        StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
     815        kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
     816        mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     817       
     818        std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
     819        kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::ParabixCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC}, 8);
     820        mGrepDriver->makeKernelCall(breakK, {BasisBits}, {RecordBreakStream});
     821       
     822       
     823        std::vector<std::string> externalStreamNames;
     824        StreamSetBuffer * MatchingRecords = nullptr;
     825        if (matchingRE != nullptr) {
     826            StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     827            kernel::Kernel * includeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, matchingRE, externalStreamNames);
     828            mGrepDriver->makeKernelCall(includeK, {BasisBits}, {MatchResults});
     829            MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     830            kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
     831            mGrepDriver->makeKernelCall(matchedLinesK, {MatchResults, RecordBreakStream}, {MatchingRecords});
     832        }
     833        if (excludedRE != nullptr) {
     834            StreamSetBuffer * ExcludedResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     835            kernel::Kernel * excludeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, excludedRE, externalStreamNames);
     836            mGrepDriver->makeKernelCall(excludeK, {BasisBits}, {ExcludedResults});
     837            StreamSetBuffer * ExcludedRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     838            kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
     839            mGrepDriver->makeKernelCall(matchedLinesK, {ExcludedResults, RecordBreakStream}, {ExcludedRecords});
     840
     841            kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
     842            if (matchingRE != nullptr) {
     843                StreamSetBuffer * nonExcluded = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     844                mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {nonExcluded});
     845                StreamSetBuffer * included = MatchingRecords;
     846                MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     847                kernel::Kernel * streamsIntersectK = mGrepDriver->addKernelInstance<kernel::StreamsIntersect>(idb, 1, 2);
     848                mGrepDriver->makeKernelCall(streamsIntersectK, {included, nonExcluded}, {MatchingRecords});
     849            }
     850            else {
     851                MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     852                mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {MatchingRecords});
     853            }
     854        }
     855        mGrepDriver->makeKernelCall(scanMatchK, {MatchingRecords, RecordBreakStream, ByteStream}, {});
     856    }
    840857    mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
    841858    mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
Note: See TracChangeset for help on using the changeset viewer.