Ignore:
Timestamp:
Oct 7, 2017, 4:59:20 PM (22 months ago)
Author:
cameron
Message:

MatchAccumulator? objects to collect match results

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

Legend:

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

    r5646 r5676  
    546546}
    547547
     548class CodepointAccumulator : public kernel::MatchAccumulator {
     549public:
     550   
     551    CodepointAccumulator(const char * searchBuffer) : mSearchBuffer(searchBuffer), mParsedCodePointSet(re::makeCC()) {}
     552   
     553    void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) override;
     554    re::CC * getCodePoints() {return mParsedCodePointSet;}
     555private:
     556    const char * mSearchBuffer;
     557    re::CC * mParsedCodePointSet;
     558};
     559   
     560void CodepointAccumulator::accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) {
     561    assert (line_start <= line_end);
     562    re::codepoint_t c = 0;
     563    size_t line_pos = line_start;
     564    while (isxdigit(mSearchBuffer[line_pos])) {
     565        assert (line_pos < line_end);
     566        if (isdigit(mSearchBuffer[line_pos])) {
     567            c = (c << 4) | (mSearchBuffer[line_pos] - '0');
     568        }
     569        else {
     570            c = (c << 4) | (tolower(mSearchBuffer[line_pos]) - 'a' + 10);
     571        }
     572        line_pos++;
     573    }
     574    assert(((line_pos - line_start) >= 4) && ((line_pos - line_start) <= 6)); // UCD format 4 to 6 hex digits.
     575    mParsedCodePointSet->insert(c);   
     576}
     577
     578
     579   
    548580re::CC * grepCodepoints(re::RE * pattern, char * UnicodeDataBuffer, size_t bufferLength) {
    549     parsedCodePointSet = re::makeCC();       
     581    //parsedCodePointSet = re::makeCC();       
    550582    const unsigned segmentSize = 8;
    551583
     
    590622    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
    591623   
    592     kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::NameExpression, 8));
    593     scanMatchK->setInitialArguments({idb->getInt32(0)});
     624    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::CallBack, 8));
     625    CodepointAccumulator accum(UnicodeDataBuffer);
     626    intptr_t accum_addr = (intptr_t) &accum;
     627    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), accum_addr)});
    594628    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
    595     pxDriver.LinkFunction(*scanMatchK, "matcher", &insert_codepoints);
    596629    pxDriver.generatePipelineIR();
    597630    pxDriver.deallocateBuffers();
     
    603636    f(UnicodeDataBuffer, bufferLength);
    604637   
    605     return parsedCodePointSet;   
     638    //return parsedCodePointSet;
     639    return accum.getCodePoints();
    606640}
    607641
     
    614648}
    615649
     650   
    616651
    617652const std::vector<std::string> & grepPropertyValues(const std::string& propertyName, re::RE * propertyValuePattern) {
  • icGREP/icgrep-devel/icgrep/grep_type.h

    r5418 r5676  
    1212    , NameExpression
    1313    , PropertyValue
     14    , CallBack
    1415};
    1516
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5630 r5676  
    88#include <llvm/IR/Module.h>
    99#include <kernels/kernel_builder.h>
     10#include <IR_Gen/FunctionTypeBuilder.h>
     11#include <llvm/Support/raw_ostream.h>
    1012
    1113using namespace llvm;
     
    2628        case GrepType::PropertyValue:
    2729            return "P";
     30        case GrepType::CallBack:
     31            return "C";
    2832        default:
    2933            llvm_unreachable("unknown grep type!");
    3034    }
    3135}
     36   
     37void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, size_t line_start, size_t line_end) {
     38    reinterpret_cast<MatchAccumulator *>(accum_addr)->accumulate_match(lineNum, line_start, line_end);
     39}
     40
    3241
    3342void ScanMatchKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> &iBuilder) {
    3443
    3544    Module * const m = iBuilder->getModule();
     45   
    3646    BasicBlock * const entryBlock = iBuilder->GetInsertBlock();
    3747    BasicBlock * const initialBlock = iBuilder->CreateBasicBlock("initialBlock");
     
    147157            phiRecordStart->addIncoming(matchRecordStart, loop_final_block);
    148158            Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateCountForwardZeroes(phiMatchWord));
    149 
    150             Function * const matcher = m->getFunction("matcher"); assert (matcher);
    151             auto args_matcher = matcher->arg_begin();
    152             Value * const mrn = iBuilder->CreateZExtOrTrunc(matchRecordNum, args_matcher->getType());
    153             Value * const mrs = iBuilder->CreateZExtOrTrunc(matchRecordStart, (++args_matcher)->getType());
    154             Value * const mre = iBuilder->CreateZExtOrTrunc(matchRecordEnd, (++args_matcher)->getType());
    155             Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    156             Value * const is = iBuilder->CreatePointerCast(inputStream, (++args_matcher)->getType());
    157             if (mGrepType == GrepType::Normal) {
    158                 Value * const sz = iBuilder->CreateZExtOrTrunc(iBuilder->getBufferedSize("InputStream"), (++args_matcher)->getType());
    159                 Value * const fi = iBuilder->CreateZExtOrTrunc(iBuilder->getScalarField("FileIdx"), (++args_matcher)->getType());
    160                 iBuilder->CreateCall(matcher, {mrn, mrs, mre, is, sz, fi});
    161             } else {
    162                 iBuilder->CreateCall(matcher, {mrn, mrs, mre, is});
     159            if (mGrepType == GrepType::CallBack) {
     160                Function * dispatcher = iBuilder->LinkFunction<void (intptr_t, size_t, size_t, size_t)>("accumulate_match_wrapper", & accumulate_match_wrapper);
     161                Value * accumulator = iBuilder->getScalarField("accumulator_address");
     162                iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, matchRecordStart, matchRecordEnd});
    163163            }
    164 
     164            else {
     165                Function * matcher = m->getFunction("matcher"); assert (matcher);
     166                auto args_matcher = matcher->arg_begin();
     167                Value * const mrn = iBuilder->CreateZExtOrTrunc(matchRecordNum, args_matcher->getType());
     168                Value * const mrs = iBuilder->CreateZExtOrTrunc(matchRecordStart, (++args_matcher)->getType());
     169                Value * const mre = iBuilder->CreateZExtOrTrunc(matchRecordEnd, (++args_matcher)->getType());
     170                Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     171                Value * const is = iBuilder->CreatePointerCast(inputStream, (++args_matcher)->getType());
     172                if (mGrepType == GrepType::Normal) {
     173                    Value * const sz = iBuilder->CreateZExtOrTrunc(iBuilder->getBufferedSize("InputStream"), (++args_matcher)->getType());
     174                    Value * const fi = iBuilder->CreateZExtOrTrunc(iBuilder->getScalarField("FileIdx"), (++args_matcher)->getType());
     175                    iBuilder->CreateCall(matcher, {mrn, mrs, mre, is, sz, fi});
     176                } else {
     177                    iBuilder->CreateCall(matcher, {mrn, mrs, mre, is});
     178                }
     179            }
    165180            Value * remaining_matches = iBuilder->CreateResetLowestBit(phiMatchWord);
    166181            phiMatchWord->addIncoming(remaining_matches, loop_final_block);
     
    219234    {Binding{b->getStreamSetTy(1, 1), "matchResult"}, Binding{b->getStreamSetTy(1, 1), "lineBreak"}, Binding{b->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    220235    {},
    221     {Binding{b->getInt32Ty(), "FileIdx"}},
     236    {},
    222237    {},
    223238    {Binding{b->getSizeTy(), "BlockNo"}, Binding{b->getSizeTy(), "LineNum"}})
    224239, mGrepType(grepType) {
    225 
    226 }
    227 
    228 }
     240    if (mGrepType == GrepType::CallBack) {
     241        mScalarInputs.push_back(Binding{b->getIntAddrTy(), "accumulator_address"});
     242    }
     243    else {
     244        mScalarInputs.push_back(Binding{b->getInt32Ty(), "FileIdx"});
     245    }
     246}
     247
     248}
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5526 r5676  
    1414namespace kernel {
    1515   
     16
     17class MatchAccumulator {
     18public:
     19    MatchAccumulator() {};
     20    virtual void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) = 0;
     21};
     22
     23   
    1624class ScanMatchKernel : public MultiBlockKernel {
    1725public:
Note: See TracChangeset for help on using the changeset viewer.