Changeset 5025


Ignore:
Timestamp:
May 3, 2016, 5:53:12 PM (17 months ago)
Author:
xuedongx
Message:

If '-c', ignore the scanmatch kernel.

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

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

    r5021 r5025  
    6969}
    7070
    71 void GrepEngine::doGrep(const std::string & fileName, const int fileIdx) {
     71void GrepEngine::doGrep(const std::string & fileName, const int fileIdx, bool CountOnly, std::vector<int> & total_CountOnly) {
    7272    const path file(fileName);
    7373    if (exists(file)) {
     
    8989        }
    9090        char * fileBuffer = const_cast<char *>(file.data());
    91         mGrepFunction(fileBuffer, fileSize, fileIdx, finalLineIsUnterminated(fileBuffer, fileSize));
     91        if(CountOnly){
     92            total_CountOnly[fileIdx] = mGrepFunction_CountOnly(fileBuffer, fileSize, fileIdx, finalLineIsUnterminated(fileBuffer, fileSize));
     93        }
     94        else{
     95            mGrepFunction(fileBuffer, fileSize, fileIdx, finalLineIsUnterminated(fileBuffer, fileSize));
     96        }
    9297        file.close();
    9398    }
    9499    else {
    95         mGrepFunction(nullptr, 0, fileIdx, false);
     100        if(CountOnly) {
     101            mGrepFunction_CountOnly(nullptr, 0, fileIdx, false);
     102        }
     103        else{
     104            mGrepFunction(nullptr, 0, fileIdx, false);
     105        }
    96106    }
    97107}
    98108
    99109
    100 void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression) {
    101                            
     110void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool isNameExpression) {
    102111    Module * M = new Module(moduleName, getGlobalContext());
    103112   
     
    114123    pipelineBuilder.CreateKernels(function, isNameExpression);
    115124
    116     llvm::Function * grepIR = pipelineBuilder.ExecuteKernels();
     125    llvm::Function * grepIR = pipelineBuilder.ExecuteKernels(CountOnly);
    117126
    118127    mEngine = JIT_to_ExecutionEngine(M);
     
    125134    delete idb;
    126135
    127     mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(grepIR));
     136    if(CountOnly){
     137        mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(mEngine->getPointerToFunction(grepIR));
     138    }
     139    else{
     140        mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(grepIR));
     141    }
     142
    128143}
    129144
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5017 r5025  
    1717class GrepEngine {
    1818    typedef void (*GrepFunctionType)(char * byte_data, size_t filesize, const int fileIdx, uint64_t finalLineUnterminated);
     19    typedef int64_t (*GrepFunctionType_CountOnly)(char * byte_data, size_t filesize, const int fileIdx, uint64_t finalLineUnterminated);
    1920public:
    2021
     
    2324    ~GrepEngine();
    2425 
    25     void grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression = false);
     26    void grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool isNameExpression = false);
    2627   
    27     void doGrep(const std::string & fileName, const int fileIdx);
     28    void doGrep(const std::string & fileName, const int fileIdx, bool CountOnly, std::vector<int> & total_CountOnly);
    2829   
    2930    re::CC *  grepCodepoints();
     
    3435
    3536    GrepFunctionType mGrepFunction;
    36    
     37    GrepFunctionType_CountOnly mGrepFunction_CountOnly;
     38
    3739    bool mIsNameExpression;
    3840    llvm::ExecutionEngine * mEngine;
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5017 r5025  
    66
    77#include <cstdio>
    8 
     8#include <vector>
    99#include <llvm/Support/CommandLine.h>
    1010#include <re/re_alt.h>
     
    1919
    2020#include <iostream> // MEEE
     21static cl::OptionCategory CountOnlyOptions("CountOnly Option",
     22                                       "This option controls the output.");
     23static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(CountOnlyOptions));
     24static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
    2125
    2226static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
     
    9195}
    9296
     97std::vector<int> total_CountOnly;
    9398std::mutex count_mutex;
    9499size_t fileCount;
     
    104109
    105110    while (fileIdx < inputFiles.size()){
    106         grepEngine->doGrep(inputFiles[fileIdx], fileIdx);
     111        grepEngine->doGrep(inputFiles[fileIdx], fileIdx, CountOnly, total_CountOnly);
    107112       
    108113        count_mutex.lock();
     
    236241   
    237242    GrepEngine grepEngine;
    238     grepEngine.grepCodeGen(module_name, re_ast);
    239 
     243    grepEngine.grepCodeGen(module_name, re_ast, CountOnly);
     244   
    240245    initResult(inputFiles);
     246    for (int i=0; i<inputFiles.size(); i++){
     247        total_CountOnly.push_back(0);
     248    }
     249
    241250    if (Threads <= 1) {
    242251        for (unsigned i = 0; i != inputFiles.size(); ++i) {
    243             grepEngine.doGrep(inputFiles[i], i);
     252            grepEngine.doGrep(inputFiles[i], i, CountOnly, total_CountOnly);
    244253        }       
    245254    } else if (Threads > 1) {
     
    262271        }
    263272    }
    264     PrintResult();   
     273    PrintResult(CountOnly, total_CountOnly);
    265274   
    266275    return 0;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5017 r5025  
    1616
    1717#include <llvm/Support/CommandLine.h>
     18#include <llvm/IR/Intrinsics.h>
    1819
    1920static cl::opt<unsigned> SegmentSize("segment-size", cl::desc("Segment Size"), cl::value_desc("positive integer"), cl::init(1));
     
    5758}
    5859
    59 Function * PipelineBuilder::ExecuteKernels() {
     60Value * generatePopcount(IDISA::IDISA_Builder * iBuilder, Value * bits) {
     61    Value * ctpopFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::ctpop, bits->getType());
     62    return iBuilder->CreateCall(ctpopFunc, std::vector<Value *>({bits}));
     63}
     64
     65Value * Cal_Count(Instance * icGrepInstance, IDISA::IDISA_Builder * iBuilder, int mBlockSize) {
     66    const unsigned index = 0;
     67    const unsigned streamOffset = 0;
     68    Value * match = (icGrepInstance->getOutputStream(index, streamOffset));
     69    Value * temp = iBuilder->CreateLoad(match);
     70    Value * matches = iBuilder->CreateBitCast(temp, iBuilder->getIntNTy(mBlockSize));
     71    Value * popcount = generatePopcount(iBuilder, matches);
     72    return popcount;
     73}
     74
     75Function * PipelineBuilder::ExecuteKernels(bool CountOnly) {
    6076    Type * const int64ty = iBuilder->getInt64Ty();
    6177    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     
    95111    BasicBlock * exitBlock = BasicBlock::Create(mMod->getContext(), "exit", main, 0);
    96112
     113    Value * count = iBuilder->CreateAlloca (Type::getIntNTy(mMod->getContext(), mBlockSize), nullptr, "count");
     114    Value * num = ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 0);
     115    iBuilder->CreateStore(num, count, false);
     116
    97117    Instance * s2pInstance = mS2PKernel->instantiate(inputStream);
    98118    Instance * icGrepInstance = mICgrepKernel->instantiate(s2pInstance->getOutputStreamBuffer());
    99119    Instance * scanMatchInstance = mScanMatchKernel->instantiate(icGrepInstance->getOutputStreamBuffer());
    100 
    101     scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
    102     scanMatchInstance->setInternalState("FileSize", bufferSize);
    103     scanMatchInstance->setInternalState("FileIdx", fileIdx);
    104 
     120   
     121    if(!CountOnly) {
     122        scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
     123        scanMatchInstance->setInternalState("FileSize", bufferSize);
     124        scanMatchInstance->setInternalState("FileIdx", fileIdx);
     125    }
    105126    Value * initialBufferSize = nullptr;
    106127    BasicBlock * initialBlock = nullptr;
     
    120141        for (unsigned i = 0; i < segmentSize; ++i) {
    121142            icGrepInstance->CreateDoBlockCall();
     143            if(CountOnly){
     144                Value * popcount_for = Cal_Count(icGrepInstance, iBuilder, mBlockSize);
     145                Value * temp_countfor = iBuilder->CreateLoad(count);
     146                Value * add_for = iBuilder->CreateAdd(temp_countfor, popcount_for);
     147                iBuilder->CreateStore(add_for, count);
     148            }
    122149        }
    123         for (unsigned i = 0; i < segmentSize; ++i) {
    124             scanMatchInstance->CreateDoBlockCall();
    125         }
     150        if(!CountOnly) {
     151            for (unsigned i = 0; i < segmentSize; ++i) {
     152                scanMatchInstance->CreateDoBlockCall();
     153            }
     154        }
    126155        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
    127156        iBuilder->CreateBr(segmentCondBlock);
     
    145174    s2pInstance->CreateDoBlockCall();
    146175    icGrepInstance->CreateDoBlockCall();
    147     scanMatchInstance->CreateDoBlockCall();
     176    if(CountOnly){
     177        Value * popcount = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
     178        Value * temp_count = iBuilder->CreateLoad(count);
     179        Value * add = iBuilder->CreateAdd(temp_count, popcount);
     180        iBuilder->CreateStore(add, count);
     181    }
     182
     183    if(!CountOnly) {
     184        scanMatchInstance->CreateDoBlockCall();
     185    }
    148186
    149187    remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), fullBodyBlock);
     
    189227
    190228    icGrepInstance->CreateDoBlockCall();
    191     scanMatchInstance->CreateDoBlockCall();
    192     iBuilder->CreateRetVoid();
     229    if(CountOnly){
     230        Value * popcount1 = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
     231        Value * temp_count1 = iBuilder->CreateLoad(count);
     232        Value * add1 = iBuilder->CreateAdd(temp_count1, popcount1);
     233        iBuilder->CreateStore(add1, count);
     234    }
     235    if(!CountOnly) {
     236        scanMatchInstance->CreateDoBlockCall();
     237    }
     238    if(CountOnly){
     239        Value * Ret = iBuilder->CreateLoad(count);
     240        iBuilder->CreateRet(Ret);
     241    }
     242    else{
     243        iBuilder->CreateRetVoid();
     244    }
     245
    193246
    194247    return main;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r4986 r5025  
    3131
    3232        void CreateKernels(pablo::PabloFunction * function, bool isNameExpression);
    33     llvm::Function * ExecuteKernels();
     33    llvm::Function * ExecuteKernels(bool CountOnly);
    3434
    3535private:
  • icGREP/icgrep-devel/icgrep/toolchain.cpp

    r5017 r5025  
    3232                                      "These options control the output.");
    3333
    34 static cl::opt<bool> CountOnly("c", cl::desc("Count and display the matching lines per file only."), cl::cat(bGrepOutputOptions));
    35 static cl::alias CountOnlyLong("count", cl::desc("Alias for -c"), cl::aliasopt(CountOnly));
    3634static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
    3735
     
    150148        int idx = fileIdx;
    151149
    152         if(CountOnly){
    153             total_count[idx]++;
    154             return;
    155         }
    156 
    157150        if (ShowFileNames) {
    158151            resultStrs[idx] << inputFiles[idx] << ':';
     
    200193}
    201194
    202 void PrintResult(){
     195void PrintResult(bool CountOnly, std::vector<int> & total_CountOnly){
    203196    if(CountOnly){
    204197        if (!ShowFileNames) {
    205198           for (int i=0; i<inputFiles.size(); i++){
    206                std::cout << total_count[i] << std::endl;
     199               std::cout << total_CountOnly[i] << std::endl;
    207200           }
    208201        }
    209202        else {
    210203            for (int i=0; i<inputFiles.size(); i++){
    211                 std::cout << inputFiles[i] << ':' << total_count[i] << std::endl;
     204                std::cout << inputFiles[i] << ':' << total_CountOnly[i] << std::endl;
    212205            };
    213206        }
  • icGREP/icgrep-devel/icgrep/toolchain.h

    r5015 r5025  
    2323
    2424void initResult(std::vector<std::string> filenames);
    25 void PrintResult();
     25void PrintResult(bool CountOnly, std::vector<int> & total_CountOnly);
    2626
    2727#endif
Note: See TracChangeset for help on using the changeset viewer.