Ignore:
Timestamp:
Dec 9, 2017, 4:37:51 PM (21 months ago)
Author:
cameron
Message:

Restructure to eliminate unnecessary dependencies on RegExpCompiler? and UCDLIB

File:
1 edited

Legend:

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

    r5769 r5770  
    2626#include <re/re_toolchain.h>
    2727#include <toolchain/toolchain.h>
    28 #include <re/re_name_resolve.h>   
     28#include <re/re_name_resolve.h>
    2929#include <re/re_collect_unicodesets.h>
    3030#include <re/re_multiplex.h>
     
    5050
    5151// Grep Engine construction and initialization.
    52    
     52
    5353GrepEngine::GrepEngine() :
    5454    mGrepDriver(nullptr),
     
    5858    mMoveMatchesToEOL(true),
    5959    mEngineThread(pthread_self()) {}
    60    
     60
    6161GrepEngine::~GrepEngine() {
    6262    delete mGrepDriver;
    6363}
    64    
     64
    6565QuietModeEngine::QuietModeEngine() : GrepEngine() {
    6666    mMoveMatchesToEOL = false;
     
    9292    inputFiles = filenames;
    9393}
    94    
    9594
    9695// Code Generation
     
    103102    const unsigned bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
    104103    const unsigned encodingBits = 8;
    105    
     104
    106105    StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(encodingBits, 1), segmentSize * bufferSegments);
    107106    kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
    108107    mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    109    
     108
    110109    StreamSetBuffer * LineBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
    111110    kernel::Kernel * linebreakK = mGrepDriver->addKernelInstance<kernel::LineBreakKernelBuilder>(idb, encodingBits);
    112111    mGrepDriver->makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    113    
     112
    114113    kernel::Kernel * requiredStreamsK = mGrepDriver->addKernelInstance<kernel::RequiredStreams_UTF8>(idb);
    115114    StreamSetBuffer * RequiredStreams = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(4, 1), segmentSize * bufferSegments);
    116115    mGrepDriver->makeKernelCall(requiredStreamsK, {BasisBits}, {RequiredStreams});
    117    
     116
    118117    const auto n = REs.size();
    119    
    120118    std::vector<std::vector<re::CC *>> charclasses(n);
    121    
    122119    for (unsigned i = 0; i < n; i++) {
    123         REs[i] = resolveCaseInsensitiveMode(REs[i], false);
     120        REs[i] = resolveCaseInsensitiveMode(REs[i], grep::IgnoreCaseFlag);
    124121        REs[i] = re::resolveNames(REs[i]);
    125122        const auto UnicodeSets = re::collectUnicodeSets(REs[i]);
     
    129126        REs[i] = regular_expression_passes(REs[i]);
    130127  }
    131    
     128
    132129    std::vector<StreamSetBuffer *> MatchResultsBufs(n);
    133    
     130
    134131    for(unsigned i = 0; i < n; ++i){
    135132        const auto numOfCharacterClasses = charclasses[i].size();
     
    149146    }
    150147    StreamSetBuffer * Matches = MergedResults;
    151    
     148
    152149    if (mMoveMatchesToEOL) {
    153150        StreamSetBuffer * OriginalMatches = Matches;
     
    156153        mGrepDriver->makeKernelCall(matchedLinesK, {OriginalMatches, LineBreakStream}, {Matches});
    157154    }
    158    
     155
    159156    if (InvertMatchFlag) {
    160157        kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
     
    178175
    179176void GrepEngine::grepCodeGen(std::vector<re::RE *> REs) {
    180    
     177
    181178    assert (mGrepDriver == nullptr);
    182179    mGrepDriver = new ParabixDriver("engine");
    183180    auto & idb = mGrepDriver->getBuilder();
    184181    Module * M = idb->getModule();
    185    
     182
    186183    const auto segmentSize = codegen::SegmentSize;
    187184    const auto bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
    188185
    189186    const unsigned encodingBits = 8;
    190    
     187
    191188    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), nullptr));
    192189    mainFunc->setCallingConv(CallingConv::C);
    193190    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    194191    auto args = mainFunc->arg_begin();
    195    
     192
    196193    Value * const fileDescriptor = &*(args++);
    197194    fileDescriptor->setName("fileDescriptor");
    198    
     195
    199196    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
    200197    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb, segmentSize * bufferSegments);
    201198    sourceK->setInitialArguments({fileDescriptor});
    202199    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    203    
     200
    204201    StreamSetBuffer * LineBreakStream;
    205202    StreamSetBuffer * Matches;
    206203    std::tie(LineBreakStream, Matches) = grepPipeline(REs, ByteStream);
    207    
     204
    208205    kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance<kernel::PopcountKernel>(idb);
    209206    mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
     
    279276    auto & idb = mGrepDriver->getBuilder();
    280277    Module * M = idb->getModule();
    281    
     278
    282279    const auto segmentSize = codegen::SegmentSize;
    283280    const auto bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
    284281    const unsigned encodingBits = 8;
    285    
     282
    286283    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
    287284    mainFunc->setCallingConv(CallingConv::C);
    288285    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    289286    auto args = mainFunc->arg_begin();
    290    
     287
    291288    Value * const fileDescriptor = &*(args++);
    292289    fileDescriptor->setName("fileDescriptor");
    293290    Value * match_accumulator = &*(args++);
    294291    match_accumulator->setName("match_accumulator");
    295    
     292
    296293    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
    297294    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb, segmentSize * bufferSegments);
    298295    sourceK->setInitialArguments({fileDescriptor});
    299296    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    300    
     297
    301298    StreamSetBuffer * LineBreakStream;
    302299    StreamSetBuffer * Matches;
    303300    std::tie(LineBreakStream, Matches) = grepPipeline(REs, ByteStream);
    304    
     301
    305302    kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
    306303    scanMatchK->setInitialArguments({match_accumulator});
     
    308305    mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
    309306    mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
    310    
     307
    311308    mGrepDriver->generatePipelineIR();
    312309    mGrepDriver->deallocateBuffers();
     
    319316//  The doGrep methods apply a GrepEngine to a single file, processing the results
    320317//  differently based on the engine type.
    321    
     318
    322319uint64_t GrepEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
    323320    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor);
    324321    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    325    
     322
    326323    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx].get());
    327324    if (fileDescriptor == -1) return 0;
    328    
     325
    329326    uint64_t grepResult = f(fileDescriptor);
    330327    close(fileDescriptor);
     
    347344    }
    348345}
    349    
     346
    350347uint64_t MatchOnlyEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
    351348    uint64_t grepResult = GrepEngine::doGrep(fileName, fileIdx);
     
    359356    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor, intptr_t accum_addr);
    360357    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
    361    
     358
    362359    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx].get());
    363360    if (fileDescriptor == -1) return 0;
     
    404401// The process of searching a group of files may use a sequential or a task
    405402// parallel approach.
    406    
     403
    407404void * DoGrepThreadFunction(void *args) {
    408405    return reinterpret_cast<GrepEngine *>(args)->DoGrepThreadMethod();
     
    412409    const unsigned numOfThreads = Threads; // <- convert the command line value into an integer to allow stack allocation
    413410    pthread_t threads[numOfThreads];
    414    
     411
    415412    for(unsigned long i = 1; i < numOfThreads; ++i) {
    416413        const int rc = pthread_create(&threads[i], nullptr, DoGrepThreadFunction, (void *)this);
     
    420417    }
    421418    // Main thread also does the work;
    422    
     419
    423420    DoGrepThreadMethod();
    424421    for(unsigned i = 1; i < numOfThreads; ++i) {
     
    480477
    481478}
    482 
Note: See TracChangeset for help on using the changeset viewer.