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

    r5436 r5440  
    1515namespace kernel{
    1616       
    17 void p2s_step(IDISA::IDISA_Builder * const iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
     17void p2s_step(const std::unique_ptr<KernelBuilder> & iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
    1818    Value * t0 = iBuilder->simd_if(1, hi_mask, p0, iBuilder->simd_srli(16, p1, shift));
    1919    Value * t1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, p0, shift), p1);
     
    2222}
    2323
    24 inline void p2s(IDISA::IDISA_Builder * const iBuilder, Value * p[], Value * s[]) {
     24inline void p2s(const std::unique_ptr<KernelBuilder> & iBuilder, Value * p[], Value * s[]) {
    2525    Value * bit00004444[2];
    2626    Value * bit22226666[2];
     
    4242}
    4343               
    44 void P2SKernel::generateDoBlockMethod() {
     44void P2SKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    4545    Value * p_bitblock[8];
    4646    for (unsigned i = 0; i < 8; i++) {
    47         p_bitblock[i] = loadInputStreamBlock("basisBits", iBuilder->getInt32(i));
     47        p_bitblock[i] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(i));
    4848    }
    4949    Value * s_bytepack[8];
    5050    p2s(iBuilder, p_bitblock, s_bytepack);
    5151    for (unsigned j = 0; j < 8; ++j) {
    52         storeOutputStreamPack("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(j), s_bytepack[j]);
     52        iBuilder->storeOutputStreamPack("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(j), s_bytepack[j]);
    5353    }
    5454}
    5555
    56 void P2SKernelWithCompressedOutput::generateDoBlockMethod() {
     56void P2SKernelWithCompressedOutput::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    5757    IntegerType * i32 = iBuilder->getInt32Ty();
    5858    PointerType * bitBlockPtrTy = PointerType::get(iBuilder->getBitBlockType(), 0);
     
    6060    Value * basisBits[8];
    6161    for (unsigned i = 0; i < 8; i++) {
    62         basisBits[i] = loadInputStreamBlock("basisBits", iBuilder->getInt32(i));
     62        basisBits[i] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(i));
    6363    }
    6464    Value * bytePack[8];
     
    6666
    6767    unsigned units_per_register = iBuilder->getBitBlockWidth()/8;
    68     Value * delCountBlock_ptr = getInputStreamBlockPtr("deletionCounts", iBuilder->getInt32(0));
     68    Value * delCountBlock_ptr = iBuilder->getInputStreamBlockPtr("deletionCounts", iBuilder->getInt32(0));
    6969    Value * unit_counts = iBuilder->fwCast(units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
    7070
    71     Value * output_ptr = getOutputStreamBlockPtr("byteStream", iBuilder->getInt32(0));
     71    Value * output_ptr = iBuilder->getOutputStreamBlockPtr("byteStream", iBuilder->getInt32(0));
    7272    output_ptr = iBuilder->CreatePointerCast(output_ptr, iBuilder->getInt8PtrTy());
    7373    Value * offset = iBuilder->getInt32(0);
     
    7777    }
    7878
    79     Value * unitsGenerated = getProducedItemCount("byteStream"); // units generated to buffer
     79    Value * unitsGenerated = iBuilder->getProducedItemCount("byteStream"); // units generated to buffer
    8080    unitsGenerated = iBuilder->CreateAdd(unitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    81     setProducedItemCount("byteStream", unitsGenerated);
     81    iBuilder->setProducedItemCount("byteStream", unitsGenerated);
    8282}
    8383
    84 void P2S16Kernel::generateDoBlockMethod() {
     84void P2S16Kernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    8585    Value * hi_input[8];
    8686    for (unsigned j = 0; j < 8; ++j) {
    87         hi_input[j] = loadInputStreamBlock("basisBits", iBuilder->getInt32(j));
     87        hi_input[j] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(j));
    8888    }
    8989    Value * hi_bytes[8];
     
    9191    Value * lo_input[8];
    9292    for (unsigned j = 0; j < 8; ++j) {
    93         lo_input[j] = loadInputStreamBlock("basisBits", iBuilder->getInt32(j + 8));
     93        lo_input[j] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(j + 8));
    9494    }
    9595    Value * lo_bytes[8];
     
    9898        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    9999        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    100         storeOutputStreamPack("i16Stream", iBuilder->getInt32(0), iBuilder->getInt32(2 * j), merge0);
    101         storeOutputStreamPack("i16Stream", iBuilder->getInt32(0), iBuilder->getInt32(2 * j + 1), merge1);
     100        iBuilder->storeOutputStreamPack("i16Stream", iBuilder->getInt32(0), iBuilder->getInt32(2 * j), merge0);
     101        iBuilder->storeOutputStreamPack("i16Stream", iBuilder->getInt32(0), iBuilder->getInt32(2 * j + 1), merge1);
    102102    }
    103103}
    104104       
    105 void P2S16KernelWithCompressedOutput::generateDoBlockMethod() {
     105void P2S16KernelWithCompressedOutput::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    106106    IntegerType * i32Ty = iBuilder->getInt32Ty();
    107107    PointerType * int16PtrTy = iBuilder->getInt16Ty()->getPointerTo();
     
    111111    Value * hi_input[8];
    112112    for (unsigned j = 0; j < 8; ++j) {
    113         hi_input[j] = loadInputStreamBlock("basisBits", iBuilder->getInt32(j));
     113        hi_input[j] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(j));
    114114    }
    115115    Value * hi_bytes[8];
     
    118118    Value * lo_input[8];
    119119    for (unsigned j = 0; j < 8; ++j) {
    120         lo_input[j] = loadInputStreamBlock("basisBits", iBuilder->getInt32(j + 8));
     120        lo_input[j] = iBuilder->loadInputStreamBlock("basisBits", iBuilder->getInt32(j + 8));
    121121    }
    122122    Value * lo_bytes[8];
    123123    p2s(iBuilder, lo_input, lo_bytes);
    124124
    125     Value * delCountBlock_ptr = getInputStreamBlockPtr("deletionCounts", iBuilder->getInt32(0));
     125    Value * delCountBlock_ptr = iBuilder->getInputStreamBlockPtr("deletionCounts", iBuilder->getInt32(0));
    126126    Value * unit_counts = iBuilder->fwCast(iBuilder->getBitBlockWidth() / 16, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
    127127
    128128
    129     Value * u16_output_ptr = getOutputStreamBlockPtr("i16Stream", iBuilder->getInt32(0));
     129    Value * u16_output_ptr = iBuilder->getOutputStreamBlockPtr("i16Stream", iBuilder->getInt32(0));
    130130    u16_output_ptr = iBuilder->CreatePointerCast(u16_output_ptr, int16PtrTy);
    131     Value * i16UnitsGenerated = getProducedItemCount("i16Stream"); // units generated to buffer
     131    Value * i16UnitsGenerated = iBuilder->getProducedItemCount("i16Stream"); // units generated to buffer
    132132    u16_output_ptr = iBuilder->CreateGEP(u16_output_ptr, iBuilder->CreateURem(i16UnitsGenerated, stride));
    133133
     
    144144    }   
    145145    Value * i16UnitsFinal = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    146     setProducedItemCount("i16Stream", i16UnitsFinal);
     146    iBuilder->setProducedItemCount("i16Stream", i16UnitsFinal);
    147147}
    148148
Note: See TracChangeset for help on using the changeset viewer.