Changeset 5698


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

Modularization progress

Location:
icGREP/icgrep-devel/icgrep
Files:
7 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() {
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5697 r5698  
    4444
    4545
    46     ~GrepEngine();
     46    virtual ~GrepEngine();
    4747   
    4848    void initFileResult(std::vector<std::string> filenames);
    4949   
    50     void grepCodeGen(std::vector<re::RE *> REs, GrepModeType grepMode);
     50    virtual void grepCodeGen(std::vector<re::RE *> REs);
    5151
    5252    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
     
    6969};
    7070
     71class CountOnlyGrepEngine : public GrepEngine {
     72public:
    7173   
     74    CountOnlyGrepEngine() : GrepEngine() {}
     75    void grepCodeGen(std::vector<re::RE *> REs) override;
     76   
     77};
     78
    7279}
    7380
  • icGREP/icgrep-devel/icgrep/grep_interface.cpp

    r5697 r5698  
    210210
    211211int MaxCountFlag;
    212 static cl::opt<int, true> MaxCountOption("m", cl::location(MaxCountFlag), cl::desc("Process only the first <num> matches per file."), cl::cat(Output_Options), cl::Grouping);
     212static cl::opt<int, true> MaxCountOption("m", cl::location(MaxCountFlag),
     213                                         cl::desc("Process only the first <num> matches per file3."),
     214                                         cl::cat(Output_Options), cl::Grouping);
    213215static cl::alias MaxCountAlias("max-count", cl::desc("Alias for -m"), cl::aliasopt(MaxCountOption));
    214216   
     
    307309        llvm::report_fatal_error("Sorry, -color is not yet supported.\n");
    308310    }
     311    if (Mode == QuietMode) {
     312        NoMessagesFlag = true;
     313    }
    309314    if ((Mode == QuietMode) | (Mode == FilesWithMatch) | (Mode == FilesWithoutMatch)) {
    310315        MaxCountFlag = 1;
  • icGREP/icgrep-devel/icgrep/grep_interface.h

    r5480 r5698  
    7777extern BinaryFilesMode BinaryFilesFlag;
    7878   
    79 extern bool NoMessagesFlag; // -s
     79extern bool NoMessagesFlag; // -s  (also set by QuietMode/-q)
    8080extern bool WithFilenameFlag; // -H
    8181extern bool NoFilenameFlag; // -h
     
    9292extern int BeforeContextFlag; // -B
    9393extern int ContextFlag; // -C
    94 extern int MaxCountFlag; // -m
     94extern int MaxCountFlag; // -m  (overridden and set to 1 with -q, -l, -L modes)
    9595   
    9696
  • icGREP/icgrep-devel/icgrep/grep_options.py

    r5480 r5698  
    6161                  [integer, "B", "before-context", "Print <num>lines of context before each matching line.", "Output_Options"],
    6262                  [integer, "C", "context", "Print <num> lines of context before and after each matching line.", "Output_Options"],
    63                   [integer, "m", "max-count", "Process only the first <num> matches per file.", "Output_Options"]]
     63                  [integer, "m", "max-count", "Process only the first <num> matches per file (overridden and set to 1 in -q, -l, -L modes).", "Output_Options"]]
    6464
    6565
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5695 r5698  
    185185    }
    186186
    187     grep::GrepEngine grepEngine;
     187    grep::GrepEngine * grepEngine;
     188   
     189    if (grep::Mode == grep::NormalMode) {
     190        grepEngine = new grep::GrepEngine();
     191    }
     192    else {
     193        grepEngine = new grep::CountOnlyGrepEngine();
     194    }
    188195
    189196               
    190     grepEngine.grepCodeGen(REs, grep::Mode);
    191 
    192     grepEngine.initFileResult(allFiles);
     197    grepEngine->grepCodeGen(REs);
     198
     199    grepEngine->initFileResult(allFiles);
    193200
    194201    if (Threads <= 1) {
    195202        for (unsigned i = 0; i != allFiles.size(); ++i) {
    196             grepEngine.doGrep(allFiles[i], i);
     203            grepEngine->doGrep(allFiles[i], i);
    197204        }
    198205    } else if (Threads > 1) {
     
    201208
    202209        for(unsigned long i = 0; i < numOfThreads; ++i){
    203             const int rc = pthread_create(&threads[i], nullptr, grep::DoGrepThreadFunction, (void *)&grepEngine);
     210            const int rc = pthread_create(&threads[i], nullptr, grep::DoGrepThreadFunction, (void *)grepEngine);
    204211            if (rc) {
    205212                llvm::report_fatal_error("Failed to create thread: code " + std::to_string(rc));
     
    216223
    217224   
    218     grepEngine.PrintResults();
     225    grepEngine->PrintResults();
     226   
     227    delete(grepEngine);
    219228   
    220229    return 0;
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r5683 r5698  
    2424#include <UCD/resolve_properties.h>
    2525#include <UCD/CaseFolding.h>
    26 #include <grep_engine.h>
    2726#include <sstream>
    2827#include <string>
     
    3231#include <llvm/Support/ErrorHandling.h>
    3332#include <llvm/Support/raw_ostream.h>
     33#include <llvm/ADT/STLExtras.h> // for make_unique
    3434
    3535using namespace llvm;
     
    3737namespace re {
    3838
    39 template<typename T, typename... Args>
    40 std::unique_ptr<T> make_unique(Args&&... args) {
    41     return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
    42 }
    4339
    4440RE * RE_Parser::parse(const std::string & regular_expression, ModeFlagSet initialFlags, RE_Syntax syntax, bool ByteMode) {
Note: See TracChangeset for help on using the changeset viewer.