Changeset 5217


Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (3 years ago)
Author:
nmedfort
Message:

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

Location:
icGREP/icgrep-devel/icgrep
Files:
4 added
6 deleted
81 edited
4 moved

Legend:

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

    r5212 r5217  
    5050SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
    5151
    52 SET(IDISA_SRC IDISA/idisa_builder.cpp IDISA/idisa_avx_builder.cpp IDISA/idisa_i64_builder.cpp IDISA/idisa_sse_builder.cpp IDISA/idisa_nvptx_builder.cpp IDISA/idisa_target.cpp)
    53 
    54 SET(PABLO_SRC pablo/type/streamtype.cpp pablo/pabloAST.cpp pablo/branch.cpp pablo/function.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_toolchain.cpp)
    55 SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp pablo/pablo_kernel.cpp)
     52SET(IDISA_SRC IDISA/types/streamtype.cpp IDISA/idisa_builder.cpp IDISA/idisa_avx_builder.cpp IDISA/idisa_i64_builder.cpp IDISA/idisa_sse_builder.cpp IDISA/idisa_nvptx_builder.cpp IDISA/idisa_target.cpp)
     53
     54SET(PABLO_SRC pablo/pabloAST.cpp pablo/branch.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_toolchain.cpp)
     55SET(PABLO_SRC ${PABLO_SRC} pablo/pablo_kernel.cpp pablo/pablo_compiler.cpp pablo/carry_manager.cpp pablo/carry_data.cpp)
    5656SET(PABLO_SRC ${PABLO_SRC} kernels/kernel.cpp kernels/s2p_kernel.cpp kernels/streamset.cpp kernels/interface.cpp)
    5757SET(PABLO_SRC ${PABLO_SRC} pablo/analysis/pabloverifier.cpp)
     
    122122ENDIF()
    123123
    124 target_link_libraries(icgrep ${Boost_LIBRARIES})
    125 target_link_libraries(u8u16 ${Boost_LIBRARIES})
    126 target_link_libraries(wc ${Boost_LIBRARIES})
    127 target_link_libraries(editd ${Boost_LIBRARIES})
    128 
    129 target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${CUDA_LIB})
    130 target_link_libraries (u8u16 UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${CUDA_LIB})
    131 target_link_libraries (wc UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${CUDA_LIB})
    132 target_link_libraries (editd UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${CUDA_LIB})
     124target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${Boost_LIBRARIES} ${CUDA_LIB})
     125target_link_libraries (u8u16 UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${Boost_LIBRARIES} ${CUDA_LIB})
     126target_link_libraries (wc UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${Boost_LIBRARIES} ${CUDA_LIB})
     127target_link_libraries (editd UCDlib PabloADT RegExpCompiler CCADT CodeGen ${REQ_LLVM_LIBRARIES} ${Boost_LIBRARIES} ${CUDA_LIB})
    133128
    134129IF(ENABLE_MULTIPLEXING)
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_avx_builder.h

    r5118 r5217  
    77*/
    88
    9 #include <IDISA/idisa_builder.h>
    109#include <IDISA/idisa_sse_builder.h>
    1110
     
    1716public:
    1817   
    19     IDISA_AVX_Builder(Module * m, Type * bitBlockType) : IDISA_SSE2_Builder(m, bitBlockType) {
     18    IDISA_AVX_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
     19    : IDISA_SSE2_Builder(m, archBitWidth, bitBlockWidth) {
    2020    }
     21
    2122    Value * hsimd_signmask(unsigned fw, Value * a) override;
    22     ~IDISA_AVX_Builder() {};
     23    ~IDISA_AVX_Builder() {}
    2324
    2425};
     
    2728public:
    2829   
    29     IDISA_AVX2_Builder(Module * m, Type * bitBlockType) : IDISA_AVX_Builder(m, bitBlockType) {
     30    IDISA_AVX2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
     31    : IDISA_AVX_Builder(m, archBitWidth, bitBlockWidth) {
    3032    }
     33
    3134    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
    3235    Value * hsimd_packl(unsigned fw, Value * a, Value * b) override;
     
    3740    std::pair<Value *, Value *> bitblock_add_with_carry(Value * a, Value * b, Value * carryin) override;
    3841
    39     ~IDISA_AVX2_Builder() {};
     42    ~IDISA_AVX2_Builder() {}
    4043};
    4144   
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r5204 r5217  
    2525}
    2626
    27 std::string IDISA_Builder::getBitBlockTypeName() {
    28     if (mBitBlockType->isIntegerTy()) return "i" + std::to_string(mBitBlockWidth);
    29     assert(mBitBlockType->isVectorTy() || "BitBlockType is neither integer nor vector");
    30     unsigned fw = mBitBlockType->getScalarSizeInBits();
    31     return "v" + std::to_string(mBitBlockWidth/fw) + "i" + std::to_string(fw);
     27std::string IDISA_Builder::getBitBlockTypeName() const {
     28    const auto type = getBitBlockType();
     29    if (type->isIntegerTy()) {
     30        return "i" + std::to_string(getBitBlockWidth());
     31    }
     32    assert("BitBlockType is neither integer nor vector" && type->isVectorTy());
     33    const auto fw = type->getScalarSizeInBits();
     34    return "v" + std::to_string(getBitBlockWidth() / fw) + "i" + std::to_string(fw);
    3235}
    3336
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r5204 r5217  
    1414#include <llvm/Support/Host.h>
    1515#include <llvm/ADT/Triple.h>
     16#include <IDISA/types/streamtype.h>
    1617
    1718using namespace llvm;
     
    2223public:
    2324
    24     IDISA_Builder(Module * m, Type * bitBlockType, unsigned CacheAlignment=64)
     25    IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, unsigned CacheAlignment=64)
    2526    : IRBuilder<>(m->getContext())
    2627    , mMod(m)
    2728    , mCacheLineAlignment(CacheAlignment)
    28     , mIsArch32Bit(Triple(llvm::sys::getProcessTriple()).isArch32Bit())
    29     , mBitBlockType(bitBlockType)
    30     , mBitBlockWidth(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth())
    31     , mStride(mBitBlockWidth)
    32     , mZeroInitializer(Constant::getNullValue(bitBlockType))
    33     , mOneInitializer(Constant::getAllOnesValue(bitBlockType))
     29    , mBitBlockWidth(bitBlockWidth)
     30    , mStride(stride)
     31    , mSizeType(getIntNTy(archBitWidth))
     32    , mBitBlockType(VectorType::get(IntegerType::get(getContext(), 64), bitBlockWidth / 64))
     33    , mZeroInitializer(Constant::getNullValue(mBitBlockType))
     34    , mOneInitializer(Constant::getAllOnesValue(mBitBlockType))
    3435    , mPrintRegisterFunction(nullptr) {
    3536
     
    3839    virtual ~IDISA_Builder() {}
    3940   
    40     Type * getBitBlockType() const {
    41         return mBitBlockType;
    42     }
    43 
    44     std::string getBitBlockTypeName();  // A short string such as v4i64 or i256.
     41    std::string getBitBlockTypeName() const;  // A short string such as v4i64 or i256.
    4542
    4643    Value * bitCast(Value * a) {
    47         return a->getType() == mBitBlockType ? a : CreateBitCast(a, mBitBlockType);
     44        return (a->getType() == mBitBlockType) ? a : CreateBitCast(a, mBitBlockType);
    4845    }
    4946
     
    142139    Value * fwCast(unsigned fw, Value * a);
    143140   
    144     inline bool isArch32Bit() const {
    145         return mIsArch32Bit;
    146     }
    147 
    148     inline llvm::IntegerType * getSizeTy() {
    149         return isArch32Bit() ? getInt32Ty() : getInt64Ty();
     141    inline llvm::IntegerType * getSizeTy() const {
     142        return mSizeType;
     143    }
     144
     145    inline VectorType * getBitBlockType() const {
     146        return mBitBlockType;
     147    }
     148
     149    inline Type * getStreamSetTy(const uint64_t NumElements = 1, const uint64_t FieldWidth = 1) {
     150        return StreamType::get(getContext(), NumElements, FieldWidth);
    150151    }
    151152   
     
    160161   
    161162protected:
    162     Module * mMod;
    163     unsigned mCacheLineAlignment;
    164     const bool mIsArch32Bit;
    165     Type * mBitBlockType;
    166     unsigned mBitBlockWidth;
    167     unsigned mStride;
    168     Constant * mZeroInitializer;
    169     Constant * mOneInitializer;
    170     Constant * mPrintRegisterFunction;
    171 
     163    Module *            mMod;
     164    unsigned            mCacheLineAlignment;
     165    unsigned            mBitBlockWidth;
     166    unsigned            mStride;
     167    IntegerType *       mSizeType;
     168    VectorType *        mBitBlockType;
     169
     170    Constant *          mZeroInitializer;
     171    Constant *          mOneInitializer;
     172    Constant *          mPrintRegisterFunction;
    172173   
    173174    VectorType * fwVectorType(unsigned fw);
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_i64_builder.h

    r4944 r5217  
    2020public:
    2121 
    22     IDISA_I64_Builder(Module * m, Type * bitBlockType) : IDISA_Builder(m, bitBlockType) {
     22    IDISA_I64_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64)
     23    : IDISA_Builder(m, archBitWidth, bitBlockWidth, stride) {
    2324    }
     25
    2426    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
    2527    Value * hsimd_packl(unsigned fw, Value * a, Value * b) override;
    26     ~IDISA_I64_Builder() {};
     28    ~IDISA_I64_Builder() {}
    2729
    2830};
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_nvptx_builder.h

    r5192 r5217  
    1717public:
    1818   
    19     IDISA_NVPTX20_Builder(Module * m, int groupSize)
    20     : IDISA_I64_Builder(m, VectorType::get(IntegerType::get(m->getContext(), 64), 1))
    21     , groupThreads(groupSize)
    22     {
    23         mStride = mBitBlockWidth * groupSize;
     19    IDISA_NVPTX20_Builder(Module * m, unsigned groupSize)
     20    : IDISA_I64_Builder(m, 64, 64, 64 * groupSize)
     21    , groupThreads(groupSize) {
    2422        CreateGlobals();
    2523        CreateBuiltinFunctions();
     
    2927    }
    3028   
    31     ~IDISA_NVPTX20_Builder() {};
     29    ~IDISA_NVPTX20_Builder() {}
    3230
    3331    int getGroupThreads();
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_sse_builder.h

    r5203 r5217  
    77 *  icgrep is a trademark of International Characters.
    88 */
    9 #include <llvm/IR/Module.h>
    10 #include <llvm/IR/Constant.h>
    11 #include <llvm/IR/Type.h>
    12 #include <llvm/IR/Value.h>
     9
    1310#include <IDISA/idisa_builder.h>
    1411
     
    2017public:
    2118 
    22     IDISA_SSE_Builder(Module * m, Type * bitBlockType) : IDISA_Builder(m, bitBlockType) {
     19    IDISA_SSE_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
     20    : IDISA_Builder(m, archBitWidth, bitBlockWidth, bitBlockWidth) {
    2321    }
     22
    2423    Value * hsimd_signmask(unsigned fw, Value * a) override;
    2524    ~IDISA_SSE_Builder() {}
     
    3029public:
    3130 
    32     IDISA_SSE2_Builder(Module * m, Type * bitBlockType) : IDISA_SSE_Builder(m, bitBlockType) {
     31    IDISA_SSE2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
     32    : IDISA_SSE_Builder(m, archBitWidth, bitBlockWidth) {
    3333    }
     34
    3435    Value * hsimd_signmask(unsigned fw, Value * a) override;
    3536    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_target.cpp

    r5175 r5217  
    1212namespace IDISA {
    1313   
    14 
    15 
    1614IDISA_Builder * GetIDISA_Builder(Module * mod) {
    17     bool hasAVX2 = AVX2_available();
    18     unsigned theBlockSize = codegen::BlockSize;  // from command line
    19    
    20     if (theBlockSize == 0) {  // No BlockSize override: use processor SIMD width
    21         theBlockSize = hasAVX2 ? 256 : 128;
     15    const bool hasAVX2 = AVX2_available();
     16    const bool isArch32Bit = Triple(llvm::sys::getProcessTriple()).isArch32Bit();
     17    if (LLVM_LIKELY(codegen::BlockSize == 0)) {  // No BlockSize override: use processor SIMD width
     18        codegen::BlockSize = hasAVX2 ? 256 : 128;
    2219    }
    23     Type * bitBlockType = VectorType::get(IntegerType::get(mod->getContext(), 64), theBlockSize/64);
    24    
    25     int blockSize = bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth();
    26     if (blockSize >= 256) {
     20    if (codegen::BlockSize >= 256) {
    2721        if (hasAVX2) {
    28             return new IDISA_AVX2_Builder(mod, bitBlockType);
     22            return new IDISA_AVX2_Builder(mod, isArch32Bit ? 32 : 64, codegen::BlockSize);
    2923        }
    30         else{
    31             return new IDISA_SSE2_Builder(mod, bitBlockType);
    32         }
     24    } else if (codegen::BlockSize == 64) {
     25        return new IDISA_I64_Builder(mod, isArch32Bit ? 32 : 64);
    3326    }
    34     else if (blockSize == 64)
    35         return new IDISA_I64_Builder(mod, bitBlockType);
    36     return new IDISA_SSE2_Builder(mod, bitBlockType);
     27    return new IDISA_SSE2_Builder(mod, isArch32Bit ? 32 : 64, codegen::BlockSize);
    3728}
    3829
  • icGREP/icgrep-devel/icgrep/IDISA/types/streamtype.cpp

    r5216 r5217  
    1 #include <pablo/type/streamtype.h>
     1#include "streamtype.h"
    22#include <boost/container/flat_map.hpp>
    33#include <IDISA/idisa_builder.h>
     
    66using namespace llvm;
    77
    8 namespace pablo {
     8namespace IDISA {
    99
    10 static flat_map<uint64_t, StreamType *> STREAM_TYPES;
     10static flat_map<std::pair<unsigned, unsigned>, StreamType *> STREAM_TYPES;
    1111
    12 StreamType * StreamType::get(llvm::LLVMContext & ctx, const uint64_t FieldWidth) {
    13     const auto f = STREAM_TYPES.find(FieldWidth);
     12StreamType * StreamType::get(llvm::LLVMContext & ctx, unsigned NumElements, unsigned FieldWidth) {
     13    const auto f = STREAM_TYPES.find(std::make_pair(NumElements, FieldWidth));
    1414    if (LLVM_LIKELY(f != STREAM_TYPES.end())) {
    1515        return f->second;
    1616    } else {
    17         StreamType * const T = new StreamType(ctx, FieldWidth);
    18         STREAM_TYPES.emplace(FieldWidth, T);
     17        StreamType * const T = new StreamType(ctx, NumElements, FieldWidth);
     18        STREAM_TYPES.emplace(std::make_pair(NumElements, FieldWidth), T);
    1919        return T;
    2020    }
     
    2222
    2323llvm::Type * StreamType::resolveType(IDISA::IDISA_Builder * const iBuilder) {
    24     return mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
     24    return ArrayType::get(iBuilder->getBitBlockType(), mNumElements);
    2525}
    2626
    27 StreamType::StreamType(llvm::LLVMContext & C, uint64_t FieldWidth)
     27StreamType::StreamType(llvm::LLVMContext & C, unsigned NumElements, unsigned FieldWidth)
    2828: llvm::Type(C, (Type::TypeID)(StreamTyId))
     29, mNumElements(NumElements)
    2930, mFieldWidth(FieldWidth) {
    3031
  • icGREP/icgrep-devel/icgrep/IDISA/types/streamtype.h

    r5216 r5217  
    66
    77namespace IDISA {
    8     class IDISA_Builder;
    9 }
    108
    11 namespace pablo {
     9class IDISA_Builder;
    1210
    1311class StreamType : public llvm::Type {
    1412
    15     StreamType(llvm::LLVMContext & ctx, uint64_t FieldWidth);
     13    StreamType(llvm::LLVMContext & ctx, unsigned NumElements, unsigned FieldWidth);
    1614
    1715public:
     
    2119    };
    2220
    23     static StreamType * get(llvm::LLVMContext & ctx, uint64_t FieldWidth);
     21    static StreamType * get(llvm::LLVMContext & ctx, unsigned NumElements, unsigned FieldWidth);
    2422
    25     llvm::Type * resolveType(IDISA::IDISA_Builder * const iBuilder);
     23    unsigned getNumElements() const {
     24        return mNumElements;
     25    }
     26
     27    unsigned getFieldWidth() const {
     28        return mFieldWidth;
     29    }
     30
     31    StreamType * getStreamElementType() const {
     32        return get(getContext(), 1, mFieldWidth);
     33    }
     34
     35    llvm::Type * resolveType(IDISA_Builder * const iBuilder);
    2636
    2737    /// Methods for support type inquiry through isa, cast, and dyn_cast.
     
    3343    }
    3444private:
    35 
    36     uint64_t mFieldWidth;
    37     uint64_t mNumElements;
    38 
     45    unsigned mNumElements;
     46    unsigned mFieldWidth;
    3947};
    4048
    4149}
    4250
    43 inline llvm::Type * getStreamTy(const uint64_t FieldWidth = 1, const uint64_t NumElements = 1) {
    44     llvm::Type * ty = pablo::StreamType::get(llvm::getGlobalContext(), FieldWidth);
    45     if (NumElements > 1) {
    46         ty = llvm::ArrayType::get(ty, NumElements);
    47     }
    48     return ty;
    49 }
    50 
    51 inline llvm::Type * getScalarTy(const uint64_t FieldWidth = 0) {
    52     return llvm::Type::getIntNTy(llvm::getGlobalContext(), FieldWidth);
    53 }
    54 
    5551#endif // STREAMTYPE_H
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5202 r5217  
    1818#include <pablo/codegenstate.h>
    1919#include <pablo/builder.hpp>
    20 #include <pablo/function.h>
     20#include <pablo/prototype.h>
     21#include <pablo/pablo_kernel.h>
    2122#include <stdexcept>
    2223
     
    2627namespace cc {
    2728
    28 CC_Compiler::CC_Compiler(PabloFunction & function, const unsigned encodingBits, const std::string prefix)
    29 : mBuilder(function.getEntryBlock())
     29CC_Compiler::CC_Compiler(PabloKernel * kernel, const unsigned encodingBits, const std::string prefix)
     30: mBuilder(kernel->getEntryBlock())
    3031, mBasisBit(encodingBits)
    3132, mEncodingBits(encodingBits) {
    3233
    3334    // TODO: basisBits should be defined prior and only retrieved here.
    34     Var * const basisBits = function.addParameter(prefix, getStreamTy(1, 8));
     35    Var * const basisBits = kernel->addInput(prefix, kernel->getStreamSetTy(encodingBits));
    3536    for (unsigned i = 0; i != mEncodingBits; i++) {
    3637        mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
     
    224225}
    225226
    226 inline PabloAST *CC_Compiler::getBasisVar(const unsigned i) const {
     227inline PabloAST * CC_Compiler::getBasisVar(const unsigned i) const {
    227228    assert (i < mEncodingBits);
    228229    const unsigned index = mEncodingBits - i - 1; assert (index < mEncodingBits);
     
    230231    return mBasisBit[index];
    231232}
    232    
    233 PabloFunction * ParabixCharacterClassFunction(const std::string & name, const std::vector<CC *> & charClasses, const unsigned basisBitsCount) {
    234     PabloFunction * f = PabloFunction::Create(name + "_fn");
    235     CC_Compiler ccc(*f, basisBitsCount);
    236     PabloBuilder builder(f->getEntryBlock());
    237     for (CC * cc : charClasses) {
    238         Var * const r = f->addResult(cc->canonicalName(re::ByteClass), getStreamTy());
    239         builder.createAssign(r, ccc.charset_expr(cc, builder));
    240     }
    241     return f;
    242 }
    243233
    244234} // end of namespace cc
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5202 r5217  
    1414
    1515namespace pablo {
    16     class PabloFunction;
     16    class PabloKernel;
    1717    class Var;
    1818}
     
    2323
    2424class CC_Compiler{
    25 
    26     friend pablo::PabloFunction * ParabixCharacterClassFunction(const std::string &, const std::vector<re::CC *> &, const unsigned);
    27 
     25    friend class ParabixCharacterClassKernelBuilder;
    2826public:
    2927
    3028    using Vars = std::vector<pablo::Var *>;
    3129
    32     CC_Compiler(pablo::PabloFunction & function, const unsigned encodingBits = 8, const std::string prefix = "basis");
     30    CC_Compiler(pablo::PabloKernel * kernel, const unsigned encodingBits = 8, const std::string prefix = "basis");
    3331
    3432    pablo::PabloAST * compileCC(const re::CC *cc);
    3533
    36     pablo::PabloAST *compileCC(const re::CC *cc, pablo::PabloBlock & block);
     34    pablo::PabloAST * compileCC(const re::CC *cc, pablo::PabloBlock & block);
    3735
    3836    pablo::PabloAST * compileCC(const re::CC *cc, pablo::PabloBuilder & builder);
     
    9189}
    9290
    93 pablo::PabloFunction * ParabixCharacterClassFunction(const std::string & name, const std::vector<re::CC *> & charClasses, const unsigned basisBitsCount);
    94 
    9591}
    9692
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5215 r5217  
    2525#include <re/re_cc.h>
    2626#include <cc/cc_compiler.h>
    27 #include <pablo/function.h>
     27#include <pablo/prototype.h>
    2828#include <pablo/pablo_compiler.h>
    2929#include <pablo/pablo_kernel.h>
     
    192192}
    193193
    194 Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
    195    
    196     ExternalFileBuffer ChStream(iBuilder, StreamSetType(iBuilder, 4, i1));
    197     SingleBlockBuffer MatchResults(iBuilder, StreamSetType(iBuilder, editDistance + 1, i1));
    198 
    199     pablo_function_passes(function);
    200     PabloKernel editdk(iBuilder, "editd", function);
     194void buildPatternKernel(PabloKernel & kernel, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
     195    PabloBuilder entry(kernel.getEntryBlock());
     196
     197    Var * pat = kernel.addInput("pat", iBuilder->getStreamSetTy(4));
     198
     199    PabloAST * basisBits[4];
     200
     201    basisBits[0] = entry.createExtract(pat, 0, "A");
     202    basisBits[1] = entry.createExtract(pat, 1, "C");
     203    basisBits[2] = entry.createExtract(pat, 2, "T");
     204    basisBits[3] = entry.createExtract(pat, 3, "G");
     205
     206    re::Pattern_Compiler pattern_compiler(kernel);
     207    pattern_compiler.compile(patterns, entry, basisBits, editDistance, optPosition, stepSize);
     208
     209    pablo_function_passes(&kernel);
     210}
     211
     212Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
     213   
     214    ExternalFileBuffer ChStream(iBuilder, iBuilder->getStreamSetTy(4));
     215    SingleBlockBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(editDistance + 1));
     216
     217    PabloKernel editdk(iBuilder, "editd");
     218
     219    buildPatternKernel(editdk, iBuilder, patterns);
     220
    201221    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    202222   
     
    239259}
    240260
    241 Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
     261void buildPreprocessKernel(PabloKernel & kernel, IDISA::IDISA_Builder * iBuilder) {
     262    cc::CC_Compiler ccc(&kernel);
     263    PabloBuilder & pb = ccc.getBuilder();
     264
     265    PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
     266    PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
     267    PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
     268    PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
     269
     270    Var * const pat = kernel.addOutput("pat", iBuilder->getStreamSetTy(4));
     271
     272    pb.createAssign(pb.createExtract(pat, 0), A);
     273    pb.createAssign(pb.createExtract(pat, 1), C);
     274    pb.createAssign(pb.createExtract(pat, 2), T);
     275    pb.createAssign(pb.createExtract(pat, 3), G);
     276
     277    pablo_function_passes(&kernel);
     278}
     279
     280Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder) {
    242281    Type * mBitBlockType = iBuilder->getBitBlockType();
    243282   
    244     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
    245     SingleBlockBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1));
    246     ExternalFileBuffer CCResults(iBuilder, StreamSetType(iBuilder,4, 1));
     283    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     284    SingleBlockBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8));
     285    ExternalFileBuffer CCResults(iBuilder, iBuilder->getStreamSetTy(4));
    247286
    248287    s2pKernel  s2pk(iBuilder);
    249288    std::unique_ptr<Module> s2pM = s2pk.createKernelModule({&ByteStream}, {&BasisBits});
    250289
    251     pablo_function_passes(function);
    252     PabloKernel  ccck(iBuilder, "ccc", function);
     290    PabloKernel  ccck(iBuilder, "ccc");
     291
     292    buildPreprocessKernel(ccck, iBuilder);
    253293   
    254294    std::unique_ptr<Module> cccM = ccck.createKernelModule({&BasisBits}, {&CCResults});
     
    301341    Module * M = new Module("preprocess", TheContext);
    302342    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    303     ExecutionEngine * preprocessEngine = nullptr;
    304 
    305     PabloFunction * function = PabloFunction::Create("preprocess"); // , 8, 4
    306     cc::CC_Compiler ccc(*function);
    307     PabloBuilder & pb = ccc.getBuilder();
    308 
    309     PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
    310     PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
    311     PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
    312     PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
    313 
    314     Var * pat = function->addResult("pat", getStreamTy(1, 4));
    315 
    316     pb.createAssign(pb.createExtract(pat, 0), A);
    317     pb.createAssign(pb.createExtract(pat, 1), C);
    318     pb.createAssign(pb.createExtract(pat, 2), T);
    319     pb.createAssign(pb.createExtract(pat, 3), G);
    320 
    321     llvm::Function * main_IR = preprocessPipeline(M, idb, function);
    322 
    323     preprocessEngine = JIT_to_ExecutionEngine(M);
     343
     344    llvm::Function * main_IR = preprocessPipeline(M, idb);
     345
     346    ExecutionEngine * preprocessEngine = JIT_to_ExecutionEngine(M);
    324347   
    325348    preprocessEngine->finalizeObject();
     
    331354typedef void (*editdFunctionType)(char * byte_data, size_t filesize);
    332355
    333 editdFunctionType editdCodeGen(std::vector<std::string> patterns) {
     356editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {
    334357                           
    335358    LLVMContext TheContext;
    336359    Module * M = new Module("editd", TheContext);
    337360    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    338     ExecutionEngine * editdEngine = nullptr;
    339 
    340     PabloFunction * function = PabloFunction::Create("editd"); // , 4, editDistance + 1
    341     PabloBuilder main (function->getEntryBlock());
    342 
    343     Var * pat = function->addParameter("pat", getStreamTy(1, 4));
    344 
    345     PabloAST * basisBits[4];
    346 
    347     basisBits[0] = main.createExtract(pat, 0, "A");
    348     basisBits[1] = main.createExtract(pat, 1, "C");
    349     basisBits[2] = main.createExtract(pat, 2, "T");
    350     basisBits[3] = main.createExtract(pat, 3, "G");
    351 
    352     re::Pattern_Compiler pattern_compiler(*function);
    353     pattern_compiler.compile(patterns, main, basisBits, editDistance, optPosition, stepSize);
    354 
    355     llvm::Function * main_IR = editdPipeline(M, idb, function);
    356 
    357     editdEngine = JIT_to_ExecutionEngine(M);
     361
     362    llvm::Function * main_IR = editdPipeline(M, idb, patterns);
     363
     364    ExecutionEngine * editdEngine = JIT_to_ExecutionEngine(M);
    358365   
    359366    editdEngine->finalizeObject();
     
    442449    Type * const stridesTy = PointerType::get(int32ty, 1);
    443450
    444     ExternalFileBuffer CCStream(iBuilder, StreamSetType(iBuilder, 4, 1), addrSpace);
    445     ExternalFileBuffer ResultStream(iBuilder, StreamSetType(iBuilder, editDistance+1, 1), addrSpace);
     451    ExternalFileBuffer CCStream(iBuilder, iBuilder->getStreamSetTy( 4, 1), addrSpace);
     452    ExternalFileBuffer ResultStream(iBuilder, iBuilder->getStreamSetTy( editDistance+1, 1), addrSpace);
    446453
    447454    kernel::editdGPUKernel editdk(iBuilder, editDistance, patternLen);
     
    584591    Type * const inputType = PointerType::get(ArrayType::get(mBitBlockType, editDistance+1), 0);
    585592
    586     ExternalFileBuffer MatchResults(iBuilder, StreamSetType(iBuilder, editDistance+1, 1));
     593    ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy( editDistance+1, 1));
    587594    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    588595    editdScanK.generateKernel({&MatchResults}, {});               
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5212 r5217  
    1919public:
    2020   
    21     editdCPUKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist, unsigned pattLen) :
    22     KernelBuilder(iBuilder, "editd_cpu",
    23                   {Binding{parabix::StreamSetType(iBuilder, 4, 1), "CCStream"}},
    24                   {Binding{parabix::StreamSetType(iBuilder, dist+1, 1), "ResultStream"}},
    25                   {Binding{PointerType::get(iBuilder->getInt8Ty(), 1), "pattStream"},
    26                   Binding{PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
     21    editdCPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
     22    KernelBuilder(b, "editd_cpu",
     23                  {Binding{b->getStreamSetTy(4), "CCStream"}},
     24                  {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
     25                  {Binding{PointerType::get(b->getInt8Ty(), 1), "pattStream"},
     26                  Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
    2727                  {},
    28                   {Binding{iBuilder->getBitBlockType(), "EOFmask"}}),
     28                  {Binding{b->getBitBlockType(), "EOFmask"}}),
    2929    mEditDistance(dist),
    3030    mPatternLen(pattLen){}
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5212 r5217  
    1919public:
    2020   
    21     editdGPUKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist, unsigned pattLen) :
    22     KernelBuilder(iBuilder, "editd_gpu",
    23                   {Binding{parabix::StreamSetType(iBuilder, 4, 1), "CCStream"}},
    24                   {Binding{parabix::StreamSetType(iBuilder, dist+1, 1), "ResultStream"}},
    25                   {Binding{PointerType::get(iBuilder->getInt8Ty(), 1), "pattStream"},
    26                   Binding{PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
     21    editdGPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
     22    KernelBuilder(b, "editd_gpu",
     23                  {Binding{b->getStreamSetTy(4), "CCStream"}},
     24                  {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
     25                  {Binding{PointerType::get(b->getInt8Ty(), 1), "pattStream"},
     26                  Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
    2727                  {},
    28                   {Binding{iBuilder->getBitBlockType(), "EOFmask"}}),
     28                  {Binding{b->getBitBlockType(), "EOFmask"}}),
    2929    mEditDistance(dist),
    3030    mPatternLen(pattLen){}
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5204 r5217  
    2121    editdScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist) :
    2222    KernelBuilder(iBuilder, "scanMatch",
    23                   {Binding{parabix::StreamSetType(iBuilder,dist+1, parabix::i1), "matchResults"}},
     23                  {Binding{iBuilder->getStreamSetTy(dist + 1), "matchResults"}},
    2424                  {}, {}, {}, {}),
    2525    mEditDistance(dist),
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.cpp

    r5202 r5217  
    2020#include <re/re_analysis.h>
    2121#include <pablo/codegenstate.h>
    22 #include <pablo/function.h>
     22#include <pablo/prototype.h>
    2323
    2424#include <assert.h>
     
    3333
    3434
    35 Pattern_Compiler::Pattern_Compiler(pablo::PabloFunction & function)
    36 : mFunction(function)
     35Pattern_Compiler::Pattern_Compiler(PabloKernel & kernel)
     36: mKernel(kernel)
    3737{
    3838
     
    124124    }
    125125
    126     Var * output = mFunction.addResult("E", getStreamTy(1, dist + 1));
    127126
    128     for(int d=0; d<=dist; d++){
     127    Var * output = mKernel.addOutput("E", mKernel.getBuilder()->getStreamSetTy(dist + 1));
     128    for (int d = 0; d <= dist; d++) {
    129129        pb.createAssign(pb.createExtract(output, d), E[d]);
    130         // mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
    131130    }
    132131}
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.h

    r5202 r5217  
    1818namespace pablo {
    1919class PabloBlock;
     20class PabloKernel;
    2021class PabloAST;
    2122class Assign;
     
    2829public:
    2930
    30     Pattern_Compiler(pablo::PabloFunction & function);
     31    Pattern_Compiler(pablo::PabloKernel & kernel);
    3132
    3233    void compile(const std::vector<std::string> & patterns, pablo::PabloBuilder & pb, pablo::PabloAST *basisBits[], int dist, unsigned optPosition, int stepSize);
    3334
    34 
    3535private:
    3636
    37     pablo::PabloFunction &                          mFunction;
     37    pablo::PabloKernel & mKernel;
    3838};
    3939
  • icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp

    r5202 r5217  
    1111#include <pablo/pablo_compiler.h>
    1212#include <pablo/builder.hpp>
    13 #include <pablo/function.h>
     13#include <pablo/prototype.h>
    1414#include <llvm/Support/CommandLine.h>
    1515#include <utf_encoding.h>
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5207 r5217  
    3434#include <kernels/pipeline.h>
    3535
    36 #include <pablo/function.h>
     36#include <pablo/prototype.h>
    3737#include <pablo/pablo_kernel.h>
    3838#include <pablo/pablo_toolchain.h>
     
    217217    fileIdx->setName("fileIdx");
    218218
    219     ExternalFileBuffer MatchResults(iBuilder, StreamSetType(iBuilder, 2, 1));
     219    ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy( 2, 1));
    220220    MatchResults.setStreamSetBuffer(rsltStream, fileSize);
    221221
     
    328328    }
    329329       
    330     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder, 1, 8));
    331     CircularBuffer BasisBits(iBuilder, StreamSetType(iBuilder, 8, 1), segmentSize * bufferSegments);
     330    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     331    CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments);
    332332
    333333    kernel::s2pKernel  s2pk(iBuilder);
    334334    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    335335   
     336    pablo::PabloKernel icgrepK(iBuilder, "icgrep");
     337
    336338    re_ast = re::regular_expression_passes(re_ast);
    337     pablo::PabloFunction * function = re::re2pablo_compiler(encodingBits, re_ast, CountOnly);
    338     pablo_function_passes(function);
     339    re::re2pablo_compiler(&icgrepK, encodingBits, re_ast, CountOnly);
     340    pablo_function_passes(&icgrepK);
     341
     342
    339343
    340344    ByteStream.setStreamSetBuffer(inputStream, fileSize);
     
    365369    pthreadExitFunc->setCallingConv(llvm::CallingConv::C);
    366370
    367     if (CountOnly) {
    368         pablo::PabloKernel icgrepK(iBuilder, "icgrep", function);
     371    if (CountOnly) {       
    369372        icgrepK.generateKernel({&BasisBits}, {});       
    370373        Value * icgrepInstance = icgrepK.createInstance({});
     
    384387#ifdef CUDA_ENABLED
    385388        if (codegen::NVPTX){
    386             ExternalFileBuffer MatchResults(iBuilder, StreamSetType(iBuilder,2, i1), addrSpace);
     389            ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(2, i1), addrSpace);
    387390            MatchResults.setStreamSetBuffer(outputStream, fileSize);
    388391
    389             pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {});
    390392            icgrepK.generateKernel({&BasisBits},  {&MatchResults});
    391393            Value * icgrepInstance = icgrepK.createInstance({});
     
    396398#endif
    397399        if (CPU_Only) {
    398             CircularBuffer MatchResults(iBuilder, StreamSetType(iBuilder, 2, 1), segmentSize * bufferSegments);
     400            CircularBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy( 2, 1), segmentSize * bufferSegments);
    399401            MatchResults.allocateBuffer();
    400402
    401             pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function);
    402403            icgrepK.generateKernel({&BasisBits}, {&MatchResults});
    403404            Value * icgrepInstance = icgrepK.createInstance({});
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r5202 r5217  
    121121pablo/codegenstate.h
    122122pablo/expression_map.hpp
    123 pablo/function.cpp
    124 pablo/function.h
     123pablo/prototype.cpp
     124pablo/prototype.h
    125125pablo/optimizers/booleanreassociationpass.cpp
    126126pablo/optimizers/booleanreassociationpass.h
     
    164164pablo/pe_all.h
    165165pablo/pe_and.cpp
    166 pablo/pe_and.h
    167166pablo/pe_call.cpp
    168167pablo/pe_call.h
     
    177176pablo/pe_matchstar.h
    178177pablo/pe_metadata.h
    179 pablo/pe_next.h
    180178pablo/pe_not.cpp
    181 pablo/pe_not.h
    182179pablo/pe_ones.h
    183180pablo/pe_or.cpp
    184 pablo/pe_or.h
    185181pablo/pe_scanthru.cpp
    186182pablo/pe_scanthru.h
    187183pablo/pe_sel.cpp
    188 pablo/pe_sel.h
    189184pablo/pe_setithbit.h
    190185pablo/pe_string.h
    191186pablo/pe_var.h
    192187pablo/pe_xor.cpp
    193 pablo/pe_xor.h
    194188pablo/pe_zeroes.h
    195189pablo/printer_pablos.cpp
     
    345339pablo/ps_assign.cpp
    346340pablo/pe_var.cpp
     341pablo/arithmetic.h
     342pablo/boolean.h
     343kernels/type/streamtype.cpp
     344kernels/type/streamtype.h
     345IDISA/types/streamtype.cpp
     346IDISA/types/streamtype.h
     347editd/pattern_compiler.cpp
     348editd/editd.cpp
     349editd/pattern_compiler.h
     350editd/EditdCudaDriver.h
     351editd/editd_cpu_kernel.h
     352editd/editd_gpu_kernel.cpp
     353editd/editd_cpu_kernel.cpp
     354editd/editd_gpu_kernel.h
     355editd/editdscan_kernel.h
     356editd/editdscan_kernel.cpp
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r5202 r5217  
    2424pablo/type
    2525editd
     26kernels/type
     27IDISA/types
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5202 r5217  
    44 */
    55
     6#include "cc_kernel.h"
     7#include <re/re_cc.h>
     8#include <cc/cc_compiler.h>
     9#include <pablo/builder.hpp>
    610
    7 #include "cc_kernel.h"
    8 
    9 
     11using namespace cc;
    1012using namespace kernel;
     13using namespace pablo;
     14using namespace re;
    1115
    1216void DirectCharacterClassKernelBuilder::generateDoBlockMethod() {
     
    7175}
    7276
     77ParabixCharacterClassKernelBuilder::ParabixCharacterClassKernelBuilder (
     78IDISA::IDISA_Builder * iBuilder
     79, std::string ccSetName
     80, const std::vector<CC *> & charClasses
     81, unsigned basisBitsCount)
     82: PabloKernel(iBuilder, ccSetName +"_kernel") {
     83
     84    CC_Compiler ccc(this, basisBitsCount);
     85    auto & builder = ccc.getBuilder();
     86    for (CC * cc : charClasses) {
     87        Var * const r = addOutput(cc->canonicalName(re::ByteClass), getStreamSetTy());
     88        builder.createAssign(r, ccc.compileCC("cc", cc, builder));
     89    }
     90
     91}
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.h

    r5202 r5217  
    99#include "interface.h"
    1010#include "kernel.h"
    11 #include <re/re_cc.h>
    1211#include <pablo/pablo_kernel.h>
    13 #include <cc/cc_compiler.h>
     12
     13namespace re {
     14    class CC;
     15}
    1416
    1517namespace kernel {
    1618
    1719class KernelBuilder;
    18 
    19 
    2020
    2121class DirectCharacterClassKernelBuilder : public KernelBuilder {
     
    2424    DirectCharacterClassKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned codeUnitSize) :
    2525    KernelBuilder(iBuilder, "cc",
    26                   {Binding{parabix::StreamSetType(iBuilder,1, 8 * codeUnitSize), "codeUnitStream"}},
    27                   {Binding{parabix::StreamSetType(iBuilder,charClasses.size(), 1), "ccStream"}},
     26                  {Binding{iBuilder->getStreamSetTy(1, 8 * codeUnitSize), "codeUnitStream"}},
     27                  {Binding{iBuilder->getStreamSetTy(charClasses.size(), 1), "ccStream"}},
    2828                  {}, {}, {}), mCharClasses(charClasses), mCodeUnitSize(codeUnitSize) {}
    2929   
     
    3535   
    3636};
    37    
    38    
    3937
    4038class ParabixCharacterClassKernelBuilder: public pablo::PabloKernel {
    4139public:
    42     ParabixCharacterClassKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string ccSetName, std::vector<re::CC *> charClasses, unsigned basisBitsCount) :
    43         PabloKernel(iBuilder, ccSetName +"_kernel", cc::ParabixCharacterClassFunction(ccSetName, charClasses, basisBitsCount)) {}
    44    
     40    ParabixCharacterClassKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string ccSetName, const std::vector<re::CC *> & charClasses, unsigned basisBitsCount);
    4541};
    46  
    4742
    4843}
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5202 r5217  
    5353    auto savePoint = iBuilder->saveIP();
    5454    Module * m = iBuilder->getModule();
    55    
     55
    5656    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    57    
     57
    5858    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    59    
     59
    6060    Value * self = getParameter(doBlockFunction, "self");
     61
    6162    Value * blockNo = getScalarField(self, blockNoScalar);
    62     Value * inputStreamBlock = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
    63     Value * outputStreamBlock = getStreamSetBlockPtr(self, "outputStreamSet", blockNo);
    64     Value * delCountBlock = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    6563
    66     Value * del_mask = iBuilder->CreateBlockAlignedLoad(inputStreamBlock, {iBuilder->getInt32(0), iBuilder->getInt32(mStreamCount)});
    67    
    68     std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, del_mask);
    69    
     64    Value * inputStreamPtr = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
     65
     66    Value * delMaskPtr = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
     67
     68    Value * outputStreamPtr = getStreamSetBlockPtr(self, "outputStreamSet", blockNo);
     69
     70    Value * delCountPtr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
     71
     72    Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     73
     74    std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, delMask);
     75
    7076    for (unsigned j = 0; j < mStreamCount; ++j) {
    71         Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamBlock, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    72         Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, del_mask, move_masks, input);
    73         iBuilder->CreateBlockAlignedStore(output, outputStreamBlock, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     77        Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     78        Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, delMask, move_masks, input);
     79        iBuilder->CreateBlockAlignedStore(output, outputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    7480    }
    75     Value * counts = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(del_mask));
    76     iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(counts), delCountBlock, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     81    Value * counts = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
     82    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(counts), delCountPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    7783    /* Stream deletion has only been applied within fields; the actual number of data items
    7884     * has not yet changed.   */
    7985    Value * produced = getProducedItemCount(self);
    8086    produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
    81     setProducedItemCount(self, produced);   
     87    setProducedItemCount(self, produced);
    8288    iBuilder->CreateRetVoid();
    8389    iBuilder->restoreIP(savePoint);
     
    8793    auto savePoint = iBuilder->saveIP();
    8894    Module * m = iBuilder->getModule();
    89    
     95
    9096    unsigned blockSize = iBuilder->getBitBlockWidth();
    9197    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     
    96102    Value * self = getParameter(finalBlockFunction, "self");
    97103    Value * blockNo = getScalarField(self, blockNoScalar);
    98     Value * inputStreamBlock = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
     104    Value * delMaskBlock = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
    99105    Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(blockSize));
    100106    Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(blockSize)), remaining));
    101     Value * const delmaskPtr = iBuilder->CreateGEP(inputStreamBlock, {iBuilder->getInt32(0), iBuilder->getInt32(16)});
     107    Value * const delmaskPtr = iBuilder->CreateGEP(delMaskBlock, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    102108    Value * const delmaskVal = iBuilder->CreateBlockAlignedLoad(delmaskPtr);
    103109    iBuilder->CreateBlockAlignedStore(iBuilder->CreateOr(EOF_del, delmaskVal), delmaskPtr);
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5202 r5217  
    4141    DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
    4242    KernelBuilder(iBuilder, "del",
    43                   {Binding{StreamSetType(iBuilder,streamCount + 2, 1), "inputStreamSet"}},
    44                   {Binding{StreamSetType(iBuilder,streamCount, 1), "outputStreamSet"},
    45                    Binding{StreamSetType(iBuilder,1, 1), "deletionCounts"}},
     43                  {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
     44                   Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     45                  {Binding{iBuilder->getStreamSetTy(streamCount), "outputStreamSet"},
     46                   Binding{iBuilder->getStreamSetTy(), "deletionCounts"}},
    4647                  {}, {}, {}),
    4748    mDeletionFieldWidth(fw),
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5202 r5217  
    141141        throw std::runtime_error("Cannot find " + fnName);
    142142    }
    143     std::vector<Value *> args = {self, blksToDo};
    144     return iBuilder->CreateCall(method, args);
     143    return iBuilder->CreateCall(method, {self, blksToDo});
    145144}
    146145
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5203 r5217  
    4141        out << "kernel contains " << mStreamSetInputBuffers.size() << " input buffers for "
    4242            << mStreamSetInputs.size() << " input stream sets.";
    43         llvm::report_fatal_error(out.str());
     43        throw std::runtime_error(out.str());
    4444    }
    4545    if (mStreamSetOutputs.size() != mStreamSetOutputBuffers.size()) {
     
    4848        out << "kernel contains " << mStreamSetOutputBuffers.size() << " output buffers for "
    4949            << mStreamSetOutputs.size() << " output stream sets.";
    50         llvm::report_fatal_error(out.str());
     50        throw std::runtime_error(out.str());
    5151    }
    5252    addScalar(iBuilder->getSizeTy(), blockNoScalar);
     
    187187        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetInputs[i].name);
    188188        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(ssStructPtr));
    189         endSignalPtrs.push_back(mStreamSetInputBuffers[i]->hasEndOfInputPtr(ssStructPtr));
     189        endSignalPtrs.push_back(mStreamSetInputBuffers[i]->getEndOfInputPtr(ssStructPtr));
    190190    }
    191191   
     
    453453        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(ssStructPtr));
    454454        inbufConsumerPtrs.push_back(mStreamSetInputBuffers[i]->getConsumerPosPtr(ssStructPtr));
    455         endSignalPtrs.push_back(mStreamSetInputBuffers[i]->hasEndOfInputPtr(ssStructPtr));
     455        endSignalPtrs.push_back(mStreamSetInputBuffers[i]->getEndOfInputPtr(ssStructPtr));
    456456    }
    457457    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5202 r5217  
    5656    llvm::Value * getTerminationSignal(llvm::Value * kernelInstance);
    5757   
     58    inline llvm::IntegerType * getSizeTy() {
     59        return getBuilder()->getSizeTy();
     60    }
     61
     62    inline Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
     63        return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
     64    }
    5865
    5966protected:
     
    122129    void setTerminationSignal(llvm::Value * self);
    123130
    124 
    125131protected:
    126132
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5202 r5217  
    6767}
    6868       
    69    
    70 void p2sKernel_withCompressedOutput::prepareKernel() {
    71     KernelBuilder::prepareKernel();
    72 }
    73 
    7469void p2sKernel_withCompressedOutput::generateDoBlockMethod() {
    7570    auto savePoint = iBuilder->saveIP();
     
    109104    iBuilder->restoreIP(savePoint);
    110105}
    111    
    112    
     106
    113107void p2s_16Kernel::generateDoBlockMethod() {
    114108    auto savePoint = iBuilder->saveIP();
     
    140134        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    141135        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    142         iBuilder->CreateBlockAlignedStore(merge0, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(2*j)});
    143         iBuilder->CreateBlockAlignedStore(merge1, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(2*j+1)});
    144     }
    145     iBuilder->CreateRetVoid();
    146     iBuilder->restoreIP(savePoint);
    147 }
    148        
    149 
    150 void p2s_16Kernel_withCompressedOutput::prepareKernel() {
    151     KernelBuilder::prepareKernel();
    152 }
    153    
     136        // iBuilder->getInt32(0),
     137        iBuilder->CreateBlockAlignedStore(merge0, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2*j)});
     138        iBuilder->CreateBlockAlignedStore(merge1, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2*j+1)});
     139    }
     140    iBuilder->CreateRetVoid();
     141    iBuilder->restoreIP(savePoint);
     142}
    154143
    155144void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() {
    156145    auto savePoint = iBuilder->saveIP();
    157146    Module * m = iBuilder->getModule();
    158     Type * i32 = iBuilder->getIntNTy(32); 
    159     Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0); 
    160 
    161     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    162    
     147    Type * i32 = iBuilder->getIntNTy(32);
     148    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
     149
     150    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     151
    163152    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    164153    Constant * stride = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
     
    170159    Value * i16UnitsGenerated = getProducedItemCount(self); // units generated to buffer
    171160    Value * i16BlockNo = iBuilder->CreateUDiv(i16UnitsGenerated, stride);
    172    
     161
    173162    Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBlockPtr(self, "i16Stream", i16BlockNo), PointerType::get(iBuilder->getInt16Ty(), 0));
    174    
     163
    175164    Value * u16_output_ptr = iBuilder->CreateGEP(i16StreamBase_ptr, iBuilder->CreateURem(i16UnitsGenerated, stride));
    176165
    177    
     166
    178167    Value * hi_input[8];
    179168    for (unsigned j = 0; j < 8; ++j) {
     
    182171    Value * hi_bytes[8];
    183172    p2s(iBuilder, hi_input, hi_bytes);
    184    
     173
    185174    Value * lo_input[8];
    186175    for (unsigned j = 0; j < 8; ++j) {
     
    189178    Value * lo_bytes[8];
    190179    p2s(iBuilder, lo_input, lo_bytes);
    191    
    192     unsigned UTF_16_units_per_register = iBuilder->getBitBlockWidth()/16;
    193    
     180
     181    const auto UTF_16_units_per_register = iBuilder->getBitBlockWidth() / 16;
     182
    194183    Value * unit_counts = iBuilder->fwCast(UTF_16_units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    195    
     184
    196185    Value * offset = ConstantInt::get(i32, 0);
    197    
     186
    198187    for (unsigned j = 0; j < 8; ++j) {
    199188        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    200189        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    201         //iBuilder->CallPrintRegister("merge0", merge0);
    202190        iBuilder->CreateAlignedStore(merge0, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    203191        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j)), i32);
    204         //iBuilder->CallPrintInt("offset", offset);
    205192        iBuilder->CreateAlignedStore(merge1, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    206         //iBuilder->CallPrintRegister("merge1", merge1);
    207193        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j+1)), i32);
    208         //iBuilder->CallPrintInt("offset", offset);
    209     }
    210    
     194    }
     195
    211196    i16UnitsGenerated = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    212197    setProducedItemCount(self, i16UnitsGenerated);
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5202 r5217  
    2121    p2sKernel(IDISA::IDISA_Builder * iBuilder) :
    2222    KernelBuilder(iBuilder, "p2s",
    23                   {Binding{StreamSetType(iBuilder,8, 1), "basisBits"}},
    24                   {Binding{StreamSetType(iBuilder,1, 8), "byteStream"}},
     23                  {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
     24                  {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
    2525                  {}, {}, {}) {}
    2626   
     
    3434    p2sKernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    3535    KernelBuilder(iBuilder, "p2s_compress",
    36                   {Binding{StreamSetType(iBuilder,8, 1), "basisBits"}, Binding{StreamSetType(iBuilder,1, 1), "deletionCounts"}},
    37                   {Binding{StreamSetType(iBuilder,1, 8), "byteStream"}},
     36                  {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
     37                  {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
    3838                  {}, {}, {}) {}
    3939   
    4040private:
    41     void prepareKernel() override;
    4241    void generateDoBlockMethod() override;
    4342};
     
    4847    p2s_16Kernel(IDISA::IDISA_Builder * iBuilder) :
    4948    KernelBuilder(iBuilder, "p2s_16",
    50                   {Binding{StreamSetType(iBuilder,16, 1), "basisBits"}},
    51                   {Binding{StreamSetType(iBuilder,1, 16), "i16Stream"}},
     49                  {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}},
     50                  {Binding{iBuilder->getStreamSetTy(1, 16), "i16Stream"}},
    5251                  {}, {}, {}) {}
    5352   
     
    6261    p2s_16Kernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    6362    KernelBuilder(iBuilder, "p2s_16_compress",
    64                   {Binding{StreamSetType(iBuilder,16, 1), "basisBits"}, Binding{StreamSetType(iBuilder,1, 1), "deletionCounts"}},
    65                   {Binding{StreamSetType(iBuilder,1, 16), "i16Stream"}},
     63                  {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
     64                  {Binding{iBuilder->getStreamSetTy(1, 16), "i16Stream"}},
    6665                  {},
    6766                  {},
     
    6968       
    7069private:
    71     void prepareKernel() override;
    7270    void generateDoBlockMethod() override;
    7371    void generateFinalBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5202 r5217  
    211211        kernels[i]->createDoSegmentCall(instances[i], segBlocks);
    212212    }
    213     Value * endSignal = kernels[kernels.size()-1]->getTerminationSignal(instances[kernels.size()-1]);
     213    Value * endSignal = kernels.back()->getTerminationSignal(instances.back());
    214214    iBuilder->CreateCondBr(endSignal, exitBlock, segmentBlock);
    215215    iBuilder->SetInsertPoint(exitBlock);
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5202 r5217  
    162162   
    163163void s2pKernel::generateDoBlockLogic(Value * self, Value * blockNo) {
    164     Value * byteStream = getStreamSetBlockPtr(self, "byteStream", blockNo);
     164
     165    Value * bytePtr = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), 8));
     166    Value * byteStream = getStreamSetBlockPtr(self, "byteStream", bytePtr);
    165167    Value * basisBits = getStreamSetBlockPtr(self, "basisBits", blockNo);
    166168
    167169    Value * bytepack[8];
    168170    for (unsigned i = 0; i < 8; i++) {
    169         bytepack[i] = iBuilder->CreateBlockAlignedLoad(byteStream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     171        Value * ptr = iBuilder->CreateGEP(byteStream, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     172        bytepack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    170173    }
    171174    Value * bitblock[8];
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5202 r5217  
    2727    s2pKernel(IDISA::IDISA_Builder * iBuilder) :
    2828    KernelBuilder(iBuilder, "s2p",
    29                   {Binding{parabix::StreamSetType(iBuilder,1, 8), "byteStream"}},
    30                   {Binding{parabix::StreamSetType(iBuilder,8, 1), "basisBits"}},
     29                  {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
     30                  {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
    3131                  {}, {}, {}) {}
    3232   
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5206 r5217  
    119119    recordNum_input_parm->setName("lineNum");
    120120   
    121     Constant * matchProcessor;
     121    Constant * matchProcessor = nullptr;
    122122    switch (mGrepType) {
    123123        case GrepType::Normal:
     
    130130            matchProcessor = m->getOrInsertFunction("insert_property_values", Type::getVoidTy(ctxt), T, T, T, S, nullptr);
    131131            break;
    132 
     132        default: llvm_unreachable("unknown grep type");
    133133    }
    134134    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", function,0));
     
    213213            iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, fileBuf}));
    214214            break;
     215        default: llvm_unreachable("unknown grep type");
    215216    }
    216217   
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5206 r5217  
    2222    ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, GrepType grepType) :
    2323    KernelBuilder(iBuilder, "scanMatch",
    24                   {Binding{parabix::StreamSetType(iBuilder,2, 1), "matchResults"}},
     24                  {Binding{iBuilder->getStreamSetTy(2, 1), "matchResults"}},
    2525                    {},
    2626                    {Binding{iBuilder->getInt8PtrTy(), "FileBuf"}, Binding{iBuilder->getSizeTy(), "FileSize"}, Binding{iBuilder->getSizeTy(), "FileIdx"}},
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5204 r5217  
    7373    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    7474    Value * bytePtr = iBuilder->CreateGEP(iBuilder->CreateBitCast(basePtr, i8PtrTy), byteOffset);
    75 //#undef NDEBUG
    76 #ifndef NDEBUG
    77     iBuilder->CallPrintInt(mKernelName + "_segmentNo", segmentNo);
    78     iBuilder->CallPrintInt(mKernelName + "_itemsAvail", itemsAvail);
    79     iBuilder->CallPrintInt(mKernelName + "_itemsToDo", itemsToDo);
    80 #endif
     75
    8176    iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes)}));
    8277   
     
    8681    mStreamSetInputBuffers[0]->setConsumerPos(streamStructPtr, processed);
    8782
    88     Value * endSignal = iBuilder->CreateLoad(mStreamSetInputBuffers[0]->hasEndOfInputPtr(streamStructPtr));
     83    Value * endSignal = iBuilder->CreateLoad(mStreamSetInputBuffers[0]->getEndOfInputPtr(streamStructPtr));
    8984    Value * inFinalSegment = iBuilder->CreateAnd(endSignal, lessThanFullSegment);
    9085   
    9186    iBuilder->CreateCondBr(inFinalSegment, setTermination, stdOutexit);
    9287    iBuilder->SetInsertPoint(setTermination);
    93 #ifndef NDEBUG
    94     iBuilder->CallPrintInt(mKernelName + " termination in segment ", segmentNo);
    95 #endif
     88
    9689    setTerminationSignal(self);
    9790
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5202 r5217  
    1818    stdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth) :
    1919    KernelBuilder(iBuilder, "stdout",
    20                   {Binding{parabix::StreamSetType(iBuilder, 1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {}),
     20                  {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {}),
    2121    mCodeUnitWidth(codeUnitWidth) {}
    2222   
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5204 r5217  
    1414enum SS_struct_index {iProducer_pos = 0, iConsumer_pos = 1, iEnd_of_input = 2, iBuffer_ptr = 3};
    1515
    16 llvm::PointerType * StreamSetBuffer::getStreamBufferPointerType() {
    17     return PointerType::get(mStreamSetType, mAddrSpace);
    18 }
    19 
    20 llvm::PointerType * StreamSetBuffer::getStreamSetStructPointerType() {
    21     return PointerType::get(mStreamSetStructType, 0);
    22 }
    23 
    2416llvm::Value * StreamSetBuffer::getProducerPosPtr(Value * bufferStructPtr) {
    2517    return iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)});
    2618}
    2719
    28 void StreamSetBuffer::setProducerPos(Value * bufferStructPtr, llvm::Value * pos){
    29     iBuilder->CreateStore(pos, iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     20void StreamSetBuffer::setProducerPos(Value * bufferStructPtr, llvm::Value * pos) {
     21    iBuilder->CreateStore(pos, getProducerPosPtr(bufferStructPtr));
    3022}
    3123
     
    3426}
    3527
    36 void StreamSetBuffer::setConsumerPos(Value * bufferStructPtr, Value * pos){
    37     iBuilder->CreateStore(pos, iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     28void StreamSetBuffer::setConsumerPos(Value * bufferStructPtr, Value * pos) {
     29    iBuilder->CreateStore(pos, getConsumerPosPtr(bufferStructPtr));
    3830}
    3931
    40 llvm::Value * StreamSetBuffer::hasEndOfInputPtr(Value * bufferStructPtr) {
     32llvm::Value * StreamSetBuffer::getEndOfInputPtr(Value * bufferStructPtr) {
    4133    return iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)});
    4234}
    4335
    44 void StreamSetBuffer::setEndOfInput(Value * bufferStructPtr){
    45     iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     36void StreamSetBuffer::setEndOfInput(Value * bufferStructPtr) {
     37    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), getEndOfInputPtr(bufferStructPtr));
    4638}
    4739
    48 llvm::Value * StreamSetBuffer::getStreamSetStructPtr(){
    49     return mStreamSetStructPtr;
    50 }
    51 
    52 llvm::Value * StreamSetBuffer::allocateBuffer() {
     40void StreamSetBuffer::allocateBuffer() {
    5341    Type * const size_ty = iBuilder->getSizeTy();
    5442    Type * const int1ty = iBuilder->getInt1Ty();
    5543    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetType, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
    5644    mStreamSetStructPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetStructType);
    57 
    5845    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    5946    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
    6047    iBuilder->CreateStore(ConstantInt::get(int1ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
    6148    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
    62    
    63     return mStreamSetBufferPtr;
    64 }
    65 
    66 llvm::Value * StreamSetBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
    67     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    68     return iBuilder->CreateGEP(iBuilder->CreateLoad(handle), {blockNo});
    6949}
    7050
    7151// Single Block Buffer
    7252// For a single block buffer, the block pointer is always the buffer base pointer.
    73 llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
     53llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value *) {
    7454    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    7555    return iBuilder->CreateLoad(handle);
     
    10989}
    11090
    111 llvm::Value * ExternalFileBuffer::allocateBuffer() {
     91void ExternalFileBuffer::allocateBuffer() {
    11292    throw std::runtime_error("External buffers cannot be allocated.");
    11393}
     
    11595llvm::Value * ExternalFileBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
    11696    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    117     return iBuilder->CreateGEP(iBuilder->CreateLoad(handle), {blockNo});
     97    Value * bufPtr = iBuilder->CreateLoad(handle);
     98    return iBuilder->CreateGEP(bufPtr, blockNo);
    11899}
    119100
     
    121102
    122103llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
     104    assert (blockNo->getType()->isIntegerTy());
     105
    123106    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    124     // Circular access is based on blockNo mod mBufferBlocks.  For power of 2 buffer sizes (required), we
    125     // use bitwise masking to efficiently compute the mod function  (blockNo & (mBufferBlocks - 1)
    126107    Value * bufPtr = iBuilder->CreateLoad(handle);
    127     //iBuilder->CallPrintInt("CircularBuffer bufPtr", iBuilder->CreatePtrToInt(bufPtr, iBuilder->getSizeTy()));
    128     return iBuilder->CreateGEP(bufPtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
     108    Value * offset = nullptr;
     109    if (mBufferBlocks == 1) {
     110        offset = ConstantInt::getNullValue(iBuilder->getSizeTy());
     111    } else if ((mBufferBlocks & (mBufferBlocks - 1)) == 0) { // is power of 2
     112        offset = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks - 1));
     113    } else {
     114        offset = iBuilder->CreateURem(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks));
     115    }
     116    return iBuilder->CreateGEP(bufPtr, offset);
    129117}
    130118
     
    136124    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    137125    Value * bufPtr = iBuilder->CreateLoad(handle);
    138     //iBuilder->CallPrintInt("LinearBuffer bufPtr", iBuilder->CreatePtrToInt(bufPtr, iBuilder->getSizeTy()));
    139126    return iBuilder->CreateGEP(bufPtr, {iBuilder->CreateSub(blockNo, consumerBlock)});
    140127}
     
    144131    Type * const i8 = iBuilder->getInt8Ty();
    145132    Type * const i32 = iBuilder->getInt32Ty();
    146     Type * const i8_ptr = PointerType::get(i8, mAddrSpace);
     133    Type * const i8_ptr = i8->getPointerTo(mAddrSpace);
     134    IntegerType * const sizeTy = iBuilder->getSizeTy();
    147135
     136    Module * const M = iBuilder->getModule();
    148137
    149     Module * M = iBuilder->getModule();
     138    Function * const memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeTy->getBitWidth()),
     139                                                                  iBuilder->getVoidTy(), i8_ptr, i8_ptr, sizeTy, i32, i1, nullptr));
     140    Function * const current = iBuilder->GetInsertBlock()->getParent();
     141    BasicBlock * const copyBackBody = BasicBlock::Create(M->getContext(), "copy_back", current, 0);
     142    BasicBlock * const setConsumerPosExit = BasicBlock::Create(M->getContext(), "setConsumerPos_done", current, 0);
     143    Constant * const blockWidth = ConstantInt::get(sizeTy, iBuilder->getStride());
    150144
    151     IntegerType * sizeTy = iBuilder->getSizeTy();
     145    Constant * const one = ConstantInt::get(sizeTy, 1);
    152146
    153     Function * memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeTy->getBitWidth()),
    154                                                                   iBuilder->getVoidTy(), i8_ptr, i8_ptr, sizeTy, i32, i1, nullptr));
    155     Function * current = iBuilder->GetInsertBlock()->getParent();
    156     BasicBlock * copyBackBody = BasicBlock::Create(M->getContext(), "copy_back", current, 0);
    157     BasicBlock * setConsumerPosExit = BasicBlock::Create(M->getContext(), "setConsumerPos_done", current, 0);
    158     Constant * blockWidth = ConstantInt::get(sizeTy, iBuilder->getStride());
    159     Constant * one = ConstantInt::get(sizeTy, 1);
    160     Value * consumerPos_ptr = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
    161     Value * consumerPos = iBuilder->CreateLoad(consumerPos_ptr);
    162     Value * consumerBlock = iBuilder->CreateUDiv(consumerPos, blockWidth);
     147    Value * const consumerPosPtr = getConsumerPosPtr(bufferStructPtr);
     148    Value * const consumerPos = iBuilder->CreateLoad(consumerPosPtr);
     149
    163150    // Ensure that the new consumer position is no less than the current position.
    164151    new_consumer_pos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(new_consumer_pos, consumerPos), consumerPos, new_consumer_pos);
    165152    Value * producerPos = iBuilder->CreateLoad(iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     153
    166154    // Ensure that the new consumer position is no greater than the current producer position.
    167155    Value * new_pos_lt_producer_pos = iBuilder->CreateICmpULT(new_consumer_pos, producerPos);
    168156    new_consumer_pos = iBuilder->CreateSelect(new_pos_lt_producer_pos, new_consumer_pos, producerPos);
     157
    169158    // Now, the new_consumer_pos is at most = to the producer_pos; if =, we're done.
    170159    iBuilder->CreateCondBr(new_pos_lt_producer_pos, copyBackBody, setConsumerPosExit);
     
    172161   
    173162    Value * new_consumer_block = iBuilder->CreateUDiv(new_consumer_pos, blockWidth);
    174    
    175163    Value * lastProducerBlock = iBuilder->CreateUDiv(iBuilder->CreateSub(producerPos, one), blockWidth);
    176     //iBuilder->CallPrintInt("new_consumer_block", new_consumer_block);
    177     //iBuilder->CallPrintInt("lastProducerBlock", lastProducerBlock);
    178 
    179164    Value * copyBlocks = iBuilder->CreateAdd(iBuilder->CreateSub(lastProducerBlock, new_consumer_block), one);
    180165
     
    182167
    183168    Constant * blockBytes = ConstantInt::get(sizeTy, dl.getTypeAllocSize(mStreamSetType) * iBuilder->getStride());
     169
    184170    Value * copyLength = iBuilder->CreateMul(copyBlocks, blockBytes);
    185     //iBuilder->CallPrintInt("memmove copyLength", copyLength);
     171
    186172    // Must copy back one full block for each of the streams in the stream set.
    187173    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    188174    Value * bufferPtr = iBuilder->CreateLoad(handle);
    189     //iBuilder->CallPrintInt("memmove bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, sizeTy));
    190 
     175    Value * const consumerBlock = iBuilder->CreateUDiv(consumerPos, blockWidth);
    191176    Value * copyFrom = iBuilder->CreateGEP(bufferPtr, {iBuilder->CreateSub(new_consumer_block, consumerBlock)});
    192     //iBuilder->CallPrintInt("memmove copyFrom", iBuilder->CreatePtrToInt(copyFrom, sizeTy));
    193     Value * alignment = ConstantInt::get(iBuilder->getInt32Ty(), iBuilder->getBitBlockWidth()/8);
     177    Value * alignment = ConstantInt::get(iBuilder->getInt32Ty(), iBuilder->getBitBlockWidth() / 8);
    194178   
    195179    iBuilder->CreateCall(memmoveFunc, {iBuilder->CreateBitCast(bufferPtr, i8_ptr), iBuilder->CreateBitCast(copyFrom, i8_ptr), copyLength, alignment, ConstantInt::getNullValue(i1)});
     
    197181    // Copy back done, store the new consumer position.
    198182    iBuilder->SetInsertPoint(setConsumerPosExit);
    199     iBuilder->CreateStore(new_consumer_pos, consumerPos_ptr);
     183
     184    iBuilder->CreateStore(new_consumer_pos, consumerPosPtr);
    200185}   
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5202 r5217  
    1616enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
    1717
    18 inline llvm::Type * StreamSetType(IDISA::IDISA_Builder * iBuilder, const unsigned count, const unsigned width) {
    19     llvm::Type * streamType = ((width == 1) ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), width));
    20     return ArrayType::get(streamType, count);
    21 }
    22 
    23 // Stream Set Structs hold information about the current state
    24 // of a stream set buffer.
     18// Stream Set Structs hold information about the current state of a stream set buffer.
    2519
    2620llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    2721llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    28 llvm::Value * hasEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     22llvm::Value * getEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    2923llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    3024
     
    3428    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer};
    3529
    36     inline BufferKind getBufferKind() const {return mBufferKind;}
     30    inline BufferKind getBufferKind() const {
     31        return mBufferKind;
     32    }
    3733
    38     inline llvm::Type * getBufferStreamSetType() {return mStreamSetType;}
     34    inline llvm::Type * getBufferStreamSetType() const {
     35        return mStreamSetType;
     36    }
    3937
    40     llvm::PointerType * getStreamBufferPointerType();
     38    llvm::PointerType * getStreamBufferPointerType() const {
     39        return mStreamSetType->getPointerTo(mAddrSpace);
     40    }
    4141
    42     size_t getBufferSize() { return mBufferBlocks;}
     42    llvm::PointerType * getStreamSetStructPointerType() const {
     43        return mStreamSetStructType->getPointerTo();
     44    }
     45
     46    size_t getBufferSize() const { return mBufferBlocks; }
     47       
     48    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
    4349   
    44     virtual llvm::Value * allocateBuffer();
    45    
    46     llvm::Value * getStreamSetBasePtr() {return mStreamSetBufferPtr;}
    47    
     50    llvm::Value * getStreamSetStructPtr() const { return mStreamSetStructPtr; }
     51
     52    virtual void allocateBuffer();
     53
    4854    // Get the buffer pointer for a given block of the stream.
    4955    virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) = 0;
     
    5763    virtual void setConsumerPos(Value * bufferStructPtr, Value * pos);
    5864
    59     llvm::Value * hasEndOfInputPtr(Value * bufferStructPtr);
     65    llvm::Value * getEndOfInputPtr(Value * bufferStructPtr);
    6066
    6167    void setEndOfInput(Value * bufferStructPtr);
    6268   
    63     llvm::Value * getStreamSetBufferPtrPtr(Value * bufferStructPtr);
     69protected:
     70    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace = 0)
     71    : mBufferKind(k)
     72    , iBuilder(b)
     73    , mStreamSetType(isa<IDISA::StreamType>(type) ? cast<IDISA::StreamType>(type)->resolveType(b) : type)
     74    , mBufferBlocks(blocks)
     75    , mAddrSpace(AddressSpace)
     76    , mStreamSetBufferPtr(nullptr)
     77    , mStreamSetStructPtr(nullptr)
     78    , mStreamSetStructType(StructType::get(b->getContext(),
     79                            {{b->getSizeTy(),
     80                              b->getSizeTy(),
     81                              b->getInt1Ty(),
     82                              PointerType::get(mStreamSetType, AddressSpace)}})) {
    6483
    65     virtual llvm::PointerType * getStreamSetStructPointerType();
    66 
    67     virtual llvm::Value * getStreamSetStructPtr();
    68    
    69 protected:
    70     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace = 0) :
    71         mBufferKind(k), iBuilder(b), mStreamSetType(type), mBufferBlocks(blocks), mAddrSpace(AddressSpace), mStreamSetBufferPtr(nullptr) {
    72             mStreamSetStructType =
    73                 StructType::get(iBuilder->getContext(),
    74                                 std::vector<Type *>({iBuilder->getSizeTy(),
    75                                                     iBuilder->getSizeTy(),
    76                                                     iBuilder->getInt1Ty(),
    77                                                     PointerType::get(type, AddressSpace)}));
    7884    }
    7985protected:
    8086    const BufferKind        mBufferKind;
    8187    IDISA::IDISA_Builder *  iBuilder;
    82     llvm::Type *            mStreamSetType;
     88    llvm::Type * const      mStreamSetType;
    8389    size_t                  mBufferBlocks;
    8490    int                     mAddrSpace;
    8591    llvm::Value *           mStreamSetBufferPtr;
    8692    llvm::Value *           mStreamSetStructPtr;
    87     llvm::Type *            mStreamSetStructType;
     93    llvm::Type * const      mStreamSetStructType;
    8894};   
    8995
     
    115121
    116122    // Can't allocate - raise an error. */
    117     llvm::Value * allocateBuffer() override;
     123    void allocateBuffer() override;
     124
    118125    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    119 
    120126};
    121127   
     
    128134    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0)
    129135    : StreamSetBuffer(BufferKind::CircularBuffer, b, type, bufferBlocks, AddressSpace) {
    130         if (((bufferBlocks - 1) & bufferBlocks) != 0) {
    131             throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
    132         }
     136
    133137    }
    134138
  • icGREP/icgrep-devel/icgrep/kernels/symboltablepipeline.cpp

    r5106 r5217  
    1313#include <kernels/instance.h>
    1414
    15 #include <pablo/function.h>
     15#include <pablo/prototype.h>
    1616#include <pablo/pablo_compiler.h>
    1717#include <pablo/analysis/pabloverifier.hpp>
  • icGREP/icgrep-devel/icgrep/pablo/analysis/pabloverifier.cpp

    r5202 r5217  
    11#include "pabloverifier.hpp"
    2 #include <pablo/function.h>
     2#include <pablo/pablo_kernel.h>
    33#include <pablo/codegenstate.h>
    44#include <pablo/printer_pablos.h>
     
    2727            continue;
    2828        }
    29         if (LLVM_UNLIKELY(isa<PabloFunction>(use))) {
    30             const PabloFunction * f = cast<PabloFunction>(use);
    31             bool isParameter = false;
    32             bool isResult = false;
    33             for (unsigned i = 0; i != f->getNumOfParameters(); ++i) {
    34                 if (f->getParameter(i) == expr) {
    35                     isParameter = true;
    36                     break;
    37                 }
    38             }
    39             for (unsigned i = 0; i != f->getNumOfResults(); ++i) {
    40                 if (f->getResult(i) == expr) {
    41                     isResult = true;
    42                     break;
    43                 }
    44             }
    45             if (LLVM_UNLIKELY(!(isParameter ^ isResult))) {
    46                 std::string tmp;
    47                 raw_string_ostream str(tmp);
    48                 str << "use-def error: ";
    49                 PabloPrinter::print(expr, str);
    50                 if (isParameter && isResult) {
    51                     str << " is both a parameter and result of ";
    52                 } else {
    53                     str << " is neither a parameter nor result of ";
    54                 }
    55                 PabloPrinter::print(f, str);
    56                 throw std::runtime_error(str.str());
    57             }
    58             ++uses;
    59         } else if (const Statement * const user = dyn_cast<Statement>(use)) {
     29        if (const Statement * const user = dyn_cast<Statement>(use)) {
    6030            // test whether this user is in a block in the program
    6131            if (LLVM_UNLIKELY(user->getParent() == nullptr || validScopes.count(user->getParent()) == 0)) {
     
    10171            }
    10272        } else if (isa<Var>(use)) {
    103             if (LLVM_UNLIKELY(isa<Branch>(expr) || isa<PabloFunction>(expr))) {
     73            if (LLVM_UNLIKELY(isa<Branch>(expr))) {
    10474                ++uses;
    10575            } else {
     
    169139}
    170140
    171 void verifyUseDefInformation(const PabloFunction & function) {
     141void verifyUseDefInformation(const PabloKernel * kernel) {
    172142    ScopeSet validScopes;
    173     gatherValidScopes(function.getEntryBlock(), validScopes);
    174     for (unsigned i = 0; i < function.getNumOfParameters(); ++i) {
    175         if (LLVM_UNLIKELY(function.getParameter(i) == nullptr)) {
    176             throw std::runtime_error("parameter " + std::to_string(i) + " is Null!");
    177         }
    178         testUsers(function.getParameter(i), validScopes);
    179     }
    180     for (unsigned i = 0; i < function.getNumOfResults(); ++i) {
    181         if (LLVM_UNLIKELY(function.getResult(i) == nullptr)) {
    182             throw std::runtime_error("result " + std::to_string(i) + " is Null!");
    183         }
    184         testUsers(function.getResult(i), validScopes);
    185     }
    186     verifyUseDefInformation(function.getEntryBlock(), validScopes);
     143    gatherValidScopes(kernel->getEntryBlock(), validScopes);
     144    for (unsigned i = 0; i < kernel->getNumOfInputs(); ++i) {
     145        testUsers(kernel->getInput(i), validScopes);
     146    }
     147    for (unsigned i = 0; i < kernel->getNumOfOutputs(); ++i) {
     148        testUsers(kernel->getOutput(i), validScopes);
     149    }
     150    verifyUseDefInformation(kernel->getEntryBlock(), validScopes);
    187151}
    188152
     
    326290}
    327291
    328 inline void verifyProgramStructure(const PabloFunction & function) {
     292inline void verifyProgramStructure(const PabloKernel * kernel) {
    329293    unsigned nestingDepth = 0;
    330     verifyProgramStructure(function.getEntryBlock(), nestingDepth);
     294    verifyProgramStructure(kernel->getEntryBlock(), nestingDepth);
    331295    if (LLVM_UNLIKELY(nestingDepth != 0)) {
    332296        // This error isn't actually possible to occur with the current AST structure but that could change
     
    401365}
    402366
    403 void isTopologicallyOrdered(const PabloFunction & function) {
     367void isTopologicallyOrdered(const PabloKernel * kernel) {
    404368    OrderingVerifier ov;
    405     for (unsigned i = 0; i != function.getNumOfParameters(); ++i) {
    406         ov.insert(function.getParameter(i));
    407     }
    408     for (unsigned i = 0; i != function.getNumOfResults(); ++i) {
    409         ov.insert(function.getResult(i));
    410     }
    411     isTopologicallyOrdered(function.getEntryBlock(), ov);
    412 }
    413 
    414 void PabloVerifier::verify(const PabloFunction & function, const std::string location) {
     369    for (unsigned i = 0; i != kernel->getNumOfInputs(); ++i) {
     370        ov.insert(kernel->getInput(i));
     371    }
     372    for (unsigned i = 0; i != kernel->getNumOfOutputs(); ++i) {
     373        ov.insert(kernel->getOutput(i));
     374    }
     375    isTopologicallyOrdered(kernel->getEntryBlock(), ov);
     376}
     377
     378void PabloVerifier::verify(const PabloKernel * kernel, const std::string & location) {
    415379    try {
    416         verifyProgramStructure(function);
    417         verifyUseDefInformation(function);
    418         isTopologicallyOrdered(function);
     380        verifyProgramStructure(kernel);
     381        verifyUseDefInformation(kernel);
     382        isTopologicallyOrdered(kernel);
    419383    } catch(std::runtime_error & err) {
    420384        raw_os_ostream out(std::cerr);
    421         PabloPrinter::print(function, out);
     385        PabloPrinter::print(kernel, out);
    422386        out.flush();
    423387        if (location.empty()) {
  • icGREP/icgrep-devel/icgrep/pablo/analysis/pabloverifier.hpp

    r4797 r5217  
    66namespace pablo {
    77
    8 class PabloFunction;
     8class PabloKernel;
    99
    1010class PabloVerifier {
    1111public:
    12     static void verify(const PabloFunction & function, const std::string location = "");
     12    static void verify(const PabloKernel * kernel, const std::string & location = "");
    1313};
    1414
  • icGREP/icgrep-devel/icgrep/pablo/branch.cpp

    r5202 r5217  
    1818    bool outside = false;
    1919    for (const PabloAST * user : var->users()) {
    20         if (isa<Assign>(user)) {
    21             // is this var assigned a value within the scope of the branch?
     20        if (isa<Assign>(user)) {           
     21
    2222            const PabloBlock * const scope = cast<Assign>(user)->getParent();
    2323
     24            // Is this Var assigned a value within the body of this branch?
    2425            for (const PabloBlock * test = scope; test; test = test->getPredecessor()) {
    2526                if (test == br->getBody()) {
     
    2829                    }
    2930                    inside = true;
    30                     break;
     31                    goto outer_loop;
    3132                }
    3233            }
    3334
    34             for (const PabloBlock * test = br->getParent(); test; test = test->getPredecessor()) {
    35                 // technically we should check whether this user dominates the branch but if it
    36                 // doesn't, then the program is illegal anyway and the error will be found.
     35            // Is there an assignment to this Var that dominates this branch?
     36            const Branch * check = br;
     37            for (const PabloBlock * test = br->getParent(); test; ) {
    3738                if (test == scope) {
    38                     if (inside) {
    39                         return true;
     39                    // verify this assignment actually dominates the branch
     40                    const Statement * temp1 = cast<Assign>(user);
     41                    const Statement * temp2 = check;
     42                    while (temp1 && temp2) {
     43                        if (temp1 == check) {
     44                            break;
     45                        } else if (temp2 == cast<Assign>(user)) {
     46                            temp1 = nullptr;
     47                            break;
     48                        }
     49                        temp1 = temp1->getNextNode();
     50                        temp2 = temp2->getNextNode();
    4051                    }
    41                     outside = true;
     52                    if (temp1 != nullptr) {
     53                        if (inside) {
     54                            return true;
     55                        }
     56                        outside = true;
     57                    }
    4258                    break;
    4359                }
     60                check = test->getBranch();
     61                if (LLVM_UNLIKELY(check == nullptr)) {
     62                    break;
     63                }
     64                test = check->getParent();
    4465            }
    45 
    4666        }
     67outer_loop: continue;
    4768    }
    4869    return false;
     
    5475std::vector<Var *> Branch::getEscaped() const {
    5576
    56     PabloFunction * const f = getParent()->getParent();
     77    const auto f = getParent()->getParent();
    5778    const auto n = f->getNumOfVariables();
    5879
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r5202 r5217  
    9999}
    100100
     101inline void printType(const Type * type, raw_string_ostream & out) {
     102    if (auto st = dyn_cast<IDISA::StreamType>(type)) {
     103        out << "<" << st->getNumElements() << " x s" << st->getFieldWidth() << ">";
     104    } else {
     105        type->print(out);
     106    }
     107}
     108
    101109using TypeId = PabloAST::ClassTypeId;
    102110
     
    193201
    194202PabloAST * PabloBuilder::createAssign(PabloAST * const variable, PabloAST * const value) {
    195     MAKE_BINARY(createAssign, TypeId::Assign, variable, value);
    196     return result;
     203    if (variable->getType() != value->getType()) {
     204        std::string tmp;
     205        raw_string_ostream out(tmp);
     206        out << "Cannot assign ";
     207        value->print(out);
     208        out << " to ";
     209        variable->print(out);
     210        out << ": type of ";
     211        value->print(out);
     212        out << " ";
     213        printType(value->getType(), out);
     214        out << " does not match ";
     215        variable->print(out);
     216        out << " ";
     217        printType(variable->getType(), out);
     218        throw std::runtime_error(out.str());
     219    }
     220    return mPb->createAssign(variable, value);
    197221}
    198222
     
    399423}
    400424
     425PabloAST * PabloBuilder::createAdd(PabloAST * expr1, PabloAST * expr2) {
     426    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     427        return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
     428    }
     429    MAKE_BINARY(createAdd, TypeId::Add, expr1, expr2);
     430    return result;
     431}
     432
     433PabloAST * PabloBuilder::createAdd(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     434    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     435        return getInteger(cast<Integer>(expr1)->value() + cast<Integer>(expr2)->value());
     436    }
     437    MAKE_NAMED_BINARY(createAdd, TypeId::Add, prefix, expr1, expr2);
     438    return result;
     439}
     440
     441PabloAST * PabloBuilder::createSubtract(PabloAST * expr1, PabloAST * expr2) {
     442    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     443        return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
     444    }
     445    MAKE_BINARY(createSubtract, TypeId::Subtract, expr1, expr2);
     446    return result;
     447}
     448
     449PabloAST * PabloBuilder::createSubtract(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     450    if (isa<Integer>(expr1) && isa<Integer>(expr2)) {
     451        return getInteger(cast<Integer>(expr1)->value() - cast<Integer>(expr2)->value());
     452    }
     453    MAKE_NAMED_BINARY(createSubtract, TypeId::Subtract, prefix, expr1, expr2);
     454    return result;
     455}
     456
    401457PabloAST * PabloBuilder::createInFile(PabloAST * expr) {
    402458    MAKE_UNARY(createInFile, TypeId::InFile, expr);
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5202 r5217  
    8181    Extract * createExtract(PabloAST * value, not_null<PabloAST *> index);
    8282
    83     inline Extract * createExtract(PabloAST * value, const Integer::Type index) {
     83    inline Extract * createExtract(PabloAST * value, const int64_t index) {
    8484        return createExtract(value, getInteger(index));
    8585    }
     
    8787    Extract * createExtract(PabloAST * value, not_null<PabloAST *> index, const std::string & prefix);
    8888
    89     inline Extract * createExtract(PabloAST * value, const Integer::Type index, const std::string & prefix) {
     89    inline Extract * createExtract(PabloAST * value, const int64_t index, const std::string & prefix) {
    9090        return createExtract(value, getInteger(index), prefix);
    9191    }
     
    9797    Call * createCall(Prototype * prototype, const std::vector<PabloAST *> &vars);
    9898
    99     inline PabloAST * createAdvance(PabloAST * expr, const Integer::Type shiftAmount) {
     99    inline PabloAST * createAdvance(PabloAST * expr, const int64_t shiftAmount) {
    100100        return createAdvance(expr, mPb->getInteger(shiftAmount));
    101101    }
     
    103103    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount);
    104104
    105     inline PabloAST * createAdvance(PabloAST * expr, const Integer::Type shiftAmount, const std::string & prefix) {
     105    inline PabloAST * createAdvance(PabloAST * expr, const int64_t shiftAmount, const std::string & prefix) {
    106106        return createAdvance(expr, mPb->getInteger(shiftAmount), prefix);
    107107    }
     
    109109    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount, const std::string & prefix);
    110110
    111     inline PabloAST * createLookahead(PabloAST * expr, const Integer::Type shiftAmount) {
     111    inline PabloAST * createLookahead(PabloAST * expr, const int64_t shiftAmount) {
    112112        if (shiftAmount == 0) {
    113113            return expr;
     
    118118    PabloAST * createLookahead(PabloAST * expr, PabloAST * shiftAmount);
    119119
    120     inline PabloAST * createLookahead(PabloAST * expr, const Integer::Type shiftAmount, const std::string & prefix) {
     120    inline PabloAST * createLookahead(PabloAST * expr, const int64_t shiftAmount, const std::string & prefix) {
    121121        if (shiftAmount == 0) {
    122122            return expr;
     
    169169    PabloAST * createAtEOF(PabloAST * expr, const std::string & prefix);
    170170   
     171    PabloAST * createAdd(PabloAST * expr1, PabloAST * expr2);
     172
     173    PabloAST * createAdd(PabloAST * expr1, PabloAST * expr2, const std::string & prefix);
     174
     175    PabloAST * createSubtract(PabloAST * expr1, PabloAST * expr2);
     176
     177    PabloAST * createSubtract(PabloAST * expr1, PabloAST * expr2, const std::string & prefix);
     178
    171179    inline If * createIf(PabloAST * condition, PabloBlock * body) {
    172180        return mPb->createIf(condition, body);
     
    231239    }
    232240
    233     inline String * getName(const std::string name) const {
     241    inline String * getName(const std::string & name) const {
    234242        return mPb->getName(name);
    235243    }
     
    239247    }
    240248
    241     inline Integer * getInteger(Integer::Type value) const {
     249    inline Integer * getInteger(const uint64_t value) const {
    242250        return mPb->getInteger(value);
    243     }
    244 
    245     inline SymbolGenerator * getSymbolTable() const {
    246         return mPb->getSymbolTable();
    247251    }
    248252
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5202 r5217  
    2222 * @brief initializeCarryData
    2323 ** ------------------------------------------------------------------------------------------------------------- */
    24 Type * CarryManager::initializeCarryData(PabloFunction * const function) {
    25     mRootScope = function->getEntryBlock();
     24Type * CarryManager::initializeCarryData(PabloKernel * const kernel) {
     25    mRootScope = kernel->getEntryBlock();
    2626    mCarryInfoVector.resize(mRootScope->enumerateScopes(0) + 1);
    2727    mCarryPackType = mBitBlockType;
     
    4040 * @brief initializeCodeGen
    4141 ** ------------------------------------------------------------------------------------------------------------- */
    42 void CarryManager::initializeCodeGen(PabloKernel * const kBuilder, Value * selfPtr) {
    43     mKernelBuilder = kBuilder;
     42void CarryManager::initializeCodeGen(PabloKernel * const kernel, Value * selfPtr) {
     43    mKernelBuilder = kernel;
    4444    mSelf = selfPtr;
    4545   
     
    399399    Type * summaryTy = summary->getType();
    400400    Type * valueTy = value->getType();
     401
    401402    if (LLVM_UNLIKELY(isa<Constant>(value))) {
    402403        if (LLVM_LIKELY(cast<Constant>(value)->isZeroValue())) return;
     
    406407        }
    407408    }
     409
    408410    Value * v = value;
    409411    if (valueTy != summaryTy) {
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5115 r5217  
    5959    ~CarryManager();
    6060   
    61     Type * initializeCarryData(PabloFunction * const function);
    62     void initializeCodeGen(PabloKernel * const kBuilder, Value * selfPtr);
     61    Type * initializeCarryData(PabloKernel * const kernel);
     62    void initializeCodeGen(PabloKernel * const kernel, Value * selfPtr);
    6363
    6464    void reset();
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5202 r5217  
    66
    77#include <pablo/codegenstate.h>
    8 #include <pablo/printer_pablos.h>
     8
     9#define CHECK_SAME_TYPE(A, B) \
     10    assert ("DIFFERING CONTEXTS" && (&((A)->getType()->getContext()) == &((B)->getType()->getContext()))); \
     11    assert ("DIFFERING TYPES" && ((A)->getType() == (B)->getType()))
     12
     13using StreamType = IDISA::StreamType;
    914
    1015namespace pablo {
     
    1924
    2025Count * PabloBlock::createCount(PabloAST * expr) {
    21     return insertAtInsertionPoint(new Count(expr, makeName("count")));
     26    Type * type = getParent()->getBuilder()->getSizeTy();
     27    return insertAtInsertionPoint(new Count(expr, makeName("count"), type));
    2228}
    2329
    2430Count * PabloBlock::createCount(PabloAST * const expr, const std::string & prefix)  {
    25     return insertAtInsertionPoint(new Count(expr, makeName(prefix)));
     31    Type * type = getParent()->getBuilder()->getSizeTy();
     32    return insertAtInsertionPoint(new Count(expr, makeName(prefix), type));
    2633}
    2734
     
    3643Var * PabloBlock::createVar(PabloAST * name, Type * type) {
    3744    if (type == nullptr) {
    38         type = getStreamTy();
     45        type = getParent()->getStreamSetTy();
    3946    }
    4047    if (LLVM_UNLIKELY(name == nullptr || !isa<String>(name))) {
     
    7986Extract * PabloBlock::createExtract(PabloAST * array, PabloAST * index, String * name) {
    8087    assert (array && index);
    81     if (LLVM_LIKELY(isa<ArrayType>(array->getType()))) {
    82         if (name == nullptr) {
    83             std::string tmp;
    84             raw_string_ostream out(tmp);
    85             PabloPrinter::print(array, out);
    86             PabloPrinter::print(index, out);
    87             name = makeName(out.str());
    88         }
    89         return insertAtInsertionPoint(new Extract(array, index, name));
     88    if (name == nullptr) {
     89        std::string tmp;
     90        raw_string_ostream out(tmp);
     91        array->print(out);
     92        out << '[';
     93        index->print(out);
     94        out << ']';
     95        name = makeName(out.str());
     96    }
     97    llvm::Type * const type = array->getType();
     98    if (LLVM_LIKELY(isa<StreamType>(type))) {
     99        Type * elementType = cast<StreamType>(type)->getStreamElementType();
     100        return insertAtInsertionPoint(new Extract(array, index, name, elementType));
     101    }
     102    if (LLVM_LIKELY(isa<ArrayType>(type))) {
     103        Type * elementType = cast<ArrayType>(type)->getArrayElementType();
     104        return insertAtInsertionPoint(new Extract(array, index, name, elementType));
    90105    }
    91106    std::string tmp;
     
    93108    out << "cannot extract element from ";
    94109    array->print(out);
    95     out << ": type is not a valid ArrayType";
     110    out << " : not a StreamType or ArrayType";
    96111    throw std::runtime_error(out.str());
    97112}
    98113
    99114And * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2, String * name) {
     115    CHECK_SAME_TYPE(expr1, expr2);
    100116    if (name == nullptr) {
    101117        name = makeName("and");
     
    112128
    113129Or * PabloBlock::createOr(PabloAST * expr1, PabloAST * expr2, String * name) {
     130    CHECK_SAME_TYPE(expr1, expr2);
    114131    if (name == nullptr) {
    115132        name = makeName("or");
     
    126143
    127144Xor * PabloBlock::createXor(PabloAST * expr1, PabloAST * expr2, String * name) {
     145    CHECK_SAME_TYPE(expr1, expr2);
    128146    if (name == nullptr) {
    129147        name = makeName("xor");
     
    139157}
    140158
     159Add * PabloBlock::createAdd(PabloAST * expr1, PabloAST * expr2, String * name) {
     160    CHECK_SAME_TYPE(expr1, expr2);
     161    if (name == nullptr) {
     162        name = makeName("add");
     163    }
     164    return insertAtInsertionPoint(new Add(expr1->getType(), expr1, expr2, name));
     165}
     166
     167Subtract * PabloBlock::createSubtract(PabloAST * expr1, PabloAST * expr2, String * name) {
     168    CHECK_SAME_TYPE(expr1, expr2);
     169    if (name == nullptr) {
     170        name = makeName("sub");
     171    }
     172    return insertAtInsertionPoint(new Subtract(expr1->getType(), expr1, expr2, name));
     173}
     174
    141175Assign * PabloBlock::createAssign(PabloAST * const var, PabloAST * const value) {
     176    CHECK_SAME_TYPE(var, value);
    142177    return insertAtInsertionPoint(new Assign(var, value));
    143178}
    144179
    145180MatchStar * PabloBlock::createMatchStar(PabloAST * marker, PabloAST * charclass, String * name) {
     181    CHECK_SAME_TYPE(marker, charclass);
    146182    if (name == nullptr) {
    147183        name = makeName("matchstar");
     
    151187
    152188ScanThru * PabloBlock::createScanThru(PabloAST * from, PabloAST * thru, String * name) {
     189    CHECK_SAME_TYPE(from, thru);
    153190    if (name == nullptr) {
    154191        name = makeName("scanthru");
     
    174211
    175212Sel * PabloBlock::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * name) {
     213    CHECK_SAME_TYPE(trueExpr, falseExpr);
    176214    if (name == nullptr) {
    177215        name = makeName("sel");
     
    230268    return nextScopeIndex;
    231269}   
    232    
    233 /// CONSTRUCTOR
    234 
    235 PabloBlock::PabloBlock(PabloFunction * const parent) noexcept
    236 : PabloAST(PabloAST::ClassTypeId::Block, nullptr, nullptr)
    237 , mParent(parent)
    238 , mBranch(nullptr)
    239 , mScopeIndex(0)
    240 {
    241 
    242 }
    243 
    244 PabloBlock::~PabloBlock() {
    245 
    246 }
    247 
    248 }
     270
     271}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5202 r5217  
    1010#include <pablo/pabloAST.h>
    1111#include <pablo/symbol_generator.h>
     12#include <pablo/boolean.h>
     13#include <pablo/arithmetic.h>
     14#include <pablo/branch.h>
     15
    1216#include <pablo/pe_advance.h>
    1317#include <pablo/pe_lookahead.h>
    14 #include <pablo/pe_and.h>
    15 #include <pablo/pe_call.h>
    1618#include <pablo/pe_matchstar.h>
    17 #include <pablo/pe_not.h>
    18 #include <pablo/pe_ones.h>
    19 #include <pablo/pe_or.h>
    2019#include <pablo/pe_scanthru.h>
    21 #include <pablo/pe_sel.h>
    2220#include <pablo/pe_infile.h>
     21
     22#include <pablo/pe_count.h>
     23
    2324#include <pablo/pe_integer.h>
    2425#include <pablo/pe_string.h>
     26#include <pablo/pe_zeroes.h>
     27#include <pablo/pe_ones.h>
     28
    2529#include <pablo/pe_var.h>
    26 #include <pablo/pe_xor.h>
    27 #include <pablo/pe_zeroes.h>
    28 #include <pablo/pe_count.h>
    2930#include <pablo/ps_assign.h>
    30 #include <pablo/branch.h>
    31 #include <pablo/function.h>
     31
     32#include <pablo/pe_call.h>
     33
     34#include <pablo/pablo_kernel.h>
     35
    3236#include <llvm/ADT/ArrayRef.h>
    3337#include <stdexcept>
    3438
    3539namespace pablo {
     40
     41class PabloKernel;
    3642
    3743class PabloBlock : public PabloAST, public StatementList {
     
    5460    }
    5561
    56     inline static PabloBlock * Create(PabloFunction & parent) noexcept {
    57         return new PabloBlock(&parent);
     62    inline static PabloBlock * Create(PabloKernel * const parent) noexcept {
     63        return new PabloBlock(parent);
    5864    }
    5965
     
    146152    AtEOF * createAtEOF(PabloAST * expr, String * const name);
    147153
    148     Extract * createExtract(PabloAST * array, const Integer::Type index) {
     154    Extract * createExtract(PabloAST * array, const int64_t index) {
    149155        return createExtract(array, getInteger(index), nullptr);
    150156    }
     
    158164    }
    159165
    160     Extract * createExtract(PabloAST * array, const Integer::Type index, const std::string & prefix) {
     166    Extract * createExtract(PabloAST * array, const int64_t index, const std::string & prefix) {
    161167        return createExtract(array, getInteger(index), makeName(prefix));
    162168    }
     
    214220    Xor * createXor(Type * const type, const unsigned reserved, String * const name);
    215221
     222    Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
     223        return createSel(condition, trueExpr, falseExpr, nullptr);
     224    }
     225
     226    Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string & prefix) {
     227        return createSel(condition, trueExpr, falseExpr, makeName(prefix));
     228    }
     229
     230    Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * const name);
     231
     232    Add * createAdd(PabloAST * expr1, PabloAST * expr2) {
     233        return createAdd(expr1, expr2, nullptr);
     234    }
     235
     236    Add * createAdd(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     237        return createAdd(expr1, expr2, makeName(prefix));
     238    }
     239
     240    Add * createAdd(PabloAST * expr1, PabloAST * expr2, String * const name);
     241
     242    Subtract * createSubtract(PabloAST * expr1, PabloAST * expr2) {
     243        return createSubtract(expr1, expr2, nullptr);
     244    }
     245
     246    Subtract * createSubtract(PabloAST * expr1, PabloAST * expr2, const std::string & prefix) {
     247        return createSubtract(expr1, expr2, makeName(prefix));
     248    }
     249
     250    Subtract * createSubtract(PabloAST * expr1, PabloAST * expr2, String * const name);
     251
    216252    MatchStar * createMatchStar(PabloAST * marker, PabloAST * charclass) {
    217253        return createMatchStar(marker, charclass, nullptr);
     
    234270    ScanThru * createScanThru(PabloAST * from, PabloAST * thru, String * const name);
    235271
    236     Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    237         return createSel(condition, trueExpr, falseExpr, nullptr);
    238     }
    239 
    240     Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string & prefix) {
    241         return createSel(condition, trueExpr, falseExpr, makeName(prefix));
    242     }
    243 
    244     Sel * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, String * const name);
    245    
    246272    If * createIf(PabloAST * condition, PabloBlock * body);
    247273
     
    252278    }
    253279
    254     inline PabloFunction * getParent() const {
     280    inline PabloKernel * getParent() const {
    255281        return mParent;
    256     }
    257 
    258     void setParent(PabloFunction * const parent) {
    259         mParent = parent;
    260282    }
    261283
     
    278300    }
    279301
    280     inline String * getName(const std::string name) const {
    281         return getSymbolTable()->get(name);
     302    inline String * getName(const std::string & name) const {
     303        return mParent->getName(name);
    282304    }
    283305
    284306    inline String * makeName(const std::string & prefix) const {
    285         return getSymbolTable()->make(prefix);
    286     }
    287 
    288     inline Integer * getInteger(Integer::Type value) const {
    289         return getSymbolTable()->getInteger(value);
    290     }
    291 
    292     SymbolGenerator * getSymbolTable() const {
    293         return mParent->getSymbolTable();
    294     }
    295 
    296     virtual ~PabloBlock();
     307        return mParent->makeName(prefix);
     308    }
     309
     310    inline Integer * getInteger(const int64_t value) const {
     311        return mParent->getInteger(value);
     312    }
     313
     314    virtual ~PabloBlock() {}
    297315
    298316protected:
    299317
    300     explicit PabloBlock(PabloFunction * parent) noexcept;
     318    explicit PabloBlock(PabloKernel * const parent) noexcept
     319    : PabloAST(PabloAST::ClassTypeId::Block, nullptr, nullptr)
     320    , mParent(parent)
     321    , mBranch(nullptr)
     322    , mScopeIndex(0) {
     323
     324    }
    301325
    302326    template<typename Type>
     
    313337
    314338private:       
    315     PabloFunction *                                     mParent;
    316     Branch *                                            mBranch;
    317     unsigned                                            mScopeIndex;
     339    PabloKernel * const         mParent;
     340    Branch *                    mBranch;
     341    unsigned                    mScopeIndex;
    318342};
    319343
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/codemotionpass.cpp

    r5202 r5217  
    11#include "codemotionpass.h"
     2#include <pablo/pablo_kernel.h>
    23#include <pablo/codegenstate.h>
    34#include <pablo/analysis/pabloverifier.hpp>
    45#include <boost/container/flat_set.hpp>
    5 #include <boost/container/flat_map.hpp>
    6 #include <boost/graph/adjacency_list.hpp>
    7 #include <boost/graph/topological_sort.hpp>
    8 #include <boost/circular_buffer.hpp>
     6// #include <boost/circular_buffer.hpp>
    97
    108using namespace boost;
     
    1614 * @brief optimize
    1715 ** ------------------------------------------------------------------------------------------------------------- */
    18 bool CodeMotionPass::optimize(PabloFunction & function) {
    19     CodeMotionPass::movement(function.getEntryBlock());
     16bool CodeMotionPass::optimize(PabloKernel * kernel) {
     17    CodeMotionPass::movement(kernel->getEntryBlock());
    2018    #ifndef NDEBUG
    21     PabloVerifier::verify(function, "post-code-motion");
     19    PabloVerifier::verify(kernel, "post-code-motion");
    2220    #endif
    2321    return true;
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/codemotionpass.h

    r5202 r5217  
    77namespace pablo {
    88
    9 class PabloFunction;
     9class PabloKernel;
    1010class PabloBlock;
    1111class Statement;
     
    2929    };
    3030public:
    31     static bool optimize(PabloFunction & function);
     31    static bool optimize(PabloKernel * kernel);
    3232protected:
    3333    static void movement(PabloBlock * const block);
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r5202 r5217  
    11#include "pablo_automultiplexing.hpp"
    22#include <pablo/builder.hpp>
    3 #include <pablo/function.h>
     3#include <pablo/prototype.h>
    44#include <pablo/printer_pablos.h>
    55#include <boost/container/flat_set.hpp>
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r5202 r5217  
    11#include <pablo/optimizers/pablo_simplifier.hpp>
     2#include <pablo/pablo_kernel.h>
    23#include <pablo/codegenstate.h>
    34#include <pablo/expression_map.hpp>
    4 #include <pablo/function.h>
     5//#include <pablo/function.h>
    56#include <pablo/analysis/pabloverifier.hpp>
    6 #include <boost/container/flat_set.hpp>
    7 #include <boost/container/flat_map.hpp>
     7//#include <boost/container/flat_set.hpp>
     8//#include <boost/container/flat_map.hpp>
    89#include <pablo/printer_pablos.h>
    9 #include <iostream>
     10//#include <iostream>
    1011
    1112using namespace boost;
     
    559560 * @brief deadCodeElimination
    560561 ** ------------------------------------------------------------------------------------------------------------- */
    561 void Simplifier::deadCodeElimination(PabloFunction & f) {
    562 
    563     deadCodeElimination(f.getEntryBlock());
    564 
    565     for (unsigned i = 0; i < f.getNumOfVariables(); ++i) {
    566         Var * var = f.getVariable(i);
     562void Simplifier::deadCodeElimination(PabloKernel * kernel) {
     563
     564    deadCodeElimination(kernel->getEntryBlock());
     565
     566    for (unsigned i = 0; i < kernel->getNumOfVariables(); ++i) {
     567        Var * var = kernel->getVariable(i);
    567568        bool unused = true;
    568569        for (PabloAST * user : var->users()) {
     
    642643 * @brief optimize
    643644 ** ------------------------------------------------------------------------------------------------------------- */
    644 bool Simplifier::optimize(PabloFunction & function) {
    645     redundancyElimination(function.getEntryBlock());
    646     strengthReduction(function.getEntryBlock());
    647     deadCodeElimination(function);
     645bool Simplifier::optimize(PabloKernel * kernel) {
     646    redundancyElimination(kernel->getEntryBlock());
     647    strengthReduction(kernel->getEntryBlock());
     648    deadCodeElimination(kernel);
    648649    #ifndef NDEBUG
    649     PabloVerifier::verify(function, "post-simplification");
     650    PabloVerifier::verify(kernel, "post-simplification");
    650651    #endif
    651652    return true;
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.hpp

    r5202 r5217  
    22#define PABLO_SIMPLIFIER_HPP
    33
    4 #include <pablo/codegenstate.h>
    5 
    64namespace pablo {
    75
    8 class PabloFunction;
     6class PabloKernel;
     7class PabloAST;
     8class Variadic;
     9class Statement;
     10class PabloBlock;
     11
    912struct ExpressionTable;
    1013
     
    1316    struct VariableTable;
    1417public:
    15     static bool optimize(PabloFunction & function);
     18    static bool optimize(PabloKernel * kernel);
    1619protected:
    1720    Simplifier() = default;
     
    2023    static PabloAST * fold(Statement * const stmt, PabloBlock * const block);
    2124    static void redundancyElimination(PabloBlock * const block, ExpressionTable * et = nullptr, VariableTable * const vt = nullptr);
    22     static void deadCodeElimination(PabloFunction & f);
     25    static void deadCodeElimination(PabloKernel * const kernel);
    2326    static void deadCodeElimination(PabloBlock * const block);
    2427    static void strengthReduction(PabloBlock * const block);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5202 r5217  
    88#define PE_PabloAST_H
    99
    10 #include <pablo/type/streamtype.h>
     10#include <IDISA/types/streamtype.h>
    1111#include <llvm/Support/Casting.h>
    1212#include <llvm/Support/Compiler.h>
     
    3636    friend class Count;
    3737    friend class Var;
    38     friend void addUsage(PabloAST *, PabloBlock *);
    39     friend void removeUsage(PabloAST *, PabloBlock *);
    4038public:
    4139
     
    8179        // Statistics operations
    8280        , Count
     81        // Arithmetic operations
     82        , Add
     83        , Subtract
    8384        // Variable assignments
    8485        , Assign
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5204 r5217  
    1010#include <pablo/carry_manager.h>
    1111#include <pablo/printer_pablos.h>
    12 #include <pablo/function.h>
     12#include <pablo/prototype.h>
    1313#include <re/re_name.h>
    1414#include <stdexcept>
     
    2323namespace pablo {
    2424
    25 PabloCompiler::PabloCompiler(PabloKernel * k, PabloFunction * const function)
    26 : iBuilder(k->getBuilder())
     25PabloCompiler::PabloCompiler(PabloKernel * kernel)
     26: iBuilder(kernel->getBuilder())
    2727, mBitBlockType(iBuilder->getBitBlockType())
    2828, mCarryManager(nullptr)
    29 , mPabloFunction(function)
    30 , mKernelBuilder(k)
     29, mKernel(kernel)
    3130, mWhileDepth(0)
    3231, mIfDepth(0)
     
    3736
    3837Type * PabloCompiler::initializeKernelData() {
    39     Examine(mPabloFunction);   
     38    Examine();
    4039    mCarryManager = std::unique_ptr<CarryManager>(new CarryManager(iBuilder));
    41     Type * carryDataType = mCarryManager->initializeCarryData(mPabloFunction);
    42     return carryDataType;
    43 }
    44    
    45 void PabloCompiler::verifyParameter(const Var * var, const Value * param) {
    46     if (LLVM_UNLIKELY(&(param->getContext()) != &(iBuilder->getContext()))) {
    47         std::string tmp;
    48         raw_string_ostream out(tmp);
    49         out << "Cannot compile ";
    50         mPabloFunction->print(out);
    51         out << ": LLVM Context for ";
    52         var->print(out);
    53         out << " differs from that of the kernel.";
    54         throw std::runtime_error(out.str());
    55     }
    56 }
    57 
    58 void PabloCompiler::compile(Function * doBlockFunction) {
     40    return mCarryManager->initializeCarryData(mKernel);
     41}
     42   
     43void PabloCompiler::compile(Value * const self, Function * doBlockFunction) {
    5944
    6045    // Make sure that we generate code into the right module.
    6146    mFunction = doBlockFunction;
     47    mSelf = self;
     48
    6249    #ifdef PRINT_TIMING_INFORMATION
    6350    const timestamp_t pablo_compilation_start = read_cycle_counter();
     
    6653    //Generate Kernel//
    6754    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    68     mSelf = mKernelBuilder->getParameter(doBlockFunction, "self");
    69 
    70     mCarryManager->initializeCodeGen(mKernelBuilder, mSelf);
     55
     56    mCarryManager->initializeCodeGen(mKernel, mSelf);
    7157     
    72     PabloBlock * const entryBlock = mPabloFunction->getEntryBlock(); assert (entryBlock);
     58    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
    7359    mMarkerMap.emplace(entryBlock->createZeroes(), iBuilder->allZeroes());
    7460    mMarkerMap.emplace(entryBlock->createOnes(), iBuilder->allOnes());
    7561
    76     Value * const blockNo = mKernelBuilder->getScalarField(mSelf, blockNoScalar);
    77 
    78     for (unsigned i = 0, j = 0; i < mPabloFunction->getNumOfParameters(); ++i) {
    79         Var * var = mPabloFunction->getParameter(i);
     62    Value * const blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
     63
     64    for (unsigned i = 0; i < mKernel->getNumOfInputs(); ++i) {
     65        Var * var = mKernel->getInput(i);
    8066        std::string name = var->getName()->to_string();
    8167        Value * input = nullptr;
    8268        if (var->getType()->isSingleValueType()) {
    83             input = mKernelBuilder->getScalarFieldPtr(mSelf, name);
     69            input = mKernel->getScalarFieldPtr(mSelf, name);
    8470        } else {
    85             input = mKernelBuilder->getStreamSetBlockPtr(mSelf, name, blockNo);
    86             input = iBuilder->CreateGEP(input, {iBuilder->getInt32(0), iBuilder->getInt32(j++)});
    87         }
    88         verifyParameter(var, input);
     71            input = mKernel->getStreamSetBlockPtr(mSelf, name, blockNo);
     72        }
    8973        mMarkerMap.emplace(var, input);
    9074    }
    9175
    92     for (unsigned i = 0, j = 0; i < mPabloFunction->getNumOfResults(); ++i) {
    93         Var * var = mPabloFunction->getResult(i);
     76    for (unsigned i = 0; i < mKernel->getNumOfOutputs(); ++i) {
     77        Var * var = mKernel->getOutput(i);
    9478        std::string name = var->getName()->to_string();
    9579        Value * output = nullptr;
    9680        if (var->getType()->isSingleValueType()) {
    97             output = mKernelBuilder->getScalarFieldPtr(mSelf, name);
     81            output = mKernel->getScalarFieldPtr(mSelf, name);
    9882        } else {
    99             output = mKernelBuilder->getStreamSetBlockPtr(mSelf, name, blockNo);
    100             output = iBuilder->CreateGEP(output, {iBuilder->getInt32(0), iBuilder->getInt32(j++)});
    101         }
    102         verifyParameter(var, output);
     83            output = mKernel->getStreamSetBlockPtr(mSelf, name, blockNo);
     84        }
    10385        mMarkerMap.emplace(var, output);
    10486    }
     
    11294}
    11395
    114 inline void PabloCompiler::Examine(const PabloFunction * const function) {
     96inline void PabloCompiler::Examine() {
    11597    mWhileDepth = 0;
    11698    mIfDepth = 0;
    11799    mMaxWhileDepth = 0;
    118     Examine(function->getEntryBlock());
     100    Examine(mKernel->getEntryBlock());
    119101}
    120102
     
    124106            const Lookahead * const la = cast<Lookahead>(stmt);
    125107            assert (isa<Var>(la->getExpr()));
    126             if (LLVM_LIKELY(la->getAmount() > mKernelBuilder->getLookAhead())) {
    127                 mKernelBuilder->setLookAhead(la->getAmount());
     108            if (LLVM_LIKELY(la->getAmount() > mKernel->getLookAhead())) {
     109                mKernel->setLookAhead(la->getAmount());
    128110            }
    129111        } else {
     
    277259
    278260    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
    279     for (const auto var : whileStatement->getEscaped()) {
    280         PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, getName(var));
     261    for (const auto var : whileStatement->getEscaped()) {       
    281262        auto f = mMarkerMap.find(var);
    282263        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
     
    284265            raw_string_ostream out(tmp);
    285266            PabloPrinter::print(var, out);
    286             out << " was not assigned a value.";
     267            out << " is uninitialized prior to entering ";
     268            PabloPrinter::print(whileStatement, out);
    287269            llvm::report_fatal_error(out.str());
    288270        }
     271
     272        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, getName(var));
    289273        phi->addIncoming(f->second, whileEntryBlock);
    290274        f->second = phi;
     
    362346            bool storeInstRequired = false;
    363347            if (LLVM_LIKELY(isa<Var>(expr))) {
    364                 for (unsigned i = 0; i < mPabloFunction->getNumOfResults(); ++i) {
    365                     if (expr == mPabloFunction->getResult(i)) {
     348                for (unsigned i = 0; i < mKernel->getNumOfOutputs(); ++i) {
     349                    if (expr == mKernel->getOutput(i)) {
    366350                        storeInstRequired = true;
    367351                        break;
     
    371355
    372356            if (LLVM_UNLIKELY(storeInstRequired || isa<Extract>(expr))) {
    373 
    374357                const auto f = mMarkerMap.find(expr);
    375358                if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
    376359                    std::string tmp;
    377360                    raw_string_ostream out(tmp);
    378                     PabloPrinter::print(expr, out);
    379                     out << " was not defined prior to ";
    380                     PabloPrinter::print(stmt, out);
     361                    out << "Use-before-definition error: ";
     362                    expr->print(out);
     363                    out << " does not dominate ";
     364                    stmt->print(out);
    381365                    throw std::runtime_error(out.str());
    382366                }
     
    389373                    value = iBuilder->CreateTruncOrBitCast(value, count->getType());
    390374                    value = iBuilder->CreateAdd(value, count);
     375                }
     376
     377//                cast<PointerType>(ptr->getType())->getElementType()->getPrimitiveSizeInBits() / 8;
     378
     379                const Type * const type = value->getType();
     380                if (isa<VectorType>(type) || isa<IntegerType>(type)) {
     381                    const auto bitWidth = isa<VectorType>(type)
     382                            ? cast<VectorType>(type)->getBitWidth()
     383                            : cast<IntegerType>(type)->getBitWidth();
     384                    iBuilder->CreateAlignedStore(value, ptr, bitWidth / 8);
     385                } else {
    391386                    iBuilder->CreateStore(value, ptr);
    392                 } else {
    393                     iBuilder->CreateBlockAlignedStore(value, ptr);
    394387                }
    395388            }
     
    398391            Value * array = compileExpression(extract->getArray(), false);
    399392            Value * index = compileExpression(extract->getIndex());
    400             value = iBuilder->CreateGEP(array, index, getName(stmt));
     393            value = iBuilder->CreateGEP(array, {ConstantInt::getNullValue(index->getType()), index}, getName(stmt));
    401394        } else if (const And * pablo_and = dyn_cast<And>(stmt)) {
    402395            value = iBuilder->simd_and(compileExpression(pablo_and->getOperand(0)), compileExpression(pablo_and->getOperand(1)));
     
    427420            value = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    428421        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    429             Value * EOFmask = mKernelBuilder->getScalarField(mSelf, "EOFmask");
     422            Value * EOFmask = mKernel->getScalarField(mSelf, "EOFmask");
    430423            value = iBuilder->simd_xor(compileExpression(e->getExpr()), EOFmask);
    431424        } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
    432             Value * EOFbit = mKernelBuilder->getScalarField(mSelf, "EOFbit");
     425            Value * EOFbit = mKernel->getScalarField(mSelf, "EOFbit");
    433426            value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
    434427        } else if (const Count * c = dyn_cast<Count>(stmt)) {
    435428            Value * const to_count = compileExpression(c->getExpr());
    436             const unsigned counterSize = 64;
    437             Value * fieldCounts = iBuilder->simd_popcount(counterSize, to_count);
    438             value = iBuilder->mvmd_extract(counterSize, fieldCounts, 0);
    439             for (unsigned i = 1; i < (iBuilder->getBitBlockWidth() / counterSize); ++i) {
    440                 Value * temp = iBuilder->mvmd_extract(counterSize, fieldCounts, i);
    441                 value = iBuilder->CreateAdd(value, temp);
     429            const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
     430            Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
     431            if (LLVM_UNLIKELY(counterSize <= 1)) {
     432                value = partial;
     433            } else {
     434                value = iBuilder->mvmd_extract(counterSize, partial, 0);
     435                const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
     436                for (unsigned i = 1; i < fields; ++i) {
     437                    Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
     438                    value = iBuilder->CreateAdd(value, temp);
     439                }
    442440            }
    443441        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
     
    447445            }
    448446            unsigned index = 0;
    449             for (; index < mPabloFunction->getNumOfParameters(); ++index) {
    450                 if (mPabloFunction->getParameter(index) == var) {
     447            for (; index < mKernel->getNumOfInputs(); ++index) {
     448                if (mKernel->getInput(index) == var) {
    451449                    break;
    452450                }
    453451            }
    454             if (LLVM_UNLIKELY(index >= mPabloFunction->getNumOfParameters())) {
     452            if (LLVM_UNLIKELY(index >= mKernel->getNumOfInputs())) {
    455453                throw std::runtime_error("Lookahead has an illegal Var operand");
    456454            }
     
    458456            const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    459457            std::string inputName = var->getName()->to_string();;
    460             Value * blockNo = mKernelBuilder->getScalarField(mSelf, blockNoScalar);
    461             Value * lookAhead_blockPtr  = mKernelBuilder->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift)));
     458            Value * blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
     459            Value * lookAhead_blockPtr  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift)));
    462460            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    463461            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     
    465463                value = lookAhead;
    466464            } else { // Need to form shift result from two adjacent blocks.
    467                 Value * lookAhead_blockPtr1  = mKernelBuilder->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift + 1)));
     465                Value * lookAhead_blockPtr1  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift + 1)));
    468466                Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    469467                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5202 r5217  
    4848    using MarkerMap = std::unordered_map<const PabloAST *, Value *>;
    4949public:
    50     PabloCompiler(PabloKernel * k, PabloFunction * function);
     50    PabloCompiler(PabloKernel * kernel);
    5151    Type * initializeKernelData();
    52     void compile(Function * doBlockFunction);
     52    void compile(Value * const self, Function * doBlockFunction);
    5353
    5454private:
     
    5656    void verifyParameter(const Var * var, const Value * param);
    5757
    58     void Examine(const PabloFunction * const function);
     58    void Examine();
    5959    void Examine(const PabloBlock * const block);
    6060
     
    7373    std::unique_ptr<CarryManager>       mCarryManager;
    7474
    75     PabloFunction *  const              mPabloFunction;
    76 
    77     PabloKernel *                       mKernelBuilder;
     75    PabloKernel * const                 mKernel;
    7876    Value *                             mSelf;
    7977
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5204 r5217  
    88#include <llvm/Support/Debug.h>
    99#include <pablo/pe_var.h>
    10 #include <pablo/type/streamtype.h>
    1110#include <llvm/IR/Verifier.h>
     11#include <IDISA/idisa_builder.h>
     12#include <pablo/prototype.h>
    1213
    1314using namespace pablo;
    1415using namespace kernel;
    1516using namespace parabix;
     17using namespace IDISA;
    1618
    17 PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
    18                          std::string kernelName,
    19                          PabloFunction * function)
    20 : KernelBuilder(builder, kernelName, {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
    21 , mPabloFunction(function)
    22 , mPabloCompiler(new PabloCompiler(this, function))
     19Var * PabloKernel::addInput(const std::string name, Type * const type) {
     20    Var * param = new Var(mSymbolTable->make(name), type);
     21    mInputs.push_back(param);
     22    if (isa<StreamType>(type)) {
     23        Type * const resolvedType = cast<StreamType>(type)->resolveType(iBuilder);
     24        mStreamSetInputs.emplace_back(resolvedType, name);
     25    } else {
     26        mScalarInputs.emplace_back(type, name);
     27    }
     28    assert (mStreamSetInputs.size() + mScalarInputs.size() == mInputs.size());
     29    return param;
     30}
    2331
    24 {
    25     for (unsigned i = 0; i < function->getNumOfParameters(); ++i) {
    26         const auto var = function->getParameter(i);
    27         Type * type = var->getType();
    28         bool scalar = false;
    29         if (isa<StreamType>(type)) {
    30             type = cast<StreamType>(type)->resolveType(builder);
    31         } else if (type->isSingleValueType()) {
    32             if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
    33                 type = builder->getSizeTy();
    34             }
    35             scalar = true;
    36         }
     32Var * PabloKernel::addOutput(const std::string name, Type * const type) {
     33    Var * result = new Var(mSymbolTable->make(name), type);
     34    mOutputs.push_back(result);
     35    if (isa<StreamType>(type)) {
     36        Type * const resolvedType = cast<StreamType>(type)->resolveType(iBuilder);
     37        mStreamSetOutputs.emplace_back(resolvedType, name);
     38    } else {
     39        mScalarOutputs.emplace_back(type, name);
     40    }
     41    assert (mStreamSetOutputs.size() + mScalarOutputs.size() == mOutputs.size());
     42    return result;
     43}
    3744
    38         std::string name = var->getName()->to_string();
    39         if (scalar) {
    40             mScalarInputs.emplace_back(type, std::move(name));
    41         } else {
    42             mStreamSetInputs.emplace_back(type, std::move(name));
     45Var * PabloKernel::makeVariable(PabloAST * name, Type * const type) {
     46    Var * const var = new Var(name, type);
     47    mVariables.push_back(var);
     48    return var;
     49}
     50
     51Zeroes * PabloKernel::getNullValue(Type * type) {
     52    if (type == nullptr) {
     53        type = getStreamSetTy();
     54    }
     55    for (PabloAST * constant : mConstants) {
     56        if (isa<Zeroes>(constant) && constant->getType() == type) {
     57            return cast<Zeroes>(constant);
    4358        }
    4459    }
     60    Zeroes * value = new Zeroes(type);
     61    mConstants.push_back(value);
     62    return value;
     63}
    4564
    46     for (unsigned i = 0; i < function->getNumOfResults(); ++i) {
    47         const auto var = function->getResult(i);
    48         Type * type = var->getType();
    49         bool scalar = false;
    50         if (isa<StreamType>(type)) {
    51             type = cast<StreamType>(type)->resolveType(builder);
    52         } else if (type->isSingleValueType()) {
    53             if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
    54                 type = builder->getSizeTy();
    55             }
    56             scalar = true;
    57         }
    58 
    59         std::string name = var->getName()->to_string();
    60         if (scalar) {
    61             mScalarOutputs.emplace_back(type, std::move(name));
    62         } else {
    63             mStreamSetOutputs.emplace_back(type, std::move(name));
     65Ones * PabloKernel::getAllOnesValue(Type * type) {
     66    if (type == nullptr) {
     67        type = getStreamSetTy();
     68    }
     69    for (PabloAST * constant : mConstants) {
     70        if (isa<Ones>(constant) && constant->getType() == type) {
     71            return cast<Ones>(constant);
    6472        }
    6573    }
    66 
    67 
    68 }
    69 
    70 PabloKernel::~PabloKernel() {
    71     delete mPabloCompiler;
     74    Ones * value = new Ones(type);
     75    mConstants.push_back(value);
     76    return value;
    7277}
    7378
     
    8287    Module * m = iBuilder->getModule();
    8388    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    84     mPabloCompiler->compile(doBlockFunction);
    85     Function::arg_iterator args = doBlockFunction->arg_begin();
    86     Value * self = &*(args);
     89    auto args = doBlockFunction->arg_begin();
     90    Value * const self = &*(args);
     91    mPabloCompiler->compile(self, doBlockFunction);
    8792    Value * produced = getProducedItemCount(self);
    8893    produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     
    124129    iBuilder->restoreIP(savePoint);
    125130}
     131
     132PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, const std::string & kernelName)
     133: KernelBuilder(builder, kernelName, {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
     134, mPabloCompiler(new PabloCompiler(this))
     135, mSymbolTable(new SymbolGenerator())
     136, mEntryBlock(PabloBlock::Create(this))
     137{
     138
     139}
     140
     141PabloKernel::~PabloKernel() {
     142    delete mPabloCompiler;
     143    delete mSymbolTable;
     144}
     145
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5202 r5217  
    88
    99#include <kernels/kernel.h>
    10 #include <IDISA/idisa_builder.h>
    11 #include <pablo/function.h>
     10#include <pablo/symbol_generator.h>
     11
     12namespace IDISA {
     13class IDISA_Builder;
     14}
    1215
    1316namespace pablo {
    1417   
    15 class PabloCompiler; class CarryManager;
    16 
     18class PabloCompiler;
     19class PabloBlock;
     20class PabloAST;
     21class CarryManager;
     22class Var;
     23class Zeroes;
     24class Ones;
     25class String;
     26class Integer;
    1727
    1828class PabloKernel : public kernel::KernelBuilder {
     29
     30    friend class PabloCompiler;
     31    friend class PabloBlock;
     32    friend class CarryManager;
     33
    1934public:
    20     PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName, PabloFunction * function);
     35
     36    PabloKernel(IDISA::IDISA_Builder * builder, const std::string & kernelName);
    2137    // At present only population count accumulator are supported,
    2238    // using the pablo.Count operation.
     
    2440    ~PabloKernel();
    2541
     42    PabloBlock * getEntryBlock() {
     43        return mEntryBlock;
     44    }
     45
     46    const PabloBlock * getEntryBlock() const {
     47        return mEntryBlock;
     48    }
     49
     50    PabloBlock * setEntryBlock(PabloBlock * entryBlock) {
     51        assert (entryBlock);
     52        std::swap(mEntryBlock, entryBlock);
     53        return entryBlock;
     54    }
     55
     56    Var * getInput(const unsigned index) {
     57        return mInputs[index];
     58    }
     59
     60    const Var * getInput(const unsigned index) const {
     61        return mInputs[index];
     62    }
     63
     64    Var * addInput(const std::string name, Type * const type);
     65
     66    unsigned getNumOfInputs() const {
     67        return mInputs.size();
     68    }
     69
     70    Var * getOutput(const unsigned index) {
     71        return mOutputs[index];
     72    }
     73
     74    const Var * getOutput(const unsigned index) const {
     75        return mOutputs[index];
     76    }
     77
     78    Var * addOutput(const std::string name, Type * const type);
     79
     80    unsigned getNumOfOutputs() const {
     81        return mOutputs.size();
     82    }
     83
     84    Var * makeVariable(PabloAST * name, Type * const type);
     85
     86    Var * getVariable(const unsigned index) {
     87        return mVariables[index];
     88    }
     89
     90    unsigned getNumOfVariables() const {
     91        return mVariables.size();
     92    }
     93
     94    Zeroes * getNullValue(Type * const type);
     95
     96    Ones * getAllOnesValue(Type * const type);
     97
     98    inline SymbolGenerator * getSymbolTable() const {
     99        return mSymbolTable;
     100    }
     101
    26102protected:
     103
    27104    // A custom method for preparing kernel declarations is needed,
    28105    // so that the carry data requirements may be accommodated before
     
    36113    // This may be overridden for specialized processing.
    37114    virtual void generateFinalBlockMethod() override;
    38    
    39     PabloFunction * mPabloFunction;
    40    
    41     PabloCompiler * mPabloCompiler;
    42115
    43     friend class PabloCompiler;
    44     friend class CarryManager;
     116    inline String * getName(const std::string & name) const {
     117        return mSymbolTable->get(name);
     118    }
     119
     120    inline String * makeName(const std::string & prefix) const {
     121        return mSymbolTable->make(prefix);
     122    }
     123
     124    inline Integer * getInteger(const int64_t value) const {
     125        return mSymbolTable->getInteger(value, iBuilder);
     126    }
     127
     128private:
     129
     130    PabloCompiler * const           mPabloCompiler;
     131    SymbolGenerator *               mSymbolTable;
     132    PabloBlock *                    mEntryBlock;
     133    std::vector<Var *>              mInputs;
     134    std::vector<Var *>              mOutputs;
     135    std::vector<PabloAST *>         mConstants;
     136    std::vector<Var *>              mVariables;
     137
    45138};
     139
    46140}
     141
    47142#endif // PABLO_KERNEL_H
  • icGREP/icgrep-devel/icgrep/pablo/pablo_toolchain.cpp

    r5202 r5217  
    55 */
    66
    7 #include <string>
    8 #include <iostream>
    9 #include <fstream>
    10 
    117#include <pablo/pablo_toolchain.h>
     8#include <pablo/pablo_kernel.h>
    129#include <pablo/pablo_compiler.h>
    1310#include <pablo/optimizers/pablo_simplifier.hpp>
     
    2320#include <pablo/optimizers/schedulingprepass.h>
    2421#endif
    25 #include <pablo/function.h>
     22#include <pablo/prototype.h>
    2623#include <pablo/analysis/pabloverifier.hpp>
    2724#include <pablo/printer_pablos.h>
    28 #include <sstream>
    2925#include <llvm/Support/CommandLine.h>
    3026#include <llvm/Support/FileSystem.h>
     
    3228#include <hrtime.h>
    3329#endif
     30#include <string>
     31#include <iostream>
     32#include <fstream>
     33#include <sstream>
    3434
    3535namespace pablo {
     
    172172#endif
    173173
    174 void pablo_function_passes(PabloFunction * function) {
     174void pablo_function_passes(PabloKernel * kernel) {
    175175   
    176176    if (DebugOptions.isSet(PrintCompiledREcode)) {
     
    178178        llvm::raw_os_ostream cerr(std::cerr);
    179179        cerr << "Initial Pablo AST:\n";
    180         PabloPrinter::print(*function, cerr);
     180        PabloPrinter::print(kernel, cerr);
    181181    }
    182182   
    183183    #ifndef NDEBUG
    184     PabloVerifier::verify(*function, "creation");
     184    PabloVerifier::verify(kernel, "creation");
    185185    #endif
    186186
     
    202202    if (!PabloOptimizationsOptions.isSet(DisableSimplification)) {
    203203        READ_CYCLE_COUNTER(simplification_start);
    204         Simplifier::optimize(*function);
     204        Simplifier::optimize(kernel);
    205205        READ_CYCLE_COUNTER(simplification_end);
    206206    }
    207207    if (Flatten){
    208208        READ_CYCLE_COUNTER(flattenif_start);
    209         FlattenIf::transform(*function);
     209        FlattenIf::transform(kernel);
    210210        READ_CYCLE_COUNTER(flattenif_end);
    211211    }
     
    213213//    if (PabloOptimizationsOptions.isSet(EnableLowering) || PabloOptimizationsOptions.isSet(EnablePreDistribution) || PabloOptimizationsOptions.isSet(EnablePostDistribution)) {
    214214//        READ_CYCLE_COUNTER(coalescing_start);
    215 //        CanonicalizeDFG::transform(*function);
     215//        CanonicalizeDFG::transform(kernel);
    216216//        READ_CYCLE_COUNTER(coalescing_end);
    217217//    }
    218218    if (PabloOptimizationsOptions.isSet(EnablePreDistribution)) {
    219219        READ_CYCLE_COUNTER(pre_distribution_start);
    220         BooleanReassociationPass::optimize(*function);
     220        BooleanReassociationPass::optimize(kernel);
    221221        READ_CYCLE_COUNTER(pre_distribution_end);
    222222    }
    223223    if (PabloOptimizationsOptions.isSet(EnableMultiplexing)) {
    224224        READ_CYCLE_COUNTER(multiplexing_start);
    225         MultiplexingPass::optimize(*function);
     225        MultiplexingPass::optimize(kernel);
    226226        READ_CYCLE_COUNTER(multiplexing_end);
    227227//        if (PabloOptimizationsOptions.isSet(EnableLowering) || PabloOptimizationsOptions.isSet(EnablePreDistribution) || PabloOptimizationsOptions.isSet(EnablePostDistribution)) {
    228 //            CanonicalizeDFG::transform(*function);
     228//            CanonicalizeDFG::transform(kernel);
    229229//        }
    230230    }
    231231    if (PabloOptimizationsOptions.isSet(EnablePostDistribution)) {
    232232        READ_CYCLE_COUNTER(post_distribution_start);
    233         BooleanReassociationPass::optimize(*function);
     233        BooleanReassociationPass::optimize(kernel);
    234234        READ_CYCLE_COUNTER(post_distribution_end);
    235235    }
     
    237237    if (PabloOptimizationsOptions.isSet(EnableCodeMotion)) {
    238238        READ_CYCLE_COUNTER(sinking_start);
    239         CodeMotionPass::optimize(*function);
     239        CodeMotionPass::optimize(kernel);
    240240        READ_CYCLE_COUNTER(sinking_end);
    241241    }
     
    245245        llvm::raw_os_ostream cerr(std::cerr);
    246246        cerr << "Unlowered Pablo AST:\n";
    247         PabloPrinter::print(*function, cerr);
     247        PabloPrinter::print(kernel, cerr);
    248248    }
    249249    #ifdef PRINT_TIMING_INFORMATION
     
    252252//    if (PabloOptimizationsOptions.isSet(EnableLowering) || PabloOptimizationsOptions.isSet(EnablePreDistribution) || PabloOptimizationsOptions.isSet(EnablePostDistribution)) {
    253253//        READ_CYCLE_COUNTER(lowering_start);
    254 //        FactorizeDFG::transform(*function);
     254//        FactorizeDFG::transform(kernel);
    255255//        READ_CYCLE_COUNTER(lowering_end);
    256256//    }
    257257//    if (PabloOptimizationsOptions.isSet(EnablePrePassScheduling)) {
    258258//        READ_CYCLE_COUNTER(scheduling_start);
    259 //        SchedulingPrePass::optimize(*function);
     259//        SchedulingPrePass::optimize(kernel);
    260260//        READ_CYCLE_COUNTER(scheduling_end);
    261261//    }
     
    269269            llvm::raw_os_ostream cerr(std::cerr);
    270270            cerr << "Final Pablo AST:\n";
    271             PabloPrinter::print(*function, cerr);
     271            PabloPrinter::print(kernel, cerr);
    272272        } else {
    273273            std::error_code error;
    274274            llvm::raw_fd_ostream out(PabloOutputFilename, error, sys::fs::OpenFlags::F_None);
    275             PabloPrinter::print(*function, out);
     275            PabloPrinter::print(kernel, out);
    276276        }
    277277    }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_toolchain.h

    r5202 r5217  
    88#define PABLO_TOOLCHAIN_H
    99
    10 #include <pablo/function.h>
    11 #include <llvm/Support/CommandLine.h>
     10namespace llvm {
     11namespace cl {
     12class OptionCategory;
     13}
     14}
    1215
    1316namespace pablo {
    14    
     17
     18class PabloKernel;
     19
    1520enum PabloDebugFlags {
    1621    PrintOptimizedREcode, PrintCompiledCCcode, PrintCompiledREcode, DumpTrace, PrintUnloweredCode
     
    2227};
    2328   
    24 const cl::OptionCategory * pablo_toolchain_flags();
     29const llvm::cl::OptionCategory * pablo_toolchain_flags();
    2530
    2631bool DebugOptionIsSet(PabloDebugFlags flag);
    2732
    28 void pablo_function_passes(PabloFunction * function);
     33void pablo_function_passes(PabloKernel * kernel);
    2934
    3035}
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.cpp

    r5202 r5217  
    11#include <pablo/passes/flattenif.hpp>
     2#include <pablo/pablo_kernel.h>
    23#include <pablo/codegenstate.h>
    34#include <pablo/analysis/pabloverifier.hpp>
     
    3132 * @brief transform
    3233 ** ------------------------------------------------------------------------------------------------------------- */
    33 void FlattenIf::transform(PabloFunction & function) {
    34     flattenIf(function.getEntryBlock());
     34void FlattenIf::transform(PabloKernel * function) {
     35    flattenIf(function->getEntryBlock());
    3536    #ifndef NDEBUG
    3637    PabloVerifier::verify(function, "flatten-if");
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.hpp

    r5202 r5217  
    44namespace pablo {
    55
    6 class PabloFunction;
     6class PabloKernel;
    77class PabloBlock;
    88
    99class FlattenIf {
    1010public:
    11     static void transform(PabloFunction & function);
     11    static void transform(PabloKernel * function);
    1212protected:
    1313    FlattenIf() = default;
  • icGREP/icgrep-devel/icgrep/pablo/pe_advance.h

    r5202 r5217  
    2828        return getOperand(0);
    2929    }
    30     inline Integer::Type getAmount() const {
     30    inline int64_t getAmount() const {
    3131        return cast<Integer>(getOperand(1))->value();
    3232    }
  • icGREP/icgrep-devel/icgrep/pablo/pe_call.h

    r5202 r5217  
    33
    44#include <pablo/pabloAST.h>
    5 #include <pablo/function.h>
     5#include <pablo/prototype.h>
    66
    77namespace pablo {
  • icGREP/icgrep-devel/icgrep/pablo/pe_count.h

    r5204 r5217  
    2727    }
    2828protected:
    29     explicit Count(PabloAST * expr, const String * counter)
    30         : Statement(ClassTypeId::Count, getScalarTy(), {expr}, counter)
    31     {
     29    explicit Count(PabloAST * expr, const String * counter, Type * type)
     30    : Statement(ClassTypeId::Count, type, {expr}, counter) {
    3231
    3332    }
  • icGREP/icgrep-devel/icgrep/pablo/pe_integer.h

    r5204 r5217  
    99    friend class SymbolGenerator;
    1010public:
    11     typedef u_int64_t Type;
     11
     12
    1213    static inline bool classof(const PabloAST * e) {
    1314        return e->getClassTypeId() == ClassTypeId::Integer;
     
    1920
    2021    }
    21     inline Type value() const {
     22    inline int64_t value() const {
    2223        return mValue;
    2324    }
    2425protected:
    25     Integer(Type value) noexcept
    26     : PabloAST(ClassTypeId::Integer, getScalarTy(), nullptr)
     26    Integer(const int64_t value, Type * type) noexcept
     27    : PabloAST(ClassTypeId::Integer, type, nullptr)
    2728    , mValue(value)
    2829    {
     
    3031    }
    3132private:
    32     Type mValue;
     33    int64_t mValue;
    3334};
    3435
  • icGREP/icgrep-devel/icgrep/pablo/pe_lookahead.h

    r5202 r5217  
    2828        return getOperand(0);
    2929    }
    30     inline Integer::Type getAmount() const {
     30    inline int64_t getAmount() const {
    3131        return cast<Integer>(getOperand(1))->value();
    3232    }
  • icGREP/icgrep-devel/icgrep/pablo/pe_ones.h

    r5202 r5217  
    1414class Ones : public PabloAST {
    1515    friend class PabloBlock;
    16     friend class PabloFunction;
     16    friend class PabloKernel;
    1717public:
    1818    static inline bool classof(const PabloAST * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_setithbit.h

    r5202 r5217  
    1919        return getOperand(0);
    2020    }
    21     inline Integer::Type position() const {
     21    inline int64_t pint64_tion() const {
    2222        return cast<Integer>(getOperand(1))->value();
    2323    }
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r5202 r5217  
    2323    friend class PabloBlock;
    2424    friend class PabloAST;
    25     friend class PabloFunction;
     25    friend class PabloKernel;
    2626    friend class Statement;
    2727public:
     
    5353        return getOperand(0);
    5454    }
    55     inline Integer * getIndex() const {
    56         return cast<Integer>(getOperand(1));
     55    inline PabloAST * getIndex() const {
     56        return getOperand(1);
    5757    }
    5858protected:
    59     Extract(PabloAST * array, PabloAST * const index, const String * const name)
    60     : Statement(ClassTypeId::Extract, cast<ArrayType>(array->getType())->getArrayElementType(), {array, cast<Integer>(index)}, name) {
     59    Extract(PabloAST * array, PabloAST * const index, const String * const name, Type * type)
     60    : Statement(ClassTypeId::Extract, type, {array, index}, name) {
    6161
    6262    }
    6363};
    64 
    65 //class Extract : public PabloAST {
    66 //    friend class PabloBlock;
    67 //public:
    68 //    static inline bool classof(const PabloAST * e) {
    69 //        return e->getClassTypeId() == ClassTypeId::Extract;
    70 //    }
    71 //    static inline bool classof(const void *) {
    72 //        return false;
    73 //    }
    74 //    virtual ~Extract(){
    75 //    }
    76 //    inline const String * getName() const {
    77 //        if (isa<Parameter>(mArray)) {
    78 //            return cast<Parameter>(mArray)->getName();
    79 //        } else {
    80 //            return cast<Statement>(mArray)->getName();
    81 //        }
    82 //    }
    83 //    inline const PabloAST * getArray() const {
    84 //        return mArray;
    85 //    }
    86 //    inline const Integer * getIndex() const {
    87 //        return mIndex;
    88 //    }
    89 //protected:
    90 //    Extract(PabloAST * array, PabloAST * const index)
    91 //    : PabloAST(ClassTypeId::Extract, array->getType()->getIndexedType())
    92 //    , mArray(array)
    93 //    , mIndex(cast<Integer>(index)) {
    94 //        assert (isa<Parameter>(array) || isa<Statement>(array));
    95 //    }
    96 //private:
    97 //    PabloAST * mArray;
    98 //    Integer * mIndex;
    99 //};
    100 
    101 //class ParameterBinding {
    102 //    using Allocator = SlabAllocator<Parameter *>;
    103 
    104 //public:
    105 
    106 //    void add(Parameter * const param);
    107 
    108 //private:
    109 //    std::vector<Parameter *, Allocator> mParameters;
    110 //};
    111 
    11264
    11365}
  • icGREP/icgrep-devel/icgrep/pablo/pe_zeroes.h

    r5202 r5217  
    1515class Zeroes : public PabloAST {
    1616    friend class PabloBlock;
    17     friend class PabloFunction;
     17    friend class PabloKernel;
    1818public:
    1919    static inline bool classof(const PabloAST * expr) {
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r5202 r5217  
    77#include "printer_pablos.h"
    88#include <pablo/codegenstate.h>
     9#include <pablo/pablo_kernel.h>
    910#include <llvm/Support/raw_os_ostream.h>
    10 #include <iostream>
    1111
    1212using namespace pablo;
     
    1616const unsigned BlockIndenting = 2;
    1717
    18 void PabloPrinter::print(const PabloFunction & function, llvm::raw_ostream & out) {
    19     print(function.getEntryBlock(), out, true);
     18void PabloPrinter::print(const PabloKernel * kernel, llvm::raw_ostream & out) {
     19    print(kernel->getEntryBlock(), out, true);
    2020}
    2121
     
    146146    } else if (isa<Prototype>(expr)) {
    147147        out << cast<Prototype>(expr)->getName();
    148     } else if (isa<PabloFunction>(expr)) {
    149         out << cast<PabloFunction>(expr)->getName();
    150148    } else {
    151149        out << "???";
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.h

    r5202 r5217  
    1212namespace pablo {
    1313
    14 class PabloFunction;
     14class PabloKernel;
    1515class PabloBlock;
    1616class Statement;
     
    1919class PabloPrinter {
    2020public:
    21     static void print(const PabloFunction & function, llvm::raw_ostream & out);
     21    static void print(const PabloKernel * kernel, llvm::raw_ostream & out);
    2222    static void print(const PabloAST * expr, llvm::raw_ostream & out);
    2323    static void print(const PabloBlock * block, llvm::raw_ostream & strm, const bool expandNested = false, const unsigned indent = 0);
  • icGREP/icgrep-devel/icgrep/pablo/prototype.cpp

    r5216 r5217  
    1 #include "function.h"
     1#include "prototype.h"
    22#include <pablo/codegenstate.h>
    33#include <cstring>
     
    1313}
    1414
    15 PabloFunction::PabloFunction(std::string && name)
    16 : Prototype(ClassTypeId::Function, std::move(name), 0, 0)
    17 , mSymbolTable(new SymbolGenerator())
    18 , mEntryBlock(PabloBlock::Create(*this))
    19 , mConstants(0, nullptr) {
    20 
    2115}
    22 
    23 Var * PabloFunction::addParameter(const std::string name, Type * const type) {
    24     Var * param = new Var(mSymbolTable->make(name), type);
    25     mParameters.push_back(param);
    26     mNumOfParameters = mParameters.size();
    27     return param;
    28 }
    29 
    30 Var * PabloFunction::addResult(const std::string name, Type * const type) {
    31     Var * result = new Var(mSymbolTable->make(name), type);
    32     mResults.push_back(result);
    33     mNumOfResults = mResults.size();
    34     return result;
    35 }
    36 
    37 Var * PabloFunction::makeVariable(PabloAST * name, Type * const type) {
    38     Var * const var = new Var(name, type);
    39     mVariables.push_back(var);
    40     return var;
    41 }
    42 
    43 Zeroes * PabloFunction::getNullValue(Type * type) {
    44     if (type == nullptr) {
    45         type = getStreamTy();
    46     }
    47     for (PabloAST * constant : mConstants) {
    48         if (isa<Zeroes>(constant) && constant->getType() == type) {
    49             return cast<Zeroes>(constant);
    50         }
    51     }
    52     Zeroes * value = new Zeroes(type);
    53     mConstants.push_back(value);
    54     return value;
    55 }
    56 
    57 Ones * PabloFunction::getAllOnesValue(Type * type) {
    58     if (type == nullptr) {
    59         type = getStreamTy();
    60     }
    61     for (PabloAST * constant : mConstants) {
    62         if (isa<Ones>(constant) && constant->getType() == type) {
    63             return cast<Ones>(constant);
    64         }
    65     }
    66     Ones * value = new Ones(type);
    67     mConstants.push_back(value);
    68     return value;
    69 }
    70 
    71 void PabloFunction::throwInvalidParameterIndex(const unsigned index) const {
    72     throw std::runtime_error(
    73                 "Invalid parameter index " +
    74                 std::to_string(index) + " of " + std::to_string(getNumOfParameters()) +
    75                 " in function " + getName()->to_string());
    76 }
    77 
    78 void PabloFunction::throwInvalidResultIndex(const unsigned index) const {
    79     throw std::runtime_error(
    80                 "Invalid result index " +
    81                 std::to_string(index) + " of " + std::to_string(getNumOfResults()) +
    82                 " in function " + getName()->to_string());
    83 }
    84 
    85 void PabloFunction::operator delete(void * ptr) {
    86     PabloFunction * f = static_cast<PabloFunction *>(ptr);
    87     delete f->mSymbolTable;
    88     f->mSymbolTable = nullptr;
    89 }
    90 
    91 }
  • icGREP/icgrep-devel/icgrep/pablo/prototype.h

    r5216 r5217  
    5050}
    5151
    52 class PabloFunction : public Prototype {
    53     friend class PabloBlock;
    54     friend class Branch;
    55     using Allocator = SlabAllocator<PabloAST *>;
    56 public:
    57 
    58     static inline bool classof(const PabloAST * e) {
    59         switch (e->getClassTypeId()) {
    60             case ClassTypeId::Function:
    61             case ClassTypeId::Prototype:
    62                 return true;
    63             default:
    64                 return false;
    65         }       
    66     }
    67 
    68     static inline bool classof(void *) {
    69         return false;
    70     }
    71 
    72     static PabloFunction * Create(std::string name);
    73    
    74     virtual bool operator==(const PabloAST & other) const {
    75         return &other == this;
    76     }
    77 
    78     PabloBlock * getEntryBlock() {
    79         return mEntryBlock;
    80     }
    81 
    82     const PabloBlock * getEntryBlock() const {
    83         return mEntryBlock;
    84     }
    85 
    86     PabloBlock * setEntryBlock(PabloBlock * entryBlock) {
    87         assert (entryBlock);
    88         std::swap(mEntryBlock, entryBlock);
    89         return entryBlock;
    90     }
    91 
    92     Var * getParameter(const unsigned index) {
    93         return static_cast<Var *>(mParameters[index]);
    94     }
    95 
    96     const Var * getParameter(const unsigned index) const {
    97         return static_cast<Var *>(mParameters[index]);
    98     }
    99 
    100     Var * addParameter(const std::string name, Type * const type);
    101 
    102     Var * getResult(const unsigned index) {
    103         return static_cast<Var *>(mResults[index]);
    104     }
    105 
    106     const Var * getResult(const unsigned index) const {
    107         return static_cast<Var *>(mResults[index]);
    108     }
    109 
    110     Var * addResult(const std::string name, Type * const type);
    111 
    112     Var * makeVariable(PabloAST * name, Type * const type);
    113 
    114     Var * getVariable(const unsigned index) {
    115         return static_cast<Var *>(mVariables[index]);
    116     }
    117 
    118     unsigned getNumOfVariables() {
    119         return mVariables.size();
    120     }
    121 
    122     Zeroes * getNullValue(Type * const type);
    123 
    124     Ones * getAllOnesValue(Type * const type);
    125 
    126     void operator delete (void*);
    127 
    128     virtual ~PabloFunction() { }
    129 
    130     inline SymbolGenerator * getSymbolTable() const {
    131         return mSymbolTable;
    132     }
    133 
    134 protected:
    135 
    136     __attribute__((noreturn)) void throwInvalidParameterIndex(const unsigned index) const;
    137 
    138     __attribute__((noreturn)) void throwInvalidResultIndex(const unsigned index) const;
    139 
    140     PabloFunction(std::string && name);
    141 private:
    142     SymbolGenerator *                           mSymbolTable;
    143     PabloBlock *                                mEntryBlock;
    144     std::vector<PabloAST *, Allocator>          mParameters;
    145     std::vector<PabloAST *, Allocator>          mResults;
    146     std::vector<PabloAST *, Allocator>          mConstants;
    147     std::vector<PabloAST *, Allocator>          mVariables;
    148 };
    149 
    150 inline PabloFunction * PabloFunction::Create(std::string name) {
    151     return new PabloFunction(std::move(name));
    152 }
    153    
    15452}
    15553
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp

    r5202 r5217  
    88#include <pablo/pe_string.h>
    99#include <pablo/pe_integer.h>
     10#include <IDISA/idisa_builder.h>
    1011
    1112namespace pablo {
     
    2829}
    2930
    30 Integer * SymbolGenerator::getInteger(const integer_t value) {
     31Integer * SymbolGenerator::getInteger(const integer_t value, IDISA::IDISA_Builder * builder) {
    3132    auto f = mIntegerMap.find(value);
    3233    Integer * result;
    3334    if (f == mIntegerMap.end()) {
    34         result = new Integer(value);
     35        result = new Integer(value, builder->getSizeTy());
    3536        assert (result->value() == value);
    3637        mIntegerMap.insert(std::make_pair(value, result));
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.h

    r5202 r5217  
    99
    1010#include <pablo/pabloAST.h>
     11#include <unordered_map>
    1112#include <string>
    12 #include <unordered_map>
    13 #include <llvm/ADT/Twine.h>
    14 #include <llvm/ADT/StringMap.h>
    15 #include <llvm/Support/StringPool.h>
     13
     14namespace IDISA {
     15    class IDISA_Builder;
     16}
    1617
    1718namespace pablo {
     
    2425    using Twine = llvm::Twine;
    2526public:
    26     typedef u_int64_t integer_t;
     27    typedef int64_t integer_t;
    2728    String * get(const std::string name);
    2829    String * make(const std::string prefix);
    29     Integer * getInteger(const integer_t value);
     30    Integer * getInteger(const integer_t value, IDISA::IDISA_Builder * builder);
    3031    SymbolGenerator() = default;
    3132    ~SymbolGenerator() = default;
     
    3637};
    3738
    38 static SymbolGenerator GlobalSymbolGenerator;
    39 
    4039}
    4140
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5204 r5217  
    2323#include <re/printer_re.h>
    2424#include <pablo/codegenstate.h>
     25#include <pablo/pablo_kernel.h>
    2526#include <UCD/ucd_compiler.hpp>
    2627#include <UCD/resolve_properties.h>
     
    235236    PabloAST * matches = mPB.createAnd(match_follow, mLineBreak, "matches");
    236237    if (mCountOnly) {
    237         Var * const output = mFunction.addResult("matchedLineCount", getScalarTy());
     238        Var * const output = mKernel->addOutput("matchedLineCount", mKernel->getSizeTy());
    238239        PabloBuilder nestedCount = PabloBuilder::Create(mPB);
    239240        mPB.createIf(matches, nestedCount);
    240241        nestedCount.createAssign(output, nestedCount.createCount(matches));
    241242    } else {
    242         Var * const output = mFunction.addResult("output", getStreamTy(1, 2));
     243        Var * const output = mKernel->addOutput("output", mKernel->getStreamSetTy(2));
    243244        mPB.createAssign(mPB.createExtract(output, mPB.getInteger(0)), matches);
    244245        mPB.createAssign(mPB.createExtract(output, mPB.getInteger(1)), mLineBreak);
     
    629630}
    630631
    631 RE_Compiler::RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler, bool CountOnly)
    632 : mCountOnly(CountOnly)
     632RE_Compiler::RE_Compiler(PabloKernel * kernel, cc::CC_Compiler & ccCompiler, bool CountOnly)
     633: mKernel(kernel)
     634, mCountOnly(CountOnly)
    633635, mCCCompiler(ccCompiler)
    634636, mLineBreak(nullptr)
     
    641643, mWhileTest(nullptr)
    642644, mStarDepth(0)
    643 , mPB(ccCompiler.getBuilder())
    644 , mFunction(function) {
     645, mPB(ccCompiler.getBuilder()) {
    645646
    646647}
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r5202 r5217  
    5252public:
    5353
    54     RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler, bool CountOnly = false);
     54    RE_Compiler(pablo::PabloKernel * kernel, cc::CC_Compiler & ccCompiler, bool CountOnly = false);
    5555    void initializeRequiredStreams(const unsigned encodingBits);
    5656    void compileUnicodeNames(RE *& re);
     
    9393private:
    9494
     95    pablo::PabloKernel * const                      mKernel;
    9596    bool                                            mCountOnly;
    9697    cc::CC_Compiler &                               mCCCompiler;
     
    106107    pablo::PabloBuilder &                           mPB;
    107108    std::unordered_map<Name *, MarkerType>          mCompiledName;
    108     pablo::PabloFunction &                          mFunction;
     109
    109110};
    110111
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5202 r5217  
    1818#include <utf8_encoder.h>
    1919#include <cc/cc_compiler.h>
    20 #include <pablo/function.h>
     20#include <pablo/prototype.h>
     21#include <pablo/pablo_kernel.h>
    2122#include <re/printer_re.h>
    2223#include <llvm/Support/CommandLine.h>
     
    9596}
    9697   
    97 PabloFunction * re2pablo_compiler(const unsigned encodingBits, RE * re_ast, const bool CountOnly) {
    98     PabloFunction * function = PabloFunction::Create("process_block");
    99     cc::CC_Compiler cc_compiler(*function, encodingBits);
    100     re::RE_Compiler re_compiler(*function, cc_compiler, CountOnly);
     98void re2pablo_compiler(PabloKernel * kernel, const unsigned encodingBits, RE * re_ast, const bool CountOnly) {
     99    cc::CC_Compiler cc_compiler(kernel, encodingBits);
     100    re::RE_Compiler re_compiler(kernel, cc_compiler, CountOnly);
    101101    re_compiler.initializeRequiredStreams(encodingBits);
    102102    re_compiler.compileUnicodeNames(re_ast);
    103103    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast), AlgorithmOptions.isSet(InvertMatches));
    104     return function;
    105104}
    106105
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.h

    r5202 r5217  
    88#define RE_TOOLCHAIN_H
    99
    10 #include <re/re_re.h>
    11 #include <pablo/function.h>
    1210#include <llvm/Support/CommandLine.h>
    1311
     12namespace pablo {
     13    class PabloKernel;
     14}
     15
    1416namespace re {
     17
     18class RE;
    1519
    1620enum RE_PrintFlags {
     
    2731extern int IfInsertionGap;
    2832
    29 const cl::OptionCategory * re_toolchain_flags();
     33const llvm::cl::OptionCategory * re_toolchain_flags();
    3034
    3135RE * regular_expression_passes(RE * re_ast);
    3236
    33 pablo::PabloFunction * re2pablo_compiler(const unsigned encodingBits, RE * re_ast, const bool CountOnly = false);
     37void re2pablo_compiler(pablo::PabloKernel * kernel, const unsigned encodingBits, RE * re_ast, const bool CountOnly = false);
    3438   
    3539}
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5202 r5217  
    2626#include <pablo/pablo_toolchain.h>
    2727#include <pablo/pablo_kernel.h>
    28 #include <pablo/function.h>
     28#include <pablo/prototype.h>
    2929#include <IDISA/idisa_builder.h>
    3030#include <IDISA/idisa_target.h>
     
    5454static cl::opt<bool> memAlignBuffering("memalign-buffering", cl::desc("Enable posix_memalign buffering."), cl::cat(u8u16Options));
    5555
    56 //
    57 //
    58 //
    59 namespace pablo {
    60 
    61 PabloFunction * u8u16_pablo() {
     56
     57using namespace pablo;
     58using namespace kernel;
     59using namespace parabix;
     60
     61void u8u16_pablo(PabloKernel * kernel) {
    6262    //  input: 8 basis bit streams
    6363    //  output: 16 u8-indexed streams, + delmask stream + error stream
    64     PabloFunction * function = PabloFunction::Create("u8u16"); // , 1, 18
    65     cc::CC_Compiler ccc(*function);
     64
     65    cc::CC_Compiler ccc(kernel);
    6666   
    6767    PabloBuilder & main = ccc.getBuilder();
     
    8181    Var * delmask = main.createVar("delmask", zeroes);
    8282    Var * error_mask = main.createVar("error_mask", zeroes);
    83 
    84 
    8583
    8684    // The logic for processing non-ASCII bytes will be embedded within an if-hierarchy.
     
    245243    main.createAssign(u16_lo[7], main.createOr(main.createAnd(last_byte, u8_bits[7]), s43_lo7));
    246244   
    247     Var * output = function->addResult("output", getStreamTy(1, 18));
     245    Var * output = kernel->addOutput("output", kernel->getStreamSetTy(16));
     246    Var * delmask_out = kernel->addOutput("delmask_out", kernel->getStreamSetTy());
     247    Var * error_mask_out = kernel->addOutput("error_mask_out", kernel->getStreamSetTy());
    248248    for (unsigned i = 0; i < 8; i++) {
    249249        main.createAssign(main.createExtract(output, i), u16_hi[i]);
     
    252252        main.createAssign(main.createExtract(output, i + 8), u16_lo[i]);
    253253    }
    254     main.createAssign(main.createExtract(output, 16), delmask);
    255     main.createAssign(main.createExtract(output, 17), error_mask);
    256 
    257     return function;
     254    main.createAssign(main.createExtract(delmask_out, main.getInteger(0)), delmask);
     255    main.createAssign(main.createExtract(error_mask_out,  main.getInteger(0)), error_mask);
     256
     257    pablo_function_passes(kernel);
    258258}
    259 }
    260 
    261 
    262 
    263 using namespace kernel;
    264 using namespace parabix;
    265 
    266 Function * u8u16Pipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
    267     Type * mBitBlockType = iBuilder->getBitBlockType();
     259
     260Function * u8u16Pipeline(Module * mod, IDISA::IDISA_Builder * iBuilder) {
    268261
    269262    const unsigned segmentSize = codegen::SegmentSize;
    270263    const unsigned bufferSegments = codegen::BufferSegments;
    271264   
    272     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
    273 
    274     CircularBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1), segmentSize * bufferSegments);
    275 
    276     CircularBuffer U8u16Bits(iBuilder, StreamSetType(iBuilder, 18, 1), segmentSize * bufferSegments);
    277 
    278     CircularBuffer U16Bits(iBuilder, StreamSetType(iBuilder,16, 1), segmentSize * bufferSegments);
    279    
    280     CircularBuffer DeletionCounts(iBuilder, StreamSetType(iBuilder, 1, 1), segmentSize * bufferSegments);
     265    assert (iBuilder);
     266
     267    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     268
     269    CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
     270
     271    CircularBuffer U8u16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
     272    CircularBuffer DelMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
     273    CircularBuffer ErrorMask(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
     274
     275    CircularBuffer U16Bits(iBuilder, iBuilder->getStreamSetTy(16), segmentSize * bufferSegments);
     276   
     277    CircularBuffer DeletionCounts(iBuilder, iBuilder->getStreamSetTy(), segmentSize * bufferSegments);
    281278
    282279    // Different choices for the output buffer depending on chosen option.
    283     ExternalFileBuffer U16external(iBuilder, StreamSetType(iBuilder,1, 16));
    284     LinearCopybackBuffer U16out(iBuilder, StreamSetType(iBuilder,1, 16), segmentSize * bufferSegments + 2);
    285 
    286     s2pKernel  s2pk(iBuilder);
     280    ExternalFileBuffer U16external(iBuilder, iBuilder->getStreamSetTy(1, 16));
     281    LinearCopybackBuffer U16out(iBuilder, iBuilder->getStreamSetTy(16, 16), segmentSize * bufferSegments + 2);
     282
     283    s2pKernel s2pk(iBuilder);
     284
    287285    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    288286
    289     pablo_function_passes(function);
    290     pablo::PabloKernel u8u16k(iBuilder, "u8u16", function);
    291     u8u16k.generateKernel({&BasisBits}, {&U8u16Bits});
    292    
     287    pablo::PabloKernel u8u16k(iBuilder, "u8u16");
     288
     289    u8u16_pablo(&u8u16k);
     290
     291    u8u16k.generateKernel({&BasisBits}, {&U8u16Bits, &DelMask, &ErrorMask});
     292
    293293    DeletionKernel delK(iBuilder, iBuilder->getBitBlockWidth()/16, 16);
    294     delK.generateKernel({&U8u16Bits}, {&U16Bits, &DeletionCounts});
    295    
     294    delK.generateKernel({&U8u16Bits, &DelMask}, {&U16Bits, &DeletionCounts});
     295
    296296    p2s_16Kernel_withCompressedOutput p2sk(iBuilder);
    297    
     297
    298298    stdOutKernel stdoutK(iBuilder, 16);
    299    
     299
    300300    if (mMapBuffering || memAlignBuffering) {
    301301        p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16external});
    302302        stdoutK.generateKernel({&U16external}, {});
    303     }
    304     else {
     303    } else {
    305304        p2sk.generateKernel({&U16Bits, &DeletionCounts}, {&U16out});
    306305        stdoutK.generateKernel({&U16out}, {});
    307306    }
    308    
     307
    309308    Type * const size_ty = iBuilder->getSizeTy();
    310     Type * const voidTy = Type::getVoidTy(mMod->getContext());
    311     Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
    312     Type * const outputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 16), 1), 0);
     309    Type * const voidTy = Type::getVoidTy(mod->getContext());
     310    Type * const bitBlockType = iBuilder->getBitBlockType();
     311    Type * const inputType = ArrayType::get(ArrayType::get(bitBlockType, 8), 1)->getPointerTo();
     312    Type * const outputType = ArrayType::get(ArrayType::get(bitBlockType, 16), 1)->getPointerTo();
    313313    Type * const int32ty = iBuilder->getInt32Ty();
    314314    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    315     Type * const voidPtrTy = TypeBuilder<void *, false>::get(mMod->getContext());
    316 
    317    
    318     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, outputType, size_ty, nullptr));
     315    Type * const voidPtrTy = Type::getVoidTy(mod->getContext())->getPointerTo();
     316
     317    Function * const main = cast<Function>(mod->getOrInsertFunction("Main", voidTy, inputType, outputType, size_ty, nullptr));
    319318    main->setCallingConv(CallingConv::C);
    320319    Function::arg_iterator args = main->arg_begin();
    321    
     320
    322321    Value * const inputStream = &*(args++);
    323322    inputStream->setName("inputStream");
     
    326325    Value * const fileSize = &*(args++);
    327326    fileSize->setName("fileSize");
    328    
    329     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    330        
     327
     328    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
    331329
    332330    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    333331    BasisBits.allocateBuffer();
    334332    U8u16Bits.allocateBuffer();
     333    DelMask.allocateBuffer();
     334    ErrorMask.allocateBuffer();
    335335    U16Bits.allocateBuffer();
    336336    DeletionCounts.allocateBuffer();
    337337    if (mMapBuffering || memAlignBuffering) {
    338338        U16external.setEmptyBuffer(outputStream);
    339     }
    340     else {
     339    } else {
    341340        U16out.allocateBuffer();
    342341    }
     
    346345    Value * p2sInstance = p2sk.createInstance({});
    347346    Value * stdoutInstance = stdoutK.createInstance({});
    348    
     347
    349348    Type * pthreadTy = size_ty;
    350349    FunctionType * funVoidPtrVoidTy = FunctionType::get(voidTy, int8PtrTy, false);
    351    
    352     Function * pthreadCreateFunc = cast<Function>(mMod->getOrInsertFunction("pthread_create",
     350
     351    Function * pthreadCreateFunc = cast<Function>(mod->getOrInsertFunction("pthread_create",
    353352                                                                         int32ty,
    354353                                                                         pthreadTy->getPointerTo(),
     
    357356                                                                         voidPtrTy, nullptr));
    358357    pthreadCreateFunc->setCallingConv(llvm::CallingConv::C);
    359     Function * pthreadJoinFunc = cast<Function>(mMod->getOrInsertFunction("pthread_join",
     358    Function * pthreadJoinFunc = cast<Function>(mod->getOrInsertFunction("pthread_join",
    360359                                                                       int32ty,
    361360                                                                       pthreadTy,
    362361                                                                       PointerType::get(int8PtrTy, 0), nullptr));
    363362    pthreadJoinFunc->setCallingConv(llvm::CallingConv::C);
    364    
    365     Function * pthreadExitFunc = cast<Function>(mMod->getOrInsertFunction("pthread_exit",
    366                                                                        voidTy, 
     363
     364    Function * pthreadExitFunc = cast<Function>(mod->getOrInsertFunction("pthread_exit",
     365                                                                       voidTy,
    367366                                                                       voidPtrTy, nullptr));
    368367    pthreadExitFunc->addFnAttr(llvm::Attribute::NoReturn);
     
    371370    if (segmentPipelineParallel){
    372371        generateSegmentParallelPipeline(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
    373     }
    374     else{
     372    } else {
    375373        generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
    376374    }
     
    393391    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    394392
    395     pablo::PabloFunction * function = pablo::u8u16_pablo();
    396    
    397     llvm::Function * main_IR = u8u16Pipeline(M, idb, function);
     393    llvm::Function * main_IR = u8u16Pipeline(M, idb);
    398394   
    399395    verifyModule(*M, &dbgs());
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5202 r5217  
    2525#include <re/re_cc.h>
    2626#include <cc/cc_compiler.h>
    27 #include <pablo/function.h>
     27#include <pablo/prototype.h>
    2828#include <pablo/pablo_kernel.h>
    2929#include <IDISA/idisa_builder.h>
     
    4343
    4444#include <fcntl.h>
    45 using namespace pablo;
    4645
    4746static cl::OptionCategory wcFlags("Command Flags", "wc options");
     
    8079uint64_t TotalBytes = 0;
    8180
     81using namespace pablo;
     82using namespace kernel;
     83using namespace parabix;
    8284
    8385//  The callback routine that records counts in progress.
     
    99101//
    100102
    101 PabloFunction * wc_gen() {
     103void wc_gen(PabloKernel * kernel) {
    102104    //  input: 8 basis bit streams
    103105    //  output: 3 counters
    104106   
    105     PabloFunction * function = PabloFunction::Create("wc"); // , 8, 0
    106     cc::CC_Compiler ccc(*function);
     107    cc::CC_Compiler ccc(kernel);
    107108   
    108109    PabloBuilder & pb = ccc.getBuilder();
    109     // const std::vector<Parameter *> u8_bits = ccc.getBasisBits();
    110 
    111     Var * lc = function->addResult("lineCount", getScalarTy());
    112     Var * wc = function->addResult("wordCount", getScalarTy());
    113     Var * cc = function->addResult("charCount", getScalarTy());
     110
     111    Var * lc = kernel->addOutput("lineCount", kernel->getSizeTy());
     112    Var * wc = kernel->addOutput("wordCount", kernel->getSizeTy());
     113    Var * cc = kernel->addOutput("charCount", kernel->getSizeTy());
    114114
    115115    if (CountLines) {
     
    133133        pb.createAssign(cc, pb.createCount(u8Begin));
    134134    }
    135     return function;
    136 }
    137 
    138 using namespace kernel;
    139 using namespace parabix;
    140 
    141 
    142 Function * wcPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
     135}
     136
     137Function * wcPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder) {
    143138    Type * mBitBlockType = iBuilder->getBitBlockType();
    144139   
    145     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
    146     SingleBlockBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1));
    147     //CircularBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1), codegen::SegmentSize * codegen::BufferSegments);
     140    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     141
     142    SingleBlockBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8, 1));
    148143
    149144    s2pKernel  s2pk(iBuilder);
    150145    std::unique_ptr<Module> s2pM = s2pk.createKernelModule({&ByteStream}, {&BasisBits});
    151146   
    152     pablo_function_passes(function);
    153     PabloKernel wck(iBuilder, "wc", function);
     147    PabloKernel wck(iBuilder, "wc");
     148    wc_gen(&wck);
     149    pablo_function_passes(&wck);
    154150   
    155151    std::unique_ptr<Module> wcM = wck.createKernelModule({&BasisBits}, {});
     
    209205    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    210206
    211     PabloFunction * function = wc_gen();
    212     llvm::Function * main_IR = wcPipeline(M, idb, function);
     207    llvm::Function * main_IR = wcPipeline(M, idb);
    213208
    214209    wcEngine = JIT_to_ExecutionEngine(M);
Note: See TracChangeset for help on using the changeset viewer.