Changeset 5431 for icGREP


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
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5429 r5431  
    3232        return mMod;
    3333    }
    34    
    35     void setModule(llvm::Module * m) {
    36         assert (m);
    37         mMod = m;
     34
     35    void setModule(llvm::Module * const mod) {
     36        mMod = mod;
    3837    }
    3938
     
    211210
    212211protected:
    213     llvm::Module *                  mMod;   
     212    llvm::Module *                  mMod;
    214213    unsigned                        mCacheLineAlignment;
    215214    llvm::IntegerType *             mSizeType;
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5429 r5431  
    170170    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main, 0));
    171171
    172  //   ByteStream.setExternalBuffer(inputStream);
    173     BasisBits.allocateBuffer();
    174     matches.allocateBuffer();
    175     errors.allocateBuffer();
     172    BasisBits.allocateBuffer(iBuilder);
     173    matches.allocateBuffer(iBuilder);
     174    errors.allocateBuffer(iBuilder);
    176175
    177176    pxDriver.generatePipelineIR();
  • icGREP/icgrep-devel/icgrep/base64.cpp

    r5429 r5431  
    8686    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main,0));
    8787
    88     ByteStream.allocateBuffer();
    89     Expanded3_4Out.allocateBuffer();
    90     Radix64out.allocateBuffer();
    91     Base64out.allocateBuffer();
     88    ByteStream.allocateBuffer(iBuilder);
     89    Expanded3_4Out.allocateBuffer(iBuilder);
     90    Radix64out.allocateBuffer(iBuilder);
     91    Base64out.allocateBuffer(iBuilder);
    9292
    9393    pxDriver.generatePipelineIR();
  • 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:
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5400 r5431  
    6262 * @brief initializeCarryData
    6363 ** ------------------------------------------------------------------------------------------------------------- */
    64 void CarryManager::initializeCarryData(PabloKernel * const kernel) {
     64void CarryManager::initializeCarryData() {
    6565
    6666    // Each scope constructs its own CarryData struct, which will be added to the final "carries" struct
     
    8080    // set of carries for that iteration.
    8181
    82     mKernel = kernel;
    83 
    84     mCurrentScope = kernel->getEntryBlock();
     82    iBuilder = mKernel->getBuilder();
     83    assert ("CarryManager does not have a IDISA builder" && iBuilder);
     84
     85    PabloBlock * const entryBlock = mKernel->getEntryBlock();
     86
     87    mCurrentScope = entryBlock;
    8588
    8689    mCarryScopes = 0;
    8790
    88     mCarryMetadata.resize(getScopeCount(kernel->getEntryBlock()));
    89 
    90     Type * const carryStateTy = analyse(kernel->getEntryBlock());
     91    mCarryMetadata.resize(getScopeCount(entryBlock));
     92
     93    Type * const carryStateTy = analyse(entryBlock);
    9194
    9295    mKernel->addScalar(carryStateTy, "carries");
     
    108111    mCarryInfo = &mCarryMetadata[0];
    109112    assert (!mCarryInfo->hasSummary());
     113
     114    iBuilder = mKernel->getBuilder();
     115    assert ("CarryManager does not have a IDISA builder" && iBuilder);
    110116
    111117    mCurrentFrame = mKernel->getScalarFieldPtr("carries");
     
    117123
    118124    assert (mCarrySummaryStack.empty());
    119     mCarrySummaryStack.push_back(Constant::getNullValue(mCarryPackType));
    120 
    121     if (mHasLoop) {
     125    mCarrySummaryStack.push_back(Constant::getNullValue(getCarryPackType()));
     126
     127    if (mHasLoop) {       
    122128        mLoopSelector = mKernel->getScalarField("selector");
    123129        mNextLoopSelector = iBuilder->CreateXor(mLoopSelector, ConstantInt::get(mLoopSelector->getType(), 1));
    124130    }
     131
    125132}
    126133
     
    160167void CarryManager::enterLoopBody(BasicBlock * const entryBlock) {
    161168    if (mCarryInfo->hasSummary()) {
    162         PHINode * phiCarryOutSummary = iBuilder->CreatePHI(mCarryPackType, 2, "summary");
     169        PHINode * phiCarryOutSummary = iBuilder->CreatePHI(getCarryPackType(), 2, "summary");
    163170        assert (!mCarrySummaryStack.empty());
    164171        phiCarryOutSummary->addIncoming(mCarrySummaryStack.back(), entryBlock);
     
    195202        // RESIZE CARRY BLOCK
    196203        iBuilder->SetInsertPoint(resizeCarryState);
    197         const auto BlockWidth = mCarryPackType->getPrimitiveSizeInBits() / 8;
     204        const auto BlockWidth = getCarryPackType()->getPrimitiveSizeInBits() / 8;
    198205        const auto Log2BlockWidth = floor_log2(BlockWidth);
    199206        Constant * const carryStateWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(array->getType()->getPointerElementType()), iBuilder->getSizeTy(), false);
     
    230237
    231238        Value * ptr1 = iBuilder->CreateGEP(newSummary, summarySize);
    232         ptr1 = iBuilder->CreatePointerCast(ptr1, mCarryPackType->getPointerTo());
     239        ptr1 = iBuilder->CreatePointerCast(ptr1, getCarryPackType()->getPointerTo());
    233240
    234241        Value * ptr2 = iBuilder->CreateGEP(newSummary, iBuilder->CreateAdd(summarySize, iBuilder->getSize(BlockWidth)));
    235         ptr2 = iBuilder->CreatePointerCast(ptr2, mCarryPackType->getPointerTo());
    236 
    237         newSummary = iBuilder->CreatePointerCast(newSummary, mCarryPackType->getPointerTo());
     242        ptr2 = iBuilder->CreatePointerCast(ptr2, getCarryPackType()->getPointerTo());
     243
     244        newSummary = iBuilder->CreatePointerCast(newSummary, getCarryPackType()->getPointerTo());
    238245        iBuilder->CreateStore(newSummary, summaryPtr);
    239246        Value * const newCapacity = iBuilder->CreateShl(ONE, log2capacity);
     
    258265        Value * initialSummary = iBuilder->CreateAlignedMalloc(initialSummarySize, BlockWidth);
    259266        iBuilder->CreateMemZero(initialSummary, initialSummarySize, BlockWidth);
    260         initialSummary = iBuilder->CreatePointerCast(initialSummary, mCarryPackType->getPointerTo());
     267        initialSummary = iBuilder->CreatePointerCast(initialSummary, getCarryPackType()->getPointerTo());
    261268        iBuilder->CreateStore(initialSummary, summaryPtr);
    262269
     
    333340        carry->addIncoming(carryOutAccumulator, entry);
    334341        // OR the updated carry in summary later for the summaryTest
    335         PHINode * const carryInSummary = iBuilder->CreatePHI(mCarryPackType, 2);
    336         carryInSummary->addIncoming(Constant::getNullValue(mCarryPackType), entry);
     342        PHINode * const carryInSummary = iBuilder->CreatePHI(getCarryPackType(), 2);
     343        carryInSummary->addIncoming(Constant::getNullValue(getCarryPackType()), entry);
    337344
    338345        // half subtractor
     
    362369        iBuilder->SetInsertPoint(resume);
    363370
    364         IntegerType * ty = IntegerType::get(iBuilder->getContext(), mCarryPackType->getPrimitiveSizeInBits());
     371        IntegerType * ty = IntegerType::get(iBuilder->getContext(), getCarryPackType()->getPrimitiveSizeInBits());
    365372        iBuilder->CreateAssert(iBuilder->CreateICmpEQ(iBuilder->CreateBitCast(finalBorrow, ty), ConstantInt::getNullValue(ty)), "finalBorrow != 0");
    366373        iBuilder->CreateAssert(iBuilder->CreateICmpEQ(iBuilder->CreateBitCast(finalCarry, ty), ConstantInt::getNullValue(ty)), "finalCarry != 0");
     
    381388        // If we're returning to the base scope, reset our accumulated summary value.
    382389        if (n == 2) {
    383             carryOut = Constant::getNullValue(mCarryPackType);
     390            carryOut = Constant::getNullValue(getCarryPackType());
    384391        }
    385392        mCarrySummaryStack.back() = carryOut;
     
    412419        }
    413420    }
    414     mCarrySummaryStack.push_back(Constant::getNullValue(mCarryPackType));
     421    mCarrySummaryStack.push_back(Constant::getNullValue(getCarryPackType()));
    415422}
    416423
     
    523530    std::tie(carryOut, result) = iBuilder->bitblock_add_with_carry(e1, e2, carryIn);
    524531    setNextCarryOut(carryOut);
    525     assert (result->getType() == mBitBlockType);
     532    assert (result->getType() == getBitBlockType());
    526533    return result;
    527534}
     
    537544        std::tie(carryOut, result) = iBuilder->bitblock_advance(value, carryIn, shiftAmount);
    538545        setNextCarryOut(carryOut);
    539         assert (result->getType() == mBitBlockType);
     546        assert (result->getType() == getBitBlockType());
    540547        return result;
    541548    } else {
     
    552559    assert (shiftAmount >= LONG_ADVANCE_BREAKPOINT);
    553560
    554     Type * const streamTy = iBuilder->getIntNTy(mBitBlockWidth);
     561    Type * const streamTy = iBuilder->getIntNTy(getBitBlockWidth());
    555562
    556563    if (mIfDepth > 0) {
    557         if (shiftAmount > mBitBlockWidth) {
     564        if (shiftAmount > getBitBlockWidth()) {
    558565            const auto frameIndex = mCurrentFrameIndex++;
    559566            Value * carry = iBuilder->CreateZExt(iBuilder->bitblock_any(value), streamTy);
    560             const unsigned summarySize = ceil_udiv(shiftAmount, mBitBlockWidth * mBitBlockWidth);
     567            const unsigned summarySize = ceil_udiv(shiftAmount, getBitBlockWidth() * getBitBlockWidth());
    561568            for (unsigned i = 0;;++i) {
    562569                Value * const ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), iBuilder->getInt32(i)});
    563570                Value * const prior = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(ptr), streamTy);
    564                 Value * const stream = iBuilder->CreateBitCast(iBuilder->CreateOr(iBuilder->CreateShl(prior, 1), carry), mBitBlockType);
     571                Value * const stream = iBuilder->CreateBitCast(iBuilder->CreateOr(iBuilder->CreateShl(prior, 1), carry), getBitBlockType());
    565572                if (LLVM_LIKELY(i == summarySize)) {
    566                     Value * const maskedStream = iBuilder->CreateAnd(stream, iBuilder->bitblock_mask_from(iBuilder->getInt32(summarySize % mBitBlockWidth)));
     573                    Value * const maskedStream = iBuilder->CreateAnd(stream, iBuilder->bitblock_mask_from(iBuilder->getInt32(summarySize % getBitBlockWidth())));
    567574                    addToCarryOutSummary(maskedStream);
    568575                    iBuilder->CreateBlockAlignedStore(maskedStream, ptr);
     
    571578                addToCarryOutSummary(stream);
    572579                iBuilder->CreateBlockAlignedStore(stream, ptr);
    573                 carry = iBuilder->CreateLShr(prior, mBitBlockWidth - 1);
     580                carry = iBuilder->CreateLShr(prior, getBitBlockWidth() - 1);
    574581            }
    575582        } else if (LLVM_LIKELY(mCarryInfo->hasExplicitSummary())) {
     
    579586    const auto frameIndex = mCurrentFrameIndex++;
    580587    // special case using a single buffer entry and the carry_out value.
    581     if (LLVM_LIKELY((shiftAmount < mBitBlockWidth) && (mLoopDepth == 0))) {
     588    if (LLVM_LIKELY((shiftAmount < getBitBlockWidth()) && (mLoopDepth == 0))) {
    582589        Value * const buffer = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), iBuilder->getInt32(0)});
    583         assert (buffer->getType()->getPointerElementType() == mBitBlockType);
     590        assert (buffer->getType()->getPointerElementType() == getBitBlockType());
    584591        Value * carryIn = iBuilder->CreateBlockAlignedLoad(buffer);       
    585592        iBuilder->CreateBlockAlignedStore(value, buffer);
    586593        /* Very special case - no combine */
    587         if (LLVM_UNLIKELY(shiftAmount == mBitBlockWidth)) {
    588             return iBuilder->CreateBitCast(carryIn, mBitBlockType);
    589         }
    590         Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), mBitBlockWidth - shiftAmount);
     594        if (LLVM_UNLIKELY(shiftAmount == getBitBlockWidth())) {
     595            return iBuilder->CreateBitCast(carryIn, getBitBlockType());
     596        }
     597        Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), getBitBlockWidth() - shiftAmount);
    591598        Value* block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(value, streamTy), shiftAmount);
    592         return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
     599        return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), getBitBlockType());
    593600    } else { //
    594         const unsigned blockShift = shiftAmount % mBitBlockWidth;
    595         const unsigned blocks = ceil_udiv(shiftAmount, mBitBlockWidth);
     601        const unsigned blockShift = shiftAmount % getBitBlockWidth();
     602        const unsigned blocks = ceil_udiv(shiftAmount, getBitBlockWidth());
    596603        // Create a mask to implement circular buffer indexing
    597604        Value * indexMask = iBuilder->getSize(nearest_pow2(blocks + ((mLoopDepth != 0) ? 1 : 0)) - 1);
     
    604611        Value * storeIndex = iBuilder->CreateAnd(blockIndex, indexMask);
    605612        Value * const carryOutPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), storeIndex});
    606         assert (carryIn->getType() == mBitBlockType);
     613        assert (carryIn->getType() == getBitBlockType());
    607614
    608615        // If the long advance is an exact multiple of BitBlockWidth, we simply return the oldest
     
    616623            Value * const carryInPtr2 = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(frameIndex), loadIndex1});
    617624            Value * carry_block1 = iBuilder->CreateBlockAlignedLoad(carryInPtr2);
    618             Value * block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), mBitBlockWidth - blockShift);
     625            Value * block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carryIn, streamTy), getBitBlockWidth() - blockShift);
    619626            Value * block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(carry_block1, streamTy), blockShift);
    620627            iBuilder->CreateBlockAlignedStore(value, carryOutPtr);
    621             return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
     628            return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), getBitBlockType());
    622629        }
    623630    }
     
    634641        mCarryPackPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(mCurrentFrameIndex), mLoopSelector});
    635642    }
    636     assert (mCarryPackPtr->getType()->getPointerElementType() == mCarryPackType);
     643    assert (mCarryPackPtr->getType()->getPointerElementType() == getCarryPackType());
    637644    Value * const carryIn = iBuilder->CreateBlockAlignedLoad(mCarryPackPtr);
    638645    if (mLoopDepth > 0) {
    639         iBuilder->CreateBlockAlignedStore(Constant::getNullValue(mCarryPackType), mCarryPackPtr);
     646        iBuilder->CreateBlockAlignedStore(Constant::getNullValue(getCarryPackType()), mCarryPackPtr);
    640647    }
    641648    return carryIn;
     
    647654void CarryManager::setNextCarryOut(Value * carryOut) {
    648655    assert (mCurrentFrameIndex < mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    649     carryOut = iBuilder->CreateBitCast(carryOut, mCarryPackType);
     656    carryOut = iBuilder->CreateBitCast(carryOut, getCarryPackType());
    650657    if (mCarryInfo->hasSummary()) {
    651658        addToCarryOutSummary(carryOut);
     
    659666    }
    660667    ++mCurrentFrameIndex;
    661     assert (mCarryPackPtr->getType()->getPointerElementType() == mCarryPackType);
     668    assert (mCarryPackPtr->getType()->getPointerElementType() == getCarryPackType());
    662669    iBuilder->CreateBlockAlignedStore(carryOut, mCarryPackPtr);
    663670}
     
    690697    Value * const summary = iBuilder->CreateBlockAlignedLoad(ptr);
    691698    if (mLoopDepth != 0 && mCarryInfo->hasExplicitSummary()) {
    692         iBuilder->CreateBlockAlignedStore(Constant::getNullValue(mCarryPackType), ptr);
     699        iBuilder->CreateBlockAlignedStore(Constant::getNullValue(getCarryPackType()), ptr);
    693700    }
    694701    return summary;
     
    767774    assert (scope != mKernel->getEntryBlock() || mCarryScopes == 0);
    768775    assert (mCarryScopes < mCarryMetadata.size());
    769     assert (mCarryPackType);
     776    assert (getCarryPackType());
    770777
    771778    const unsigned carryScopeIndex = mCarryScopes++;
    772779    const bool nonCarryCollapsingMode = hasIterationSpecificAssignment(scope);
    773     Type * const carryPackType = (loopDepth == 0) ? mCarryPackType : ArrayType::get(mCarryPackType, 2);
     780    Type * const carryPackType = (loopDepth == 0) ? getCarryPackType() : ArrayType::get(getCarryPackType(), 2);
    774781    std::vector<Type *> state;
    775782
     
    779786            Type * type = carryPackType;
    780787            if (LLVM_UNLIKELY(amount >= LONG_ADVANCE_BREAKPOINT)) {
    781                 const unsigned blocks = ceil_udiv(amount, mBitBlockWidth);
    782                 type = ArrayType::get(mBitBlockType, nearest_pow2(blocks + ((loopDepth != 0) ? 1 : 0)));
    783                 if (LLVM_UNLIKELY(ifDepth > 0 && amount > mBitBlockWidth)) {
     788                const unsigned blocks = ceil_udiv(amount, getBitBlockWidth());
     789                type = ArrayType::get(getBitBlockType(), nearest_pow2(blocks + ((loopDepth != 0) ? 1 : 0)));
     790                if (LLVM_UNLIKELY(ifDepth > 0 && amount > getBitBlockWidth())) {
    784791                    // 1 bit will mark the presense of any bit in each block.
    785                     Type * carryType = ArrayType::get(mBitBlockType, ceil_udiv(amount, mBitBlockWidth * mBitBlockWidth));
     792                    Type * carryType = ArrayType::get(getBitBlockType(), ceil_udiv(amount, getBitBlockWidth() * getBitBlockWidth()));
    786793                    state.push_back(carryType);
    787794                }
     
    823830        // carry state pointer, and summary pointer struct.
    824831        if (LLVM_UNLIKELY(nonCarryCollapsingMode)) {
    825             carryState = StructType::get(iBuilder->getSizeTy(), carryState->getPointerTo(), mCarryPackType->getPointerTo(), nullptr);
     832            carryState = StructType::get(iBuilder->getSizeTy(), carryState->getPointerTo(), getCarryPackType()->getPointerTo(), nullptr);
    826833        }
    827834        cd.setNonCollapsingCarryMode(nonCarryCollapsingMode);
     
    831838}
    832839
     840inline unsigned CarryManager::getBitBlockWidth() const {
     841    return iBuilder->getBitBlockWidth();
     842}
     843
     844inline llvm::Type * CarryManager::getCarryPackType() const {
     845    return getBitBlockType();
     846}
     847
     848inline llvm::Type * CarryManager::getBitBlockType() const {
     849    return iBuilder->getBitBlockType();
     850}
     851
    833852/** ------------------------------------------------------------------------------------------------------------- *
    834853 * @brief constructor
    835854 ** ------------------------------------------------------------------------------------------------------------- */
    836 CarryManager::CarryManager(IDISA::IDISA_Builder * idb) noexcept
    837 : iBuilder(idb)
    838 , mKernel(nullptr)
    839 , mBitBlockType(idb->getBitBlockType())
    840 , mBitBlockWidth(idb->getBitBlockWidth())
     855CarryManager::CarryManager(PabloKernel * const kernel) noexcept
     856: mKernel(kernel)
     857, iBuilder(nullptr)
    841858, mCurrentFrame(nullptr)
    842859, mCurrentFrameIndex(0)
    843860, mCurrentScope(nullptr)
    844861, mCarryInfo(nullptr)
    845 , mCarryPackType(mBitBlockType)
    846862, mNextSummaryTest(nullptr)
    847863, mIfDepth(0)
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5400 r5431  
    2323namespace pablo { class Statement; }
    2424
    25 
    2625/*
    2726 * Carry Data Manager.
     
    4342public:
    4443 
    45     CarryManager(IDISA::IDISA_Builder * idb) noexcept;
     44    CarryManager(PabloKernel * const kernel) noexcept;
    4645
    47     void initializeCarryData(PabloKernel * const kernel);
     46    void initializeCarryData();
    4847
    4948    void initializeCodeGen();
     
    103102    void addToCarryOutSummary(llvm::Value * const value);
    104103
     104    llvm::Type * getBitBlockType() const;
     105
     106    unsigned getBitBlockWidth() const;
     107
     108    llvm::Type * getCarryPackType() const;
     109
    105110private:
    106111
    107     IDISA::IDISA_Builder * const                    iBuilder;
    108     PabloKernel *                                   mKernel;
    109     llvm::Type * const                              mBitBlockType;
    110     const unsigned                                  mBitBlockWidth;
     112    PabloKernel * const                             mKernel;
     113    IDISA::IDISA_Builder *                          iBuilder;
    111114
    112115    llvm::Value *                                   mCurrentFrame;
     
    116119    CarryData *                                     mCarryInfo;
    117120
    118     llvm::Type *                                    mCarryPackType;
    119121    llvm::Value *                                   mNextSummaryTest;
    120122
     
    137139    std::vector<unsigned>                           mCarryScopeIndex;
    138140
    139 //    std::vector<llvm::Value *>                      mCarryInSummary;
    140141    std::vector<llvm::Value *>                      mCarrySummaryStack;
    141142};
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5385 r5431  
    4545
    4646void PabloCompiler::compile() {
     47    iBuilder = mKernel->getBuilder();
     48    assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    4749    mCarryManager->initializeCodeGen();     
    4850    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
     
    5456
    5557void PabloCompiler::initializeKernelData() {
     58    iBuilder = mKernel->getBuilder();
     59    assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    5660    examineBlock(mKernel->getEntryBlock());
    57     mCarryManager->initializeCarryData(mKernel);
     61    mCarryManager->initializeCarryData();
    5862}
    5963
     
    641645}
    642646
    643 PabloCompiler::PabloCompiler(PabloKernel * kernel)
    644 : iBuilder(kernel->getBuilder())
     647PabloCompiler::PabloCompiler(PabloKernel * const kernel)
     648: iBuilder(nullptr)
    645649, mKernel(kernel)
    646 , mCarryManager(new CarryManager(iBuilder)) {
    647 
     650, mCarryManager(new CarryManager(kernel)) {
     651    assert ("PabloKernel cannot be null!" && kernel);
    648652}
    649653
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5347 r5431  
    5656private:
    5757
    58     IDISA::IDISA_Builder * const    iBuilder;
     58    IDISA::IDISA_Builder *          iBuilder;
    5959    PabloKernel * const             mKernel;
    6060    CarryManager * const            mCarryManager;
  • icGREP/icgrep-devel/icgrep/toolchain/object_cache.cpp

    r5425 r5431  
    11#include "object_cache.h"
     2#include <kernels/kernel.h>
    23#include <llvm/Support/raw_ostream.h>
     4#include <llvm/Support/MemoryBuffer.h>
    35#include <llvm/Support/FileSystem.h>
    46#include <llvm/Support/Path.h>
    57#include <llvm/IR/Module.h>
    6 #include <string>
     8#include <sys/file.h>
     9#include <sys/stat.h>
     10#include <fcntl.h>
     11#include <boost/filesystem.hpp>
     12#include <ctime>
    713
    814using namespace llvm;
     
    1622// file exists.
    1723//
    18 ParabixObjectCache::ParabixObjectCache(const std::string &dir): CacheDir(dir) {}
     24ParabixObjectCache::ParabixObjectCache(const std::string &dir): mCachePath(dir) {}
    1925
    2026ParabixObjectCache::ParabixObjectCache() {
    2127    // $HOME/.cache/icgrep
    2228    // TODO use path::user_cache_directory once we have llvm >= 3.7.
    23     sys::path::home_directory(CacheDir);
    24     std::string Version = PARABIX_VERSION;
    25     std::string Date = __DATE__;
    26     std::string Time = __TIME__;
    27     std::string DateStamp = Date.substr(7) + Date.substr(0,3) + (Date[4] == ' ' ? Date.substr(5,1) : Date.substr(4,2));
    28     std::string CacheSubDir = "Parabix" + Version + "_" + DateStamp + "@" + Time;
    29     sys::path::append(CacheDir, ".cache", CacheSubDir);
     29    sys::path::home_directory(mCachePath);
     30    sys::path::append(mCachePath, ".cache", "parabix");
     31
     32    const std::string Version = PARABIX_VERSION;
     33    const std::string Date = __DATE__;
     34    const std::string Time = __TIME__;
     35    const std::string DateStamp = Date.substr(7) + Date.substr(0, 3) + (Date[4] == ' ' ? Date.substr(5, 1) : Date.substr(4, 2));
     36    mCachePrefix = Version + "_" + DateStamp + "@" + Time;
    3037}
    3138
    32 ParabixObjectCache::~ParabixObjectCache() {}
     39bool ParabixObjectCache::loadCachedObjectFile(kernel::KernelBuilder * const kernel) {
     40    if (LLVM_LIKELY(kernel->isCachable())) {
    3341
    34 // A new module has been compiled.   If it is cacheable and no conflicting module
    35 // exists, write it out. 
    36 void ParabixObjectCache::notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) {
    37     const std::string &ModuleID = M->getModuleIdentifier();
    38     auto f = cachedObjectMap.find(ModuleID);
    39     if (f!= cachedObjectMap.end()) return;
    40     Path CacheName(CacheDir);
    41     if (!getCacheFilename(ModuleID, CacheName)) return;
    42     if (!CacheDir.empty())      // Re-creating an existing directory is fine.
    43         sys::fs::create_directories(Twine(CacheDir));
    44     std::error_code EC;
    45     raw_fd_ostream outfile(CacheName, EC, sys::fs::F_None);
    46     outfile.write(Obj.getBufferStart(), Obj.getBufferSize());
    47     outfile.close();
    48     auto s = kernelSignatureMap.find(ModuleID);  // Check for a kernel signature.
    49     if (s != kernelSignatureMap.end()) {
    50         if (s->second == ModuleID) return;  // No signature is written when the signature is the ModuleID.
    51         sys::path::replace_extension(CacheName, ".sig");
    52         raw_fd_ostream sigfile(CacheName, EC, sys::fs::F_None);
    53         sigfile << s->second;
    54         sigfile.close();
     42        Module * const module = kernel->getModule();
     43        assert ("kernel module cannot be null!" && module);
     44        const auto moduleId = module->getModuleIdentifier();
     45
     46        // Have we already seen this module before?
     47        if (LLVM_UNLIKELY(mCachedObjectMap.count(moduleId) != 0)) {
     48            const auto f = mKernelSignatureMap.find(moduleId);
     49            if (f == mKernelSignatureMap.end()) {
     50                return kernel->moduleIDisSignature();
     51            } else if (kernel->moduleIDisSignature() || (kernel->makeSignature() != f->second)) {
     52                return false;
     53            }
     54            return true;
     55        }
     56
     57        // No, check for an existing cache file.
     58        Path objectName(mCachePath);
     59        sys::path::append(objectName, mCachePrefix + moduleId + ".o");
     60        auto objectBuffer = MemoryBuffer::getFile(objectName.c_str(), -1, false);
     61        if (objectBuffer) {
     62            if (!kernel->moduleIDisSignature()) {
     63                sys::path::replace_extension(objectName, ".sig");
     64                const auto signatureBuffer = MemoryBuffer::getFile(objectName.c_str(), -1, false);
     65                if (signatureBuffer) {
     66                    const StringRef loadedSig = signatureBuffer.get()->getBuffer();
     67                    if (!loadedSig.equals(kernel->makeSignature())) {
     68                        return false;
     69                    }
     70                } else {
     71                    report_fatal_error("signature file expected but not found: " + moduleId);
     72                    return false;
     73                }
     74            }
     75            // updae the modified time of the file then add it to our cache
     76            boost::filesystem::last_write_time(objectName.c_str(), time(0));
     77            mCachedObjectMap.emplace(moduleId, std::move(objectBuffer.get()));
     78            return true;
     79        } else if (!kernel->moduleIDisSignature()) {
     80            mKernelSignatureMap.emplace(moduleId, kernel->makeSignature());
     81        }
    5582    }
     83    return false;
    5684}
    5785
    58 bool ParabixObjectCache::loadCachedObjectFile(std::string ModuleID, std::string signature) {
    59     // Have we already seen this module before.
    60     auto s = kernelSignatureMap.find(ModuleID);
    61     if (s!= kernelSignatureMap.end()) {
    62         if (s->second != signature) {
     86// A new module has been compiled. If it is cacheable and no conflicting module
     87// exists, write it out.
     88void ParabixObjectCache::notifyObjectCompiled(const Module * M, MemoryBufferRef Obj) {
     89    const auto moduleId = M->getModuleIdentifier();
     90    if (mCachedObjectMap.count(moduleId) == 0) {
    6391
     92        Path objectName(mCachePath);
     93        sys::path::append(objectName, mCachePrefix + moduleId + ".o");
    6494
    65 #ifdef OBJECT_CACHE_DEBUG
    66             std::cerr << "loadCachedObjectFile:  conflicting signatures for the same moduleID! " << ModuleID << std::endl;
    67 #endif
    68             return false;
     95        if (LLVM_LIKELY(!mCachePath.empty())) {
     96            sys::fs::create_directories(Twine(mCachePath));
    6997        }
    70         // A cached entry exists if it has already been loaded.
    71         return cachedObjectMap.count(ModuleID) != 0;
    72     }
    73     // Confirm that the module is cacheable.
    74     Path CachedObjectName(CacheDir);
    75     if (!getCacheFilename(ModuleID, CachedObjectName)) {
    76         return false;
    77     }
    78     //
    79     // Save the signature.
    80     kernelSignatureMap.emplace(ModuleID, signature);
    81     //
    82     // Now checkfor a cache file.
    83     ErrorOr<std::unique_ptr<MemoryBuffer>> KernelObjectBuffer = MemoryBuffer::getFile(CachedObjectName.c_str(), -1, false);
    84     if (!KernelObjectBuffer) return false;
    85     //
    86     if (ModuleID != signature) {
    87         // Confirm the signature.
    88         sys::path::replace_extension(CachedObjectName, ".sig");
    89         ErrorOr<std::unique_ptr<MemoryBuffer>> SignatureBuffer = MemoryBuffer::getFile(CachedObjectName.c_str(), -1, false);
    90         if (!SignatureBuffer) {
    91             report_fatal_error("signature file expected but not found: " + ModuleID);
    92             return false;
    93         }
    94         StringRef loadedSig = SignatureBuffer.get()->getBuffer(); 
    95         if (!loadedSig.equals(signature)) {
    96             report_fatal_error("computed signature does not match stored signature: " + ModuleID);
     98
     99        std::error_code EC;
     100        raw_fd_ostream outfile(objectName, EC, sys::fs::F_None);
     101        outfile.write(Obj.getBufferStart(), Obj.getBufferSize());
     102        outfile.close();
     103
     104        // Check for a kernel signature.
     105        const auto sig = mKernelSignatureMap.find(moduleId);
     106        if (LLVM_UNLIKELY(sig != mKernelSignatureMap.end())) {
     107            sys::path::replace_extension(objectName, ".sig");
     108            raw_fd_ostream sigfile(objectName, EC, sys::fs::F_None);
     109            sigfile << sig->second;
     110            sigfile.close();
    97111        }
    98112    }
    99     // Make a copy so that the JIT engine can freely modify it.
    100     cachedObjectMap.emplace(ModuleID, std::move(KernelObjectBuffer.get()));
    101     return true;
    102113}
    103114
     
    115126
    116127std::unique_ptr<MemoryBuffer> ParabixObjectCache::getObject(const Module* M) {
    117     const std::string &ModuleID = M->getModuleIdentifier();
    118     auto f = cachedObjectMap.find(ModuleID);
    119     if (f == cachedObjectMap.end()) {
     128    auto f = mCachedObjectMap.find(M->getModuleIdentifier());
     129    if (f == mCachedObjectMap.end()) {
    120130        return nullptr;
    121131    }
     
    124134}
    125135
    126 bool ParabixObjectCache::getCacheFilename(const std::string &ModID, Path &CacheName) {
    127     const std::string Prefix("Parabix:");
    128     size_t PrefixLength = Prefix.length();
    129     if (ModID.substr(0, PrefixLength) != Prefix)
    130         return false;
    131     CacheName = CacheDir;
    132     sys::path::append(CacheName, ModID.substr(PrefixLength) + ".o");
    133     return true;
    134 }
  • icGREP/icgrep-devel/icgrep/toolchain/object_cache.h

    r5425 r5431  
    1010#include <llvm/ADT/SmallString.h>
    1111#include <llvm/ExecutionEngine/ObjectCache.h>
    12 #include <llvm/Support/MemoryBuffer.h>
    1312#include <llvm/ADT/StringRef.h>
    1413#include <string>
    15 #include <map>
     14#include <boost/container/flat_map.hpp>
    1615
    1716namespace llvm { class Module; }
     17namespace llvm { class MemoryBuffer; }
     18namespace llvm { class MemoryBufferRef; }
     19namespace kernel { class KernelBuilder; }
    1820
    1921// The ParabixObjectCache is a two-level cache compatible with the requirements
     
    2931//
    3032
    31 class ParabixObjectCache : public llvm::ObjectCache {
    32     public:
    33         ParabixObjectCache(const std::string &dir);
    34         ParabixObjectCache();
    35         virtual ~ParabixObjectCache();
     33class ParabixObjectCache final : public llvm::ObjectCache {
     34    using Path = llvm::SmallString<128>;
     35    template <typename K, typename V>
     36    using Map = boost::container::flat_map<K, V>;
     37    using CacheEntry = std::pair<kernel::KernelBuilder *, std::unique_ptr<llvm::MemoryBuffer>>;
     38    using CacheMap = Map<llvm::Module *, CacheEntry>;
     39public:
    3640
    37         void notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef Obj) override;
    38         bool loadCachedObjectFile(std::string ModuleID, std::string signature);
    39         std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module* M) override;
    40    
    41     private:
    42         std::map<std::string, std::string> kernelSignatureMap;
    43         std::map<std::string, std::unique_ptr<llvm::MemoryBuffer>> cachedObjectMap;
    44         using Path = llvm::SmallString<128>;
    45         Path CacheDir;
     41//    enum Status {
     42//        Failed
     43//        , Succeeded
     44//        , ObjectFileLocked
     45//    };
    4646
    47         bool getCacheFilename(const std::string & ModID, Path & CacheName);
     47    ParabixObjectCache(const std::string &dir);
     48    ParabixObjectCache();
     49    bool loadCachedObjectFile(kernel::KernelBuilder * const kernel);
     50    void notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef Obj) override;
     51    std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module * M) override;
     52private:
     53//    CacheMap        mCachedObject;
     54
     55    Map<std::string, std::string>                           mKernelSignatureMap;
     56    Map<std::string, std::unique_ptr<llvm::MemoryBuffer>>   mCachedObjectMap;
     57    Path                                                    mCachePath;
     58    Path                                                    mCachePrefix;
    4859};
    4960
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5429 r5431  
    9191   
    9292static cl::opt<bool> segmentPipelineParallel("enable-segment-pipeline-parallel", cl::desc("Enable multithreading with segment pipeline parallelism."), cl::cat(CodeGenOptions));
    93    
    94 #ifdef CUDA_ENABLED
    95 bool NVPTX;
    96 int GroupNum;
    97 static cl::opt<bool> USENVPTX("NVPTX", cl::desc("Run on GPU only."), cl::init(false));
    98 static cl::opt<int, true> GroupNumOption("group-num", cl::location(GroupNum), cl::desc("NUmber of groups declared on GPU"), cl::value_desc("positive integer"), cl::init(256));
    99 #endif
    100 
    101 }
    102 
    103 #ifdef CUDA_ENABLED
    104 void setNVPTXOption(){
    105     codegen::NVPTX = codegen::USENVPTX;
    106 }
    107 
    108 void Compile2PTX (Module * m, std::string IRFilename, std::string PTXFilename) {
    109     InitializeAllTargets();
    110     InitializeAllTargetMCs();
    111     InitializeAllAsmPrinters();
    112     InitializeAllAsmParsers();
    113 
    114     PassRegistry *Registry = PassRegistry::getPassRegistry();
    115     initializeCore(*Registry);
    116     initializeCodeGen(*Registry);
    117     initializeLoopStrengthReducePass(*Registry);
    118     initializeLowerIntrinsicsPass(*Registry);
    119     initializeUnreachableBlockElimPass(*Registry);
    120 
    121     std::error_code error;
    122     raw_fd_ostream out(IRFilename, error, sys::fs::OpenFlags::F_None);
    123     m->print(out, nullptr);
    124 
    125     if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowIR)))
    126             m->dump();
    127 
    128     llvm2ptx(IRFilename, PTXFilename);
    129 }
    130 #endif
     93
     94}
    13195
    13296void printParabixVersion () {
     
    223187
    224188StreamSetBuffer * ParabixDriver::addBuffer(std::unique_ptr<StreamSetBuffer> b) {
    225     b->allocateBuffer();
     189    b->allocateBuffer(iBuilder.get());
    226190    mOwnedBuffers.emplace_back(std::move(b));
    227191    return mOwnedBuffers.back().get();
     
    229193
    230194kernel::KernelBuilder * ParabixDriver::addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb) {
     195    kb->setBuilder(iBuilder.get());
    231196    mOwnedKernels.emplace_back(std::move(kb));
    232197    return mOwnedKernels.back().get();
     
    259224    // note: instantiation of all kernels must occur prior to initialization
    260225    for (const auto & k : mPipeline) {
    261         k->addKernelDeclarations(mMainModule);
    262     }
    263 
     226        k->addKernelDeclarations();
     227    }
    264228    for (const auto & k : mPipeline) {
    265229        k->createInstance();
    266230    }
    267 
    268231    for (const auto & k : mPipeline) {
    269232        k->initializeInstance();
    270233    }
    271 
    272234    if (codegen::pipelineParallel) {
    273235        generateParallelPipeline(iBuilder, mPipeline);
     
    278240        generatePipelineLoop(iBuilder, mPipeline);
    279241    }
    280 
    281242    for (const auto & k : mPipeline) {
    282243        k->finalizeInstance();
     
    333294
    334295    PM.run(*m);
     296
    335297    for (kernel::KernelBuilder * const kb : mPipeline) {
    336298        m = kb->getModule();
    337299        bool uncachedObject = true;
    338         if (mCache) {
    339             const std::string moduleID = m->getModuleIdentifier();
    340             const std::string signature = kb->generateKernelSignature(moduleID);
    341             if (mCache->loadCachedObjectFile(moduleID, signature)) {
    342                 uncachedObject = false;
    343             }
     300        if (mCache && mCache->loadCachedObjectFile(kb)) {
     301            uncachedObject = false;
    344302        }
    345303        if (uncachedObject) {
    346             Module * const cm = iBuilder->getModule();
    347             iBuilder->setModule(m);
     304            iBuilder->setModule(kb->getModule());
    348305            kb->generateKernel();
    349306            PM.run(*m);
    350             iBuilder->setModule(cm);
    351         }       
     307        }
    352308        mEngine->addModule(std::unique_ptr<Module>(m));
    353309    }   
    354310    mEngine->finalizeObject();
    355311
     312    iBuilder->setModule(mMainModule);
     313
    356314    delete IROutputStream;
    357315    #ifndef USE_LLVM_3_6
Note: See TracChangeset for help on using the changeset viewer.