Ignore:
Timestamp:
May 3, 2017, 1:13:04 PM (2 years ago)
Author:
nmedfort
Message:

partial refactoring check in with change for Linda.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5392 r5431  
    8282
    8383DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount)
    84 : BlockOrientedKernel(iBuilder, "Parabix:del" + std::to_string(fw) + "_" + std::to_string(streamCount),
     84: BlockOrientedKernel(iBuilder, "del" + std::to_string(fw) + "_" + std::to_string(streamCount),
    8585              {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    8686               Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     
    225225
    226226DeleteByPEXTkernel::DeleteByPEXTkernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle)
    227     : BlockOrientedKernel(iBuilder, "Parabix:PEXTdel" + std::to_string(fw) + "_" + std::to_string(streamCount) + (shouldSwizzle ? "swiz" : "noswiz"),
     227    : BlockOrientedKernel(iBuilder, "PEXTdel" + std::to_string(fw) + "_" + std::to_string(streamCount) + (shouldSwizzle ? "swiz" : "noswiz"),
    228228                      {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    229229                          Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     
    265265
    266266SwizzledBitstreamCompressByCount::SwizzledBitstreamCompressByCount(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned fieldWidth)
    267     : BlockOrientedKernel(iBuilder, "Parabix:swizzled_compress" + std::to_string(fieldWidth) + "_" + std::to_string(bitStreamCount),
     267    : BlockOrientedKernel(iBuilder, "swizzled_compress" + std::to_string(fieldWidth) + "_" + std::to_string(bitStreamCount),
    268268                         {Binding{iBuilder->getStreamSetTy(), "countsPerStride"}}, {}, {}, {}, {})
    269269, mBitStreamCount(bitStreamCount)
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5392 r5431  
    2323namespace kernel {
    2424
    25 class DeletionKernel : public BlockOrientedKernel {
     25class DeletionKernel final : public BlockOrientedKernel {
    2626public:
    27 
    2827    DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount);
    29     bool moduleIDisSignature() override {return true;}
    30 
     28    bool isCachable() const override { return true; }
     29    bool moduleIDisSignature() const override { return true; }
    3130protected:
    3231    void generateDoBlockMethod() override;
    33 
    3432    void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
    35 
    3633private:
    3734    const unsigned mDeletionFieldWidth;
     
    3936};
    4037
    41 class DeleteByPEXTkernel : public BlockOrientedKernel {
     38class DeleteByPEXTkernel final : public BlockOrientedKernel {
    4239public:
    43 
    4440    DeleteByPEXTkernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
    45     bool moduleIDisSignature() override {return true;}
    46    
     41    bool isCachable() const override { return true; }
     42    bool moduleIDisSignature() const override { return true; }
    4743protected:
    4844    void generateDoBlockMethod() override;
    49    
    5045    void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
    51 
    5246    void generatePEXTAndSwizzleLoop(const std::vector<llvm::Value *> & masks);
    53 
    5447    void generatePEXTLoop(const std::vector<llvm::Value *> & masks);
    55 
    56     void generateProcessingLoop(const std::vector<llvm::Value *> & masks, llvm::Value * delMask);
    57    
     48    void generateProcessingLoop(const std::vector<llvm::Value *> & masks, llvm::Value * delMask);   
    5849private:
    5950    const unsigned mDelCountFieldWidth;
     
    6455};
    6556   
    66 class SwizzledBitstreamCompressByCount : public BlockOrientedKernel {
     57class SwizzledBitstreamCompressByCount final : public BlockOrientedKernel {
    6758public:
    68    
    6959    SwizzledBitstreamCompressByCount(IDISA::IDISA_Builder * iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
    70     bool moduleIDisSignature() override {return true;}
    71    
     60    bool isCachable() const override { return true; }
     61    bool moduleIDisSignature() const override { return true; }
    7262protected:
    7363    void generateDoBlockMethod() override;
    74    
    75     void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
    76    
     64    void generateFinalBlockMethod(llvm::Value * remainingBytes) override;   
    7765private:
    7866    const unsigned mBitStreamCount;
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp

    r5413 r5431  
    2929}
    3030
    31 inline std::string makeSignature(RE * const re_ast) {
    32     std::string signature = Printer_RE::PrintRE(re_ast);
    33     return signature;
    34 }
    35 
    36 ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re_ast)
     31ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re)
    3732: PabloKernel(iBuilder, "",
    3833              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
     
    4035              {},
    4136              {})
    42 , mRE(re_ast)
    43 , mSignature(makeSignature(re_ast)) {
    44     setName("Parabix:" + sha1sum(mSignature));
     37, mRE(re)
     38, mSignature(Printer_RE::PrintRE(re)) {
     39    setName(sha1sum(mSignature));
    4540}
    4641
    47 std::string ICgrepKernelBuilder::generateKernelSignature(std::string moduleId) {
     42std::string ICgrepKernelBuilder::makeSignature() {
    4843    return mSignature;
    4944}
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.h

    r5413 r5431  
    1616    ICgrepKernelBuilder(IDISA::IDISA_Builder * const iBuilder, re::RE * const re_ast);
    1717   
    18     std::string generateKernelSignature(std::string moduleId) override;
    19    
     18    std::string makeSignature() override;
     19    bool isCachable() const override { return true; }
     20
    2021    void prepareKernel() override;
    2122
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5425 r5431  
    6868}
    6969
    70 void KernelInterface::addKernelDeclarations(Module * const client) {
    71     Module * const saveModule = iBuilder->getModule();
    72     iBuilder->setModule(client);
     70void KernelInterface::addKernelDeclarations() {
     71
    7372    if (mKernelStateType == nullptr) {
    7473        throw std::runtime_error("Kernel interface " + getName() + " not yet finalized.");
    7574    }
     75
     76    Module * const module = iBuilder->getModule();
    7677    PointerType * const selfType = mKernelStateType->getPointerTo();
    7778    IntegerType * const sizeTy = iBuilder->getSizeTy();
     
    8081
    8182    // Create the initialization function prototype
    82     std::vector<Type *> initParameters = {selfType};   
     83    std::vector<Type *> initParameters = {selfType};
    8384    for (auto binding : mScalarInputs) {
    8485        initParameters.push_back(binding.type);
     
    8788
    8889    FunctionType * const initType = FunctionType::get(voidTy, initParameters, false);
    89     Function * const initFunc = Function::Create(initType, GlobalValue::ExternalLinkage, getName() + INIT_SUFFIX, client);
     90    Function * const initFunc = Function::Create(initType, GlobalValue::ExternalLinkage, getName() + INIT_SUFFIX, module);
    9091    initFunc->setCallingConv(CallingConv::C);
    9192    initFunc->setDoesNotThrow();
     
    104105
    105106    FunctionType * const doSegmentType = FunctionType::get(voidTy, params, false);
    106     Function * const doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, getName() + DO_SEGMENT_SUFFIX, client);
     107    Function * const doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, getName() + DO_SEGMENT_SUFFIX, module);
    107108    doSegment->setCallingConv(CallingConv::C);
    108109    doSegment->setDoesNotThrow();
    109     doSegment->setDoesNotCapture(1); // for self parameter only.   
     110    doSegment->setDoesNotCapture(1); // for self parameter only.
    110111    args = doSegment->arg_begin();
    111112    args->setName("self");
     
    132133    }
    133134    FunctionType * const terminateType = FunctionType::get(resultType, {selfType}, false);
    134     Function * const terminateFunc = Function::Create(terminateType, GlobalValue::ExternalLinkage, getName() + TERMINATE_SUFFIX, client);
     135    Function * const terminateFunc = Function::Create(terminateType, GlobalValue::ExternalLinkage, getName() + TERMINATE_SUFFIX, module);
    135136    terminateFunc->setCallingConv(CallingConv::C);
    136137    terminateFunc->setDoesNotThrow();
     
    140141
    141142    linkExternalMethods();
    142 
    143     iBuilder->setModule(saveModule);
    144143}
    145144
     
    148147}
    149148
    150 Function * KernelInterface::getInitFunction() const {
     149Function * KernelInterface::getInitFunction(Module * const module) const {
    151150    const auto name = getName() + INIT_SUFFIX;
    152     Function * f = iBuilder->getModule()->getFunction(name);
     151    Function * f = module->getFunction(name);
    153152    if (LLVM_UNLIKELY(f == nullptr)) {
    154153        llvm::report_fatal_error("Cannot find " + name);
     
    157156}
    158157
    159 Function * KernelInterface::getDoSegmentFunction() const {
     158Function * KernelInterface::getDoSegmentFunction(llvm::Module * const module) const {
    160159    const auto name = getName() + DO_SEGMENT_SUFFIX;
    161     Function * f = iBuilder->getModule()->getFunction(name);
     160    Function * f = module->getFunction(name);
    162161    if (LLVM_UNLIKELY(f == nullptr)) {
    163162        llvm::report_fatal_error("Cannot find " + name);
     
    166165}
    167166
    168 Function * KernelInterface::getTerminateFunction() const {
     167Function * KernelInterface::getTerminateFunction(Module * const module) const {
    169168    const auto name = getName() + TERMINATE_SUFFIX;
    170     Function * f = iBuilder->getModule()->getFunction(name);
     169    Function * f = module->getFunction(name);
    171170    if (LLVM_UNLIKELY(f == nullptr)) {
    172171        llvm::report_fatal_error("Cannot find " + name);
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5425 r5431  
    8282    void setName(std::string newName) { mKernelName = newName; }
    8383       
     84    virtual bool isCachable() const = 0;
     85
     86    virtual std::string makeSignature() = 0;
     87
    8488    const std::vector<Binding> & getStreamInputs() const { return mStreamSetInputs; }
    8589
     
    9195       
    9296    // Add ExternalLinkage method declarations for the kernel to a given client module.
    93     void addKernelDeclarations(llvm::Module * client);
     97    void addKernelDeclarations();
     98
     99    virtual void linkExternalMethods() = 0;
    94100
    95101    virtual llvm::Value * createInstance() = 0;
     
    109115    }
    110116   
    111     IDISA::IDISA_Builder * getBuilder() const {
    112         return iBuilder;
    113     }
    114 
    115117    virtual llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr) const = 0;
    116118
     
    133135    }
    134136
    135     llvm::Function * getInitFunction() const;
     137    IDISA::IDISA_Builder * getBuilder() const {
     138        return iBuilder;
     139    }
    136140
    137     llvm::Function * getDoSegmentFunction() const;
    138 
    139     llvm::Function * getTerminateFunction() const;
     141    void setBuilder(IDISA::IDISA_Builder * const builder) {
     142        iBuilder = builder;
     143    }
    140144
    141145protected:
    142146
    143     virtual void linkExternalMethods() = 0;
     147    llvm::Function * getInitFunction(llvm::Module * const module) const;
    144148
    145     KernelInterface(IDISA::IDISA_Builder * builder,
     149    llvm::Function * getDoSegmentFunction(llvm::Module * const module) const;
     150
     151    llvm::Function * getTerminateFunction(llvm::Module * const module) const;
     152
     153    KernelInterface(IDISA::IDISA_Builder * const builder,
    146154                    std::string kernelName,
    147155                    std::vector<Binding> && stream_inputs,
     
    172180protected:
    173181   
    174     IDISA::IDISA_Builder * const    iBuilder;
     182    IDISA::IDISA_Builder *          iBuilder;
    175183    llvm::Value *                   mKernelInstance;
    176184    llvm::StructType *              mKernelStateType;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5429 r5431  
    136136
    137137void KernelBuilder::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs) {
    138 
     138    std::stringstream cacheName;
     139    cacheName << getName() << '_' << iBuilder->getBuilderUniqueName();
     140    for (const StreamSetBuffer * b: inputs) {
     141        cacheName <<  ':' <<  b->getUniqueID();
     142    }
     143    for (const StreamSetBuffer * b: outputs) {
     144        cacheName <<  ':' <<  b->getUniqueID();
     145    }
     146    Module * const kernelModule = new Module(cacheName.str(), iBuilder->getContext());
     147    kernelModule->setTargetTriple(iBuilder->getModule()->getTargetTriple());
     148    createKernelStub(inputs, outputs, kernelModule);
     149}
     150
     151void KernelBuilder::createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs, Module * const kernelModule) {
    139152    assert (mModule == nullptr);
    140153    assert (mStreamSetInputBuffers.empty());
     
    176189    }
    177190
    178     std::stringstream cacheName;
    179 
    180     cacheName << getName() << '_' << iBuilder->getBuilderUniqueName();
    181     for (const StreamSetBuffer * b: inputs) {
    182         cacheName <<  ':' <<  b->getUniqueID();
    183     }
    184     for (const StreamSetBuffer * b: outputs) {
    185         cacheName <<  ':' <<  b->getUniqueID();
    186     }
     191    mModule = kernelModule;
    187192
    188193    mStreamSetInputBuffers.assign(inputs.begin(), inputs.end());
     
    190195
    191196    prepareKernel();
    192 
    193     mModule = new Module(cacheName.str(), iBuilder->getContext());
    194     mModule->setTargetTriple(iBuilder->getModule()->getTargetTriple());
    195 }
     197}
     198
    196199
    197200// Default kernel signature: generate the IR and emit as byte code.
    198 std::string KernelBuilder::generateKernelSignature(std::string moduleId) {
    199     if (moduleIDisSignature()) {
    200         return moduleId;
     201std::string KernelBuilder::makeSignature() {
     202    if (LLVM_LIKELY(moduleIDisSignature())) {
     203        return getModule()->getModuleIdentifier();
    201204    } else {
    202205        generateKernel();
    203206        std::string signature;
    204207        raw_string_ostream OS(signature);
    205         WriteBitcodeToFile(iBuilder->getModule(), OS);
     208        WriteBitcodeToFile(getModule(), OS);
    206209        return signature;
    207210    }
     
    212215    // generated the unoptimized IR.
    213216    if (!mIsGenerated) {
     217        auto ip = iBuilder->saveIP();
    214218        auto saveInstance = getInstance();
    215         auto savePoint = iBuilder->saveIP();
    216         addKernelDeclarations(iBuilder->getModule());
     219        addKernelDeclarations();
    217220        callGenerateInitializeMethod();
    218221        callGenerateDoSegmentMethod();       
    219222        callGenerateFinalizeMethod();
    220         iBuilder->restoreIP(savePoint);
    221223        setInstance(saveInstance);
    222         mIsGenerated = true;       
     224        iBuilder->restoreIP(ip);
     225        mIsGenerated = true;
    223226    }
    224227}
    225228
    226229inline void KernelBuilder::callGenerateInitializeMethod() {
    227     mCurrentMethod = getInitFunction();
     230    mCurrentMethod = getInitFunction(iBuilder->getModule());
    228231    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
    229232    Function::arg_iterator args = mCurrentMethod->arg_begin();
     
    241244
    242245inline void KernelBuilder::callGenerateDoSegmentMethod() {
    243     mCurrentMethod = getDoSegmentFunction();
     246    mCurrentMethod = getDoSegmentFunction(iBuilder->getModule());
    244247    BasicBlock * const entry = CreateBasicBlock(getName() + "_entry");
    245248    iBuilder->SetInsertPoint(entry);
     
    259262
    260263inline void KernelBuilder::callGenerateFinalizeMethod() {
    261     mCurrentMethod = getTerminateFunction();
     264    mCurrentMethod = getTerminateFunction(iBuilder->getModule());
    262265    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
    263266    auto args = mCurrentMethod->arg_begin();
     
    365368
    366369LoadInst * KernelBuilder::acquireLogicalSegmentNo() const {
    367     return iBuilder->CreateAtomicLoadAcquire(getScalarFieldPtr(getInstance(), LOGICAL_SEGMENT_NO_SCALAR));
     370    return iBuilder->CreateAtomicLoadAcquire(getScalarFieldPtr(LOGICAL_SEGMENT_NO_SCALAR));
    368371}
    369372
    370373void KernelBuilder::releaseLogicalSegmentNo(Value * nextSegNo) const {
    371     iBuilder->CreateAtomicStoreRelease(nextSegNo, getScalarFieldPtr(getInstance(), LOGICAL_SEGMENT_NO_SCALAR));
     374    iBuilder->CreateAtomicStoreRelease(nextSegNo, getScalarFieldPtr(LOGICAL_SEGMENT_NO_SCALAR));
     375}
     376
     377llvm::Value * KernelBuilder::getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const {
     378    llvm::Value * instance = getStreamSetBufferPtr(name);
     379    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
     380    return buf->getLinearlyAccessibleItems(iBuilder, instance, fromPosition);
    372381}
    373382
     
    397406    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    398407    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    399     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
     408    return buf->getStreamBlockPtr(iBuilder, getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    400409}
    401410
     
    407416    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    408417    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    409     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, true);
     418    return buf->getStreamPackPtr(iBuilder, getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, true);
    410419}
    411420
     
    415424
    416425llvm::Value * KernelBuilder::getInputStreamSetCount(const std::string & name) const {
    417     return getInputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     426    return getInputStreamSetBuffer(name)->getStreamSetCount(iBuilder, getStreamSetBufferPtr(name));
    418427}
    419428
     
    422431    blockIndex = iBuilder->CreateAdd(blockIndex, blockAdjustment);
    423432    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    424     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
     433    return buf->getStreamBlockPtr(iBuilder, getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    425434}
    426435
     
    428437    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    429438    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    430     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, false);
     439    return buf->getStreamBlockPtr(iBuilder, getStreamSetBufferPtr(name), streamIndex, blockIndex, false);
    431440}
    432441
     
    438447    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    439448    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    440     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, false);
     449    return buf->getStreamPackPtr(iBuilder, getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, false);
    441450}
    442451
     
    446455
    447456llvm::Value * KernelBuilder::getOutputStreamSetCount(const std::string & name) const {
    448     return getOutputStreamSetBuffer(name)->getStreamSetCount(getStreamSetBufferPtr(name));
     457    return getOutputStreamSetBuffer(name)->getStreamSetCount(iBuilder, getStreamSetBufferPtr(name));
    449458}
    450459
    451460Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    452     return getInputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     461    return getInputStreamSetBuffer(name)->getRawItemPointer(iBuilder, getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    453462}
    454463
    455464Value * KernelBuilder::getRawOutputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    456     return getOutputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     465    return getOutputStreamSetBuffer(name)->getRawItemPointer(iBuilder, getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    457466}
    458467
    459468Value * KernelBuilder::getBaseAddress(const std::string & name) const {
    460     return getAnyStreamSetBuffer(name)->getBaseAddress(getStreamSetBufferPtr(name));
     469    return getAnyStreamSetBuffer(name)->getBaseAddress(iBuilder, getStreamSetBufferPtr(name));
    461470}
    462471
    463472void KernelBuilder::setBaseAddress(const std::string & name, Value * const addr) const {
    464     return getAnyStreamSetBuffer(name)->setBaseAddress(getStreamSetBufferPtr(name), addr);
     473    return getAnyStreamSetBuffer(name)->setBaseAddress(iBuilder, getStreamSetBufferPtr(name), addr);
    465474}
    466475
    467476Value * KernelBuilder::getBufferedSize(const std::string & name) const {
    468     return getAnyStreamSetBuffer(name)->getBufferedSize(getStreamSetBufferPtr(name));
     477    return getAnyStreamSetBuffer(name)->getBufferedSize(iBuilder, getStreamSetBufferPtr(name));
    469478}
    470479
     
    480489        buf = mStreamSetOutputBuffers[index];
    481490    }
    482     buf->setBufferedSize(getStreamSetBufferPtr(name), size);
     491    buf->setBufferedSize(iBuilder, getStreamSetBufferPtr(name), size);
    483492}
    484493
     
    486495    Value * itemCount = getProducedItemCount(name);
    487496    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    488     buf->reserveBytes(getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
     497    buf->reserveBytes(iBuilder, getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
    489498}
    490499
     
    557566
    558567CallInst * KernelBuilder::createDoSegmentCall(const std::vector<Value *> & args) const {
    559     Function * const doSegment = getDoSegmentFunction();
     568    Function * const doSegment = getDoSegmentFunction(iBuilder->getModule());
    560569    assert (doSegment->getArgumentList().size() == args.size());
    561570    return iBuilder->CreateCall(doSegment, args);
     
    563572
    564573Value * KernelBuilder::getAccumulator(const std::string & accumName) const {
     574    assert ("KernelBuilder does not have a valid IDISA Builder" && iBuilder);
    565575    if (LLVM_UNLIKELY(mOutputScalarResult == nullptr)) {
    566576        report_fatal_error("Cannot get accumulator " + accumName + " until " + getName() + " has terminated.");
     
    597607
    598608void KernelBuilder::initializeInstance() {
    599 
    600609
    601610    if (LLVM_UNLIKELY(getInstance() == nullptr)) {
     
    658667    }
    659668
    660     iBuilder->CreateCall(getInitFunction(), args);
     669    iBuilder->CreateCall(getInitFunction(iBuilder->getModule()), args);
    661670}
    662671
     
    783792        mCurrentMethod->setDoesNotCapture(1);
    784793        auto args = mCurrentMethod->arg_begin();
    785         mCurrentMethod = mCurrentMethod;
    786794        args->setName("self");
    787795        setInstance(&*args);
     
    801809    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    802810        Value * log2BlockSize = iBuilder->getSize(std::log2(iBuilder->getBitBlockWidth()));
    803         if (auto cb = dyn_cast<SwizzledCopybackBuffer>(mStreamSetOutputBuffers[i]))  {
     811        if (SwizzledCopybackBuffer * const cb = dyn_cast<SwizzledCopybackBuffer>(mStreamSetOutputBuffers[i]))  {
    804812            BasicBlock * copyBack = CreateBasicBlock(mStreamSetOutputs[i].name + "_copyBack");
    805813            BasicBlock * done = CreateBasicBlock(mStreamSetOutputs[i].name + "_copyBackDone");
     
    808816            Value * priorOffset = iBuilder->CreateAnd(priorProduced[priorIdx], iBuilder->getSize(iBuilder->getBitBlockWidth() - 1));
    809817            Value * instance = getStreamSetBufferPtr(mStreamSetOutputs[i].name);
    810             Value * accessibleBlocks = cb->getLinearlyAccessibleBlocks(instance, priorBlock);
     818            Value * accessibleBlocks = cb->getLinearlyAccessibleBlocks(iBuilder, instance, priorBlock);
    811819            Value * accessible = iBuilder->CreateSub(iBuilder->CreateShl(accessibleBlocks, log2BlockSize), priorOffset);
    812820            Value * wraparound = iBuilder->CreateICmpULT(accessible, newlyProduced);
     
    814822            iBuilder->SetInsertPoint(copyBack);
    815823            Value * copyItems = iBuilder->CreateSub(newlyProduced, accessible);
    816             cb->createCopyBack(instance, copyItems);
     824            cb->createCopyBack(iBuilder, instance, copyItems);
    817825            iBuilder->CreateBr(done);
    818826            iBuilder->SetInsertPoint(done);
    819827            priorIdx++;
    820828        }
    821         if (auto cb = dyn_cast<CircularCopybackBuffer>(mStreamSetOutputBuffers[i]))  {
     829        if (CircularCopybackBuffer * const cb = dyn_cast<CircularCopybackBuffer>(mStreamSetOutputBuffers[i]))  {
    822830            BasicBlock * copyBack = CreateBasicBlock(mStreamSetOutputs[i].name + "_copyBack");
    823831            BasicBlock * done = CreateBasicBlock(mStreamSetOutputs[i].name + "_copyBackDone");
    824832            Value * instance = getStreamSetBufferPtr(mStreamSetOutputs[i].name);
    825833            Value * newlyProduced = iBuilder->CreateSub(getProducedItemCount(mStreamSetOutputs[i].name), priorProduced[priorIdx]);
    826             Value * accessible = cb->getLinearlyAccessibleItems(instance, priorProduced[priorIdx]);
     834            Value * accessible = cb->getLinearlyAccessibleItems(iBuilder, instance, priorProduced[priorIdx]);
    827835            Value * wraparound = iBuilder->CreateICmpULT(accessible, newlyProduced);
    828836            iBuilder->CreateCondBr(wraparound, copyBack, done);
    829837            iBuilder->SetInsertPoint(copyBack);
    830838            Value * copyItems = iBuilder->CreateSub(newlyProduced, accessible);
    831             cb->createCopyBack(instance, copyItems);
     839            cb->createCopyBack(iBuilder, instance, copyItems);
    832840            iBuilder->CreateBr(done);
    833841            iBuilder->SetInsertPoint(done);
     
    835843        }
    836844    }
     845
    837846
    838847    /// Call the do block method if necessary then restore the current function state to the do segement method
     
    902911
    903912void KernelBuilder::finalizeInstance() {
    904     mOutputScalarResult = iBuilder->CreateCall(getTerminateFunction(), { getInstance() });
     913    mOutputScalarResult = iBuilder->CreateCall(getTerminateFunction(iBuilder->getModule()), { getInstance() });
    905914}
    906915
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5429 r5431  
    6161    // should return true.
    6262    //
    63    
     63       
     64    bool isCachable() const override { return false; }
     65
     66    std::string makeSignature() override;
     67
    6468    // Can the module ID itself serve as the unique signature?
    65     virtual bool moduleIDisSignature() { return false; }
    66    
    67     virtual std::string generateKernelSignature(std::string moduleId);
    68    
     69    virtual bool moduleIDisSignature() const { return false; }
     70
    6971    // Create a module stub for the kernel, populated only with its Module ID.     
    7072    //
     73
    7174    void createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs);
     75
     76    void createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs, llvm::Module * const kernelModule);
    7277
    7378    llvm::Module * getModule() const {
     
    106111    // Get the value of a scalar field for the current instance.
    107112    llvm::Value * getScalarFieldPtr(llvm::Value * index) const {
    108         return getScalarFieldPtr(getInstance(), index);
     113        return iBuilder->CreateGEP(getInstance(), {iBuilder->getInt32(0), index});
    109114    }
    110115
    111116    llvm::Value * getScalarFieldPtr(const std::string & fieldName) const {
    112         return getScalarFieldPtr(getInstance(), fieldName);
     117        return getScalarFieldPtr(getScalarIndex(fieldName));
    113118    }
    114119
     
    168173    // Constructor
    169174    KernelBuilder(IDISA::IDISA_Builder * builder,
    170                     std::string && kernelName,
    171                     std::vector<Binding> && stream_inputs,
    172                     std::vector<Binding> && stream_outputs,
    173                     std::vector<Binding> && scalar_parameters,
    174                     std::vector<Binding> && scalar_outputs,
    175                     std::vector<Binding> && internal_scalars);
     175                  std::string && kernelName,
     176                  std::vector<Binding> && stream_inputs,
     177                  std::vector<Binding> && stream_outputs,
     178                  std::vector<Binding> && scalar_parameters,
     179                  std::vector<Binding> && scalar_outputs,
     180                  std::vector<Binding> && internal_scalars);
    176181
    177182    //
     
    252257    llvm::Value * getAvailableItemCount(const std::string & name) const;
    253258
     259    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const;
     260
    254261    llvm::Value * getIsFinal() const {
    255262        return mIsFinal;
     
    260267    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
    261268
    262     // Stream set helpers.
    263 
    264269    llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    265 
    266     llvm::Value * getScalarFieldPtr(llvm::Value * const instance, llvm::Value * index) const {
    267         assert ("instance cannot be null!" && instance);
    268         return iBuilder->CreateGEP(getInstance(), {iBuilder->getInt32(0), index});
    269     }
    270 
    271     llvm::Value * getScalarFieldPtr(llvm::Value * const instance, const std::string & fieldName) const {
    272         return getScalarFieldPtr(instance, getScalarIndex(fieldName));
    273     }
    274270
    275271    void callGenerateInitializeMethod();
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp

    r5401 r5431  
    1212#include <cc/cc_compiler.h>
    1313#include <pablo/builder.hpp>
    14 #include <llvm/IR/Module.h>
    15 
    16 #include <llvm/Support/raw_ostream.h>
    1714
    1815using namespace cc;
     
    2421#define UNICODE_LINE_BREAK (!AlgorithmOptionIsSet(DisableUnicodeLineBreak))
    2522
    26 LineBreakKernelBuilder::LineBreakKernelBuilder (
    27 IDISA::IDISA_Builder * iBuilder
    28 , unsigned basisBitsCount)
    29 : PabloKernel(iBuilder, "Parabix:lb_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}, {Binding{iBuilder->getStreamSetTy(1), "linebreak", Add1()}}) {
     23LineBreakKernelBuilder::LineBreakKernelBuilder (IDISA::IDISA_Builder * iBuilder, unsigned basisBitsCount)
     24: PabloKernel(iBuilder, "lb", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}, {Binding{iBuilder->getStreamSetTy(1), "linebreak", Add1()}}) {
    3025
    3126    CC_Compiler ccc(this, getInput(0));
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5401 r5431  
    77
    88#include <pablo/pablo_kernel.h>  // for PabloKernel
    9 #include "kernel.h"              // for KernelBuilder
    10 #include <string>                // for string
     9
    1110namespace IDISA { class IDISA_Builder; }
    1211
     
    1615public:
    1716    LineBreakKernelBuilder(IDISA::IDISA_Builder * iBuilder, unsigned basisBitsCount);
    18     bool moduleIDisSignature() override {return true;}
     17    bool isCachable() const override { return true; }
     18    bool moduleIDisSignature() const override { return true; }
    1919};
    2020
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5395 r5431  
    147147
    148148P2SKernel::P2SKernel(IDISA::IDISA_Builder * iBuilder)
    149 : BlockOrientedKernel(iBuilder, "Parabix:p2s",
     149: BlockOrientedKernel(iBuilder, "p2s",
    150150              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
    151151              {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
     
    154154
    155155P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder)
    156 : BlockOrientedKernel(iBuilder, "Parabix:p2s_compress",
     156: BlockOrientedKernel(iBuilder, "p2s_compress",
    157157              {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
    158158                      {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream", MaxRatio(1)}},
     
    161161
    162162P2S16Kernel::P2S16Kernel(IDISA::IDISA_Builder * iBuilder)
    163 : BlockOrientedKernel(iBuilder, "Parabix:p2s_16",
     163: BlockOrientedKernel(iBuilder, "p2s_16",
    164164              {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}},
    165165              {Binding{iBuilder->getStreamSetTy(1, 16), "i16Stream"}},
     
    169169
    170170P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * b)
    171 : BlockOrientedKernel(b, "Parabix:p2s_16_compress",
     171: BlockOrientedKernel(b, "p2s_16_compress",
    172172              {Binding{b->getStreamSetTy(16, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "deletionCounts"}},
    173173              {Binding{b->getStreamSetTy(1, 16), "i16Stream", MaxRatio(1)}},
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5402 r5431  
    1212
    1313   
    14 class P2SKernel : public BlockOrientedKernel {
     14class P2SKernel final : public BlockOrientedKernel {
    1515public:
    1616    P2SKernel(IDISA::IDISA_Builder * iBuilder);
    17     bool moduleIDisSignature() override {return true;}
     17    bool isCachable() const override { return true; }
     18    bool moduleIDisSignature() const override { return true; }
    1819private:
    1920    void generateDoBlockMethod() override;
    2021};
    2122
    22 class P2SKernelWithCompressedOutput : public BlockOrientedKernel {
     23class P2SKernelWithCompressedOutput final : public BlockOrientedKernel {
    2324public:
    2425    P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);   
    25     bool moduleIDisSignature() override {return true;}
     26    bool isCachable() const override { return true; }
     27    bool moduleIDisSignature() const override { return true; }
    2628private:
    2729    void generateDoBlockMethod() override;
    2830};
    2931
    30 class P2S16Kernel : public BlockOrientedKernel {
     32class P2S16Kernel final : public BlockOrientedKernel {
    3133public:
    3234    P2S16Kernel(IDISA::IDISA_Builder * iBuilder);
    33     bool moduleIDisSignature() override {return true;}
     35    bool isCachable() const override { return true; }
     36    bool moduleIDisSignature() const override { return true; }
    3437private:
    3538    void generateDoBlockMethod() override;
    3639};
    3740   
    38 class P2S16KernelWithCompressedOutput : public BlockOrientedKernel {
     41class P2S16KernelWithCompressedOutput final : public BlockOrientedKernel {
    3942public:
    4043    P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);
    41     bool moduleIDisSignature() override {return true;}
     44    bool isCachable() const override { return true; }
     45    bool moduleIDisSignature() const override { return true; }
    4246private:
    4347    void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5418 r5431  
    451451
    452452expand3_4Kernel::expand3_4Kernel(IDISA::IDISA_Builder * iBuilder)
    453 : SegmentOrientedKernel(iBuilder, "Parabix:expand3_4",
     453: SegmentOrientedKernel(iBuilder, "expand3_4",
    454454            {Binding{iBuilder->getStreamSetTy(1, 8), "sourceStream"}},
    455455            {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream", FixedRatio(4,3)}},
     
    458458
    459459radix64Kernel::radix64Kernel(IDISA::IDISA_Builder * iBuilder)
    460 : BlockOrientedKernel(iBuilder, "Parabix:radix64",
     460: BlockOrientedKernel(iBuilder, "radix64",
    461461            {Binding{iBuilder->getStreamSetTy(1, 8), "expandedStream"}},
    462462            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
     
    465465
    466466base64Kernel::base64Kernel(IDISA::IDISA_Builder * iBuilder)
    467 : BlockOrientedKernel(iBuilder, "Parabix:base64",
     467: BlockOrientedKernel(iBuilder, "base64",
    468468            {Binding{iBuilder->getStreamSetTy(1, 8), "radix64stream"}},
    469469            {Binding{iBuilder->getStreamSetTy(1, 8), "base64stream", RoundUpToMultiple(4)}},
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5418 r5431  
    1919    This is a useful preparatory transformation in various radix-64 encodings. */
    2020 
    21 class expand3_4Kernel : public SegmentOrientedKernel {
     21class expand3_4Kernel final : public SegmentOrientedKernel {
    2222public:   
    2323    expand3_4Kernel(IDISA::IDISA_Builder * iBuilder);
     24    bool isCachable() const override { return true; }
    2425private:
    25     void generateDoSegmentMethod() override final;
     26    void generateDoSegmentMethod() override;
    2627};
    2728
    28 class radix64Kernel : public BlockOrientedKernel {
     29class radix64Kernel final : public BlockOrientedKernel {
    2930public:
    3031    radix64Kernel(IDISA::IDISA_Builder * iBuilder);
     32    bool isCachable() const override { return true; }
    3133private:
    32     virtual void generateDoBlockMethod() override final;
    33     virtual void generateFinalBlockMethod(llvm::Value * remainingBytes) override final;
     34    virtual void generateDoBlockMethod() override;
     35    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
    3436    llvm::Value* processPackData(llvm::Value* packData) const;
    3537};
    3638
    37 class base64Kernel : public BlockOrientedKernel {
     39class base64Kernel final : public BlockOrientedKernel {
    3840public:
    3941    base64Kernel(IDISA::IDISA_Builder * iBuilder);
     42    bool isCachable() const override { return true; }
    4043private:
    41     virtual void generateDoBlockMethod() override final;
    42     virtual void generateFinalBlockMethod(llvm::Value * remainingBytes) override final;
     44    virtual void generateDoBlockMethod() override;
     45    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes) override;
    4346    llvm::Value* processPackData(llvm::Value* packData) const;
    4447};
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5422 r5431  
    168168
    169169S2PKernel::S2PKernel(IDISA::IDISA_Builder * builder, bool aligned)
    170 : BlockOrientedKernel(builder, aligned ? "Parabix:s2p" : "Parabix:s2p_unaligned",
     170: BlockOrientedKernel(builder, aligned ? "s2p" : "s2p_unaligned",
    171171    {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {Binding{builder->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}),
    172172  mAligned(aligned) {
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5422 r5431  
    1212namespace kernel {
    1313
    14 class S2PKernel : public BlockOrientedKernel {
     14class S2PKernel final : public BlockOrientedKernel {
    1515public:   
    1616    S2PKernel(IDISA::IDISA_Builder * builder, bool aligned = true);
    17     bool moduleIDisSignature() override {return true;}
    18     virtual ~S2PKernel() {}
     17    bool isCachable() const override { return true; }
     18    bool moduleIDisSignature() const override { return true; }
    1919protected:
    2020    void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5427 r5431  
    190190
    191191ScanMatchKernel::ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, GrepType grepType, const unsigned codeUnitWidth)
    192 : BlockOrientedKernel(iBuilder, "Parabix:scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
     192: BlockOrientedKernel(iBuilder, "scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
    193193    {Binding{iBuilder->getStreamSetTy(1, 1), "matchResult"}, Binding{iBuilder->getStreamSetTy(1, 1), "lineBreak"}, Binding{iBuilder->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    194194    {},
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5427 r5431  
    1717public:
    1818    ScanMatchKernel(IDISA::IDISA_Builder * const iBuilder, const GrepType grepType, const unsigned codeUnitWidth);
    19     bool moduleIDisSignature() override { return true; }
     19    bool isCachable() const override { return true; }
     20    bool moduleIDisSignature() const override { return true; }
    2021protected:
    2122    void generateDoBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5429 r5431  
    9797    sourceBuffer = iBuilder->CreatePtrToInt(sourceBuffer, consumedTy);
    9898    Value * consumedBuffer = iBuilder->CreateAdd(sourceBuffer, consumed);
     99
     100
     101
     102
    99103    Value * readableBuffer = getScalarField("readableBuffer");
    100104    readableBuffer = iBuilder->CreatePtrToInt(readableBuffer, consumedTy);
    101105    Value * unnecessaryBytes = iBuilder->CreateSub(consumedBuffer, readableBuffer);
     106
     107
     108
    102109    // avoid calling madvise unless an actual page table change could occur
    103110    Value * hasPagesToDrop = iBuilder->CreateICmpEQ(unnecessaryBytes, ConstantInt::getNullValue(unnecessaryBytes->getType()));
     
    135142
    136143MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    137 : SegmentOrientedKernel(iBuilder, "Parabix:mmap_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth),
     144: SegmentOrientedKernel(iBuilder, "mmap_source" + std::to_string(blocksPerSegment) + "@" + std::to_string(codeUnitWidth),
    138145{},
    139146{Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
     
    275282
    276283ReadSourceKernel::ReadSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    277 : SegmentOrientedKernel(iBuilder, "Parabix:read_source"
     284: SegmentOrientedKernel(iBuilder, "read_source"
    278285, {}
    279286, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}
     
    320327
    321328MemorySourceKernel::MemorySourceKernel(IDISA::IDISA_Builder * iBuilder, Type * type, unsigned blocksPerSegment, unsigned codeUnitWidth)
    322 : SegmentOrientedKernel(iBuilder, "Parabix:memory_source",
     329: SegmentOrientedKernel(iBuilder, "memory_source",
    323330    {},
    324331    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.h

    r5429 r5431  
    1414public:
    1515    MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    16     bool moduleIDisSignature() final { return true; }
     16    bool isCachable() const override { return true; }
     17    bool moduleIDisSignature() const override { return true; }
    1718protected:
    1819    void linkExternalMethods() override;
     
    2930public:
    3031    ReadSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    31     bool moduleIDisSignature() override { return true; }
     32    bool isCachable() const override { return true; }
     33    bool moduleIDisSignature() const override { return true; }
    3234protected:
    3335    void generateInitializeMethod() override;
     
    4244public:
    4345    MemorySourceKernel(IDISA::IDISA_Builder * iBuilder, llvm::Type * type, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    44     bool moduleIDisSignature() override { return true; }
     46    bool moduleIDisSignature() const override { return true; }
    4547protected:
    4648    void generateInitializeMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5418 r5431  
    3030    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    3131        Value * instance = getStreamSetBufferPtr("codeUnitBuffer");
    32         Value * accessible = b->getLinearlyAccessibleItems(instance, processed);
     32
     33
     34
     35        Value * accessible = b->getLinearlyAccessibleItems(iBuilder, instance, processed);
    3336        wraparound = iBuilder->CreateICmpULT(accessible, itemsToDo);
    3437        itemsToDo = iBuilder->CreateSelect(wraparound, accessible, itemsToDo);
     
    117120    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    118121        Value * instance = getStreamSetBufferPtr("codeUnitBuffer");
    119         Value * accessible = b->getLinearlyAccessibleItems(instance, processed);
     122        Value * accessible = b->getLinearlyAccessibleItems(iBuilder, instance, processed);
    120123        wraparound = iBuilder->CreateICmpULT(accessible, itemsToDo);
    121124        itemsToDo = iBuilder->CreateSelect(wraparound, accessible, itemsToDo);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5429 r5431  
    2828StructType * resolveExpandableStreamSetType(IDISA_Builder * const b, Type * type);
    2929
    30 void StreamSetBuffer::allocateBuffer() {
     30void StreamSetBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
    3131    if (LLVM_LIKELY(mStreamSetBufferPtr == nullptr)) {
    3232        Type * const ty = getType();
     
    3838}
    3939
    40 Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    41     iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(self)), "StreamSetBuffer: out-of-bounds stream access");
    42     return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    43 }
    44 
    45 Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    46     iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(self)), "StreamSetBuffer: out-of-bounds stream access");
    47     return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    48 }
    49 
    50 void StreamSetBuffer::setBaseAddress(Value * /* self */, Value * /* addr */) const {
     40Value * StreamSetBuffer::getStreamBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
     41    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
     42    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex});
     43}
     44
     45Value * StreamSetBuffer::getStreamPackPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
     46    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
     47    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
     48}
     49
     50void StreamSetBuffer::setBaseAddress(IDISA_Builder * const iBuilder, Value * /* self */, Value * /* addr */) const {
    5151    report_fatal_error("setBaseAddress is not supported by this buffer type");
    5252}
    5353
    54 Value * StreamSetBuffer::getBufferedSize(Value * /* self */) const {
     54Value * StreamSetBuffer::getBufferedSize(IDISA_Builder * const iBuilder, Value * /* self */) const {
    5555    report_fatal_error("getBufferedSize is not supported by this buffer type");
    5656}
    5757
    58 void StreamSetBuffer::setBufferedSize(Value * /* self */, llvm::Value * /* size */) const {
     58void StreamSetBuffer::setBufferedSize(IDISA_Builder * const iBuilder, Value * /* self */, llvm::Value * /* size */) const {
    5959    report_fatal_error("setBufferedSize is not supported by this buffer type");
    6060}
     
    6969}
    7070
    71 Value * StreamSetBuffer::getStreamSetCount(Value *) const {
     71Value * StreamSetBuffer::getStreamSetCount(IDISA_Builder * const iBuilder, Value *) const {
    7272    uint64_t count = 1;
    7373    if (isa<ArrayType>(mBaseType)) {
     
    7777}
    7878
    79 inline Value * StreamSetBuffer::modByBufferBlocks(Value * const offset) const {
     79inline Value * StreamSetBuffer::modByBufferBlocks(IDISA_Builder * const iBuilder, Value * const offset) const {
    8080    assert (offset->getType()->isIntegerTy());
    8181    if (isCapacityGuaranteed(offset, mBufferBlocks)) {
     
    9797 * The type of the pointer is i8* for fields of 8 bits or less, otherwise iN* for N-bit fields.
    9898 */
    99 Value * StreamSetBuffer::getRawItemPointer(Value * self, Value * streamIndex, Value * absolutePosition) const {
    100     Value * ptr = getBaseAddress(self);
     99Value * StreamSetBuffer::getRawItemPointer(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * absolutePosition) const {
     100    Value * ptr = getBaseAddress(iBuilder, self);
    101101    if (!isa<ConstantInt>(streamIndex) || !cast<ConstantInt>(streamIndex)->isZero()) {
    102102        ptr = iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), streamIndex});
     
    116116}
    117117
    118 Value * StreamSetBuffer::getLinearlyAccessibleItems(Value * self, Value * fromPosition) const {
     118Value * StreamSetBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value * fromPosition) const {
    119119    if (isa<ArrayType>(mType) && dyn_cast<ArrayType>(mType)->getNumElements() > 1) {
    120120        Constant * stride = iBuilder->getSize(iBuilder->getStride());
     
    126126}
    127127
    128 Value * StreamSetBuffer::getLinearlyAccessibleBlocks(Value * self, Value * fromBlock) const {
     128Value * StreamSetBuffer::getLinearlyAccessibleBlocks(IDISA_Builder * const iBuilder, Value * self, Value * fromBlock) const {
    129129    Constant * bufBlocks = iBuilder->getSize(mBufferBlocks);
    130130    return iBuilder->CreateSub(bufBlocks, iBuilder->CreateURem(fromBlock, bufBlocks));
    131131}
    132132
    133 void StreamSetBuffer::reserveBytes(Value * self, llvm::Value *requested) const {
     133void StreamSetBuffer::reserveBytes(IDISA_Builder * const iBuilder, Value * self, llvm::Value *requested) const {
    134134    report_fatal_error("reserve() can only be used with ExtensibleBuffers");
    135135}
    136136
    137 Value * StreamSetBuffer::getBaseAddress(Value * self) const {
     137Value * StreamSetBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * self) const {
    138138    return self;
    139139}
    140140
    141 void StreamSetBuffer::releaseBuffer(Value * /* self */) const {
     141void StreamSetBuffer::releaseBuffer(IDISA_Builder * const iBuilder, Value * /* self */) const {
    142142    /* do nothing: memory is stack allocated */
    143143}
     
    146146
    147147// For a single block buffer, the block pointer is always the buffer base pointer.
    148 Value * SingleBlockBuffer::getStreamSetBlockPtr(Value * self, Value *) const {
     148Value * SingleBlockBuffer::getStreamSetBlockPtr(IDISA_Builder * const, Value * self, Value *) const {
    149149    return self;
    150150}
    151151
    152152// Source File Buffer
    153 Value * SourceBuffer::getBufferedSize(Value * self) const {
     153Value * SourceBuffer::getBufferedSize(IDISA_Builder * const iBuilder, Value * self) const {
    154154    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    155155    return iBuilder->CreateLoad(ptr);
    156156}
    157157
    158 void SourceBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
     158void SourceBuffer::setBufferedSize(IDISA_Builder * const iBuilder, Value * self, llvm::Value * size) const {
    159159    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    160160    iBuilder->CreateStore(size, ptr);
    161161}
    162162
    163 void SourceBuffer::setBaseAddress(Value * self, Value * addr) const {
     163void SourceBuffer::setBaseAddress(IDISA_Builder * const iBuilder, Value * self, Value * addr) const {
    164164    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    165165    iBuilder->CreateStore(iBuilder->CreatePointerCast(addr, ptr->getType()->getPointerElementType()), ptr);
    166166}
    167167
    168 Value * SourceBuffer::getBaseAddress(Value * const self) const {
     168Value * SourceBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * const self) const {
    169169    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    170170    Value * const addr = iBuilder->CreateLoad(ptr);
     
    172172}
    173173
    174 Value * SourceBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    175     return iBuilder->CreateGEP(getBaseAddress(self), blockIndex);
    176 }
    177 
    178 Value * SourceBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
     174Value * SourceBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     175    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), blockIndex);
     176}
     177
     178Value * SourceBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value *) const {
    179179    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    180180}
    181181
    182182// External File Buffer
    183 void ExternalBuffer::allocateBuffer() {
     183void ExternalBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
    184184    report_fatal_error("External buffers cannot be allocated.");
    185185}
    186186
    187 Value * ExternalBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    188     return iBuilder->CreateGEP(getBaseAddress(self), blockIndex);
    189 }
    190 
    191 Value * ExternalBuffer::getLinearlyAccessibleItems(Value *, Value *) const {
     187Value * ExternalBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     188    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), blockIndex);
     189}
     190
     191Value * ExternalBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value *, Value *) const {
    192192    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    193193}
    194194
    195195// Circular Buffer
    196 Value * CircularBuffer::getStreamSetBlockPtr(Value * const self, Value * const blockIndex) const {
    197     return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
     196Value * CircularBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * const self, Value * const blockIndex) const {
     197    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    198198}
    199199
    200200// CircularCopybackBuffer Buffer
    201 void CircularCopybackBuffer::allocateBuffer() {
     201void CircularCopybackBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
    202202    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
    203203}
    204204
    205 void CircularCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) const {
     205void CircularCopybackBuffer::createCopyBack(IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
    206206    Type * size_ty = iBuilder->getSizeTy();
    207207    Type * i8ptr = iBuilder->getInt8PtrTy();
     
    237237}
    238238
    239 Value * CircularCopybackBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    240     return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
     239Value * CircularCopybackBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     240    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    241241}
    242242
    243243// SwizzledCopybackBuffer Buffer
    244244
    245 void SwizzledCopybackBuffer::allocateBuffer() {
     245void SwizzledCopybackBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
    246246    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
    247247}
    248248
    249 void SwizzledCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) const {
     249void SwizzledCopybackBuffer::createCopyBack(IDISA_Builder * const iBuilder, Value * self, Value * overFlowItems) const {
    250250    Type * size_ty = iBuilder->getSizeTy();
    251251    Type * i8ptr = iBuilder->getInt8PtrTy();
     
    282282}
    283283
    284 Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    285     return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
    286 }
    287 
    288 SwizzledCopybackBuffer::SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
    289 : StreamSetBuffer(BufferKind::SwizzledCopybackBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks), mFieldWidth(fieldwidth) {
    290     mUniqueID = "SW" + std::to_string(fieldwidth) + ":" + std::to_string(bufferBlocks);
    291     if (mOverflowBlocks != 1) {
    292         mUniqueID += "_" + std::to_string(mOverflowBlocks);
    293     }
    294     if (AddressSpace > 0) {
    295         mUniqueID += "@" + std::to_string(AddressSpace);
    296     }
     284Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * blockIndex) const {
     285    return iBuilder->CreateGEP(getBaseAddress(iBuilder, self), modByBufferBlocks(iBuilder, blockIndex));
    297286}
    298287
    299288// Expandable Buffer
    300289
    301 void ExpandableBuffer::allocateBuffer() {
     290void ExpandableBuffer::allocateBuffer(IDISA_Builder * const iBuilder) {
    302291    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType());
    303292    Value * const capacityPtr = iBuilder->CreateGEP(mStreamSetBufferPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     
    312301}
    313302
    314 std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
     303std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    315304
    316305    // ENTRY
     
    319308    Value * const streamSetPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    320309    Value * const streamSet = iBuilder->CreateLoad(streamSetPtr);
    321     blockIndex = modByBufferBlocks(blockIndex);
     310    blockIndex = modByBufferBlocks(iBuilder, blockIndex);
    322311
    323312    assert (streamIndex->getType() == capacity->getType());
     
    417406}
    418407
    419 Value * ExpandableBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
     408Value * ExpandableBuffer::getStreamBlockPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    420409    Value * ptr, * offset;
    421     std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
     410    std::tie(ptr, offset) = getInternalStreamBuffer(iBuilder, self, streamIndex, blockIndex, readOnly);
    422411    return iBuilder->CreateGEP(ptr, offset);
    423412}
    424413
    425 Value * ExpandableBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
     414Value * ExpandableBuffer::getStreamPackPtr(IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
    426415    Value * ptr, * offset;
    427     std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
     416    std::tie(ptr, offset) = getInternalStreamBuffer(iBuilder, self, streamIndex, blockIndex, readOnly);
    428417    return iBuilder->CreateGEP(ptr, {offset, packIndex});
    429418}
    430419
    431 Value * ExpandableBuffer::getStreamSetCount(Value * self) const {
     420Value * ExpandableBuffer::getStreamSetCount(IDISA_Builder * const iBuilder, Value * self) const {
    432421    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    433422}
    434423
    435 Value * ExpandableBuffer::getBaseAddress(Value * self) const {
     424Value * ExpandableBuffer::getBaseAddress(IDISA_Builder * const iBuilder, Value * self) const {
    436425    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
    437426}
    438427
    439 void ExpandableBuffer::releaseBuffer(Value * self) const {
    440     iBuilder->CreateAlignedFree(getBaseAddress(self));
    441 }
    442 
    443 Value * ExpandableBuffer::getStreamSetBlockPtr(Value *, Value *) const {
     428void ExpandableBuffer::releaseBuffer(IDISA_Builder * const iBuilder, Value * self) const {
     429    iBuilder->CreateAlignedFree(getBaseAddress(iBuilder, self));
     430}
     431
     432Value * ExpandableBuffer::getStreamSetBlockPtr(IDISA_Builder * const iBuilder, Value *, Value *) const {
    444433    report_fatal_error("Expandable buffers: getStreamSetBlockPtr is not supported.");
    445434}
    446435
    447 Value * ExpandableBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
     436Value * ExpandableBuffer::getLinearlyAccessibleItems(IDISA_Builder * const iBuilder, Value * self, Value *) const {
    448437    report_fatal_error("Expandable buffers: getLinearlyAccessibleItems is not supported.");
    449438}
     
    451440// Constructors
    452441SingleBlockBuffer::SingleBlockBuffer(IDISA::IDISA_Builder * b, Type * type)
    453 : StreamSetBuffer(BufferKind::BlockBuffer, b, type, resolveStreamSetType(b, type), 1, 0) {
     442: StreamSetBuffer(BufferKind::BlockBuffer, type, resolveStreamSetType(b, type), 1, 0) {
    454443    mUniqueID = "S";
    455444
     
    457446
    458447SourceBuffer::SourceBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
    459 : StreamSetBuffer(BufferKind::SourceBuffer, b, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
     448: StreamSetBuffer(BufferKind::SourceBuffer, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
    460449    mUniqueID = "M"; // + std::to_string(bufferBlocks);
    461450    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     
    463452
    464453ExternalBuffer::ExternalBuffer(IDISA::IDISA_Builder * b, Type * type, llvm::Value * addr, unsigned AddressSpace)
    465 : StreamSetBuffer(BufferKind::ExternalBuffer, b, type, resolveStreamSetType(b, type), 0, AddressSpace) {
     454: StreamSetBuffer(BufferKind::ExternalBuffer, type, resolveStreamSetType(b, type), 0, AddressSpace) {
    466455    mUniqueID = "E";
    467456    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     
    470459
    471460CircularBuffer::CircularBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    472 : StreamSetBuffer(BufferKind::CircularBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace) {
     461: StreamSetBuffer(BufferKind::CircularBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace) {
    473462    mUniqueID = "C" + std::to_string(bufferBlocks);
    474463    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     
    476465
    477466CircularCopybackBuffer::CircularCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace)
    478 : StreamSetBuffer(BufferKind::CircularCopybackBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks) {
     467: StreamSetBuffer(BufferKind::CircularCopybackBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks) {
    479468    mUniqueID = "CC" + std::to_string(bufferBlocks);
    480469    if (mOverflowBlocks != 1) mUniqueID += "_" + std::to_string(mOverflowBlocks);
     
    483472
    484473ExpandableBuffer::ExpandableBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    485 : StreamSetBuffer(BufferKind::ExpandableBuffer, b, type, resolveExpandableStreamSetType(b, type), bufferBlocks, AddressSpace)
     474: StreamSetBuffer(BufferKind::ExpandableBuffer, type, resolveExpandableStreamSetType(b, type), bufferBlocks, AddressSpace)
    486475, mInitialCapacity(type->getArrayNumElements()) {
    487476    mUniqueID = "XP" + std::to_string(bufferBlocks);
     
    489478}
    490479
    491 inline StreamSetBuffer::StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, Type * baseType, Type * resolvedType, unsigned blocks, unsigned AddressSpace)
     480SwizzledCopybackBuffer::SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
     481: StreamSetBuffer(BufferKind::SwizzledCopybackBuffer, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks), mFieldWidth(fieldwidth) {
     482    mUniqueID = "SW" + std::to_string(fieldwidth) + ":" + std::to_string(bufferBlocks);
     483    if (mOverflowBlocks != 1) {
     484        mUniqueID += "_" + std::to_string(mOverflowBlocks);
     485    }
     486    if (AddressSpace > 0) {
     487        mUniqueID += "@" + std::to_string(AddressSpace);
     488    }
     489}
     490
     491inline StreamSetBuffer::StreamSetBuffer(BufferKind k, Type * baseType, Type * resolvedType, unsigned blocks, unsigned AddressSpace)
    492492: mBufferKind(k)
    493 , iBuilder(b)
    494493, mType(resolvedType)
    495494, mBufferBlocks(blocks)
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5429 r5431  
    5757    }
    5858
    59     virtual void allocateBuffer();
    60 
    61     virtual void releaseBuffer(llvm::Value * self) const;
    62 
    63     virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    64 
    65     virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const;
    66    
    67     virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
    68 
    69     llvm::Value * getRawItemPointer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    70 
    71 
    72     virtual void setBaseAddress(llvm::Value * self, llvm::Value * addr) const;
    73 
    74     virtual void setBufferedSize(llvm::Value * self, llvm::Value * size) const;
    75 
    76     virtual llvm::Value * getBufferedSize(llvm::Value * self) const;
     59    virtual void allocateBuffer(IDISA::IDISA_Builder * const iBuilder);
     60
     61    virtual void releaseBuffer(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
     62
     63    virtual llvm::Value * getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
     64
     65    virtual llvm::Value * getStreamPackPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const;
     66   
     67    virtual llvm::Value * getStreamSetCount(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
     68
     69    llvm::Value * getRawItemPointer(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
     70
     71    virtual void setBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * addr, llvm::Value *) const;
     72
     73    virtual void setBufferedSize(IDISA::IDISA_Builder * const iBuilder, llvm::Value * size, llvm::Value *) const;
     74
     75    virtual llvm::Value * getBufferedSize(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
    7776
    7877    // The number of items that cam be linearly accessed from a given logical stream position.
    79     virtual llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const;
    80 
    81     virtual llvm::Value * getLinearlyAccessibleBlocks(llvm::Value * self, llvm::Value * fromBlock) const;
    82 
    83     virtual void reserveBytes(llvm::Value * self, llvm::Value * requested) const;
     78    virtual llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const;
     79
     80    virtual llvm::Value * getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromBlock) const;
     81
     82    virtual void reserveBytes(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * requested) const;
    8483
    8584    virtual ~StreamSetBuffer() = 0;
     
    9594protected:
    9695
    97     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * baseType, llvm::Type * resolvedType, unsigned blocks, unsigned AddressSpace);
     96    StreamSetBuffer(BufferKind k, llvm::Type * baseType, llvm::Type * resolvedType, unsigned blocks, unsigned AddressSpace);
    9897
    9998    // Get the buffer pointer for a given block of the stream.
    100     virtual llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const = 0;
     99    virtual llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockNo) const = 0;
    101100
    102101    bool isCapacityGuaranteed(const llvm::Value * const index, const size_t capacity) const;
    103102
    104     llvm::Value * modByBufferBlocks(llvm::Value * const offset) const;
    105 
    106     virtual llvm::Value * getBaseAddress(llvm::Value * self) const;
     103    llvm::Value * modByBufferBlocks(IDISA::IDISA_Builder * const iBuilder, llvm::Value * const offset) const;
     104
     105    virtual llvm::Value * getBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const;
    107106
    108107    void setProducer(kernel::KernelBuilder * const producer) {
     
    118117protected:
    119118    const BufferKind                        mBufferKind;
    120     IDISA::IDISA_Builder * const            iBuilder;
    121119    llvm::Type * const                      mType;
    122120    const size_t                            mBufferBlocks;
     
    139137protected:
    140138
    141     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     139    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockNo) const override;
    142140};
    143141
     
    150148    SourceBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    151149
    152     void setBaseAddress(llvm::Value * self, llvm::Value * addr) const override;
    153 
    154     void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
    155 
    156     llvm::Value * getBufferedSize(llvm::Value * self) const override;
    157 
    158     llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
    159 
    160 protected:
    161 
    162     llvm::Value * getBaseAddress(llvm::Value * self) const override;
    163 
    164     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     150    void setBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * addr) const override;
     151
     152    void setBufferedSize(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * size) const override;
     153
     154    llvm::Value * getBufferedSize(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
     155
     156    llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const override;
     157
     158protected:
     159
     160    llvm::Value * getBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
     161
     162    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockNo) const override;
    165163
    166164};
     
    175173
    176174    // Can't allocate - raise an error. */
    177     void allocateBuffer() override;
    178 
    179     llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
    180 
    181 protected:
    182     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     175    void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     176
     177    llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * fromPosition, llvm::Value *) const override;
     178
     179protected:
     180    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockNo) const override;
    183181};
    184182
     
    192190
    193191protected:
    194     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
     192    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockIndex) const override;
    195193};
    196194   
     
    209207    CircularCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace = 0);
    210208
    211     void allocateBuffer() override;
     209    void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
    212210   
    213211    // Generate copyback code for the given number of overflowItems.
    214     void createCopyBack(llvm::Value * self, llvm::Value * overflowItems) const;
     212    void createCopyBack(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * overflowItems) const;
    215213       
    216214protected:
    217     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
     215    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockIndex) const override;
    218216private:
    219217    size_t mOverflowBlocks;
     
    227225    SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth = 64, unsigned AddressSpace = 0);
    228226   
    229     void allocateBuffer() override;
     227    void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
    230228   
    231229    // Generate copyback code for the given number of overflowItems.
    232     void createCopyBack(llvm::Value * self, llvm::Value * overflowItems) const;
    233 protected:
    234     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
     230    void createCopyBack(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * overflowItems) const;
     231protected:
     232    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * blockIndex) const override;
    235233private:
    236234    size_t mOverflowBlocks;
     
    248246    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    249247
    250     llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
    251 
    252     llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const override;
    253 
    254     llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
    255 
    256     void allocateBuffer() override;
    257 
    258     llvm::Value * getStreamSetCount(llvm::Value * self) const override;
    259 
    260     void releaseBuffer(llvm::Value * self) const override;
    261 
    262 protected:
    263 
    264     llvm::Value * getBaseAddress(llvm::Value * self) const override;
    265 
    266     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
    267 
    268 private:
    269 
    270     std::pair<llvm::Value *, llvm::Value *> getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
     248    llvm::Value * getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
     249
     250    llvm::Value * getStreamPackPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const override;
     251
     252    llvm::Value * getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * fromPosition) const override;
     253
     254    void allocateBuffer(IDISA::IDISA_Builder * const iBuilder) override;
     255
     256    llvm::Value * getStreamSetCount(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
     257
     258    void releaseBuffer(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
     259
     260protected:
     261
     262    llvm::Value * getBaseAddress(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self) const override;
     263
     264    llvm::Value * getStreamSetBlockPtr(IDISA::IDISA_Builder * const iBuilder, llvm::Value * blockIndex, llvm::Value *) const override;
     265
     266private:
     267
     268    std::pair<llvm::Value *, llvm::Value *> getInternalStreamBuffer(IDISA::IDISA_Builder * const iBuilder, llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    271269
    272270private:
Note: See TracChangeset for help on using the changeset viewer.