Ignore:
Timestamp:
May 10, 2017, 4:26:11 PM (2 years ago)
Author:
nmedfort
Message:

Large refactoring step. Removed IR generation code from Kernel (formally KernelBuilder?) and moved it into the new KernelBuilder? class.

File:
1 edited

Legend:

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

    r5436 r5440  
    3131}
    3232
    33 void ScanMatchKernel::generateDoBlockMethod() {
     33void ScanMatchKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> &iBuilder) {
    3434
    3535    Module * const m = iBuilder->getModule();
    3636    BasicBlock * const entryBlock = iBuilder->GetInsertBlock();
    37     BasicBlock * const scanWordIteration = CreateBasicBlock("ScanWordIteration");
    38     BasicBlock * const matches_test_block = CreateBasicBlock("matches_test_block");
    39     BasicBlock * const processMatchesEntry = CreateBasicBlock("process_matches_loop");
    40     BasicBlock * const prior_breaks_block = CreateBasicBlock("prior_breaks_block");
    41     BasicBlock * const loop_final_block = CreateBasicBlock("loop_final_block");
    42     BasicBlock * const processMatchesExit = CreateBasicBlock("matches_done_block");
    43     BasicBlock * const remaining_breaks_block = CreateBasicBlock("remaining_breaks_block");
    44     BasicBlock * const return_block = CreateBasicBlock("return_block");
    45     BasicBlock * const scanWordExit = CreateBasicBlock("ScanWordExit");
     37    BasicBlock * const scanWordIteration = iBuilder->CreateBasicBlock("ScanWordIteration");
     38    BasicBlock * const matches_test_block = iBuilder->CreateBasicBlock("matches_test_block");
     39    BasicBlock * const processMatchesEntry = iBuilder->CreateBasicBlock("process_matches_loop");
     40    BasicBlock * const prior_breaks_block = iBuilder->CreateBasicBlock("prior_breaks_block");
     41    BasicBlock * const loop_final_block = iBuilder->CreateBasicBlock("loop_final_block");
     42    BasicBlock * const processMatchesExit = iBuilder->CreateBasicBlock("matches_done_block");
     43    BasicBlock * const remaining_breaks_block = iBuilder->CreateBasicBlock("remaining_breaks_block");
     44    BasicBlock * const return_block = iBuilder->CreateBasicBlock("return_block");
     45    BasicBlock * const scanWordExit = iBuilder->CreateBasicBlock("ScanWordExit");
    4646    IntegerType * const sizeTy = iBuilder->getSizeTy();
    4747    const unsigned fieldCount = iBuilder->getBitBlockWidth() / sizeTy->getBitWidth();
    4848    VectorType * const scanwordVectorType =  VectorType::get(sizeTy, fieldCount);
    49     Value * const blockNo = getScalarField("BlockNo");
     49    Value * const blockNo = iBuilder->getScalarField("BlockNo");
    5050    Value * const scanwordPos = iBuilder->CreateShl(blockNo, floor_log2(iBuilder->getBitBlockWidth()));
    51     Value * const lastRecordStart = getProcessedItemCount("InputStream");
    52     Value * const lastRecordNum = getScalarField("LineNum");
    53 
    54     Value * const matches = iBuilder->CreateBitCast(loadInputStreamBlock("matchResult", iBuilder->getInt32(0)), scanwordVectorType);
    55     Value * const linebreaks = iBuilder->CreateBitCast(loadInputStreamBlock("lineBreak", iBuilder->getInt32(0)), scanwordVectorType);
     51    Value * const lastRecordStart = iBuilder->getProcessedItemCount("InputStream");
     52    Value * const lastRecordNum = iBuilder->getScalarField("LineNum");
     53
     54    Value * const matches = iBuilder->CreateBitCast(iBuilder->loadInputStreamBlock("matchResult", iBuilder->getInt32(0)), scanwordVectorType);
     55    Value * const linebreaks = iBuilder->CreateBitCast(iBuilder->loadInputStreamBlock("lineBreak", iBuilder->getInt32(0)), scanwordVectorType);
    5656
    5757    iBuilder->CreateBr(scanWordIteration);
     
    105105                // PRIOR_BREAKS_BLOCK
    106106                // If there are prior breaks, we count them and compute the record start position.
    107                 iBuilder->SetInsertPoint(prior_breaks_block);               
     107                iBuilder->SetInsertPoint(prior_breaks_block);
    108108                Value * matchedRecordNum = iBuilder->CreateAdd(iBuilder->CreatePopcount(prior_breaks), phiRecordNum);
    109109                Value * reverseDistance = iBuilder->CreateCountReverseZeroes(prior_breaks);
     
    132132            Value * const mrs = iBuilder->CreateZExtOrTrunc(matchRecordStart, (++args)->getType());
    133133            Value * const mre = iBuilder->CreateZExtOrTrunc(matchRecordEnd, (++args)->getType());
    134             Value * const inputStream = getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     134            Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    135135            Value * const is = iBuilder->CreatePointerCast(inputStream, (++args)->getType());
    136136            if (mGrepType == GrepType::Normal) {
    137                 Value * const sz = iBuilder->CreateZExtOrTrunc(getBufferedSize("InputStream"), (++args)->getType());
    138                 Value * const fi = iBuilder->CreateZExtOrTrunc(getScalarField("FileIdx"), (++args)->getType());
     137                Value * const sz = iBuilder->CreateZExtOrTrunc(iBuilder->getBufferedSize("InputStream"), (++args)->getType());
     138                Value * const fi = iBuilder->CreateZExtOrTrunc(iBuilder->getScalarField("FileIdx"), (++args)->getType());
    139139                iBuilder->CreateCall(matcher, {mrn, mrs, mre, is, sz, fi});
    140140            } else {
     
    184184
    185185    iBuilder->SetInsertPoint(scanWordExit);
    186     setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, ConstantInt::get(blockNo->getType(), 1)));
    187     setScalarField("LineNum", phiFinalRecordNum);
    188     setProcessedItemCount("InputStream", phiFinalRecordStart);
     186    iBuilder->setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, ConstantInt::get(blockNo->getType(), 1)));
     187    iBuilder->setScalarField("LineNum", phiFinalRecordNum);
     188    iBuilder->setProcessedItemCount("InputStream", phiFinalRecordStart);
    189189}
    190190
Note: See TracChangeset for help on using the changeset viewer.