Changeset 5971 for icGREP


Ignore:
Timestamp:
Apr 17, 2018, 6:22:07 AM (17 months ago)
Author:
cameron
Message:

Internal grep engine fixes

File:
1 edited

Legend:

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

    r5970 r5971  
    157157}
    158158
    159 MatchOnlyEngine::MatchOnlyEngine(bool showFilesWithoutMatch, bool useNullSeparators) :
    160     GrepEngine(), mRequiredCount(showFilesWithoutMatch) {
     159MatchOnlyEngine::MatchOnlyEngine(bool showFilesWithMatch, bool useNullSeparators) :
     160    GrepEngine(), mRequiredCount(showFilesWithMatch) {
    161161    mEngineKind = EngineKind::MatchOnly;
    162162    mFileSuffix = useNullSeparators ? std::string("\0", 1) : "\n";
    163163    mMoveMatchesToEOL = false;
    164164    mMaxCount = 1;
     165    mShowFileNames = true;
    165166}
    166167
     
    476477    mGrepDriver->deallocateBuffers();
    477478    idb->CreateRet(matchedLineCount);
     479   
    478480    mGrepDriver->finalizeObject();
    479481}
     
    766768        breakCC = re::makeByte(0x0A);
    767769    }
    768    
    769770    bool excludeNothing = (excludedRE == nullptr) || (isa<re::Alt>(excludedRE) && cast<re::Alt>(excludedRE)->empty());
    770771    bool matchAllLines = (matchingRE == nullptr) || isa<re::End>(matchingRE);
    771    
    772772    if (!matchAllLines) {
    773773        matchingRE = resolveCaseInsensitiveMode(matchingRE, mCaseInsensitive);
     
    784784        excludedRE = toUTF8(excludedRE);
    785785    }
    786    
    787    
    788786    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getVoidTy(), idb->getInt8PtrTy(), idb->getSizeTy(), nullptr));
    789787    mainFunc->setCallingConv(CallingConv::C);
     
    799797    sourceK->setInitialArguments({buffer, length});
    800798    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    801    
    802799    StreamSetBuffer * RecordBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    803     kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
    804     scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
    805 
     800    std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
     801
     802   
     803    StreamSetBuffer * BasisBits = nullptr;
     804   
    806805    if (matchAllLines && excludeNothing) {
    807         StreamSetBuffer * RecordBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    808         std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
    809806        kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::DirectCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC});
    810807        mGrepDriver->makeKernelCall(breakK, {ByteStream}, {RecordBreakStream});
    811         mGrepDriver->makeKernelCall(scanMatchK, {RecordBreakStream, RecordBreakStream, ByteStream}, {});
    812808    } else {
    813        
    814         StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
     809        BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
    815810        kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
    816811        mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    817812       
    818         std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
    819813        kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::ParabixCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC}, 8);
    820814        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});
     815    }
     816   
     817    std::vector<std::string> externalStreamNames;
     818    StreamSetBuffer * MatchingRecords = nullptr;
     819    if (matchAllLines) {
     820        MatchingRecords = RecordBreakStream;
     821    } else {
     822        StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     823        kernel::Kernel * includeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, matchingRE, externalStreamNames);
     824        mGrepDriver->makeKernelCall(includeK, {BasisBits}, {MatchResults});
     825        MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     826        kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
     827        mGrepDriver->makeKernelCall(matchedLinesK, {MatchResults, RecordBreakStream}, {MatchingRecords});
     828    }
     829    if (!excludeNothing) {
     830        StreamSetBuffer * ExcludedResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     831        kernel::Kernel * excludeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, excludedRE, externalStreamNames);
     832        mGrepDriver->makeKernelCall(excludeK, {BasisBits}, {ExcludedResults});
     833        StreamSetBuffer * ExcludedRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     834        kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
     835        mGrepDriver->makeKernelCall(matchedLinesK, {ExcludedResults, RecordBreakStream}, {ExcludedRecords});
     836
     837        kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
     838        if (!matchAllLines) {
     839            StreamSetBuffer * nonExcluded = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     840            mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {nonExcluded});
     841            StreamSetBuffer * included = MatchingRecords;
    829842            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     }
     843            kernel::Kernel * streamsIntersectK = mGrepDriver->addKernelInstance<kernel::StreamsIntersect>(idb, 1, 2);
     844            mGrepDriver->makeKernelCall(streamsIntersectK, {included, nonExcluded}, {MatchingRecords});
     845        }
     846        else {
     847            MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     848            mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {MatchingRecords});
     849        }
     850    }
     851    kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
     852    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
     853    mGrepDriver->makeKernelCall(scanMatchK, {MatchingRecords, RecordBreakStream, ByteStream}, {});
    857854    mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
    858855    mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
Note: See TracChangeset for help on using the changeset viewer.