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

MatchAccumulator? objects to collect match results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.