Ignore:
Timestamp:
Jan 28, 2017, 3:12:03 PM (3 years ago)
Author:
nmedfort
Message:

Start of work to simplify kernel writing. Removed generateDoBlockLogic method.

File:
1 edited

Legend:

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

    r5283 r5285  
    9292#endif
    9393   
    94    
    9594#if 0
    96 
    97 
    9895void generateS2P_16Kernel(Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder) {
    9996    kBuilder->addInputStream(16, "unit_pack");
     
    121118    }
    122119    kBuilder->finalize();
    123 }
    124    
     120}   
    125121#endif
    126122   
    127 void S2PKernel::generateFinalBlockMethod() const {
    128     /* Prepare the s2p final block function:
    129      assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
    130      if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
    131      */
    132     auto savePoint = iBuilder->saveIP();
    133     Module * m = iBuilder->getModule();
    134     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    135     Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    136     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
    137    
    138     Value * self = getParameter(finalBlockFunction, "self");
    139     Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
    140    
    141     BasicBlock * finalPartialBlock = BasicBlock::Create(iBuilder->getContext(), "partial", finalBlockFunction, 0);
    142     BasicBlock * finalEmptyBlock = BasicBlock::Create(iBuilder->getContext(), "empty", finalBlockFunction, 0);
    143     BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), "exit", finalBlockFunction, 0);
    144    
    145     Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0));
    146     iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
    147     iBuilder->SetInsertPoint(finalPartialBlock);
    148     iBuilder->CreateCall(doBlockFunction, {self});
    149    
    150     iBuilder->CreateBr(exitBlock);
    151    
    152     iBuilder->SetInsertPoint(finalEmptyBlock);
    153     Value * blockNo = getScalarField(self, blockNoScalar);
    154     Value * basisBitsPtr = getStreamView(self, "basisBits", blockNo, iBuilder->getInt64(0));
    155     iBuilder->CreateStore(Constant::getNullValue(basisBitsPtr->getType()->getPointerElementType()), basisBitsPtr);
    156     iBuilder->CreateBr(exitBlock);
    157    
    158     iBuilder->SetInsertPoint(exitBlock);
    159     iBuilder->CreateRetVoid();
    160     iBuilder->restoreIP(savePoint);
    161 }
    162    
    163 void S2PKernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
     123void S2PKernel::generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const {
    164124    Value * bytepack[8];
    165125    for (unsigned i = 0; i < 8; i++) {
     
    174134    }
    175135}
     136
     137void S2PKernel::generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, Value * remainingBytes, llvm::Value * blockNo) const {
     138    /* Prepare the s2p final block function:
     139     assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
     140     if remaining bytes is zero, no read should be performed (e.g. for mmapped buffer).
     141     */
    176142   
    177 void S2PKernel::generateDoBlockMethod() const {
    178     auto savePoint = iBuilder->saveIP();
    179 
    180     Function * doBlockFunction = iBuilder->getModule()->getFunction(mKernelName + doBlock_suffix);
     143    BasicBlock * finalPartialBlock = BasicBlock::Create(iBuilder->getContext(), "partial", function, 0);
     144    BasicBlock * finalEmptyBlock = BasicBlock::Create(iBuilder->getContext(), "empty", function, 0);
     145    BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), "exit", function, 0);
    181146   
    182     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction));
     147    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0));
     148    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
     149    iBuilder->SetInsertPoint(finalPartialBlock);
     150    iBuilder->CreateCall(getDoBlockFunction(), {self});
    183151   
    184     Value * self = getParameter(doBlockFunction, "self");
    185     Value * blockNo = getScalarField(self, blockNoScalar);
     152    iBuilder->CreateBr(exitBlock);
    186153   
    187     generateDoBlockLogic(self, blockNo);
    188 
    189     iBuilder->CreateRetVoid();
    190     iBuilder->restoreIP(savePoint);
     154    iBuilder->SetInsertPoint(finalEmptyBlock);
     155    Value * basisBitsPtr = getStreamView(self, "basisBits", blockNo, iBuilder->getInt64(0));
     156    iBuilder->CreateStore(Constant::getNullValue(basisBitsPtr->getType()->getPointerElementType()), basisBitsPtr);
     157    iBuilder->CreateBr(exitBlock);
     158   
     159    iBuilder->SetInsertPoint(exitBlock);
    191160}
    192161
Note: See TracChangeset for help on using the changeset viewer.