Changeset 5435


Ignore:
Timestamp:
May 6, 2017, 4:05:05 PM (22 months ago)
Author:
nmedfort
Message:

Continued refactoring work.

Location:
icGREP/icgrep-devel/icgrep
Files:
2 added
82 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r5429 r5435  
    6161SET(TOOLCHAIN_SRC toolchain/toolchain.cpp toolchain/pipeline.cpp ${OBJECT_CACHE_SRC})
    6262
    63 SET(KERNEL_SRC kernels/kernel.cpp kernels/streamset.cpp kernels/interface.cpp)
     63SET(KERNEL_SRC kernels/kernel.cpp kernels/streamset.cpp kernels/interface.cpp kernels/kernel_builder.cpp)
    6464SET(KERNEL_SRC ${KERNEL_SRC} kernels/source_kernel.cpp kernels/s2p_kernel.cpp kernels/deletion.cpp kernels/swizzle.cpp kernels/p2s_kernel.cpp kernels/stdout_kernel.cpp)
    6565
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5429 r5435  
    746746}
    747747
    748 CBuilder::CBuilder(Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
     748CBuilder::CBuilder(Module * const module, const unsigned GeneralRegisterWidthInBits)
    749749: IRBuilder<>(module->getContext())
    750750, mMod(module)
    751 , mCacheLineAlignment(CacheLineAlignmentInBytes)
     751, mCacheLineAlignment(64)
    752752, mSizeType(getIntNTy(GeneralRegisterWidthInBits))
    753753, mFILEtype(nullptr)
    754 , mSupportsIndirectBr(SupportsIndirectBr)
    755754, mDriver(nullptr) {
    756755
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5431 r5435  
    2525public:
    2626
    27     CBuilder(llvm::Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
     27    CBuilder(llvm::Module * const module, const unsigned GeneralRegisterWidthInBits);
    2828   
    2929    virtual ~CBuilder() {}
     
    173173    }
    174174
    175     bool supportsIndirectBr() const {
    176         return mSupportsIndirectBr;
     175    virtual bool supportsIndirectBr() const {
     176        return true;
    177177    }
    178178
     
    214214    llvm::IntegerType *             mSizeType;
    215215    llvm::StructType *              mFILEtype;
    216     const bool                      mSupportsIndirectBr;
    217216    ParabixDriver *                 mDriver;
    218217    llvm::LLVMContext               mContext;
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_avx_builder.h

    r5425 r5435  
    1616public:
    1717   
    18     IDISA_AVX_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
    19     : IDISA_SSE2_Builder(module, archBitWidth, bitBlockWidth) {
     18    IDISA_AVX_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     19    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride)
     20    , IDISA_SSE2_Builder(module, archBitWidth, bitBlockWidth, stride)
     21    {
     22
    2023    }
    2124
    2225    virtual std::string getBuilderUniqueName() override;
     26
    2327    Value * hsimd_signmask(unsigned fw, Value * a) override;
     28
    2429    ~IDISA_AVX_Builder() {}
    2530
     
    2934public:
    3035   
    31     IDISA_AVX2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
    32     : IDISA_AVX_Builder(module, archBitWidth, bitBlockWidth) {
     36    IDISA_AVX2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     37    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride)
     38    , IDISA_AVX_Builder(module, archBitWidth, bitBlockWidth, stride) {
     39
    3340    }
    3441
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5425 r5435  
    376376}
    377377
    378 IDISA_Builder::IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
    379 : CBuilder(module, archBitWidth, SupportsIndirectBr, CacheAlignment)
     378void IDISA_Builder::initialize(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride) {
     379
     380}
     381
     382IDISA_Builder::IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     383: CBuilder(module, archBitWidth)
    380384, mBitBlockWidth(bitBlockWidth)
    381385, mStride(stride)
    382 , mBitBlockType(VectorType::get(IntegerType::get(getContext(), 64), bitBlockWidth / 64))
     386, mBitBlockType(VectorType::get(IntegerType::get(module->getContext(), 64), bitBlockWidth / 64))
    383387, mZeroInitializer(Constant::getNullValue(mBitBlockType))
    384388, mOneInitializer(Constant::getAllOnesValue(mBitBlockType))
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5425 r5435  
    2020public:
    2121
    22     IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
     22    IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride);
    2323
    2424    virtual ~IDISA_Builder();
     
    131131   
    132132protected:
     133
     134    void initialize(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride);
     135
     136protected:
    133137    unsigned            mBitBlockWidth;
    134138    unsigned            mStride;
     
    155159    CreateBlockAlignedStore(value, CreateGEP(ptr, indices));
    156160}
    157    
     161
    158162}
    159163#endif // IDISA_BUILDER_H
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_i64_builder.h

    r5425 r5435  
    1313namespace IDISA {
    1414
    15 class IDISA_I64_Builder : public IDISA_Builder {
     15class IDISA_I64_Builder : public virtual IDISA_Builder {
    1616public:
    1717 
    18     IDISA_I64_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64, const bool SupportsIndirectBr = true)
    19     : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride, SupportsIndirectBr) {
     18    IDISA_I64_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     19    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride) {
    2020
    2121    }
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_nvptx_builder.h

    r5425 r5435  
    1616public:
    1717   
    18     IDISA_NVPTX20_Builder(llvm::Module * const module, unsigned groupSize)
    19     : IDISA_I64_Builder(module, 64, 64, 64 * groupSize, false)
     18    IDISA_NVPTX20_Builder(llvm::Module * const module, unsigned registerWidth, unsigned vectorWidth, unsigned groupSize)
     19    : IDISA_Builder(module, registerWidth, registerWidth, (vectorWidth * groupSize))
     20    , IDISA_I64_Builder(module, registerWidth, registerWidth, (vectorWidth * groupSize))
    2021    , groupThreads(groupSize) {
    2122        CreateGlobals();
     
    4344    LoadInst * CreateAtomicLoadAcquire(Value * ptr) override;
    4445    StoreInst * CreateAtomicStoreRelease(Value * val, Value * ptr) override;
     46
     47    bool supportsIndirectBr() const final {
     48        return false;
     49    }
    4550
    4651private:
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_sse_builder.h

    r5425 r5435  
    1414namespace IDISA {
    1515
    16 class IDISA_SSE_Builder : public IDISA_Builder {
     16class IDISA_SSE_Builder : public virtual IDISA_Builder {
    1717public:
    1818 
    19     IDISA_SSE_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
    20     : IDISA_Builder(module, archBitWidth, bitBlockWidth, bitBlockWidth) {
     19    IDISA_SSE_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     20    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride) {
     21
    2122    }
    2223
     
    3031public:
    3132 
    32     IDISA_SSE2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
    33     : IDISA_SSE_Builder(module, archBitWidth, bitBlockWidth) {
     33    IDISA_SSE2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride)
     34    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride)
     35    , IDISA_SSE_Builder(module, archBitWidth, bitBlockWidth, stride) {
     36
    3437    }
    3538
     
    3841    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
    3942    Value * hsimd_packl(unsigned fw, Value * a, Value * b) override;
    40     std::pair<Value *, Value *> bitblock_advance(Value * a, Value * shiftin, unsigned shift) override;
     43    std::pair<Value *, Value *> bitblock_advance(Value * a, Value * shiftin, unsigned shift) final;
    4144
    4245    ~IDISA_SSE2_Builder() {}
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp

    r5425 r5435  
    1313#include <llvm/ADT/Triple.h>
    1414
     15#include <kernels/kernel_builder.h>
     16
     17using namespace kernel;
     18
    1519namespace IDISA {
    1620   
    17 IDISA_Builder * GetIDISA_Builder(llvm::Module * const module) {
     21KernelBuilder * GetIDISA_Builder(llvm::Module * const module) {
    1822    unsigned registerWidth = 0;
    1923    Triple T(module->getTargetTriple());
     
    3135    if (codegen::BlockSize >= 256) {
    3236        if (hasAVX2) {
    33             return new IDISA_AVX2_Builder(module, registerWidth, codegen::BlockSize);
     37            return new KernelBuilderImpl<IDISA_AVX2_Builder>(module, registerWidth, codegen::BlockSize, codegen::BlockSize);
    3438        }
    3539    } else if (codegen::BlockSize == 64) {
    36         return new IDISA_I64_Builder(module, registerWidth);
     40        return new KernelBuilderImpl<IDISA_I64_Builder>(module, registerWidth, codegen::BlockSize, codegen::BlockSize);
    3741    }
    38     return new IDISA_SSE2_Builder(module, registerWidth, codegen::BlockSize);
     42    return new KernelBuilderImpl<IDISA_SSE2_Builder>(module, registerWidth, codegen::BlockSize, codegen::BlockSize);
    3943}
    4044
    41 IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module) {
    42     return new IDISA_NVPTX20_Builder(module, 64);
     45KernelBuilder * GetIDISA_GPU_Builder(llvm::Module * const module) {
     46    return new KernelBuilderImpl<IDISA_NVPTX20_Builder>(module, 64, 64, 64);
    4347}
    4448
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.h

    r5425 r5435  
    99#include <string>
    1010namespace llvm { class Module; }
    11 namespace IDISA { class IDISA_Builder; }
     11namespace kernel { class KernelBuilder; }
    1212
    1313namespace IDISA {
    1414   
    15 IDISA::IDISA_Builder * GetIDISA_Builder(llvm::Module * const module);
     15kernel::KernelBuilder * GetIDISA_Builder(llvm::Module * const module);
    1616
    17 IDISA::IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module);
     17kernel::KernelBuilder * GetIDISA_GPU_Builder(llvm::Module * const module);
    1818
    1919}
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5431 r5435  
    125125void pipeline(ParabixDriver & pxDriver, const unsigned count) {
    126126
    127     IDISA::IDISA_Builder * const iBuilder = pxDriver.getIDISA_Builder();
     127    auto & iBuilder = pxDriver.getBuilder();
    128128    Module * const mod = iBuilder->getModule();
    129129
  • icGREP/icgrep-devel/icgrep/base64.cpp

    r5431 r5435  
    3939void base64PipelineGen(ParabixDriver & pxDriver) {
    4040       
    41     auto iBuilder = pxDriver.getIDISA_Builder();
     41    auto & iBuilder = pxDriver.getBuilder();
    4242    Module * mod = iBuilder->getModule();
    4343    Type * bitBlockType = iBuilder->getBitBlockType();
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5429 r5435  
    191191void editdPipeline(ParabixDriver & pxDriver, const std::vector<std::string> & patterns) {
    192192
    193     IDISA::IDISA_Builder * const idb = pxDriver.getIDISA_Builder();
     193    auto & idb = pxDriver.getBuilder();
    194194    Module * const m = idb->getModule();
    195195    Type * const sizeTy = idb->getSizeTy();
     
    221221        ));
    222222
     223    editdk->setBuilder(idb.get());
    223224    buildPatternKernel(reinterpret_cast<PabloKernel *>(editdk), patterns);
    224225    pxDriver.makeKernelCall(editdk, {ChStream}, {MatchResults});
     
    235236
    236237void buildPreprocessKernel(PabloKernel * const kernel) {
     238    assert (kernel->getBuilder());
    237239    cc::CC_Compiler ccc(kernel, kernel->getInputStreamVar("basis"));
    238240
     
    256258void preprocessPipeline(ParabixDriver & pxDriver) {
    257259
    258     IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     260    auto & iBuilder = pxDriver.getBuilder();
    259261    Module * m = iBuilder->getModule();
    260262    Type * mBitBlockType = iBuilder->getBitBlockType();
     
    292294    ));
    293295
     296    ccck->setBuilder(iBuilder.get());
    294297    buildPreprocessKernel(reinterpret_cast<PabloKernel *>(ccck));
    295298
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.cpp

    r5356 r5435  
    8484}
    8585
    86 editdCPUKernel::editdCPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
    87 BlockOrientedKernel(b, "editd_cpu",
     86editdCPUKernel::editdCPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen) :
     87BlockOrientedKernel("editd_cpu",
    8888             {Binding{b->getStreamSetTy(4), "CCStream"}},
    8989             {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5347 r5435  
    1717public:
    1818
    19     editdCPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen);
     19    editdCPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen);
    2020   
    2121
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.cpp

    r5356 r5435  
    1111namespace kernel {
    1212
    13 void bitblock_advance_ci_co(IDISA::IDISA_Builder * iBuilder, Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j){   
     13void bitblock_advance_ci_co(IDISA::IDISA_Builder * const iBuilder, Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j){
    1414    if (!calculated[i][j]) {
    1515        Value * ptr = iBuilder->CreateGEP(stideCarryArr, {iBuilder->getInt32(0), iBuilder->getInt32(carryIdx)});
     
    8080}
    8181
    82 editdGPUKernel::editdGPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
    83 BlockOrientedKernel(b, "editd_gpu",
     82editdGPUKernel::editdGPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen) :
     83BlockOrientedKernel("editd_gpu",
    8484              {Binding{b->getStreamSetTy(4), "CCStream"}},
    8585              {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5297 r5435  
    1717public:
    1818   
    19     editdGPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen);
     19    editdGPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen);
    2020   
    2121   
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5398 r5435  
    8787}
    8888
    89 editdScanKernel::editdScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist) :
    90 BlockOrientedKernel(iBuilder, "scanMatch",
     89editdScanKernel::editdScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned dist) :
     90BlockOrientedKernel("scanMatch",
    9191              {Binding{iBuilder->getStreamSetTy(dist + 1), "matchResults"}},
    9292              {}, {}, {}, {Binding{iBuilder->getSizeTy(), "BlockNo"}}),
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5297 r5435  
    1515class editdScanKernel : public BlockOrientedKernel {
    1616public:
    17     editdScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist);
     17    editdScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned dist);
    1818       
    1919private:
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5429 r5435  
    195195
    196196    ParabixDriver pxDriver(moduleName + ":icgrep");
    197     auto idb = pxDriver.getIDISA_Builder();
     197    auto & idb = pxDriver.getBuilder();
    198198    Module * M = idb->getModule();
    199199
     
    208208    Value * fileIdx = nullptr;
    209209    StreamSetBuffer * ByteStream = nullptr;
    210     kernel::KernelBuilder * sourceK = nullptr;
     210    kernel::Kernel * sourceK = nullptr;
    211211
    212212    if (grepSource == GrepSource::Internal) {
     
    258258    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    259259   
    260     kernel::KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
     260    kernel::Kernel * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
    261261    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    262262   
    263     kernel::KernelBuilder * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
     263    kernel::Kernel * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
    264264    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    265265    pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
     
    271271    for(unsigned i = 0; i < n; ++i){
    272272        StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    273         kernel::KernelBuilder * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(idb, REs[i]));
     273        kernel::Kernel * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(idb, REs[i]));
    274274        pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    275275        MatchResultsBufs[i] = MatchResults;
     
    278278    if (REs.size() > 1) {
    279279        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    280         kernel::KernelBuilder * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
     280        kernel::Kernel * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
    281281        pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    282282    }
    283283   
    284284    if (AlgorithmOptionIsSet(re::InvertMatches)) {
    285         kernel::KernelBuilder * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
     285        kernel::Kernel * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
    286286        StreamSetBuffer * OriginalMatches = MergedResults;
    287287        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r5429 r5435  
    4949kernels/kernel.cpp
    5050kernels/kernel.h
     51kernels/kernel_builder.cpp
     52kernels/kernel_builder.h
    5153kernels/linebreak_kernel.cpp
    5254kernels/linebreak_kernel.h
     
    6567kernels/scanmatchgen.cpp
    6668kernels/scanmatchgen.h
     69kernels/source_kernel.cpp
     70kernels/source_kernel.h
    6771kernels/stdout_kernel.cpp
    6872kernels/stdout_kernel.h
     
    244248wc.cpp
    245249CMakeLists.txt
    246 kernels/source_kernel.h
    247 kernels/source_kernel.cpp
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp

    r5398 r5435  
    1212namespace kernel {
    1313
    14     void ap_p2s_step(IDISA::IDISA_Builder * iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
     14inline void ap_p2s_step(IDISA::IDISA_Builder * const iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
    1515    Value * t0 = iBuilder->simd_if(1, hi_mask, p0, iBuilder->simd_srli(16, p1, shift));
    1616    Value * t1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, p0, shift), p1);
     
    1919}
    2020
    21 void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
     21inline void p2s(IDISA::IDISA_Builder * const iBuilder, Value * p[], Value * s[]) {
    2222    Value * bit00004444[2];
    2323    Value * bit22226666[2];
     
    256256}
    257257
    258 PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
    259 : BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {}) {
     258PrintableBits::PrintableBits(const std::unique_ptr<IDISA::IDISA_Builder> & builder)
     259: BlockOrientedKernel("PrintableBits", {Binding{builder->getStreamSetTy(1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {}) {
    260260    setNoTerminateAttribute(true);
    261261}
    262262
    263 SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
    264 : BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex) {
     263SelectStream::SelectStream(const std::unique_ptr<IDISA::IDISA_Builder> & builder, unsigned sizeInputStreamSet, unsigned streamIndex)
     264: BlockOrientedKernel("SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex) {
    265265    setNoTerminateAttribute(true);
    266266
    267267}
    268268
    269 PrintStreamSet::PrintStreamSet(IDISA::IDISA_Builder * builder, std::vector<std::string> && names, const unsigned minWidth)
    270 : BlockOrientedKernel(builder, "PrintableStreamSet", {}, {}, {}, {}, {})
     269PrintStreamSet::PrintStreamSet(const std::unique_ptr<IDISA::IDISA_Builder> & builder, std::vector<std::string> && names, const unsigned minWidth)
     270: BlockOrientedKernel("PrintableStreamSet", {}, {}, {}, {}, {})
    271271, mNames(names)
    272272, mNameWidth(0) {
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.h

    r5337 r5435  
    1414class PrintableBits : public BlockOrientedKernel {
    1515public:
    16     PrintableBits(IDISA::IDISA_Builder * builder);
     16    PrintableBits(const std::unique_ptr<IDISA::IDISA_Builder> & builder);
    1717    virtual ~PrintableBits() {}
    1818private:
     
    2222class SelectStream : public BlockOrientedKernel {
    2323public:
    24     SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex);
     24    SelectStream(const std::unique_ptr<IDISA::IDISA_Builder> & builder, unsigned sizeInputStreamSet, unsigned streamIndex);
    2525    virtual ~SelectStream() {}
    2626private:
     
    3232class PrintStreamSet : public BlockOrientedKernel {
    3333public:
    34     PrintStreamSet(IDISA::IDISA_Builder * builder, std::vector<std::string> && names, const unsigned minWidth = 16);
     34    PrintStreamSet(const std::unique_ptr<IDISA::IDISA_Builder> & builder, std::vector<std::string> && names, const unsigned minWidth = 16);
    3535    virtual ~PrintStreamSet() {}
    3636private:
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5320 r5435  
    1515using namespace re;
    1616using namespace llvm;
     17
     18DirectCharacterClassKernelBuilder::DirectCharacterClassKernelBuilder(
     19        const std::unique_ptr<IDISA::IDISA_Builder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned codeUnitSize)
     20: BlockOrientedKernel(std::move(ccSetName),
     21              {Binding{b->getStreamSetTy(1, 8 * codeUnitSize), "codeUnitStream"}},
     22              {Binding{b->getStreamSetTy(charClasses.size(), 1), "ccStream"}},
     23              {}, {}, {})
     24, mCharClasses(charClasses)
     25, mCodeUnitSize(codeUnitSize) {
     26
     27}
    1728
    1829void DirectCharacterClassKernelBuilder::generateDoBlockMethod() {
     
    6071
    6172ParabixCharacterClassKernelBuilder::ParabixCharacterClassKernelBuilder (
    62 IDISA::IDISA_Builder * iBuilder
    63 , std::string ccSetName
    64 , const std::vector<CC *> & charClasses
    65 , unsigned basisBitsCount)
    66 : PabloKernel(iBuilder, ccSetName +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
     73        const std::unique_ptr<IDISA::IDISA_Builder> & b, std::string ccSetName, const std::vector<CC *> & charClasses, unsigned codeUnitSize)
     74: PabloKernel(b, ccSetName +"_kernel", {Binding{b->getStreamSetTy(codeUnitSize), "basis"}})
     75, mCharClasses(charClasses) {
     76    for (CC * cc : mCharClasses) {
     77        addOutput(cc->canonicalName(re::ByteClass), b->getStreamTy());
     78    }
     79}
     80
     81void ParabixCharacterClassKernelBuilder::prepareKernel() {
    6782    CC_Compiler ccc(this, getInput(0));
    6883    auto & builder = ccc.getBuilder();
    69     for (CC * cc : charClasses) {
    70         Var * const r = addOutput(cc->canonicalName(re::ByteClass), getStreamTy());
    71         builder.createAssign(r, ccc.compileCC("cc", cc, builder));
     84    for (unsigned i = 0; i < mCharClasses.size(); ++i) {
     85        builder.createAssign(getOutput(i), ccc.compileCC("cc", mCharClasses[i], builder));
    7286    }
    73 
     87    PabloKernel::prepareKernel();
    7488}
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.h

    r5297 r5435  
    1515namespace kernel {
    1616
    17 class DirectCharacterClassKernelBuilder : public BlockOrientedKernel {
    18 public:
    19    
    20     DirectCharacterClassKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned codeUnitSize)
    21     : BlockOrientedKernel(iBuilder, std::move(ccSetName),
    22                   {Binding{iBuilder->getStreamSetTy(1, 8 * codeUnitSize), "codeUnitStream"}},
    23                   {Binding{iBuilder->getStreamSetTy(charClasses.size(), 1), "ccStream"}},
    24                   {}, {}, {})
    25     , mCharClasses(charClasses)
    26     , mCodeUnitSize(codeUnitSize) {
    27     }
    28    
     17class DirectCharacterClassKernelBuilder final : public BlockOrientedKernel {
     18public:   
     19    DirectCharacterClassKernelBuilder(const std::unique_ptr<IDISA::IDISA_Builder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned codeUnitSize);
    2920    void generateDoBlockMethod() override;
    30 
    3121private:
    32     std::vector<re::CC *> mCharClasses;
    33     unsigned mCodeUnitSize;
     22    const std::vector<re::CC *> mCharClasses;
     23    const unsigned              mCodeUnitSize;
    3424   
    3525};
    3626
    37 class ParabixCharacterClassKernelBuilder: public pablo::PabloKernel {
     27class ParabixCharacterClassKernelBuilder final : public pablo::PabloKernel {
    3828public:
    39     ParabixCharacterClassKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string ccSetName, const std::vector<re::CC *> & charClasses, unsigned basisBitsCount);
     29    ParabixCharacterClassKernelBuilder(const std::unique_ptr<IDISA::IDISA_Builder> & b, std::string ccSetName, const std::vector<re::CC *> & charClasses, unsigned codeUnitSize);
     30protected:
     31    void prepareKernel() override;
     32private:
     33    const std::vector<re::CC *> mCharClasses;
    4034};
    4135
  • icGREP/icgrep-devel/icgrep/kernels/cc_scan_kernel.cpp

    r5317 r5435  
    9090}
    9191
    92 CCScanKernel::CCScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned streamNum) :
    93 BlockOrientedKernel(iBuilder, "CCScan",
     92CCScanKernel::CCScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned streamNum) :
     93BlockOrientedKernel("CCScan",
    9494              {Binding{iBuilder->getStreamSetTy(streamNum), "matchResults"}},
    9595              {}, {}, {}, {Binding{iBuilder->getSizeTy(), "BlockNo"}}),
  • icGREP/icgrep-devel/icgrep/kernels/cc_scan_kernel.h

    r5315 r5435  
    1515class CCScanKernel : public BlockOrientedKernel {
    1616public:
    17     CCScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned streamNum);
     17    CCScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned streamNum);
    1818       
    1919private:
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5431 r5435  
    1414namespace kernel {
    1515
    16 inline std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask) {
     16inline std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * const iBuilder, const unsigned fw, Value * del_mask) {
    1717    Value * m = iBuilder->simd_not(del_mask);
    1818    Value * mk = iBuilder->simd_slli(fw, del_mask, 1);
     
    3131}
    3232
    33 inline Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask, const std::vector<Value *> & mv, Value * strm) {
     33inline Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * const iBuilder, const unsigned fw, Value * del_mask, const std::vector<Value *> & mv, Value * strm) {
    3434    Value * s = iBuilder->simd_and(strm, iBuilder->simd_not(del_mask));
    3535    for (unsigned i = 0; i < mv.size(); i++) {
     
    4141}
    4242
    43 inline Value * partial_sum_popcount(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * mask) {
     43inline Value * partial_sum_popcount(IDISA::IDISA_Builder * const iBuilder, const unsigned fw, Value * mask) {
    4444    Value * field = iBuilder->simd_popcount(fw, mask);
    4545    const auto count = iBuilder->getBitBlockWidth() / fw;
     
    8181}
    8282
    83 DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount)
    84 : BlockOrientedKernel(iBuilder, "del" + std::to_string(fw) + "_" + std::to_string(streamCount),
     83DeletionKernel::DeletionKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned fw, unsigned streamCount)
     84: BlockOrientedKernel("del" + std::to_string(fw) + "_" + std::to_string(streamCount),
    8585              {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    8686               Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     
    9494const unsigned PEXT_width = 64;
    9595
    96 inline std::vector<Value *> get_PEXT_masks(IDISA::IDISA_Builder * iBuilder, Value * del_mask) {
     96inline std::vector<Value *> get_PEXT_masks(IDISA::IDISA_Builder * const iBuilder, Value * del_mask) {
    9797    Value * m = iBuilder->fwCast(PEXT_width, iBuilder->simd_not(del_mask));
    9898    std::vector<Value *> masks;
     
    105105// Apply PEXT deletion to a collection of blocks and swizzle the result.
    106106// strms contains the blocks to process
    107 inline std::vector<Value *> apply_PEXT_deletion_with_swizzle(IDISA::IDISA_Builder * iBuilder, const std::vector<Value *> & masks, std::vector<Value *> strms) {   
     107inline std::vector<Value *> apply_PEXT_deletion_with_swizzle(IDISA::IDISA_Builder * const iBuilder, const std::vector<Value *> & masks, std::vector<Value *> strms) {
    108108    Value * PEXT_func = nullptr;
    109109    if (PEXT_width == 64) {
     
    148148}
    149149
    150 inline Value * apply_PEXT_deletion(IDISA::IDISA_Builder * iBuilder, const std::vector<Value *> & masks, Value * strm) { 
     150inline Value * apply_PEXT_deletion(IDISA::IDISA_Builder * const iBuilder, const std::vector<Value *> & masks, Value * strm) {
    151151    Value * PEXT_func = nullptr;
    152152    if (PEXT_width == 64) {
     
    224224}
    225225
    226 DeleteByPEXTkernel::DeleteByPEXTkernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle)
    227     : BlockOrientedKernel(iBuilder, "PEXTdel" + std::to_string(fw) + "_" + std::to_string(streamCount) + (shouldSwizzle ? "swiz" : "noswiz"),
    228                       {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    229                           Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
    230                       {}, {}, {}, {})
     226DeleteByPEXTkernel::DeleteByPEXTkernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle)
     227: BlockOrientedKernel("PEXTdel" + std::to_string(fw) + "_" + std::to_string(streamCount) + (shouldSwizzle ? "swiz" : "noswiz"),
     228                  {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
     229                      Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     230                  {}, {}, {}, {})
    231231, mDelCountFieldWidth(fw)
    232232, mStreamCount(streamCount)
     
    262262//
    263263
    264    
    265 
    266 SwizzledBitstreamCompressByCount::SwizzledBitstreamCompressByCount(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned fieldWidth)
    267     : BlockOrientedKernel(iBuilder, "swizzled_compress" + std::to_string(fieldWidth) + "_" + std::to_string(bitStreamCount),
    268                          {Binding{iBuilder->getStreamSetTy(), "countsPerStride"}}, {}, {}, {}, {})
     264SwizzledBitstreamCompressByCount::SwizzledBitstreamCompressByCount(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth)
     265: BlockOrientedKernel("swizzled_compress" + std::to_string(fieldWidth) + "_" + std::to_string(bitStreamCount),
     266                     {Binding{iBuilder->getStreamSetTy(), "countsPerStride"}}, {}, {}, {}, {})
    269267, mBitStreamCount(bitStreamCount)
    270268    , mFieldWidth(fieldWidth)
     
    283281        addScalar(iBuilder->getSizeTy(), "pendingOffset");
    284282}
    285 
    286283   
    287284void SwizzledBitstreamCompressByCount::generateDoBlockMethod() {
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5431 r5435  
    2525class DeletionKernel final : public BlockOrientedKernel {
    2626public:
    27     DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount);
     27    DeletionKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned fw, unsigned streamCount);
    2828    bool isCachable() const override { return true; }
    2929    bool moduleIDisSignature() const override { return true; }
     
    3838class DeleteByPEXTkernel final : public BlockOrientedKernel {
    3939public:
    40     DeleteByPEXTkernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
     40    DeleteByPEXTkernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
    4141    bool isCachable() const override { return true; }
    4242    bool moduleIDisSignature() const override { return true; }
     
    5757class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
    5858public:
    59     SwizzledBitstreamCompressByCount(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
     59    SwizzledBitstreamCompressByCount(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
    6060    bool isCachable() const override { return true; }
    6161    bool moduleIDisSignature() const override { return true; }
  • icGREP/icgrep-devel/icgrep/kernels/evenodd.cpp

    r5356 r5435  
    1818}
    1919
    20 EvenOddKernel::EvenOddKernel(IDISA::IDISA_Builder * builder)
    21 : BlockOrientedKernel(builder, "EvenOdd", {Binding{builder->getStreamSetTy(8, 1), "BasisBits"}}, {Binding{builder->getStreamSetTy(2, 1), "even_odd"}}, {}, {}, {}) {
     20EvenOddKernel::EvenOddKernel(const std::unique_ptr<IDISA::IDISA_Builder> & builder)
     21: BlockOrientedKernel("EvenOdd", {Binding{builder->getStreamSetTy(8, 1), "BasisBits"}}, {Binding{builder->getStreamSetTy(2, 1), "even_odd"}}, {}, {}, {}) {
    2222    setNoTerminateAttribute(true);
    2323
  • icGREP/icgrep-devel/icgrep/kernels/evenodd.h

    r5297 r5435  
    1414class EvenOddKernel : public BlockOrientedKernel {
    1515public:
    16     EvenOddKernel(IDISA::IDISA_Builder * builder);
     16    EvenOddKernel(const std::unique_ptr<IDISA::IDISA_Builder> & builder);
    1717    virtual ~EvenOddKernel() {}
    1818private:
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp

    r5431 r5435  
    2929}
    3030
    31 ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re)
     31ICgrepKernelBuilder::ICgrepKernelBuilder (const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, RE * const re)
    3232: PabloKernel(iBuilder, "",
    3333              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
     
    5757}
    5858
    59 InvertMatchesKernel::InvertMatchesKernel(IDISA::IDISA_Builder * builder)
    60 : BlockOrientedKernel(builder, "Invert", {Binding{builder->getStreamSetTy(1, 1), "matchedLines"}, Binding{builder->getStreamSetTy(1, 1), "lineBreaks"}}, {Binding{builder->getStreamSetTy(1, 1), "nonMatches"}}, {}, {}, {}) {
    61     setNoTerminateAttribute(true);
    62    
     59InvertMatchesKernel::InvertMatchesKernel(const std::unique_ptr<IDISA::IDISA_Builder> & builder)
     60: BlockOrientedKernel("Invert", {Binding{builder->getStreamSetTy(1, 1), "matchedLines"}, Binding{builder->getStreamSetTy(1, 1), "lineBreaks"}}, {Binding{builder->getStreamSetTy(1, 1), "nonMatches"}}, {}, {}, {}) {
     61    setNoTerminateAttribute(true);   
    6362}
    6463
    6564
    66 PopcountKernel::PopcountKernel (IDISA::IDISA_Builder * const iBuilder)
     65PopcountKernel::PopcountKernel (const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
    6766: PabloKernel(iBuilder, "Popcount",
    6867              {Binding{iBuilder->getStreamSetTy(1), "toCount"}},
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.h

    r5431 r5435  
    1414class ICgrepKernelBuilder: public pablo::PabloKernel {
    1515public:
    16     ICgrepKernelBuilder(IDISA::IDISA_Builder * const iBuilder, re::RE * const re_ast);
     16    ICgrepKernelBuilder(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, re::RE * const re_ast);
    1717   
    1818    std::string makeSignature() override;
     
    2828class InvertMatchesKernel : public BlockOrientedKernel {
    2929public:
    30     InvertMatchesKernel(IDISA::IDISA_Builder * builder);
     30    InvertMatchesKernel(const std::unique_ptr<IDISA::IDISA_Builder> & builder);
    3131private:
    3232    void generateDoBlockMethod() override;
     
    3636class PopcountKernel : public pablo::PabloKernel {
    3737public:
    38     PopcountKernel(IDISA::IDISA_Builder * builder);
     38    PopcountKernel(const std::unique_ptr<IDISA::IDISA_Builder> & builder);
    3939};
    4040
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5433 r5435  
    4040}
    4141
    42 Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * referenceItems, Value * doFinal) const {
     42Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * const b, Value * referenceItems, Value * doFinal) const {
    4343    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
    4444        if (mRatioNumerator == mRatioDenominator) {
     
    6868}
    6969
    70 Value * ProcessingRate::CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * b, Value * outputItems, Value * doFinal) const {
     70Value * ProcessingRate::CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, Value * outputItems, Value * doFinal) const {
    7171    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio) {
    7272        if (mRatioNumerator == mRatioDenominator) {
     
    168168}
    169169
    170 void KernelInterface::setInitialArguments(std::vector<Value *> args) {
    171     mInitialArguments = args;
    172 }
    173 
    174170Function * KernelInterface::getInitFunction(Module * const module) const {
    175171    const auto name = getName() + INIT_SUFFIX;
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5434 r5435  
    3838    bool isExact() const {return (mKind == ProcessingRateKind::FixedRatio)||(mKind == ProcessingRateKind::RoundUp)||(mKind == ProcessingRateKind::Add1) ;}
    3939    bool isUnknownRate() const { return mKind == ProcessingRateKind::Unknown; }
    40     llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems, llvm::Value * doFinal = nullptr) const;
    41     llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * b, llvm::Value * outputItems, llvm::Value * doFinal = nullptr) const;
     40    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * const b, llvm::Value * principalInputItems, llvm::Value * doFinal = nullptr) const;
     41    llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, llvm::Value * outputItems, llvm::Value * doFinal) const;
    4242    friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
    4343    friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
     
    4747    uint16_t getRatioNumerator() const { return mRatioNumerator;}
    4848    uint16_t getRatioDenominator() const { return mRatioDenominator;}
    49     std::string referenceStreamSet() const { return mReferenceStreamSet;}
     49    const std::string & referenceStreamSet() const { return mReferenceStreamSet;}
    5050protected:
    5151    ProcessingRate(ProcessingRateKind k, unsigned numerator, unsigned denominator, std::string && referenceStreamSet)
     
    9191    virtual std::string makeSignature() = 0;
    9292
    93     const std::vector<Binding> & getStreamInputs() const { return mStreamSetInputs; }
    94 
    95     const std::vector<Binding> & getStreamOutputs() const { return mStreamSetOutputs; }
    96 
    97     const std::vector<Binding> & getScalarInputs() const { return mScalarInputs; }
    98 
    99     const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs; }
    100        
     93    const std::vector<Binding> & getStreamInputs() const {
     94        return mStreamSetInputs;
     95    }
     96
     97    const Binding & getStreamInput(const unsigned i) const {
     98        return mStreamSetInputs[i];
     99    }
     100
     101    const std::vector<Binding> & getStreamOutputs() const {
     102        return mStreamSetOutputs;
     103    }
     104
     105    const Binding & getStreamOutput(const unsigned i) const {
     106        return mStreamSetOutputs[i];
     107    }
     108
     109    const std::vector<Binding> & getScalarInputs() const {
     110        return mScalarInputs;
     111    }
     112
     113    const Binding & getScalarInput(const unsigned i) const {
     114        return mScalarInputs[i];
     115    }
     116
     117    const std::vector<Binding> & getScalarOutputs() const {
     118        return mScalarOutputs;
     119    }
     120
     121    const Binding & getScalarOutput(const unsigned i) const {
     122        return mScalarOutputs[i];
     123    }
     124
    101125    // Add ExternalLinkage method declarations for the kernel to a given client module.
    102126    void addKernelDeclarations();
     
    110134    virtual void finalizeInstance() = 0;
    111135
    112     void setInitialArguments(std::vector<llvm::Value *> args);
    113 
     136    void setInitialArguments(std::vector<llvm::Value *> && args) {
     137        mInitialArguments.swap(args);
     138    }
    114139    llvm::Value * getInstance() const {
    115140        return mKernelInstance;
     
    119144        return mLookAheadPositions;
    120145    }
    121    
    122     virtual llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr) const = 0;
    123 
    124     virtual void setProducedItemCount(const std::string & name, llvm::Value * value) const = 0;
    125 
    126     virtual llvm::Value * getProcessedItemCount(const std::string & name) const = 0;
    127 
    128     virtual void setProcessedItemCount(const std::string & name, llvm::Value * value) const = 0;
    129 
    130     virtual llvm::Value * getConsumedItemCount(const std::string & name) const = 0;
    131 
    132     virtual void setConsumedItemCount(const std::string & name, llvm::Value * value) const = 0;
    133 
    134     virtual llvm::Value * getTerminationSignal() const = 0;
    135 
    136     virtual void setTerminationSignal() const = 0;
    137    
    138     void setLookAhead(unsigned lookAheadPositions) {
     146
     147    void setLookAhead(const unsigned lookAheadPositions) {
    139148        mLookAheadPositions = lookAheadPositions;
    140149    }
     
    150159protected:
    151160
     161    virtual llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr) const = 0;
     162
     163    virtual void setProducedItemCount(const std::string & name, llvm::Value * value) const = 0;
     164
     165    virtual llvm::Value * getProcessedItemCount(const std::string & name) const = 0;
     166
     167    virtual void setProcessedItemCount(const std::string & name, llvm::Value * value) const = 0;
     168
     169    virtual llvm::Value * getConsumedItemCount(const std::string & name) const = 0;
     170
     171    virtual void setConsumedItemCount(const std::string & name, llvm::Value * value) const = 0;
     172
     173    virtual llvm::Value * getTerminationSignal() const = 0;
     174
     175    virtual void setTerminationSignal() const = 0;
     176
    152177    llvm::Function * getInitFunction(llvm::Module * const module) const;
    153178
     
    156181    llvm::Function * getTerminateFunction(llvm::Module * const module) const;
    157182
    158     KernelInterface(IDISA::IDISA_Builder * const builder,
    159                     std::string kernelName,
     183    KernelInterface(std::string kernelName,
    160184                    std::vector<Binding> && stream_inputs,
    161185                    std::vector<Binding> && stream_outputs,
     
    163187                    std::vector<Binding> && scalar_outputs,
    164188                    std::vector<Binding> && internal_scalars)
    165     : iBuilder(builder)
     189    : iBuilder(nullptr)
     190    , mModule(nullptr)
    166191    , mKernelInstance(nullptr)
    167192    , mKernelStateType(nullptr)
     
    185210protected:
    186211   
    187     IDISA::IDISA_Builder *          iBuilder;
    188     llvm::Value *                   mKernelInstance;
    189     llvm::StructType *              mKernelStateType;
    190     unsigned                        mLookAheadPositions;
    191     std::string                     mKernelName;
    192     std::vector<llvm::Value *>      mInitialArguments;
    193     std::vector<Binding>            mStreamSetInputs;
    194     std::vector<Binding>            mStreamSetOutputs;
    195     std::vector<Binding>            mScalarInputs;
    196     std::vector<Binding>            mScalarOutputs;
    197     std::vector<Binding>            mInternalScalars;
     212    IDISA::IDISA_Builder *                  iBuilder;
     213    llvm::Module *                          mModule;
     214
     215    llvm::Value *                           mKernelInstance;
     216    llvm::StructType *                      mKernelStateType;
     217    unsigned                                mLookAheadPositions;
     218    std::string                             mKernelName;
     219    std::vector<llvm::Value *>              mInitialArguments;
     220    std::vector<Binding>                    mStreamSetInputs;
     221    std::vector<Binding>                    mStreamSetOutputs;
     222    std::vector<Binding>                    mScalarInputs;
     223    std::vector<Binding>                    mScalarOutputs;
     224    std::vector<Binding>                    mInternalScalars;
    198225};
    199226
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5434 r5435  
    1818#include <sstream>
    1919
    20 static const std::string DO_BLOCK_SUFFIX = "_DoBlock";
    21 
    22 static const std::string FINAL_BLOCK_SUFFIX = "_FinalBlock";
    23 
    24 static const std::string LOGICAL_SEGMENT_NO_SCALAR = "logicalSegNo";
    25 
    26 static const std::string PROCESSED_ITEM_COUNT_SUFFIX = "_processedItemCount";
    27 
    28 static const std::string CONSUMED_ITEM_COUNT_SUFFIX = "_consumedItemCount";
    29 
    30 static const std::string PRODUCED_ITEM_COUNT_SUFFIX = "_producedItemCount";
    31 
    32 static const std::string TERMINATION_SIGNAL = "terminationSignal";
    33 
    34 static const std::string BUFFER_PTR_SUFFIX = "_bufferPtr";
    35 
    36 static const std::string CONSUMER_SUFFIX = "_consumerLocks";
    37 
    3820using namespace llvm;
    39 using namespace kernel;
    4021using namespace parabix;
    4122
    42 unsigned KernelBuilder::addScalar(Type * const type, const std::string & name) {
     23namespace kernel {
     24
     25const std::string Kernel::DO_BLOCK_SUFFIX = "_DoBlock";
     26const std::string Kernel::FINAL_BLOCK_SUFFIX = "_FinalBlock";
     27const std::string Kernel::LOGICAL_SEGMENT_NO_SCALAR = "logicalSegNo";
     28const std::string Kernel::PROCESSED_ITEM_COUNT_SUFFIX = "_processedItemCount";
     29const std::string Kernel::CONSUMED_ITEM_COUNT_SUFFIX = "_consumedItemCount";
     30const std::string Kernel::PRODUCED_ITEM_COUNT_SUFFIX = "_producedItemCount";
     31const std::string Kernel::TERMINATION_SIGNAL = "terminationSignal";
     32const std::string Kernel::BUFFER_PTR_SUFFIX = "_bufferPtr";
     33const std::string Kernel::CONSUMER_SUFFIX = "_consumerLocks";
     34
     35unsigned Kernel::addScalar(Type * const type, const std::string & name) {
    4336    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    4437        report_fatal_error("Cannot add field " + name + " to " + getName() + " after kernel state finalized");
     
    5346}
    5447
    55 unsigned KernelBuilder::addUnnamedScalar(Type * const type) {
     48unsigned Kernel::addUnnamedScalar(Type * const type) {
    5649    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    5750        report_fatal_error("Cannot add unnamed field  to " + getName() + " after kernel state finalized");
     
    6255}
    6356
    64 void KernelBuilder::prepareStreamSetNameMap() {
     57void Kernel::prepareStreamSetNameMap() {
    6558    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    6659        mStreamMap.emplace(mStreamSetInputs[i].name, std::make_pair(Port::Input, i));
     
    7164}
    7265   
    73 void KernelBuilder::prepareKernel() {
     66void Kernel::prepareKernel() {
     67    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    7468    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    7569        report_fatal_error("Cannot prepare kernel after kernel state finalized");
     
    135129}
    136130
    137 void KernelBuilder::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs) {
    138     std::stringstream cacheName;
     131void Kernel::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs) {
     132    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
     133    assert ("IDISA Builder does not have a valid Module" && iBuilder->getModule());
     134    std::stringstream cacheName;   
    139135    cacheName << getName() << '_' << iBuilder->getBuilderUniqueName();
    140136    for (const StreamSetBuffer * b: inputs) {
     
    149145}
    150146
    151 void KernelBuilder::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs, Module * const kernelModule) {
     147void Kernel::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs, Module * const kernelModule) {
    152148    assert (mModule == nullptr);
     149    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    153150    assert (mStreamSetInputBuffers.empty());
    154151    assert (mStreamSetOutputBuffers.empty());
     
    157154        report_fatal_error(getName() + ": expected " + std::to_string(mStreamSetInputs.size()) +
    158155                           " input stream sets but was given "
    159                            + std::to_string(mStreamSetInputBuffers.size()));
     156                           + std::to_string(inputs.size()));
    160157    }
    161158
     
    172169        report_fatal_error(getName() + ": expected " + std::to_string(mStreamSetOutputs.size())
    173170                           + " output stream sets but was given "
    174                            + std::to_string(mStreamSetOutputBuffers.size()));
     171                           + std::to_string(outputs.size()));
    175172    }
    176173
     
    178175        StreamSetBuffer * const buf = outputs[i];
    179176        if (LLVM_UNLIKELY(buf == nullptr)) {
    180             report_fatal_error(getName() + ": output stream set " + std::to_string(i)
    181                                + " cannot be null");
     177            report_fatal_error(getName() + ": output stream set " + std::to_string(i) + " cannot be null");
    182178        }
    183179        if (LLVM_LIKELY(buf->getProducer() == nullptr)) {
     
    199195
    200196// Default kernel signature: generate the IR and emit as byte code.
    201 std::string KernelBuilder::makeSignature() {
     197std::string Kernel::makeSignature() {
     198    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    202199    if (LLVM_LIKELY(moduleIDisSignature())) {
    203200        return getModule()->getModuleIdentifier();
     
    211208}
    212209
    213 void KernelBuilder::generateKernel() {
     210void Kernel::generateKernel() {
     211    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    214212    // If the module id cannot uniquely identify this kernel, "generateKernelSignature()" will have already
    215213    // generated the unoptimized IR.
     
    227225}
    228226
    229 inline void KernelBuilder::callGenerateInitializeMethod() {
     227inline void Kernel::callGenerateInitializeMethod() {
    230228    mCurrentMethod = getInitFunction(iBuilder->getModule());
    231229    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
     
    243241}
    244242
    245 inline void KernelBuilder::callGenerateDoSegmentMethod() {
     243inline void Kernel::callGenerateDoSegmentMethod() {
    246244    mCurrentMethod = getDoSegmentFunction(iBuilder->getModule());
    247245    BasicBlock * const entry = CreateBasicBlock(getName() + "_entry");
     
    261259}
    262260
    263 inline void KernelBuilder::callGenerateFinalizeMethod() {
     261inline void Kernel::callGenerateFinalizeMethod() {
    264262    mCurrentMethod = getTerminateFunction(iBuilder->getModule());
    265263    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
     
    283281}
    284282
    285 ConstantInt * KernelBuilder::getScalarIndex(const std::string & name) const {
     283unsigned Kernel::getScalarIndex(const std::string & name) const {
     284    assert ("getScalarIndex was given a null IDISA Builder" && iBuilder);
    286285    const auto f = mKernelMap.find(name);
    287286    if (LLVM_UNLIKELY(f == mKernelMap.end())) {
    288287        report_fatal_error(getName() + " does not contain scalar: " + name);
    289288    }
    290     return iBuilder->getInt32(f->second);
    291 }
    292 
    293 Value * KernelBuilder::getProducedItemCount(const std::string & name, Value * doFinal) const {
     289    return f->second;
     290}
     291
     292Value * Kernel::getProducedItemCount(const std::string & name, Value * doFinal) const {
    294293    Port port; unsigned ssIdx;
    295294    std::tie(port, ssIdx) = getStreamPort(name);
     
    319318}
    320319
    321 llvm::Value * KernelBuilder::getAvailableItemCount(const std::string & name) const {
     320llvm::Value * Kernel::getAvailableItemCount(const std::string & name) const {
    322321    for (unsigned i = 0; i < mStreamSetInputs.size(); ++i) {
    323322        if (mStreamSetInputs[i].name == name) {
     
    328327}
    329328
    330 Value * KernelBuilder::getProcessedItemCount(const std::string & name) const {
     329Value * Kernel::getProcessedItemCount(const std::string & name) const {
    331330    Port port; unsigned ssIdx;
    332331    std::tie(port, ssIdx) = getStreamPort(name);
     
    343342}
    344343
    345 Value * KernelBuilder::getConsumedItemCount(const std::string & name) const {
     344Value * Kernel::getConsumedItemCount(const std::string & name) const {
    346345    return getScalarField(name + CONSUMED_ITEM_COUNT_SUFFIX);
    347346}
    348347
    349 void KernelBuilder::setProducedItemCount(const std::string & name, Value * value) const {
     348void Kernel::setProducedItemCount(const std::string & name, Value * value) const {
    350349    setScalarField(name + PRODUCED_ITEM_COUNT_SUFFIX, value);
    351350}
    352351
    353 void KernelBuilder::setProcessedItemCount(const std::string & name, Value * value) const {
     352void Kernel::setProcessedItemCount(const std::string & name, Value * value) const {
    354353    setScalarField(name + PROCESSED_ITEM_COUNT_SUFFIX, value);
    355354}
    356355
    357 void KernelBuilder::setConsumedItemCount(const std::string & name, Value * value) const {
     356void Kernel::setConsumedItemCount(const std::string & name, Value * value) const {
    358357    setScalarField(name + CONSUMED_ITEM_COUNT_SUFFIX, value);
    359358}
    360359
    361 Value * KernelBuilder::getTerminationSignal() const {
     360Value * Kernel::getTerminationSignal() const {
    362361    return getScalarField(TERMINATION_SIGNAL);
    363362}
    364363
    365 void KernelBuilder::setTerminationSignal() const {
     364void Kernel::setTerminationSignal() const {
    366365    setScalarField(TERMINATION_SIGNAL, iBuilder->getTrue());
    367366}
    368367
    369 LoadInst * KernelBuilder::acquireLogicalSegmentNo() const {
     368LoadInst * Kernel::acquireLogicalSegmentNo() const {
     369    assert (iBuilder);
    370370    return iBuilder->CreateAtomicLoadAcquire(getScalarFieldPtr(LOGICAL_SEGMENT_NO_SCALAR));
    371371}
    372372
    373 void KernelBuilder::releaseLogicalSegmentNo(Value * nextSegNo) const {
     373void Kernel::releaseLogicalSegmentNo(Value * nextSegNo) const {
    374374    iBuilder->CreateAtomicStoreRelease(nextSegNo, getScalarFieldPtr(LOGICAL_SEGMENT_NO_SCALAR));
    375375}
    376376
    377 llvm::Value * KernelBuilder::getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const {
     377llvm::Value * Kernel::getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const {
    378378    llvm::Value * instance = getStreamSetBufferPtr(name);
    379379    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
     
    381381}
    382382
    383 llvm::Value * KernelBuilder::getConsumerLock(const std::string & name) const {
     383llvm::Value * Kernel::getConsumerLock(const std::string & name) const {
    384384    return getScalarField(name + CONSUMER_SUFFIX);
    385385}
    386386
    387 void KernelBuilder::setConsumerLock(const std::string & name, llvm::Value * value) const {
     387void Kernel::setConsumerLock(const std::string & name, llvm::Value * value) const {
    388388    setScalarField(name + CONSUMER_SUFFIX, value);
    389389}
    390390
    391 inline Value * KernelBuilder::computeBlockIndex(const std::vector<Binding> & bindings, const std::string & name, Value * itemCount) const {
     391inline Value * Kernel::computeBlockIndex(const std::vector<Binding> & bindings, const std::string & name, Value * itemCount) const {
    392392    for (const Binding & b : bindings) {
    393393        if (b.name == name) {
     
    403403}
    404404
    405 Value * KernelBuilder::getInputStreamBlockPtr(const std::string & name, Value * streamIndex) const {
     405Value * Kernel::getInputStreamBlockPtr(const std::string & name, Value * streamIndex) const {
    406406    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    407407    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
     
    409409}
    410410
    411 Value * KernelBuilder::loadInputStreamBlock(const std::string & name, Value * streamIndex) const {
     411Value * Kernel::loadInputStreamBlock(const std::string & name, Value * streamIndex) const {
    412412    return iBuilder->CreateBlockAlignedLoad(getInputStreamBlockPtr(name, streamIndex));
    413413}
    414414
    415 Value * KernelBuilder::getInputStreamPackPtr(const std::string & name, Value * streamIndex, Value * packIndex) const {
     415Value * Kernel::getInputStreamPackPtr(const std::string & name, Value * streamIndex, Value * packIndex) const {
    416416    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    417417    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
     
    419419}
    420420
    421 Value * KernelBuilder::loadInputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex) const {
     421Value * Kernel::loadInputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex) const {
    422422    return iBuilder->CreateBlockAlignedLoad(getInputStreamPackPtr(name, streamIndex, packIndex));
    423423}
    424424
    425 llvm::Value * KernelBuilder::getInputStreamSetCount(const std::string & name) const {
     425llvm::Value * Kernel::getInputStreamSetCount(const std::string & name) const {
    426426    return getInputStreamSetBuffer(name)->getStreamSetCount(iBuilder, getStreamSetBufferPtr(name));
    427427}
    428428
    429 llvm::Value * KernelBuilder::getAdjustedInputStreamBlockPtr(Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const {
     429llvm::Value * Kernel::getAdjustedInputStreamBlockPtr(Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const {
    430430    Value * blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    431431    blockIndex = iBuilder->CreateAdd(blockIndex, blockAdjustment);
     
    434434}
    435435
    436 Value * KernelBuilder::getOutputStreamBlockPtr(const std::string & name, Value * streamIndex) const {
     436Value * Kernel::getOutputStreamBlockPtr(const std::string & name, Value * streamIndex) const {
    437437    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    438438    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
     
    440440}
    441441
    442 void KernelBuilder::storeOutputStreamBlock(const std::string & name, Value * streamIndex, Value * toStore) const {
     442void Kernel::storeOutputStreamBlock(const std::string & name, Value * streamIndex, Value * toStore) const {
    443443    return iBuilder->CreateBlockAlignedStore(toStore, getOutputStreamBlockPtr(name, streamIndex));
    444444}
    445445
    446 Value * KernelBuilder::getOutputStreamPackPtr(const std::string & name, Value * streamIndex, Value * packIndex) const {
     446Value * Kernel::getOutputStreamPackPtr(const std::string & name, Value * streamIndex, Value * packIndex) const {
    447447    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    448448    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
     
    450450}
    451451
    452 void KernelBuilder::storeOutputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex, Value * toStore) const {
     452void Kernel::storeOutputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex, Value * toStore) const {
    453453    return iBuilder->CreateBlockAlignedStore(toStore, getOutputStreamPackPtr(name, streamIndex, packIndex));
    454454}
    455455
    456 llvm::Value * KernelBuilder::getOutputStreamSetCount(const std::string & name) const {
     456llvm::Value * Kernel::getOutputStreamSetCount(const std::string & name) const {
    457457    return getOutputStreamSetBuffer(name)->getStreamSetCount(iBuilder, getStreamSetBufferPtr(name));
    458458}
    459459
    460 Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     460Value * Kernel::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    461461    return getInputStreamSetBuffer(name)->getRawItemPointer(iBuilder, getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    462462}
    463463
    464 Value * KernelBuilder::getRawOutputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     464Value * Kernel::getRawOutputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    465465    return getOutputStreamSetBuffer(name)->getRawItemPointer(iBuilder, getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    466466}
    467467
    468 Value * KernelBuilder::getBaseAddress(const std::string & name) const {
     468Value * Kernel::getBaseAddress(const std::string & name) const {
    469469    return getAnyStreamSetBuffer(name)->getBaseAddress(iBuilder, getStreamSetBufferPtr(name));
    470470}
    471471
    472 void KernelBuilder::setBaseAddress(const std::string & name, Value * const addr) const {
     472void Kernel::setBaseAddress(const std::string & name, Value * const addr) const {
    473473    return getAnyStreamSetBuffer(name)->setBaseAddress(iBuilder, getStreamSetBufferPtr(name), addr);
    474474}
    475475
    476 Value * KernelBuilder::getBufferedSize(const std::string & name) const {
     476Value * Kernel::getBufferedSize(const std::string & name) const {
    477477    return getAnyStreamSetBuffer(name)->getBufferedSize(iBuilder, getStreamSetBufferPtr(name));
    478478}
    479479
    480 void KernelBuilder::setBufferedSize(const std::string & name, Value * size) const {
     480void Kernel::setBufferedSize(const std::string & name, Value * size) const {
    481481    unsigned index; Port port;
    482482    std::tie(port, index) = getStreamPort(name);
     
    492492}
    493493
    494 void KernelBuilder::reserveBytes(const std::string & name, llvm::Value * value) const {
    495     Value * itemCount = getProducedItemCount(name);
    496     const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    497     buf->reserveBytes(iBuilder, getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
    498 }
    499 
    500 BasicBlock * KernelBuilder::CreateWaitForConsumers() const {
     494BasicBlock * Kernel::CreateWaitForConsumers() const {
    501495
    502496    const auto consumers = getStreamOutputs();
     
    552546}
    553547
    554 Value * KernelBuilder::getStreamSetBufferPtr(const std::string & name) const {
     548Value * Kernel::getStreamSetBufferPtr(const std::string & name) const {
    555549    return getScalarField(name + BUFFER_PTR_SUFFIX);
    556550}
    557551
    558 Argument * KernelBuilder::getParameter(Function * const f, const std::string & name) const {
     552Argument * Kernel::getParameter(Function * const f, const std::string & name) const {
    559553    for (auto & arg : f->getArgumentList()) {
    560554        if (arg.getName().equals(name)) {
     
    565559}
    566560
    567 CallInst * KernelBuilder::createDoSegmentCall(const std::vector<Value *> & args) const {
     561CallInst * Kernel::createDoSegmentCall(const std::vector<Value *> & args) const {
    568562    Function * const doSegment = getDoSegmentFunction(iBuilder->getModule());
    569563    assert (doSegment->getArgumentList().size() == args.size());
     
    571565}
    572566
    573 Value * KernelBuilder::getAccumulator(const std::string & accumName) const {
     567Value * Kernel::getAccumulator(const std::string & accumName) const {
    574568    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    575569    if (LLVM_UNLIKELY(mOutputScalarResult == nullptr)) {
     
    594588}
    595589
    596 BasicBlock * KernelBuilder::CreateBasicBlock(std::string && name) const {
     590BasicBlock * Kernel::CreateBasicBlock(std::string && name) const {
    597591    return BasicBlock::Create(iBuilder->getContext(), name, mCurrentMethod);
    598592}
    599593
    600 Value * KernelBuilder::createInstance() {
     594Value * Kernel::createInstance() {
     595    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    601596    if (LLVM_UNLIKELY(mKernelStateType == nullptr)) {
    602597        report_fatal_error("Cannot instantiate " + getName() + " before calling prepareKernel()");
     
    606601}
    607602
    608 void KernelBuilder::initializeInstance() {
    609 
     603void Kernel::initializeInstance() {
     604    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    610605    if (LLVM_UNLIKELY(getInstance() == nullptr)) {
    611606        report_fatal_error("Cannot initialize " + getName() + " before calling createInstance()");
    612607    }
    613 
    614608    std::vector<Value *> args;
    615609    args.reserve(1 + mInitialArguments.size() + mStreamSetInputBuffers.size() + (mStreamSetOutputBuffers.size() * 2));
     
    643637    }
    644638    assert (mStreamSetOutputs.size() == mStreamSetOutputBuffers.size());
    645 
    646639    IntegerType * const sizeTy = iBuilder->getSizeTy();
    647640    PointerType * const sizePtrTy = sizeTy->getPointerTo();
     
    655648        Value * const consumerSegNoArray = iBuilder->CreateAlloca(ArrayType::get(sizePtrTy, n));
    656649        for (unsigned i = 0; i < n; ++i) {
    657             KernelBuilder * const consumer = consumers[i];
     650            Kernel * const consumer = consumers[i];
    658651            assert ("all instances must be created prior to initialization of any instance" && consumer->getInstance());
     652            consumer->setBuilder(iBuilder);
    659653            Value * const segmentNoPtr = consumer->getScalarFieldPtr(LOGICAL_SEGMENT_NO_SCALAR);
    660654            iBuilder->CreateStore(segmentNoPtr, iBuilder->CreateGEP(consumerSegNoArray, { iBuilder->getInt32(0), iBuilder->getInt32(i) }));
     
    673667//  each block of the given number of blocksToDo, and then updates counts.
    674668
    675 void BlockOrientedKernel::generateDoSegmentMethod() {
    676 
     669void BlockOrientedKernel::generateDoSegmentMethod() {   
    677670    BasicBlock * const entryBlock = iBuilder->GetInsertBlock();
    678671    BasicBlock * const strideLoopCond = CreateBasicBlock(getName() + "_strideLoopCond");
     
    910903}
    911904
    912 void KernelBuilder::finalizeInstance() {
     905void Kernel::finalizeInstance() {
     906    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    913907    mOutputScalarResult = iBuilder->CreateCall(getTerminateFunction(iBuilder->getModule()), { getInstance() });
    914908}
    915909
    916 KernelBuilder::StreamPort KernelBuilder::getStreamPort(const std::string & name) const {
     910Kernel::StreamPort Kernel::getStreamPort(const std::string & name) const {
    917911    const auto f = mStreamMap.find(name);
    918912    if (LLVM_UNLIKELY(f == mStreamMap.end())) {
     
    923917
    924918// CONSTRUCTOR
    925 KernelBuilder::KernelBuilder(IDISA::IDISA_Builder * builder,
    926                              std::string && kernelName,
     919Kernel::Kernel(std::string && kernelName,
    927920                             std::vector<Binding> && stream_inputs,
    928921                             std::vector<Binding> && stream_outputs,
     
    930923                             std::vector<Binding> && scalar_outputs,
    931924                             std::vector<Binding> && internal_scalars)
    932 : KernelInterface(builder, std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars))
    933 , mModule(nullptr)
     925: KernelInterface(std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars))
    934926, mCurrentMethod(nullptr)
    935927, mNoTerminateAttribute(false)
     
    940932}
    941933
    942 KernelBuilder::~KernelBuilder() {
     934Kernel::~Kernel() {
    943935
    944936}
    945937
    946938// CONSTRUCTOR
    947 BlockOrientedKernel::BlockOrientedKernel(IDISA::IDISA_Builder * builder,
    948                                          std::string && kernelName,
     939BlockOrientedKernel::BlockOrientedKernel(std::string && kernelName,
    949940                                         std::vector<Binding> && stream_inputs,
    950941                                         std::vector<Binding> && stream_outputs,
     
    952943                                         std::vector<Binding> && scalar_outputs,
    953944                                         std::vector<Binding> && internal_scalars)
    954 : KernelBuilder(builder, std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars))
     945: Kernel(std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars))
    955946, mDoBlockMethod(nullptr)
    956947, mStrideLoopBody(nullptr)
     
    961952
    962953// CONSTRUCTOR
    963 SegmentOrientedKernel::SegmentOrientedKernel(IDISA::IDISA_Builder * builder,
    964                                              std::string && kernelName,
     954SegmentOrientedKernel::SegmentOrientedKernel(std::string && kernelName,
    965955                                             std::vector<Binding> && stream_inputs,
    966956                                             std::vector<Binding> && stream_outputs,
     
    968958                                             std::vector<Binding> && scalar_outputs,
    969959                                             std::vector<Binding> && internal_scalars)
    970 : KernelBuilder(builder, std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars)) {
    971 
    972 }
    973 
     960: Kernel(std::move(kernelName), std::move(stream_inputs), std::move(stream_outputs), std::move(scalar_parameters), std::move(scalar_outputs), std::move(internal_scalars)) {
     961
     962}
     963
     964}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5431 r5435  
    44 */
    55
    6 #ifndef KERNEL_BUILDER_H
    7 #define KERNEL_BUILDER_H
     6#ifndef KERNEL_H
     7#define KERNEL_H
    88
    99#include "interface.h"
     
    2222namespace kernel {
    2323   
    24 class KernelBuilder : public KernelInterface {
     24class Kernel : public KernelInterface {
    2525protected:
    2626    using KernelMap = boost::container::flat_map<std::string, unsigned>;
     
    2929    using StreamMap = boost::container::flat_map<std::string, StreamPort>;
    3030    using StreamSetBuffers = std::vector<parabix::StreamSetBuffer *>;
    31     using Kernels = std::vector<KernelBuilder *>;
    32 
    33     friend void ::generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
    34     friend void ::generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
    35     friend void ::generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
     31    using Kernels = std::vector<Kernel *>;
     32
     33    friend class KernelBuilder;
     34    friend void ::generateSegmentParallelPipeline(IDISA::IDISA_Builder * const, const Kernels &);
     35    friend void ::generatePipelineLoop(IDISA::IDISA_Builder * const, const Kernels &);
     36    friend void ::generateParallelPipeline(IDISA::IDISA_Builder * const, const Kernels &);
     37
     38    static const std::string DO_BLOCK_SUFFIX;
     39    static const std::string FINAL_BLOCK_SUFFIX;
     40    static const std::string LOGICAL_SEGMENT_NO_SCALAR;
     41    static const std::string PROCESSED_ITEM_COUNT_SUFFIX;
     42    static const std::string CONSUMED_ITEM_COUNT_SUFFIX;
     43    static const std::string PRODUCED_ITEM_COUNT_SUFFIX;
     44    static const std::string TERMINATION_SIGNAL;
     45    static const std::string BUFFER_PTR_SUFFIX;
     46    static const std::string CONSUMER_SUFFIX;
     47
    3648public:
    3749   
     
    101113    void setConsumedItemCount(const std::string & name, llvm::Value * value) const final;
    102114
     115    llvm::Value * getTerminationSignal() const final;
     116
     117    void setTerminationSignal() const final;
     118
    103119    bool hasNoTerminateAttribute() const {
    104120        return mNoTerminateAttribute;
    105121    }
    106    
    107     llvm::Value * getTerminationSignal() const final;
    108 
    109     void setTerminationSignal() const final;
    110122
    111123    // Get the value of a scalar field for the current instance.
     
    115127
    116128    llvm::Value * getScalarFieldPtr(const std::string & fieldName) const {
    117         return getScalarFieldPtr(getScalarIndex(fieldName));
     129        return getScalarFieldPtr(iBuilder->getInt32(getScalarIndex(fieldName)));
    118130    }
    119131
     
    143155    llvm::Argument * getParameter(llvm::Function * f, const std::string & name) const;
    144156
    145     inline llvm::IntegerType * getSizeTy() const {
    146         return getBuilder()->getSizeTy();
    147     }
    148 
    149     inline llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
    150         return getBuilder()->getStreamTy(FieldWidth);
    151     }
    152    
    153     inline llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    154         return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    155     }
    156        
    157     const StreamSetBuffers & getStreamSetInputBuffers() const { return mStreamSetInputBuffers; }
    158 
    159     const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const { return mStreamSetInputBuffers[i]; }
    160 
    161     const StreamSetBuffers & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
    162 
    163     const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const { return mStreamSetOutputBuffers[i]; }
     157    const StreamSetBuffers & getStreamSetInputBuffers() const {
     158        return mStreamSetInputBuffers;
     159    }
     160
     161    const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const {
     162        return mStreamSetInputBuffers[i];
     163    }
     164
     165    const StreamSetBuffers & getStreamSetOutputBuffers() const {
     166        return mStreamSetOutputBuffers;
     167    }
     168
     169    const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const {
     170        return mStreamSetOutputBuffers[i];
     171    }
    164172
    165173    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
     
    167175    llvm::Value * getAccumulator(const std::string & accumName) const;
    168176
    169     virtual ~KernelBuilder() = 0;
     177    virtual ~Kernel() = 0;
    170178
    171179protected:
    172180
    173181    // Constructor
    174     KernelBuilder(IDISA::IDISA_Builder * builder,
    175                   std::string && kernelName,
     182    Kernel(std::string && kernelName,
    176183                  std::vector<Binding> && stream_inputs,
    177184                  std::vector<Binding> && stream_outputs,
     
    190197    // all scalar fields have been added.   If there are no fields to
    191198    // be added, the default method for preparing kernel state may be used.
    192    
     199
    193200    void setNoTerminateAttribute(const bool noTerminate = true) {
    194201        mNoTerminateAttribute = noTerminate;
     
    217224   
    218225    // Get the index of a named scalar field within the kernel state struct.
    219     llvm::ConstantInt * getScalarIndex(const std::string & name) const;
     226    unsigned getScalarIndex(const std::string & name) const;
    220227
    221228    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
     
    258265
    259266    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const;
     267
     268    llvm::BasicBlock * CreateWaitForConsumers() const;
     269
     270    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
     271
     272    llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    260273
    261274    llvm::Value * getIsFinal() const {
    262275        return mIsFinal;
    263276    }
    264 
    265     llvm::BasicBlock * CreateWaitForConsumers() const;
    266 
    267     llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
    268 
    269     llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    270277
    271278    void callGenerateInitializeMethod();
     
    313320protected:
    314321
    315     llvm::Module *                      mModule;
    316322    llvm::Function *                    mCurrentMethod;
    317323    bool                                mNoTerminateAttribute;
     
    331337};
    332338
    333 class SegmentOrientedKernel : public KernelBuilder {
    334 protected:
    335 
    336     SegmentOrientedKernel(IDISA::IDISA_Builder * builder,
    337                           std::string && kernelName,
     339class SegmentOrientedKernel : public Kernel {
     340protected:
     341
     342    SegmentOrientedKernel(std::string && kernelName,
    338343                          std::vector<Binding> && stream_inputs,
    339344                          std::vector<Binding> && stream_outputs,
     
    344349};
    345350
    346 class BlockOrientedKernel : public KernelBuilder {
     351class BlockOrientedKernel : public Kernel {
    347352protected:
    348353
     
    364369    void generateDoSegmentMethod() override final;
    365370
    366     BlockOrientedKernel(IDISA::IDISA_Builder * builder,
    367                         std::string && kernelName,
     371    BlockOrientedKernel(std::string && kernelName,
    368372                        std::vector<Binding> && stream_inputs,
    369373                        std::vector<Binding> && stream_outputs,
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp

    r5431 r5435  
    2121#define UNICODE_LINE_BREAK (!AlgorithmOptionIsSet(DisableUnicodeLineBreak))
    2222
    23 LineBreakKernelBuilder::LineBreakKernelBuilder (IDISA::IDISA_Builder * iBuilder, unsigned basisBitsCount)
    24 : PabloKernel(iBuilder, "lb", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}, {Binding{iBuilder->getStreamSetTy(1), "linebreak", Add1()}}) {
     23LineBreakKernelBuilder::LineBreakKernelBuilder(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned basisBitsCount)
     24: PabloKernel(b, "lb", {Binding{b->getStreamSetTy(basisBitsCount), "basis"}}, {Binding{b->getStreamSetTy(1), "linebreak", Add1()}}) {
     25
     26}
     27
     28void LineBreakKernelBuilder::prepareKernel() {
    2529
    2630    CC_Compiler ccc(this, getInput(0));
    27     auto & builder = ccc.getBuilder();
    28    
     31    auto & pb = ccc.getBuilder();
     32
    2933    PabloAST * LineBreak = nullptr;
    30     PabloAST * LF = ccc.compileCC("LF", makeCC(0x0A), builder);
     34    PabloAST * LF = ccc.compileCC("LF", makeCC(0x0A), pb);
    3135    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
    3236    PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
    3337
    34     Zeroes * const zero = builder.createZeroes();
    35     Var * crlf = builder.createVar("crlf", zero);
    36     PabloBuilder crb = PabloBuilder::Create(builder);
     38    Zeroes * const zero = pb.createZeroes();
     39    Var * crlf = pb.createVar("crlf", zero);
     40    PabloBuilder crb = PabloBuilder::Create(pb);
    3741#ifndef USE_LOOKAHEAD_CRLF
    3842    PabloAST * cr1 = crb.createAdvance(CR, 1, "cr1");
     
    4246    crb.createAssign(crlf, crb.createAnd(CR, lookaheadLF));
    4347#endif
    44     builder.createIf(CR, crb);
    45    
    46     Var * NEL_LS_PS = builder.createVar("NEL_LS_PS", zero);
     48    pb.createIf(CR, crb);
     49
     50    Var * NEL_LS_PS = pb.createVar("NEL_LS_PS", zero);
    4751
    4852    PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF));
    49     PabloBuilder it = PabloBuilder::Create(builder);
    50     builder.createIf(u8pfx, it);
     53    PabloBuilder it = PabloBuilder::Create(pb);
     54    pb.createIf(u8pfx, it);
    5155    PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it);
    5256    PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it);
     
    6165    //
    6266    // Three-byte sequences
    63 
    6467    Var * LS_PS = it.createVar("LS_PS", zero);
    6568    PabloBuilder it3 = PabloBuilder::Create(it);
     
    6972    it.createAssign(NEL_LS_PS, it.createOr(NEL, LS_PS));
    7073
    71 
    72     PabloAST * LB_chars = builder.createOr(LF_VT_FF_CR, NEL_LS_PS);
    73     PabloAST * UnicodeLineBreak = builder.createAnd(LB_chars, builder.createNot(crlf));  // count the CR, but not CRLF
     74    PabloAST * LB_chars = pb.createOr(LF_VT_FF_CR, NEL_LS_PS);
     75    PabloAST * UnicodeLineBreak = pb.createAnd(LB_chars, pb.createNot(crlf));  // count the CR, but not CRLF
    7476
    7577    PabloAST * lb = UNICODE_LINE_BREAK ? UnicodeLineBreak : LF;
    76     PabloAST * unterminatedLineAtEOF = builder.createAtEOF(builder.createAdvance(builder.createNot(LB_chars), 1));
    77     LineBreak = builder.createOr(lb, unterminatedLineAtEOF);
    78     PabloAST * const r = builder.createExtract(getOutput(0), builder.getInteger(0));
    79     builder.createAssign(r, LineBreak);
     78    PabloAST * unterminatedLineAtEOF = pb.createAtEOF(pb.createAdvance(pb.createNot(LB_chars), 1));
     79    LineBreak = pb.createOr(lb, unterminatedLineAtEOF);
     80    PabloAST * const r = pb.createExtract(getOutput(0), pb.getInteger(0));
     81    pb.createAssign(r, LineBreak);
    8082#ifdef USE_LOOKAHEAD_CRLF
    8183    setLookAhead(1);
    8284#endif
     85
     86    PabloKernel::prepareKernel();
    8387}
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5431 r5435  
    1212namespace kernel {
    1313
    14 class LineBreakKernelBuilder: public pablo::PabloKernel {
     14class LineBreakKernelBuilder final : public pablo::PabloKernel {
    1515public:
    16     LineBreakKernelBuilder(IDISA::IDISA_Builder * iBuilder, unsigned basisBitsCount);
     16    LineBreakKernelBuilder(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned basisBitsCount);
    1717    bool isCachable() const override { return true; }
    1818    bool moduleIDisSignature() const override { return true; }
     19protected:
     20    void prepareKernel() override;
    1921};
    2022
  • icGREP/icgrep-devel/icgrep/kernels/lz4_bytestream_decoder.cpp

    r5422 r5435  
    1313namespace {
    1414
    15 Value * getInputPtr(IDISA::IDISA_Builder * iBuilder, Value * blockStartPtr, Value * offset) {
     15Value * getInputPtr(IDISA::IDISA_Builder * const iBuilder, Value * blockStartPtr, Value * offset) {
    1616    return iBuilder->CreateGEP(
    1717            iBuilder->CreatePointerCast(blockStartPtr, iBuilder->getInt32Ty()->getPointerTo()),
     
    2020}
    2121
    22 Value * selectMin(IDISA::IDISA_Builder * iBuilder, Value * a, Value * b) {
     22Value * selectMin(IDISA::IDISA_Builder * const iBuilder, Value * a, Value * b) {
    2323    return iBuilder->CreateSelect(iBuilder->CreateICmpULT(a, b), a, b);
    2424}
     
    192192
    193193
    194 LZ4ByteStreamDecoderKernel::LZ4ByteStreamDecoderKernel(IDISA::IDISA_Builder * iBuilder, size_t bufferSize)
    195 : BlockOrientedKernel(iBuilder, "lz4ByteStreamDecoder",
     194LZ4ByteStreamDecoderKernel::LZ4ByteStreamDecoderKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, size_t bufferSize)
     195: BlockOrientedKernel("lz4ByteStreamDecoder",
    196196    // Inputs
    197197    {Binding{iBuilder->getStreamSetTy(2, 32), "literalIndexes"},
  • icGREP/icgrep-devel/icgrep/kernels/lz4_bytestream_decoder.h

    r5422 r5435  
    1616class LZ4ByteStreamDecoderKernel : public BlockOrientedKernel {
    1717public:
    18     LZ4ByteStreamDecoderKernel(IDISA::IDISA_Builder * iBuilder, size_t bufferSize);
     18    LZ4ByteStreamDecoderKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, size_t bufferSize);
    1919protected:
    2020    void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/lz4_index_decoder.cpp

    r5422 r5435  
    3636namespace {
    3737
    38 Value * countForwardZeroes(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    39     Value * cttzFunc = Intrinsic::getDeclaration(iBuilder->getModule(),
    40             Intrinsic::cttz, iBuilder->getSizeTy());
    41     // The last argument is is_zero_undef.  We'd like it to be false (defined)
    42     // so that cttz(0) == width.
    43     return iBuilder->CreateCall(cttzFunc, {bits, iBuilder->getFalse()});
    44 }
    45 
    46 #if 0
    47 Value * countReverseZeroes(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    48     Value * ctlzFunc = Intrinsic::getDeclaration(iBuilder->getModule(),
    49             Intrinsic::ctlz, iBuilder->getSizeTy());
    50     // The last argument is is_zero_undef.  We'd like it to be false (defined)
    51     // so that ctlz(0) == width.
    52     return iBuilder->CreateCall(ctlzFunc, {bits, iBuilder->getFalse()});
    53 }
    54 #endif
    55 
    56 Value * generateBitswap(IDISA::IDISA_Builder * iBuilder, Value * v) {
     38Value * generateBitswap(IDISA::IDISA_Builder * const iBuilder, Value * v) {
    5739    Value * bswapFunc = Intrinsic::getDeclaration(iBuilder->getModule(),
    5840            Intrinsic::bswap, v->getType());
     
    6042}
    6143
    62 Value * selectMin(IDISA::IDISA_Builder * iBuilder, Value * a, Value * b) {
     44Value * selectMin(IDISA::IDISA_Builder * const iBuilder, Value * a, Value * b) {
    6345    return iBuilder->CreateSelect(iBuilder->CreateICmpULT(a, b), a, b);
    6446}
    6547
    66 #if 0
    67 Value * selectMax(IDISA::IDISA_Builder * iBuilder, Value * a, Value * b) {
    68     return iBuilder->CreateSelect(iBuilder->CreateICmpUGT(a, b), a, b);
    69 }
    70 #endif
    71 
    72 Value * createStackVar(IDISA::IDISA_Builder * iBuilder, Type * type, StringRef name, Value * initializer = nullptr) {
     48Value * createStackVar(IDISA::IDISA_Builder * const iBuilder, Type * type, StringRef name, Value * initializer = nullptr) {
    7349    Value * var = iBuilder->CreateAlloca(type, nullptr, name);
    7450    if (initializer) {
     
    8056}
    8157
    82 void incStackVar(IDISA::IDISA_Builder * iBuilder, Value * svar, Value * increment = nullptr) {
     58void incStackVar(IDISA::IDISA_Builder * const iBuilder, Value * svar, Value * increment = nullptr) {
    8359    Value * value = iBuilder->CreateLoad(svar);
    8460    if (increment) {
     
    9066}
    9167
    92 Value * getOutputPtr(IDISA::IDISA_Builder * iBuilder, Value * blockStartPtr, Value * offset) {
     68Value * getOutputPtr(IDISA::IDISA_Builder * const iBuilder, Value * blockStartPtr, Value * offset) {
    9369    return iBuilder->CreateGEP(
    9470            iBuilder->CreatePointerCast(blockStartPtr, iBuilder->getInt32Ty()->getPointerTo()),
     
    528504    Value * literalLen = iBuilder->CreateLoad(sTempLength);
    529505    Value * literalExtEnd = iBuilder->CreateTrunc(
    530         countForwardZeroes(iBuilder, iBuilder->CreateNot(iBuilder->CreateLoad(sExtender))),
    531         iBuilder->getInt32Ty()
    532         );
     506                iBuilder->CreateCountForwardZeroes(iBuilder->CreateNot(iBuilder->CreateLoad(sExtender))),
     507                iBuilder->getInt32Ty());
    533508    printRTDebugInt("wordOffset", wordOffset);
    534509    printRTDebugInt("literalExtEnd", literalExtEnd);
     
    649624    Value * matchLen = iBuilder->CreateLoad(sTempLength);
    650625    Value * matchExtEnd = iBuilder->CreateTrunc(
    651         countForwardZeroes(iBuilder, iBuilder->CreateNot(iBuilder->CreateLoad(sExtender))),
     626        iBuilder->CreateCountForwardZeroes(iBuilder->CreateNot(iBuilder->CreateLoad(sExtender))),
    652627        iBuilder->getInt32Ty()
    653628        );
     
    739714}
    740715
    741 LZ4IndexDecoderKernel::LZ4IndexDecoderKernel(IDISA::IDISA_Builder * iBuilder)
    742 : BlockOrientedKernel(iBuilder, "lz4IndexDecoder",
     716LZ4IndexDecoderKernel::LZ4IndexDecoderKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     717: BlockOrientedKernel("lz4IndexDecoder",
    743718    // Inputs
    744719    {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"},
  • icGREP/icgrep-devel/icgrep/kernels/lz4_index_decoder.h

    r5422 r5435  
    2424class LZ4IndexDecoderKernel : public BlockOrientedKernel {
    2525public:
    26     LZ4IndexDecoderKernel(IDISA::IDISA_Builder * iBuilder);
     26    LZ4IndexDecoderKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    2727protected:
    2828    void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/match_count.cpp

    r5343 r5435  
    1212namespace kernel {
    1313
    14 MatchCount::MatchCount(IDISA::IDISA_Builder * iBuilder)
    15     : BlockOrientedKernel(iBuilder, "matchCount",
     14MatchCount::MatchCount(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     15    : BlockOrientedKernel("matchCount",
    1616                        {Binding{iBuilder->getStreamSetTy(1, 1), "matches"}}, {}, {}, {Binding{iBuilder->getSizeTy(), "matchedLineCount"}}, {}) {
    1717    }
  • icGREP/icgrep-devel/icgrep/kernels/match_count.h

    r5343 r5435  
    1414public:
    1515   
    16     MatchCount(IDISA::IDISA_Builder * iBuilder);
     16    MatchCount(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    1717   
    1818protected:
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5431 r5435  
    1414namespace kernel{
    1515       
    16 void p2s_step(IDISA::IDISA_Builder * iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
     16void p2s_step(IDISA::IDISA_Builder * const iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
    1717    Value * t0 = iBuilder->simd_if(1, hi_mask, p0, iBuilder->simd_srli(16, p1, shift));
    1818    Value * t1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, p0, shift), p1);
     
    2121}
    2222
    23 inline void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
     23inline void p2s(IDISA::IDISA_Builder * const iBuilder, Value * p[], Value * s[]) {
    2424    Value * bit00004444[2];
    2525    Value * bit22226666[2];
     
    146146}
    147147
    148 P2SKernel::P2SKernel(IDISA::IDISA_Builder * iBuilder)
    149 : BlockOrientedKernel(iBuilder, "p2s",
     148P2SKernel::P2SKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     149: BlockOrientedKernel("p2s",
    150150              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
    151151              {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
     
    153153}
    154154
    155 P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder)
    156 : BlockOrientedKernel(iBuilder, "p2s_compress",
     155P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     156: BlockOrientedKernel("p2s_compress",
    157157              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
    158158                      {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream", MaxRatio(1)}},
     
    160160}
    161161
    162 P2S16Kernel::P2S16Kernel(IDISA::IDISA_Builder * iBuilder)
    163 : BlockOrientedKernel(iBuilder, "p2s_16",
     162P2S16Kernel::P2S16Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     163: BlockOrientedKernel("p2s_16",
    164164              {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}},
    165165              {Binding{iBuilder->getStreamSetTy(1, 16), "i16Stream"}},
     
    168168
    169169
    170 P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * b)
    171 : BlockOrientedKernel(b, "p2s_16_compress",
     170P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(const std::unique_ptr<IDISA::IDISA_Builder> & b)
     171: BlockOrientedKernel("p2s_16_compress",
    172172              {Binding{b->getStreamSetTy(16, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "deletionCounts"}},
    173173              {Binding{b->getStreamSetTy(1, 16), "i16Stream", MaxRatio(1)}},
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5431 r5435  
    1414class P2SKernel final : public BlockOrientedKernel {
    1515public:
    16     P2SKernel(IDISA::IDISA_Builder * iBuilder);
     16    P2SKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    1717    bool isCachable() const override { return true; }
    1818    bool moduleIDisSignature() const override { return true; }
     
    2323class P2SKernelWithCompressedOutput final : public BlockOrientedKernel {
    2424public:
    25     P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);   
     25    P2SKernelWithCompressedOutput(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    2626    bool isCachable() const override { return true; }
    2727    bool moduleIDisSignature() const override { return true; }
     
    3232class P2S16Kernel final : public BlockOrientedKernel {
    3333public:
    34     P2S16Kernel(IDISA::IDISA_Builder * iBuilder);
     34    P2S16Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    3535    bool isCachable() const override { return true; }
    3636    bool moduleIDisSignature() const override { return true; }
     
    4141class P2S16KernelWithCompressedOutput final : public BlockOrientedKernel {
    4242public:
    43     P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);
     43    P2S16KernelWithCompressedOutput(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    4444    bool isCachable() const override { return true; }
    4545    bool moduleIDisSignature() const override { return true; }
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5431 r5435  
    450450}
    451451
    452 expand3_4Kernel::expand3_4Kernel(IDISA::IDISA_Builder * iBuilder)
    453 : SegmentOrientedKernel(iBuilder, "expand3_4",
     452expand3_4Kernel::expand3_4Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     453: SegmentOrientedKernel("expand3_4",
    454454            {Binding{iBuilder->getStreamSetTy(1, 8), "sourceStream"}},
    455455            {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream", FixedRatio(4,3)}},
     
    457457}
    458458
    459 radix64Kernel::radix64Kernel(IDISA::IDISA_Builder * iBuilder)
    460 : BlockOrientedKernel(iBuilder, "radix64",
     459radix64Kernel::radix64Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     460: BlockOrientedKernel("radix64",
    461461            {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream"}},
    462462            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
     
    464464}
    465465
    466 base64Kernel::base64Kernel(IDISA::IDISA_Builder * iBuilder)
    467 : BlockOrientedKernel(iBuilder, "base64",
     466base64Kernel::base64Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder)
     467: BlockOrientedKernel("base64",
    468468            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
    469469            {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream", RoundUpToMultiple(4)}},
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5431 r5435  
    2121class expand3_4Kernel final : public SegmentOrientedKernel {
    2222public:   
    23     expand3_4Kernel(IDISA::IDISA_Builder * iBuilder);
     23    expand3_4Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    2424    bool isCachable() const override { return true; }
     25    bool moduleIDisSignature() const override { return true; }
    2526private:
    2627    void generateDoSegmentMethod() override;
     
    2930class radix64Kernel final : public BlockOrientedKernel {
    3031public:
    31     radix64Kernel(IDISA::IDISA_Builder * iBuilder);
     32    radix64Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    3233    bool isCachable() const override { return true; }
     34    bool moduleIDisSignature() const override { return true; }
    3335private:
    3436    virtual void generateDoBlockMethod() override;
     
    3941class base64Kernel final : public BlockOrientedKernel {
    4042public:
    41     base64Kernel(IDISA::IDISA_Builder * iBuilder);
     43    base64Kernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    4244    bool isCachable() const override { return true; }
     45    bool moduleIDisSignature() const override { return true; }
    4346private:
    4447    virtual void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5431 r5435  
    1919const int PACK_LANES = 1;
    2020
    21 void s2p_step(IDISA::IDISA_Builder * iBuilder, Value * s0, Value * s1, Value * hi_mask, unsigned shift, Value * &p0, Value * &p1) {
     21void s2p_step(IDISA::IDISA_Builder * const iBuilder, Value * s0, Value * s1, Value * hi_mask, unsigned shift, Value * &p0, Value * &p1) {
    2222    Value * t0 = nullptr;
    2323    Value * t1 = nullptr;
     
    3535}
    3636
    37 void s2p(IDISA::IDISA_Builder * iBuilder, Value * input[], Value * output[]) {
     37void s2p(IDISA::IDISA_Builder * const iBuilder, Value * input[], Value * output[]) {
    3838    Value * bit00224466[4];
    3939    Value * bit11335577[4];
     
    6262/* Alternative transposition model, but small field width packs are problematic. */
    6363#if 0
    64 void s2p_ideal(IDISA::IDISA_Builder * iBuilder, Value * input[], Value * output[]) {
     64void s2p_ideal(IDISA::IDISA_Builder * const iBuilder, Value * input[], Value * output[]) {
    6565    Value * hi_nybble[4];
    6666    Value * lo_nybble[4];
     
    9393   
    9494#if 0
    95 void generateS2P_16Kernel(Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder) {
     95void generateS2P_16Kernel(Module *, IDISA::IDISA_Builder * const iBuilder, KernelBuilder * kBuilder) {
    9696    kBuilder->addInputStream(16, "unit_pack");
    9797    for(unsigned i = 0; i < 16; i++) {
     
    167167}
    168168
    169 S2PKernel::S2PKernel(IDISA::IDISA_Builder * builder, bool aligned)
    170 : BlockOrientedKernel(builder, aligned ? "s2p" : "s2p_unaligned",
    171     {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {Binding{builder->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
     169S2PKernel::S2PKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, bool aligned)
     170: BlockOrientedKernel(aligned ? "s2p" : "s2p_unaligned",
     171    {Binding{b->getStreamSetTy(1, 8), "byteStream"}}, {Binding{b->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
    172172  mAligned(aligned) {
    173173    setNoTerminateAttribute(true);
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5431 r5435  
    1414class S2PKernel final : public BlockOrientedKernel {
    1515public:   
    16     S2PKernel(IDISA::IDISA_Builder * builder, bool aligned = true);
     16    S2PKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, bool aligned = true);
    1717    bool isCachable() const override { return true; }
    1818    bool moduleIDisSignature() const override { return true; }
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5431 r5435  
    189189}
    190190
    191 ScanMatchKernel::ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, GrepType grepType, const unsigned codeUnitWidth)
    192 : BlockOrientedKernel(iBuilder, "scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
    193     {Binding{iBuilder->getStreamSetTy(1, 1), "matchResult"}, Binding{iBuilder->getStreamSetTy(1, 1), "lineBreak"}, Binding{iBuilder->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
     191ScanMatchKernel::ScanMatchKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, GrepType grepType, const unsigned codeUnitWidth)
     192: BlockOrientedKernel("scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
     193    {Binding{b->getStreamSetTy(1, 1), "matchResult"}, Binding{b->getStreamSetTy(1, 1), "lineBreak"}, Binding{b->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    194194    {},
    195     {Binding{iBuilder->getInt32Ty(), "FileIdx"}},
     195    {Binding{b->getInt32Ty(), "FileIdx"}},
    196196    {},
    197     {Binding{iBuilder->getSizeTy(), "BlockNo"}, Binding{iBuilder->getSizeTy(), "LineNum"}})
     197    {Binding{b->getSizeTy(), "BlockNo"}, Binding{b->getSizeTy(), "LineNum"}})
    198198, mGrepType(grepType) {
    199199
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5431 r5435  
    1616class ScanMatchKernel final : public BlockOrientedKernel {
    1717public:
    18     ScanMatchKernel(IDISA::IDISA_Builder * const iBuilder, const GrepType grepType, const unsigned codeUnitWidth);
     18    ScanMatchKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, const GrepType grepType, const unsigned codeUnitWidth);
    1919    bool isCachable() const override { return true; }
    2020    bool moduleIDisSignature() const override { return true; }
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5431 r5435  
    141141}
    142142
    143 MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    144 : SegmentOrientedKernel(iBuilder, "mmap_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth),
     143MMapSourceKernel::MMapSourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
     144: SegmentOrientedKernel("mmap_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth),
    145145{},
    146146{Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
     
    281281}
    282282
    283 ReadSourceKernel::ReadSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    284 : SegmentOrientedKernel(iBuilder, "read_source"
     283ReadSourceKernel::ReadSourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
     284: SegmentOrientedKernel("read_source"
    285285, {}
    286286, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}
     
    326326}
    327327
    328 MemorySourceKernel::MemorySourceKernel(IDISA::IDISA_Builder * iBuilder, Type * type, unsigned blocksPerSegment, unsigned codeUnitWidth)
    329 : SegmentOrientedKernel(iBuilder, "memory_source",
     328MemorySourceKernel::MemorySourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, Type * type, unsigned blocksPerSegment, unsigned codeUnitWidth)
     329: SegmentOrientedKernel("memory_source",
    330330    {},
    331331    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.h

    r5431 r5435  
    1313class MMapSourceKernel final : public SegmentOrientedKernel {
    1414public:
    15     MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     15    MMapSourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    1616    bool isCachable() const override { return true; }
    1717    bool moduleIDisSignature() const override { return true; }
     
    2929class ReadSourceKernel final : public SegmentOrientedKernel {
    3030public:
    31     ReadSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     31    ReadSourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    3232    bool isCachable() const override { return true; }
    3333    bool moduleIDisSignature() const override { return true; }
     
    4343class MemorySourceKernel final : public SegmentOrientedKernel {
    4444public:
    45     MemorySourceKernel(IDISA::IDISA_Builder * iBuilder, llvm::Type * type, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     45    MemorySourceKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, llvm::Type * type, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    4646    bool moduleIDisSignature() const override { return true; }
    4747protected:
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5431 r5435  
    6868}
    6969
    70 StdOutKernel::StdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth)
    71 : SegmentOrientedKernel(iBuilder, "stdout", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {})
     70StdOutKernel::StdOutKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned codeUnitWidth)
     71: SegmentOrientedKernel("stdout", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {})
    7272, mCodeUnitWidth(codeUnitWidth) {
    7373    setNoTerminateAttribute(true);
     
    165165}
    166166
    167 FileSink::FileSink(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth)
    168 : SegmentOrientedKernel(iBuilder, "filesink", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {},
     167FileSink::FileSink(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned codeUnitWidth)
     168: SegmentOrientedKernel("filesink", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {},
    169169                {Binding{iBuilder->getInt8PtrTy(), "fileName"}}, {}, {Binding{iBuilder->getInt8PtrTy(), "tmpFileName"}, Binding{iBuilder->getInt32Ty(), "fileDes"}})
    170170, mCodeUnitWidth(codeUnitWidth) {
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5418 r5435  
    1414class StdOutKernel : public SegmentOrientedKernel {
    1515public:
    16     StdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
     16    StdOutKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned codeUnitWidth);
    1717private:
    1818    void generateDoSegmentMethod() override final;
     
    2525class FileSink : public SegmentOrientedKernel {
    2626public: 
    27     FileSink(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
     27    FileSink(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned codeUnitWidth);
    2828protected:
    2929    void generateInitializeMethod() override final;
  • icGREP/icgrep-devel/icgrep/kernels/streams_merge.cpp

    r5338 r5435  
    1212namespace kernel {
    1313
    14 StreamsMerge::StreamsMerge(IDISA::IDISA_Builder * iBuilder, unsigned streamsPerSet, unsigned inputSets)
    15     : BlockOrientedKernel(iBuilder, "streamsMerge", {}, {}, {}, {}, {})
    16     , mStreamsPerSet(streamsPerSet)
    17     , mInputSets(inputSets) {
    18         for (unsigned i = 0; i < mInputSets; i++) {
    19             mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "inputGroup" + std::to_string(i)});
    20         }
    21         mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "output"});
     14StreamsMerge::StreamsMerge(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned streamsPerSet, unsigned inputSets)
     15: BlockOrientedKernel("streamsMerge", {}, {}, {}, {}, {})
     16, mStreamsPerSet(streamsPerSet)
     17, mInputSets(inputSets) {
     18    for (unsigned i = 0; i < mInputSets; i++) {
     19        mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "inputGroup" + std::to_string(i)});
    2220    }
     21    mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "output"});
     22}
    2323
    2424void StreamsMerge::generateDoBlockMethod() {
  • icGREP/icgrep-devel/icgrep/kernels/streams_merge.h

    r5338 r5435  
    1414public:
    1515   
    16     StreamsMerge(IDISA::IDISA_Builder * iBuilder, unsigned streamsPerSet=1, unsigned inputSets = 1);
     16    StreamsMerge(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned streamsPerSet=1, unsigned inputSets = 1);
    1717   
    1818protected:
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5434 r5435  
    2424using namespace IDISA;
    2525
    26 ArrayType * resolveStreamSetType(IDISA_Builder * const b, Type * type);
    27 
    28 StructType * resolveExpandableStreamSetType(IDISA_Builder * const b, Type * type);
    29 
    30 void StreamSetBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
     26ArrayType * resolveStreamSetType(const std::unique_ptr<IDISA_Builder> &b, Type * type);
     27
     28StructType * resolveExpandableStreamSetType(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type);
     29
     30void StreamSetBuffer::allocateBuffer(const std::unique_ptr<IDISA_Builder> & iBuilder) {
    3131    if (LLVM_LIKELY(mStreamSetBufferPtr == nullptr)) {
    3232        Type * const ty = getType();
     
    3838}
    3939
    40 Value * StreamSetBuffer::getStreamBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
     40Value * StreamSetBuffer::getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    4141    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
    4242    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    4343}
    4444
    45 Value * StreamSetBuffer::getStreamPackPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
     45Value * StreamSetBuffer::getStreamPackPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    4646    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
    4747    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    4848}
    4949
    50 void StreamSetBuffer::setBaseAddress(IDISA_Builder * const iBuilder, Value * /* self */, Value * /* addr */) const {
     50void StreamSetBuffer::setBaseAddress(IDISA::IDISA_Builder * const iBuilder, Value * /* self */, Value * /* addr */) const {
    5151    report_fatal_error("setBaseAddress is not supported by this buffer type");
    5252}
    5353
    54 Value * StreamSetBuffer::getBufferedSize(IDISA_Builder * const iBuilder, Value * /* self */) const {
     54Value * StreamSetBuffer::getBufferedSize(IDISA::IDISA_Builder * const iBuilder, Value * /* self */) const {
    5555    report_fatal_error("getBufferedSize is not supported by this buffer type");
    5656}
    5757
    58 void StreamSetBuffer::setBufferedSize(IDISA_Builder * const iBuilder, Value * /* self */, llvm::Value * /* size */) const {
     58void StreamSetBuffer::setBufferedSize(IDISA::IDISA_Builder * const iBuilder, Value * /* self */, llvm::Value * /* size */) const {
    5959    report_fatal_error("setBufferedSize is not supported by this buffer type");
    6060}
     
    6969}
    7070
    71 Value * StreamSetBuffer::getStreamSetCount(IDISA_Builder * const iBuilder, Value *) const {
     71Value * StreamSetBuffer::getStreamSetCount(IDISA::IDISA_Builder * const iBuilder, Value *) const {
    7272    uint64_t count = 1;
    7373    if (isa<ArrayType>(mBaseType)) {
     
    7777}
    7878
    79 inline Value * StreamSetBuffer::modByBufferBlocks(IDISA_Builder * const iBuilder, Value * const offset) const {
     79inline Value * StreamSetBuffer::modByBufferBlocks(IDISA::IDISA_Builder * const iBuilder, Value * const offset) const {
    8080    assert (offset->getType()->isIntegerTy());
    8181    if (isCapacityGuaranteed(offset, mBufferBlocks)) {
     
    9797 * The type of the pointer is i8* for fields of 8 bits or less, otherwise iN* for N-bit fields.
    9898 */
    99 Value * StreamSetBuffer::getRawItemPointer(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * absolutePosition) const {
     99Value * StreamSetBuffer::getRawItemPointer(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * absolutePosition) const {
    100100    Value * ptr = getBaseAddress(iBuilder, self);
    101101    if (!isa<ConstantInt>(streamIndex) || !cast<ConstantInt>(streamIndex)->isZero()) {
     
    116116}
    117117
    118 Value * StreamSetBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
     118Value * StreamSetBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * /* self */, Value * fromPosition) const {
    119119    if (isa<ArrayType>(mType) && dyn_cast<ArrayType>(mType)->getNumElements() > 1) {
    120120        Constant * stride = iBuilder->getSize(iBuilder->getStride());
     
    126126}
    127127
    128 Value * StreamSetBuffer::getLinearlyAccessibleBlocks(IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
     128Value * StreamSetBuffer::getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const iBuilder, Value * /* self */, Value * fromBlock) const {
    129129    Constant * bufBlocks = iBuilder->getSize(mBufferBlocks);
    130130    return iBuilder->CreateSub(bufBlocks, iBuilder->CreateURem(fromBlock, bufBlocks));
    131131}
    132132
    133 Value * StreamSetBuffer::getLinearlyWritableItems(IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
     133Value * StreamSetBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
    134134    return getLinearlyAccessibleItems(iBuilder, self, fromPosition);
    135135}
    136136
    137 Value * StreamSetBuffer::getLinearlyWritableBlocks(IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
     137Value * StreamSetBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
    138138    return getLinearlyAccessibleBlocks(iBuilder, self, fromBlock);
    139139}
    140140
    141 void StreamSetBuffer::reserveBytes(IDISA_Builder * const iBuilder, Value * self, llvm::Value *requested) const {
    142     report_fatal_error("reserve() can only be used with ExtensibleBuffers");
    143 }
    144 
    145 Value * StreamSetBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * self) const {
     141Value * StreamSetBuffer::getBaseAddress(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    146142    return self;
    147143}
    148144
    149 void StreamSetBuffer::releaseBuffer(IDISA_Builder * const iBuilder, Value * /* self */) const {
     145void StreamSetBuffer::releaseBuffer(IDISA::IDISA_Builder * const iBuilder, Value * /* self */) const {
    150146    /* do nothing: memory is stack allocated */
    151147}
    152148
    153 void StreamSetBuffer::createBlockAlignedCopy(IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
     149void StreamSetBuffer::createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
    154150    Type * size_ty = iBuilder->getSizeTy();
    155151    Type * i8ptr = iBuilder->getInt8PtrTy();
     
    189185
    190186// For a single block buffer, the block pointer is always the buffer base pointer.
    191 Value * SingleBlockBuffer::getStreamSetBlockPtr(IDISA_Builder * const, Value * self, Value *) const {
     187Value * SingleBlockBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const, Value * self, Value *) const {
    192188    return self;
    193189}
    194190
    195191// Source File Buffer
    196 Value * SourceBuffer::getBufferedSize(IDISA_Builder * const iBuilder, Value * self) const {
     192Value * SourceBuffer::getBufferedSize(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    197193    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    198194    return iBuilder->CreateLoad(ptr);
    199195}
    200196
    201 void SourceBuffer::setBufferedSize(IDISA_Builder * const iBuilder, Value * self, llvm::Value * size) const {
     197void SourceBuffer::setBufferedSize(IDISA::IDISA_Builder * const iBuilder, Value * self, llvm::Value * size) const {
    202198    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    203199    iBuilder->CreateStore(size, ptr);
    204200}
    205201
    206 void SourceBuffer::setBaseAddress(IDISA_Builder * const iBuilder, Value * self, Value * addr) const {
     202void SourceBuffer::setBaseAddress(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * addr) const {
    207203    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    208204    iBuilder->CreateStore(iBuilder->CreatePointerCast(addr, ptr->getType()->getPointerElementType()), ptr);
    209205}
    210206
    211 Value * SourceBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * const self) const {
     207Value * SourceBuffer::getBaseAddress(IDISA::IDISA_Builder * const iBuilder, Value * const self) const {
    212208    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    213209    Value * const addr = iBuilder->CreateLoad(ptr);
     
    215211}
    216212
    217 Value * SourceBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     213Value * SourceBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
    218214    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), blockIndex);
    219215}
    220216
    221 Value * SourceBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value *) const {
     217Value * SourceBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value *) const {
    222218    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    223219}
    224220
    225221// External File Buffer
    226 void ExternalBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
     222void ExternalBuffer::allocateBuffer(const std::unique_ptr<IDISA_Builder> &) {
    227223    report_fatal_error("External buffers cannot be allocated.");
    228224}
    229225
    230 Value * ExternalBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     226Value * ExternalBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
    231227    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), blockIndex);
    232228}
    233229
    234 Value * ExternalBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value *, Value *) const {
     230Value * ExternalBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value *, Value *) const {
    235231    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    236232}
    237233
    238234// Circular Buffer
    239 Value * CircularBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * const self, Value * const blockIndex) const {
     235Value * CircularBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * const self, Value * const blockIndex) const {
    240236    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    241237}
    242238
    243239// CircularCopybackBuffer Buffer
    244 void CircularCopybackBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
     240void CircularCopybackBuffer::allocateBuffer(const std::unique_ptr<IDISA_Builder> & iBuilder) {
    245241    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
    246242}
    247243
    248 void CircularCopybackBuffer::createCopyBack(IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
     244void CircularCopybackBuffer::createCopyBack(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
    249245    Value * overFlowAreaPtr = iBuilder->CreateGEP(self, iBuilder->getSize(mBufferBlocks));
    250246    createBlockAlignedCopy(iBuilder, self, overFlowAreaPtr, overFlowItems);
    251247}
    252248
    253 Value * CircularCopybackBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     249Value * CircularCopybackBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
    254250    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    255251}
    256252
    257 Value * CircularCopybackBuffer::getLinearlyWritableItems(IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
     253Value * CircularCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
    258254    return iBuilder->CreateAdd(getLinearlyAccessibleItems(iBuilder, self, fromPosition), iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
    259255}
    260256
    261 Value * CircularCopybackBuffer::getLinearlyWritableBlocks(IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
     257Value * CircularCopybackBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
    262258    return iBuilder->CreateAdd(getLinearlyAccessibleBlocks(iBuilder, self, fromBlock), iBuilder->getSize(mOverflowBlocks));
    263259}
     
    265261// SwizzledCopybackBuffer Buffer
    266262
    267 void SwizzledCopybackBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
     263void SwizzledCopybackBuffer::allocateBuffer(const std::unique_ptr<IDISA_Builder> & iBuilder) {
    268264    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
    269265}
    270266
    271 void SwizzledCopybackBuffer::createBlockAlignedCopy(IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
     267void SwizzledCopybackBuffer::createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
    272268    Type * size_ty = iBuilder->getSizeTy();
    273269    Type * i8ptr = iBuilder->getInt8PtrTy();
     
    303299}
    304300
    305 void SwizzledCopybackBuffer::createCopyBack(IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
     301void SwizzledCopybackBuffer::createCopyBack(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
    306302    Value * overFlowAreaPtr = iBuilder->CreateGEP(self, iBuilder->getSize(mBufferBlocks));
    307303    createBlockAlignedCopy(iBuilder, self, overFlowAreaPtr, overFlowItems);
    308304}
    309305
    310 Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     306Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
    311307    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    312308}
    313309
    314 Value * SwizzledCopybackBuffer::getLinearlyWritableItems(IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
     310Value * SwizzledCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
    315311    return iBuilder->CreateAdd(getLinearlyAccessibleItems(iBuilder, self, fromPosition), iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
    316312}
    317313
    318 Value * SwizzledCopybackBuffer::getLinearlyWritableBlocks(IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
     314Value * SwizzledCopybackBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
    319315    return iBuilder->CreateAdd(getLinearlyAccessibleBlocks(iBuilder, self, fromBlock), iBuilder->getSize(mOverflowBlocks));
    320316}
     
    322318// Expandable Buffer
    323319
    324 void ExpandableBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
     320void ExpandableBuffer::allocateBuffer(const std::unique_ptr<IDISA_Builder> & iBuilder) {
    325321    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType());
    326322    Value * const capacityPtr = iBuilder->CreateGEP(mStreamSetBufferPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     
    335331}
    336332
    337 std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
     333std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    338334
    339335    // ENTRY
     
    440436}
    441437
    442 Value * ExpandableBuffer::getStreamBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
     438Value * ExpandableBuffer::getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    443439    Value * ptr, * offset;
    444440    std::tie(ptr, offset) = getInternalStreamBuffer(iBuilder, self, streamIndex, blockIndex, readOnly);
     
    446442}
    447443
    448 Value * ExpandableBuffer::getStreamPackPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
     444Value * ExpandableBuffer::getStreamPackPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
    449445    Value * ptr, * offset;
    450446    std::tie(ptr, offset) = getInternalStreamBuffer(iBuilder, self, streamIndex, blockIndex, readOnly);
     
    452448}
    453449
    454 Value * ExpandableBuffer::getStreamSetCount(IDISA_Builder * const iBuilder, Value * self) const {
     450Value * ExpandableBuffer::getStreamSetCount(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    455451    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    456452}
    457453
    458 Value * ExpandableBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * self) const {
     454Value * ExpandableBuffer::getBaseAddress(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    459455    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
    460456}
    461457
    462 void ExpandableBuffer::releaseBuffer(IDISA_Builder * const iBuilder, Value * self) const {
     458void ExpandableBuffer::releaseBuffer(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    463459    iBuilder->CreateAlignedFree(getBaseAddress(iBuilder, self));
    464460}
    465461
    466 Value * ExpandableBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value *, Value *) const {
     462Value * ExpandableBuffer::getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value *, Value *) const {
    467463    report_fatal_error("Expandable buffers: getStreamSetBlockPtr is not supported.");
    468464}
    469465
    470 Value * ExpandableBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value *) const {
     466Value * ExpandableBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value *) const {
    471467    report_fatal_error("Expandable buffers: getLinearlyAccessibleItems is not supported.");
    472468}
    473469
    474470// Constructors
    475 SingleBlockBuffer::SingleBlockBuffer(IDISA::IDISA_Builder * b, Type * type)
     471SingleBlockBuffer::SingleBlockBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type)
    476472: StreamSetBuffer(BufferKind::BlockBuffer, type, resolveStreamSetType(b, type), 1, 0) {
    477473    mUniqueID = "S";
     
    479475}
    480476
    481 SourceBuffer::SourceBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
     477SourceBuffer::SourceBuffer(const std::unique_ptr<IDISA_Builder> & b, Type * type, unsigned AddressSpace)
    482478: StreamSetBuffer(BufferKind::SourceBuffer, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
    483479    mUniqueID = "M"; // + std::to_string(bufferBlocks);
     
    485481}
    486482
    487 ExternalBuffer::ExternalBuffer(IDISA::IDISA_Builder * b, Type * type, llvm::Value * addr, unsigned AddressSpace)
     483ExternalBuffer::ExternalBuffer(const std::unique_ptr<IDISA_Builder> & b, Type * type, llvm::Value * addr, unsigned AddressSpace)
    488484: StreamSetBuffer(BufferKind::ExternalBuffer, type, resolveStreamSetType(b, type), 0, AddressSpace) {
    489485    mUniqueID = "E";
     
    492488}
    493489
    494 CircularBuffer::CircularBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
     490CircularBuffer::CircularBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    495491: StreamSetBuffer(BufferKind::CircularBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace) {
    496492    mUniqueID = "C" + std::to_string(bufferBlocks);
     
    498494}
    499495
    500 CircularCopybackBuffer::CircularCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace)
     496CircularCopybackBuffer::CircularCopybackBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace)
    501497: StreamSetBuffer(BufferKind::CircularCopybackBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks) {
    502498    mUniqueID = "CC" + std::to_string(bufferBlocks);
     
    505501}
    506502
    507 ExpandableBuffer::ExpandableBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
     503ExpandableBuffer::ExpandableBuffer(const std::unique_ptr<IDISA_Builder> & b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    508504: StreamSetBuffer(BufferKind::ExpandableBuffer, type, resolveExpandableStreamSetType(b, type), bufferBlocks, AddressSpace)
    509505, mInitialCapacity(type->getArrayNumElements()) {
     
    512508}
    513509
    514 SwizzledCopybackBuffer::SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
     510SwizzledCopybackBuffer::SwizzledCopybackBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
    515511: StreamSetBuffer(BufferKind::SwizzledCopybackBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks), mFieldWidth(fieldwidth) {
    516512    mUniqueID = "SW" + std::to_string(fieldwidth) + ":" + std::to_string(bufferBlocks);
     
    537533
    538534// Helper routines
    539 ArrayType * resolveStreamSetType(IDISA_Builder * const b, Type * type) {
     535ArrayType * resolveStreamSetType(const std::unique_ptr<IDISA::IDISA_Builder> & b, Type * type) {
    540536    unsigned numElements = 1;
    541537    if (LLVM_LIKELY(type->isArrayTy())) {
     
    561557}
    562558
    563 StructType * resolveExpandableStreamSetType(IDISA_Builder * const b, Type * type) {
     559StructType * resolveExpandableStreamSetType(const std::unique_ptr<IDISA_Builder> & b, Type * type) {
    564560    if (LLVM_LIKELY(type->isArrayTy())) {
    565561        type = type->getArrayElementType();
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5434 r5435  
    1010namespace IDISA { class IDISA_Builder; }
    1111namespace llvm { class Value; }
     12namespace kernel { class Kernel; }
    1213namespace kernel { class KernelBuilder; }
    1314
     
    1516   
    1617class StreamSetBuffer {
     18    friend class kernel::Kernel;
    1719    friend class kernel::KernelBuilder;
    18 
    1920public:
    2021
     
    5758    }
    5859
    59     virtual void allocateBuffer(IDISA::IDISA_Builder * const iBuilder);
     60    virtual void allocateBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder);
    6061
    6162    virtual void releaseBuffer(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
     
    8081    virtual llvm::Value * getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromBlock) const;
    8182   
     83    virtual void createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, llvm::Value * targetBlockPtr, llvm::Value * sourceBlockPtr, llvm::Value * itemsToCopy) const;
     84
    8285    virtual llvm::Value * getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const;
    8386   
    8487    virtual llvm::Value * getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromBlock) const;
    8588   
    86     virtual void createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, llvm::Value * targetBlockPtr, llvm::Value * sourceBlockPtr, llvm::Value * itemsToCopy) const;
    87 
    88     virtual void reserveBytes(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * requested) const;
    89 
    9089    virtual ~StreamSetBuffer() = 0;
    9190
    92     kernel::KernelBuilder * getProducer() const {
     91    kernel::Kernel * getProducer() const {
    9392        return mProducer;
    9493    }
    9594
    96     const std::vector<kernel::KernelBuilder *> & getConsumers() const {
     95    const std::vector<kernel::Kernel *> & getConsumers() const {
    9796        return mConsumers;
    9897    }
     
    111110    virtual llvm::Value * getBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
    112111
    113     void setProducer(kernel::KernelBuilder * const producer) {
     112    void setProducer(kernel::Kernel * const producer) {
    114113        assert (producer);
    115114        mProducer = producer;
    116115    }
    117116
    118     void addConsumer(kernel::KernelBuilder * const consumer) {
     117    void addConsumer(kernel::Kernel * const consumer) {
    119118        assert (consumer);
    120119        mConsumers.push_back(consumer);
     
    129128    llvm::Type * const                      mBaseType;
    130129    std::string                             mUniqueID;
    131     kernel::KernelBuilder *                 mProducer;
    132     std::vector<kernel::KernelBuilder *>    mConsumers;
     130    kernel::Kernel *                 mProducer;
     131    std::vector<kernel::Kernel *>    mConsumers;
    133132};   
    134133
     
    139138    }   
    140139
    141     SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
     140    SingleBlockBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type);
    142141
    143142protected:
     
    152151    }
    153152
    154     SourceBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
     153    SourceBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, unsigned AddressSpace = 0);
    155154
    156155    void setBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * addr) const override;
     
    176175    }
    177176
    178     ExternalBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, llvm::Value * addr, unsigned AddressSpace = 0);
     177    ExternalBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, llvm::Value * addr, unsigned AddressSpace = 0);
    179178
    180179    // Can't allocate - raise an error. */
    181     void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     180    void allocateBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder) override;
    182181
    183182    llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * fromPosition, llvm::Value *) const override;
     
    193192    }
    194193   
    195     CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     194    CircularBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    196195
    197196protected:
     
    211210    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularCopybackBuffer;}
    212211   
    213     CircularCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace = 0);
    214 
    215     void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     212    CircularCopybackBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace = 0);
     213
     214    void allocateBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder) override;
    216215   
    217216    // Generate copyback code for the given number of overflowItems.
     
    233232    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::SwizzledCopybackBuffer;}
    234233   
    235     SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth = 64, unsigned AddressSpace = 0);
    236    
    237     void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     234    SwizzledCopybackBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth = 64, unsigned AddressSpace = 0);
     235   
     236    void allocateBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder) override;
    238237   
    239238    void createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, llvm::Value * targetBlockPtr, llvm::Value * sourceBlockPtr, llvm::Value * itemsToCopy) const override;
     
    244243    llvm::Value * getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const override;
    245244   
    246     llvm::Value * getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromBlock) const override;
     245    llvm::Value * getLinearlyWritableBlocks(IDISA::IDISA_Builder * constiBuilder, llvm::Value * self, llvm::Value * fromBlock) const override;
    247246   
    248247protected:
     
    261260    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExpandableBuffer;}
    262261
    263     ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     262    ExpandableBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    264263
    265264    llvm::Value * getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
     
    269268    llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const override;
    270269
    271     void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     270    void allocateBuffer(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder) override;
    272271
    273272    llvm::Value * getStreamSetCount(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
  • icGREP/icgrep-devel/icgrep/kernels/swizzle.cpp

    r5335 r5435  
    1212namespace kernel {
    1313
    14 SwizzleGenerator::SwizzleGenerator(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned outputSets, unsigned inputSets, unsigned fieldWidth)
    15     : BlockOrientedKernel(iBuilder, "swizzle" + std::to_string(fieldWidth) + ":" + std::to_string(bitStreamCount), {}, {}, {}, {}, {})
    16     , mBitStreamCount(bitStreamCount)
    17     , mFieldWidth(fieldWidth)
    18     , mSwizzleFactor(iBuilder->getBitBlockWidth() / fieldWidth)
    19     , mInputSets(inputSets)
    20     , mOutputSets(outputSets) {
    21         assert((fieldWidth > 0) && ((fieldWidth & (fieldWidth - 1)) == 0) && "fieldWidth must be a power of 2");
    22         assert(fieldWidth < iBuilder->getBitBlockWidth() && "fieldWidth must be less than the block width");
    23         assert(mSwizzleFactor > 1 && "fieldWidth must be less than the block width");
    24         unsigned inputStreamsPerSet = (bitStreamCount + inputSets - 1)/inputSets;
    25         unsigned outputStreamsPerSet = (bitStreamCount + outputSets - 1)/outputSets;
    26         // Maybe the following is unnecessary.
    27         //assert(inputStreamsPerSet % swizzleFactor == 0 && "input sets must be an exact multiple of the swizzle factor");
    28         assert(outputStreamsPerSet % mSwizzleFactor == 0 && "output sets must be an exact multiple of the swizzle factor");
    29         for (unsigned i = 0; i < mInputSets; i++) {
    30             mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(inputStreamsPerSet, 1), "inputGroup" + std::to_string(i)});
    31         }
    32         for (unsigned i = 0; i < mOutputSets; i++) {
    33             mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(outputStreamsPerSet, 1), "outputGroup" + std::to_string(i)});
    34         }
     14SwizzleGenerator::SwizzleGenerator(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned bitStreamCount, unsigned outputSets, unsigned inputSets, unsigned fieldWidth)
     15: BlockOrientedKernel("swizzle" + std::to_string(fieldWidth) + ":" + std::to_string(bitStreamCount), {}, {}, {}, {}, {})
     16, mBitStreamCount(bitStreamCount)
     17, mFieldWidth(fieldWidth)
     18, mSwizzleFactor(iBuilder->getBitBlockWidth() / fieldWidth)
     19, mInputSets(inputSets)
     20, mOutputSets(outputSets) {
     21    assert((fieldWidth > 0) && ((fieldWidth & (fieldWidth - 1)) == 0) && "fieldWidth must be a power of 2");
     22    assert(fieldWidth < iBuilder->getBitBlockWidth() && "fieldWidth must be less than the block width");
     23    assert(mSwizzleFactor > 1 && "fieldWidth must be less than the block width");
     24    unsigned inputStreamsPerSet = (bitStreamCount + inputSets - 1)/inputSets;
     25    unsigned outputStreamsPerSet = (bitStreamCount + outputSets - 1)/outputSets;
     26    // Maybe the following is unnecessary.
     27    //assert(inputStreamsPerSet % swizzleFactor == 0 && "input sets must be an exact multiple of the swizzle factor");
     28    assert(outputStreamsPerSet % mSwizzleFactor == 0 && "output sets must be an exact multiple of the swizzle factor");
     29    for (unsigned i = 0; i < mInputSets; i++) {
     30        mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(inputStreamsPerSet, 1), "inputGroup" + std::to_string(i)});
    3531    }
     32    for (unsigned i = 0; i < mOutputSets; i++) {
     33        mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(outputStreamsPerSet, 1), "outputGroup" + std::to_string(i)});
     34    }
     35}
    3636
    3737void SwizzleGenerator::generateDoBlockMethod() {
  • icGREP/icgrep-devel/icgrep/kernels/swizzle.h

    r5349 r5435  
    5252public:
    5353   
    54     SwizzleGenerator(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned outputSets = 1, unsigned inputSets = 1, unsigned fieldWidth = 64);
     54    SwizzleGenerator(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned bitStreamCount, unsigned outputSets = 1, unsigned inputSets = 1, unsigned fieldWidth = 64);
    5555   
    5656protected:
  • icGREP/icgrep-devel/icgrep/lz4d.cpp

    r5429 r5435  
    4646
    4747void generatePipeline(ParabixDriver & pxDriver) {
    48     IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     48    auto & iBuilder = pxDriver.getBuilder();
    4949    Module * M = iBuilder->getModule();
    5050
     
    8080
    8181   
    82     kernel::KernelBuilder * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(iBuilder, iBuilder->getInt8PtrTy(), segmentSize));
     82    kernel::Kernel * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(iBuilder, iBuilder->getInt8PtrTy(), segmentSize));
    8383    sourceK->setInitialArguments({inputStream, fileSize});
    8484    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    8585
    8686    // Input stream is not aligned due to the offset.
    87     KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder, /*aligned = */ false));
     87    Kernel * s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder, /*aligned = */ false));
    8888    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    8989   
    90     KernelBuilder * extenderK = pxDriver.addKernelInstance(make_unique<ParabixCharacterClassKernelBuilder>(iBuilder, "extenders", std::vector<re::CC *>{re::makeCC(0xFF)}, 8));
     90    Kernel * extenderK = pxDriver.addKernelInstance(make_unique<ParabixCharacterClassKernelBuilder>(iBuilder, "extenders", std::vector<re::CC *>{re::makeCC(0xFF)}, 8));
    9191    pxDriver.makeKernelCall(extenderK, {BasisBits}, {Extenders});
    9292
    93     KernelBuilder * lz4iK = pxDriver.addKernelInstance(make_unique<LZ4IndexDecoderKernel>(iBuilder));
     93    Kernel * lz4iK = pxDriver.addKernelInstance(make_unique<LZ4IndexDecoderKernel>(iBuilder));
    9494    lz4iK->setInitialArguments({iBuilder->CreateTrunc(hasBlockChecksum, iBuilder->getInt1Ty())});
    9595    pxDriver.makeKernelCall(lz4iK, {ByteStream, Extenders}, {LiteralIndexes, MatchIndexes});
    9696
    97     KernelBuilder * lz4bK = pxDriver.addKernelInstance(make_unique<LZ4ByteStreamDecoderKernel>(iBuilder, decompressBufBlocks * codegen::BlockSize));
     97    Kernel * lz4bK = pxDriver.addKernelInstance(make_unique<LZ4ByteStreamDecoderKernel>(iBuilder, decompressBufBlocks * codegen::BlockSize));
    9898    pxDriver.makeKernelCall(lz4bK, {LiteralIndexes, MatchIndexes, ByteStream}, {DecompressedByteStream});
    9999
    100     KernelBuilder * outK = pxDriver.addKernelInstance(make_unique<FileSink>(iBuilder, 8));
     100    Kernel * outK = pxDriver.addKernelInstance(make_unique<FileSink>(iBuilder, 8));
    101101    outK->setInitialArguments({iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(outputFile), iBuilder->getInt8PtrTy())});
    102102    pxDriver.makeKernelCall(outK, {DecompressedByteStream}, {});
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5431 r5435  
    6262 * @brief initializeCarryData
    6363 ** ------------------------------------------------------------------------------------------------------------- */
    64 void CarryManager::initializeCarryData() {
     64void CarryManager::initializeCarryData(IDISA::IDISA_Builder * const builder, PabloKernel * const kernel) {
    6565
    6666    // Each scope constructs its own CarryData struct, which will be added to the final "carries" struct
     
    8080    // set of carries for that iteration.
    8181
    82     iBuilder = mKernel->getBuilder();
    83     assert ("CarryManager does not have a IDISA builder" && iBuilder);
    84 
    85     PabloBlock * const entryBlock = mKernel->getEntryBlock();
    86 
    87     mCurrentScope = entryBlock;
     82    assert (mKernel == nullptr);
     83    mCurrentScope = kernel->getEntryBlock();
     84    mKernel = kernel;
    8885
    8986    mCarryScopes = 0;
    9087
    91     mCarryMetadata.resize(getScopeCount(entryBlock));
    92 
    93     Type * const carryStateTy = analyse(entryBlock);
    94 
    95     mKernel->addScalar(carryStateTy, "carries");
     88    mCarryMetadata.resize(getScopeCount(mCurrentScope));
     89
     90    Type * const carryStateTy = analyse(builder, mCurrentScope);
     91
     92    kernel->addScalar(carryStateTy, "carries");
    9693
    9794    if (mHasLoop) {
    98         mKernel->addScalar(iBuilder->getInt32Ty(), "selector");
     95        kernel->addScalar(builder->getInt32Ty(), "selector");
    9996    }
    10097    if (mHasLongAdvance) {
    101         mKernel->addScalar(iBuilder->getSizeTy(), "CarryBlockIndex");
    102     }
     98        kernel->addScalar(builder->getSizeTy(), "CarryBlockIndex");
     99    }
     100
    103101}
    104102
     
    106104 * @brief initializeCodeGen
    107105 ** ------------------------------------------------------------------------------------------------------------- */
    108 void CarryManager::initializeCodeGen() {
     106void CarryManager::initializeCodeGen(IDISA::IDISA_Builder * const builder) {
    109107
    110108    assert(!mCarryMetadata.empty());
    111109    mCarryInfo = &mCarryMetadata[0];
    112110    assert (!mCarryInfo->hasSummary());
    113 
    114     iBuilder = mKernel->getBuilder();
    115     assert ("CarryManager does not have a IDISA builder" && iBuilder);
    116111
    117112    mCurrentFrame = mKernel->getScalarFieldPtr("carries");
     
    123118
    124119    assert (mCarrySummaryStack.empty());
    125     mCarrySummaryStack.push_back(Constant::getNullValue(getCarryPackType()));
     120
     121    Type * const carryTy = builder->getBitBlockType();
     122
     123    mCarrySummaryStack.push_back(Constant::getNullValue(carryTy));
    126124
    127125    if (mHasLoop) {       
    128126        mLoopSelector = mKernel->getScalarField("selector");
    129         mNextLoopSelector = iBuilder->CreateXor(mLoopSelector, ConstantInt::get(mLoopSelector->getType(), 1));
     127        mNextLoopSelector = builder->CreateXor(mLoopSelector, ConstantInt::get(mLoopSelector->getType(), 1));
    130128    }
    131129
     
    135133 * @brief finalizeCodeGen
    136134 ** ------------------------------------------------------------------------------------------------------------- */
    137 void CarryManager::finalizeCodeGen() {
     135void CarryManager::finalizeCodeGen(IDISA::IDISA_Builder * const builder) {
    138136    if (mHasLoop) {
    139137        mKernel->setScalarField("selector", mNextLoopSelector);
     
    141139    if (mHasLongAdvance) {
    142140        Value * idx = mKernel->getScalarField("CarryBlockIndex");
    143         idx = iBuilder->CreateAdd(idx, iBuilder->getSize(1));
     141        idx = builder->CreateAdd(idx, builder->getSize(1));
    144142        mKernel->setScalarField("CarryBlockIndex", idx);
    145143    }
     
    155153 * @brief enterLoopScope
    156154 ** ------------------------------------------------------------------------------------------------------------- */
    157 void CarryManager::enterLoopScope(const PabloBlock * const scope) {
     155void CarryManager::enterLoopScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope) {
    158156    assert (scope);
    159157    assert (mHasLoop);
    160158    ++mLoopDepth;
    161     enterScope(scope);
     159    enterScope(builder, scope);
    162160}
    163161
     
    165163 * @brief enterLoopBody
    166164 ** ------------------------------------------------------------------------------------------------------------- */
    167 void CarryManager::enterLoopBody(BasicBlock * const entryBlock) {
     165void CarryManager::enterLoopBody(IDISA::IDISA_Builder * const builder, BasicBlock * const entryBlock) {
    168166    if (mCarryInfo->hasSummary()) {
    169         PHINode * phiCarryOutSummary = iBuilder->CreatePHI(getCarryPackType(), 2, "summary");
     167        Type * const carryTy = builder->getBitBlockType();
     168        PHINode * phiCarryOutSummary = builder->CreatePHI(carryTy, 2, "summary");
    170169        assert (!mCarrySummaryStack.empty());
    171170        phiCarryOutSummary->addIncoming(mCarrySummaryStack.back(), entryBlock);
     
    181180        assert (mCarryInfo->hasSummary());
    182181
     182        Type * const carryTy = builder->getBitBlockType();
     183        PointerType * const carryPtrTy = carryTy->getPointerTo();
     184
    183185        // Check whether we need to resize the carry state
    184         PHINode * index = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
     186        PHINode * index = builder->CreatePHI(builder->getSizeTy(), 2);
    185187        mLoopIndicies.push_back(index);
    186         index->addIncoming(iBuilder->getSize(0), entryBlock);
    187 
    188         Value * capacityPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    189         Value * capacity = iBuilder->CreateLoad(capacityPtr, false, "capacity");
     188        index->addIncoming(builder->getSize(0), entryBlock);
     189
     190        Value * capacityPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(0)});
     191        Value * capacity = builder->CreateLoad(capacityPtr, false, "capacity");
    190192        Constant * const ONE = ConstantInt::get(capacity->getType(), 1);
    191         Value * arrayPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    192         Value * array = iBuilder->CreateLoad(arrayPtr, false, "array");
    193 
    194         BasicBlock * const entry = iBuilder->GetInsertBlock();
     193        Value * arrayPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(1)});
     194        Value * array = builder->CreateLoad(arrayPtr, false, "array");
     195
     196        BasicBlock * const entry = builder->GetInsertBlock();
    195197        BasicBlock * const resizeCarryState = mKernel->CreateBasicBlock("ResizeCarryState");
    196198        BasicBlock * const reallocExisting = mKernel->CreateBasicBlock("ReallocExisting");
     
    198200        BasicBlock * const resumeKernel = mKernel->CreateBasicBlock("ResumeKernel");
    199201
    200         iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(index, capacity), resumeKernel, resizeCarryState);
     202        builder->CreateLikelyCondBr(builder->CreateICmpULT(index, capacity), resumeKernel, resizeCarryState);
    201203
    202204        // RESIZE CARRY BLOCK
    203         iBuilder->SetInsertPoint(resizeCarryState);
    204         const auto BlockWidth = getCarryPackType()->getPrimitiveSizeInBits() / 8;
     205        builder->SetInsertPoint(resizeCarryState);
     206        const auto BlockWidth = carryTy->getPrimitiveSizeInBits() / 8;
    205207        const auto Log2BlockWidth = floor_log2(BlockWidth);
    206         Constant * const carryStateWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(array->getType()->getPointerElementType()), iBuilder->getSizeTy(), false);
    207         Value * summaryPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
    208 
    209         Value * const hasCarryState = iBuilder->CreateICmpNE(array, ConstantPointerNull::get(cast<PointerType>(array->getType())));
    210 
    211         iBuilder->CreateLikelyCondBr(hasCarryState, reallocExisting, createNew);
     208        Constant * const carryStateWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(array->getType()->getPointerElementType()), builder->getSizeTy(), false);
     209        Value * summaryPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(2)});
     210
     211        Value * const hasCarryState = builder->CreateICmpNE(array, ConstantPointerNull::get(cast<PointerType>(array->getType())));
     212
     213        builder->CreateLikelyCondBr(hasCarryState, reallocExisting, createNew);
    212214
    213215        // REALLOCATE EXISTING
    214         iBuilder->SetInsertPoint(reallocExisting);
    215 
    216         Value * const capacitySize = iBuilder->CreateMul(capacity, carryStateWidth);
    217         Value * const newCapacitySize = iBuilder->CreateShl(capacitySize, 1); // x 2
    218 
    219 
    220         Value * newArray = iBuilder->CreateAlignedMalloc(newCapacitySize, iBuilder->getCacheAlignment());
    221         iBuilder->CreateMemCpy(newArray, array, capacitySize, BlockWidth);
    222         iBuilder->CreateMemZero(iBuilder->CreateGEP(newArray, capacitySize), capacitySize, BlockWidth);
    223         iBuilder->CreateAlignedFree(array);
    224         newArray = iBuilder->CreatePointerCast(newArray, array->getType());
    225         iBuilder->CreateStore(newArray, arrayPtr);
    226 
    227         Value * const log2capacity = iBuilder->CreateAdd(iBuilder->CreateCeilLog2(capacity), ONE);
    228         Value * const summarySize = iBuilder->CreateShl(log2capacity, Log2BlockWidth + 1); // x 2(BlockWidth)
    229         Value * const newLog2Capacity = iBuilder->CreateAdd(log2capacity, ONE);
    230         Value * const newSummarySize = iBuilder->CreateShl(newLog2Capacity, Log2BlockWidth + 1); // x 2(BlockWidth)
    231 
    232         Value * const summary = iBuilder->CreateLoad(summaryPtr, false);
    233         Value * newSummary = iBuilder->CreateAlignedMalloc(newSummarySize, BlockWidth);
    234         iBuilder->CreateMemCpy(newSummary, summary, summarySize, BlockWidth);
    235         iBuilder->CreateMemZero(iBuilder->CreateGEP(newSummary, summarySize), iBuilder->getSize(2 * BlockWidth), BlockWidth);
    236         iBuilder->CreateAlignedFree(summary);
    237 
    238         Value * ptr1 = iBuilder->CreateGEP(newSummary, summarySize);
    239         ptr1 = iBuilder->CreatePointerCast(ptr1, getCarryPackType()->getPointerTo());
    240 
    241         Value * ptr2 = iBuilder->CreateGEP(newSummary, iBuilder->CreateAdd(summarySize, iBuilder->getSize(BlockWidth)));
    242         ptr2 = iBuilder->CreatePointerCast(ptr2, getCarryPackType()->getPointerTo());
    243 
    244         newSummary = iBuilder->CreatePointerCast(newSummary, getCarryPackType()->getPointerTo());
    245         iBuilder->CreateStore(newSummary, summaryPtr);
    246         Value * const newCapacity = iBuilder->CreateShl(ONE, log2capacity);
    247 
    248         iBuilder->CreateStore(newCapacity, capacityPtr);
    249 
    250         iBuilder->CreateBr(resumeKernel);
     216        builder->SetInsertPoint(reallocExisting);
     217
     218        Value * const capacitySize = builder->CreateMul(capacity, carryStateWidth);
     219        Value * const newCapacitySize = builder->CreateShl(capacitySize, 1); // x 2
     220
     221
     222        Value * newArray = builder->CreateAlignedMalloc(newCapacitySize, builder->getCacheAlignment());
     223        builder->CreateMemCpy(newArray, array, capacitySize, BlockWidth);
     224        builder->CreateMemZero(builder->CreateGEP(newArray, capacitySize), capacitySize, BlockWidth);
     225        builder->CreateAlignedFree(array);
     226        newArray = builder->CreatePointerCast(newArray, array->getType());
     227        builder->CreateStore(newArray, arrayPtr);
     228
     229        Value * const log2capacity = builder->CreateAdd(builder->CreateCeilLog2(capacity), ONE);
     230        Value * const summarySize = builder->CreateShl(log2capacity, Log2BlockWidth + 1); // x 2(BlockWidth)
     231        Value * const newLog2Capacity = builder->CreateAdd(log2capacity, ONE);
     232        Value * const newSummarySize = builder->CreateShl(newLog2Capacity, Log2BlockWidth + 1); // x 2(BlockWidth)
     233
     234        Value * const summary = builder->CreateLoad(summaryPtr, false);
     235        Value * newSummary = builder->CreateAlignedMalloc(newSummarySize, BlockWidth);
     236        builder->CreateMemCpy(newSummary, summary, summarySize, BlockWidth);
     237        builder->CreateMemZero(builder->CreateGEP(newSummary, summarySize), builder->getSize(2 * BlockWidth), BlockWidth);
     238        builder->CreateAlignedFree(summary);
     239
     240        Value * ptr1 = builder->CreateGEP(newSummary, summarySize);
     241        ptr1 = builder->CreatePointerCast(ptr1, carryPtrTy);
     242
     243        Value * ptr2 = builder->CreateGEP(newSummary, builder->CreateAdd(summarySize, builder->getSize(BlockWidth)));
     244        ptr2 = builder->CreatePointerCast(ptr2, carryPtrTy);
     245
     246        newSummary = builder->CreatePointerCast(newSummary, carryPtrTy);
     247        builder->CreateStore(newSummary, summaryPtr);
     248        Value * const newCapacity = builder->CreateShl(ONE, log2capacity);
     249
     250        builder->CreateStore(newCapacity, capacityPtr);
     251
     252        builder->CreateBr(resumeKernel);
    251253
    252254        // CREATE NEW
    253         iBuilder->SetInsertPoint(createNew);
    254 
    255         Constant * const initialLog2Capacity = iBuilder->getInt64(4);
     255        builder->SetInsertPoint(createNew);
     256
     257        Constant * const initialLog2Capacity = builder->getInt64(4);
    256258        Constant * const initialCapacity = ConstantExpr::getShl(ONE, initialLog2Capacity);
    257259        Constant * const initialCapacitySize = ConstantExpr::getMul(initialCapacity, carryStateWidth);
    258260
    259         Value * initialArray = iBuilder->CreateAlignedMalloc(initialCapacitySize, iBuilder->getCacheAlignment());
    260         iBuilder->CreateMemZero(initialArray, initialCapacitySize, BlockWidth);
    261         initialArray = iBuilder->CreatePointerCast(initialArray, array->getType());
    262         iBuilder->CreateStore(initialArray, arrayPtr);
    263 
    264         Constant * initialSummarySize = ConstantExpr::getShl(ConstantExpr::getAdd(initialLog2Capacity, iBuilder->getInt64(1)), iBuilder->getInt64(Log2BlockWidth + 1));
    265         Value * initialSummary = iBuilder->CreateAlignedMalloc(initialSummarySize, BlockWidth);
    266         iBuilder->CreateMemZero(initialSummary, initialSummarySize, BlockWidth);
    267         initialSummary = iBuilder->CreatePointerCast(initialSummary, getCarryPackType()->getPointerTo());
    268         iBuilder->CreateStore(initialSummary, summaryPtr);
    269 
    270         iBuilder->CreateStore(initialCapacity, capacityPtr);
    271 
    272         iBuilder->CreateBr(resumeKernel);
     261        Value * initialArray = builder->CreateAlignedMalloc(initialCapacitySize, builder->getCacheAlignment());
     262        builder->CreateMemZero(initialArray, initialCapacitySize, BlockWidth);
     263        initialArray = builder->CreatePointerCast(initialArray, array->getType());
     264        builder->CreateStore(initialArray, arrayPtr);
     265
     266        Constant * initialSummarySize = ConstantExpr::getShl(ConstantExpr::getAdd(initialLog2Capacity, builder->getInt64(1)), builder->getInt64(Log2BlockWidth + 1));
     267        Value * initialSummary = builder->CreateAlignedMalloc(initialSummarySize, BlockWidth);
     268        builder->CreateMemZero(initialSummary, initialSummarySize, BlockWidth);
     269        initialSummary = builder->CreatePointerCast(initialSummary, carryPtrTy);
     270        builder->CreateStore(initialSummary, summaryPtr);
     271
     272        builder->CreateStore(initialCapacity, capacityPtr);
     273
     274        builder->CreateBr(resumeKernel);
    273275
    274276        // RESUME KERNEL
    275         iBuilder->SetInsertPoint(resumeKernel);
     277        builder->SetInsertPoint(resumeKernel);
    276278        // Load the appropriate carry stat block
    277         PHINode * phiArrayPtr = iBuilder->CreatePHI(array->getType(), 3);
     279        PHINode * phiArrayPtr = builder->CreatePHI(array->getType(), 3);
    278280        phiArrayPtr->addIncoming(array, entry);
    279281        phiArrayPtr->addIncoming(initialArray, createNew);
     
    282284        // NOTE: the 3 here is only to pass the assertion later. It refers to the number of elements in the carry data struct.
    283285        mCarryFrameStack.emplace_back(mCurrentFrame, 3);
    284         mCurrentFrame = iBuilder->CreateGEP(phiArrayPtr, index);
     286        mCurrentFrame = builder->CreateGEP(phiArrayPtr, index);
    285287    }
    286288}
     
    289291 * @brief leaveLoopBody
    290292 ** ------------------------------------------------------------------------------------------------------------- */
    291 void CarryManager::leaveLoopBody(BasicBlock * /* exitBlock */) {
     293void CarryManager::leaveLoopBody(IDISA::IDISA_Builder * const builder, BasicBlock * /* exitBlock */) {
     294
     295    Type * const carryTy = builder->getBitBlockType();
    292296
    293297    if (LLVM_UNLIKELY(mCarryInfo->nonCarryCollapsingMode())) {
     
    295299        assert (mCarryInfo->hasSummary());
    296300
    297         ConstantInt * const summaryIndex = iBuilder->getInt32(mCarryInfo->hasExplicitSummary() ? mCurrentFrameIndex : (mCurrentFrameIndex - 1));
    298 
    299         Value * const carryInAccumulator = readCarryInSummary(summaryIndex);
     301        ConstantInt * const summaryIndex = builder->getInt32(mCarryInfo->hasExplicitSummary() ? mCurrentFrameIndex : (mCurrentFrameIndex - 1));
     302
     303        Value * const carryInAccumulator = readCarryInSummary(builder, summaryIndex);
    300304        Value * const carryOutAccumulator = mCarrySummaryStack.back();
    301305
    302306        if (mCarryInfo->hasExplicitSummary()) {
    303             writeCarryOutSummary(carryOutAccumulator, summaryIndex);
     307            writeCarryOutSummary(builder, carryOutAccumulator, summaryIndex);
    304308        }
    305309
     
    317321        // Otherwise we may end up with an incorrect result or being trapped in an infinite loop.
    318322
    319         Value * capacityPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    320         Value * capacity = iBuilder->CreateLoad(capacityPtr, false);
    321         Value * summaryPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
    322         Value * summary = iBuilder->CreateLoad(summaryPtr, false);
     323        Value * capacityPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(0)});
     324        Value * capacity = builder->CreateLoad(capacityPtr, false);
     325        Value * summaryPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(2)});
     326        Value * summary = builder->CreateLoad(summaryPtr, false);
    323327
    324328        Constant * const ONE = ConstantInt::get(capacity->getType(), 1);
    325329
    326         Value * loopSelector = iBuilder->CreateZExt(mLoopSelector, capacity->getType());
    327 
    328         BasicBlock * entry = iBuilder->GetInsertBlock();
     330        Value * loopSelector = builder->CreateZExt(mLoopSelector, capacity->getType());
     331
     332        BasicBlock * entry = builder->GetInsertBlock();
    329333        BasicBlock * update = mKernel->CreateBasicBlock("UpdateNonCarryCollapsingSummary");
    330334        BasicBlock * resume = mKernel->CreateBasicBlock("ResumeAfterUpdatingNonCarryCollapsingSummary");
    331335
    332         iBuilder->CreateBr(update);
    333 
    334         iBuilder->SetInsertPoint(update);
    335         PHINode * i = iBuilder->CreatePHI(capacity->getType(), 2);
     336        builder->CreateBr(update);
     337
     338        builder->SetInsertPoint(update);
     339        PHINode * i = builder->CreatePHI(capacity->getType(), 2);
    336340        i->addIncoming(ConstantInt::getNullValue(capacity->getType()), entry);
    337         PHINode * const borrow = iBuilder->CreatePHI(carryInAccumulator->getType(), 2);
     341        PHINode * const borrow = builder->CreatePHI(carryInAccumulator->getType(), 2);
    338342        borrow->addIncoming(carryInAccumulator, entry);
    339         PHINode * const carry = iBuilder->CreatePHI(carryOutAccumulator->getType(), 2);
     343        PHINode * const carry = builder->CreatePHI(carryOutAccumulator->getType(), 2);
    340344        carry->addIncoming(carryOutAccumulator, entry);
    341345        // OR the updated carry in summary later for the summaryTest
    342         PHINode * const carryInSummary = iBuilder->CreatePHI(getCarryPackType(), 2);
    343         carryInSummary->addIncoming(Constant::getNullValue(getCarryPackType()), entry);
     346        PHINode * const carryInSummary = builder->CreatePHI(carryTy, 2);
     347        carryInSummary->addIncoming(Constant::getNullValue(carryTy), entry);
    344348
    345349        // half subtractor
    346         Value * const carryInOffset = iBuilder->CreateOr(iBuilder->CreateShl(i, 1), loopSelector);
    347         Value * const carryInPtr = iBuilder->CreateGEP(summary, carryInOffset);
    348         Value * const carryIn = iBuilder->CreateBlockAlignedLoad(carryInPtr);
    349         Value * const nextCarryIn = iBuilder->CreateXor(carryIn, borrow);
    350         Value * const nextSummary = iBuilder->CreateOr(carryInSummary, nextCarryIn);
    351         iBuilder->CreateBlockAlignedStore(nextCarryIn, carryInPtr);
     350        Value * const carryInOffset = builder->CreateOr(builder->CreateShl(i, 1), loopSelector);
     351        Value * const carryInPtr = builder->CreateGEP(summary, carryInOffset);
     352        Value * const carryIn = builder->CreateBlockAlignedLoad(carryInPtr);
     353        Value * const nextCarryIn = builder->CreateXor(carryIn, borrow);
     354        Value * const nextSummary = builder->CreateOr(carryInSummary, nextCarryIn);
     355        builder->CreateBlockAlignedStore(nextCarryIn, carryInPtr);
    352356        carryInSummary->addIncoming(nextSummary, update);
    353         Value * finalBorrow = iBuilder->CreateAnd(iBuilder->CreateNot(carryIn), borrow);
     357        Value * finalBorrow = builder->CreateAnd(builder->CreateNot(carryIn), borrow);
    354358        borrow->addIncoming(finalBorrow, update);
    355359
    356360        // half adder
    357         Value * const carryOutOffset = iBuilder->CreateXor(carryInOffset, ConstantInt::get(carryInOffset->getType(), 1));
    358         Value * const carryOutPtr = iBuilder->CreateGEP(summary, carryOutOffset);
    359         Value * const carryOut = iBuilder->CreateBlockAlignedLoad(carryOutPtr);
    360         Value * const nextCarryOut = iBuilder->CreateXor(carryOut, carry);
    361         iBuilder->CreateBlockAlignedStore(nextCarryOut, carryOutPtr);
    362         Value * finalCarry = iBuilder->CreateAnd(carryOut, carry);
     361        Value * const carryOutOffset = builder->CreateXor(carryInOffset, ConstantInt::get(carryInOffset->getType(), 1));
     362        Value * const carryOutPtr = builder->CreateGEP(summary, carryOutOffset);
     363        Value * const carryOut = builder->CreateBlockAlignedLoad(carryOutPtr);
     364        Value * const nextCarryOut = builder->CreateXor(carryOut, carry);
     365        builder->CreateBlockAlignedStore(nextCarryOut, carryOutPtr);
     366        Value * finalCarry = builder->CreateAnd(carryOut, carry);
    363367        carry->addIncoming(finalCarry, update);
    364368
    365369        // loop condition
    366         i->addIncoming(iBuilder->CreateAdd(i, ONE), update);
    367         iBuilder->CreateCondBr(iBuilder->CreateICmpNE(iBuilder->CreateShl(ONE, i), capacity), update, resume);
    368 
    369         iBuilder->SetInsertPoint(resume);
    370 
    371         IntegerType * ty = IntegerType::get(iBuilder->getContext(), getCarryPackType()->getPrimitiveSizeInBits());
    372         iBuilder->CreateAssert(iBuilder->CreateICmpEQ(iBuilder->CreateBitCast(finalBorrow, ty), ConstantInt::getNullValue(ty)), "finalBorrow != 0");
    373         iBuilder->CreateAssert(iBuilder->CreateICmpEQ(iBuilder->CreateBitCast(finalCarry, ty), ConstantInt::getNullValue(ty)), "finalCarry != 0");
     370        i->addIncoming(builder->CreateAdd(i, ONE), update);
     371        builder->CreateCondBr(builder->CreateICmpNE(builder->CreateShl(ONE, i), capacity), update, resume);
     372
     373        builder->SetInsertPoint(resume);
     374
     375        IntegerType * ty = IntegerType::get(builder->getContext(), carryTy->getPrimitiveSizeInBits());
     376        builder->CreateAssert(builder->CreateICmpEQ(builder->CreateBitCast(finalBorrow, ty), ConstantInt::getNullValue(ty)), "finalBorrow != 0");
     377        builder->CreateAssert(builder->CreateICmpEQ(builder->CreateBitCast(finalCarry, ty), ConstantInt::getNullValue(ty)), "finalCarry != 0");
    374378
    375379        assert (!mLoopIndicies.empty());
    376380        PHINode * index = mLoopIndicies.back();
    377         index->addIncoming(iBuilder->CreateAdd(index, iBuilder->getSize(1)), resume);
     381        index->addIncoming(builder->CreateAdd(index, builder->getSize(1)), resume);
    378382        mLoopIndicies.pop_back();
    379383
     
    385389        mCarrySummaryStack.pop_back();
    386390        PHINode * phiCarryOut = cast<PHINode>(mCarrySummaryStack.back());
    387         phiCarryOut->addIncoming(carryOut, iBuilder->GetInsertBlock());
     391        phiCarryOut->addIncoming(carryOut, builder->GetInsertBlock());
    388392        // If we're returning to the base scope, reset our accumulated summary value.
    389393        if (n == 2) {
    390             carryOut = Constant::getNullValue(getCarryPackType());
     394            carryOut = Constant::getNullValue(carryTy);
    391395        }
    392396        mCarrySummaryStack.back() = carryOut;
     
    397401 * @brief leaveLoopScope
    398402 ** ------------------------------------------------------------------------------------------------------------- */
    399 void CarryManager::leaveLoopScope(BasicBlock * const /* entryBlock */, BasicBlock * const /* exitBlock */) {
     403void CarryManager::leaveLoopScope(IDISA::IDISA_Builder * const builder, BasicBlock * const /* entryBlock */, BasicBlock * const /* exitBlock */) {
    400404    assert (mLoopDepth > 0);
    401405    --mLoopDepth;
    402     leaveScope();
     406    leaveScope(builder);
    403407}
    404408
     
    406410 * @brief enterIfScope
    407411 ** ------------------------------------------------------------------------------------------------------------- */
    408 void CarryManager::enterIfScope(const PabloBlock * const scope) {
     412void CarryManager::enterIfScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope) {
    409413    ++mIfDepth;
    410     enterScope(scope);
     414    enterScope(builder, scope);
    411415    // We zero-initialized the nested summary value and later OR in the current summary into the escaping summary
    412416    // so that upon processing the subsequent block iteration, we branch into this If scope iff a carry out was
     
    414418    if (LLVM_LIKELY(mCarryInfo->hasSummary())) {
    415419        assert (mCurrentFrameIndex == 0);
    416         mNextSummaryTest = readCarryInSummary(iBuilder->getInt32(0));
     420        mNextSummaryTest = readCarryInSummary(builder, builder->getInt32(0));
    417421        if (mCarryInfo->hasExplicitSummary()) {
    418422            mCurrentFrameIndex = 1;
    419423        }
    420424    }
    421     mCarrySummaryStack.push_back(Constant::getNullValue(getCarryPackType()));
     425    Type * const carryTy = builder->getBitBlockType();
     426    mCarrySummaryStack.push_back(Constant::getNullValue(carryTy));
    422427}
    423428
     
    425430 * @brief generateSummaryTest
    426431 ** ------------------------------------------------------------------------------------------------------------- */
    427 Value * CarryManager::generateSummaryTest(Value * condition) {
     432Value * CarryManager::generateSummaryTest(IDISA::IDISA_Builder * const builder, Value * condition) {
    428433    if (LLVM_LIKELY(mCarryInfo->hasSummary())) {
    429434        assert ("summary test was not generated" && mNextSummaryTest);
    430         condition = iBuilder->simd_or(condition, mNextSummaryTest);
     435        condition = builder->simd_or(condition, mNextSummaryTest);
    431436        mNextSummaryTest = nullptr;
    432437    }
     
    438443 * @brief enterIfBody
    439444 ** ------------------------------------------------------------------------------------------------------------- */
    440 void CarryManager::enterIfBody(BasicBlock * const entryBlock) {
     445void CarryManager::enterIfBody(IDISA::IDISA_Builder * const /* builder */, BasicBlock * const entryBlock) {
    441446    assert (entryBlock);
    442447}
     
    445450 * @brief leaveIfBody
    446451 ** ------------------------------------------------------------------------------------------------------------- */
    447 void CarryManager::leaveIfBody(BasicBlock * const exitBlock) {
     452void CarryManager::leaveIfBody(IDISA::IDISA_Builder * const builder, BasicBlock * const exitBlock) {
    448453    assert (exitBlock);
    449454    const auto n = mCarrySummaryStack.size();
    450455    if (LLVM_LIKELY(mCarryInfo->hasExplicitSummary())) {
    451         writeCarryOutSummary(mCarrySummaryStack[n - 1], iBuilder->getInt32(0));
     456        writeCarryOutSummary(builder, mCarrySummaryStack[n - 1], builder->getInt32(0));
    452457    }
    453458    if (n > 2) {
    454         mCarrySummaryStack[n - 1] = iBuilder->CreateOr(mCarrySummaryStack[n - 1], mCarrySummaryStack[n - 2], "summary");
     459        mCarrySummaryStack[n - 1] = builder->CreateOr(mCarrySummaryStack[n - 1], mCarrySummaryStack[n - 2], "summary");
    455460    }
    456461}
     
    459464 * @brief leaveIfScope
    460465 ** ------------------------------------------------------------------------------------------------------------- */
    461 void CarryManager::leaveIfScope(BasicBlock * const entryBlock, BasicBlock * const exitBlock) {
     466void CarryManager::leaveIfScope(IDISA::IDISA_Builder * const builder, BasicBlock * const entryBlock, BasicBlock * const exitBlock) {
    462467    assert (mIfDepth > 0);
    463468    if (LLVM_LIKELY(mCarryInfo->hasSummary())) {
     
    469474            Value * outer = mCarrySummaryStack[n - 2];
    470475            assert (nested->getType() == outer->getType());
    471             PHINode * const phi = iBuilder->CreatePHI(nested->getType(), 2, "summary");
     476            PHINode * const phi = builder->CreatePHI(nested->getType(), 2, "summary");
    472477            phi->addIncoming(outer, entryBlock);
    473478            phi->addIncoming(nested, exitBlock);
     
    476481    }
    477482    --mIfDepth;
    478     leaveScope();
     483    leaveScope(builder);
    479484    mCarrySummaryStack.pop_back();
    480485}
     
    483488 * @brief enterScope
    484489 ** ------------------------------------------------------------------------------------------------------------- */
    485 void CarryManager::enterScope(const PabloBlock * const scope) {
     490void CarryManager::enterScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope) {
    486491    assert (scope);
    487492    // Store the state of the current frame and update the scope state
     
    493498    // compilation or a memory corruption has occured.
    494499    assert (mCurrentFrameIndex < mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    495     mCurrentFrame = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(mCurrentFrameIndex)});
     500    mCurrentFrame = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(mCurrentFrameIndex)});
    496501    // Verify we're pointing to a carry frame struct
    497502    assert(mCurrentFrame->getType()->getPointerElementType()->isStructTy());
     
    502507 * @brief leaveScope
    503508 ** ------------------------------------------------------------------------------------------------------------- */
    504 void CarryManager::leaveScope() {
     509void CarryManager::leaveScope(IDISA::IDISA_Builder * const /* builder */) {
    505510
    506511    // Did we use all of the packs in this carry struct?
     
    524529 * @brief addCarryInCarryOut
    525530 ** ------------------------------------------------------------------------------------------------------------- */
    526 Value * CarryManager::addCarryInCarryOut(const Statement * const operation, Value * const e1, Value * const e2) {
     531Value * CarryManager::addCarryInCarryOut(IDISA::IDISA_Builder * const builder, const Statement * const operation, Value * const e1, Value * const e2) {
    527532    assert (operation && (isNonAdvanceCarryGeneratingStatement(operation)));
    528     Value * const carryIn = getNextCarryIn();
     533    Value * const carryIn = getNextCarryIn(builder);
    529534    Value * carryOut, * result;
    530     std::tie(carryOut, result) = iBuilder->bitblock_add_with_carry(e1, e2, carryIn);
    531     setNextCarryOut(carryOut);
    532     assert (result->getType() == getBitBlockType());
     535    std::tie(carryOut, result) = builder->bitblock_add_with_carry(e1, e2, carryIn);
     536    setNextCarryOut(builder, carryOut);
     537    assert (result->getType() == builder->getBitBlockType());
    533538    return result;
    534539}
     
    537542 * @brief advanceCarryInCarryOut
    538543 ** ------------------------------------------------------------------------------------------------------------- */
    539 Value * CarryManager::advanceCarryInCarryOut(const Advance * const advance, Value * const value) {
     544Value * CarryManager::advanceCarryInCarryOut(IDISA::IDISA_Builder * const builder, const Advance * const advance, Value * const value) {
    540545    const auto shiftAmount = advance->getAmount();
    541546    if (LLVM_LIKELY(shiftAmount < LONG_ADVANCE_BREAKPOINT)) {
    542         Value * const carryIn = getNextCarryIn();
     547        Value * const carryIn = getNextCarryIn(builder);
    543548        Value * carryOut, * result;
    544         std::tie(carryOut, result) = iBuilder->bitblock_advance(value, carryIn, shiftAmount);
    545         setNextCarryOut(carryOut);
    546         assert (result->getType() == getBitBlockType());
     549        std::tie(carryOut, result) = builder->bitblock_advance(value, carryIn, shiftAmount);
     550        setNextCarryOut(builder, carryOut);
     551        assert (result->getType() == builder->getBitBlockType());
    547552        return result;
    548553    } else {
    549         return longAdvanceCarryInCarryOut(value, shiftAmount);
     554        return longAdvanceCarryInCarryOut(builder, value, shiftAmount);
    550555    }
    551556}
     
    554559 * @brief longAdvanceCarryInCarryOut
    555560 ** ------------------------------------------------------------------------------------------------------------- */
    556 inline Value * CarryManager::longAdvanceCarryInCarryOut(Value * const value, const unsigned shiftAmount) {
     561inline Value * CarryManager::longAdvanceCarryInCarryOut(IDISA::IDISA_Builder * const builder, Value * const value, const unsigned shiftAmount) {
    557562
    558563    assert (mHasLongAdvance);
    559564    assert (shiftAmount >= LONG_ADVANCE_BREAKPOINT);
    560565
    561     Type * const streamTy = iBuilder->getIntNTy(getBitBlockWidth());
     566    Type * const streamTy = builder->getIntNTy(builder->getBitBlockWidth());
    562567
    563568    if (mIfDepth > 0) {
    564         if (shiftAmount > getBitBlockWidth()) {
     569        if (shiftAmount > builder->getBitBlockWidth()) {
    565570            const auto frameIndex = mCurrentFrameIndex++;
    566             Value * carry = iBuilder->CreateZExt(iBuilder->bitblock_any(value), streamTy);
    567             const unsigned summarySize = ceil_udiv(shiftAmount, getBitBlockWidth() * getBitBlockWidth());
     571            Value * carry = builder->CreateZExt(builder->bitblock_any(value), streamTy);
     572            const unsigned summarySize = ceil_udiv(shiftAmount, builder->getBitBlockWidth() * builder->getBitBlockWidth());
    568573            for (unsigned i = 0;;++i) {
    569                 Value * const ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), iBuilder->getInt32(i)});
    570                 Value * const prior = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(ptr), streamTy);
    571                 Value * const stream = iBuilder->CreateBitCast(iBuilder->CreateOr(iBuilder->CreateShl(prior, 1), carry), getBitBlockType());
     574                Value * const ptr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(frameIndex), builder->getInt32(i)});
     575                Value * const prior = builder->CreateBitCast(builder->CreateBlockAlignedLoad(ptr), streamTy);
     576                Value * const stream = builder->CreateBitCast(builder->CreateOr(builder->CreateShl(prior, 1), carry), builder->getBitBlockType());
    572577                if (LLVM_LIKELY(i == summarySize)) {
    573                     Value * const maskedStream = iBuilder->CreateAnd(stream, iBuilder->bitblock_mask_from(iBuilder->getInt32(summarySize % getBitBlockWidth())));
    574                     addToCarryOutSummary(maskedStream);
    575                     iBuilder->CreateBlockAlignedStore(maskedStream, ptr);
     578                    Value * const maskedStream = builder->CreateAnd(stream, builder->bitblock_mask_from(builder->getInt32(summarySize % builder->getBitBlockWidth())));
     579                    addToCarryOutSummary(builder, maskedStream);
     580                    builder->CreateBlockAlignedStore(maskedStream, ptr);
    576581                    break;
    577582                }
    578                 addToCarryOutSummary(stream);
    579                 iBuilder->CreateBlockAlignedStore(stream, ptr);
    580                 carry = iBuilder->CreateLShr(prior, getBitBlockWidth() - 1);
     583                addToCarryOutSummary(builder, stream);
     584                builder->CreateBlockAlignedStore(stream, ptr);
     585                carry = builder->CreateLShr(prior, builder->getBitBlockWidth() - 1);
    581586            }
    582587        } else if (LLVM_LIKELY(mCarryInfo->hasExplicitSummary())) {
    583             addToCarryOutSummary(value);
     588            addToCarryOutSummary(builder, value);
    584589        }
    585590    }
    586591    const auto frameIndex = mCurrentFrameIndex++;
    587592    // special case using a single buffer entry and the carry_out value.
    588     if (LLVM_LIKELY((shiftAmount < getBitBlockWidth()) && (mLoopDepth == 0))) {
    589         Value * const buffer = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), iBuilder->getInt32(0)});
    590         assert (buffer->getType()->getPointerElementType() == getBitBlockType());
    591         Value * carryIn = iBuilder->CreateBlockAlignedLoad(buffer);       
    592         iBuilder->CreateBlockAlignedStore(value, buffer);
     593    if (LLVM_LIKELY((shiftAmount < builder->getBitBlockWidth()) && (mLoopDepth == 0))) {
     594        Value * const buffer = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(frameIndex), builder->getInt32(0)});
     595        assert (buffer->getType()->getPointerElementType() == builder->getBitBlockType());
     596        Value * carryIn = builder->CreateBlockAlignedLoad(buffer);
     597        builder->CreateBlockAlignedStore(value, buffer);
    593598        /* Very special case - no combine */
    594         if (LLVM_UNLIKELY(shiftAmount == getBitBlockWidth())) {
    595             return iBuilder->CreateBitCast(carryIn, getBitBlockType());
    596         }
    597         Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), getBitBlockWidth() - shiftAmount);
    598         Value* block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(value, streamTy), shiftAmount);
    599         return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), getBitBlockType());
     599        if (LLVM_UNLIKELY(shiftAmount == builder->getBitBlockWidth())) {
     600            return builder->CreateBitCast(carryIn, builder->getBitBlockType());
     601        }
     602        Value* block0_shr = builder->CreateLShr(builder->CreateBitCast(carryIn, streamTy), builder->getBitBlockWidth() - shiftAmount);
     603        Value* block1_shl = builder->CreateShl(builder->CreateBitCast(value, streamTy), shiftAmount);
     604        return builder->CreateBitCast(builder->CreateOr(block1_shl, block0_shr), builder->getBitBlockType());
    600605    } else { //
    601         const unsigned blockShift = shiftAmount % getBitBlockWidth();
    602         const unsigned blocks = ceil_udiv(shiftAmount, getBitBlockWidth());
     606        const unsigned blockShift = shiftAmount % builder->getBitBlockWidth();
     607        const unsigned blocks = ceil_udiv(shiftAmount, builder->getBitBlockWidth());
    603608        // Create a mask to implement circular buffer indexing
    604         Value * indexMask = iBuilder->getSize(nearest_pow2(blocks + ((mLoopDepth != 0) ? 1 : 0)) - 1);
     609        Value * indexMask = builder->getSize(nearest_pow2(blocks + ((mLoopDepth != 0) ? 1 : 0)) - 1);
    605610        Value * blockIndex = mKernel->getScalarField("CarryBlockIndex");
    606         Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(blocks));
    607         Value * loadIndex0 = iBuilder->CreateAnd(carryIndex0, indexMask);
    608         Value * const carryInPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), loadIndex0});
    609         Value * carryIn = iBuilder->CreateBlockAlignedLoad(carryInPtr);
    610 
    611         Value * storeIndex = iBuilder->CreateAnd(blockIndex, indexMask);
    612         Value * const carryOutPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), storeIndex});
    613         assert (carryIn->getType() == getBitBlockType());
     611        Value * carryIndex0 = builder->CreateSub(blockIndex, builder->getSize(blocks));
     612        Value * loadIndex0 = builder->CreateAnd(carryIndex0, indexMask);
     613        Value * const carryInPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(frameIndex), loadIndex0});
     614        Value * carryIn = builder->CreateBlockAlignedLoad(carryInPtr);
     615
     616        Value * storeIndex = builder->CreateAnd(blockIndex, indexMask);
     617        Value * const carryOutPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(frameIndex), storeIndex});
     618        assert (carryIn->getType() == builder->getBitBlockType());
    614619
    615620        // If the long advance is an exact multiple of BitBlockWidth, we simply return the oldest
    616621        // block in the long advance carry data area.
    617622        if (LLVM_UNLIKELY(blockShift == 0)) {
    618             iBuilder->CreateBlockAlignedStore(value, carryOutPtr);
     623            builder->CreateBlockAlignedStore(value, carryOutPtr);
    619624            return carryIn;
    620625        } else { // Otherwise we need to combine data from the two oldest blocks.
    621             Value * carryIndex1 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(blocks - 1));
    622             Value * loadIndex1 = iBuilder->CreateAnd(carryIndex1, indexMask);
    623             Value * const carryInPtr2 = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), loadIndex1});
    624             Value * carry_block1 = iBuilder->CreateBlockAlignedLoad(carryInPtr2);
    625             Value * block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), getBitBlockWidth() - blockShift);
    626             Value * block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(carry_block1, streamTy), blockShift);
    627             iBuilder->CreateBlockAlignedStore(value, carryOutPtr);
    628             return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), getBitBlockType());
     626            Value * carryIndex1 = builder->CreateSub(blockIndex, builder->getSize(blocks - 1));
     627            Value * loadIndex1 = builder->CreateAnd(carryIndex1, indexMask);
     628            Value * const carryInPtr2 = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(frameIndex), loadIndex1});
     629            Value * carry_block1 = builder->CreateBlockAlignedLoad(carryInPtr2);
     630            Value * block0_shr = builder->CreateLShr(builder->CreateBitCast(carryIn, streamTy), builder->getBitBlockWidth() - blockShift);
     631            Value * block1_shl = builder->CreateShl(builder->CreateBitCast(carry_block1, streamTy), blockShift);
     632            builder->CreateBlockAlignedStore(value, carryOutPtr);
     633            return builder->CreateBitCast(builder->CreateOr(block1_shl, block0_shr), builder->getBitBlockType());
    629634        }
    630635    }
     
    634639 * @brief getNextCarryIn
    635640 ** ------------------------------------------------------------------------------------------------------------- */
    636 Value * CarryManager::getNextCarryIn() {
     641Value * CarryManager::getNextCarryIn(IDISA::IDISA_Builder * const builder) {
    637642    assert (mCurrentFrameIndex < mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    638643    if (mLoopDepth == 0) {
    639         mCarryPackPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(mCurrentFrameIndex)});
     644        mCarryPackPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(mCurrentFrameIndex)});
    640645    } else {
    641         mCarryPackPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(mCurrentFrameIndex), mLoopSelector});
    642     }
    643     assert (mCarryPackPtr->getType()->getPointerElementType() == getCarryPackType());
    644     Value * const carryIn = iBuilder->CreateBlockAlignedLoad(mCarryPackPtr);
     646        mCarryPackPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(mCurrentFrameIndex), mLoopSelector});
     647    }
     648    Type * const carryTy = builder->getBitBlockType();
     649    assert (mCarryPackPtr->getType()->getPointerElementType() == carryTy);
     650    Value * const carryIn = builder->CreateBlockAlignedLoad(mCarryPackPtr);
    645651    if (mLoopDepth > 0) {
    646         iBuilder->CreateBlockAlignedStore(Constant::getNullValue(getCarryPackType()), mCarryPackPtr);
     652        builder->CreateBlockAlignedStore(Constant::getNullValue(carryTy), mCarryPackPtr);
    647653    }
    648654    return carryIn;
     
    652658 * @brief setNextCarryOut
    653659 ** ------------------------------------------------------------------------------------------------------------- */
    654 void CarryManager::setNextCarryOut(Value * carryOut) {
     660void CarryManager::setNextCarryOut(IDISA::IDISA_Builder * const builder, Value * carryOut) {
     661    Type * const carryTy = builder->getBitBlockType();
    655662    assert (mCurrentFrameIndex < mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    656     carryOut = iBuilder->CreateBitCast(carryOut, getCarryPackType());
     663    carryOut = builder->CreateBitCast(carryOut, carryTy);
    657664    if (mCarryInfo->hasSummary()) {
    658         addToCarryOutSummary(carryOut);
     665        addToCarryOutSummary(builder, carryOut);
    659666    }
    660667    if (mLoopDepth != 0) {
    661         mCarryPackPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(mCurrentFrameIndex), mNextLoopSelector});
     668        mCarryPackPtr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), builder->getInt32(mCurrentFrameIndex), mNextLoopSelector});
    662669        if (LLVM_LIKELY(!mCarryInfo->nonCarryCollapsingMode())) {
    663             Value * accum = iBuilder->CreateBlockAlignedLoad(mCarryPackPtr);
    664             carryOut = iBuilder->CreateOr(carryOut, accum);
     670            Value * accum = builder->CreateBlockAlignedLoad(mCarryPackPtr);
     671            carryOut = builder->CreateOr(carryOut, accum);
    665672        }
    666673    }
    667674    ++mCurrentFrameIndex;
    668     assert (mCarryPackPtr->getType()->getPointerElementType() == getCarryPackType());
    669     iBuilder->CreateBlockAlignedStore(carryOut, mCarryPackPtr);
     675    assert (mCarryPackPtr->getType()->getPointerElementType() == carryTy);
     676    builder->CreateBlockAlignedStore(carryOut, mCarryPackPtr);
    670677}
    671678
     
    673680 * @brief readCarryInSummary
    674681 ** ------------------------------------------------------------------------------------------------------------- */
    675 Value * CarryManager::readCarryInSummary(ConstantInt * index) const {
     682Value * CarryManager::readCarryInSummary(IDISA::IDISA_Builder * const builder, ConstantInt * index) const {
    676683    assert (mCarryInfo->hasSummary());
    677 
    678684    unsigned count = 2;
    679685    if (LLVM_UNLIKELY(mCarryInfo->hasBorrowedSummary())) {
     
    687693    const unsigned length = (mLoopDepth == 0) ? count : (count + 1);
    688694    Value * indicies[length];
    689     std::fill(indicies, indicies + count - 1, iBuilder->getInt32(0));
     695    std::fill(indicies, indicies + count - 1, builder->getInt32(0));
    690696    indicies[count - 1] = index;
    691697    if (mLoopDepth != 0) {
     
    694700
    695701    ArrayRef<Value *> ar(indicies, length);
    696     Value * const ptr = iBuilder->CreateGEP(mCurrentFrame, ar);
    697     Value * const summary = iBuilder->CreateBlockAlignedLoad(ptr);
     702    Value * const ptr = builder->CreateGEP(mCurrentFrame, ar);
     703    Value * const summary = builder->CreateBlockAlignedLoad(ptr);
    698704    if (mLoopDepth != 0 && mCarryInfo->hasExplicitSummary()) {
    699         iBuilder->CreateBlockAlignedStore(Constant::getNullValue(getCarryPackType()), ptr);
     705        Type * const carryTy = builder->getBitBlockType();
     706        builder->CreateBlockAlignedStore(Constant::getNullValue(carryTy), ptr);
    700707    }
    701708    return summary;
     
    705712 * @brief writeCarryOutSummary
    706713 ** ------------------------------------------------------------------------------------------------------------- */
    707 inline void CarryManager::writeCarryOutSummary(Value * const summary, ConstantInt * index) const {
     714inline void CarryManager::writeCarryOutSummary(IDISA::IDISA_Builder * const builder, Value * const summary, ConstantInt * index) const {
    708715    Value * ptr = nullptr;
    709716    assert (mCarryInfo->hasExplicitSummary());
    710717    if (mLoopDepth > 0) {
    711         ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), index, mNextLoopSelector});
     718        ptr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), index, mNextLoopSelector});
    712719    } else {
    713         ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), index});
    714     }
    715     iBuilder->CreateBlockAlignedStore(summary, ptr);
     720        ptr = builder->CreateGEP(mCurrentFrame, {builder->getInt32(0), index});
     721    }
     722    builder->CreateBlockAlignedStore(summary, ptr);
    716723}
    717724
     
    719726 * @brief addToCarryOutSummary
    720727 ** ------------------------------------------------------------------------------------------------------------- */
    721 inline void CarryManager::addToCarryOutSummary(Value * const value) {
     728inline void CarryManager::addToCarryOutSummary(IDISA::IDISA_Builder * const builder, Value * const value) {
    722729    assert ("cannot add null summary value!" && value);   
    723730    assert ("summary stack is empty!" && !mCarrySummaryStack.empty());
    724731    assert (mCarryInfo->hasSummary());
    725     mCarrySummaryStack.back() = iBuilder->CreateOr(value, mCarrySummaryStack.back());
     732    mCarrySummaryStack.back() = builder->CreateOr(value, mCarrySummaryStack.back());
    726733}
    727734
     
    729736 * @brief enumerate
    730737 ** ------------------------------------------------------------------------------------------------------------- */
    731 unsigned CarryManager::getScopeCount(PabloBlock * const scope, unsigned index) {
    732     for (Statement * stmt : *scope) {
     738unsigned CarryManager::getScopeCount(const PabloBlock * const scope, unsigned index) {
     739    for (const Statement * stmt : *scope) {
    733740        if (LLVM_UNLIKELY(isa<Branch>(stmt))) {
    734741            index = getScopeCount(cast<Branch>(stmt)->getBody(), index);
     
    770777 * @brief analyse
    771778 ** ------------------------------------------------------------------------------------------------------------- */
    772 StructType * CarryManager::analyse(PabloBlock * const scope, const unsigned ifDepth, const unsigned loopDepth, const bool isNestedWithinNonCarryCollapsingLoop) {
    773 
    774     assert (scope != mKernel->getEntryBlock() || mCarryScopes == 0);
     779StructType * CarryManager::analyse(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope, const unsigned ifDepth, const unsigned loopDepth, const bool isNestedWithinNonCarryCollapsingLoop) {
     780    assert ("scope cannot be null!" && scope);
     781    assert (mCarryScopes == 0 ? (scope == mKernel->getEntryBlock()) : (scope != mKernel->getEntryBlock()));
    775782    assert (mCarryScopes < mCarryMetadata.size());
    776     assert (getCarryPackType());
     783    Type * const carryTy = builder->getBitBlockType();
     784    Type * const blockTy = builder->getBitBlockType();
    777785
    778786    const unsigned carryScopeIndex = mCarryScopes++;
    779787    const bool nonCarryCollapsingMode = hasIterationSpecificAssignment(scope);
    780     Type * const carryPackType = (loopDepth == 0) ? getCarryPackType() : ArrayType::get(getCarryPackType(), 2);
     788    Type * const carryPackType = (loopDepth == 0) ? carryTy : ArrayType::get(carryTy, 2);
    781789    std::vector<Type *> state;
    782790
    783     for (Statement * stmt : *scope) {
     791    for (const Statement * stmt : *scope) {
    784792        if (LLVM_UNLIKELY(isa<Advance>(stmt))) {
    785793            const auto amount = cast<Advance>(stmt)->getAmount();
    786794            Type * type = carryPackType;
    787795            if (LLVM_UNLIKELY(amount >= LONG_ADVANCE_BREAKPOINT)) {
    788                 const unsigned blocks = ceil_udiv(amount, getBitBlockWidth());
    789                 type = ArrayType::get(getBitBlockType(), nearest_pow2(blocks + ((loopDepth != 0) ? 1 : 0)));
    790                 if (LLVM_UNLIKELY(ifDepth > 0 && amount > getBitBlockWidth())) {
     796                const unsigned blocks = ceil_udiv(amount, builder->getBitBlockWidth());
     797                type = ArrayType::get(blockTy, nearest_pow2(blocks + ((loopDepth != 0) ? 1 : 0)));
     798                if (LLVM_UNLIKELY(ifDepth > 0 && amount > builder->getBitBlockWidth())) {
    791799                    // 1 bit will mark the presense of any bit in each block.
    792                     Type * carryType = ArrayType::get(getBitBlockType(), ceil_udiv(amount, getBitBlockWidth() * getBitBlockWidth()));
     800                    Type * carryType = ArrayType::get(blockTy, ceil_udiv(amount, std::pow(builder->getBitBlockWidth(), 2)));
    793801                    state.push_back(carryType);
    794802                }
     
    799807            state.push_back(carryPackType);
    800808        } else if (LLVM_UNLIKELY(isa<If>(stmt))) {
    801             state.push_back(analyse(cast<If>(stmt)->getBody(), ifDepth + 1, loopDepth, nonCarryCollapsingMode | isNestedWithinNonCarryCollapsingLoop));
     809            state.push_back(analyse(builder, cast<If>(stmt)->getBody(), ifDepth + 1, loopDepth, nonCarryCollapsingMode | isNestedWithinNonCarryCollapsingLoop));
    802810        } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
    803811            mHasLoop = true;
    804             state.push_back(analyse(cast<While>(stmt)->getBody(), ifDepth, loopDepth + 1, nonCarryCollapsingMode | isNestedWithinNonCarryCollapsingLoop));
     812            state.push_back(analyse(builder, cast<While>(stmt)->getBody(), ifDepth, loopDepth + 1, nonCarryCollapsingMode | isNestedWithinNonCarryCollapsingLoop));
    805813        }
    806814    }
     
    810818    CarryData::SummaryType summaryType = CarryData::NoSummary;
    811819    if (LLVM_UNLIKELY(state.empty())) {
    812         carryState = StructType::get(iBuilder->getContext());
     820        carryState = StructType::get(builder->getContext());
    813821    } else {
    814822        //if (ifDepth > 0 || (nonCarryCollapsingMode | isNestedWithinNonCarryCollapsingLoop)) {
     
    826834            }           
    827835        }
    828         carryState = StructType::get(iBuilder->getContext(), state);
     836        carryState = StructType::get(builder->getContext(), state);
    829837        // If we're in a loop and cannot use collapsing carry mode, convert the carry state struct into a capacity,
    830838        // carry state pointer, and summary pointer struct.
    831839        if (LLVM_UNLIKELY(nonCarryCollapsingMode)) {
    832             carryState = StructType::get(iBuilder->getSizeTy(), carryState->getPointerTo(), getCarryPackType()->getPointerTo(), nullptr);
     840            carryState = StructType::get(builder->getSizeTy(), carryState->getPointerTo(), carryTy->getPointerTo(), nullptr);
    833841        }
    834842        cd.setNonCollapsingCarryMode(nonCarryCollapsingMode);
     
    838846}
    839847
    840 inline unsigned CarryManager::getBitBlockWidth() const {
    841     return iBuilder->getBitBlockWidth();
    842 }
    843 
    844 inline llvm::Type * CarryManager::getCarryPackType() const {
    845     return getBitBlockType();
    846 }
    847 
    848 inline llvm::Type * CarryManager::getBitBlockType() const {
    849     return iBuilder->getBitBlockType();
    850 }
    851 
    852848/** ------------------------------------------------------------------------------------------------------------- *
    853849 * @brief constructor
    854850 ** ------------------------------------------------------------------------------------------------------------- */
    855 CarryManager::CarryManager(PabloKernel * const kernel) noexcept
    856 : mKernel(kernel)
    857 , iBuilder(nullptr)
     851CarryManager::CarryManager() noexcept
     852: mKernel(nullptr)
    858853, mCurrentFrame(nullptr)
    859854, mCurrentFrameIndex(0)
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5431 r5435  
    99
    1010#include <pablo/carry_data.h>
     11#include <memory>
    1112#include <vector>
    1213namespace IDISA { class IDISA_Builder; }
     
    4243public:
    4344 
    44     CarryManager(PabloKernel * const kernel) noexcept;
     45    CarryManager() noexcept;
    4546
    46     void initializeCarryData();
     47    void initializeCarryData(IDISA::IDISA_Builder * const builder, PabloKernel * const kernel);
    4748
    48     void initializeCodeGen();
     49    void initializeCodeGen(IDISA::IDISA_Builder * const builder);
    4950
    50     void finalizeCodeGen();
     51    void finalizeCodeGen(IDISA::IDISA_Builder * const builder);
    5152
    5253    /* Entering and leaving loops. */
    5354
    54     void enterLoopScope(const PabloBlock * const scope);
     55    void enterLoopScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope);
    5556
    56     void enterLoopBody(llvm::BasicBlock * const entryBlock);
     57    void enterLoopBody(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const entryBlock);
    5758
    58     void leaveLoopBody(llvm::BasicBlock * const exitBlock);
     59    void leaveLoopBody(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const exitBlock);
    5960
    60     void leaveLoopScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
     61    void leaveLoopScope(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
    6162
    6263    /* Entering and leaving ifs. */
    6364
    64     void enterIfScope(const PabloBlock * const scope);
     65    void enterIfScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope);
    6566
    66     void enterIfBody(llvm::BasicBlock * const entryBlock);
     67    void enterIfBody(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const entryBlock);
    6768
    68     void leaveIfBody(llvm::BasicBlock * const exitBlock);
     69    void leaveIfBody(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const exitBlock);
    6970
    70     void leaveIfScope(llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
     71    void leaveIfScope(IDISA::IDISA_Builder * const builder, llvm::BasicBlock * const entryBlock, llvm::BasicBlock * const exitBlock);
    7172
    7273    /* Methods for processing individual carry-generating operations. */
    7374   
    74     llvm::Value * addCarryInCarryOut(const Statement * operation, llvm::Value * const e1, llvm::Value * const e2);
     75    llvm::Value * addCarryInCarryOut(IDISA::IDISA_Builder * const builder, const Statement * operation, llvm::Value * const e1, llvm::Value * const e2);
    7576
    76     llvm::Value * advanceCarryInCarryOut(const Advance * advance, llvm::Value * const strm);
     77    llvm::Value * advanceCarryInCarryOut(IDISA::IDISA_Builder * const builder, const Advance * advance, llvm::Value * const strm);
    7778 
    7879    /* Methods for getting and setting carry summary values for If statements */
    7980         
    80     llvm::Value * generateSummaryTest(llvm::Value * condition);
     81    llvm::Value * generateSummaryTest(IDISA::IDISA_Builder * const builder, llvm::Value * condition);
    8182
    8283protected:
    8384
    84     static unsigned getScopeCount(PabloBlock * const scope, unsigned index = 0);
     85    static unsigned getScopeCount(const PabloBlock * const scope, unsigned index = 0);
    8586
    8687    static bool hasIterationSpecificAssignment(const PabloBlock * const scope);
    8788
    88     llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0, const bool isNestedWithinNonCarryCollapsingLoop = false);
     89    llvm::StructType * analyse(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0, const bool isNestedWithinNonCarryCollapsingLoop = false);
    8990
    9091    /* Entering and leaving scopes. */
    91     void enterScope(const PabloBlock * const scope);
    92     void leaveScope();
     92    void enterScope(IDISA::IDISA_Builder * const builder, const PabloBlock * const scope);
     93    void leaveScope(IDISA::IDISA_Builder * const builder);
    9394
    9495    /* Methods for processing individual carry-generating operations. */
    95     llvm::Value * getNextCarryIn();
    96     void setNextCarryOut(llvm::Value * const carryOut);
    97     llvm::Value * longAdvanceCarryInCarryOut(llvm::Value * const value, const unsigned shiftAmount);
    98     llvm::Value * readCarryInSummary(llvm::ConstantInt *index) const;
    99     void writeCarryOutSummary(llvm::Value * const summary, llvm::ConstantInt * index) const;
     96    llvm::Value * getNextCarryIn(IDISA::IDISA_Builder * const builder);
     97    void setNextCarryOut(IDISA::IDISA_Builder * const builder, llvm::Value * const carryOut);
     98    llvm::Value * longAdvanceCarryInCarryOut(IDISA::IDISA_Builder * const builder, llvm::Value * const value, const unsigned shiftAmount);
     99    llvm::Value * readCarryInSummary(IDISA::IDISA_Builder * const builder, llvm::ConstantInt *index) const;
     100    void writeCarryOutSummary(IDISA::IDISA_Builder * const builder, llvm::Value * const summary, llvm::ConstantInt * index) const;
    100101
    101102    /* Summary handling routines */
    102     void addToCarryOutSummary(llvm::Value * const value);
    103 
    104     llvm::Type * getBitBlockType() const;
    105 
    106     unsigned getBitBlockWidth() const;
    107 
    108     llvm::Type * getCarryPackType() const;
     103    void addToCarryOutSummary(IDISA::IDISA_Builder * const builder, llvm::Value * const value);
    109104
    110105private:
    111106
    112     PabloKernel * const                             mKernel;
    113     IDISA::IDISA_Builder *                          iBuilder;
     107    const PabloKernel *                             mKernel;
    114108
    115109    llvm::Value *                                   mCurrentFrame;
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5371 r5435  
    278278
    279279    llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    280         return mParent->getStreamSetTy(NumElements, FieldWidth);
     280        return mParent->getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    281281    }
    282282   
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5431 r5435  
    4444}
    4545
    46 void PabloCompiler::compile() {
    47     iBuilder = mKernel->getBuilder();
    48     assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    49     mCarryManager->initializeCodeGen();     
     46void PabloCompiler::initializeKernelData(IDISA::IDISA_Builder * const builder) {
     47    assert ("PabloCompiler does not have a IDISA builder" && builder);
     48    examineBlock(builder, mKernel->getEntryBlock());
     49    mCarryManager->initializeCarryData(builder, mKernel);
     50}
     51
     52void PabloCompiler::compile(IDISA::IDISA_Builder * const builder) {
     53    assert ("PabloCompiler does not have a IDISA builder" && builder);
     54    mCarryManager->initializeCodeGen(builder);
    5055    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
    51     mMarker.emplace(entryBlock->createZeroes(), iBuilder->allZeroes());
    52     mMarker.emplace(entryBlock->createOnes(), iBuilder->allOnes());
    53     compileBlock(entryBlock);
    54     mCarryManager->finalizeCodeGen();
    55 }
    56 
    57 void PabloCompiler::initializeKernelData() {
    58     iBuilder = mKernel->getBuilder();
    59     assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    60     examineBlock(mKernel->getEntryBlock());
    61     mCarryManager->initializeCarryData();
    62 }
    63 
    64 void PabloCompiler::examineBlock(const PabloBlock * const block) {
     56    mMarker.emplace(entryBlock->createZeroes(), builder->allZeroes());
     57    mMarker.emplace(entryBlock->createOnes(), builder->allOnes());
     58    compileBlock(builder, entryBlock);
     59    mCarryManager->finalizeCodeGen(builder);
     60}
     61
     62void PabloCompiler::examineBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block) {
    6563    for (const Statement * stmt : *block) {
    6664        if (LLVM_UNLIKELY(isa<Lookahead>(stmt))) {
     
    7169            }
    7270        } else if (LLVM_UNLIKELY(isa<Branch>(stmt))) {
    73             examineBlock(cast<Branch>(stmt)->getBody());
     71            examineBlock(builder, cast<Branch>(stmt)->getBody());
    7472        } else if (LLVM_UNLIKELY(isa<Count>(stmt))) {
    75             mAccumulator.insert(std::make_pair(stmt, iBuilder->getInt32(mKernel->addUnnamedScalar(stmt->getType()))));
     73            mAccumulator.insert(std::make_pair(stmt, builder->getInt32(mKernel->addUnnamedScalar(stmt->getType()))));
    7674        }
    7775    }   
    7876}
    7977
    80 inline void PabloCompiler::compileBlock(const PabloBlock * const block) {
     78inline void PabloCompiler::compileBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block) {
    8179    for (const Statement * statement : *block) {
    82         compileStatement(statement);
    83     }
    84 }
    85 
    86 void PabloCompiler::compileIf(const If * const ifStatement) {
     80        compileStatement(builder, statement);
     81    }
     82}
     83
     84void PabloCompiler::compileIf(IDISA::IDISA_Builder * const builder, const If * const ifStatement) {
    8785    //
    8886    //  The If-ElseZero stmt:
     
    103101    //
    104102
    105     BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
     103    BasicBlock * const ifEntryBlock = builder->GetInsertBlock();
    106104    BasicBlock * const ifBodyBlock = mKernel->CreateBasicBlock("if.body");
    107105    BasicBlock * const ifEndBlock = mKernel->CreateBasicBlock("if.end");
     
    115113                marker = mKernel->getScalarFieldPtr(var->getName());
    116114            } else if (var->isReadOnly()) {
    117                 marker = mKernel->getInputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     115                marker = mKernel->getInputStreamBlockPtr(var->getName(), builder->getInt32(0));
    118116            } else if (var->isReadNone()) {
    119                 marker = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     117                marker = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    120118            }
    121119            mMarker[var] = marker;
     
    136134    const PabloBlock * ifBody = ifStatement->getBody();
    137135   
    138     mCarryManager->enterIfScope(ifBody);
    139 
    140     Value * condition = compileExpression(ifStatement->getCondition());
    141     if (condition->getType() == iBuilder->getBitBlockType()) {
    142         condition = iBuilder->bitblock_any(mCarryManager->generateSummaryTest(condition));
     136    mCarryManager->enterIfScope(builder, ifBody);
     137
     138    Value * condition = compileExpression(builder, ifStatement->getCondition());
     139    if (condition->getType() == builder->getBitBlockType()) {
     140        condition = builder->bitblock_any(mCarryManager->generateSummaryTest(builder, condition));
    143141    }
    144142   
    145     iBuilder->CreateCondBr(condition, ifBodyBlock, ifEndBlock);
     143    builder->CreateCondBr(condition, ifBodyBlock, ifEndBlock);
    146144   
    147145    // Entry processing is complete, now handle the body of the if.
    148     iBuilder->SetInsertPoint(ifBodyBlock);
    149 
    150     mCarryManager->enterIfBody(ifEntryBlock);
    151 
    152     compileBlock(ifBody);
    153 
    154     mCarryManager->leaveIfBody(iBuilder->GetInsertBlock());
    155 
    156     BasicBlock * ifExitBlock = iBuilder->GetInsertBlock();
    157 
    158     iBuilder->CreateBr(ifEndBlock);
     146    builder->SetInsertPoint(ifBodyBlock);
     147
     148    mCarryManager->enterIfBody(builder, ifEntryBlock);
     149
     150    compileBlock(builder, ifBody);
     151
     152    mCarryManager->leaveIfBody(builder, builder->GetInsertBlock());
     153
     154    BasicBlock * ifExitBlock = builder->GetInsertBlock();
     155
     156    builder->CreateBr(ifEndBlock);
    159157
    160158    ifEndBlock->moveAfter(ifExitBlock);
    161159
    162160    //End Block
    163     iBuilder->SetInsertPoint(ifEndBlock);
    164 
    165     mCarryManager->leaveIfScope(ifEntryBlock, ifExitBlock);
     161    builder->SetInsertPoint(ifEndBlock);
     162
     163    mCarryManager->leaveIfScope(builder, ifEntryBlock, ifExitBlock);
    166164
    167165    for (const auto i : incoming) {
     
    198196        }
    199197
    200         PHINode * phi = iBuilder->CreatePHI(incoming->getType(), 2, var->getName());
     198        PHINode * phi = builder->CreatePHI(incoming->getType(), 2, var->getName());
    201199        phi->addIncoming(incoming, ifEntryBlock);
    202200        phi->addIncoming(outgoing, ifExitBlock);
     
    205203}
    206204
    207 void PabloCompiler::compileWhile(const While * const whileStatement) {
     205void PabloCompiler::compileWhile(IDISA::IDISA_Builder * const builder, const While * const whileStatement) {
    208206
    209207    const PabloBlock * const whileBody = whileStatement->getBody();
    210208
    211     BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
     209    BasicBlock * whileEntryBlock = builder->GetInsertBlock();
    212210
    213211    const auto escaped = whileStatement->getEscaped();
     
    226224                marker = mKernel->getScalarFieldPtr(var->getName());
    227225            } else if (var->isReadOnly()) {
    228                 marker = mKernel->getInputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     226                marker = mKernel->getInputStreamBlockPtr(var->getName(), builder->getInt32(0));
    229227            } else if (var->isReadNone()) {
    230                 marker = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     228                marker = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    231229            }
    232230            mMarker[var] = marker;
     
    234232    }
    235233
    236     mCarryManager->enterLoopScope(whileBody);
     234    mCarryManager->enterLoopScope(builder, whileBody);
    237235
    238236    BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
    239237
    240     iBuilder->CreateBr(whileBodyBlock);
    241 
    242     iBuilder->SetInsertPoint(whileBodyBlock);
     238    builder->CreateBr(whileBodyBlock);
     239
     240    builder->SetInsertPoint(whileBodyBlock);
    243241
    244242    //
     
    266264        }
    267265        Value * entryValue = f->second;
    268         PHINode * phi = iBuilder->CreatePHI(entryValue->getType(), 2, var->getName());
     266        PHINode * phi = builder->CreatePHI(entryValue->getType(), 2, var->getName());
    269267        phi->addIncoming(entryValue, whileEntryBlock);
    270268        f->second = phi;
     
    279277#endif
    280278
    281     mCarryManager->enterLoopBody(whileEntryBlock);
    282 
    283     compileBlock(whileBody);
     279    mCarryManager->enterLoopBody(builder, whileEntryBlock);
     280
     281    compileBlock(builder, whileBody);
    284282
    285283    // After the whileBody has been compiled, we may be in a different basic block.
    286284
    287     mCarryManager->leaveLoopBody(iBuilder->GetInsertBlock());
     285    mCarryManager->leaveLoopBody(builder, builder->GetInsertBlock());
    288286
    289287
     
    296294#endif
    297295
    298     BasicBlock * const whileExitBlock = iBuilder->GetInsertBlock();
     296    BasicBlock * const whileExitBlock = builder->GetInsertBlock();
    299297
    300298    // and for any variant nodes in the loop body
     
    334332
    335333    // Terminate the while loop body with a conditional branch back.
    336     Value * condition = compileExpression(whileStatement->getCondition());
    337     if (condition->getType() == iBuilder->getBitBlockType()) {
    338         condition = iBuilder->bitblock_any(mCarryManager->generateSummaryTest(condition));
    339     }
    340 
    341     iBuilder->CreateCondBr(condition, whileBodyBlock, whileEndBlock);
    342 
    343     iBuilder->SetInsertPoint(whileEndBlock);
    344 
    345     mCarryManager->leaveLoopScope(whileEntryBlock, whileExitBlock);
    346 
    347 }
    348 
    349 void PabloCompiler::compileStatement(const Statement * const stmt) {
     334    Value * condition = compileExpression(builder, whileStatement->getCondition());
     335    if (condition->getType() == builder->getBitBlockType()) {
     336        condition = builder->bitblock_any(mCarryManager->generateSummaryTest(builder, condition));
     337    }
     338
     339    builder->CreateCondBr(condition, whileBodyBlock, whileEndBlock);
     340
     341    builder->SetInsertPoint(whileEndBlock);
     342
     343    mCarryManager->leaveLoopScope(builder, whileEntryBlock, whileExitBlock);
     344
     345}
     346
     347void PabloCompiler::compileStatement(IDISA::IDISA_Builder * const builder, const Statement * const stmt) {
    350348
    351349    if (LLVM_UNLIKELY(isa<If>(stmt))) {
    352         compileIf(cast<If>(stmt));
     350        compileIf(builder, cast<If>(stmt));
    353351    } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
    354         compileWhile(cast<While>(stmt));
     352        compileWhile(builder, cast<While>(stmt));
    355353    } else {
    356354        const PabloAST * expr = stmt;
    357355        Value * value = nullptr;
    358356        if (LLVM_UNLIKELY(isa<Assign>(stmt))) {
    359             value = compileExpression(cast<Assign>(stmt)->getValue());
     357            value = compileExpression(builder, cast<Assign>(stmt)->getValue());
    360358            expr = cast<Assign>(stmt)->getVariable();
    361359            Value * ptr = nullptr;
     
    377375                        ptr = mKernel->getScalarFieldPtr(var->getName());
    378376                    } else {
    379                         ptr = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     377                        ptr = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    380378                    }
    381379                }
     
    398396            }
    399397            if (ptr) {
    400                 iBuilder->CreateAlignedStore(value, ptr, getAlignment(value));
     398                builder->CreateAlignedStore(value, ptr, getAlignment(value));
    401399                value = ptr;
    402400            }
    403401        } else if (const Extract * extract = dyn_cast<Extract>(stmt)) {
    404             Value * index = compileExpression(extract->getIndex());
     402            Value * index = compileExpression(builder, extract->getIndex());
    405403            Var * const array = dyn_cast<Var>(extract->getArray());
    406404            if (LLVM_LIKELY(array && array->isKernelParameter())) {
     
    419417                }
    420418            } else {
    421                 Value * ptr = compileExpression(extract->getArray(), false);
    422                 value = iBuilder->CreateGEP(ptr, {ConstantInt::getNullValue(index->getType()), index}, "extract");
     419                Value * ptr = compileExpression(builder, extract->getArray(), false);
     420                value = builder->CreateGEP(ptr, {ConstantInt::getNullValue(index->getType()), index}, "extract");
    423421            }
    424422        } else if (isa<And>(stmt)) {
    425             value = compileExpression(stmt->getOperand(0));
     423            value = compileExpression(builder, stmt->getOperand(0));
    426424            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    427                 value = iBuilder->simd_and(value, compileExpression(stmt->getOperand(1)));
     425                value = builder->simd_and(value, compileExpression(builder, stmt->getOperand(1)));
    428426            }
    429427        } else if (isa<Or>(stmt)) {
    430             value = compileExpression(stmt->getOperand(0));
     428            value = compileExpression(builder, stmt->getOperand(0));
    431429            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    432                 value = iBuilder->simd_or(value, compileExpression(stmt->getOperand(1)));
     430                value = builder->simd_or(value, compileExpression(builder, stmt->getOperand(1)));
    433431            }
    434432        } else if (isa<Xor>(stmt)) {
    435             value = compileExpression(stmt->getOperand(0));
     433            value = compileExpression(builder, stmt->getOperand(0));
    436434            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    437                 value = iBuilder->simd_xor(value, compileExpression(stmt->getOperand(1)));
     435                value = builder->simd_xor(value, compileExpression(builder, stmt->getOperand(1)));
    438436            }
    439437        } else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
    440             Value* ifMask = compileExpression(sel->getCondition());
    441             Value* ifTrue = iBuilder->simd_and(ifMask, compileExpression(sel->getTrueExpr()));
    442             Value* ifFalse = iBuilder->simd_and(iBuilder->simd_not(ifMask), compileExpression(sel->getFalseExpr()));
    443             value = iBuilder->simd_or(ifTrue, ifFalse);
     438            Value* ifMask = compileExpression(builder, sel->getCondition());
     439            Value* ifTrue = builder->simd_and(ifMask, compileExpression(builder, sel->getTrueExpr()));
     440            Value* ifFalse = builder->simd_and(builder->simd_not(ifMask), compileExpression(builder, sel->getFalseExpr()));
     441            value = builder->simd_or(ifTrue, ifFalse);
    444442        } else if (isa<Not>(stmt)) {
    445             value = iBuilder->simd_not(compileExpression(stmt->getOperand(0)));
     443            value = builder->simd_not(compileExpression(builder, stmt->getOperand(0)));
    446444        } else if (isa<Advance>(stmt)) {
    447445            const Advance * const adv = cast<Advance>(stmt);
    448446            // If our expr is an Extract op on a mutable Var then we need to pass the index value to the carry
    449447            // manager so that it properly selects the correct carry bit.
    450             value = mCarryManager->advanceCarryInCarryOut(adv, compileExpression(adv->getExpression()));
     448            value = mCarryManager->advanceCarryInCarryOut(builder, adv, compileExpression(builder, adv->getExpression()));
    451449        } else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
    452             Value * const marker = compileExpression(mstar->getMarker());
    453             Value * const cc = compileExpression(mstar->getCharClass());
    454             Value * const marker_and_cc = iBuilder->simd_and(marker, cc);
    455             Value * const sum = mCarryManager->addCarryInCarryOut(mstar, marker_and_cc, cc);
    456             value = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
     450            Value * const marker = compileExpression(builder, mstar->getMarker());
     451            Value * const cc = compileExpression(builder, mstar->getCharClass());
     452            Value * const marker_and_cc = builder->simd_and(marker, cc);
     453            Value * const sum = mCarryManager->addCarryInCarryOut(builder, mstar, marker_and_cc, cc);
     454            value = builder->simd_or(builder->simd_xor(sum, cc), marker);
    457455        } else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
    458             Value * const from = compileExpression(sthru->getScanFrom());
    459             Value * const thru = compileExpression(sthru->getScanThru());
    460             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, thru);
    461             value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     456            Value * const from = compileExpression(builder, sthru->getScanFrom());
     457            Value * const thru = compileExpression(builder, sthru->getScanThru());
     458            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, thru);
     459            value = builder->simd_and(sum, builder->simd_not(thru));
    462460        } else if (const ScanTo * sthru = dyn_cast<ScanTo>(stmt)) {
    463             Value * const marker_expr = compileExpression(sthru->getScanFrom());
    464             Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
    465             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, marker_expr, iBuilder->simd_not(to));
    466             value = iBuilder->simd_and(sum, to);
     461            Value * const marker_expr = compileExpression(builder, sthru->getScanFrom());
     462            Value * const to = builder->simd_xor(compileExpression(builder, sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     463            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, marker_expr, builder->simd_not(to));
     464            value = builder->simd_and(sum, to);
    467465        } else if (const AdvanceThenScanThru * sthru = dyn_cast<AdvanceThenScanThru>(stmt)) {
    468             Value * const from = compileExpression(sthru->getScanFrom());
    469             Value * const thru = compileExpression(sthru->getScanThru());
    470             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, thru));
    471             value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     466            Value * const from = compileExpression(builder, sthru->getScanFrom());
     467            Value * const thru = compileExpression(builder, sthru->getScanThru());
     468            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, builder->simd_or(from, thru));
     469            value = builder->simd_and(sum, builder->simd_not(thru));
    472470        } else if (const AdvanceThenScanTo * sthru = dyn_cast<AdvanceThenScanTo>(stmt)) {
    473             Value * const from = compileExpression(sthru->getScanFrom());
    474             Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
    475             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, iBuilder->simd_not(to)));
    476             value = iBuilder->simd_and(sum, to);
     471            Value * const from = compileExpression(builder, sthru->getScanFrom());
     472            Value * const to = builder->simd_xor(compileExpression(builder, sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     473            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, builder->simd_or(from, builder->simd_not(to)));
     474            value = builder->simd_and(sum, to);
    477475        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    478476            Value * EOFmask = mKernel->getScalarField("EOFmask");
    479             value = iBuilder->simd_and(compileExpression(e->getExpr()), iBuilder->simd_not(EOFmask));
     477            value = builder->simd_and(compileExpression(builder, e->getExpr()), builder->simd_not(EOFmask));
    480478        } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
    481479            Value * EOFbit = mKernel->getScalarField("EOFbit");
    482             value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
     480            value = builder->simd_and(compileExpression(builder, e->getExpr()), EOFbit);
    483481        } else if (const Count * c = dyn_cast<Count>(stmt)) {
    484482            Value * EOFbit = mKernel->getScalarField("EOFbit");
    485483            Value * EOFmask = mKernel->getScalarField("EOFmask");
    486             Value * const to_count = iBuilder->simd_and(iBuilder->simd_or(iBuilder->simd_not(EOFmask), EOFbit), compileExpression(c->getExpr()));
    487             const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
     484        Value * const to_count = builder->simd_and(builder->simd_or(builder->simd_not(EOFmask), EOFbit), compileExpression(builder, c->getExpr()));
     485            const unsigned counterSize = builder->getSizeTy()->getBitWidth();
    488486            const auto f = mAccumulator.find(c);
    489487            if (LLVM_UNLIKELY(f == mAccumulator.end())) {
     
    492490            Value * ptr = mKernel->getScalarFieldPtr(f->second);
    493491            const auto alignment = getPointerElementAlignment(ptr);
    494             Value * count = iBuilder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
    495             Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
     492            Value * count = builder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
     493            Value * const partial = builder->simd_popcount(counterSize, to_count);
    496494            if (LLVM_UNLIKELY(counterSize <= 1)) {
    497495                value = partial;
    498496            } else {
    499                 value = iBuilder->mvmd_extract(counterSize, partial, 0);
    500                 const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
     497                value = builder->mvmd_extract(counterSize, partial, 0);
     498                const auto fields = (builder->getBitBlockWidth() / counterSize);
    501499                for (unsigned i = 1; i < fields; ++i) {
    502                     Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
    503                     value = iBuilder->CreateAdd(value, temp);
    504                 }
    505             }
    506             value = iBuilder->CreateAdd(value, count);
    507             iBuilder->CreateAlignedStore(value, ptr, alignment);
     500                    Value * temp = builder->mvmd_extract(counterSize, partial, i);
     501                    value = builder->CreateAdd(value, temp);
     502                }
     503            }
     504            value = builder->CreateAdd(value, count);
     505            builder->CreateAlignedStore(value, ptr, alignment);
    508506        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
    509507            Var * var = nullptr;
    510508            PabloAST * stream = l->getExpr();
    511             Value * index = iBuilder->getInt32(0);
     509            Value * index = builder->getInt32(0);
    512510            if (LLVM_UNLIKELY(isa<Extract>(stream))) {
    513511                var = dyn_cast<Var>(cast<Extract>(stream)->getArray());
    514                 index = compileExpression(cast<Extract>(stream)->getIndex());
     512                index = compileExpression(builder, cast<Extract>(stream)->getIndex());
    515513                if (!var->isKernelParameter() || var->isReadNone()) {
    516514                    std::string tmp;
     
    535533                }
    536534            }
    537             const auto bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    538             const auto block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    539 
    540             Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(iBuilder->getSize(block_shift), var->getName(), index);
    541             Value * lookAhead = iBuilder->CreateBlockAlignedLoad(ptr);
     535            const auto bit_shift = (l->getAmount() % builder->getBitBlockWidth());
     536            const auto block_shift = (l->getAmount() / builder->getBitBlockWidth());
     537
     538            Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(builder->getSize(block_shift), var->getName(), index);
     539            Value * lookAhead = builder->CreateBlockAlignedLoad(ptr);
    542540            if (bit_shift == 0) {  // Simple case with no intra-block shifting.
    543541                value = lookAhead;
    544542            } else { // Need to form shift result from two adjacent blocks.
    545                 Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(iBuilder->getSize(block_shift + 1), var->getName(), index);
    546                 Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(ptr);
     543                Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(builder->getSize(block_shift + 1), var->getName(), index);
     544                Value * lookAhead1 = builder->CreateBlockAlignedLoad(ptr);
    547545                if (LLVM_UNLIKELY((bit_shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
    548                     value = iBuilder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
     546                    value = builder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
    549547                } else {
    550                     Type  * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
    551                     Value * b1 = iBuilder->CreateBitCast(lookAhead1, streamType);
    552                     Value * b0 = iBuilder->CreateBitCast(lookAhead, streamType);
    553                     Value * result = iBuilder->CreateOr(iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - bit_shift), iBuilder->CreateLShr(b0, bit_shift));
    554                     value = iBuilder->CreateBitCast(result, iBuilder->getBitBlockType());
     548                    Type  * const streamType = builder->getIntNTy(builder->getBitBlockWidth());
     549                    Value * b1 = builder->CreateBitCast(lookAhead1, streamType);
     550                    Value * b0 = builder->CreateBitCast(lookAhead, streamType);
     551                    Value * result = builder->CreateOr(builder->CreateShl(b1, builder->getBitBlockWidth() - bit_shift), builder->CreateLShr(b0, bit_shift));
     552                    value = builder->CreateBitCast(result, builder->getBitBlockType());
    555553                }
    556554            }
     
    569567            const String & name = isa<Var>(expr) ? cast<Var>(expr)->getName() : cast<Statement>(expr)->getName();
    570568            if (value->getType()->isPointerTy()) {
    571                 value = iBuilder->CreateLoad(value);
     569                value = builder->CreateLoad(value);
    572570            }
    573571            if (value->getType()->isVectorTy()) {
    574                 iBuilder->CallPrintRegister(name.str(), value);
     572                builder->CallPrintRegister(name.str(), value);
    575573            } else if (value->getType()->isIntegerTy()) {
    576                 iBuilder->CallPrintInt(name.str(), value);
    577             }
    578         }
    579     }
    580 }
    581 
    582 Value * PabloCompiler::compileExpression(const PabloAST * expr, const bool ensureLoaded) const {
     574                builder->CallPrintInt(name.str(), value);
     575            }
     576        }
     577    }
     578}
     579
     580Value * PabloCompiler::compileExpression(IDISA::IDISA_Builder * const builder, const PabloAST * expr, const bool ensureLoaded) const {
    583581    if (LLVM_UNLIKELY(isa<Ones>(expr))) {
    584         return iBuilder->allOnes();
     582        return builder->allOnes();
    585583    } else if (LLVM_UNLIKELY(isa<Zeroes>(expr))) {
    586         return iBuilder->allZeroes();
     584        return builder->allZeroes();
    587585    } else if (LLVM_UNLIKELY(isa<Integer>(expr))) {
    588586        return ConstantInt::get(cast<Integer>(expr)->getType(), cast<Integer>(expr)->value());
    589587    } else if (LLVM_UNLIKELY(isa<Operator>(expr))) {
    590588        const Operator * op = cast<Operator>(expr);
    591         Value * lh = compileExpression(op->getLH());
    592         Value * rh = compileExpression(op->getRH());
     589        Value * lh = compileExpression(builder, op->getLH());
     590        Value * rh = compileExpression(builder, op->getRH());
    593591        if (LLVM_UNLIKELY(lh->getType() != rh->getType())) {
    594592            std::string tmp;
     
    605603        switch (op->getClassTypeId()) {
    606604            case TypeId::Add:
    607                 return iBuilder->CreateAdd(lh, rh);
     605                return builder->CreateAdd(lh, rh);
    608606            case TypeId::Subtract:
    609                 return iBuilder->CreateSub(lh, rh);
     607                return builder->CreateSub(lh, rh);
    610608            case TypeId::LessThan:
    611                 return iBuilder->CreateICmpSLT(lh, rh);
     609                return builder->CreateICmpSLT(lh, rh);
    612610            case TypeId::LessThanEquals:
    613                 return iBuilder->CreateICmpSLE(lh, rh);
     611                return builder->CreateICmpSLE(lh, rh);
    614612            case TypeId::Equals:
    615                 return iBuilder->CreateICmpEQ(lh, rh);
     613                return builder->CreateICmpEQ(lh, rh);
    616614            case TypeId::GreaterThanEquals:
    617                 return iBuilder->CreateICmpSGE(lh, rh);
     615                return builder->CreateICmpSGE(lh, rh);
    618616            case TypeId::GreaterThan:
    619                 return iBuilder->CreateICmpSGT(lh, rh);
     617                return builder->CreateICmpSGT(lh, rh);
    620618            case TypeId::NotEquals:
    621                 return iBuilder->CreateICmpNE(lh, rh);
     619                return builder->CreateICmpNE(lh, rh);
    622620            default: break;
    623621        }
     
    640638    Value * value = f->second;
    641639    if (LLVM_UNLIKELY(isa<GetElementPtrInst>(value) && ensureLoaded)) {
    642         value = iBuilder->CreateAlignedLoad(value, getPointerElementAlignment(value));
     640        value = builder->CreateAlignedLoad(value, getPointerElementAlignment(value));
    643641    }
    644642    return value;
     
    646644
    647645PabloCompiler::PabloCompiler(PabloKernel * const kernel)
    648 : iBuilder(nullptr)
    649 , mKernel(kernel)
    650 , mCarryManager(new CarryManager(kernel)) {
     646: mKernel(kernel)
     647, mCarryManager(new CarryManager) {
    651648    assert ("PabloKernel cannot be null!" && kernel);
    652649}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5431 r5435  
    99
    1010#include <unordered_map>
     11#include <memory>
    1112namespace IDISA { class IDISA_Builder; }
    1213namespace llvm { class Function; }
     
    3637protected:
    3738
    38     void initializeKernelData();
     39    void initializeKernelData(IDISA::IDISA_Builder * const builder);
    3940
    40     void compile();
     41    void compile(IDISA::IDISA_Builder * const builder);
    4142
    4243private:
    4344
    44     void examineBlock(const PabloBlock * const block);
     45    void examineBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block);
    4546
    46     void compileBlock(const PabloBlock * const block);
     47    void compileBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block);
    4748
    48     void compileStatement(const Statement * stmt);
     49    void compileStatement(IDISA::IDISA_Builder * const builder, const Statement * stmt);
    4950
    50     void compileIf(const If * ifStmt);
     51    void compileIf(IDISA::IDISA_Builder * const builder, const If * ifStmt);