Ignore:
Timestamp:
Jun 13, 2016, 11:12:08 AM (3 years ago)
Author:
cameron
Message:

s2p kernel with new infrastructure, includes s2p_FinalBlock

File:
1 edited

Legend:

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

    r5046 r5051  
    148148}
    149149   
    150    
    151    
    152 }
     150std::unique_ptr<llvm::Module> s2pKernel::createKernelModule() {
     151    std::unique_ptr<llvm::Module> theModule = KernelInterface::createKernelModule();
     152   
     153    /***********************
     154     WARNING iBuilder has a different module than theModule at this point.
     155    ***********************/
     156    Function * doBlockFunction = theModule.get()->getFunction(mKernelName + "_DoBlock");
     157   
     158    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
     159   
     160    Value * byteStreamBlock_ptr = getParameter(doBlockFunction, "byteStream");
     161    Value * basisBitsBlock_ptr = getParameter(doBlockFunction, "basisBits");
     162    Value * s_bytepack[8];
     163    for (unsigned i = 0; i < 8; i++) {
     164        s_bytepack[i] = iBuilder->CreateBlockAlignedLoad(byteStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     165    }
     166    Value * p_bitblock[8];
     167    s2p(iBuilder, s_bytepack, p_bitblock);
     168    for (unsigned j = 0; j < 8; ++j) {
     169        iBuilder->CreateBlockAlignedStore(p_bitblock[j], basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     170    }
     171    iBuilder->CreateRetVoid();
     172
     173    /* Now the prepare the s2p final block function:
     174     assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
     175     if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
     176     */
     177    Function * finalBlockFunction = theModule.get()->getFunction(mKernelName + "_FinalBlock");
     178    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
     179
     180    Value * self = getParameter(finalBlockFunction, "self");
     181    Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
     182    byteStreamBlock_ptr = getParameter(finalBlockFunction, "byteStream");
     183    basisBitsBlock_ptr = getParameter(finalBlockFunction, "basisBits");
     184   
     185    BasicBlock * finalPartialBlock = BasicBlock::Create(iBuilder->getContext(), "partial", finalBlockFunction, 0);
     186    BasicBlock * finalEmptyBlock = BasicBlock::Create(iBuilder->getContext(), "empty", finalBlockFunction, 0);
     187    BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), "exit", finalBlockFunction, 0);
     188   
     189    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, ConstantInt::get(iBuilder->getInt64Ty(), 0));
     190    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
     191    iBuilder->SetInsertPoint(finalPartialBlock);
     192    iBuilder->CreateCall(doBlockFunction, {self, byteStreamBlock_ptr, basisBitsBlock_ptr});
     193   
     194    iBuilder->CreateBr(exitBlock);
     195   
     196    iBuilder->SetInsertPoint(finalEmptyBlock);
     197    iBuilder->CreateStore(Constant::getNullValue(basisBitsBlock_ptr->getType()->getPointerElementType()), basisBitsBlock_ptr);
     198    iBuilder->CreateBr(exitBlock);
     199   
     200    iBuilder->SetInsertPoint(exitBlock);
     201    iBuilder->CreateRetVoid();
     202
     203    return theModule;
     204}
     205
     206   
     207}
Note: See TracChangeset for help on using the changeset viewer.