Ignore:
Timestamp:
Jun 23, 2016, 8:26:09 PM (3 years ago)
Author:
cameron
Message:

Update u8u16 to use new kernel infrastructure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5036 r5071  
    2424#include <cc/cc_compiler.h>
    2525#include <pablo/pablo_toolchain.h>
     26#include <pablo/pablo_kernel.h>
    2627#include <pablo/function.h>
    2728#include <IDISA/idisa_builder.h>
    2829#include <IDISA/idisa_target.h>
    29 #include <kernels/u8u16_pipeline.h>
     30#include <kernels/interface.h>
     31#include <kernels/kernel.h>
     32#include <kernels/s2p_kernel.h>
     33#include <kernels/p2s_kernel.h>
     34#include <kernels/deletion.h>
    3035
    3136#include <utf_encoding.h>
     
    212217
    213218
     219
     220using namespace kernel;
     221
     222
     223Function * u8u16Pipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
     224    Type * mBitBlockType = iBuilder->getBitBlockType();
     225    unsigned mBlockSize = iBuilder->getBitBlockWidth();
     226    s2pKernel  s2pk(iBuilder);
     227    s2pk.generateKernel();
     228   
     229    pablo_function_passes(function);
     230    pablo::PabloKernel  u8u16k(iBuilder, "u8u16", function, {});
     231    u8u16k.prepareKernel();
     232    u8u16k.generateKernel();
     233   
     234    deletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
     235    delK.generateKernel();
     236   
     237    p2s_16Kernel_withCompressedOutputKernel p2sk(iBuilder);   
     238    p2sk.generateKernel();
     239   
     240    Type * const int64ty = iBuilder->getInt64Ty();
     241    Type * const voidTy = Type::getVoidTy(mMod->getContext());
     242    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
     243   
     244    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", Type::getVoidTy(mMod->getContext()), inputType, int64ty, nullptr));
     245    main->setCallingConv(CallingConv::C);
     246    Function::arg_iterator args = main->arg_begin();
     247   
     248    Value * const inputStream = &*(args++);
     249    inputStream->setName("input");
     250    Value * const bufferSize = &*(args++);
     251    bufferSize->setName("bufferSize");
     252   
     253    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
     254   
     255    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
     256   
     257    BasicBlock * fullCondBlock = BasicBlock::Create(mMod->getContext(), "fullCond", main, 0);
     258    BasicBlock * fullBodyBlock = BasicBlock::Create(mMod->getContext(), "fullBody", main, 0);
     259    BasicBlock * finalBlock = BasicBlock::Create(mMod->getContext(), "final", main, 0);
     260   
     261    StreamSetBuffer ByteStream(iBuilder, StreamSetType(1, 8), 0);
     262    StreamSetBuffer BasisBits(iBuilder, StreamSetType(8, 1), 1);
     263    StreamSetBuffer U8u16Bits(iBuilder, StreamSetType(18, 1), 1);
     264    StreamSetBuffer U16Bits(iBuilder, StreamSetType(16, 1), 1);
     265    StreamSetBuffer DeletionCounts(iBuilder, StreamSetType(1, 1), 1);
     266    StreamSetBuffer U16out(iBuilder, StreamSetType(1, 16), 1);
     267
     268    ByteStream.setStreamSetBuffer(inputStream);
     269    Value * basisBits = BasisBits.allocateBuffer();
     270    Value * u8u16Bits = U8u16Bits.allocateBuffer();
     271    Value * u16Bits = U16Bits.allocateBuffer();
     272    Value * delCounts = DeletionCounts.allocateBuffer();
     273    Value * u16out = U16out.allocateBuffer();
     274   
     275    Value * s2pInstance = s2pk.createInstance({});
     276    Value * u8u16Instance = u8u16k.createInstance({});
     277    Value * delInstance = delK.createInstance({});
     278    Value * p2sInstance = p2sk.createInstance({});
     279   
     280    Value * initialBufferSize = bufferSize;
     281    BasicBlock * initialBlock = entryBlock;
     282    Value * initialBlockNo = iBuilder->getInt64(0);
     283   
     284    iBuilder->CreateBr(fullCondBlock);
     285   
     286   
     287    iBuilder->SetInsertPoint(fullCondBlock);
     288    PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
     289    remainingBytes->addIncoming(initialBufferSize, initialBlock);
     290    PHINode * blockNo = iBuilder->CreatePHI(int64ty, 2, "blockNo");
     291    blockNo->addIncoming(initialBlockNo, initialBlock);
     292   
     293    Constant * const step = ConstantInt::get(int64ty, mBlockSize);
     294    Value * fullCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
     295    iBuilder->CreateCondBr(fullCondTest, finalBlock, fullBodyBlock);
     296   
     297    iBuilder->SetInsertPoint(fullBodyBlock);
     298   
     299    s2pk.createDoBlockCall(s2pInstance, {ByteStream.getBlockPointer(blockNo), basisBits});
     300    u8u16k.createDoBlockCall(u8u16Instance, {basisBits, u8u16Bits});
     301    delK.createDoBlockCall(delInstance, {u8u16Bits, u16Bits, delCounts});
     302    p2sk.createDoBlockCall(p2sInstance, {u16Bits, delCounts, u16out});
     303   
     304    Value * diff = iBuilder->CreateSub(remainingBytes, step);
     305   
     306    remainingBytes->addIncoming(diff, fullBodyBlock);
     307    blockNo->addIncoming(iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)), fullBodyBlock);
     308    iBuilder->CreateBr(fullCondBlock);
     309   
     310    iBuilder->SetInsertPoint(finalBlock);
     311    s2pk.createFinalBlockCall(s2pInstance, remainingBytes, {ByteStream.getBlockPointer(blockNo), basisBits});
     312    u8u16k.createFinalBlockCall(u8u16Instance, remainingBytes, {basisBits, u8u16Bits});
     313    delK.createFinalBlockCall(delInstance, remainingBytes, {u8u16Bits, u16Bits, delCounts});
     314    p2sk.createFinalBlockCall(p2sInstance, remainingBytes, {u16Bits, delCounts, u16out});
     315   
     316   
     317    iBuilder->CreateRetVoid();
     318    return main;
     319}
     320
     321
     322
     323
     324
    214325typedef void (*u8u16FunctionType)(char * byte_data, size_t filesize);
    215326
     
    219330                           
    220331    Module * M = new Module("u8u16", getGlobalContext());
    221    
    222332    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    223333
    224     kernel::PipelineBuilder pipelineBuilder(M, idb);
    225 
    226334    Encoding encoding(Encoding::Type::UTF_8, 8);
    227    
    228335    pablo::PabloFunction * function = pablo::u8u16_pablo(encoding);
    229336   
    230 
    231     pipelineBuilder.CreateKernels(function);
    232 
    233     llvm::Function * main_IR = pipelineBuilder.ExecuteKernels();
     337    llvm::Function * main_IR = u8u16Pipeline(M, idb, function);
    234338   
    235339    verifyModule(*M, &dbgs());
Note: See TracChangeset for help on using the changeset viewer.