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/lz4_bytestream_decoder.cpp

    r5436 r5440  
    1111using namespace kernel;
    1212
    13 Value * getInputPtr(IDISA::IDISA_Builder * const iBuilder, Value * blockStartPtr, Value * offset) {
     13Value * getInputPtr(const std::unique_ptr<KernelBuilder> & iBuilder, Value * blockStartPtr, Value * offset) {
    1414    return iBuilder->CreateGEP(
    1515            iBuilder->CreatePointerCast(blockStartPtr, iBuilder->getInt32Ty()->getPointerTo()),
     
    1818}
    1919
    20 Value * selectMin(IDISA::IDISA_Builder * const iBuilder, Value * a, Value * b) {
     20Value * selectMin(const std::unique_ptr<KernelBuilder> & iBuilder, Value * a, Value * b) {
    2121    return iBuilder->CreateSelect(iBuilder->CreateICmpULT(a, b), a, b);
    2222}
    2323
    24 void LZ4ByteStreamDecoderKernel::generateDoBlockMethod() {
     24void LZ4ByteStreamDecoderKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    2525    BasicBlock * entry_block = iBuilder->GetInsertBlock();
    26     BasicBlock * loopBody = CreateBasicBlock("bytestream_block_loop_body");
    27     BasicBlock * loopExit = CreateBasicBlock("bytestream_block_loop_exit");
     26    BasicBlock * loopBody = iBuilder->CreateBasicBlock("bytestream_block_loop_body");
     27    BasicBlock * loopExit = iBuilder->CreateBasicBlock("bytestream_block_loop_exit");
    2828
    2929    Value * bufferSize = iBuilder->getSize(mBufferSize);
     
    3131    Value * iterations = selectMin(iBuilder,
    3232            iBuilder->getSize(iBuilder->getBitBlockWidth()),
    33             iBuilder->CreateSub(getAvailableItemCount("literalIndexes"), getProcessedItemCount("literalIndexes")));
    34     Value * inputBufferBasePtr = getRawInputPointer("inputStream", iBuilder->getSize(0), iBuilder->getSize(0));
    35     Value * outputBufferBasePtr = getRawOutputPointer("outputStream", iBuilder->getSize(0), iBuilder->getSize(0));
     33            iBuilder->CreateSub(iBuilder->getAvailableItemCount("literalIndexes"), iBuilder->getProcessedItemCount("literalIndexes")));
     34    Value * inputBufferBasePtr = iBuilder->getRawInputPointer("inputStream", iBuilder->getSize(0), iBuilder->getSize(0));
     35    Value * outputBufferBasePtr = iBuilder->getRawOutputPointer("outputStream", iBuilder->getSize(0), iBuilder->getSize(0));
    3636    iBuilder->CreateBr(loopBody);
    3737
     
    4343    // Indexes extraction.
    4444    Value * literalStartPtr = getInputPtr(iBuilder,
    45             getInputStreamBlockPtr("literalIndexes", iBuilder->getSize(0)), phiInputIndex);
     45            iBuilder->getInputStreamBlockPtr("literalIndexes", iBuilder->getSize(0)), phiInputIndex);
    4646    Value * literalLengthPtr = getInputPtr(iBuilder,
    47             getInputStreamBlockPtr("literalIndexes", iBuilder->getSize(1)), phiInputIndex);
     47            iBuilder->getInputStreamBlockPtr("literalIndexes", iBuilder->getSize(1)), phiInputIndex);
    4848    Value * matchOffsetPtr = getInputPtr(iBuilder,
    49             getInputStreamBlockPtr("matchIndexes", iBuilder->getSize(0)), phiInputIndex);
     49            iBuilder->getInputStreamBlockPtr("matchIndexes", iBuilder->getSize(0)), phiInputIndex);
    5050    Value * matchLengthPtr = getInputPtr(iBuilder,
    51             getInputStreamBlockPtr("matchIndexes", iBuilder->getSize(1)), phiInputIndex);
     51            iBuilder->getInputStreamBlockPtr("matchIndexes", iBuilder->getSize(1)), phiInputIndex);
    5252    Value * literalStart = iBuilder->CreateZExt(iBuilder->CreateLoad(literalStartPtr), iBuilder->getSizeTy());
    5353    Value * literalLength = iBuilder->CreateZExt(iBuilder->CreateLoad(literalLengthPtr), iBuilder->getSizeTy());
     
    5656
    5757#if 0
    58     Value * processedItem = iBuilder->CreateAdd(getProcessedItemCount("literalIndexes"), phiInputIndex);
     58    Value * processedItem = iBuilder->CreateAdd(iBuilder->getProcessedItemCount("literalIndexes"), phiInputIndex);
    5959    iBuilder->CallPrintInt("ProccessedItem", processedItem);
    6060    iBuilder->CallPrintInt("LiteralStart", literalStart);
     
    6666    // =================================================
    6767    // Literals.
    68     Value * outputItems = getProducedItemCount("outputStream");
     68    Value * outputItems = iBuilder->getProducedItemCount("outputStream");
    6969    Value * bufferOffset = iBuilder->CreateAnd(outputItems, bufferSizeMask);
    7070    Value * remainingBuffer = iBuilder->CreateSub(bufferSize, bufferOffset);
     
    9494            iBuilder->getSize(4)
    9595            );
    96     BasicBlock * cpyLoopCond = CreateBasicBlock("matchcopy_loop_cond");
    97     BasicBlock * cpyLoopBody = CreateBasicBlock("matchcopy_loop_body");
    98     BasicBlock * cpyLoopExit = CreateBasicBlock("matchcopy_loop_exit");
     96    BasicBlock * cpyLoopCond = iBuilder->CreateBasicBlock("matchcopy_loop_cond");
     97    BasicBlock * cpyLoopBody = iBuilder->CreateBasicBlock("matchcopy_loop_body");
     98    BasicBlock * cpyLoopExit = iBuilder->CreateBasicBlock("matchcopy_loop_exit");
    9999    iBuilder->CreateBr(cpyLoopCond);
    100100
     
    117117    iBuilder->CallPrintIntToStderr("dstOffset", phiDstOffset);
    118118#endif
    119     BasicBlock * reachingBufferEnd_then = CreateBasicBlock("matchcopy_reaching_buf_end_then");
    120     BasicBlock * reachingBufferEnd_else = CreateBasicBlock("matchcopy_reaching_buf_end_else");
     119    BasicBlock * reachingBufferEnd_then = iBuilder->CreateBasicBlock("matchcopy_reaching_buf_end_then");
     120    BasicBlock * reachingBufferEnd_else = iBuilder->CreateBasicBlock("matchcopy_reaching_buf_end_else");
    121121    Value * distSrcEnd = iBuilder->CreateSub(bufferSize, phiSrcOffset);
    122122    Value * distDstEnd = iBuilder->CreateSub(bufferSize, phiDstOffset);
     
    170170    iBuilder->SetInsertPoint(cpyLoopExit);
    171171    outputItems = iBuilder->CreateAdd(outputItems, matchLength);
    172     setProducedItemCount("outputStream", outputItems);
     172    iBuilder->setProducedItemCount("outputStream", outputItems);
    173173
    174174    Value * newInputIndex = iBuilder->CreateAdd(phiInputIndex, iBuilder->getSize(1));
     
    182182    iBuilder->SetInsertPoint(loopExit);
    183183#ifndef NDEBUG
    184     iBuilder->CallPrintInt("Decompressed bytes", getProducedItemCount("outputStream"));
     184    iBuilder->CallPrintInt("Decompressed bytes", iBuilder->getProducedItemCount("outputStream"));
    185185#endif
    186186}
Note: See TracChangeset for help on using the changeset viewer.