Changeset 5246


Ignore:
Timestamp:
Jan 5, 2017, 3:54:40 PM (11 months ago)
Author:
nmedfort
Message:

Code clean up to enforce proper calling order of KernelBuilder? methods

Location:
icGREP/icgrep-devel/icgrep
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.cpp

    r5238 r5246  
    1212using namespace llvm;
    1313
    14 void editdCPUKernel::bitblock_advance_ci_co(Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j){   
    15     if(!calculated[i][j]){
     14void editdCPUKernel::bitblock_advance_ci_co(Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j) const {
     15    if (calculated[i][j] == 0) {
    1616        Value * ptr = iBuilder->CreateGEP(stideCarryArr, {iBuilder->getInt32(0), iBuilder->getInt32(carryIdx)});
    1717        Value * ci = iBuilder->CreateLoad(ptr);
     
    2121        calculated[i][j] = 1;
    2222    }
    23     return;
    2423}
    2524
    26 void editdCPUKernel::generateFinalBlockMethod() {
     25void editdCPUKernel::generateFinalBlockMethod() const {
    2726    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    2827    Module * m = iBuilder->getModule();
     
    4241    /* Adjust the produced item count */
    4342    Value * produced = getProducedItemCount(self);
    44     produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     43    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    4544    setProducedItemCount(self, iBuilder->CreateAdd(produced, remaining));
    4645    iBuilder->CreateRetVoid();
     
    4847}
    4948   
    50 void editdCPUKernel::generateDoBlockMethod() {
     49void editdCPUKernel::generateDoBlockMethod() const {
    5150    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    5251    Module * m = iBuilder->getModule(); 
     
    6766    Value * ccStreamPtr = getStreamSetBlockPtr(kernelStuctParam, "CCStream", blockNo);
    6867    Value * resultStreamPtr = getStreamSetBlockPtr(kernelStuctParam, "ResultStream", blockNo);
    69     Value * pattPos = ConstantInt::get(int32ty, 0);
     68
    7069   
    7170    unsigned carryIdx = 0;
     
    7372    std::vector<std::vector<Value *>> e(mPatternLen+1, std::vector<Value *>(mEditDistance+1));
    7473    std::vector<std::vector<Value *>> adv(mPatternLen, std::vector<Value *>(mEditDistance+1));
    75     std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance+1));
    76     for(unsigned i=0; i<mPatternLen; i++)
    77         for(unsigned j=0; j<=mEditDistance; j++)
    78             calculated[i][j] = 0;
    79     Value * pattPtr = iBuilder->CreateGEP(pattStartPtr, {pattPos});
     74    std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance + 1, 0));
     75    Value * pattPos = iBuilder->getInt32(0);
     76    Value * pattPtr = iBuilder->CreateGEP(pattStartPtr, pattPos);
    8077    Value * pattCh = iBuilder->CreateLoad(pattPtr);
    8178    Value * pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
     
    9087
    9188    for(unsigned i = 1; i<mPatternLen; i++){     
    92         pattPtr = iBuilder->CreateGEP(pattStartPtr, {pattPos});
     89        pattPtr = iBuilder->CreateGEP(pattStartPtr, pattPos);
    9390        pattCh = iBuilder->CreateLoad(pattPtr);
    9491        pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
     
    119116
    120117    Value * produced = getProducedItemCount(kernelStuctParam);
    121     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     118    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    122119    setProducedItemCount(kernelStuctParam, produced);
    123120       
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5223 r5246  
    3232   
    3333private:
    34     void generateDoBlockMethod() override;
    35     void generateFinalBlockMethod() override;
    36     void bitblock_advance_ci_co(Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j);
     34    void generateDoBlockMethod() const override;
     35    void generateFinalBlockMethod() const override;
     36    void bitblock_advance_ci_co(Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j) const;
    3737    unsigned mEditDistance;
    3838    unsigned mPatternLen;
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.cpp

    r5240 r5246  
    2525}
    2626
    27 void editdGPUKernel::generateFinalBlockMethod() {
     27void editdGPUKernel::generateFinalBlockMethod() const {
    2828    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    2929    Module * m = iBuilder->getModule();
     
    4343    /* Adjust the produced item count */
    4444    Value * produced = getProducedItemCount(self);
    45     produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     45    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    4646    setProducedItemCount(self, iBuilder->CreateAdd(produced, remaining));
    4747    iBuilder->CreateRetVoid();
     
    4949}
    5050   
    51 void editdGPUKernel::generateDoBlockMethod() {
     51void editdGPUKernel::generateDoBlockMethod() const {
    5252    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    5353    Module * m = iBuilder->getModule(); 
     
    124124
    125125    Value * produced = getProducedItemCount(kernelStuctParam);
    126     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     126    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    127127    setProducedItemCount(kernelStuctParam, produced);
    128128       
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5217 r5246  
    3232   
    3333private:
    34     void generateDoBlockMethod() override;
    35     void generateFinalBlockMethod() override;
     34    void generateDoBlockMethod() const override;
     35    void generateFinalBlockMethod() const override;
    3636    unsigned mEditDistance;
    3737    unsigned mPatternLen;
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5238 r5246  
    2020}
    2121
    22 void editdScanKernel::generateDoBlockMethod() {
     22void editdScanKernel::generateDoBlockMethod() const {
    2323    auto savePoint = iBuilder->saveIP();
    2424    Module * m = iBuilder->getModule();
     
    5555}
    5656
    57 Function * editdScanKernel::generateScanWordRoutine(Module * m) {
     57Function * editdScanKernel::generateScanWordRoutine(Module * m) const {
    5858
    5959    Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5217 r5246  
    2727       
    2828private:
    29     void generateDoBlockMethod() override;
    30     llvm::Function * generateScanWordRoutine(llvm::Module * m);
     29    void generateDoBlockMethod() const override;
     30    llvm::Function * generateScanWordRoutine(llvm::Module * m) const;
    3131       
    3232    unsigned mEditDistance;
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5245 r5246  
    233233    }
    234234    const unsigned bufferSegments = codegen::BufferSegments;
    235 
    236 
    237     unsigned encodingBits = UTF_16 ? 16 : 8;
     235    const unsigned encodingBits = UTF_16 ? 16 : 8;
    238236
    239237    mGrepType = grepType;
     
    241239    Type * const size_ty = iBuilder->getSizeTy();
    242240    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    243     Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), (UTF_16 ? 16 : 8)), 1), addrSpace);
     241    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), encodingBits), 1), addrSpace);
    244242    Type * const resultTy = CountOnly ? size_ty : iBuilder->getVoidTy();
    245243
     
    304302    pablo_function_passes(&icgrepK);
    305303
    306 
    307 
    308304    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    309305    BasisBits.allocateBuffer();
    310 
    311306
    312307    if (CountOnly) {
     
    353348            }
    354349        }
    355 
    356350        iBuilder->CreateRetVoid();
    357 
    358351    }
    359352
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5217 r5246  
    1414using namespace re;
    1515
    16 void DirectCharacterClassKernelBuilder::generateDoBlockMethod() {
     16void DirectCharacterClassKernelBuilder::generateDoBlockMethod() const {
    1717    auto savePoint = iBuilder->saveIP();
    1818    Module * m = iBuilder->getModule();
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.h

    r5245 r5246  
    3333   
    3434private:
    35     void generateDoBlockMethod() override;
     35    void generateDoBlockMethod() const override;
    3636    std::vector<re::CC *> mCharClasses;
    3737    unsigned mCodeUnitSize;
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5238 r5246  
    5050namespace kernel {
    5151
    52 void DeletionKernel::generateDoBlockMethod() {
     52void DeletionKernel::generateDoBlockMethod() const {
    5353    auto savePoint = iBuilder->saveIP();
    5454    Module * m = iBuilder->getModule();
     
    8484     * has not yet changed.   */
    8585    Value * produced = getProducedItemCount(self);
    86     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     86    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    8787    setProducedItemCount(self, produced);
    8888    iBuilder->CreateRetVoid();
     
    9090}
    9191
    92 void DeletionKernel::generateFinalBlockMethod() {
     92void DeletionKernel::generateFinalBlockMethod() const {
    9393    auto savePoint = iBuilder->saveIP();
    9494    Module * m = iBuilder->getModule();
     
    111111    /* Adjust the produced item count */
    112112    Value * produced = getProducedItemCount(self);
    113     produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     113    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    114114    setProducedItemCount(self, iBuilder->CreateAdd(produced, remainingBytes));
    115115
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5217 r5246  
    5050   
    5151private:
    52     void generateDoBlockMethod() override;
    53     void generateFinalBlockMethod() override;
     52    void generateDoBlockMethod() const override;
     53    void generateFinalBlockMethod() const override;
    5454    unsigned mDeletionFieldWidth;
    5555    unsigned mStreamCount;
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5227 r5246  
    9595}
    9696
    97 
    9897void KernelInterface::setInitialArguments(std::vector<Value *> args) {
    9998    mInitialArguments = args;
    10099}
    101100
    102 void KernelInterface::createInstance() {
    103     mKernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
    104     Module * m = iBuilder->getModule();
    105     std::vector<Value *> init_args = {mKernelInstance};
    106     for (auto a : mInitialArguments) {
    107         init_args.push_back(a);
    108     }
    109     std::string initFnName = mKernelName + init_suffix;
    110     Function * initMethod = m->getFunction(initFnName);
    111     if (!initMethod) {
    112         throw std::runtime_error("Cannot find " + initFnName);
    113     }
    114     iBuilder->CreateCall(initMethod, init_args);
    115 }
    116 
    117 Value * KernelInterface::createDoBlockCall(Value * self) {
     101Value * KernelInterface::createDoBlockCall(Value * self) const {
    118102    Module * m = iBuilder->getModule();
    119103    std::string doBlockName = mKernelName + doBlock_suffix;
     
    126110}
    127111
    128 Value * KernelInterface::createFinalBlockCall(Value * self, Value * remainingBytes) {
     112Value * KernelInterface::createFinalBlockCall(Value * self, Value * remainingBytes) const {
    129113    Module * m = iBuilder->getModule();
    130114    std::string finalBlockName = mKernelName + finalBlock_suffix;
     
    138122
    139123
    140 Value * KernelInterface::createDoSegmentCall(Value * self, Value * blksToDo) {
     124Value * KernelInterface::createDoSegmentCall(Value * self, Value * blksToDo) const {
    141125    Module * m = iBuilder->getModule();
    142126    std::string fnName = mKernelName + doSegment_suffix;
     
    148132}
    149133
    150 Value * KernelInterface::createGetAccumulatorCall(Value * self, std::string accumName) {
     134Value * KernelInterface::createGetAccumulatorCall(Value * self, std::string accumName) const {
    151135    Module * m = iBuilder->getModule();
    152136    std::string fnName = mKernelName + accumulator_infix + accumName;
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5245 r5246  
    1616    llvm::Type * type;
    1717    std::string name;
    18 
    19     Binding(llvm::Type * type, std::string name)
    20     : type(type)
    21     , name(std::move(name)) {
    22 
    23     }
     18    Binding(llvm::Type * type, const std::string & name) : type(type), name(name) {}
     19    Binding(llvm::Type * type, std::string && name) : type(type), name(name) {}
    2420};
    2521
     
    4137     
    4238     */
    43    
    44     std::string & getName() { return mKernelName;}
    45    
     39       
    4640    std::vector<Binding> getStreamInputs() {return mStreamSetInputs;}
    4741    std::vector<Binding> getStreamOutputs() {return mStreamSetOutputs;}
     
    5246    // Add ExternalLinkage method declarations for the kernel to a given client module.
    5347    void addKernelDeclarations(Module * client);
    54    
    55     void setInitialArguments(std::vector<llvm::Value *> initialParameters);
    56     virtual void createInstance();
    57     llvm::Value * getInstance() {return mKernelInstance;};
     48    virtual void createInstance() = 0;
     49    void setInitialArguments(std::vector<Value *> initialParameters);
     50    llvm::Value * getInstance() const { return mKernelInstance; }
    5851
    59     llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
    60     llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
    61     llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
     52    llvm::Value * createDoSegmentCall(llvm::Value * self, llvm::Value * blkCount) const;
     53    llvm::Value * createFinalBlockCall(llvm::Value * self, llvm::Value * remainingBytes) const;
     54    llvm::Value * createGetAccumulatorCall(llvm::Value * self, std::string accumName) const;
    6255   
    6356    unsigned getLookAhead() const {
     
    6962    }
    7063
    71     virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) = 0;
    72     virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) = 0;
    73     virtual llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) = 0;
     64    virtual llvm::Value * getProcessedItemCount(llvm::Value * self) const = 0;
     65    virtual llvm::Value * getProducedItemCount(llvm::Value * self) const = 0;
     66    virtual llvm::Value * getTerminationSignal(llvm::Value * self) const = 0;
    7467   
    7568    void setLookAhead(unsigned lookAheadPositions) {
     
    7770    }
    7871
    79     llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
     72    llvm::Value * createDoBlockCall(llvm::Value * self) const;
    8073
    8174protected:
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5242 r5246  
    1616
    1717KernelBuilder::KernelBuilder(IDISA::IDISA_Builder * builder,
    18                                  std::string kernelName,
    19                                  std::vector<Binding> stream_inputs,
    20                                  std::vector<Binding> stream_outputs,
    21                                  std::vector<Binding> scalar_parameters,
    22                                  std::vector<Binding> scalar_outputs,
    23                                  std::vector<Binding> internal_scalars)
     18                             std::string kernelName,
     19                             std::vector<Binding> stream_inputs,
     20                             std::vector<Binding> stream_outputs,
     21                             std::vector<Binding> scalar_parameters,
     22                             std::vector<Binding> scalar_outputs,
     23                             std::vector<Binding> internal_scalars)
    2424: KernelInterface(builder, kernelName, stream_inputs, stream_outputs, scalar_parameters, scalar_outputs, internal_scalars) {
    2525
    2626}
    2727
    28 unsigned KernelBuilder::addScalar(Type * type, std::string name) {
     28unsigned KernelBuilder::addScalar(Type * type, const std::string & name) {
    2929    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    3030        llvm::report_fatal_error("Cannot add kernel field " + name + " after kernel state finalized");
     
    3737
    3838void KernelBuilder::prepareKernel() {
     39    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
     40        llvm::report_fatal_error("Cannot prepare kernel after kernel state finalized");
     41    }
    3942    unsigned blockSize = iBuilder->getBitBlockWidth();
    4043    if (mStreamSetInputs.size() != mStreamSetInputBuffers.size()) {
     
    8386}
    8487
    85 std::unique_ptr<Module> KernelBuilder::createKernelModule(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers) {
    86     Module * saveModule = iBuilder->getModule();
     88std::unique_ptr<Module> KernelBuilder::createKernelModule(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
     89    auto saveModule = iBuilder->getModule();
    8790    auto savePoint = iBuilder->saveIP();
    88     auto theModule = make_unique<Module>(mKernelName + "_" + iBuilder->getBitBlockTypeName(), iBuilder->getContext());
    89     Module * m = theModule.get();
    90     iBuilder->setModule(m);
    91     generateKernel(input_buffers, output_buffers);
     91    auto module = make_unique<Module>(mKernelName + "_" + iBuilder->getBitBlockTypeName(), iBuilder->getContext());
     92    iBuilder->setModule(module.get());
     93    generateKernel(inputs, outputs);
    9294    iBuilder->setModule(saveModule);
    9395    iBuilder->restoreIP(savePoint);
    94     return theModule;
    95 }
    96 
    97 void KernelBuilder::generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer*> output_buffers) {
     96    return module;
     97}
     98
     99void KernelBuilder::generateKernel(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
    98100    auto savePoint = iBuilder->saveIP();
    99101    Module * const m = iBuilder->getModule();
    100     mStreamSetInputBuffers = input_buffers;
    101     mStreamSetOutputBuffers = output_buffers;
    102     prepareKernel();  // possibly overriden by the KernelBuilder subtype
     102    mStreamSetInputBuffers.assign(inputs.begin(), inputs.end());
     103    mStreamSetOutputBuffers.assign(outputs.begin(), outputs.end());
     104    prepareKernel();            // possibly overridden by the KernelBuilder subtype
    103105    addKernelDeclarations(m);
    104     generateDoBlockMethod();     // must be implemented by the KernelBuilder subtype
    105     generateFinalBlockMethod();  // possibly overriden by the KernelBuilder subtype
     106    generateDoBlockMethod();    // must be implemented by the KernelBuilder subtype
     107    generateFinalBlockMethod(); // possibly overridden by the KernelBuilder subtype
    106108    generateDoSegmentMethod();
    107109
     
    116118        iBuilder->CreateRet(retVal);
    117119    }
     120
    118121    // Implement the initializer function
    119122    Function * initFunction = m->getFunction(mKernelName + init_suffix);
    120     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));
    121    
     123    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));   
    122124    Function::arg_iterator args = initFunction->arg_begin();
    123125    Value * self = &*(args++);
    124     initializeKernelState(self);
     126    initializeKernelState(self);    // possibly overridden by the KernelBuilder subtype
    125127    for (auto binding : mScalarInputs) {
    126         Value * parm = &*(args++);
     128        Value * param = &*(args++);
    127129        Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.name)});
    128         iBuilder->CreateStore(parm, ptr);
     130        iBuilder->CreateStore(param, ptr);
    129131    }
    130132    iBuilder->CreateRetVoid();
     
    132134}
    133135
    134 void KernelBuilder::initializeKernelState(Value * self) {
    135     iBuilder->CreateStore(Constant::getNullValue(mKernelStateType), self);
     136void KernelBuilder::initializeKernelState(Value * self) const {
     137    iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);
    136138}
    137139
    138140//  The default finalBlock method simply dispatches to the doBlock routine.
    139 void KernelBuilder::generateFinalBlockMethod() {
     141void KernelBuilder::generateFinalBlockMethod() const {
    140142    auto savePoint = iBuilder->saveIP();
    141143    Module * m = iBuilder->getModule();
     
    158160// Note: this may be overridden to incorporate doBlock logic directly into
    159161// the doSegment function.
    160 void KernelBuilder::generateDoBlockLogic(Value * self, Value * blockNo) {
     162void KernelBuilder::generateDoBlockLogic(Value * self, Value * /* blockNo */) const {
    161163    Function * doBlockFunction = iBuilder->getModule()->getFunction(mKernelName + doBlock_suffix);
    162     iBuilder->CreateCall(doBlockFunction, {self});
     164    iBuilder->CreateCall(doBlockFunction, self);
    163165}
    164166
    165167//  The default doSegment method dispatches to the doBlock routine for
    166168//  each block of the given number of blocksToDo, and then updates counts.
    167 void KernelBuilder::generateDoSegmentMethod() {
     169void KernelBuilder::generateDoSegmentMethod() const {
    168170    auto savePoint = iBuilder->saveIP();
    169171    Module * m = iBuilder->getModule();
     
    190192    std::vector<Value *> endSignalPtrs;
    191193    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    192         Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetInputs[i].name);
    193         inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(ssStructPtr));
    194         endSignalPtrs.push_back(mStreamSetInputBuffers[i]->getEndOfInputPtr(ssStructPtr));
     194        Value * param = getStreamSetStructPtr(self, mStreamSetInputs[i].name);
     195        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(param));
     196        endSignalPtrs.push_back(mStreamSetInputBuffers[i]->getEndOfInputPtr(param));
    195197    }
    196198   
     
    292294    const auto f = mKernelMap.find(name);
    293295    if (LLVM_UNLIKELY(f == mKernelMap.end())) {
    294         throw std::runtime_error("Kernel does not contain internal state: " + name);
     296        llvm::report_fatal_error("Kernel does not contain scalar: " + name);
    295297    }
    296298    return iBuilder->getInt32(f->second);
     
    301303}
    302304
    303 Value * KernelBuilder::getScalarFieldPtr(Value * self, const std::string & fieldName) {
     305Value * KernelBuilder::getScalarFieldPtr(Value * self, const std::string & fieldName) const {
    304306    return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(fieldName)});
    305307}
    306308
    307 Value * KernelBuilder::getScalarField(Value * self, std::string fieldName) {
     309Value * KernelBuilder::getScalarField(Value * self, const std::string & fieldName) const {
    308310    return iBuilder->CreateLoad(getScalarFieldPtr(self, fieldName));
    309311}
    310312
    311 void KernelBuilder::setScalarField(Value * self, std::string fieldName, Value * newFieldVal) {
     313void KernelBuilder::setScalarField(Value * self, const std::string & fieldName, Value * newFieldVal) const {
    312314    iBuilder->CreateStore(newFieldVal, getScalarFieldPtr(self, fieldName));
    313315}
    314316
    315 Value * KernelBuilder::acquireLogicalSegmentNo(Value * self) {
     317LoadInst * KernelBuilder::acquireLogicalSegmentNo(Value * self) const {
    316318    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(logicalSegmentNoScalar)});
    317     LoadInst * segNo = iBuilder->CreateAtomicLoadAcquire(ptr);
    318     return segNo;
    319 }
    320 
    321 Value * KernelBuilder::getProcessedItemCount(Value * self) {
     319    return iBuilder->CreateAtomicLoadAcquire(ptr);
     320}
     321
     322Value * KernelBuilder::getProcessedItemCount(Value * self) const {
    322323    return getScalarField(self, processedItemCount);
    323324}
    324325
    325 Value * KernelBuilder::getProducedItemCount(Value * self) {
     326Value * KernelBuilder::getProducedItemCount(Value * self) const {
    326327    return getScalarField(self, producedItemCount);
    327328}
    328329
    329 Value * KernelBuilder::getTerminationSignal(Value * self) {
     330Value * KernelBuilder::getTerminationSignal(Value * self) const {
    330331    return getScalarField(self, terminationSignal);
    331332}
    332333
    333 void KernelBuilder::releaseLogicalSegmentNo(Value * self, Value * newCount) {
     334void KernelBuilder::releaseLogicalSegmentNo(Value * self, Value * newCount) const {
    334335    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(logicalSegmentNoScalar)});
    335336    iBuilder->CreateAtomicStoreRelease(newCount, ptr);
    336337}
    337338
    338 void KernelBuilder::setProcessedItemCount(Value * self, Value * newCount) {
     339void KernelBuilder::setProcessedItemCount(Value * self, Value * newCount) const {
    339340    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(processedItemCount)});
    340341    iBuilder->CreateStore(newCount, ptr);
    341342}
    342343
    343 void KernelBuilder::setProducedItemCount(Value * self, Value * newCount) {
     344void KernelBuilder::setProducedItemCount(Value * self, Value * newCount) const {
    344345    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(producedItemCount)});
    345346    iBuilder->CreateStore(newCount, ptr);
    346347}
    347348
    348 void KernelBuilder::setTerminationSignal(Value * self) {
     349void KernelBuilder::setTerminationSignal(Value * self) const {
    349350    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(terminationSignal)});
    350351    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), ptr);
    351352}
    352                                      
    353 
    354 
    355 Value * KernelBuilder::getBlockNo(Value * self) {
     353
     354Value * KernelBuilder::getBlockNo(Value * self) const {
    356355    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(blockNoScalar)});
    357     LoadInst * blockNo = iBuilder->CreateLoad(ptr);
    358     return blockNo;
    359 }
    360 
    361 void KernelBuilder::setBlockNo(Value * self, Value * newFieldVal) {
     356    return iBuilder->CreateLoad(ptr);
     357}
     358
     359void KernelBuilder::setBlockNo(Value * self, Value * newFieldVal) const {
    362360    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(blockNoScalar)});
    363361    iBuilder->CreateStore(newFieldVal, ptr);
     
    365363
    366364
    367 Value * KernelBuilder::getParameter(Function * f, std::string paramName) {
     365Value * KernelBuilder::getParameter(Function * f, const std::string & paramName) const {
    368366    for (Function::arg_iterator argIter = f->arg_begin(), end = f->arg_end(); argIter != end; argIter++) {
    369367        Value * arg = &*argIter;
     
    373371}
    374372
    375 unsigned KernelBuilder::getStreamSetIndex(std::string name) {
     373unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
    376374    const auto f = mStreamSetNameMap.find(name);
    377375    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
     
    381379}
    382380
    383 size_t KernelBuilder::getStreamSetBufferSize(Value * self, std::string name) {
     381size_t KernelBuilder::getStreamSetBufferSize(Value * /* self */, const std::string & name) const {
    384382    const unsigned index = getStreamSetIndex(name);
    385383    StreamSetBuffer * buf = nullptr;
     
    392390}
    393391
    394 Value * KernelBuilder::getStreamSetStructPtr(Value * self, std::string name) {
     392Value * KernelBuilder::getStreamSetStructPtr(Value * self, const std::string & name) const {
    395393    return getScalarField(self, name + structPtrSuffix);
    396394}
    397395
    398 Value * KernelBuilder::getStreamSetBlockPtr(Value * self, std::string name, Value * blockNo) {
     396Value * KernelBuilder::getStreamSetBlockPtr(Value * self, const std::string &name, Value * blockNo) const {
    399397    Value * const structPtr = getStreamSetStructPtr(self, name);
    400398    const unsigned index = getStreamSetIndex(name);
     
    408406}
    409407
     408Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index) {
     409    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, name, blockNo), {iBuilder->getInt32(0), index});
     410}
     411
    410412void KernelBuilder::createInstance() {
     413    if (LLVM_UNLIKELY(mKernelStateType == nullptr)) {
     414        llvm::report_fatal_error("Cannot create kernel instance before calling prepareKernel()");
     415    }
    411416    mKernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
    412417    Module * m = iBuilder->getModule();
     
    429434}
    430435
    431 Function * KernelBuilder::generateThreadFunction(std::string name){
     436Function * KernelBuilder::generateThreadFunction(const std::string & name) const {
     437    if (LLVM_UNLIKELY(mKernelStateType == nullptr)) {
     438        llvm::report_fatal_error("Cannot generate thread function before calling prepareKernel()");
     439    }
    432440    Module * m = iBuilder->getModule();
    433441    Type * const voidTy = iBuilder->getVoidTy();
     
    591599
    592600}
     601
     602KernelBuilder::~KernelBuilder() {
     603}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5240 r5246  
    66#ifndef KERNEL_BUILDER_H
    77#define KERNEL_BUILDER_H
    8 
    98
    109#include "streamset.h"
     
    2827class KernelBuilder : public KernelInterface {
    2928    using NameMap = boost::container::flat_map<std::string, unsigned>;
    30 
    3129public:
    32     KernelBuilder(IDISA::IDISA_Builder * builder,
    33                     std::string kernelName,
    34                     std::vector<Binding> stream_inputs,
    35                     std::vector<Binding> stream_outputs,
    36                     std::vector<Binding> scalar_parameters,
    37                     std::vector<Binding> scalar_outputs,
    38                     std::vector<Binding> internal_scalars);
    3930   
    4031    // Create a module for the kernel, including the kernel state type declaration and
    4132    // the full implementation of all required methods.     
    4233    //
    43     std::unique_ptr<llvm::Module> createKernelModule(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
     34    std::unique_ptr<Module> createKernelModule(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
    4435   
    4536    // Generate the Kernel to the current module (iBuilder->getModule()).
    46     void generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
     37    void generateKernel(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
    4738   
    4839    void createInstance() override;
    4940
    50     Function * generateThreadFunction(std::string name);
     41    Function * generateThreadFunction(const std::string & name) const;
    5142
    52     Value * getBlockNo(Value * self);
    53     virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) override;
    54     virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) override;
    55     virtual void initializeKernelState(Value * self);
    56     llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) override;
     43    Value * getBlockNo(Value * self) const;
     44    virtual Value * getProcessedItemCount(Value * self) const override;
     45    virtual Value * getProducedItemCount(Value * self) const override;
     46    virtual void initializeKernelState(Value * self) const;
     47    Value * getTerminationSignal(Value * self) const override;
    5748   
    58     inline llvm::IntegerType * getSizeTy() {
     49    inline IntegerType * getSizeTy() const {
    5950        return getBuilder()->getSizeTy();
    6051    }
     
    7768    // data has been extracted from the kernel for further pipeline processing, the
    7869    // segment number must be incremented and stored using releaseLogicalSegmentNo.
    79     llvm::Value * acquireLogicalSegmentNo(llvm::Value * kernelInstance);
    80     void releaseLogicalSegmentNo(llvm::Value * kernelInstance, Value * newFieldVal);
     70    LoadInst * acquireLogicalSegmentNo(Value * self) const;
    8171
     72    void releaseLogicalSegmentNo(Value * self, Value * newFieldVal) const;
     73
     74    virtual ~KernelBuilder() = 0;
    8275
    8376protected:
     77
     78    // Constructor
     79    KernelBuilder(IDISA::IDISA_Builder * builder,
     80                    std::string kernelName,
     81                    std::vector<Binding> stream_inputs,
     82                    std::vector<Binding> stream_outputs,
     83                    std::vector<Binding> scalar_parameters,
     84                    std::vector<Binding> scalar_outputs,
     85                    std::vector<Binding> internal_scalars);
     86
    8487    //
    8588    // Kernel builder subtypes define their logic of kernel construction
     
    97100    // Each kernel builder subtype must provide its own logic for generating
    98101    // doBlock calls.
    99     virtual void generateDoBlockMethod() = 0;
    100     virtual void generateDoBlockLogic(Value * self, Value * blockNo);
     102    virtual void generateDoBlockMethod() const = 0;
     103
     104    virtual void generateDoBlockLogic(Value * self, Value * blockNo) const;
    101105
    102106    // Each kernel builder subtypre must also specify the logic for processing the
     
    107111    // not be overridden.
    108112   
    109     virtual void generateFinalBlockMethod();
    110    
    111     virtual void generateDoSegmentMethod();
     113    virtual void generateFinalBlockMethod() const;
     114
     115    virtual void generateDoSegmentMethod() const;
    112116   
    113117    // Add an additional scalar field to the KernelState struct.
    114118    // Must occur before any call to addKernelDeclarations or createKernelModule.
    115     unsigned addScalar(llvm::Type * type, std::string name);
     119    unsigned addScalar(Type * type, const std::string & name);
    116120
    117121    unsigned getScalarCount() const;
     
    124128   
    125129    // Get the value of a scalar field for a given instance.
    126     llvm::Value * getScalarField(llvm::Value * self, std::string fieldName);
     130    Value * getScalarField(Value * self, const std::string & fieldName) const;
    127131
    128132    // Set the value of a scalar field for a given instance.
    129     void setScalarField(llvm::Value * self, std::string fieldName, llvm::Value * newFieldVal);
     133    void setScalarField(Value * self, const std::string & fieldName, Value * newFieldVal) const;
    130134   
    131135    // Get a parameter by name.
    132     llvm::Value * getParameter(llvm::Function * f, std::string paramName);
     136    Value * getParameter(Function * f, const std::string & paramName) const;
     137
     138    Value * getStream(Value * self, const std::string & name, Value * blockNo, const unsigned index) {
     139        return getStream(self, name, blockNo, iBuilder->getInt32(index));
     140    }
     141
     142    Value * getStream(Value * self, const std::string & name, Value * blockNo, Value * index);
    133143   
    134144    // Stream set helpers.
    135     unsigned getStreamSetIndex(std::string name);
     145    unsigned getStreamSetIndex(const std::string & name) const;
    136146   
    137     llvm::Value * getScalarFieldPtr(Value * self, const std::string & name);
     147    Value * getScalarFieldPtr(Value * self, const std::string & name) const;
    138148
    139     llvm::Value * getStreamSetStructPtr(Value * self, std::string name);
    140     size_t getStreamSetBufferSize(Value * self, std::string name);
     149    Value * getStreamSetStructPtr(Value * self, const std::string & name) const;
    141150
    142     llvm::Value * getStreamSetBlockPtr(Value * self, std::string name, Value * blockNo);
     151    size_t getStreamSetBufferSize(Value * self, const std::string & name) const;
     152
     153    Value * getStreamSetBlockPtr(Value * self, const std::string & name, Value * blockNo) const;
    143154   
    144     void setBlockNo(Value * self, Value * newFieldVal);
    145     virtual void setProcessedItemCount(llvm::Value * self, Value * newFieldVal);
    146     virtual void setProducedItemCount(llvm::Value * self, Value * newFieldVal);
    147     void setTerminationSignal(llvm::Value * self);
     155    void setBlockNo(Value * self, Value * newFieldVal) const;
     156
     157    virtual void setProcessedItemCount(Value * self, Value * newFieldVal) const;
     158
     159    virtual void setProducedItemCount(Value * self, Value * newFieldVal) const;
     160
     161    void setTerminationSignal(Value * self) const;
    148162
    149163protected:
    150164
    151     std::vector<llvm::Type *>  mKernelFields;
    152     NameMap                    mKernelMap;
    153     NameMap                    mStreamSetNameMap;
    154     std::vector<StreamSetBuffer *> mStreamSetInputBuffers;
    155     std::vector<StreamSetBuffer *> mStreamSetOutputBuffers;
     165    std::vector<Type *>             mKernelFields;
     166    NameMap                         mKernelMap;
     167    NameMap                         mStreamSetNameMap;
     168    std::vector<StreamSetBuffer *>  mStreamSetInputBuffers;
     169    std::vector<StreamSetBuffer *>  mStreamSetOutputBuffers;
    156170
    157171};
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5238 r5246  
    4040}
    4141               
    42 void p2sKernel::generateDoBlockMethod() {
     42void p2sKernel::generateDoBlockMethod() const {
    4343    auto savePoint = iBuilder->saveIP();
    4444    Module * m = iBuilder->getModule();
     
    6666}
    6767       
    68 void p2sKernel_withCompressedOutput::generateDoBlockMethod() {
     68void p2sKernel_withCompressedOutput::generateDoBlockMethod() const {
    6969    auto savePoint = iBuilder->saveIP();
    7070    Module * m = iBuilder->getModule();
     
    8282    Value * byteStreamBlock_ptr = getStreamSetBlockPtr(self, "byteStream", blockNo);
    8383   
    84     Value * p_bitblock[8];
     84    Value * basisBits[8];
    8585    for (unsigned i = 0; i < 8; i++) {
    86         p_bitblock[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
    87     }
    88     Value * s_bytepack[8];
    89     p2s(iBuilder, p_bitblock, s_bytepack);
     86        basisBits[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     87    }
     88    Value * bytePack[8];
     89    p2s(iBuilder, basisBits, bytePack);
    9090   
    9191    unsigned units_per_register = iBuilder->getBitBlockWidth()/8;
     
    9797   
    9898    for (unsigned j = 0; j < 8; ++j) {
    99         iBuilder->CreateAlignedStore(s_bytepack[j], iBuilder->CreateBitCast(iBuilder->CreateGEP(output_ptr, offset), bitBlockPtrTy), 1);
     99        iBuilder->CreateAlignedStore(bytePack[j], iBuilder->CreateBitCast(iBuilder->CreateGEP(output_ptr, offset), bitBlockPtrTy), 1);
    100100        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(j)), i32);
    101101    }
     
    104104}
    105105
    106 void p2s_16Kernel::generateDoBlockMethod() {
     106void p2s_16Kernel::generateDoBlockMethod() const {
    107107    auto savePoint = iBuilder->saveIP();
    108108    Module * m = iBuilder->getModule();
     
    141141}
    142142
    143 void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() {
     143void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() const {
    144144    auto savePoint = iBuilder->saveIP();
    145145    Module * m = iBuilder->getModule();
     
    150150
    151151    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    152     Constant * stride = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
     152    Constant * stride = iBuilder->getSize(iBuilder->getStride());
    153153
    154154    Value * self = getParameter(doBlockFunction, "self");
     
    199199}
    200200
    201 void p2s_16Kernel_withCompressedOutput::generateFinalBlockMethod() {
     201void p2s_16Kernel_withCompressedOutput::generateFinalBlockMethod() const {
    202202    auto savePoint = iBuilder->saveIP();
    203203    Module * m = iBuilder->getModule();
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5217 r5246  
    2626   
    2727private:
    28     void generateDoBlockMethod() override;
     28    void generateDoBlockMethod() const override;
    2929   
    3030};
     
    3939   
    4040private:
    41     void generateDoBlockMethod() override;
     41    void generateDoBlockMethod() const override;
    4242};
    4343   
     
    5252   
    5353private:
    54     void generateDoBlockMethod() override;
     54    void generateDoBlockMethod() const override;
    5555   
    5656};
     
    6868       
    6969private:
    70     void generateDoBlockMethod() override;
    71     void generateFinalBlockMethod() override;
     70    void generateDoBlockMethod() const override;
     71    void generateFinalBlockMethod() const override;
    7272};
    7373   
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5240 r5246  
    4040// a continous buffer for the full segment (number of blocks).
    4141
    42 void expand3_4Kernel::generateDoSegmentMethod() {
     42void expand3_4Kernel::generateDoSegmentMethod() const {
    4343    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    4444    Module * m = iBuilder->getModule();
     
    8181        expand_3_4_shuffle[j] = ConstantVector::get(Idxs);
    8282    }
    83     Constant * Const3 = ConstantInt::get(iBuilder->getSizeTy(), 3);
    84     Constant * Const4 = ConstantInt::get(iBuilder->getSizeTy(), 4);
    85     Constant * stride = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
    86     Constant * packSize = ConstantInt::get(iBuilder->getSizeTy(), PACK_SIZE);
    87     Constant * loopItemCount = ConstantInt::get(iBuilder->getSizeTy(), 3 * PACK_SIZE); // 3 packs per loop.
     83    Constant * Const3 = iBuilder->getSize(3);
     84    Constant * Const4 = iBuilder->getSize(4);
     85    Constant * stride = iBuilder->getSize(iBuilder->getStride());
     86    Constant * packSize = iBuilder->getSize(PACK_SIZE);
     87    Constant * loopItemCount = iBuilder->getSize(3 * PACK_SIZE); // 3 packs per loop.
    8888    UndefValue * undefPack = UndefValue::get(iBuilder->fwVectorType(parabix::i8));
    8989   
     
    100100    // Except for the final segment, we always process an integral number of triple blocks.
    101101    Value * tripleBlocksToDo = iBuilder->CreateMul(blocksToDo, Const3);
    102     Constant * blockItems = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth());
     102    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    103103    Value * tripleItemMax = iBuilder->CreateMul(tripleBlocksToDo, blockItems);
    104104
     
    205205    expand0 = iBuilder->bitCast(iBuilder->CreateShuffleVector(undefPack, pack0, expand_3_4_shuffle[0]));
    206206    iBuilder->CreateAlignedStore(expand0, loopExitOutput_ptr, packAlign);
    207     Value * condition_b = iBuilder->CreateICmpULE(loopExitItemsRemain, ConstantInt::get(iBuilder->getSizeTy(), 3 * PACK_SIZE/4));
     207    Value * condition_b = iBuilder->CreateICmpULE(loopExitItemsRemain, iBuilder->getSize(3 * PACK_SIZE/4));
    208208    iBuilder->CreateCondBr(condition_b, itemsDone, finalStep2);
    209209    // Final Step 2 processing
     
    222222    expand1 = iBuilder->bitCast(iBuilder->CreateShuffleVector(pack0, pack1phi, expand_3_4_shuffle[1]));
    223223    iBuilder->CreateAlignedStore(expand1, outPack1_ptr, packAlign);
    224     Value * condition_d = iBuilder->CreateICmpULE(loopExitItemsRemain, ConstantInt::get(iBuilder->getSizeTy(), 6 * PACK_SIZE/4));
     224    Value * condition_d = iBuilder->CreateICmpULE(loopExitItemsRemain, iBuilder->getSize(6 * PACK_SIZE/4));
    225225    iBuilder->CreateCondBr(condition_d, itemsDone, finalStep3);
    226226    // Final Step 3
    227227    iBuilder->SetInsertPoint(finalStep3);
    228     Value * condition_e = iBuilder->CreateICmpULE(loopExitItemsRemain, ConstantInt::get(iBuilder->getSizeTy(), 2 * PACK_SIZE));
     228    Value * condition_e = iBuilder->CreateICmpULE(loopExitItemsRemain, iBuilder->getSize(2 * PACK_SIZE));
    229229    iBuilder->CreateCondBr(condition_e, step3store, step3load);
    230230    iBuilder->SetInsertPoint(step3load);
     
    239239    expand2 = iBuilder->bitCast(iBuilder->CreateShuffleVector(pack1phi, pack2phi, expand_3_4_shuffle[2]));
    240240    iBuilder->CreateAlignedStore(expand2, outPack2_ptr, packAlign);
    241     Value * condition_f = iBuilder->CreateICmpULE(loopExitItemsRemain, ConstantInt::get(iBuilder->getSizeTy(), 9 * PACK_SIZE/4));
     241    Value * condition_f = iBuilder->CreateICmpULE(loopExitItemsRemain, iBuilder->getSize(9 * PACK_SIZE/4));
    242242    iBuilder->CreateCondBr(condition_f, itemsDone, step3store2);
    243243    iBuilder->SetInsertPoint(step3store2);
     
    284284// The doBlock method is deprecated.   But in case it is used, just call doSegment with
    285285// 1 as the number of blocks to do.
    286 void expand3_4Kernel::generateDoBlockMethod() {
     286void expand3_4Kernel::generateDoBlockMethod() const {
    287287    auto savePoint = iBuilder->saveIP();
    288288    Module * m = iBuilder->getModule();
     
    306306//                                   ba    bits to move 12 positions left
    307307//    xwvuts|  nlkjzy|  barqpm|  hgfedc    Target
    308 void radix64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) {
     308void radix64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    309309    Value * expandedStream = getStreamSetBlockPtr(self, "expandedStream", blockNo);
    310310    Value * radix64stream = getStreamSetBlockPtr(self, "radix64stream",blockNo);
     
    338338    }
    339339    Value * produced = getProducedItemCount(self);
    340     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     340    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    341341    setProducedItemCount(self, produced);   
    342342}
    343343
    344 void radix64Kernel::generateFinalBlockMethod() {
     344void radix64Kernel::generateFinalBlockMethod() const {
    345345    auto savePoint = iBuilder->saveIP();
    346346    Module * m = iBuilder->getModule();
     
    361361
    362362    const unsigned PACK_SIZE = iBuilder->getStride()/8;
    363     Constant * packSize = ConstantInt::get(iBuilder->getSizeTy(), PACK_SIZE);
     363    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    364364    Value * blockNo = getScalarField(self, blockNoScalar);
    365365    Value * expandedstream_ptr = getStreamSetBlockPtr(self, "expandedStream", blockNo);
     
    457457}
    458458
    459 void radix64Kernel::generateDoBlockMethod() {
     459void radix64Kernel::generateDoBlockMethod() const {
    460460    auto savePoint = iBuilder->saveIP();
    461461
     
    474474
    475475
    476 void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) {
     476void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    477477    Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    478478    Value * base64stream_ptr = getStreamSetBlockPtr(self, "base64stream", blockNo);   
     
    497497    }
    498498    Value * produced = getProducedItemCount(self);
    499     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     499    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    500500    setProducedItemCount(self, produced);   
    501501}
     
    505505// of 4 bytes.   When the number of radix 64 values is not a multiple of 4
    506506// number of radix 64 values
    507 void base64Kernel::generateFinalBlockMethod() {
     507void base64Kernel::generateFinalBlockMethod() const {
    508508    auto savePoint = iBuilder->saveIP();
    509509    Module * m = iBuilder->getModule();
     
    520520    Value * self = &*(args++);
    521521    Value * remainingBytes = &*(args++);
    522     Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, ConstantInt::get(iBuilder->getSizeTy(), 3));
    523     Value * padBytes = iBuilder->CreateSub(ConstantInt::get(iBuilder->getSizeTy(), 4), remainMod4);
    524     padBytes = iBuilder->CreateAnd(padBytes, ConstantInt::get(iBuilder->getSizeTy(), 3));
     522    Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, iBuilder->getSize(3));
     523    Value * padBytes = iBuilder->CreateSub(iBuilder->getSize(4), remainMod4);
     524    padBytes = iBuilder->CreateAnd(padBytes, iBuilder->getSize(3));
    525525
    526526    Constant * packSize = iBuilder->getSize(iBuilder->getStride() / 8);
     
    574574}
    575575
    576 void base64Kernel::generateDoBlockMethod() {
     576void base64Kernel::generateDoBlockMethod() const {
    577577    auto savePoint = iBuilder->saveIP();
    578578
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5232 r5246  
    3030   
    3131private:
    32     void generateDoBlockMethod() override;
    33     void generateDoSegmentMethod() override;
     32    void generateDoBlockMethod() const override;
     33    void generateDoSegmentMethod() const override;
    3434   
    3535};
     
    4545
    4646private:
    47     virtual void generateDoBlockLogic(Value * self, Value * blockNo) override;
    48     virtual void generateDoBlockMethod() override;
    49     virtual void generateFinalBlockMethod() override;
     47    virtual void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     48    virtual void generateDoBlockMethod() const override;
     49    virtual void generateFinalBlockMethod() const override;
    5050};
    5151
     
    6060   
    6161private:
    62     virtual void generateDoBlockLogic(Value * self, Value * blockNo) override;
    63     virtual void generateFinalBlockMethod() override;
    64     virtual void generateDoBlockMethod() override;
     62    virtual void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     63    virtual void generateFinalBlockMethod() const override;
     64    virtual void generateDoBlockMethod() const override;
    6565   
    6666};
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5238 r5246  
    120120#endif
    121121   
    122 void S2PKernel::generateFinalBlockMethod() {
     122void S2PKernel::generateFinalBlockMethod() const {
    123123    /* Prepare the s2p final block function:
    124124     assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
     
    144144    /* Adjust the produced item count */
    145145    Value * produced = getProducedItemCount(self);
    146     produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     146    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    147147    setProducedItemCount(self, iBuilder->CreateAdd(produced, remainingBytes));
    148148   
     
    161161
    162162   
    163 void S2PKernel::generateDoBlockLogic(Value * self, Value * blockNo) {
     163void S2PKernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    164164
    165165    Value * byteStream = getStreamSetBlockPtr(self, "byteStream", blockNo);
     
    171171        bytepack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    172172    }
    173     Value * bitblock[8];
    174     s2p(iBuilder, bytepack, bitblock);
     173    Value * basisbits[8];
     174    s2p(iBuilder, bytepack, basisbits);
    175175    for (unsigned i = 0; i < 8; ++i) {
    176         iBuilder->CreateBlockAlignedStore(bitblock[i], basisBits, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     176        iBuilder->CreateBlockAlignedStore(basisbits[i], basisBits, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
    177177    }
    178178    Value * produced = getProducedItemCount(self);
    179     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     179    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    180180    setProducedItemCount(self, produced);   
    181181}
    182182   
    183 void S2PKernel::generateDoBlockMethod() {
     183void S2PKernel::generateDoBlockMethod() const {
    184184    auto savePoint = iBuilder->saveIP();
    185185
    186186    Function * doBlockFunction = iBuilder->getModule()->getFunction(mKernelName + doBlock_suffix);
    187187   
    188     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
     188    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction));
    189189   
    190190    Value * self = getParameter(doBlockFunction, "self");
     
    196196    iBuilder->restoreIP(savePoint);
    197197}
    198 }
     198
     199S2PKernel::S2PKernel(IDISA::IDISA_Builder * builder)
     200: KernelBuilder(builder, "s2p", {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {Binding{builder->getStreamSetTy(8, 1), "basisBits"}}, {}, {}, {}) {
     201
     202}
     203
     204}
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5230 r5246  
    1616namespace kernel {
    1717
    18 class KernelBuilder;
    19 
    20 //void generateS2P_16Kernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    21 
    22 
    23 
    2418class S2PKernel : public KernelBuilder {
    2519public:
    2620   
    27     S2PKernel(IDISA::IDISA_Builder * iBuilder) :
    28     KernelBuilder(iBuilder, "s2p",
    29                   {Binding{iBuilder->getStreamSetTy(1, 8), "byteStream"}},
    30                   {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
    31                   {}, {}, {}) {}
    32    
    33    
     21    S2PKernel(IDISA::IDISA_Builder * builder);
     22
     23    virtual ~S2PKernel() {}
     24       
    3425private:
    35     void generateDoBlockLogic(Value * self, Value * blockNo) override;
    36     void generateDoBlockMethod() override;
    37     void generateFinalBlockMethod() override;
     26    void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     27    void generateDoBlockMethod() const override;
     28    void generateFinalBlockMethod() const override;
    3829   
    3930};
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5238 r5246  
    4040
    4141       
    42 void ScanMatchKernel::generateDoBlockMethod() {
     42void ScanMatchKernel::generateDoBlockMethod() const {
    4343    auto savePoint = iBuilder->saveIP();
    4444    Module * m = iBuilder->getModule();
     
    7878
    7979   
    80 Function * ScanMatchKernel::generateScanWordRoutine(Module * m) {
     80Function * ScanMatchKernel::generateScanWordRoutine(Module * m) const {
    8181    Function * function = m->getFunction("scan_matches_in_scanword");
    8282    if (LLVM_UNLIKELY(function != nullptr)) {
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5217 r5246  
    3131       
    3232private:
    33     void generateDoBlockMethod() override;
    34     llvm::Function * generateScanWordRoutine(llvm::Module * m);
     33    void generateDoBlockMethod() const override;
     34    llvm::Function * generateScanWordRoutine(llvm::Module * m) const;
    3535       
    3636    GrepType mGrepType;
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5243 r5246  
    1111// The doBlock method is deprecated.   But in case it is used, just call doSegment with
    1212// 1 as the number of blocks to do.
    13 void StdOutKernel::generateDoBlockMethod() {
     13void StdOutKernel::generateDoBlockMethod() const {
    1414    auto savePoint = iBuilder->saveIP();
    1515    Module * m = iBuilder->getModule();
     
    2525// Rather than using doBlock logic to write one block at a time, this custom
    2626// doSegment method, writes the entire segment with a single write call.
    27 void StdOutKernel::generateDoSegmentMethod() {
     27void StdOutKernel::generateDoSegmentMethod() const {
    2828    auto savePoint = iBuilder->saveIP();
    2929    Module * m = iBuilder->getModule();
     
    3434    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
    3535    BasicBlock * stdOutexit = BasicBlock::Create(iBuilder->getContext(), "stdOutexit", doSegmentFunction, 0);
    36     Constant * blockItems = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth());
    37     Constant * itemBytes = ConstantInt::get(iBuilder->getSizeTy(), mCodeUnitWidth/8);
     36    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
     37    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    3838   
    3939    Function::arg_iterator args = doSegmentFunction->arg_begin();
     
    8080}
    8181
    82 void StdOutKernel::generateFinalBlockMethod() {
     82void StdOutKernel::generateFinalBlockMethod() const {
    8383    auto savePoint = iBuilder->saveIP();
    8484    Module * m = iBuilder->getModule();
     
    8787   
    8888    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_flush", finalBlockFunction, 0));
    89     Constant * blockItems = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth());
    90     Constant * itemBytes = ConstantInt::get(iBuilder->getSizeTy(), mCodeUnitWidth/8);
     89    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
     90    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    9191    Value * self = getParameter(finalBlockFunction, "self");
    9292    Value * streamStructPtr = getStreamSetStructPtr(self, "codeUnitBuffer");
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5230 r5246  
    2424    unsigned mCodeUnitWidth;
    2525 
    26     void generateDoBlockMethod() override;
    27     void generateFinalBlockMethod() override;
    28     void generateDoSegmentMethod() override;
     26    void generateDoBlockMethod() const override;
     27    void generateFinalBlockMethod() const override;
     28    void generateDoSegmentMethod() const override;
    2929   
    3030};
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5243 r5246  
    4141    Type * const size_ty = iBuilder->getSizeTy();
    4242    Type * const int1ty = iBuilder->getInt1Ty();
    43     mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetType, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
     43    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetType, iBuilder->getSize(mBufferBlocks));
    4444    mStreamSetStructPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetStructType);
    4545    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     
    118118
    119119llvm::Value * LinearCopybackBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
    120     Constant * blockWidth = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
     120    Constant * blockWidth = iBuilder->getSize(iBuilder->getStride());
    121121    Value * consumerPos_ptr = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
    122122    Value * consumerPos = iBuilder->CreateLoad(consumerPos_ptr);
     
    127127}
    128128
    129 void LinearCopybackBuffer::setConsumerPos(Value * bufferStructPtr, Value * new_consumer_pos) {
     129void LinearCopybackBuffer::setConsumerPos(Value * bufferStructPtr, Value * newConsumerPos) {
    130130    Type * const i8 = iBuilder->getInt8Ty();
    131131    Type * const i8_ptr = i8->getPointerTo(mAddrSpace);
     
    145145
    146146    // Ensure that the new consumer position is no less than the current position.
    147     new_consumer_pos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(new_consumer_pos, consumerPos), consumerPos, new_consumer_pos);
     147    newConsumerPos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(newConsumerPos, consumerPos), consumerPos, newConsumerPos);
    148148    Value * producerPos = iBuilder->CreateLoad(iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    149149
    150150    // Ensure that the new consumer position is no greater than the current producer position.
    151     Value * new_pos_lt_producer_pos = iBuilder->CreateICmpULT(new_consumer_pos, producerPos);
    152     new_consumer_pos = iBuilder->CreateSelect(new_pos_lt_producer_pos, new_consumer_pos, producerPos);
     151    Value * new_pos_lt_producer_pos = iBuilder->CreateICmpULT(newConsumerPos, producerPos);
     152    newConsumerPos = iBuilder->CreateSelect(new_pos_lt_producer_pos, newConsumerPos, producerPos);
    153153
    154154    // Now, the new_consumer_pos is at most = to the producer_pos; if =, we're done.
     
    156156    iBuilder->SetInsertPoint(copyBackBody);
    157157   
    158     Value * new_consumer_block = iBuilder->CreateUDiv(new_consumer_pos, blockWidth);
     158    Value * new_consumer_block = iBuilder->CreateUDiv(newConsumerPos, blockWidth);
    159159    Value * lastProducerBlock = iBuilder->CreateUDiv(iBuilder->CreateSub(producerPos, one), blockWidth);
    160160    Value * copyBlocks = iBuilder->CreateAdd(iBuilder->CreateSub(lastProducerBlock, new_consumer_block), one);
     
    177177    iBuilder->SetInsertPoint(setConsumerPosExit);
    178178
    179     iBuilder->CreateStore(new_consumer_pos, consumerPosPtr);
     179    iBuilder->CreateStore(newConsumerPos, consumerPosPtr);
    180180}   
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5238 r5246  
    168168    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
    169169    // copying back any data beyond that position.
    170     void setConsumerPos(Value * bufferStructPtr, Value * new_consumer_pos) override;
     170    void setConsumerPos(Value * bufferStructPtr, Value * newConsumerPos) override;
    171171};
    172172
  • icGREP/icgrep-devel/icgrep/kernels/symboltablepipeline.cpp

    r5240 r5246  
    238238
    239239    Value * blockPos = iBuilder->CreateLoad(kBuilder->getBlockNo());
    240     blockPos = iBuilder->CreateMul(blockPos, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth()));
     240    blockPos = iBuilder->CreateMul(blockPos, iBuilder->getSize(iBuilder->getBitBlockWidth()));
    241241
    242242    iBuilder->CreateBr(groupCond);
     
    280280    PHINode * startIV = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
    281281    startIV->addIncoming(iBuilder->getSize(0), groupBody);
    282     Value * startOuterTest = iBuilder->CreateICmpNE(startIV, ConstantInt::get(iBuilder->getSizeTy(), fieldCount));
     282    Value * startOuterTest = iBuilder->CreateICmpNE(startIV, iBuilder->getSize(fieldCount));
    283283    iBuilder->CreateCondBr(startOuterTest, startOuterBody, endOuterCond);
    284284
     
    287287    Value * startField = iBuilder->CreateExtractElement(startStream, startIV);
    288288    startIV->addIncoming(iBuilder->CreateAdd(startIV, iBuilder->getSize(1)), startInnerCond);
    289     startBlockOffset->addIncoming(iBuilder->CreateAdd(startBlockOffset, ConstantInt::get(iBuilder->getSizeTy(), scanWordBitWidth)), startInnerCond);
     289    startBlockOffset->addIncoming(iBuilder->CreateAdd(startBlockOffset, iBuilder->getSize(scanWordBitWidth)), startInnerCond);
    290290    iBuilder->CreateBr(startInnerCond);
    291291
     
    319319    PHINode * endIV = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
    320320    endIV->addIncoming(iBuilder->getSize(0), startOuterCond);
    321     Value * endOuterTest = iBuilder->CreateICmpNE(endIV, ConstantInt::get(iBuilder->getSizeTy(), fieldCount));
     321    Value * endOuterTest = iBuilder->CreateICmpNE(endIV, iBuilder->getSize(fieldCount));
    322322    iBuilder->CreateCondBr(endOuterTest, endOuterBody, nextGroup);
    323323
     
    326326    Value * endField = iBuilder->CreateExtractElement(endStream, endIV);
    327327    endIV->addIncoming(iBuilder->CreateAdd(endIV, iBuilder->getSize(1)), endInnerCond);
    328     endBlockOffset->addIncoming(iBuilder->CreateAdd(endBlockOffset, ConstantInt::get(iBuilder->getSizeTy(), scanWordBitWidth)), endInnerCond);
     328    endBlockOffset->addIncoming(iBuilder->CreateAdd(endBlockOffset, iBuilder->getSize(scanWordBitWidth)), endInnerCond);
    329329    iBuilder->CreateBr(endInnerCond);
    330330
     
    681681    const unsigned leadingBlocks = (mLongestLookahead + iBuilder->getBitBlockWidth() - 1) / iBuilder->getBitBlockWidth();
    682682
    683     Value * const requiredBytes = ConstantInt::get(iBuilder->getSizeTy(), mBlockSize * leadingBlocks);
    684     Value * const blockSize = ConstantInt::get(iBuilder->getSizeTy(), mBlockSize);
     683    Value * const requiredBytes = iBuilder->getSize(mBlockSize * leadingBlocks);
     684    Value * const blockSize = iBuilder->getSize(mBlockSize);
    685685
    686686    // First compute any necessary leading blocks to allow the sorting kernel access to the "future" data produced by
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5245 r5246  
    292292    // We always use the 0-th slot for the summary value, even when it's implicit
    293293    mCurrentFrameIndex = mCarryInfo->hasExplicitSummary() ? 1 : 0;
    294 
    295294}
    296295
     
    390389
    391390    // Create a mask to implement circular buffer indexing
    392     Value * indexMask = ConstantInt::get(iBuilder->getSizeTy(), nearest_pow2(entries) - 1);
     391    Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);
    393392    Value * blockIndex = mKernel->getScalarField(mSelf, blockNoScalar);
    394393    Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(entries));
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5245 r5246  
    261261    if (whileStatement->getBound()) {
    262262        bound_phi = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "while_bound");
    263         bound_phi->addIncoming(ConstantInt::get(iBuilder->getSizeTy(), whileStatement->getBound()), whileEntryBlock);
     263        bound_phi->addIncoming(iBuilder->getSize(whileStatement->getBound()), whileEntryBlock);
    264264    }
    265265#endif
     
    452452            std::string inputName = var->getName()->to_string();;
    453453            Value * blockNo = mKernel->getScalarField(mSelf, blockNoScalar);
    454             Value * lookAhead_blockPtr  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift)));
     454            Value * lookAhead_blockPtr  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    455455            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    456456            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     
    458458                value = lookAhead;
    459459            } else { // Need to form shift result from two adjacent blocks.
    460                 Value * lookAhead_blockPtr1  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), block_shift + 1)));
     460                Value * lookAhead_blockPtr1  = mKernel->getStreamSetBlockPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    461461                Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    462462                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5245 r5246  
    1717using namespace IDISA;
    1818
    19 Var * PabloKernel::addInput(const std::string name, Type * const type) {
     19Var * PabloKernel::addInput(const std::string & name, Type * const type) {
    2020    Var * param = new (mAllocator) Var(mSymbolTable->make(name, iBuilder), type, mAllocator, true);
    2121    mInputs.push_back(param);
     
    8080}
    8181
    82 void PabloKernel::generateDoBlockMethod() {
     82void PabloKernel::generateDoBlockMethod() const {
    8383    auto savePoint = iBuilder->saveIP();
    8484    Module * const m = iBuilder->getModule();
     
    8787    mPabloCompiler->compile(self, f);
    8888    Value * produced = getProducedItemCount(self);
    89     produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     89    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    9090    setProducedItemCount(self, produced);
    9191    iBuilder->CreateRetVoid();
     
    9696}
    9797
    98 void PabloKernel::generateFinalBlockMethod() {
     98void PabloKernel::generateFinalBlockMethod() const {
    9999    auto savePoint = iBuilder->saveIP();
    100100    Module * m = iBuilder->getModule();
     
    117117    /* Adjust the produced item count */
    118118    Value * produced = getProducedItemCount(self);
    119     produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     119    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    120120    setProducedItemCount(self, iBuilder->CreateAdd(produced, remaining));
    121121    iBuilder->CreateRetVoid();
     
    126126}
    127127
    128 void PabloKernel::initializeKernelState(Value * self) {   
    129     iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);
     128void PabloKernel::initializeKernelState(Value * self) const {
     129    iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);   
    130130}
    131131
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5240 r5246  
    4141    // using the pablo.Count operation.
    4242   
    43     ~PabloKernel();
     43    virtual ~PabloKernel();
    4444
    4545    PabloBlock * getEntryBlock() {
     
    6565    }
    6666
    67     Var * addInput(const std::string name, Type * const type);
     67    Var * addInput(const std::string & name, Type * const type);
    6868
    6969    unsigned getNumOfInputs() const {
     
    110110    void prepareKernel() override;
    111111
    112     void generateDoBlockMethod() override;
     112    void generateDoBlockMethod() const override;
    113113   
    114     void initializeKernelState(Value * self) override;
     114    void initializeKernelState(Value * self) const override;
    115115
    116116    // The default method for Pablo final block processing sets the
    117117    // EOFmark bit and then calls the standard DoBlock function.
    118118    // This may be overridden for specialized processing.
    119     virtual void generateFinalBlockMethod() override;
     119    virtual void generateFinalBlockMethod() const override;
    120120
    121121    inline String * getName(const std::string & name) const {
Note: See TracChangeset for help on using the changeset viewer.