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

Continued refactoring work.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 added
42 edited

Legend:

Unmodified
Added
Removed
  • 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:
Note: See TracChangeset for help on using the changeset viewer.