Changeset 5292


Ignore:
Timestamp:
Jan 31, 2017, 4:08:11 PM (10 months ago)
Author:
nmedfort
Message:

Removed 'function' and 'self' parameters from generateXXXMethod() functions.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_nvptx_builder.cpp

    r5260 r5292  
    5353std::pair<Value *, Value *> IDISA_NVPTX20_Builder::bitblock_advance(Value * a, Value * shiftin, unsigned shift) {
    5454    Value * id = CreateCall(tidFunc);
    55     Value * retVal = CreateCall(mLongAdvanceFunc, std::vector<Value *>({id, a, CreateBitCast(getInt64(shift), mBitBlockType), shiftin}));
    56     Value * shifted = CreateExtractValue(retVal, std::vector<unsigned>({0}));
    57     Value * shiftOut = CreateExtractValue(retVal, std::vector<unsigned>({1}));
     55    Value * retVal = CreateCall(mLongAdvanceFunc, {id, a, CreateBitCast(getInt64(shift), mBitBlockType), shiftin});
     56    Value * shifted = CreateExtractValue(retVal, {0});
     57    Value * shiftOut = CreateExtractValue(retVal, {1});
    5858    return std::pair<Value *, Value *>(shiftOut, shifted);
    5959}
     
    6161std::pair<Value *, Value *> IDISA_NVPTX20_Builder::bitblock_add_with_carry(Value * a, Value * b, Value * carryIn) {
    6262    Value * id = CreateCall(tidFunc);
    63     Value * retVal = CreateCall(mLongAddFunc, std::vector<Value *>({id, a, b, carryIn}));
    64     Value * sum = CreateExtractValue(retVal, std::vector<unsigned>({0}));
    65     Value * carry_out_strm = CreateExtractValue(retVal, std::vector<unsigned>({1}));
     63    Value * retVal = CreateCall(mLongAddFunc, {id, a, b, carryIn});
     64    Value * sum = CreateExtractValue(retVal, {0});
     65    Value * carry_out_strm = CreateExtractValue(retVal, {1});
    6666    return std::pair<Value *, Value *>(carry_out_strm, sum);
    6767}
     
    7070
    7171    Type * const carryTy = ArrayType::get(mBitBlockType, groupThreads+1);
    72     carry = new GlobalVariable(/*Module=*/*mMod,
     72    carry = new GlobalVariable(*mMod,
    7373        /*Type=*/carryTy,
    7474        /*isConstant=*/false,
     
    8383    Type * const bubbleTy = ArrayType::get(mBitBlockType, groupThreads);
    8484
    85     bubble = new GlobalVariable(/*Module=*/*mMod,
     85    bubble = new GlobalVariable(*mMod,
    8686        /*Type=*/bubbleTy,
    8787        /*isConstant=*/false,
     
    111111void IDISA_NVPTX20_Builder::CreateLongAdvanceFunc(){
    112112  Type * const int32ty = getInt32Ty();
    113   Type * returnType = StructType::get(mMod->getContext(), std::vector<Type *>({mBitBlockType, mBitBlockType}));
     113  Type * returnType = StructType::get(mMod->getContext(), {mBitBlockType, mBitBlockType});
    114114
    115115  mLongAdvanceFunc = cast<Function>(mMod->getOrInsertFunction("LongAdvance", returnType, int32ty, mBitBlockType, mBitBlockType, mBitBlockType, nullptr));
     
    159159  Type * const int64ty = getInt64Ty();
    160160  Type * const int32ty = getInt32Ty();
    161   Type * returnType = StructType::get(mMod->getContext(), std::vector<Type *>({mBitBlockType, mBitBlockType}));
     161  Type * returnType = StructType::get(mMod->getContext(), {mBitBlockType, mBitBlockType});
    162162
    163163  mLongAddFunc = cast<Function>(mMod->getOrInsertFunction("LongAdd", returnType, int32ty, mBitBlockType, mBitBlockType, mBitBlockType, nullptr));
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5267 r5292  
    206206
    207207
    208 Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
    209    
    210     Type * const size_ty = iBuilder->getSizeTy();
     208Function * editdPipeline(Module * m, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
     209   
     210    Type * const sizeTy = iBuilder->getSizeTy();
    211211    Type * const voidTy = iBuilder->getVoidTy();
    212212    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), 8), 1), 0);
    213213   
    214     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, nullptr));
     214    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, sizeTy, nullptr));
    215215    main->setCallingConv(CallingConv::C);
    216216    Function::arg_iterator args = main->arg_begin();
     
    237237    std::unique_ptr<Module> scanM = editdScanK.createKernelModule({&MatchResults}, {});               
    238238   
    239     mmapK.addKernelDeclarations(mMod);
    240     editdk.addKernelDeclarations(mMod);
    241     editdScanK.addKernelDeclarations(mMod);
    242 
    243     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
     239    mmapK.addKernelDeclarations(m);
     240    editdk.addKernelDeclarations(m);
     241    editdScanK.addKernelDeclarations(m);
     242
     243    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
    244244
    245245    ChStream.setStreamSetBuffer(inputStream, fileSize);
     
    250250    iBuilder->CreateRetVoid();
    251251   
    252     Linker L(*mMod);
     252    Linker L(*m);
    253253    L.linkInModule(std::move(mmapM));
    254254    L.linkInModule(std::move(editdM));
     
    277277}
    278278
    279 Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder) {
     279Function * preprocessPipeline(Module * m, IDISA::IDISA_Builder * iBuilder) {
    280280    Type * mBitBlockType = iBuilder->getBitBlockType();
    281281   
     
    285285    Type * const outputType = PointerType::get(ArrayType::get(mBitBlockType, 4), 0);
    286286   
    287     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, outputType, nullptr));
     287    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, size_ty, outputType, nullptr));
    288288    main->setCallingConv(CallingConv::C);
    289289    Function::arg_iterator args = main->arg_begin();
     
    313313    std::unique_ptr<Module> cccM = ccck.createKernelModule({&BasisBits}, {&CCResults});
    314314   
    315     mmapK.addKernelDeclarations(mMod);
    316     s2pk.addKernelDeclarations(mMod);
    317     ccck.addKernelDeclarations(mMod);
    318    
    319     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
     315    mmapK.addKernelDeclarations(m);
     316    s2pk.addKernelDeclarations(m);
     317    ccck.addKernelDeclarations(m);
     318   
     319    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
    320320
    321321    ByteStream.setStreamSetBuffer(inputStream, fileSize);
     
    327327    iBuilder->CreateRetVoid();
    328328   
    329     Linker L(*mMod);
     329    Linker L(*m);
    330330    L.linkInModule(std::move(mmapM));
    331331    L.linkInModule(std::move(s2pM));
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.cpp

    r5285 r5292  
    2323}
    2424
    25 void editdCPUKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     25void editdCPUKernel::generateDoBlockMethod(Value * blockNo) {
    2626    auto savePoint = iBuilder->saveIP();
    2727
     
    2929    Type * const int8ty = iBuilder->getInt8Ty();
    3030
    31     Value * pattStartPtr = getScalarField(self, "pattStream");
    32     Value * stideCarryArr = getScalarField(self, "srideCarry");
     31    Value * pattStartPtr = getScalarField("pattStream");
     32    Value * stideCarryArr = getScalarField("srideCarry");
    3333
    3434    unsigned carryIdx = 0;
     
    4141    Value * pattCh = iBuilder->CreateLoad(pattPtr);
    4242    Value * pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    43     Value * pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     43    Value * pattStreamPtr = getStream("CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    4444    Value * pattStream = iBuilder->CreateLoad(pattStreamPtr);
    4545    pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     
    5454        pattCh = iBuilder->CreateLoad(pattPtr);
    5555        pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    56         pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     56        pattStreamPtr = getStream("CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    5757        pattStream = iBuilder->CreateLoad(pattStreamPtr);
    5858
     
    7272    }
    7373   
    74     Value * ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(0));
     74    Value * ptr = getStream("ResultStream", blockNo, iBuilder->getInt32(0));
    7575    iBuilder->CreateStore(e[mPatternLen - 1][0], ptr);
    7676    for(unsigned j = 1; j<= mEditDistance; j++){
    77         ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(j));
     77        ptr = getStream("ResultStream", blockNo, iBuilder->getInt32(j));
    7878        iBuilder->CreateStore(iBuilder->CreateAnd(e[mPatternLen-1][j], iBuilder->CreateNot(e[mPatternLen-1][j-1])), ptr);
    7979    }
     
    8383}
    8484
    85 void editdCPUKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
    86     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
    87     iBuilder->CreateCall(getDoBlockFunction(), {self});
     85void editdCPUKernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
     86    setScalarField("EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     87    CreateDoBlockMethodCall();
    8888}
    8989
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5285 r5292  
    2121   
    2222private:
    23     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    24     void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
     23    void generateDoBlockMethod(llvm::Value * blockNo) override;
     24    void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override;
    2525    void bitblock_advance_ci_co(llvm::Value * val, unsigned shift, llvm::Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<llvm::Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j) const;
    2626    unsigned mEditDistance;
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.cpp

    r5285 r5292  
    2222}
    2323
    24 void editdGPUKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     24void editdGPUKernel::generateDoBlockMethod(Value * blockNo) {
    2525
    2626    IntegerType * const int32ty = iBuilder->getInt32Ty();
     
    2828    Value * pattLen = iBuilder->getInt32(mPatternLen + 1);
    2929    Value * pattPos = iBuilder->getInt32(0);
    30     Value * pattBuf = getScalarField(self, "pattStream");
    31     Value * stideCarryArr = getScalarField(self, "srideCarry");
     30    Value * pattBuf = getScalarField("pattStream");
     31    Value * stideCarryArr = getScalarField("srideCarry");
    3232   
    3333    unsigned carryIdx = 0;
     
    4444    Value * pattCh = iBuilder->CreateLoad(pattPtr);
    4545    Value * pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    46     Value * pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     46    Value * pattStreamPtr = getStream("CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    4747    Value * pattStream = iBuilder->CreateLoad(pattStreamPtr);
    4848    pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     
    5656        pattCh = iBuilder->CreateLoad(pattPtr);
    5757        pattIdx = iBuilder->CreateAnd(iBuilder->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    58         pattStreamPtr = getStream(self, "CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
     58        pattStreamPtr = getStream("CCStream", blockNo, iBuilder->CreateZExt(pattIdx, int32ty));
    5959        pattStream = iBuilder->CreateLoad(pattStreamPtr);
    6060        bitblock_advance_ci_co(iBuilder, e[i-1][0], 1, stideCarryArr, carryIdx++, adv, calculated, i-1, 0);
     
    7171        pattPos = iBuilder->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
    7272    }
    73     Value * ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(0));
     73    Value * ptr = getStream("ResultStream", blockNo, iBuilder->getInt32(0));
    7474    iBuilder->CreateStore(e[mPatternLen-1][0], ptr);
    7575    for(unsigned j = 1; j<= mEditDistance; j++){
    76         ptr = getStream(self, "ResultStream", blockNo, iBuilder->getInt32(j));
     76        ptr = getStream("ResultStream", blockNo, iBuilder->getInt32(j));
    7777        iBuilder->CreateStore(iBuilder->CreateAnd(e[mPatternLen - 1][j], iBuilder->CreateNot(e[mPatternLen - 1][j - 1])), ptr);
    7878    }
    7979}
    8080
    81 void editdGPUKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
    82     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
    83     iBuilder->CreateCall(getDoBlockFunction(), { self });
     81void editdGPUKernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
     82    setScalarField("EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     83    CreateDoBlockMethodCall();
    8484}
    8585
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5285 r5292  
    2121   
    2222private:
    23     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    24     void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
     23    void generateDoBlockMethod(llvm::Value * blockNo) override;
     24    void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override;
    2525    unsigned mEditDistance;
    2626    unsigned mPatternLen;
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5285 r5292  
    1818}
    1919
    20 void editdScanKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     20void editdScanKernel::generateDoBlockMethod(Value * blockNo) {
    2121    auto savePoint = iBuilder->saveIP();
    2222    Function * scanWordFunction = generateScanWordRoutine(iBuilder->getModule());
     
    3030    std::vector<Value * > matchWordVectors;
    3131    for(unsigned d = 0; d <= mEditDistance; d++) {
    32         Value * ptr = getStream(self, "matchResults", blockNo, iBuilder->getInt32(d));
     32        Value * ptr = getStream("matchResults", blockNo, iBuilder->getInt32(d));
    3333        Value * matches = iBuilder->CreateBlockAlignedLoad(ptr);
    3434        matchWordVectors.push_back(iBuilder->CreateBitCast(matches, scanwordVectorType));
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5285 r5292  
    1818       
    1919private:
    20     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     20    void generateDoBlockMethod(llvm::Value * blockNo) override;
    2121    llvm::Function * generateScanWordRoutine(llvm::Module * m) const;
    2222       
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.cpp

    r5285 r5292  
    1616using namespace llvm;
    1717
    18 void DirectCharacterClassKernelBuilder::generateDoBlockMethod(Function * function, Value *self, Value *blockNo) const {
     18void DirectCharacterClassKernelBuilder::generateDoBlockMethod(Value *blockNo) {
    1919    unsigned packCount = 8 * mCodeUnitSize; 
    2020    unsigned codeUnitWidth = 8 * mCodeUnitSize;
    2121    Value * codeUnitPack[packCount];
    2222    for (unsigned i = 0; i < packCount; i++) {
    23         Value * ptr = getStream(self, "codeUnitStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     23        Value * ptr = getStream("codeUnitStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    2424        codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    2525    }
     
    5656            theCCstream = iBuilder->simd_or(theCCstream, pack);
    5757        }
    58         Value * ptr = getStream(self, "ccStream", blockNo, iBuilder->getInt32(j));
     58        Value * ptr = getStream("ccStream", blockNo, iBuilder->getInt32(j));
    5959        iBuilder->CreateBlockAlignedStore(theCCstream, ptr);
    6060    }
  • icGREP/icgrep-devel/icgrep/kernels/cc_kernel.h

    r5285 r5292  
    2727    }
    2828   
    29     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     29    void generateDoBlockMethod(llvm::Value * blockNo) override;
    3030
    3131private:
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5285 r5292  
    5353// Outputs: the deleted streams, plus a partial sum popcount
    5454
    55 void DeletionKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
    56     Value * delMaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
     55void DeletionKernel::generateDoBlockMethod(Value * blockNo) {
     56    Value * delMaskPtr = getStream("delMaskSet", blockNo, iBuilder->getInt32(0));
    5757    Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr);
    5858    std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, delMask);
    5959    for (unsigned j = 0; j < mStreamCount; ++j) {
    60         Value * inputStreamPtr = getStream(self, "inputStreamSet", blockNo, iBuilder->getInt32(j));
     60        Value * inputStreamPtr = getStream("inputStreamSet", blockNo, iBuilder->getInt32(j));
    6161        Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr);
    6262        Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, delMask, move_masks, input);
    63         Value * outputStreamPtr = getStream(self, "outputStreamSet", blockNo, iBuilder->getInt32(j));
     63        Value * outputStreamPtr = getStream("outputStreamSet", blockNo, iBuilder->getInt32(j));
    6464        iBuilder->CreateBlockAlignedStore(output, outputStreamPtr);
    6565    }
    6666    Value * delCount = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
    67     Value * delCountPtr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     67    Value * delCountPtr = getStream("deletionCounts", blockNo, iBuilder->getInt32(0));
    6868    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(delCount), delCountPtr);
    6969    // Stream deletion has only been applied within fields; the actual number of data items has not yet changed.
    70     Value * produced = getProducedItemCount(self, "outputStreamSet");
     70    Value * produced = getProducedItemCount("outputStreamSet");
    7171    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    72     setProducedItemCount(self, "outputStreamSet", produced);
    73     setProducedItemCount(self, "deletionCounts", produced);
     72    setProducedItemCount("outputStreamSet", produced);
     73    setProducedItemCount("deletionCounts", produced);
    7474}
    7575
    76 void DeletionKernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
     76void DeletionKernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
    7777    IntegerType * vecTy = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
    7878    Value * remaining = iBuilder->CreateZExt(remainingBytes, vecTy);
    7979    Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(vecTy), remaining));
    80     Value * const delmaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
     80    Value * const delmaskPtr = getStream("delMaskSet", blockNo, iBuilder->getInt32(0));
    8181    Value * const delmaskVal = iBuilder->CreateBlockAlignedLoad(delmaskPtr);
    8282    iBuilder->CreateBlockAlignedStore(iBuilder->CreateOr(EOF_del, delmaskVal), delmaskPtr);
    83     iBuilder->CreateCall(getDoBlockFunction(), {self});
     83    CreateDoBlockMethodCall();
    8484    // Adjust the produced item count
    85     Value * produced = getProducedItemCount(self, "outputStreamSet");
     85    Value * produced = getProducedItemCount("outputStreamSet");
    8686    produced = iBuilder->CreateSub(produced, iBuilder->getSize(iBuilder->getStride()));
    8787    produced =  iBuilder->CreateAdd(produced, remainingBytes);
    88     setProducedItemCount(self, "outputStreamSet", produced);
    89     setProducedItemCount(self, "deletionCounts", produced);
     88    setProducedItemCount("outputStreamSet", produced);
     89    setProducedItemCount("deletionCounts", produced);
    9090}
    9191
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5285 r5292  
    2929protected:
    3030
    31     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     31    void generateDoBlockMethod(llvm::Value * blockNo) override;
    3232
    33     void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
     33    void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override;
    3434
    3535private:
  • icGREP/icgrep-devel/icgrep/kernels/evenodd.cpp

    r5285 r5292  
    66#include "evenodd.h"
    77#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
    8 #include <llvm/IR/Constant.h>      // for Constant
    9 #include <llvm/IR/Module.h>
    10 #include <llvm/IR/Function.h>
    11 #include <llvm/IR/Module.h>
    12 #include <llvm/ExecutionEngine/ExecutionEngine.h>
    13 #include "llvm/Linker/Linker.h"
    14 #include <llvm/Support/CommandLine.h>
    15 #include <llvm/Support/raw_ostream.h>
    16 namespace llvm { class BasicBlock; }
    17 namespace llvm { class Function; }
    18 namespace llvm { class Value; }
    198
    209using namespace llvm;
     
    2211namespace kernel {
    2312
    24 void EvenOddKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     13void EvenOddKernel::generateDoBlockMethod(Value * blockNo) {
    2514    Value * even = iBuilder->simd_fill(64, iBuilder->getInt64(0x5555555555555555));
    2615    Value * odd = iBuilder->bitCast(iBuilder->simd_fill(8, iBuilder->getInt8(0xAA)));
    27     Value * evenBitsPtr = getStream(self, "even_odd", blockNo, iBuilder->getInt32(0));
     16    Value * evenBitsPtr = getStream("even_odd", blockNo, iBuilder->getInt32(0));
    2817    iBuilder->CreateBlockAlignedStore(even, evenBitsPtr);
    29     Value * oddBitsPtr = getStream(self, "even_odd", blockNo, iBuilder->getInt32(1));
     18    Value * oddBitsPtr = getStream("even_odd", blockNo, iBuilder->getInt32(1));
    3019    iBuilder->CreateBlockAlignedStore(odd, oddBitsPtr);
    3120}
  • icGREP/icgrep-devel/icgrep/kernels/evenodd.h

    r5285 r5292  
    1414class EvenOddKernel : public BlockOrientedKernel {
    1515public:
    16    
    1716    EvenOddKernel(IDISA::IDISA_Builder * builder);
    18 
    1917    virtual ~EvenOddKernel() {}
    20        
    2118private:
    22     void generateDoBlockLogic(llvm::Value * self, llvm::Value * blockNo) const override;   
    23     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    24     void generateFinalBlockMethod() const override;
     19    void generateDoBlockMethod(llvm::Value * blockNo) override;
    2520
    2621};
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5287 r5292  
    2222using namespace llvm;
    2323
    24 void KernelInterface::addKernelDeclarations(Module * client) const {
     24void KernelInterface::addKernelDeclarations(Module * client) {
    2525    Module * saveModule = iBuilder->getModule();
    2626    auto savePoint = iBuilder->saveIP();
     
    3131    PointerType * selfType = PointerType::getUnqual(mKernelStateType);
    3232
    33     // Create the accumulator get function prototypes
    34     for (auto binding : mScalarOutputs) {
    35         FunctionType * accumFnType = FunctionType::get(binding.type, {selfType}, false);
    36         std::string fnName = mKernelName + ACCUMULATOR_INFIX + binding.name;
    37         Function * accumFn = Function::Create(accumFnType, GlobalValue::ExternalLinkage, fnName, client);
    38         accumFn->setCallingConv(CallingConv::C);
    39         accumFn->setDoesNotThrow();
    40         Value * self = &*(accumFn->arg_begin());
    41         self->setName("self");       
    42     }
    43 
    4433    // Create the initialization function prototype
    4534    std::vector<Type *> initParameters = {selfType};
     
    4736        initParameters.push_back(binding.type);
    4837    }
    49     FunctionType * initFunctionType = FunctionType::get(iBuilder->getVoidTy(), initParameters, false);
    50     std::string initFnName = mKernelName + INIT_SUFFIX;
    51     Function * initFn = Function::Create(initFunctionType, GlobalValue::ExternalLinkage, initFnName, client);
    52     initFn->setCallingConv(CallingConv::C);
    53     initFn->setDoesNotThrow();
    54     Function::arg_iterator initArgs = initFn->arg_begin();
    55     Value * initArg = &*(initArgs++);
    56     initArg->setName("self");
     38    FunctionType * initType = FunctionType::get(iBuilder->getVoidTy(), initParameters, false);
     39    Function * init = Function::Create(initType, GlobalValue::ExternalLinkage, mKernelName + INIT_SUFFIX, client);
     40    init->setCallingConv(CallingConv::C);
     41    init->setDoesNotThrow();
     42    auto args = init->arg_begin();
     43    args++->setName("self");
    5744    for (auto binding : mScalarInputs) {
    58         initArg = &*(initArgs++);
    59         initArg->setName(binding.name);
     45        args++->setName(binding.name);
    6046    }
     47    assert (args == init->arg_end());
    6148
    6249    // Create the doSegment function prototype.
    6350    std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getInt1Ty()};
    64     for (auto ss : mStreamSetInputs) {
     51    for (unsigned i = 0; i < mStreamSetInputs.size(); ++i) {
    6552        doSegmentParameters.push_back(iBuilder->getSizeTy());
    6653    }
    67     FunctionType * doSegmentFunctionType = FunctionType::get(iBuilder->getVoidTy(), doSegmentParameters, false);
    68     std::string doSegmentName = mKernelName + DO_SEGMENT_SUFFIX;
    69     Function * doSegmentFn = Function::Create(doSegmentFunctionType, GlobalValue::ExternalLinkage, doSegmentName, client);
    70     doSegmentFn->setCallingConv(CallingConv::C);
    71     doSegmentFn->setDoesNotThrow();
    72     Function::arg_iterator args = doSegmentFn->arg_begin();
    73     Value * arg = &*(args++);
    74     arg->setName("self");
    75     arg = &*(args++);
    76     arg->setName("doFinal");
     54    FunctionType * doSegmentType = FunctionType::get(iBuilder->getVoidTy(), doSegmentParameters, false);
     55    Function * doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, mKernelName + DO_SEGMENT_SUFFIX, client);
     56    doSegment->setCallingConv(CallingConv::C);
     57    doSegment->setDoesNotThrow();
     58    doSegment->setDoesNotCapture(1); // for self parameter only.
     59    args = doSegment->arg_begin();
     60    args++->setName("self");
     61    args++->setName("doFinal");
    7762    for (auto ss : mStreamSetInputs) {
    78         arg = &*(args++);
    79         arg->setName(ss.name + "_availableItems");
     63        args++->setName(ss.name + "_availableItems");
    8064    }
    81     doSegmentFn->setDoesNotCapture(1); // for self parameter only.
     65    assert (args == doSegment->arg_end());
    8266
    8367    // Add any additional kernel declarations
    8468    addAdditionalKernelDeclarations(client, selfType);
    8569
     70    // Create the accumulator get function prototypes
     71    for (const auto & binding : mScalarOutputs) {
     72        FunctionType * accumFnType = FunctionType::get(binding.type, {selfType}, false);
     73        Function * accumFn = Function::Create(accumFnType, GlobalValue::ExternalLinkage, mKernelName + ACCUMULATOR_INFIX + binding.name, client);
     74        accumFn->setCallingConv(CallingConv::C);
     75        accumFn->setDoesNotThrow();
     76        auto self = accumFn->arg_begin();
     77        self->setName("self");
     78    }
     79
    8680    iBuilder->setModule(saveModule);
    8781    iBuilder->restoreIP(savePoint);
    88 }
    89 
    90 void KernelInterface::addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) const {
    91 
    9282}
    9383
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5287 r5292  
    4545
    4646    const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs;}
    47    
    48    
     47       
    4948    // Add ExternalLinkage method declarations for the kernel to a given client module.
    50     void addKernelDeclarations(llvm::Module * client) const;
     49    void addKernelDeclarations(llvm::Module * client);
    5150
    5251    virtual void createInstance() = 0;
     
    6463    }
    6564
    66     virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
     65    virtual llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const = 0;
    6766
    68     virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
     67    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
    6968
    70     virtual llvm::Value * getTerminationSignal(llvm::Value * self) const = 0;
     69    virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const = 0;
     70
     71    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
     72
     73    virtual llvm::Value * getTerminationSignal(llvm::Value * instance) const = 0;
     74
     75    virtual void setTerminationSignal(llvm::Value * instance) const = 0;
    7176   
    7277    void setLookAhead(unsigned lookAheadPositions) {
     
    102107    }
    103108   
    104     virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) const;
     109    virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) {}
    105110
    106111protected:
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5287 r5292  
    2727static const auto FINAL_BLOCK_SUFFIX = "_FinalBlock";
    2828
     29static const auto LOGICAL_SEGMENT_NO_SCALAR = "logicalSegNo";
     30
     31static const auto PROCESSED_ITEM_COUNT_SUFFIX = "_processedItemCount";
     32
     33static const auto PRODUCED_ITEM_COUNT_SUFFIX = "_producedItemCount";
     34
     35static const auto TERMINATION_SIGNAL = "terminationSignal";
     36
     37static const auto BUFFER_PTR_SUFFIX = "_bufferPtr";
     38
     39static const auto BLOCK_MASK_SUFFIX = "_blkMask";
     40
    2941using namespace llvm;
    3042using namespace kernel;
     
    7789             llvm::report_fatal_error("Kernel preparation: Buffer size too small " + mStreamSetInputs[i].name);
    7890        }
    79         mScalarInputs.push_back(Binding{mStreamSetInputBuffers[i]->getStreamBufferPointerType(), mStreamSetInputs[i].name + bufferPtrSuffix});
     91        mScalarInputs.push_back(Binding{mStreamSetInputBuffers[i]->getStreamBufferPointerType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX});
    8092        mStreamSetNameMap.emplace(mStreamSetInputs[i].name, streamSetNo);
    81         addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + processedItemCountSuffix);
     93        addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
    8294        streamSetNo++;
    8395    }
    8496    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    85         mScalarInputs.push_back(Binding{mStreamSetOutputBuffers[i]->getStreamBufferPointerType(), mStreamSetOutputs[i].name + bufferPtrSuffix});
     97        mScalarInputs.push_back(Binding{mStreamSetOutputBuffers[i]->getStreamBufferPointerType(), mStreamSetOutputs[i].name + BUFFER_PTR_SUFFIX});
    8698        mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, streamSetNo);
    87         addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + producedItemCountSuffix);
     99        addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + PRODUCED_ITEM_COUNT_SUFFIX);
    88100        streamSetNo++;
    89101    }
     
    98110    }
    99111    addScalar(iBuilder->getSizeTy(), BLOCK_NO_SCALAR);
    100     addScalar(iBuilder->getSizeTy(), logicalSegmentNoScalar);
    101     addScalar(iBuilder->getInt1Ty(), terminationSignal);
     112    addScalar(iBuilder->getSizeTy(), LOGICAL_SEGMENT_NO_SCALAR);
     113    addScalar(iBuilder->getInt1Ty(), TERMINATION_SIGNAL);
    102114    mKernelStateType = StructType::create(iBuilder->getContext(), mKernelFields, mKernelName);
    103115}
     
    122134    addKernelDeclarations(m);
    123135    callGenerateInitMethod();
     136    generateInternalMethods();
    124137    callGenerateDoSegmentMethod();
    125138    // Implement the accumulator get functions
     
    135148}
    136149
    137 void KernelBuilder::callGenerateDoSegmentMethod() const {
    138     Function * doSegmentFunction = getDoSegmentFunction();
    139     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
    140     auto args = doSegmentFunction->arg_begin();
    141     Value * self = &*(args++);
     150void KernelBuilder::callGenerateDoSegmentMethod() {
     151    mCurrentFunction = getDoSegmentFunction();
     152    iBuilder->SetInsertPoint(CreateBasicBlock(mKernelName + "_entry"));
     153    auto args = mCurrentFunction->arg_begin();
     154    mSelf = &*(args++);
    142155    Value * doFinal = &*(args++);
    143156    std::vector<Value *> producerPos;
     
    145158        producerPos.push_back(&*(args++));
    146159    }
    147     assert (args == doSegmentFunction->arg_end());
    148     generateDoSegmentMethod(doSegmentFunction, self, doFinal, producerPos); // must be overridden by the KernelBuilder subtype
     160    assert (args == mCurrentFunction->arg_end());
     161    generateDoSegmentMethod(doFinal, producerPos); // must be overridden by the KernelBuilder subtype
    149162    iBuilder->CreateRetVoid();
    150163}
    151164
    152 void KernelBuilder::callGenerateInitMethod() const {
    153     Function * initFunction = getInitFunction();
    154     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));
    155     Function::arg_iterator args = initFunction->arg_begin();
    156     Value * self = &*(args++);
    157     iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);
     165void KernelBuilder::callGenerateInitMethod() {
     166    mCurrentFunction = getInitFunction();
     167    iBuilder->SetInsertPoint(CreateBasicBlock("Init_entry"));
     168    Function::arg_iterator args = mCurrentFunction->arg_begin();
     169    mSelf = &*(args++);
     170    iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), mSelf);
    158171    for (auto binding : mScalarInputs) {
    159172        Value * param = &*(args++);
    160         Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.name)});
     173        Value * ptr = iBuilder->CreateGEP(mSelf, {iBuilder->getInt32(0), getScalarIndex(binding.name)});
    161174        iBuilder->CreateStore(param, ptr);
    162175    }
    163     generateInitMethod(initFunction, self);
     176    generateInitMethod();
    164177    iBuilder->CreateRetVoid();
    165178}
    166 
    167 // Default init method, possibly overridden if special init actions required.
    168 void KernelBuilder::generateInitMethod(Function * /* initFunction */, Value * /* self */) const { }
    169 
    170179
    171180ConstantInt * KernelBuilder::getScalarIndex(const std::string & name) const {
     
    181190}
    182191
    183 Value * KernelBuilder::getScalarFieldPtr(Value * self, const std::string & fieldName) const {
    184     return getScalarFieldPtr(self, getScalarIndex(fieldName));
    185 }
    186 
    187 Value * KernelBuilder::getScalarFieldPtr(Value * self, Value * index) const {
    188     return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), index});
    189 }
    190 
    191 Value * KernelBuilder::getScalarField(Value * self, const std::string & fieldName) const {
    192     return iBuilder->CreateLoad(getScalarFieldPtr(self, fieldName));
    193 }
    194 
    195 Value * KernelBuilder::getScalarField(Value * self, Value * index) const {
    196     return iBuilder->CreateLoad(getScalarFieldPtr(self, index));
    197 }
    198 
    199 void KernelBuilder::setScalarField(Value * self, const std::string & fieldName, Value * value) const {
    200     iBuilder->CreateStore(value, getScalarFieldPtr(self, fieldName));
    201 }
    202 
    203 void KernelBuilder::setScalarField(Value * self, Value * index, Value * value) const {
    204     iBuilder->CreateStore(value, getScalarFieldPtr(self, index));
    205 }
    206 
    207 LoadInst * KernelBuilder::acquireLogicalSegmentNo(Value * self) const {
    208     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(logicalSegmentNoScalar)});
    209     return iBuilder->CreateAtomicLoadAcquire(ptr);
    210 }
    211 
    212 Value * KernelBuilder::getProcessedItemCount(Value * self, const std::string & ssName) const {
    213     return getScalarField(self, ssName + processedItemCountSuffix);
    214 }
    215 
    216 Value * KernelBuilder::getProducedItemCount(Value * self, const std::string & ssName) const {
    217     return getScalarField(self, ssName + producedItemCountSuffix);
    218 }
    219 
    220 Value * KernelBuilder::getTerminationSignal(Value * self) const {
    221     return getScalarField(self, terminationSignal);
    222 }
    223 
    224 void KernelBuilder::releaseLogicalSegmentNo(Value * self, Value * newCount) const {
    225     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(logicalSegmentNoScalar)});
    226     iBuilder->CreateAtomicStoreRelease(newCount, ptr);
    227 }
    228 
    229 void KernelBuilder::setProcessedItemCount(Value * self, const std::string & name, Value * value) const {
    230     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(name + processedItemCountSuffix)});
     192Value * KernelBuilder::getScalarFieldPtr(llvm::Value * instance, Value * index) const {
     193    return iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), index});
     194}
     195
     196Value * KernelBuilder::getScalarFieldPtr(llvm::Value * instance, const std::string & fieldName) const {
     197    return getScalarFieldPtr(instance, getScalarIndex(fieldName));
     198}
     199
     200Value * KernelBuilder::getScalarField(Value * instance, const std::string & fieldName) const {
     201    return iBuilder->CreateLoad(getScalarFieldPtr(instance, fieldName));
     202}
     203
     204Value * KernelBuilder::getScalarField(Value * instance, Value * index) const {
     205    return iBuilder->CreateLoad(getScalarFieldPtr(instance, index));
     206}
     207
     208void KernelBuilder::setScalarField(Value * instance, const std::string & fieldName, Value * value) const {
     209    iBuilder->CreateStore(value, getScalarFieldPtr(instance, fieldName));
     210}
     211
     212void KernelBuilder::setScalarField(Value * instance, Value * index, Value * value) const {
     213    iBuilder->CreateStore(value, getScalarFieldPtr(instance, index));
     214}
     215
     216Value * KernelBuilder::getProcessedItemCount(Value * instance, const std::string & name) const {
     217    return getScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX);
     218}
     219
     220Value * KernelBuilder::getProducedItemCount(Value * instance, const std::string & name) const {
     221    return getScalarField(instance, name + PRODUCED_ITEM_COUNT_SUFFIX);
     222}
     223
     224void KernelBuilder::setProcessedItemCount(Value * instance, const std::string & name, Value * value) const {
     225    setScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX, value);
     226}
     227
     228void KernelBuilder::setProducedItemCount(Value * instance, const std::string & name, Value * value) const {
     229    setScalarField(instance, name + PRODUCED_ITEM_COUNT_SUFFIX, value);
     230}
     231
     232Value * KernelBuilder::getTerminationSignal(Value * instance) const {
     233    return getScalarField(instance, TERMINATION_SIGNAL);
     234}
     235
     236void KernelBuilder::setTerminationSignal(Value * instance) const {
     237    setScalarField(instance, TERMINATION_SIGNAL, iBuilder->getInt1(true));
     238}
     239
     240LoadInst * KernelBuilder::acquireLogicalSegmentNo(llvm::Value * instance) const {
     241    return iBuilder->CreateAtomicLoadAcquire(getScalarFieldPtr(instance, LOGICAL_SEGMENT_NO_SCALAR));
     242}
     243
     244void KernelBuilder::releaseLogicalSegmentNo(Value * instance, Value * newCount) const {
     245    iBuilder->CreateAtomicStoreRelease(newCount, getScalarFieldPtr(instance, LOGICAL_SEGMENT_NO_SCALAR));
     246}
     247
     248Value * KernelBuilder::getBlockNo() const {
     249    Value * ptr = iBuilder->CreateGEP(mSelf, {iBuilder->getInt32(0), getScalarIndex(BLOCK_NO_SCALAR)});
     250    return iBuilder->CreateLoad(ptr);
     251}
     252
     253void KernelBuilder::setBlockNo(Value * value) const {
     254    Value * ptr = iBuilder->CreateGEP(mSelf, {iBuilder->getInt32(0), getScalarIndex(BLOCK_NO_SCALAR)});
    231255    iBuilder->CreateStore(value, ptr);
    232256}
    233257
    234 void KernelBuilder::setProducedItemCount(Value * self, const std::string & name, Value * value) const {
    235     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(name + producedItemCountSuffix)});
    236     iBuilder->CreateStore(value, ptr);
    237 }
    238 
    239 void KernelBuilder::setTerminationSignal(Value * self) const {
    240     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(terminationSignal)});
    241     iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), ptr);
    242 }
    243 
    244 Value * KernelBuilder::getBlockNo(Value * self) const {
    245     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(BLOCK_NO_SCALAR)});
    246     return iBuilder->CreateLoad(ptr);
    247 }
    248 
    249 void KernelBuilder::setBlockNo(Value * self, Value * value) const {
    250     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(BLOCK_NO_SCALAR)});
    251     iBuilder->CreateStore(value, ptr);
    252 }
    253 
    254 Argument * KernelBuilder::getParameter(Function * const f, const std::string & name) const {
    255     for (auto & arg : f->getArgumentList()) {
    256         if (arg.getName().equals(name)) {
    257             return &arg;
    258         }
    259     }
    260     llvm::report_fatal_error(f->getName() + " does not have parameter " + name);
    261 }
    262 
    263 Value * KernelBuilder::createDoSegmentCall(const std::vector<llvm::Value *> & args) const {
    264     return iBuilder->CreateCall(getDoSegmentFunction(), args);
    265 }
    266 
    267 Value * KernelBuilder::createGetAccumulatorCall(Value * self, const std::string & accumName) const {
    268     return iBuilder->CreateCall(getAccumulatorFunction(accumName), {self});
    269 }
    270 
    271 
    272 unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
     258inline unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
    273259    const auto f = mStreamSetNameMap.find(name);
    274260    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
     
    276262    }
    277263    return f->second;
    278 }
    279 
    280 Value * KernelBuilder::getStreamSetBufferPtr(Value * self, const std::string & name) const {
    281     return getScalarField(self, name + bufferPtrSuffix);
    282264}
    283265
     
    291273}
    292274
    293 Value * KernelBuilder::getStreamSetPtr(Value * self, const std::string & name, Value * blockNo) const {
    294     return getStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(self, name), blockNo);
    295 }
    296 
    297 Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index) const {
    298     return getStreamSetBuffer(name)->getStream(getStreamSetBufferPtr(self, name), blockNo, index);
    299 }
    300 
    301 Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index1, Value * index2) const {
     275inline Value * KernelBuilder::getStreamSetBufferPtr(llvm::Value * instance, const std::string & name) const {
     276    return getScalarField(instance, name + BUFFER_PTR_SUFFIX);
     277}
     278
     279inline Value * KernelBuilder::getStreamSetBufferPtr(llvm::Value * instance, llvm::Value * index) const {
     280    return getScalarField(instance, index);
     281}
     282
     283Argument * KernelBuilder::getParameter(Function * const f, const std::string & name) const {
     284    for (auto & arg : f->getArgumentList()) {
     285        if (arg.getName().equals(name)) {
     286            return &arg;
     287        }
     288    }
     289    llvm::report_fatal_error(f->getName() + " does not have parameter " + name);
     290}
     291
     292Value * KernelBuilder::createDoSegmentCall(const std::vector<llvm::Value *> & args) const {
     293    return iBuilder->CreateCall(getDoSegmentFunction(), args);
     294}
     295
     296Value * KernelBuilder::createGetAccumulatorCall(Value * self, const std::string & accumName) const {
     297    return iBuilder->CreateCall(getAccumulatorFunction(accumName), {self});
     298}
     299
     300Value * KernelBuilder::getStreamSetPtr(const std::string & name, Value * blockNo) const {
     301    return getStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
     302}
     303
     304Value * KernelBuilder::getStream(const std::string & name, Value * blockNo, Value * index) const {
     305    return getStreamSetBuffer(name)->getStream(getStreamSetBufferPtr(name), blockNo, index);
     306}
     307
     308Value * KernelBuilder::getStream(const std::string & name, Value * blockNo, Value * index1, Value * index2) const {
    302309    assert (index1->getType() == index2->getType());
    303     return getStreamSetBuffer(name)->getStream(getStreamSetBufferPtr(self, name), blockNo, index1, index2);
    304 }
    305 
    306 Value * KernelBuilder::getStreamView(Value * self, const std::string & name, Value * blockNo, Value * index) const {
    307     return getStreamSetBuffer(name)->getStreamView(getStreamSetBufferPtr(self, name), blockNo, index);
    308 }
    309 
    310 Value * KernelBuilder::getStreamView(llvm::Type * type, Value * self, const std::string & name, Value * blockNo, Value * index) const {
    311     return getStreamSetBuffer(name)->getStreamView(type, getStreamSetBufferPtr(self, name), blockNo, index);
     310    return getStreamSetBuffer(name)->getStream(getStreamSetBufferPtr(name), blockNo, index1, index2);
     311}
     312
     313Value * KernelBuilder::getStreamView(const std::string & name, Value * blockNo, Value * index) const {
     314    return getStreamSetBuffer(name)->getStreamView(getStreamSetBufferPtr(name), blockNo, index);
     315}
     316
     317Value * KernelBuilder::getStreamView(llvm::Type * type, const std::string & name, Value * blockNo, Value * index) const {
     318    return getStreamSetBuffer(name)->getStreamView(type, getStreamSetBufferPtr(name), blockNo, index);
     319}
     320
     321BasicBlock * KernelBuilder::CreateBasicBlock(std::string && name) const {
     322    return BasicBlock::Create(iBuilder->getContext(), name, mCurrentFunction);
    312323}
    313324
     
    332343
    333344//  The default finalBlock method simply dispatches to the doBlock routine.
    334 void BlockOrientedKernel::generateFinalBlockMethod(Function * function, Value * self, Value * /* remainingBytes */, Value * /* blockNo */) const {
     345void BlockOrientedKernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
    335346//    std::vector<Value *> args = {self};
    336347//    for (Argument & arg : function->getArgumentList()){
    337348//        args.push_back(&arg);
    338349//    }
    339     iBuilder->CreateCall(getDoBlockFunction(), { self });
     350    CreateDoBlockMethodCall();
    340351}
    341352
    342353//  The default doSegment method dispatches to the doBlock routine for
    343354//  each block of the given number of blocksToDo, and then updates counts.
    344 void BlockOrientedKernel::generateDoSegmentMethod(Function * doSegmentFunction, Value * self, Value * doFinal, const std::vector<Value *> &producerPos) const {
    345 
    346     auto savePoint = iBuilder->saveIP();
    347     callGenerateDoBlockMethod();
    348     callGenerateDoFinalBlockMethod();
    349     iBuilder->restoreIP(savePoint);
    350 
    351     BasicBlock * entryBlock = iBuilder->GetInsertBlock();
    352     BasicBlock * strideLoopCond = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_strideLoopCond", doSegmentFunction, 0);
    353     BasicBlock * strideLoopBody = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_strideLoopBody", doSegmentFunction, 0);
    354     BasicBlock * stridesDone = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_stridesDone", doSegmentFunction, 0);
    355     BasicBlock * doFinalBlock = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_doFinalBlock", doSegmentFunction, 0);
    356     BasicBlock * segmentDone = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_segmentDone", doSegmentFunction, 0);
    357     Type * const size_ty = iBuilder->getSizeTy();
     355void BlockOrientedKernel::generateDoSegmentMethod(Value * doFinal, const std::vector<Value *> &producerPos) {
     356
     357    BasicBlock * const entryBlock = iBuilder->GetInsertBlock();
     358    BasicBlock * const strideLoopCond = CreateBasicBlock(mKernelName + "_strideLoopCond");
     359    BasicBlock * const strideLoopBody = CreateBasicBlock(mKernelName + "_strideLoopBody");
     360    BasicBlock * const stridesDone = CreateBasicBlock(mKernelName + "_stridesDone");
     361    BasicBlock * const doFinalBlock = CreateBasicBlock(mKernelName + "_doFinalBlock");
     362    BasicBlock * const segmentDone = CreateBasicBlock(mKernelName + "_segmentDone");
    358363
    359364    ConstantInt * stride = iBuilder->getSize(iBuilder->getStride());
     
    365370        availablePos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(availablePos, p), availablePos, p);
    366371    }
    367     Value * processed = getProcessedItemCount(self, mStreamSetInputs[0].name);
     372    Value * processed = getProcessedItemCount(mStreamSetInputs[0].name);
    368373    Value * itemsAvail = iBuilder->CreateSub(availablePos, processed);
    369374    Value * stridesToDo = iBuilder->CreateUDiv(itemsAvail, stride);
     
    371376
    372377    iBuilder->SetInsertPoint(strideLoopCond);
    373     PHINode * stridesRemaining = iBuilder->CreatePHI(size_ty, 2, "stridesRemaining");
     378    PHINode * stridesRemaining = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "stridesRemaining");
    374379    stridesRemaining->addIncoming(stridesToDo, entryBlock);
    375380    Value * notDone = iBuilder->CreateICmpUGT(stridesRemaining, iBuilder->getSize(0));
     
    377382
    378383    iBuilder->SetInsertPoint(strideLoopBody);
    379     Value * blockNo = getBlockNo(self);
    380 
    381     iBuilder->CreateCall(getDoBlockFunction(), self);
    382 
    383     setBlockNo(self, iBuilder->CreateAdd(blockNo, strideBlocks));
     384    Value * blockNo = getBlockNo();
     385
     386    CreateDoBlockMethodCall();
     387
     388    setBlockNo(iBuilder->CreateAdd(blockNo, strideBlocks));
    384389    stridesRemaining->addIncoming(iBuilder->CreateSub(stridesRemaining, iBuilder->getSize(1)), strideLoopBody);
    385390    iBuilder->CreateBr(strideLoopCond);
     
    389394    Value * segmentItemsProcessed = iBuilder->CreateMul(stridesToDo, stride);
    390395    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    391         Value * preProcessed = getProcessedItemCount(self, mStreamSetInputs[i].name);
    392         setProcessedItemCount(self, mStreamSetInputs[i].name, iBuilder->CreateAdd(preProcessed, segmentItemsProcessed));
     396        Value * preProcessed = getProcessedItemCount(mStreamSetInputs[i].name);
     397        setProcessedItemCount(mStreamSetInputs[i].name, iBuilder->CreateAdd(preProcessed, segmentItemsProcessed));
    393398    }
    394399    if (!mDoBlockUpdatesProducedItemCountsAttribute) {
    395400        for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    396             Value * preProduced = getProducedItemCount(self, mStreamSetOutputs[i].name);
    397             setProducedItemCount(self, mStreamSetOutputs[i].name, iBuilder->CreateAdd(preProduced, segmentItemsProcessed));
     401            Value * preProduced = getProducedItemCount(mStreamSetOutputs[i].name);
     402            setProducedItemCount(mStreamSetOutputs[i].name, iBuilder->CreateAdd(preProduced, segmentItemsProcessed));
    398403        }
    399404    }
     
    403408    iBuilder->SetInsertPoint(doFinalBlock);
    404409
    405     Value * remainingItems = iBuilder->CreateSub(producerPos[0], getProcessedItemCount(self, mStreamSetInputs[0].name));
    406 
    407     iBuilder->CreateCall(getDoFinalBlockFunction(), {self, remainingItems});
    408 
    409     // createFinalBlockCall(self, remainingItems);
     410    Value * remainingItems = iBuilder->CreateSub(producerPos[0], getProcessedItemCount(mStreamSetInputs[0].name));
     411
     412    CreateDoFinalBlockMethodCall(remainingItems);
     413
    410414    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    411         Value * preProcessed = getProcessedItemCount(self, mStreamSetInputs[i].name);
    412         setProcessedItemCount(self, mStreamSetInputs[i].name, iBuilder->CreateAdd(preProcessed, remainingItems));
     415        Value * preProcessed = getProcessedItemCount(mStreamSetInputs[i].name);
     416        setProcessedItemCount(mStreamSetInputs[i].name, iBuilder->CreateAdd(preProcessed, remainingItems));
    413417    }
    414418    if (!mDoBlockUpdatesProducedItemCountsAttribute) {
    415419        for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    416             Value * preProduced = getProducedItemCount(self, mStreamSetOutputs[i].name);
    417             setProducedItemCount(self, mStreamSetOutputs[i].name, iBuilder->CreateAdd(preProduced, remainingItems));
     420            Value * preProduced = getProducedItemCount(mStreamSetOutputs[i].name);
     421            setProducedItemCount(mStreamSetOutputs[i].name, iBuilder->CreateAdd(preProduced, remainingItems));
    418422        }
    419423    }
    420     setTerminationSignal(self);
     424    setTerminationSignal();
    421425    iBuilder->CreateBr(segmentDone);
    422426
     
    425429}
    426430
    427 void BlockOrientedKernel::callGenerateDoBlockMethod() const {
    428     Function * f = getDoBlockFunction();
    429     auto args = f->arg_begin();
    430     Value * const self = &(*args);
    431     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", f));
    432     generateDoBlockMethod(f, self, getBlockNo(self)); // must be implemented by the KernelBuilder subtype
     431void BlockOrientedKernel::generateInternalMethods() {
     432
     433    callGenerateDoBlockMethod();
     434
     435    callGenerateDoFinalBlockMethod();
     436}
     437
     438void BlockOrientedKernel::callGenerateDoBlockMethod() {
     439    mCurrentFunction = getDoBlockFunction();
     440    auto args = mCurrentFunction->arg_begin();
     441    mSelf = &(*args);
     442    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
     443    generateDoBlockMethod(getBlockNo()); // must be implemented by the KernelBuilder subtype
    433444    iBuilder->CreateRetVoid();
    434445}
    435446
    436 void BlockOrientedKernel::callGenerateDoFinalBlockMethod() const {
    437     Function * f = getDoFinalBlockFunction();
    438     auto args = f->arg_begin();
    439     Value * const self = &(*args++);
     447
     448void BlockOrientedKernel::callGenerateDoFinalBlockMethod() {
     449    mCurrentFunction = getDoFinalBlockFunction();
     450    auto args = mCurrentFunction->arg_begin();
     451    mSelf = &(*args++);
    440452    Value * const remainingBytes = &(*args);
    441     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", f));
    442     generateFinalBlockMethod(f, self, remainingBytes, getBlockNo(self)); // possibly overridden by the KernelBuilder subtype
     453    iBuilder->SetInsertPoint(CreateBasicBlock("entry"));
     454    generateFinalBlockMethod(remainingBytes, getBlockNo()); // possibly overridden by the KernelBuilder subtype
    443455    iBuilder->CreateRetVoid();
    444456}
    445457
    446458Function * BlockOrientedKernel::getDoBlockFunction() const {
    447     return iBuilder->getModule()->getFunction(mKernelName + DO_BLOCK_SUFFIX);
     459    const auto name = mKernelName + DO_BLOCK_SUFFIX;
     460    Function * const f = iBuilder->getModule()->getFunction(name);
     461    if (LLVM_UNLIKELY(f == nullptr)) {
     462        llvm::report_fatal_error("Cannot find " + name);
     463    }
     464    return f;
     465}
     466
     467CallInst * BlockOrientedKernel::CreateDoBlockMethodCall() const {
     468    return iBuilder->CreateCall(getDoBlockFunction(), mSelf);
    448469}
    449470
    450471Function * BlockOrientedKernel::getDoFinalBlockFunction() const {
    451     return iBuilder->getModule()->getFunction(mKernelName + FINAL_BLOCK_SUFFIX);
    452 }
    453 
    454 void BlockOrientedKernel::addAdditionalKernelDeclarations(Module * m, PointerType * selfType) const {
     472    const auto name = mKernelName + FINAL_BLOCK_SUFFIX;
     473    Function * const f = iBuilder->getModule()->getFunction(name);
     474    if (LLVM_UNLIKELY(f == nullptr)) {
     475        llvm::report_fatal_error("Cannot find " + name);
     476    }
     477    return f;
     478}
     479
     480CallInst * BlockOrientedKernel::CreateDoFinalBlockMethodCall(Value * remainingItems) const {
     481    return iBuilder->CreateCall(getDoFinalBlockFunction(), {mSelf, remainingItems});
     482}
     483
     484void BlockOrientedKernel::addAdditionalKernelDeclarations(Module * m, PointerType * selfType) {
    455485    // Create the doBlock and finalBlock function prototypes
    456     FunctionType * doBlockFunctionType = FunctionType::get(iBuilder->getVoidTy(), {selfType}, false);
    457     Function * doBlockFn = Function::Create(doBlockFunctionType, GlobalValue::ExternalLinkage, mKernelName + DO_BLOCK_SUFFIX, m);
    458     doBlockFn->setCallingConv(CallingConv::C);
    459     doBlockFn->setDoesNotThrow();
    460     doBlockFn->setDoesNotCapture(1);
    461     auto doBlockArgs = doBlockFn->arg_begin();
    462     Value * doBlockArg = &*(doBlockArgs++);
    463     doBlockArg->setName("self");
    464 
    465     FunctionType * finalBlockType = FunctionType::get(iBuilder->getVoidTy(), {selfType, iBuilder->getSizeTy()}, false);
    466     Function * finalBlockFn = Function::Create(finalBlockType, GlobalValue::ExternalLinkage, mKernelName + FINAL_BLOCK_SUFFIX, m);
    467     finalBlockFn->setCallingConv(CallingConv::C);
    468     finalBlockFn->setDoesNotThrow();
    469     finalBlockFn->setDoesNotCapture(1);
    470     auto finalBlockArgs = finalBlockFn->arg_begin();
    471     Value * finalBlockArg = &*(finalBlockArgs++);
    472     finalBlockArg->setName("self");
    473     finalBlockArg = &*(finalBlockArgs++);
    474     finalBlockArg->setName("remainingBytes");
    475 
     486    FunctionType * const doBlockType = FunctionType::get(iBuilder->getVoidTy(), {selfType}, false);
     487    Function * const doBlock = Function::Create(doBlockType, GlobalValue::ExternalLinkage, mKernelName + DO_BLOCK_SUFFIX, m);
     488    doBlock->setCallingConv(CallingConv::C);
     489    doBlock->setDoesNotThrow();
     490    doBlock->setDoesNotCapture(1);
     491    auto args = doBlock->arg_begin();
     492    args->setName("self");
     493
     494    FunctionType * const finalBlockType = FunctionType::get(iBuilder->getVoidTy(), {selfType, iBuilder->getSizeTy()}, false);
     495    Function * const finalBlock = Function::Create(finalBlockType, GlobalValue::ExternalLinkage, mKernelName + FINAL_BLOCK_SUFFIX, m);
     496    finalBlock->setCallingConv(CallingConv::C);
     497    finalBlock->setDoesNotThrow();
     498    finalBlock->setDoesNotCapture(1);
     499    args = finalBlock->arg_begin();
     500    args++->setName("self");
     501    args->setName("remainingBytes");
    476502}
    477503
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5287 r5292  
    2020namespace parabix { class StreamSetBuffer; }
    2121
    22 const std::string logicalSegmentNoScalar = "logicalSegNo";
    23 const std::string processedItemCountSuffix = "_processedItemCount";
    24 const std::string producedItemCountSuffix = "_producedItemCount";
    25 const std::string terminationSignal = "terminationSignal";
    26 const std::string bufferPtrSuffix = "_bufferPtr";
    27 const std::string blkMaskSuffix = "_blkMask";
    28 
    2922namespace kernel {
    3023   
     
    4336    void createInstance() override;
    4437
    45     llvm::Value * getBlockNo(llvm::Value * self) const;
    46 
    47     virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const override;
    48 
    49     virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const override;
    50    
     38    virtual llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const override;
     39
     40    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const;
     41
     42    virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const override;
     43
     44    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const;
     45
    5146    bool hasNoTerminateAttribute() { return mNoTerminateAttribute;}
    5247   
    53     llvm::Value * getTerminationSignal(llvm::Value * self) const override;
    54    
    55     inline llvm::IntegerType * getSizeTy() const {
    56         return getBuilder()->getSizeTy();
    57     }
    58 
    59     inline llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
    60         return getBuilder()->getStreamTy(FieldWidth);
    61     }
    62    
    63     inline llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    64         return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    65     }
    66    
     48    llvm::Value * getTerminationSignal(llvm::Value * instance) const override final;
     49
     50    void setTerminationSignal(llvm::Value * instance) const override final;
     51
     52    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & name) const;
     53
     54    llvm::Value * getScalarFieldPtr(llvm::Value *instance, llvm::Value * index) const;
     55
     56    llvm::Value * getStreamSetBufferPtr(llvm::Value * instance, const std::string & name) const;
     57
     58    llvm::Value * getStreamSetBufferPtr(llvm::Value * instance, llvm::Value * index) const;
     59   
     60    // Get the value of a scalar field for a given instance.
     61    llvm::Value * getScalarField(llvm::Value * instance, const std::string & fieldName) const;
     62
     63    llvm::Value * getScalarField(llvm::Value * instance, llvm::Value * index) const;
     64
     65    // Set the value of a scalar field for a given instance.
     66    void setScalarField(llvm::Value *instance, const std::string & fieldName, llvm::Value * value) const;
     67
     68    void setScalarField(llvm::Value * instance, llvm::Value * index, llvm::Value * value) const;
     69
    6770    // Synchronization actions for executing a kernel for a particular logical segment.
    68     // 
     71    //
    6972    // Before the segment is processed, acquireLogicalSegmentNo must be used to load
    7073    // the segment number of the kernel state to ensure that the previous segment is
    7174    // complete (by checking that the acquired segment number is equal to the desired segment
    7275    // number).
    73     // After all segment processing actions for the kernel are complete, and any necessary 
    74     // data has been extracted from the kernel for further pipeline processing, the 
     76    // After all segment processing actions for the kernel are complete, and any necessary
     77    // data has been extracted from the kernel for further pipeline processing, the
    7578    // segment number must be incremented and stored using releaseLogicalSegmentNo.
    76     llvm::LoadInst * acquireLogicalSegmentNo(llvm::Value * self) const;
    77 
    78     void releaseLogicalSegmentNo(llvm::Value * self, llvm::Value * newFieldVal) const;
    79 
     79    llvm::LoadInst * acquireLogicalSegmentNo(llvm::Value * instance) const;
     80
     81    void releaseLogicalSegmentNo(llvm::Value * instance, llvm::Value * newFieldVal) const;
     82
     83    // Get a parameter by name.
     84    llvm::Argument * getParameter(llvm::Function * f, const std::string & name) const;
     85
     86    inline llvm::IntegerType * getSizeTy() const {
     87        return getBuilder()->getSizeTy();
     88    }
     89
     90    inline llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
     91        return getBuilder()->getStreamTy(FieldWidth);
     92    }
     93   
     94    inline llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
     95        return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
     96    }
     97   
    8098    virtual ~KernelBuilder() = 0;
    8199   
     
    83101
    84102    const std::vector<const parabix::StreamSetBuffer *> & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
    85 
    86     void setTerminationSignal(llvm::Value * self) const;
    87103
    88104    llvm::Value * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
     
    122138    virtual void prepareKernel();
    123139       
    124     virtual void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const;
    125    
    126     virtual void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const = 0;
    127    
     140    virtual void generateInitMethod() { }
     141   
     142    virtual void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) = 0;
     143
     144    virtual void generateInternalMethods() { }
     145
    128146    // Add an additional scalar field to the KernelState struct.
    129147    // Must occur before any call to addKernelDeclarations or createKernelModule.
     
    139157    // Get the index of a named scalar field within the kernel state struct.
    140158    llvm::ConstantInt * getScalarIndex(const std::string & name) const;
     159
     160    llvm::Value * getBlockNo() const;
     161
     162    void setBlockNo(llvm::Value * value) const;
    141163   
    142164    // Get the value of a scalar field for a given instance.
    143     llvm::Value * getScalarField(llvm::Value * self, const std::string & fieldName) const;
    144 
    145     llvm::Value * getScalarField(llvm::Value * self, llvm::Value * index) const;
     165    llvm::Value * getScalarField(const std::string & fieldName) const {
     166        return getScalarField(getSelf(), fieldName);
     167    }
     168
     169    llvm::Value * getScalarField(llvm::Value * index) const {
     170        return getScalarField(getSelf(), index);
     171    }
    146172
    147173    // Set the value of a scalar field for a given instance.
    148     void setScalarField(llvm::Value * self, const std::string & fieldName, llvm::Value * value) const;
    149 
    150     void setScalarField(llvm::Value * self, llvm::Value * index, llvm::Value * value) const;
    151 
    152     // Get a parameter by name.
    153     llvm::Argument * getParameter(llvm::Function * f, const std::string & name) const;
    154 
    155     llvm::Value * getStream(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
    156 
    157     llvm::Value * getStream(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
    158 
    159     llvm::Value * getStreamView(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
    160 
    161     llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
     174    void setScalarField(const std::string & fieldName, llvm::Value * value) const {
     175        return setScalarField(getSelf(), fieldName, value);
     176    }
     177
     178    void setScalarField(llvm::Value * index, llvm::Value * value) const {
     179        return setScalarField(getSelf(), index, value);
     180    }
     181
     182    llvm::Value * getStream(const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
     183
     184    llvm::Value * getStream(const std::string & name, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
     185
     186    llvm::Value * getStreamView(const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
     187
     188    llvm::Value * getStreamView(llvm::Type * type, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
    162189
    163190    // Stream set helpers.
     191    llvm::Value * getScalarFieldPtr(const std::string & name) const {
     192        return getScalarFieldPtr(getSelf(), name);
     193    }
     194
     195    llvm::Value * getScalarFieldPtr(llvm::Value * index) const {
     196        return getScalarFieldPtr(getSelf(), index);
     197    }
     198
     199    llvm::Value * getStreamSetBufferPtr(const std::string & name) const {
     200        return getStreamSetBufferPtr(getSelf(), name);
     201    }
     202
     203    llvm::Value * getStreamSetBufferPtr(llvm::Value * index) const {
     204        return getStreamSetBufferPtr(getSelf(), index);
     205    }
     206
     207    llvm::Value * getStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
     208
     209    inline llvm::Value * getProcessedItemCount(const std::string & name) const {
     210        return getProcessedItemCount(getSelf(), name);
     211    }
     212
     213    inline void setProcessedItemCount(const std::string & name, llvm::Value * value) const {
     214        setProcessedItemCount(getSelf(), name, value);
     215    }
     216
     217    inline llvm::Value * getProducedItemCount(const std::string & name) const {
     218        return getProducedItemCount(getSelf(), name);
     219    }
     220
     221    inline void setProducedItemCount(const std::string & name, llvm::Value * value) const {
     222        setProducedItemCount(getSelf(), name, value);
     223    }
     224
     225    llvm::Value * getTerminationSignal() const {
     226        return getTerminationSignal(getSelf());
     227    }
     228
     229    void setTerminationSignal() const {
     230        return setTerminationSignal(getSelf());
     231    }
     232
     233
     234    llvm::Value * getSelf() const {
     235        return mSelf;
     236    }
     237
     238    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
     239
     240private:
     241
    164242    unsigned getStreamSetIndex(const std::string & name) const;
    165    
    166     llvm::Value * getScalarFieldPtr(llvm::Value * self, const std::string & name) const;
    167 
    168     llvm::Value * getScalarFieldPtr(llvm::Value * self, llvm::Value * index) const;
    169 
    170     llvm::Value * getStreamSetBufferPtr(llvm::Value * self, const std::string & name) const;
    171 
    172     llvm::Value * getStreamSetBufferPtr(llvm::Value * self, llvm::Value * index) const;
    173 
    174     llvm::Value * getStreamSetPtr(llvm::Value * self, const std::string & name, llvm::Value * blockNo) const;
    175    
    176     void setBlockNo(llvm::Value * self, llvm::Value * value) const;
    177 
    178     virtual void setProcessedItemCount(llvm::Value * self, const std::string & name, llvm::Value * value) const;
    179 
    180     virtual void setProducedItemCount(llvm::Value * self, const std::string & name, llvm::Value * value) const;
    181243
    182244    const parabix::StreamSetBuffer * getStreamSetBuffer(const std::string & name) const;
    183245
    184 private:
    185 
    186     void callGenerateInitMethod() const;
    187 
    188     void callGenerateDoSegmentMethod() const;
     246    void callGenerateInitMethod();
     247
     248    void callGenerateDoSegmentMethod();
    189249
    190250protected:
     251
     252    llvm::Value *                                   mSelf;
     253    llvm::Function *                                mCurrentFunction;
    191254
    192255    std::vector<llvm::Type *>                       mKernelFields;
     
    216279
    217280class BlockOrientedKernel : public KernelBuilder {
     281public:
     282
     283    llvm::CallInst * CreateDoBlockMethodCall() const;
     284
     285    llvm::CallInst * CreateDoFinalBlockMethodCall(llvm::Value * remainingItems) const;
     286
    218287protected:
     288
     289    virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType);
    219290
    220291    // Each kernel builder subtype must provide its own logic for generating
    221292    // doBlock calls.
    222     virtual void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const = 0;
    223 
    224     virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) const;
     293    virtual void generateDoBlockMethod(llvm::Value * blockNo) = 0;
    225294
    226295    // Each kernel builder subtypre must also specify the logic for processing the
     
    231300    // not be overridden.
    232301
    233     virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const;
    234 
    235     virtual void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const final;
     302    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo);
     303
     304    virtual void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) final;
     305
     306    void generateInternalMethods() override final;
    236307
    237308    BlockOrientedKernel(IDISA::IDISA_Builder * builder,
     
    250321
    251322private:
    252     void callGenerateDoBlockMethod() const;
    253 
    254     void callGenerateDoFinalBlockMethod() const;
     323
     324    void callGenerateDoBlockMethod();
     325
     326    void callGenerateDoFinalBlockMethod();
     327
    255328};
    256329
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5286 r5292  
    1717namespace kernel {
    1818           
    19 void MMapSourceKernel::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
    20     BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
    21     BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
     19void MMapSourceKernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
     20    BasicBlock * setTermination = CreateBasicBlock("setTermination");
     21    BasicBlock * mmapSourceExit = CreateBasicBlock("mmapSourceExit");
    2222    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    23     Value * fileItems = getScalarField(self, "fileSize");
     23    Value * fileItems = getScalarField("fileSize");
    2424    if (mCodeUnitWidth > 8) {
    2525        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
    2626    }
    27     Value * produced = getProducedItemCount(self, "sourceBuffer");   
     27    Value * produced = getProducedItemCount("sourceBuffer");
    2828    Value * nextProduced = iBuilder->CreateAdd(produced, segmentItems);
    2929    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, nextProduced);
    3030    produced = iBuilder->CreateSelect(lessThanFullSegment, fileItems, nextProduced);
    31     setProducedItemCount(self, "sourceBuffer", produced);
     31    setProducedItemCount("sourceBuffer", produced);
    3232
    3333    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
    3434    iBuilder->SetInsertPoint(setTermination);
    35     setTerminationSignal(self);
     35    setTerminationSignal();
    3636    iBuilder->CreateBr(mmapSourceExit);   
    3737
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.h

    r5286 r5292  
    1919    MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8); 
    2020private:
    21     void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
     21    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
    2222private:
    2323    const unsigned mSegmentBlocks;
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5285 r5292  
    4040}
    4141               
    42 void P2SKernel::generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const {
     42void P2SKernel::generateDoBlockMethod(llvm::Value * blockNo) {
    4343    Value * p_bitblock[8];
    4444    for (unsigned i = 0; i < 8; i++) {
    45         Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     45        Value * ptr = getStream("basisBits", blockNo, iBuilder->getInt32(i));
    4646        p_bitblock[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    4747    }
     
    4949    p2s(iBuilder, p_bitblock, s_bytepack);
    5050    for (unsigned j = 0; j < 8; ++j) {
    51         Value * ptr = getStream(self, "byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
     51        Value * ptr = getStream("byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
    5252        iBuilder->CreateBlockAlignedStore(s_bytepack[j], ptr);
    5353    }
     
    6363   
    6464
    65 void P2SKernelWithCompressedOutput::generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const {
     65void P2SKernelWithCompressedOutput::generateDoBlockMethod(llvm::Value * blockNo) {
    6666    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    6767    IntegerType * i32 = iBuilder->getInt32Ty();
     
    7070    Value * basisBits[8];
    7171    for (unsigned i = 0; i < 8; i++) {
    72         Value * basisBitsBlock_ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     72        Value * basisBitsBlock_ptr = getStream("basisBits", blockNo, iBuilder->getInt32(i));
    7373        basisBits[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr);
    7474    }
     
    7777
    7878    unsigned units_per_register = iBuilder->getBitBlockWidth()/8;
    79     Value * delCountBlock_ptr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     79    Value * delCountBlock_ptr = getStream("deletionCounts", blockNo, iBuilder->getInt32(0));
    8080    Value * unit_counts = iBuilder->fwCast(units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
    8181
    82     Value * unitsGenerated = getProducedItemCount(self, "byteStream"); // units generated to buffer
    83     Value * output_ptr = getStreamView(i8PtrTy, self, "byteStream", blockNo, iBuilder->getInt32(0));
     82    Value * unitsGenerated = getProducedItemCount("byteStream"); // units generated to buffer
     83    Value * output_ptr = getStreamView(i8PtrTy, "byteStream", blockNo, iBuilder->getInt32(0));
    8484    Value * offset = iBuilder->getInt32(0);
    8585    for (unsigned j = 0; j < 8; ++j) {
     
    8888    }
    8989    unitsGenerated = iBuilder->CreateAdd(unitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    90     setProducedItemCount(self, "byteStream", unitsGenerated);
     90    setProducedItemCount("byteStream", unitsGenerated);
    9191}
    9292   
     
    101101   
    102102
    103 void P2S16Kernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     103void P2S16Kernel::generateDoBlockMethod(Value * blockNo) {
    104104    Value * hi_input[8];
    105105    for (unsigned j = 0; j < 8; ++j) {
    106         Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
     106        Value * ptr = getStream("basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
    107107        hi_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    108108    }
     
    111111    Value * lo_input[8];
    112112    for (unsigned j = 0; j < 8; ++j) {
    113         Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j + 8));
     113        Value * ptr = getStream("basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j + 8));
    114114        lo_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    115115    }
     
    119119        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    120120        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    121         Value * ptr0 = getStream(self, "i16Stream", blockNo, iBuilder->getInt32(2 * j));
     121        Value * ptr0 = getStream("i16Stream", blockNo, iBuilder->getInt32(2 * j));
    122122        iBuilder->CreateBlockAlignedStore(merge0, ptr0);
    123         Value * ptr1 = getStream(self, "i16Stream", blockNo, iBuilder->getInt32(2 * j + 1));
     123        Value * ptr1 = getStream("i16Stream", blockNo, iBuilder->getInt32(2 * j + 1));
    124124        iBuilder->CreateBlockAlignedStore(merge1, ptr1);
    125125    }
     
    136136
    137137   
    138 void P2S16KernelWithCompressedOutput::generateDoBlockMethod(Function * function, Value *self, Value *blockNo) const {
     138void P2S16KernelWithCompressedOutput::generateDoBlockMethod(Value * blockNo) {
    139139    IntegerType * i32Ty = iBuilder->getInt32Ty();
    140140    PointerType * bitBlockPtrTy = iBuilder->getBitBlockType()->getPointerTo();
    141141    Value * hi_input[8];
    142142    for (unsigned j = 0; j < 8; ++j) {
    143         Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(j));
     143        Value * ptr = getStream("basisBits", blockNo, iBuilder->getInt32(j));
    144144        hi_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    145145    }
     
    148148    Value * lo_input[8];
    149149    for (unsigned j = 0; j < 8; ++j) {
    150         Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(j + 8));
     150        Value * ptr = getStream("basisBits", blockNo, iBuilder->getInt32(j + 8));
    151151        lo_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    152152    }
    153153    Value * lo_bytes[8];
    154154    p2s(iBuilder, lo_input, lo_bytes);
    155     Value * delCountBlock_ptr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     155    Value * delCountBlock_ptr = getStream("deletionCounts", blockNo, iBuilder->getInt32(0));
    156156    Value * unit_counts = iBuilder->fwCast(iBuilder->getBitBlockWidth() / 16, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
    157157    PointerType * int16PtrTy = PointerType::get(iBuilder->getInt16Ty(), 0);
    158158    ConstantInt * stride = iBuilder->getSize(iBuilder->getStride());
    159     Value * i16UnitsGenerated = getProducedItemCount(self, "i16Stream"); // units generated to buffer
     159    Value * i16UnitsGenerated = getProducedItemCount("i16Stream"); // units generated to buffer
    160160    Value * i16BlockNo = iBuilder->CreateUDiv(i16UnitsGenerated, stride);
    161     Value * u16_output_ptr = getStreamView(int16PtrTy, self, "i16Stream", i16BlockNo, iBuilder->CreateURem(i16UnitsGenerated, stride));
     161    Value * u16_output_ptr = getStreamView(int16PtrTy, "i16Stream", i16BlockNo, iBuilder->CreateURem(i16UnitsGenerated, stride));
    162162    Value * offset = ConstantInt::get(i32Ty, 0);
    163163    for (unsigned j = 0; j < 8; ++j) {
     
    170170    }
    171171    i16UnitsGenerated = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    172     setProducedItemCount(self, "i16Stream", i16UnitsGenerated);
     172    setProducedItemCount("i16Stream", i16UnitsGenerated);
    173173}
    174174   
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5285 r5292  
    1616    P2SKernel(IDISA::IDISA_Builder * iBuilder);
    1717private:
    18     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     18    void generateDoBlockMethod(llvm::Value * blockNo) override;
    1919};
    2020
     
    2323    P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);   
    2424private:
    25     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     25    void generateDoBlockMethod(llvm::Value * blockNo) override;
    2626};
    2727
     
    3030    P2S16Kernel(IDISA::IDISA_Builder * iBuilder);   
    3131private:
    32     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     32    void generateDoBlockMethod(llvm::Value * blockNo) override;
    3333};
    3434   
     
    3737    P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder);
    3838private:
    39     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     39    void generateDoBlockMethod(llvm::Value * blockNo) override;
    4040};
    4141   
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5283 r5292  
    146146        if (kernels[k]->hasNoTerminateAttribute()) {
    147147            iBuilder->CreateCondBr(cond, segmentLoopBody[k], segmentWait[k]);
    148         }
    149         else {
    150             // If the kernel terminated in a previous segment then the pipeline is done.
     148        } else { // If the kernel was terminated in a previous segment then the pipeline is done.
    151149            BasicBlock * completionTest = BasicBlock::Create(iBuilder->getContext(), kernels[k]->getName() + "Completed", threadFunc, 0);
    152150            iBuilder->CreateCondBr(cond, completionTest, segmentWait[k]);
     
    184182            segNo->addIncoming(iBuilder->CreateAdd(segNo, iBuilder->getSize(codegen::ThreadNum)), segmentLoopBody[last_kernel]);
    185183            iBuilder->CreateCondBr(doFinal, exitThreadBlock, segmentLoop);
    186         }
    187         else {
     184        } else {
    188185            iBuilder->CreateBr(segmentWait[k+1]);
    189186        }
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5291 r5292  
    4141// a continous buffer for the full segment (number of blocks).
    4242
    43 void expand3_4Kernel::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     43void expand3_4Kernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
    4444
    4545    BasicBlock * expand2_3entry = iBuilder->GetInsertBlock();
    46     BasicBlock * expand_3_4_loop = BasicBlock::Create(iBuilder->getContext(), "expand_3_4_loop", doSegmentFunction, 0);
    47     BasicBlock * expand3_4_loop_exit = BasicBlock::Create(iBuilder->getContext(), "expand3_4_loop_exit", doSegmentFunction, 0);
    48     BasicBlock * finalStep1 = BasicBlock::Create(iBuilder->getContext(), "finalStep1", doSegmentFunction, 0);
    49     BasicBlock * finalStep2 = BasicBlock::Create(iBuilder->getContext(), "finalStep2", doSegmentFunction, 0);
    50     BasicBlock * step2load = BasicBlock::Create(iBuilder->getContext(), "step2load", doSegmentFunction, 0);
    51     BasicBlock * step2store = BasicBlock::Create(iBuilder->getContext(), "step2store", doSegmentFunction, 0);
    52     BasicBlock * finalStep3 = BasicBlock::Create(iBuilder->getContext(), "finalStep3", doSegmentFunction, 0);
    53     BasicBlock * step3load = BasicBlock::Create(iBuilder->getContext(), "step3load", doSegmentFunction, 0);
    54     BasicBlock * step3store = BasicBlock::Create(iBuilder->getContext(), "step3store", doSegmentFunction, 0);
    55     BasicBlock * step3store2 = BasicBlock::Create(iBuilder->getContext(), "step3store2", doSegmentFunction, 0);
    56     BasicBlock * itemsDone = BasicBlock::Create(iBuilder->getContext(), "itemsDone", doSegmentFunction, 0);
    57     BasicBlock * expand3_4_final = BasicBlock::Create(iBuilder->getContext(), "expand3_4_final", doSegmentFunction, 0);
    58     BasicBlock * expand3_4_exit = BasicBlock::Create(iBuilder->getContext(), "expand3_4_exit", doSegmentFunction, 0);
     46    BasicBlock * expand_3_4_loop = CreateBasicBlock("expand_3_4_loop");
     47    BasicBlock * expand3_4_loop_exit = CreateBasicBlock("expand3_4_loop_exit");
     48    BasicBlock * finalStep1 = CreateBasicBlock("finalStep1");
     49    BasicBlock * finalStep2 = CreateBasicBlock("finalStep2");
     50    BasicBlock * step2load = CreateBasicBlock("step2load");
     51    BasicBlock * step2store = CreateBasicBlock("step2store");
     52    BasicBlock * finalStep3 = CreateBasicBlock("finalStep3");
     53    BasicBlock * step3load = CreateBasicBlock("step3load");
     54    BasicBlock * step3store = CreateBasicBlock("step3store");
     55    BasicBlock * step3store2 = CreateBasicBlock("step3store2");
     56    BasicBlock * itemsDone = CreateBasicBlock("itemsDone");
     57    BasicBlock * expand3_4_final = CreateBasicBlock("expand3_4_final");
     58    BasicBlock * expand3_4_exit = CreateBasicBlock("expand3_4_exit");
    5959   
    6060    // Determine the require shufflevector constants.
     
    8888    const unsigned packAlign = iBuilder->getBitBlockWidth()/8;
    8989
    90     Value * processed = getProcessedItemCount(self, "sourceStream");
     90    Value * processed = getProcessedItemCount("sourceStream");
    9191    Value * itemsAvail = iBuilder->CreateSub(producerPos[0], processed);
    9292   
     
    100100    Value * loopItemsToDo = iBuilder->CreateSub(itemsAvail, excessItems);
    101101
    102     Value * blockNo = getBlockNo(self);
     102    Value * blockNo = getBlockNo();
    103103
    104104    // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
    105     Value * sourcePackPtr = getStream(self, "sourceStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
    106 
    107     Value * outputGenerated = getProducedItemCount(self, "expandedStream"); // bytes previously generated to output
     105    Value * sourcePackPtr = getStream("sourceStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
     106
     107    Value * outputGenerated = getProducedItemCount("expandedStream"); // bytes previously generated to output
    108108    Value * outputBlockNo = iBuilder->CreateUDiv(outputGenerated, stride);
    109     Value * outputPackPtr = getStream(self, "expandedStream", outputBlockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
     109    Value * outputPackPtr = getStream("expandedStream", outputBlockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
    110110
    111111    Value * hasFullLoop = iBuilder->CreateICmpUGE(loopItemsToDo, triplePackSize);
     
    164164    // Update the produced and processed items count based on the loopItemsToDo value.
    165165    processed = iBuilder->CreateAdd(processed, loopItemsToDo);
    166     setProcessedItemCount(self, "sourceStream", processed);
    167    
    168     setBlockNo(self, iBuilder->CreateUDiv(processed, stride));
     166    setProcessedItemCount("sourceStream", processed);
     167   
     168    setBlockNo(iBuilder->CreateUDiv(processed, stride));
    169169    // We have produced 4 output bytes for every 3 input bytes.
    170170    Value * totalProduced = iBuilder->CreateMul(iBuilder->CreateUDiv(processed, Const3), Const4);
    171     setProducedItemCount(self, "expandedStream", totalProduced);
     171    setProducedItemCount("expandedStream", totalProduced);
    172172   
    173173    // Except for final segment processing, we are done.
     
    238238    iBuilder->SetInsertPoint(itemsDone);
    239239    processed = iBuilder->CreateAdd(processed, excessItems);
    240     setProcessedItemCount(self, "sourceStream", processed);
    241 
    242     setBlockNo(self, iBuilder->CreateUDiv(processed, stride));
     240    setProcessedItemCount("sourceStream", processed);
     241
     242    setBlockNo(iBuilder->CreateUDiv(processed, stride));
    243243    // We have produced 4 output bytes for every 3 input bytes.  If the number of input
    244244    // bytes is not a multiple of 3, then we have one more output byte for each excess
    245245    // input byte.
    246246    totalProduced = iBuilder->CreateAdd(iBuilder->CreateMul(iBuilder->CreateUDiv(processed, Const3), Const4), iBuilder->CreateURem(processed, Const3));
    247     setProducedItemCount(self, "expandedStream", totalProduced);
     247    setProducedItemCount("expandedStream", totalProduced);
    248248   
    249249    iBuilder->CreateBr(expand3_4_exit);
     
    287287}
    288288
    289 void radix64Kernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     289void radix64Kernel::generateDoBlockMethod(Value * blockNo) {
    290290    for (unsigned i = 0; i < 8; i++) {
    291         Value * expandedStream = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     291        Value * expandedStream = getStream("expandedStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    292292        Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStream);
    293293        Value * radix64pack = processPackData(bytepack);
    294         Value * radix64stream = getStream(self, "radix64stream",blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     294        Value * radix64stream = getStream("radix64stream",blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    295295        iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream);
    296296    }
    297     Value * produced = getProducedItemCount(self, "radix64stream");
     297    Value * produced = getProducedItemCount("radix64stream");
    298298    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    299     setProducedItemCount(self, "radix64stream", produced);
    300 }
    301 
    302 void radix64Kernel::generateFinalBlockMethod(Function * function, Value *self, Value * remainingBytes, Value * blockNo) const {
     299    setProducedItemCount("radix64stream", produced);
     300}
     301
     302void radix64Kernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
    303303
    304304    BasicBlock * entry = iBuilder->GetInsertBlock();
    305     BasicBlock * radix64_loop = BasicBlock::Create(iBuilder->getContext(), "radix64_loop", function, 0);
    306     BasicBlock * loopExit = BasicBlock::Create(iBuilder->getContext(), "loopExit", function, 0);
    307     BasicBlock * fbExit = BasicBlock::Create(iBuilder->getContext(), "fbExit", function, 0);
     305    BasicBlock * radix64_loop = CreateBasicBlock("radix64_loop");
     306    BasicBlock * loopExit = CreateBasicBlock("loopExit");
     307    BasicBlock * fbExit = CreateBasicBlock("fbExit");
    308308    // Final Block arguments: self, remaining.
    309309    Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, iBuilder->getSize(3));
     
    321321    loopRemain->addIncoming(remainingBytes, entry);
    322322
    323     Value * expandedStreamLoopPtr = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), idx);
     323    Value * expandedStreamLoopPtr = getStream("expandedStream", blockNo, iBuilder->getInt32(0), idx);
    324324    Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStreamLoopPtr);
    325325    Value * radix64pack = processPackData(bytepack);
    326326
    327     Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     327    Value * radix64streamPtr = getStream("radix64stream", blockNo, iBuilder->getInt32(0), idx);
    328328    iBuilder->CreateBlockAlignedStore(radix64pack, radix64streamPtr);
    329329
     
    343343    iBuilder->SetInsertPoint(fbExit);
    344344    Value * outputNumberAdd = iBuilder->CreateSelect(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(0)), iBuilder->getSize(0), iBuilder->getSize(1));
    345     Value * produced = iBuilder->CreateAdd(getProducedItemCount(self, "radix64stream"), iBuilder->CreateAdd(remainingBytes, outputNumberAdd));
    346     setProducedItemCount(self, "radix64stream", produced);
     345    Value * produced = iBuilder->CreateAdd(getProducedItemCount("radix64stream"), iBuilder->CreateAdd(remainingBytes, outputNumberAdd));
     346    setProducedItemCount("radix64stream", produced);
    347347}
    348348
     
    366366}
    367367
    368 void base64Kernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     368void base64Kernel::generateDoBlockMethod(Value * blockNo) {
    369369    for (unsigned i = 0; i < 8; i++) {
    370         Value * radix64stream_ptr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     370        Value * radix64stream_ptr = getStream("radix64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    371371        Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr);
    372372
    373373        Value* base64pack = processPackData(bytepack);
    374374
    375         Value * base64stream_ptr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     375        Value * base64stream_ptr = getStream("base64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    376376        iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr);
    377377    }
    378     Value * produced = getProducedItemCount(self, "base64stream");
     378    Value * produced = getProducedItemCount("base64stream");
    379379    produced = iBuilder->CreateAdd(produced, iBuilder->getSize(iBuilder->getStride()));
    380     setProducedItemCount(self, "base64stream", produced);
     380    setProducedItemCount("base64stream", produced);
    381381}
    382382
     
    384384// of 4 bytes.   When the number of radix 64 values is not a multiple of 4
    385385// number of radix 64 values
    386 void base64Kernel::generateFinalBlockMethod(Function * function, Value * self, Value * remainingBytes, Value * blockNo) const {
     386void base64Kernel::generateFinalBlockMethod(Value * remainingBytes, Value * blockNo) {
    387387
    388388    BasicBlock * entry = iBuilder->GetInsertBlock();
    389     BasicBlock * base64_loop = BasicBlock::Create(iBuilder->getContext(), "base64_loop", function, 0);
    390     BasicBlock * loopExit = BasicBlock::Create(iBuilder->getContext(), "loopExit", function, 0);
    391     BasicBlock * doPadding = BasicBlock::Create(iBuilder->getContext(), "doPadding", function, 0);
    392     BasicBlock * doPadding2 = BasicBlock::Create(iBuilder->getContext(), "doPadding2", function, 0);
    393     BasicBlock * fbExit = BasicBlock::Create(iBuilder->getContext(), "fbExit", function, 0);
     389    BasicBlock * base64_loop = CreateBasicBlock("base64_loop");
     390    BasicBlock * loopExit = CreateBasicBlock("loopExit");
     391    BasicBlock * doPadding = CreateBasicBlock("doPadding");
     392    BasicBlock * doPadding2 = CreateBasicBlock("doPadding2");
     393    BasicBlock * fbExit = CreateBasicBlock("fbExit");
    394394
    395395    Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, iBuilder->getSize(3));
     
    407407    idx->addIncoming(ConstantInt::getNullValue(iBuilder->getInt32Ty()), entry);
    408408    loopRemain->addIncoming(remainingBytes, entry);
    409     Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     409    Value * radix64streamPtr = getStream("radix64stream", blockNo, iBuilder->getInt32(0), idx);
    410410    Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64streamPtr);
    411411    Value * base64pack = processPackData(bytepack);
    412     Value * base64streamPtr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), idx);
     412    Value * base64streamPtr = getStream("base64stream", blockNo, iBuilder->getInt32(0), idx);
    413413    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64streamPtr);
    414414    idx->addIncoming(iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1)), base64_loop);
     
    423423
    424424    iBuilder->SetInsertPoint(doPadding);
    425     Value * i8output_ptr = getStreamView(iBuilder->getInt8PtrTy(), self, "base64stream", blockNo, iBuilder->getInt32(0));
     425    Value * i8output_ptr = getStreamView(iBuilder->getInt8PtrTy(), "base64stream", blockNo, iBuilder->getInt32(0));
    426426    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8output_ptr, remainingBytes));
    427427    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(3)), fbExit, doPadding2);
     
    431431    iBuilder->CreateBr(fbExit);
    432432    iBuilder->SetInsertPoint(fbExit);
    433     Value * produced = iBuilder->CreateAdd(getProducedItemCount(self, "base64stream"), iBuilder->CreateAdd(remainingBytes, padBytes));
    434     setProducedItemCount(self, "base64stream", produced);
     433    Value * produced = iBuilder->CreateAdd(getProducedItemCount("base64stream"), iBuilder->CreateAdd(remainingBytes, padBytes));
     434    setProducedItemCount("base64stream", produced);
    435435}
    436436
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5288 r5292  
    2323    expand3_4Kernel(IDISA::IDISA_Builder * iBuilder);
    2424private:
    25     void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value *self, llvm::Value *doFinal, const std::vector<llvm::Value *> &producerPos) const override;
     25    void generateDoSegmentMethod(llvm::Value *doFinal, const std::vector<llvm::Value *> &producerPos) override final;
    2626};
    2727
     
    3030    radix64Kernel(IDISA::IDISA_Builder * iBuilder);
    3131private:
    32     virtual void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    33     virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
     32    virtual void generateDoBlockMethod(llvm::Value * blockNo) override final;
     33    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override final;
    3434    llvm::Value* processPackData(llvm::Value* packData) const;
    3535};
     
    3939    base64Kernel(IDISA::IDISA_Builder * iBuilder);
    4040private:
    41     virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;
    42     virtual void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     41    virtual void generateDoBlockMethod(llvm::Value * blockNo) override final;
     42    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override final;
    4343    llvm::Value* processPackData(llvm::Value* packData) const;
    4444};
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5285 r5292  
    121121#endif
    122122   
    123 void S2PKernel::generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const {
     123void S2PKernel::generateDoBlockMethod(llvm::Value * blockNo) {
    124124    Value * bytepack[8];
    125125    for (unsigned i = 0; i < 8; i++) {
    126         Value * byteStream = getStream(self, "byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     126        Value * byteStream = getStream("byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
    127127        bytepack[i] = iBuilder->CreateBlockAlignedLoad(byteStream);
    128128    }
     
    130130    s2p(iBuilder, bytepack, basisbits);
    131131    for (unsigned i = 0; i < 8; ++i) {
    132         Value * basisBits = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     132        Value * basisBits = getStream("basisBits", blockNo, iBuilder->getInt32(i));
    133133        iBuilder->CreateBlockAlignedStore(basisbits[i], basisBits);
    134134    }
    135135}
    136136
    137 void S2PKernel::generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, Value * remainingBytes, llvm::Value * blockNo) const {
     137void S2PKernel::generateFinalBlockMethod(Value * remainingBytes, llvm::Value * blockNo) {
    138138    /* Prepare the s2p final block function:
    139139     assumption: if remaining bytes is greater than 0, it is safe to read a full block of bytes.
     
    141141     */
    142142   
    143     BasicBlock * finalPartialBlock = BasicBlock::Create(iBuilder->getContext(), "partial", function, 0);
    144     BasicBlock * finalEmptyBlock = BasicBlock::Create(iBuilder->getContext(), "empty", function, 0);
    145     BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), "exit", function, 0);
     143    BasicBlock * finalPartialBlock = CreateBasicBlock("partial");
     144    BasicBlock * finalEmptyBlock = CreateBasicBlock("empty");
     145    BasicBlock * exitBlock = CreateBasicBlock("exit");
    146146   
    147147    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0));
    148148    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
    149149    iBuilder->SetInsertPoint(finalPartialBlock);
    150     iBuilder->CreateCall(getDoBlockFunction(), {self});
     150    CreateDoBlockMethodCall();
    151151   
    152152    iBuilder->CreateBr(exitBlock);
    153153   
    154154    iBuilder->SetInsertPoint(finalEmptyBlock);
    155     Value * basisBitsPtr = getStreamView(self, "basisBits", blockNo, iBuilder->getInt64(0));
     155    Value * basisBitsPtr = getStreamView("basisBits", blockNo, iBuilder->getInt64(0));
    156156    iBuilder->CreateStore(Constant::getNullValue(basisBitsPtr->getType()->getPointerElementType()), basisBitsPtr);
    157157    iBuilder->CreateBr(exitBlock);
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5285 r5292  
    1717    virtual ~S2PKernel() {}
    1818private:
    19     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
    20     void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override;   
     19    void generateDoBlockMethod(llvm::Value * blockNo) override;
     20    void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override;
    2121};
    2222
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5285 r5292  
    3838}
    3939       
    40 void ScanMatchKernel::generateDoBlockMethod(Function * function, Value * self, Value * blockNo) const {
     40void ScanMatchKernel::generateDoBlockMethod(Value * blockNo) {
    4141
    4242    auto savePoint = iBuilder->saveIP();
     
    4848    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    4949    Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));   
    50     Value * recordStart = getScalarField(self, "LineStart");
    51     Value * recordNum = getScalarField(self, "LineNum");
    52     Value * matches = iBuilder->CreateBlockAlignedLoad(getStream(self, "matchResults", blockNo, iBuilder->getInt32(0)));
    53     Value * linebreaks = iBuilder->CreateBlockAlignedLoad(getStream(self, "matchResults", blockNo, iBuilder->getInt32(1)));
     50    Value * recordStart = getScalarField("LineStart");
     51    Value * recordNum = getScalarField("LineNum");
     52    Value * matches = iBuilder->CreateBlockAlignedLoad(getStream("matchResults", blockNo, iBuilder->getInt32(0)));
     53    Value * linebreaks = iBuilder->CreateBlockAlignedLoad(getStream("matchResults", blockNo, iBuilder->getInt32(1)));
    5454    Value * matchWordVector = iBuilder->CreateBitCast(matches, scanwordVectorType);
    5555    Value * breakWordVector = iBuilder->CreateBitCast(linebreaks, scanwordVectorType);
     
    5757        Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
    5858        Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
    59         Value * wordResult = iBuilder->CreateCall(scanWordFunction, {self, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum});
     59        Value * wordResult = iBuilder->CreateCall(scanWordFunction, {getSelf(), matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum});
    6060        scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, T->getBitWidth()));
    6161        recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
    6262        recordNum = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({1}));
    6363    }
    64     setScalarField(self, "LineStart", recordStart);
    65     setScalarField(self, "LineNum", recordNum);
     64    setScalarField("LineStart", recordStart);
     65    setScalarField("LineNum", recordNum);
    6666}
    6767
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5285 r5292  
    1818    ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, GrepType grepType);
    1919protected:
    20     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override;
     20    void generateDoBlockMethod(llvm::Value * blockNo) override;
    2121private:
    2222    llvm::Function * generateScanWordRoutine(llvm::Module * m) const;
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.cpp

    r5286 r5292  
    1212namespace kernel {
    1313   
    14 void StdInKernel::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     14void StdInKernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
    1515
    1616    Type * i8PtrTy = iBuilder->getInt8PtrTy();
    1717   
    18     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
    19     BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
    20     BasicBlock * stdInExit = BasicBlock::Create(iBuilder->getContext(), "stdInExit", doSegmentFunction, 0);
     18    BasicBlock * setTermination = CreateBasicBlock("setTermination");
     19    BasicBlock * stdInExit = CreateBasicBlock("stdInExit");
    2120    ConstantInt * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    2221    ConstantInt * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    2322    ConstantInt * segmentBytes = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth() * mCodeUnitWidth/8);
    2423    ConstantInt * stdin_fileno = iBuilder->getInt32(STDIN_FILENO);
    25     Value * produced = getProducedItemCount(self, "codeUnitBuffer");
     24    Value * produced = getProducedItemCount("codeUnitBuffer");
    2625    Value * blockNo = iBuilder->CreateUDiv(produced, blockItems);
    2726    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(produced, blockItems), itemBytes);
    28     Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
     27    Value * bytePtr = getStreamView(i8PtrTy, "codeUnitBuffer", blockNo, byteOffset);
    2928   
    3029    Value * nRead = iBuilder->CreateReadCall(stdin_fileno, bytePtr, segmentBytes);
    3130    Value * bytesRead = iBuilder->CreateSelect(iBuilder->CreateICmpSLT(nRead, iBuilder->getSize(0)), iBuilder->getSize(0), nRead);
    3231    produced = iBuilder->CreateAdd(produced, iBuilder->CreateUDiv(bytesRead, itemBytes));
    33     setProducedItemCount(self, "codeUnitBuffer", produced);
     32    setProducedItemCount("codeUnitBuffer", produced);
    3433    Value * lessThanFullSegment = iBuilder->CreateICmpULT(bytesRead, segmentBytes);
    3534    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, stdInExit);
    3635    iBuilder->SetInsertPoint(setTermination);
    37     setTerminationSignal(self);
     36    setTerminationSignal();
    3837    iBuilder->CreateBr(stdInExit);
    3938   
     
    5049}
    5150
    52 void FileSource::generateInitMethod(Function * initFunction, Value * self) const {
    53     BasicBlock * setTerminationOnFailure = BasicBlock::Create(iBuilder->getContext(), "setTerminationOnFailure", initFunction, 0);
    54     BasicBlock * fileSourceInitExit = BasicBlock::Create(iBuilder->getContext(), "fileSourceInitExit", initFunction, 0);
    55     Value * handle = iBuilder->CreateFOpenCall(getScalarField(self, "fileName"), iBuilder->CreateGlobalStringPtr("r"));
    56     setScalarField(self, "IOstreamPtr", handle);
     51void FileSource::generateInitMethod() {
     52    BasicBlock * setTerminationOnFailure = CreateBasicBlock("setTerminationOnFailure");
     53    BasicBlock * fileSourceInitExit = CreateBasicBlock("fileSourceInitExit");
     54    Value * handle = iBuilder->CreateFOpenCall(getScalarField("fileName"), iBuilder->CreateGlobalStringPtr("r"));
     55    setScalarField("IOstreamPtr", handle);
    5756    Value * failure = iBuilder->CreateICmpEQ(iBuilder->CreatePtrToInt(handle, iBuilder->getSizeTy()), iBuilder->getSize(0));
    5857    iBuilder->CreateCondBr(failure, setTerminationOnFailure, fileSourceInitExit);
    5958    iBuilder->SetInsertPoint(setTerminationOnFailure);
    60     setTerminationSignal(self);
     59    setTerminationSignal();
    6160    iBuilder->CreateBr(fileSourceInitExit);
    6261    iBuilder->SetInsertPoint(fileSourceInitExit);
    6362}
    6463   
    65 void FileSource::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value * doFinal, const std::vector<Value *> & producerPos) const {
     64void FileSource::generateDoSegmentMethod(Value * doFinal, const std::vector<Value *> & producerPos) {
    6665
    6766    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    68    
    69     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
    70     BasicBlock * closeFile = BasicBlock::Create(iBuilder->getContext(), "closeFile", doSegmentFunction, 0);
    71     BasicBlock * fileSourceExit = BasicBlock::Create(iBuilder->getContext(), "fileSourceExit", doSegmentFunction, 0);
     67    BasicBlock * closeFile = CreateBasicBlock("closeFile");
     68    BasicBlock * fileSourceExit = CreateBasicBlock("fileSourceExit");
    7269    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    7370    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    7471   
    75     Value * produced = getProducedItemCount(self, "codeUnitBuffer");
     72    Value * produced = getProducedItemCount("codeUnitBuffer");
    7673    Value * blockNo = iBuilder->CreateUDiv(produced, blockItems);
    7774    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(produced, blockItems), itemBytes);
    78     Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
    79     Value * IOstreamPtr = getScalarField(self, "IOstreamPtr");
     75    Value * bytePtr = getStreamView(i8PtrTy, "codeUnitBuffer", blockNo, byteOffset);
     76    Value * IOstreamPtr = getScalarField("IOstreamPtr");
    8077    Value * itemsToDo = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    8178    Value * nRead = iBuilder->CreateFReadCall(bytePtr, itemsToDo, itemBytes, IOstreamPtr);
    8279    produced = iBuilder->CreateAdd(produced, nRead);
    83     setProducedItemCount(self, "codeUnitBuffer", produced);
     80    setProducedItemCount("codeUnitBuffer", produced);
    8481    Value * lessThanFullSegment = iBuilder->CreateICmpULT(nRead, itemsToDo);
    8582    iBuilder->CreateCondBr(lessThanFullSegment, closeFile, fileSourceExit);
     
    8784    iBuilder->SetInsertPoint(closeFile);
    8885    iBuilder->CreateFCloseCall(IOstreamPtr);
    89     setTerminationSignal(self);
     86    setTerminationSignal();
    9087    iBuilder->CreateBr(fileSourceExit);
    9188   
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.h

    r5286 r5292  
    1818    StdInKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    1919protected:
    20     void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
     20    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
    2121private:
    2222    unsigned mSegmentBlocks;
     
    2929    FileSource(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    3030protected:
    31     void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const override final;
    32     void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
     31    void generateInitMethod() override final;
     32    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
    3333private:
    3434    unsigned mSegmentBlocks;
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5286 r5292  
    1717// Rather than using doBlock logic to write one block at a time, this custom
    1818// doSegment method, writes the entire segment with a single write call.
    19 void StdOutKernel::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     19void StdOutKernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
    2020
    2121    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
     
    2424    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    2525   
    26     Value * processed = getProcessedItemCount(self, "codeUnitBuffer");
     26    Value * processed = getProcessedItemCount("codeUnitBuffer");
    2727    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    2828   
    29     Value * blockNo = getBlockNo(self);
     29    Value * blockNo = getBlockNo();
    3030    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    31     Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
     31    Value * bytePtr = getStreamView(i8PtrTy, "codeUnitBuffer", blockNo, byteOffset);
    3232    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
    3333
    3434    processed = iBuilder->CreateAdd(processed, itemsToDo);
    35     setProcessedItemCount(self, "codeUnitBuffer", processed);
    36     setBlockNo(self, iBuilder->CreateUDiv(processed, blockItems));
     35    setProcessedItemCount("codeUnitBuffer", processed);
     36    setBlockNo(iBuilder->CreateUDiv(processed, blockItems));
    3737
    3838}
     
    4444}
    4545
    46 void FileSink::generateInitMethod(Function *initFunction, Value *self) const {
    47     BasicBlock * setTerminationOnFailure = BasicBlock::Create(iBuilder->getContext(), "setTerminationOnFailure", initFunction, 0);
    48     BasicBlock * fileSinkInitExit = BasicBlock::Create(iBuilder->getContext(), "fileSinkInitExit", initFunction, 0);
    49     Value * handle = iBuilder->CreateFOpenCall(getScalarField(self, "fileName"), iBuilder->CreateGlobalStringPtr("w"));
    50     setScalarField(self, "IOstreamPtr", handle);
     46void FileSink::generateInitMethod() {
     47    BasicBlock * setTerminationOnFailure = CreateBasicBlock("setTerminationOnFailure");
     48    BasicBlock * fileSinkInitExit = CreateBasicBlock("fileSinkInitExit");
     49    Value * handle = iBuilder->CreateFOpenCall(getScalarField("fileName"), iBuilder->CreateGlobalStringPtr("w"));
     50    setScalarField("IOstreamPtr", handle);
    5151    Value * failure = iBuilder->CreateICmpEQ(iBuilder->CreatePtrToInt(handle, iBuilder->getSizeTy()), iBuilder->getSize(0));
    5252    iBuilder->CreateCondBr(failure, setTerminationOnFailure, fileSinkInitExit);
    5353    iBuilder->SetInsertPoint(setTerminationOnFailure);
    54     setTerminationSignal(self);
     54    setTerminationSignal();
    5555    iBuilder->CreateBr(fileSinkInitExit);
    5656    iBuilder->SetInsertPoint(fileSinkInitExit);
    5757}
    5858
    59 void FileSink::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     59void FileSink::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
    6060    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    6161   
    62     BasicBlock * closeFile = BasicBlock::Create(iBuilder->getContext(), "closeFile", doSegmentFunction, 0);
    63     BasicBlock * fileOutExit = BasicBlock::Create(iBuilder->getContext(), "fileOutExit", doSegmentFunction, 0);
     62    BasicBlock * closeFile = CreateBasicBlock("closeFile");
     63    BasicBlock * fileOutExit = CreateBasicBlock("fileOutExit");
    6464    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    6565    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    6666   
    67     Value * processed = getProcessedItemCount(self, "codeUnitBuffer");
     67    Value * processed = getProcessedItemCount("codeUnitBuffer");
    6868    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    69     Value * IOstreamPtr = getScalarField(self, "IOstreamPtr");
     69    Value * IOstreamPtr = getScalarField("IOstreamPtr");
    7070   
    71     Value * blockNo = getBlockNo(self);
     71    Value * blockNo = getBlockNo();
    7272    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    73     Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
     73    Value * bytePtr = getStreamView(i8PtrTy, "codeUnitBuffer", blockNo, byteOffset);
    7474    iBuilder->CreateFWriteCall(bytePtr, itemsToDo, itemBytes, IOstreamPtr);
    7575   
    7676    processed = iBuilder->CreateAdd(processed, itemsToDo);
    77     setProcessedItemCount(self, "codeUnitBuffer", processed);
    78     setBlockNo(self, iBuilder->CreateUDiv(processed, blockItems));
     77    setProcessedItemCount("codeUnitBuffer", processed);
     78    setBlockNo(iBuilder->CreateUDiv(processed, blockItems));
    7979    iBuilder->CreateCondBr(doFinal, closeFile, fileOutExit);
    8080   
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5286 r5292  
    1616    StdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
    1717private:
    18     void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
     18    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
    1919private:
    2020    const unsigned mCodeUnitWidth;
     
    2727    FileSink(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
    2828protected:
    29     void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const override final;
    30     void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
     29    void generateInitMethod() override final;
     30    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
    3131private:
    3232    const unsigned mCodeUnitWidth;
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5285 r5292  
    5555    mCurrentScope = kernel->getEntryBlock();
    5656
    57     mCarryMetadata.resize(enumerate(mCurrentScope));
    58 
    59     mKernel->addScalar(analyse(mCurrentScope), "carries");
     57    mCarryMetadata.resize(enumerate(kernel->getEntryBlock()));
     58
     59    mKernel->addScalar(analyse(kernel->getEntryBlock()), "carries");
    6060}
    6161
     
    6363 * @brief initializeCodeGen
    6464 ** ------------------------------------------------------------------------------------------------------------- */
    65 void CarryManager::initializeCodeGen(Value * self, Function * function) {
     65void CarryManager::initializeCodeGen() {
    6666    // TODO: need to look into abstracting the Initialize creation function in KernelBuilder::generateKernel
    6767    // so that we can allocate the variable length buffers if needed.
    6868
    69     mSelf = self;
    70     mFunction = function;
    71 
    72     assert(mCarryMetadata.size() > 0);
     69    assert(!mCarryMetadata.empty());
    7370    mCarryInfo = &mCarryMetadata[0];
    7471    assert (!mCarryInfo->hasSummary());
    7572
    76     mCurrentFrame = iBuilder->CreateGEP(mSelf, {iBuilder->getInt32(0), mKernel->getScalarIndex("carries")}, "carries");
     73    mCurrentFrame = mKernel->getScalarFieldPtr("carries");
    7774    mCurrentFrameIndex = 0;
    7875
     
    8481 * @brief enterLoopScope
    8582 ** ------------------------------------------------------------------------------------------------------------- */
    86 void CarryManager::enterLoopScope(PabloBlock * const scope) {
     83void CarryManager::enterLoopScope(const PabloBlock * const scope) {
    8784    assert (scope);
    8885    if (mLoopDepth++ == 0) {
    89         Value * const blockNo = mKernel->getBlockNo(mSelf);
     86        Value * const blockNo = mKernel->getBlockNo();
    9087        mLoopSelector = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), 1));
    9188    }
     
    10097    if (mCarryInfo->hasSummary()) {
    10198        PHINode * carrySummary = iBuilder->CreatePHI(mCarryPackType, 2, "summary");
    102         assert (mCarrySummary.size() > 0);
     99        assert (!mCarrySummary.empty());
    103100        carrySummary->addIncoming(mCarrySummary.back(), entryBlock);
    104101        // Replace the incoming carry summary with the phi node and add the phi node to the stack
     
    118115        Value * array = iBuilder->CreateLoad(arrayPtr, false, "array");
    119116
    120         LLVMContext & C = iBuilder->getContext();
    121 
    122         BasicBlock * resizeBlock = BasicBlock::Create(C, "", mFunction);
    123         BasicBlock * cleanUpBlock = BasicBlock::Create(C, "", mFunction);
    124         BasicBlock * zeroBlock = BasicBlock::Create(C, "", mFunction);
    125         BasicBlock * codeBlock = BasicBlock::Create(C, "", mFunction);
     117        BasicBlock * resizeBlock = mKernel->CreateBasicBlock("");
     118        BasicBlock * cleanUpBlock = mKernel->CreateBasicBlock("");
     119        BasicBlock * zeroBlock = mKernel->CreateBasicBlock("");
     120        BasicBlock * codeBlock = mKernel->CreateBasicBlock("");
    126121
    127122        Value * cond = iBuilder->CreateICmpULT(index, capacity);
     
    171166    }
    172167    if (LLVM_UNLIKELY(mCarryInfo->variableLength)) {
    173         assert (mLoopIndicies.size() > 0);
     168        assert (!mLoopIndicies.empty());
    174169        PHINode * index = mLoopIndicies.back();
    175170        index->addIncoming(iBuilder->CreateAdd(index, iBuilder->getSize(1)), exitBlock);
     
    192187 * @brief enterIfScope
    193188 ** ------------------------------------------------------------------------------------------------------------- */
    194 void CarryManager::enterIfScope(PabloBlock * const scope) {
     189void CarryManager::enterIfScope(const PabloBlock * const scope) {
    195190    ++mIfDepth;
    196191    enterScope(scope);
     
    242237    const auto n = mCarrySummary.size();
    243238    if (LLVM_LIKELY(mCarryInfo->hasExplicitSummary())) {
    244         assert (mCarrySummary.size() > 0);
     239        assert (!mCarrySummary.empty());
    245240        Value * ptr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    246241        Value * const value = iBuilder->CreateBitCast(mCarrySummary.back(), mBitBlockType);
     
    281276 * @brief enterScope
    282277 ** ------------------------------------------------------------------------------------------------------------- */
    283 void CarryManager::enterScope(PabloBlock * const scope) {
     278void CarryManager::enterScope(const PabloBlock * const scope) {
    284279    assert (scope);
    285280    // Store the state of the current frame and update the scope state
     
    305300    assert (mCurrentFrameIndex == mCurrentFrame->getType()->getPointerElementType()->getStructNumElements());
    306301    // Sanity test: are there remaining carry frames?
    307     assert (mCarryFrame.size() > 0);
     302    assert (!mCarryFrame.empty());
    308303
    309304    std::tie(mCurrentFrame, mCurrentFrameIndex) = mCarryFrame.back();
     
    393388    // Create a mask to implement circular buffer indexing
    394389    Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);
    395     Value * blockIndex = mKernel->getBlockNo(mSelf);
     390    Value * blockIndex = mKernel->getBlockNo();
    396391    Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(entries));
    397392    Value * loadIndex0 = iBuilder->CreateAnd(carryIndex0, indexMask);
     
    458453 ** ------------------------------------------------------------------------------------------------------------- */
    459454void CarryManager::addToSummary(Value * value) { assert (value);
    460     assert (mIfDepth > 0 && mCarrySummary.size() > 0);
     455    assert (mIfDepth > 0 && !mCarrySummary.empty());
    461456    Value * const summary = mCarrySummary.back(); assert (summary);
    462457    if (LLVM_UNLIKELY(summary == value)) {
     
    609604: iBuilder(idb)
    610605, mKernel(nullptr)
    611 , mSelf(nullptr)
    612 , mFunction(nullptr)
    613606, mBitBlockType(idb->getBitBlockType())
    614607, mBitBlockWidth(idb->getBitBlockWidth())
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5267 r5292  
    4646    void initializeCarryData(PabloKernel * const kernel);
    4747
    48     void initializeCodeGen(llvm::Value * const self, llvm::Function *function);
     48    void initializeCodeGen();
    4949
    5050    /* Entering and leaving loops. */
    5151
    52     void enterLoopScope(PabloBlock * const scope);
     52    void enterLoopScope(const PabloBlock * const scope);
    5353
    5454    void enterLoopBody(llvm::BasicBlock * const entryBlock);
     
    6060    /* Entering and leaving ifs. */
    6161
    62     void enterIfScope(PabloBlock * const scope);
     62    void enterIfScope(const PabloBlock * const scope);
    6363
    6464    void enterIfBody(llvm::BasicBlock * const entryBlock);
     
    8585
    8686    /* Entering and leaving scopes. */
    87     void enterScope(PabloBlock * const scope);
     87    void enterScope(const PabloBlock * const scope);
    8888    void leaveScope();
    8989
     
    103103    PabloKernel *                                   mKernel;
    104104    llvm::Value *                                   mSelf;
    105     llvm::Function *                                mFunction;
    106105    llvm::Type * const                              mBitBlockType;
    107106    const unsigned                                  mBitBlockWidth;
     
    110109    unsigned                                        mCurrentFrameIndex;
    111110
    112     PabloBlock *                                    mCurrentScope;
     111    const PabloBlock *                              mCurrentScope;
    113112    CarryData *                                     mCarryInfo;
    114113
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5285 r5292  
    4848}
    4949   
    50 void PabloCompiler::compile(Function * function, Value * const self, Value * const blockNo) {
    51 
    52     mSelf = self;
    53 
    54     mFunction = function;
    55 
    56     mCarryManager->initializeCodeGen(self, function);
     50void PabloCompiler::compile(Value * const blockNo) {
     51
     52    mCarryManager->initializeCodeGen();
    5753     
    5854    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
     
    6561        Value * input = nullptr;
    6662        if (var->getType()->isSingleValueType()) {
    67             input = mKernel->getScalarFieldPtr(mSelf, name);
     63            input = mKernel->getScalarFieldPtr(name);
    6864        } else {
    69             input = mKernel->getStreamSetPtr(mSelf, name, blockNo);
     65            input = mKernel->getStreamSetPtr(name, blockNo);
    7066        }
    7167        mMarker.emplace(var, input);
     
    7773        Value * output = nullptr;
    7874        if (var->getType()->isSingleValueType()) {
    79             output = mKernel->getScalarFieldPtr(mSelf, name);
     75            output = mKernel->getScalarFieldPtr(name);
    8076        } else {
    81             output = mKernel->getStreamSetPtr(mSelf, name, blockNo);
     77            output = mKernel->getStreamSetPtr(name, blockNo);
    8278        }
    8379        mMarker.emplace(var, output);
     
    134130
    135131    BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
    136     BasicBlock * const ifBodyBlock = BasicBlock::Create(mFunction->getContext(), "if.body", mFunction);
    137     BasicBlock * const ifEndBlock = BasicBlock::Create(mFunction->getContext(), "if.end", mFunction);
     132    BasicBlock * const ifBodyBlock = mKernel->CreateBasicBlock("if.body");
     133    BasicBlock * const ifEndBlock = mKernel->CreateBasicBlock("if.end");
    138134   
    139135    std::vector<std::pair<const Var *, Value *>> incoming;
     
    152148    }
    153149
    154     PabloBlock * ifBody = ifStatement->getBody();
     150    const PabloBlock * ifBody = ifStatement->getBody();
    155151   
    156152    mCarryManager->enterIfScope(ifBody);
     
    222218void PabloCompiler::compileWhile(const While * const whileStatement) {
    223219
    224     PabloBlock * const whileBody = whileStatement->getBody();
    225    
     220    const PabloBlock * const whileBody = whileStatement->getBody();
     221
    226222    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
    227 
    228     BasicBlock * whileBodyBlock = BasicBlock::Create(iBuilder->getContext(), "while.body", mFunction);
    229 
    230     BasicBlock * whileEndBlock = BasicBlock::Create(iBuilder->getContext(), "while.end", mFunction);
     223    BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
     224    BasicBlock * whileEndBlock = mKernel->CreateBasicBlock("while.end");
    231225
    232226    const auto escaped = whileStatement->getEscaped();
     
    432426            value = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    433427        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    434             Value * EOFmask = mKernel->getScalarField(mSelf, "EOFmask");
     428            Value * EOFmask = mKernel->getScalarField("EOFmask");
    435429            value = iBuilder->simd_xor(compileExpression(e->getExpr()), EOFmask);
    436430        } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
    437             Value * EOFbit = mKernel->getScalarField(mSelf, "EOFbit");
     431            Value * EOFbit = mKernel->getScalarField("EOFbit");
    438432            value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
    439433        } else if (const Count * c = dyn_cast<Count>(stmt)) {
     
    444438                llvm::report_fatal_error("Unknown accumulator: " + c->getName().str());
    445439            }
    446             Value * ptr = mKernel->getScalarFieldPtr(mSelf, f->second);
     440            Value * ptr = mKernel->getScalarFieldPtr(f->second);
    447441            Value * count = iBuilder->CreateAlignedLoad(ptr, getPointerElementAlignment(ptr));
    448442            Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
     
    477471            const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    478472            std::string inputName = cast<Var>(var)->getName().str();
    479             Value * blockNo = mKernel->getBlockNo(mSelf);
    480             Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
     473            Value * blockNo = mKernel->getBlockNo();
     474            Value * lookAhead_blockPtr  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    481475            Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    482476            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     
    484478                value = lookAhead;
    485479            } else { // Need to form shift result from two adjacent blocks.
    486                 Value * lookAhead_blockPtr1  = mKernel->getStreamSetPtr(mSelf, inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
     480                Value * lookAhead_blockPtr1  = mKernel->getStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    487481                Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    488482                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
     
    586580: iBuilder(kernel->getBuilder())
    587581, mKernel(kernel)
    588 , mCarryManager(new CarryManager(iBuilder))
    589 , mFunction(nullptr) {
     582, mCarryManager(new CarryManager(iBuilder)) {
    590583
    591584}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5285 r5292  
    3434    ~PabloCompiler();
    3535    void initializeKernelData();
    36     void compile(llvm::Function * function, llvm::Value * const self, llvm::Value * const blockNo);
     36    void compile(llvm::Value * const blockNo);
    3737
    3838private:
     
    5757    PabloKernel * const             mKernel;
    5858    CarryManager * const            mCarryManager;
    59     llvm::Value *                   mSelf;
    60     llvm::Function *                mFunction;
    6159    TranslationMap                  mMarker;
    6260    TranslationMap                  mAccumulator;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5285 r5292  
    1010#include <pablo/pe_zeroes.h>
    1111#include <pablo/pe_ones.h>
    12 #include <llvm/IR/Module.h>
    13 #include <llvm/IR/Verifier.h>
    14 #include <IR_Gen/idisa_builder.h>
    15 #include <llvm/Support/raw_os_ostream.h>
     12//#include <llvm/IR/Module.h>
     13//#include <llvm/IR/Verifier.h>
     14//#include <IR_Gen/idisa_builder.h>
    1615
    1716using namespace pablo;
     
    8887}
    8988
    90 void PabloKernel::generateDoBlockMethod(Function * function, Value  *self, Value * blockNo) const {
    91     mPabloCompiler->compile(function, self, blockNo);
     89void PabloKernel::generateDoBlockMethod(Value * blockNo) {
     90    mPabloCompiler->compile(blockNo);
    9291}
    9392
    94 void PabloKernel::generateFinalBlockMethod(Function * function, Value *self, Value *remainingBytes, Value *blockNo) const {
     93void PabloKernel::generateFinalBlockMethod(Value *remainingBytes, Value * blockNo) {
    9594    // Standard Pablo convention for final block processing: set a bit marking
    9695    // the position just past EOF, as well as a mask marking all positions past EOF.
    97     setScalarField(self, "EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
    98     setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
    99     iBuilder->CreateCall(getDoBlockFunction(), { self });
     96    setScalarField("EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
     97    setScalarField("EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
     98    CreateDoBlockMethodCall();
    10099}
    101100
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5285 r5292  
    116116    void prepareKernel()  override final;
    117117
    118     void generateDoBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * blockNo) const override final;
     118    void generateDoBlockMethod(llvm::Value * blockNo) override final;
    119119
    120120    // The default method for Pablo final block processing sets the
    121121    // EOFmark bit and then calls the standard DoBlock function.
    122122    // This may be overridden for specialized processing.
    123     virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const override final;
     123    virtual void generateFinalBlockMethod(llvm::Value * remainingBytes, llvm::Value * blockNo) override final;
    124124
    125125    inline String * makeName(const llvm::StringRef & prefix) const {
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5267 r5292  
    122122}
    123123
    124 Function * pipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder) {
     124Function * pipeline(Module * m, IDISA::IDISA_Builder * iBuilder) {
    125125    Type * mBitBlockType = iBuilder->getBitBlockType();
    126126    Constant * record_counts_routine;
    127127    Type * const size_ty = iBuilder->getSizeTy();
    128128    Type * const voidTy = iBuilder->getVoidTy();
    129     record_counts_routine = mMod->getOrInsertFunction("record_counts", voidTy, size_ty, size_ty, size_ty, size_ty, size_ty, nullptr);
     129    record_counts_routine = m->getOrInsertFunction("record_counts", voidTy, size_ty, size_ty, size_ty, size_ty, size_ty, nullptr);
    130130    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
    131131   
    132     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, size_ty, nullptr));
     132    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, size_ty, size_ty, nullptr));
    133133    main->setCallingConv(CallingConv::C);
    134134    Function::arg_iterator args = main->arg_begin();
     
    158158    std::unique_ptr<Module> wcM = wck.createKernelModule({&BasisBits}, {});
    159159   
    160     mmapK.addKernelDeclarations(mMod);
    161     s2pk.addKernelDeclarations(mMod);
    162     wck.addKernelDeclarations(mMod);
    163    
    164     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
     160    mmapK.addKernelDeclarations(m);
     161    s2pk.addKernelDeclarations(m);
     162    wck.addKernelDeclarations(m);
     163   
     164    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
    165165
    166166    ByteStream.setStreamSetBuffer(inputStream, fileSize);
     
    177177    iBuilder->CreateRetVoid();
    178178   
    179     Linker L(*mMod);
     179    Linker L(*m);
    180180    L.linkInModule(std::move(mmapM));
    181181    L.linkInModule(std::move(s2pM));
Note: See TracChangeset for help on using the changeset viewer.