Ignore:
Timestamp:
Oct 18, 2017, 9:35:52 AM (21 months ago)
Author:
cameron
Message:

Update scanmatch callback protocol to use line start/end pointers; add finalize callback for buffer end

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5678 r5694  
    5252    BasicBlock * const scanWordExit = iBuilder->CreateBasicBlock("ScanWordExit");
    5353    BasicBlock * const blocksExit = iBuilder->CreateBasicBlock("blocksExit");
     54    BasicBlock * const callFinalizeScan = iBuilder->CreateBasicBlock("callFinalizeScan");
     55    BasicBlock * const scanReturn = iBuilder->CreateBasicBlock("scanReturn");
    5456    IntegerType * const sizeTy = iBuilder->getSizeTy();
    5557    const unsigned fieldCount = iBuilder->getBitBlockWidth() / sizeTy->getBitWidth();
    5658    VectorType * const scanwordVectorType =  VectorType::get(sizeTy, fieldCount);
    5759    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    58     Constant * blockSizeLess1 = iBuilder->getSize(iBuilder->getBitBlockWidth() - 1);
    5960
    6061    Function::arg_iterator args = mCurrentMethod->arg_begin();
     
    6667    /* input_stream = */ args++;
    6768
    68     Value * blocksToDo = iBuilder->CreateUDiv(iBuilder->CreateAdd(itemsToDo, blockSizeLess1), blockSize);
     69    Value * blocksToDo = iBuilder->CreateUDivCeil(itemsToDo, blockSize);
    6970   
    7071    Value * match_result_ptr = iBuilder->CreateBitCast(match_result, scanwordVectorType->getPointerTo());
     
    154155            Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateCountForwardZeroes(phiMatchWord));
    155156            if (mGrepType == GrepType::CallBack) {
     157                Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    156158                Function * dispatcher = m->getFunction("accumulate_match_wrapper"); assert (dispatcher);
    157159                //Function * dispatcher = iBuilder->LinkFunction<void (intptr_t, size_t, size_t, size_t)>("accumulate_match_wrapper", & grep::accumulate_match_wrapper);
    158160                Value * accumulator = iBuilder->getScalarField("accumulator_address");
    159                 iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, matchRecordStart, matchRecordEnd});
     161                Value * start_ptr = iBuilder->CreateGEP(inputStream, matchRecordStart);
     162                Value * end_ptr = iBuilder->CreateGEP(inputStream, matchRecordEnd);
     163                iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, start_ptr, end_ptr});
    160164            }
    161165            else {
     
    225229
    226230    iBuilder->SetInsertPoint(blocksExit);
     231    iBuilder->CreateCondBr(iBuilder->CreateICmpULT(itemsToDo, blockSize), callFinalizeScan, scanReturn);
     232    iBuilder->SetInsertPoint(callFinalizeScan);
     233    if (mGrepType == GrepType::CallBack) {
     234        Value * bufSize = iBuilder->getBufferedSize("InputStream");
     235        Function * finalizer = m->getFunction("finalize_match_wrapper"); assert (finalizer);
     236        Value * accumulator = iBuilder->getScalarField("accumulator_address");
     237        Value * const buffer_base = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     238        Value * buffer_end_address = iBuilder->CreateGEP(buffer_base, bufSize);
     239        iBuilder->CreateCall(finalizer, {accumulator, buffer_end_address});
     240    }
     241    iBuilder->CreateBr(scanReturn);
     242    iBuilder->SetInsertPoint(scanReturn);
     243   
    227244}
    228245
Note: See TracChangeset for help on using the changeset viewer.