Ignore:
Timestamp:
Jan 14, 2017, 3:49:56 PM (2 years ago)
Author:
nmedfort
Message:

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

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

Legend:

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

    r5246 r5260  
    88#include <cc/cc_compiler.h>
    99#include <pablo/builder.hpp>
     10#include <llvm/IR/Module.h>
    1011
    1112using namespace cc;
     
    2526    Value * blockNo = getScalarField(self, blockNoScalar);
    2627   
    27     Value * codeUnitStreamBlock_ptr = getStreamSetBlockPtr(self, "codeUnitStream", blockNo);
    28     Value * ccStreamBlock_ptr = getStreamSetBlockPtr(self, "ccStream", blockNo);
    29 
    3028    unsigned packCount = 8 * mCodeUnitSize; 
    3129    unsigned codeUnitWidth = 8 * mCodeUnitSize;
    3230    Value * codeUnitPack[packCount];
    3331    for (unsigned i = 0; i < packCount; i++) {
    34         codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(codeUnitStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     32        Value * ptr = getStream(self, "codeUnitStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     33        codeUnitPack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    3534    }
    3635
    37     std::vector<Value *> ccStreams;
    3836    for (unsigned j = 0; j < mCharClasses.size();  j++) {
    3937        Value * theCCstream = iBuilder->allZeroes();
     
    6866            theCCstream = iBuilder->simd_or(theCCstream, pack);
    6967        }
    70         iBuilder->CreateBlockAlignedStore(theCCstream, ccStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     68        Value * ptr = getStream(self, "ccStream", blockNo, iBuilder->getInt32(j));
     69        iBuilder->CreateBlockAlignedStore(theCCstream, ptr);
    7170    }
    7271 
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r5247 r5260  
    44 */
    55
    6 #include <kernels/kernel.h>
    7 #include <kernels/deletion.h>
     6#include "deletion.h"
    87#include <IR_Gen/idisa_builder.h>
    98#include <llvm/IR/Value.h>
     9#include <llvm/IR/Module.h>
    1010
    11 std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * del_mask) {
     11using namespace llvm;
     12
     13namespace kernel {
     14
     15inline std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask) {
    1216    Value * m = iBuilder->simd_not(del_mask);
    1317    Value * mk = iBuilder->simd_slli(fw, del_mask, 1);
     
    2630}
    2731
    28 Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * del_mask, std::vector<Value *> mv, Value * strm) {
     32inline Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask, const std::vector<Value *> & mv, Value * strm) {
    2933    Value * s = iBuilder->simd_and(strm, iBuilder->simd_not(del_mask));
    3034    for (unsigned i = 0; i < mv.size(); i++) {
     
    3640}
    3741
    38 Value * partial_sum_popcount(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * mask) {
    39     Value * per_field = iBuilder->simd_popcount(fw, mask);
    40     for (unsigned move = 1; move < iBuilder->getBitBlockWidth()/fw; move *= 2) {
    41         per_field = iBuilder->simd_add(fw, per_field, iBuilder->mvmd_slli(fw, per_field, move));
     42inline Value * partial_sum_popcount(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * mask) {
     43    Value * field = iBuilder->simd_popcount(fw, mask);
     44    const auto count = iBuilder->getBitBlockWidth() / fw;
     45    for (unsigned move = 1; move < count; move *= 2) {
     46        field = iBuilder->simd_add(fw, field, iBuilder->mvmd_slli(fw, field, move));
    4247    }
    43     return per_field;
     48    return field;
    4449}
    4550
     
    4853// Outputs: the deleted streams, plus a partial sum popcount
    4954
    50 namespace kernel {
     55void DeletionKernel::generateDoBlockMethod() const {
    5156
    52 void DeletionKernel::generateDoBlockMethod() const {
    5357    auto savePoint = iBuilder->saveIP();
    5458    Module * m = iBuilder->getModule();
     
    6266    Value * blockNo = getScalarField(self, blockNoScalar);
    6367
    64     Value * inputStreamPtr = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
    65 
    66     Value * delMaskPtr = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
    67 
    68     Value * outputStreamPtr = getStreamSetBlockPtr(self, "outputStreamSet", blockNo);
    69 
    70     Value * delCountPtr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    71 
    72     Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     68    Value * delMaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
     69    Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr);
    7370
    7471    std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, delMask);
    7572
    7673    for (unsigned j = 0; j < mStreamCount; ++j) {
    77         Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     74        Value * inputStreamPtr = getStream(self, "inputStreamSet", blockNo, iBuilder->getInt32(j));
     75        Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr);
     76
    7877        Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, delMask, move_masks, input);
    79         iBuilder->CreateBlockAlignedStore(output, outputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     78
     79        Value * outputStreamPtr = getStream(self, "outputStreamSet", blockNo, iBuilder->getInt32(j));
     80        iBuilder->CreateBlockAlignedStore(output, outputStreamPtr);
    8081    }
    81     Value * counts = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
    82     iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(counts), delCountPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     82    Value * delCount = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
     83    Value * delCountPtr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     84    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(delCount), delCountPtr);
    8385    /* Stream deletion has only been applied within fields; the actual number of data items
    8486     * has not yet changed.   */
     
    103105    Value * self = getParameter(finalBlockFunction, "self");
    104106    Value * blockNo = getScalarField(self, blockNoScalar);
    105     Value * delMaskBlock = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
    106107    Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(blockSize));
    107108    Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(blockSize)), remaining));
    108     Value * const delmaskPtr = iBuilder->CreateGEP(delMaskBlock, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     109    Value * const delmaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
    109110    Value * const delmaskVal = iBuilder->CreateBlockAlignedLoad(delmaskPtr);
    110111    iBuilder->CreateBlockAlignedStore(iBuilder->CreateOr(EOF_del, delmaskVal), delmaskPtr);
     
    121122}
    122123
     124DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
     125KernelBuilder(iBuilder, "del",
     126              {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
     127               Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     128              {Binding{iBuilder->getStreamSetTy(streamCount), "outputStreamSet"},
     129               Binding{iBuilder->getStreamSetTy(), "deletionCounts"}},
     130              {}, {}, {}),
     131mDeletionFieldWidth(fw),
     132mStreamCount(streamCount) {
     133
    123134}
     135
     136}
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5246 r5260  
    2525// algorithm.
    2626//
    27 // Deletion Mask Calculation
    28 
    29 std::vector<llvm::Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, unsigned fw, llvm::Value * del_mask);
    30 
    31 // Applying Deletion Masks to a Stream
    32 
    33 llvm::Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, unsigned fw, llvm::Value * del_mask, std::vector<llvm::Value *> mv, llvm::Value * strm);
    3427
    3528using namespace parabix;
     
    3932class DeletionKernel : public kernel::KernelBuilder {
    4033public:
    41     DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
    42     KernelBuilder(iBuilder, "del",
    43                   {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
    44                    Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
    45                   {Binding{iBuilder->getStreamSetTy(streamCount), "outputStreamSet"},
    46                    Binding{iBuilder->getStreamSetTy(), "deletionCounts"}},
    47                   {}, {}, {}),
    48     mDeletionFieldWidth(fw),
    49     mStreamCount(streamCount) {}
     34
     35    DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount);
    5036   
     37protected:
     38
     39    void generateDoBlockMethod() const override;
     40
     41    void generateFinalBlockMethod() const override;
     42
    5143private:
    52     void generateDoBlockMethod() const override;
    53     void generateFinalBlockMethod() const override;
    5444    unsigned mDeletionFieldWidth;
    5545    unsigned mStreamCount;
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5257 r5260  
    55
    66#include "interface.h"
     7#include <llvm/IR/Value.h>         // for Value
     8#include <llvm/IR/CallingConv.h>   // for ::C
     9#include <llvm/IR/DerivedTypes.h>  // for FunctionType (ptr only), PointerType
     10#include <llvm/IR/Function.h>      // for Function, Function::arg_iterator
    711#include <llvm/IR/Module.h>
    8 #include <llvm/IR/Type.h>
    9 #include <llvm/IR/Value.h>
    10 #include <llvm/Support/raw_ostream.h>
     12#include <IR_Gen/idisa_builder.h>
     13namespace llvm { class Module; }
     14namespace llvm { class Type; }
    1115
    1216using namespace llvm;
    13 using namespace parabix;
    1417
    1518void KernelInterface::addKernelDeclarations(Module * client) {
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5257 r5260  
    77#define KERNEL_INTERFACE_H
    88
    9 #include <string>
    10 #include <vector>
    11 #include <llvm/IR/Type.h>
    12 #include <IR_Gen/idisa_builder.h>
    13 #include <kernels/streamset.h>
     9#include <string>  // for string
     10#include <vector>  // for vector
     11namespace IDISA { class IDISA_Builder; }
     12namespace llvm { class Module; }
     13namespace llvm { class StructType; }
     14namespace llvm { class Type; }
     15namespace llvm { class Value; }
    1416
    1517struct Binding {
     
    4850   
    4951    // Add ExternalLinkage method declarations for the kernel to a given client module.
    50     void addKernelDeclarations(Module * client);
     52    void addKernelDeclarations(llvm::Module * client);
    5153    virtual void createInstance() = 0;
    52     void setInitialArguments(std::vector<Value *> initialParameters);
     54    void setInitialArguments(std::vector<llvm::Value *> args);
    5355    llvm::Value * getInstance() const { return mKernelInstance; }
    5456
     
    100102    IDISA::IDISA_Builder * const iBuilder;
    101103    std::string mKernelName;
    102     std::vector<Value *> mInitialArguments;
     104    std::vector<llvm::Value *> mInitialArguments;
    103105    std::vector<Binding> mStreamSetInputs;
    104106    std::vector<Binding> mStreamSetOutputs;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5257 r5260  
    55
    66#include "kernel.h"
    7 #include <llvm/IR/Module.h>
    8 #include <llvm/IR/Type.h>
    9 #include <llvm/IR/Value.h>
    10 #include <llvm/Support/raw_ostream.h>
    11 #include <llvm/Support/ErrorHandling.h>
    12 #include <toolchain.h>
     7#include <llvm/IR/Value.h>               // for Value
     8#include <llvm/Support/ErrorHandling.h>  // for report_fatal_error
     9#include <toolchain.h>                   // for BufferSegments, SegmentSize
     10#include "IR_Gen/idisa_builder.h"        // for IDISA_Builder
     11#include "kernels/streamset.h"           // for StreamSetBuffer
     12#include "llvm/ADT/StringRef.h"          // for StringRef, operator==
     13#include "llvm/IR/CallingConv.h"         // for ::C
     14#include "llvm/IR/Constant.h"            // for Constant
     15#include "llvm/IR/Constants.h"           // for ConstantInt
     16#include "llvm/IR/Function.h"            // for Function, Function::arg_iter...
     17#include "llvm/IR/Instructions.h"        // for LoadInst (ptr only), PHINode
     18#include "llvm/Support/Compiler.h"       // for LLVM_UNLIKELY
     19namespace llvm { class BasicBlock; }
     20namespace llvm { class Module; }
     21namespace llvm { class Type; }
    1322
    1423using namespace llvm;
    1524using namespace kernel;
     25using namespace parabix;
    1626
    1727KernelBuilder::KernelBuilder(IDISA::IDISA_Builder * builder,
     
    213223    Value * processed = getProcessedItemCount(self, mStreamSetInputs[0].name);
    214224    Value * itemsAvail = iBuilder->CreateSub(availablePos, processed);
    215 #ifndef NDEBUG
    216     iBuilder->CallPrintInt(mKernelName + "_itemsAvail", itemsAvail);
    217 #endif
     225//#ifndef NDEBUG
     226//    iBuilder->CallPrintInt(mKernelName + "_itemsAvail", itemsAvail);
     227//#endif
    218228    Value * stridesToDo = iBuilder->CreateUDiv(blocksToDo, strideBlocks);
    219229    Value * stridesAvail = iBuilder->CreateUDiv(itemsAvail, stride);
     
    243253    iBuilder->CreateBr(segmentDone);
    244254    iBuilder->SetInsertPoint(segmentDone);
    245 #ifndef NDEBUG
    246     iBuilder->CallPrintInt(mKernelName + "_processed", processed);
    247 #endif
     255//#ifndef NDEBUG
     256//    iBuilder->CallPrintInt(mKernelName + "_processed", processed);
     257//#endif
    248258    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    249259        Value * produced = getProducedItemCount(self, mStreamSetOutputs[i].name);
     
    293303    Value * processed = getProcessedItemCount(self, mStreamSetInputs[0].name);
    294304    Value * itemsAvail = iBuilder->CreateSub(availablePos, processed);
    295 #ifndef NDEBUG
    296     iBuilder->CallPrintInt(mKernelName + "_itemsAvail final", itemsAvail);
    297 #endif
     305//#ifndef NDEBUG
     306//    iBuilder->CallPrintInt(mKernelName + "_itemsAvail final", itemsAvail);
     307//#endif
    298308    Value * stridesToDo = iBuilder->CreateUDiv(blocksToDo, strideBlocks);
    299309    Value * stridesAvail = iBuilder->CreateUDiv(itemsAvail, stride);
     
    317327    createFinalBlockCall(self, remainingItems);
    318328    processed = iBuilder->CreateAdd(processed, remainingItems);
    319     setProcessedItemCount(self, mStreamSetInputs[0].name, processed);
    320        
    321 #ifndef NDEBUG
    322     iBuilder->CallPrintInt(mKernelName + "_processed final", processed);
    323 #endif
     329    setProcessedItemCount(self, mStreamSetInputs[0].name, processed);       
     330//#ifndef NDEBUG
     331//    iBuilder->CallPrintInt(mKernelName + "_processed final", processed);
     332//#endif
    324333    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    325334        Value * produced = getProducedItemCount(self, mStreamSetOutputs[i].name);
     
    402411}
    403412
    404 void KernelBuilder::setBlockNo(Value * self, Value * newFieldVal) const {
     413void KernelBuilder::setBlockNo(Value * self, Value * value) const {
    405414    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(blockNoScalar)});
    406     iBuilder->CreateStore(newFieldVal, ptr);
     415    iBuilder->CreateStore(value, ptr);
    407416}
    408417
     
    424433}
    425434
    426 size_t KernelBuilder::getStreamSetBufferSize(Value * /* self */, const std::string & name) const {
    427     const unsigned index = getStreamSetIndex(name);
    428     StreamSetBuffer * buf = nullptr;
    429     if (index < mStreamSetInputs.size()) {
    430         buf = mStreamSetInputBuffers[index];
    431     } else {
    432         buf = mStreamSetOutputBuffers[index - mStreamSetInputs.size()];
    433     }
    434     return buf->getBufferSize();
    435 }
    436 
    437435Value * KernelBuilder::getStreamSetStructPtr(Value * self, const std::string & name) const {
    438436    return getScalarField(self, name + structPtrSuffix);
    439437}
    440438
    441 Value * KernelBuilder::getStreamSetBlockPtr(Value * self, const std::string &name, Value * blockNo) const {
    442     Value * const structPtr = getStreamSetStructPtr(self, name);
    443     const unsigned index = getStreamSetIndex(name);
    444     StreamSetBuffer * buf = nullptr;
    445     if (index < mStreamSetInputs.size()) {
    446         buf = mStreamSetInputBuffers[index];
     439inline const StreamSetBuffer * KernelBuilder::getStreamSetBuffer(const std::string & name) const {
     440    const unsigned structIdx = getStreamSetIndex(name);
     441    if (structIdx < mStreamSetInputs.size()) {
     442        return mStreamSetInputBuffers[structIdx];
    447443    } else {
    448         buf = mStreamSetOutputBuffers[index - mStreamSetInputs.size()];
    449     }   
    450     return buf->getStreamSetBlockPointer(structPtr, blockNo);
    451 }
    452 
    453 Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index) {
    454     return iBuilder->CreateGEP(getStreamSetBlockPtr(self, name, blockNo), {iBuilder->getInt32(0), index});
     444        return mStreamSetOutputBuffers[structIdx - mStreamSetInputs.size()];
     445    }
     446}
     447
     448Value * KernelBuilder::getStreamSetPtr(Value * self, const std::string & name, Value * blockNo) const {
     449    return getStreamSetBuffer(name)->getStreamSetPtr(getStreamSetStructPtr(self, name), blockNo);
     450}
     451
     452Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index) const {
     453    return getStreamSetBuffer(name)->getStream(getStreamSetStructPtr(self, name), blockNo, index);
     454}
     455
     456Value * KernelBuilder::getStream(Value * self, const std::string & name, Value * blockNo, Value * index1, Value * index2) const {
     457    assert (index1->getType() == index2->getType());
     458    return getStreamSetBuffer(name)->getStream(getStreamSetStructPtr(self, name), blockNo, index1, index2);
     459}
     460
     461Value * KernelBuilder::getStreamView(Value * self, const std::string & name, Value * blockNo, Value * index) const {
     462    return getStreamSetBuffer(name)->getStreamView(getStreamSetStructPtr(self, name), blockNo, index);
     463}
     464
     465Value * KernelBuilder::getStreamView(llvm::Type * type, Value * self, const std::string & name, Value * blockNo, Value * index) const {
     466    return getStreamSetBuffer(name)->getStreamView(type, getStreamSetStructPtr(self, name), blockNo, index);
    455467}
    456468
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5257 r5260  
    77#define KERNEL_BUILDER_H
    88
    9 #include "streamset.h"
    10 #include "interface.h"
    11 #include <vector>
    12 #include <llvm/IR/Type.h>
     9#include <string>           // for string
     10#include <memory>           // for unique_ptr
     11#include "interface.h"      // for KernelInterface
     12#include <boost/container/flat_map.hpp>
    1313#include <IR_Gen/idisa_builder.h>
    14 #include <boost/container/flat_map.hpp>
     14namespace llvm { class ConstantInt; }
     15namespace llvm { class Function; }
     16namespace llvm { class IntegerType; }
     17namespace llvm { class LoadInst; }
     18namespace llvm { class Type; }
     19namespace llvm { class Value; }
     20namespace parabix { class StreamSetBuffer; }
    1521
    1622const std::string blockNoScalar = "blockNo";
     
    2228const std::string blkMaskSuffix = "_blkMask";
    2329
    24 using namespace parabix;
    2530namespace kernel {
    2631   
     
    3237    // the full implementation of all required methods.     
    3338    //
    34     std::unique_ptr<Module> createKernelModule(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
     39    std::unique_ptr<llvm::Module> createKernelModule(const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    3540   
    3641    // Generate the Kernel to the current module (iBuilder->getModule()).
    37     void generateKernel(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
     42    void generateKernel(const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    3843   
    3944    void createInstance() override;
    4045
    41     Function * generateThreadFunction(const std::string & name) const;
     46    llvm::Function * generateThreadFunction(const std::string & name) const;
    4247
    43     Value * getBlockNo(Value * self) const;
    44     virtual Value * getProcessedItemCount(Value * self, const std::string & ssName) const override;
    45     virtual Value * getProducedItemCount(Value * self, const std::string & ssName) const override;
     48    llvm::Value * getBlockNo(llvm::Value * self) const;
     49    virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const override;
     50    virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const override;
    4651   
    4752    bool hasNoTerminateAttribute() { return mNoTerminateAttribute;}
    4853   
    49     Value * getTerminationSignal(Value * self) const override;
     54    llvm::Value * getTerminationSignal(llvm::Value * self) const override;
    5055   
    51     inline IntegerType * getSizeTy() const {
     56    inline llvm::IntegerType * getSizeTy() const {
    5257        return getBuilder()->getSizeTy();
    5358    }
    5459
    55     inline Type * getStreamTy(const unsigned FieldWidth = 1) {
     60    inline llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
    5661        return getBuilder()->getStreamTy(FieldWidth);
    5762    }
    5863   
    59     inline Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
     64    inline llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    6065        return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    6166    }
     
    7075    // data has been extracted from the kernel for further pipeline processing, the
    7176    // segment number must be incremented and stored using releaseLogicalSegmentNo.
    72     LoadInst * acquireLogicalSegmentNo(Value * self) const;
     77    llvm::LoadInst * acquireLogicalSegmentNo(llvm::Value * self) const;
    7378
    74     void releaseLogicalSegmentNo(Value * self, Value * newFieldVal) const;
     79    void releaseLogicalSegmentNo(llvm::Value * self, llvm::Value * newFieldVal) const;
    7580
    7681    virtual ~KernelBuilder() = 0;
    7782   
    78     std::vector<StreamSetBuffer *> getStreamSetInputBuffers() {return mStreamSetInputBuffers;}
    79     std::vector<StreamSetBuffer *> getStreamSetOutputBuffers() {return mStreamSetOutputBuffers;}
     83    const std::vector<const parabix::StreamSetBuffer *> & getStreamSetInputBuffers() const { return mStreamSetInputBuffers; }
     84
     85    const std::vector<const parabix::StreamSetBuffer *> & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
    8086
    8187
     
    110116    virtual void generateDoBlockMethod() const = 0;
    111117
    112     virtual void generateDoBlockLogic(Value * self, Value * blockNo) const;
     118    virtual void generateDoBlockLogic(llvm::Value * self, llvm::Value * blockNo) const;
    113119
    114120    // Each kernel builder subtypre must also specify the logic for processing the
     
    129135    // Add an additional scalar field to the KernelState struct.
    130136    // Must occur before any call to addKernelDeclarations or createKernelModule.
    131     unsigned addScalar(Type * type, const std::string & name);
     137    unsigned addScalar(llvm::Type * type, const std::string & name);
    132138
    133139    unsigned getScalarCount() const;
     
    137143   
    138144    // Get the index of a named scalar field within the kernel state struct.
    139     ConstantInt * getScalarIndex(const std::string & name) const;
     145    llvm::ConstantInt * getScalarIndex(const std::string & name) const;
    140146   
    141147    // Get the value of a scalar field for a given instance.
    142     Value * getScalarField(Value * self, const std::string & fieldName) const;
     148    llvm::Value * getScalarField(llvm::Value * self, const std::string & fieldName) const;
    143149
    144150    // Set the value of a scalar field for a given instance.
    145     void setScalarField(Value * self, const std::string & fieldName, Value * newFieldVal) const;
     151    void setScalarField(llvm::Value * self, const std::string & fieldName, llvm::Value * newFieldVal) const;
    146152   
    147153    // Get a parameter by name.
    148     Value * getParameter(Function * f, const std::string & paramName) const;
     154    llvm::Value * getParameter(llvm::Function * f, const std::string & paramName) const;
    149155
    150     Value * getStream(Value * self, const std::string & name, Value * blockNo, const unsigned index) {
    151         return getStream(self, name, blockNo, iBuilder->getInt32(index));
    152     }
     156    llvm::Value * getStream(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
    153157
    154     Value * getStream(Value * self, const std::string & name, Value * blockNo, Value * index);
    155    
     158    llvm::Value * getStream(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
     159
     160    llvm::Value * getStreamView(llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
     161
     162    llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
     163
    156164    // Stream set helpers.
    157165    unsigned getStreamSetIndex(const std::string & name) const;
    158166   
    159     Value * getScalarFieldPtr(Value * self, const std::string & name) const;
     167    llvm::Value * getScalarFieldPtr(llvm::Value * self, const std::string & name) const;
    160168
    161     Value * getStreamSetStructPtr(Value * self, const std::string & name) const;
     169    llvm::Value * getStreamSetStructPtr(llvm::Value * self, const std::string & name) const;
    162170
    163     size_t getStreamSetBufferSize(Value * self, const std::string & name) const;
     171    llvm::Value * getStreamSetPtr(llvm::Value * self, const std::string & name, llvm::Value * blockNo) const;
     172   
     173    void setBlockNo(llvm::Value * self, llvm::Value * value) const;
    164174
    165     Value * getStreamSetBlockPtr(Value * self, const std::string & name, Value * blockNo) const;
    166    
    167     void setBlockNo(Value * self, Value * newFieldVal) const;
     175    virtual void setProcessedItemCount(llvm::Value * self, const std::string & ssName, llvm::Value * newFieldVal) const;
    168176
    169     virtual void setProcessedItemCount(Value * self, const std::string & ssName, Value * newFieldVal) const;
     177    virtual void setProducedItemCount(llvm::Value * self, const std::string & ssName, llvm::Value * newFieldVal) const;
    170178
    171     virtual void setProducedItemCount(Value * self, const std::string & ssName, Value * newFieldVal) const;
     179    void setTerminationSignal(llvm::Value * self) const;
    172180
    173     void setTerminationSignal(Value * self) const;
     181private:
     182
     183    const parabix::StreamSetBuffer * getStreamSetBuffer(const std::string & name) const;
    174184
    175185protected:
    176186
    177     std::vector<Type *>             mKernelFields;
    178     NameMap                         mKernelMap;
    179     NameMap                         mStreamSetNameMap;
    180     std::vector<StreamSetBuffer *>  mStreamSetInputBuffers;
    181     std::vector<StreamSetBuffer *>  mStreamSetOutputBuffers;
    182     bool                            mNoTerminateAttribute;
     187    std::vector<llvm::Type *>                       mKernelFields;
     188    NameMap                                         mKernelMap;
     189    NameMap                                         mStreamSetNameMap;
     190    std::vector<const parabix::StreamSetBuffer *>   mStreamSetInputBuffers;
     191    std::vector<const parabix::StreamSetBuffer *>   mStreamSetOutputBuffers;
     192    bool                                            mNoTerminateAttribute;
    183193
    184194};
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5259 r5260  
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 */
    5 #include <kernels/mmap_kernel.h>
     5#include "mmap_kernel.h"
     6#include <llvm/IR/Function.h>  // for Function, Function::arg_iterator
     7#include <llvm/IR/Module.h>
    68#include <IR_Gen/idisa_builder.h>
     9#include <kernels/streamset.h>
     10namespace llvm { class BasicBlock; }
     11namespace llvm { class Constant; }
     12namespace llvm { class Module; }
     13namespace llvm { class Value; }
     14
     15using namespace llvm;
    716
    817namespace kernel {
     
    7685    iBuilder->restoreIP(savePoint);
    7786}
    78    
     87
     88MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth) :
     89KernelBuilder(iBuilder, "mmap_source",
     90              {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
     91              {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
     92, mSegmentBlocks(blocksPerSegment)
     93, mCodeUnitWidth(codeUnitWidth) {
     94
    7995}
     96
     97}
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.h

    r5257 r5260  
    66#define MMAP_KERNEL_H
    77
    8 #include "streamset.h"
    98#include "kernel.h"
    10 #include <llvm/IR/Type.h>
    11 
    129namespace IDISA { class IDISA_Builder; }
    1310
     
    2017class MMapSourceKernel : public KernelBuilder {
    2118public:
    22     MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8) :
    23     KernelBuilder(iBuilder, "mmap_source",
    24                   {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
    25                   {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {}),
    26     mSegmentBlocks(blocksPerSegment),
    27     mCodeUnitWidth(codeUnitWidth) {}
     19    MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    2820   
    2921private:
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5247 r5260  
    33#include "IR_Gen/idisa_builder.h"
    44#include <llvm/IR/Type.h>
     5#include <llvm/IR/Module.h>
    56#include <iostream>
    67#include <stdint.h>
     
    89#include <llvm/Support/raw_ostream.h>
    910
    10 
     11using namespace llvm;
    1112
    1213namespace kernel{
     
    4041}
    4142               
    42 void p2sKernel::generateDoBlockMethod() const {
     43void P2SKernel::generateDoBlockMethod() const {
    4344    auto savePoint = iBuilder->saveIP();
    4445    Module * m = iBuilder->getModule();
     
    5051    Value * self = getParameter(doBlockFunction, "self");
    5152    Value * blockNo = getScalarField(self, blockNoScalar);
    52     Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    53     Value * byteStreamBlock_ptr = getStreamSetBlockPtr(self, "byteStream", blockNo);
    54 
    5553    Value * p_bitblock[8];
    5654    for (unsigned i = 0; i < 8; i++) {
    57         p_bitblock[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     55        Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     56        p_bitblock[i] = iBuilder->CreateBlockAlignedLoad(ptr);
    5857    }
    5958    Value * s_bytepack[8];
    6059    p2s(iBuilder, p_bitblock, s_bytepack);
    6160    for (unsigned j = 0; j < 8; ++j) {
    62         iBuilder->CreateBlockAlignedStore(s_bytepack[j], byteStreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(j)});
    63     }
    64     iBuilder->CreateRetVoid();
    65     iBuilder->restoreIP(savePoint);
    66 }
    67        
    68 void p2sKernel_withCompressedOutput::generateDoBlockMethod() const {
    69     auto savePoint = iBuilder->saveIP();
    70     Module * m = iBuilder->getModule();
    71     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    72     Type * i32 = iBuilder->getIntNTy(32);
    73     Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
    74    
    75     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    76    
     61        Value * ptr = getStream(self, "byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
     62        iBuilder->CreateBlockAlignedStore(s_bytepack[j], ptr);
     63    }
     64    iBuilder->CreateRetVoid();
     65    iBuilder->restoreIP(savePoint);
     66}
     67
     68void P2SKernelWithCompressedOutput::generateDoBlockMethod() const {
     69    auto savePoint = iBuilder->saveIP();
     70    Module * m = iBuilder->getModule();
     71    Type * i8PtrTy = iBuilder->getInt8PtrTy();
     72    Type * i32 = iBuilder->getIntNTy(32);
     73    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
     74
     75    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     76
    7777    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    7878    Value * self = getParameter(doBlockFunction, "self");
    7979    Value * blockNo = getScalarField(self, blockNoScalar);
    80     Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    81     Value * delCountBlock_ptr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    82     Value * byteStreamBlock_ptr = getStreamSetBlockPtr(self, "byteStream", blockNo);
    83    
     80
     81
     82
    8483    Value * basisBits[8];
    8584    for (unsigned i = 0; i < 8; i++) {
    86         basisBits[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     85        Value * basisBitsBlock_ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     86        basisBits[i] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr);
    8787    }
    8888    Value * bytePack[8];
    8989    p2s(iBuilder, basisBits, bytePack);
    90    
     90
    9191    unsigned units_per_register = iBuilder->getBitBlockWidth()/8;
    92    
    93     Value * unit_counts = iBuilder->fwCast(units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    94    
    95     Value * output_ptr = iBuilder->CreateBitCast(byteStreamBlock_ptr, i8PtrTy);
    96     Value * offset = ConstantInt::get(i32, 0);
    97    
     92    Value * delCountBlock_ptr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     93    Value * unit_counts = iBuilder->fwCast(units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
     94
     95    Value * output_ptr = getStreamView(i8PtrTy, self, "byteStream", blockNo, iBuilder->getInt32(0));
     96    Value * offset = iBuilder->getInt32(0);
    9897    for (unsigned j = 0; j < 8; ++j) {
    9998        iBuilder->CreateAlignedStore(bytePack[j], iBuilder->CreateBitCast(iBuilder->CreateGEP(output_ptr, offset), bitBlockPtrTy), 1);
     
    104103}
    105104
    106 void p2s_16Kernel::generateDoBlockMethod() const {
    107     auto savePoint = iBuilder->saveIP();
    108     Module * m = iBuilder->getModule();
    109    
    110     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    111    
    112     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    113     Value * self = getParameter(doBlockFunction, "self");
    114     Value * blockNo = getScalarField(self, blockNoScalar);
    115     Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    116     Value * i16StreamBlock_ptr = getStreamSetBlockPtr(self, "i16Stream", blockNo);
     105void P2S16Kernel::generateDoBlockMethod() const {
     106    auto savePoint = iBuilder->saveIP();
     107    Module * m = iBuilder->getModule();
     108   
     109    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     110   
     111    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
     112    Value * self = getParameter(doBlockFunction, "self");
     113    Value * blockNo = getScalarField(self, blockNoScalar);   
    117114   
    118115    Value * hi_input[8];
    119116    for (unsigned j = 0; j < 8; ++j) {
    120         hi_input[j] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(j)});
     117        Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j));
     118        hi_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    121119    }
    122120    Value * hi_bytes[8];
     
    125123    Value * lo_input[8];
    126124    for (unsigned j = 0; j < 8; ++j) {
    127         lo_input[j] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(j+8)});
     125        Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(j + 8));
     126        lo_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
    128127    }
    129128    Value * lo_bytes[8];
     
    133132        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    134133        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    135         // iBuilder->getInt32(0),
    136         iBuilder->CreateBlockAlignedStore(merge0, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2*j)});
    137         iBuilder->CreateBlockAlignedStore(merge1, i16StreamBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2*j+1)});
    138     }
    139     iBuilder->CreateRetVoid();
    140     iBuilder->restoreIP(savePoint);
    141 }
    142 
    143 void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() const {
     134        Value * ptr0 = getStream(self, "i16Stream", blockNo, iBuilder->getInt32(2 * j));
     135        iBuilder->CreateBlockAlignedStore(merge0, ptr0);
     136        Value * ptr1 = getStream(self, "i16Stream", blockNo, iBuilder->getInt32(2 * j + 1));
     137        iBuilder->CreateBlockAlignedStore(merge1, ptr1);
     138    }
     139    iBuilder->CreateRetVoid();
     140    iBuilder->restoreIP(savePoint);
     141}
     142
     143void P2S16KernelWithCompressedOutput::generateDoBlockMethod() const {
    144144    auto savePoint = iBuilder->saveIP();
    145145    Module * m = iBuilder->getModule();
     
    150150
    151151    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
    152     Constant * stride = iBuilder->getSize(iBuilder->getStride());
    153152
    154153    Value * self = getParameter(doBlockFunction, "self");
    155154    Value * blockNo = getScalarField(self, blockNoScalar);
    156     Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    157     Value * delCountBlock_ptr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
     155
     156    Value * hi_input[8];
     157    for (unsigned j = 0; j < 8; ++j) {
     158        Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(j));
     159        hi_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
     160    }
     161    Value * hi_bytes[8];
     162    p2s(iBuilder, hi_input, hi_bytes);
     163
     164    Value * lo_input[8];
     165    for (unsigned j = 0; j < 8; ++j) {
     166        Value * ptr = getStream(self, "basisBits", blockNo, iBuilder->getInt32(j + 8));
     167        lo_input[j] = iBuilder->CreateBlockAlignedLoad(ptr);
     168    }
     169    Value * lo_bytes[8];
     170    p2s(iBuilder, lo_input, lo_bytes);
     171
     172    Value * delCountBlock_ptr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     173    Value * unit_counts = iBuilder->fwCast(iBuilder->getBitBlockWidth() / 16, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr));
     174
     175    PointerType * int16PtrTy = PointerType::get(iBuilder->getInt16Ty(), 0);
     176    ConstantInt * stride = iBuilder->getSize(iBuilder->getStride());
    158177    Value * i16UnitsGenerated = getProducedItemCount(self, "i16Stream"); // units generated to buffer
    159178    Value * i16BlockNo = iBuilder->CreateUDiv(i16UnitsGenerated, stride);
    160 
    161     Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBlockPtr(self, "i16Stream", i16BlockNo), PointerType::get(iBuilder->getInt16Ty(), 0));
    162 
    163     Value * u16_output_ptr = iBuilder->CreateGEP(i16StreamBase_ptr, iBuilder->CreateURem(i16UnitsGenerated, stride));
    164 
    165 
    166     Value * hi_input[8];
    167     for (unsigned j = 0; j < 8; ++j) {
    168         hi_input[j] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    169     }
    170     Value * hi_bytes[8];
    171     p2s(iBuilder, hi_input, hi_bytes);
    172 
    173     Value * lo_input[8];
    174     for (unsigned j = 0; j < 8; ++j) {
    175         lo_input[j] = iBuilder->CreateBlockAlignedLoad(basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j+8)});
    176     }
    177     Value * lo_bytes[8];
    178     p2s(iBuilder, lo_input, lo_bytes);
    179 
    180     const auto UTF_16_units_per_register = iBuilder->getBitBlockWidth() / 16;
    181 
    182     Value * unit_counts = iBuilder->fwCast(UTF_16_units_per_register, iBuilder->CreateBlockAlignedLoad(delCountBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0)}));
    183 
     179    Value * u16_output_ptr = getStreamView(int16PtrTy, self, "i16Stream", i16BlockNo, iBuilder->CreateURem(i16UnitsGenerated, stride));
    184180    Value * offset = ConstantInt::get(i32, 0);
    185 
    186181    for (unsigned j = 0; j < 8; ++j) {
    187182        Value * merge0 = iBuilder->bitCast(iBuilder->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
    188183        Value * merge1 = iBuilder->bitCast(iBuilder->esimd_mergeh(8, hi_bytes[j], lo_bytes[j]));
    189184        iBuilder->CreateAlignedStore(merge0, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    190         offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j)), i32);
     185        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2 * j)), i32);
    191186        iBuilder->CreateAlignedStore(merge1, iBuilder->CreateBitCast(iBuilder->CreateGEP(u16_output_ptr, offset), bitBlockPtrTy), 1);
    192         offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2*j+1)), i32);
    193     }
    194 
     187        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(2 * j + 1)), i32);
     188    }
    195189    i16UnitsGenerated = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    196190    setProducedItemCount(self, "i16Stream", i16UnitsGenerated);
     
    199193}
    200194
    201 void p2s_16Kernel_withCompressedOutput::generateFinalBlockMethod() const {
     195void P2S16KernelWithCompressedOutput::generateFinalBlockMethod() const {
    202196    auto savePoint = iBuilder->saveIP();
    203197    Module * m = iBuilder->getModule();
     
    214208    }
    215209    Value * i16UnitsGenerated = getProducedItemCount(self, "i16Stream"); // units generated to buffer
    216 
    217210    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    218211    i16UnitsGenerated = getProducedItemCount(self, "i16Stream"); // units generated to buffer
     
    226219}
    227220   
    228    
    229 }
     221}
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5246 r5260  
    1717
    1818   
    19 class p2sKernel : public KernelBuilder {
     19class P2SKernel : public KernelBuilder {
    2020public:
    21     p2sKernel(IDISA::IDISA_Builder * iBuilder) :
     21    P2SKernel(IDISA::IDISA_Builder * iBuilder) :
    2222    KernelBuilder(iBuilder, "p2s",
    2323                  {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}},
     
    3030};
    3131
    32 class p2sKernel_withCompressedOutput : public KernelBuilder {
     32class P2SKernelWithCompressedOutput : public KernelBuilder {
    3333public:
    34     p2sKernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
     34    P2SKernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    3535    KernelBuilder(iBuilder, "p2s_compress",
    3636                  {Binding{iBuilder->getStreamSetTy(8, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
     
    4343   
    4444
    45 class p2s_16Kernel : public KernelBuilder {
     45class P2S16Kernel : public KernelBuilder {
    4646public:
    47     p2s_16Kernel(IDISA::IDISA_Builder * iBuilder) :
     47    P2S16Kernel(IDISA::IDISA_Builder * iBuilder) :
    4848    KernelBuilder(iBuilder, "p2s_16",
    4949                  {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}},
     
    5757
    5858   
    59 class p2s_16Kernel_withCompressedOutput : public KernelBuilder {
     59class P2S16KernelWithCompressedOutput : public KernelBuilder {
    6060public:
    61     p2s_16Kernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
     61    P2S16KernelWithCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    6262    KernelBuilder(iBuilder, "p2s_16_compress",
    6363                  {Binding{iBuilder->getStreamSetTy(16, 1), "basisBits"}, Binding{iBuilder->getStreamSetTy(1, 1), "deletionCounts"}},
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5258 r5260  
    1414
    1515using namespace kernel;
     16using namespace parabix;
     17using namespace llvm;
     18
     19#if 0
    1620
    1721using BufferMap = std::unordered_map<StreamSetBuffer *, std::pair<KernelBuilder *, unsigned>>;
    1822
    19 
    20 static void createStreamBufferMap(BufferMap & bufferMap, std::vector<KernelBuilder *> kernels) {
     23static void createStreamBufferMap(BufferMap & bufferMap, const std::vector<KernelBuilder *> & kernels) {
    2124    for (auto k: kernels) {
    2225        auto outputSets = k->getStreamSetOutputBuffers();
     
    5760    return iBuilder->CreateUDiv(itemsToDo, iBuilder->getSize(iBuilder->getStride()));
    5861}
    59                                    
    60 
    61 
    62 Function * generateSegmentParallelPipelineThreadFunction(std::string name, IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, Type * sharedStructType, int id) {
     62
     63#endif
     64
     65Function * generateSegmentParallelPipelineThreadFunction(std::string name, IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels, Type * sharedStructType, int id) {
    6366
    6467    Module * m = iBuilder->getModule();
     
    176179
    177180
    178 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels) {
     181void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels) {
    179182   
    180183    unsigned threadNum = codegen::ThreadNum;
     
    231234}
    232235
    233 void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels) {
     236void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels) {
    234237 
    235238    Type * pthreadTy = iBuilder->getSizeTy();
     
    271274
    272275
    273 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels) {
     276void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels) {
    274277    for (auto k : kernels) k->createInstance();
    275278    //BufferMap bufferMap;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r5238 r5260  
    66#define PIPELINE_H
    77
    8 #include <IR_Gen/idisa_builder.h>
    9 #include <kernels/interface.h>
    10 #include <kernels/kernel.h>
     8#include <vector>
     9namespace IDISA { class IDISA_Builder; }
     10namespace kernel { class KernelBuilder; }
    1111
    12 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels);
     12void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    1313
    14 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels);
     14void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    1515
    16 void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels);
     16void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    1717
    1818#endif // PIPELINE_H
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5247 r5260  
    77#include <kernels/kernel.h>
    88#include <IR_Gen/idisa_builder.h>
     9#include <llvm/IR/Module.h>
    910#include <llvm/Support/raw_ostream.h>
    1011
     12using namespace llvm;
     13
    1114namespace kernel {
    12 using namespace llvm;
    1315
    1416// This kernel produces an expanded input stream by duplicating every third byte.
     
    8688    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    8789    Constant * loopItemCount = iBuilder->getSize(3 * PACK_SIZE); // 3 packs per loop.
    88     UndefValue * undefPack = UndefValue::get(iBuilder->fwVectorType(parabix::i8));
     90    UndefValue * undefPack = UndefValue::get(iBuilder->fwVectorType(8));
    8991   
    9092    const unsigned packAlign = iBuilder->getBitBlockWidth()/8;
     
    114116    Value * blockNo = getScalarField(self, blockNoScalar);
    115117
    116     Value * sourceBlockPtr = getStreamSetBlockPtr(self, "sourceStream", blockNo);
     118    // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
     119    Value * sourcePackPtr = getStream(self, "sourceStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
    117120
    118121    Value * outputGenerated = getProducedItemCount(self, "expandedStream"); // bytes previously generated to output
    119122    Value * outputBlockNo = iBuilder->CreateUDiv(outputGenerated, stride);
    120 
    121     Value * outputBlockPtr = getStreamSetBlockPtr(self, "expandedStream", outputBlockNo);
    122 
    123     // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
    124     Value * sourcePackPtr = iBuilder->CreateGEP(sourceBlockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(0)});
    125     Value * outputPackPtr = iBuilder->CreateGEP(outputBlockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(0)});
     123    Value * outputPackPtr = getStream(self, "expandedStream", outputBlockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
     124
    126125    Value * hasFullLoop = iBuilder->CreateICmpUGE(itemsToDo, loopItemCount);
    127126
     
    307306//    xwvuts|  nlkjzy|  barqpm|  hgfedc    Target
    308307void radix64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    309     Value * expandedStream = getStreamSetBlockPtr(self, "expandedStream", blockNo);
    310     Value * radix64stream = getStreamSetBlockPtr(self, "radix64stream",blockNo);
    311308
    312309    Value * step_right_6 = iBuilder->simd_fill(32, ConstantInt::get(iBuilder->getInt32Ty(), 0x00C00000));
     
    318315   
    319316    for (unsigned i = 0; i < 8; i++) {
    320         Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     317        Value * expandedStream = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     318        Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStream);
    321319
    322320        Value * right_6_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_6), 6);
     
    335333        Value * radix64pack = iBuilder->bitCast(mid);
    336334
    337         iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     335        Value * radix64stream = getStream(self, "radix64stream",blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     336        iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream);
    338337    }
    339338    Value * produced = getProducedItemCount(self, "radix64stream");
     
    363362    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    364363    Value * blockNo = getScalarField(self, blockNoScalar);
    365     Value * expandedstream_ptr = getStreamSetBlockPtr(self, "expandedStream", blockNo);
    366     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    367364
    368365    Value * step_right_6 = iBuilder->simd_fill(32, iBuilder->getInt32(0x00C00000));
     
    383380    loopRemain->addIncoming(remainingBytes, radix64_fb_entry);
    384381
    385     Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedstream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     382    Value * expandedStreamLoopPtr = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), idx);
     383    Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStreamLoopPtr);
    386384    Value * right_6_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_6), 6);
    387385    Value * right_4_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_4), 4);
     
    399397    Value * radix64pack = iBuilder->bitCast(mid);
    400398
    401     iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     399    Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     400    iBuilder->CreateBlockAlignedStore(radix64pack, radix64streamPtr);
    402401
    403402    Value* nextIdx = iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1));
     
    414413    iBuilder->SetInsertPoint(handleRemainFirstByte);
    415414    // At least one padding byte required.
    416 
    417     Value * i8output_ptr = iBuilder->CreatePointerCast(radix64stream_ptr, iBuilder->getInt8PtrTy());
    418     Value * i8input_ptr = iBuilder->CreatePointerCast(expandedstream_ptr, iBuilder->getInt8PtrTy());
     415    Value * i8input_ptr = getStreamView(iBuilder->getInt8PtrTy(), self, "expandedStream", blockNo, iBuilder->getInt32(0));
    419416    Value * remainOutputStart = iBuilder->CreateSub(remainingBytes, remainMod4);
    420417
    421     Value * firstRemainByte = iBuilder->CreateLoad(iBuilder->CreateGEP(i8input_ptr, iBuilder->getInt32(0)));
     418    Value * firstRemainByte = iBuilder->CreateLoad(i8input_ptr);
    422419
    423420    Value * first_move_right_2_mask = ConstantInt::get(iBuilder->getInt8Ty(), 0xFC);
     
    427424    Value * first_move_left_4_byte = iBuilder->CreateShl(iBuilder->CreateAnd(firstRemainByte, first_move_left_4_mask), 4);
    428425
    429     iBuilder->CreateStore(first_output_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(0))));
    430 
     426
     427    Value * i8OutPtr0 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, remainOutputStart);
     428
     429    iBuilder->CreateStore(first_output_byte, i8OutPtr0);
    431430
    432431    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(1)), handleNoRemainSecondByte, handleRemainSecondByte);
     
    437436    Value * second_move_right_4_byte = iBuilder->CreateLShr(iBuilder->CreateAnd(secondRemainByte, second_move_right_4_mask), 4);
    438437    Value * second_output_byte = iBuilder->CreateOr(first_move_left_4_byte, second_move_right_4_byte);
    439     iBuilder->CreateStore(second_output_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1))));
     438
     439    Value * i8OutPtr1 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1)));
     440
     441    iBuilder->CreateStore(second_output_byte, i8OutPtr1);
    440442
    441443    Value * second_move_left_2_mask = ConstantInt::get(iBuilder->getInt8Ty(), 0x0F);
    442444    Value * second_move_left_2_byte = iBuilder->CreateShl(iBuilder->CreateAnd(secondRemainByte, second_move_left_2_mask), 2);
    443     iBuilder->CreateStore(second_move_left_2_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(2))));
     445
     446    Value * i8OutPtr2 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(2)));
     447
     448    iBuilder->CreateStore(second_move_left_2_byte, i8OutPtr2);
    444449    iBuilder->CreateBr(fbExit);
    445450
    446451    iBuilder->SetInsertPoint(handleNoRemainSecondByte);
    447     iBuilder->CreateStore(first_move_left_4_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1))));
     452
     453    i8OutPtr1 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1)));
     454
     455    iBuilder->CreateStore(first_move_left_4_byte, i8OutPtr1);
    448456    iBuilder->CreateBr(fbExit);
    449457
     
    474482
    475483
    476 void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    477     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    478     Value * base64stream_ptr = getStreamSetBlockPtr(self, "base64stream", blockNo);   
     484void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {       
    479485    for (unsigned i = 0; i < 8; i++) {
    480         Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     486        Value * radix64stream_ptr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     487        Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr);
    481488        Value * mask_gt_25 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(25)));
    482489        Value * mask_gt_51 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(51)));
     
    494501        Value * t0_62 = iBuilder->simd_sub(8, t0_61, iBuilder->simd_and(mask_eq_62, iBuilder->simd_fill(8, iBuilder->getInt8(15))));
    495502        Value * base64pack = iBuilder->simd_sub(8, t0_62, iBuilder->simd_and(mask_eq_63, iBuilder->simd_fill(8, iBuilder->getInt8(2))));
    496         iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     503        Value * base64stream_ptr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     504        iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr);
    497505    }
    498506    Value * produced = getProducedItemCount(self, "base64stream");
     
    526534    Constant * packSize = iBuilder->getSize(iBuilder->getStride() / 8);
    527535    Value * blockNo = getScalarField(self, blockNoScalar);
    528     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    529     Value * base64stream_ptr = getStreamSetBlockPtr(self, "base64stream", blockNo);
    530    
     536
    531537    // Enter the loop only if there is at least one byte remaining to process.
    532538    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0)), fbExit, base64_loop);
     
    537543    idx->addIncoming(ConstantInt::getNullValue(iBuilder->getInt32Ty()), base64_fb_entry);
    538544    loopRemain->addIncoming(remainingBytes, base64_fb_entry);
    539     Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     545    Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     546    Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64streamPtr);
    540547    Value * mask_gt_25 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(25)));
    541548    Value * mask_gt_51 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(51)));
     
    547554    Value * t0_62 = iBuilder->simd_sub(8, t0_61, iBuilder->simd_and(mask_eq_62, iBuilder->simd_fill(8, iBuilder->getInt8(15))));
    548555    Value * base64pack = iBuilder->simd_sub(8, t0_62, iBuilder->simd_and(mask_eq_63, iBuilder->simd_fill(8, iBuilder->getInt8(2))));
    549     iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     556    Value * base64streamPtr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), idx);
     557    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64streamPtr);
    550558    idx->addIncoming(iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1)), base64_loop);
    551559    Value* remainAfterLoop = iBuilder->CreateSub(loopRemain, packSize);
     
    557565    iBuilder->SetInsertPoint(loopExit);
    558566    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(padBytes, iBuilder->getSize(0)), fbExit, doPadding);
     567
    559568    iBuilder->SetInsertPoint(doPadding);
    560     Value * i8output_ptr = iBuilder->CreatePointerCast(base64stream_ptr, iBuilder->getInt8PtrTy());
     569    Value * i8output_ptr = getStreamView(iBuilder->getInt8PtrTy(), self, "base64stream", blockNo, iBuilder->getInt32(0));
    561570    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8output_ptr, remainingBytes));
    562571    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(3)), fbExit, doPadding2);
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5246 r5260  
    1111
    1212namespace llvm { class Module; }
     13namespace llvm { class Value; }
    1314
    1415namespace IDISA { class IDISA_Builder; }
     
    4546
    4647private:
    47     virtual void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     48    virtual void generateDoBlockLogic(llvm::Value * self, llvm::Value * blockNo) const override;
    4849    virtual void generateDoBlockMethod() const override;
    4950    virtual void generateFinalBlockMethod() const override;
     
    6061   
    6162private:
    62     virtual void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     63    virtual void generateDoBlockLogic(llvm::Value * self, llvm::Value * blockNo) const override;
    6364    virtual void generateFinalBlockMethod() const override;
    6465    virtual void generateDoBlockMethod() const override;
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5252 r5260  
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 */
     5
    56#include "s2p_kernel.h"
    6 #include <kernels/kernel.h>
    7 #include <IR_Gen/idisa_builder.h>
    8 #include <llvm/Support/raw_ostream.h>
     7#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
     8#include <llvm/IR/Constant.h>      // for Constant
     9#include <llvm/IR/Module.h>
     10namespace llvm { class BasicBlock; }
     11namespace llvm { class Function; }
     12namespace llvm { class Value; }
     13
     14using namespace llvm;
    915
    1016namespace kernel {
    11 using namespace llvm;
    1217
    1318const int PACK_LANES = 1;
     
    151156    iBuilder->SetInsertPoint(finalEmptyBlock);
    152157    Value * blockNo = getScalarField(self, blockNoScalar);
    153     Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    154     iBuilder->CreateStore(Constant::getNullValue(basisBitsBlock_ptr->getType()->getPointerElementType()), basisBitsBlock_ptr);
     158    Value * basisBitsPtr = getStreamView(self, "basisBits", blockNo, iBuilder->getInt64(0));
     159    iBuilder->CreateStore(Constant::getNullValue(basisBitsPtr->getType()->getPointerElementType()), basisBitsPtr);
    155160    iBuilder->CreateBr(exitBlock);
    156161   
     
    159164    iBuilder->restoreIP(savePoint);
    160165}
    161 
    162166   
    163167void S2PKernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    164 
    165     Value * byteStream = getStreamSetBlockPtr(self, "byteStream", blockNo);
    166     Value * basisBits = getStreamSetBlockPtr(self, "basisBits", blockNo);
    167 
    168168    Value * bytepack[8];
    169169    for (unsigned i = 0; i < 8; i++) {
    170         Value * ptr = iBuilder->CreateGEP(byteStream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
    171         bytepack[i] = iBuilder->CreateBlockAlignedLoad(ptr);
     170        Value * byteStream = getStream(self, "byteStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     171        bytepack[i] = iBuilder->CreateBlockAlignedLoad(byteStream);
    172172    }
    173173    Value * basisbits[8];
    174174    s2p(iBuilder, bytepack, basisbits);
    175175    for (unsigned i = 0; i < 8; ++i) {
    176         iBuilder->CreateBlockAlignedStore(basisbits[i], basisBits, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     176        Value * basisBits = getStream(self, "basisBits", blockNo, iBuilder->getInt32(i));
     177        iBuilder->CreateBlockAlignedStore(basisbits[i], basisBits);
    177178    }
    178179    Value * produced = getProducedItemCount(self, "basisBits");
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5246 r5260  
    66#define S2P_KERNEL_H
    77
    8 #include "streamset.h"
    9 #include "interface.h"
    10 #include "kernel.h"
    11 
    12 namespace llvm { class Module; }
    13 
    14 namespace IDISA { class IDISA_Builder; }
     8#include "kernel.h"  // for KernelBuilder
     9namespace IDISA { class IDISA_Builder; }  // lines 14-14
     10namespace llvm { class Value; }
    1511
    1612namespace kernel {
     
    2420       
    2521private:
    26     void generateDoBlockLogic(Value * self, Value * blockNo) const override;
     22    void generateDoBlockLogic(llvm::Value * self, llvm::Value * blockNo) const override;
    2723    void generateDoBlockMethod() const override;
    2824    void generateFinalBlockMethod() const override;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5246 r5260  
    88#include <llvm/IR/Intrinsics.h>
    99#include <IR_Gen/idisa_builder.h>
     10#include <llvm/IR/Module.h>
    1011#include <llvm/Support/raw_os_ostream.h>
    1112
     
    5859    Value * recordStart = getScalarField(kernelStuctParam, "LineStart");
    5960    Value * recordNum = getScalarField(kernelStuctParam, "LineNum");
    60     Value * matchResultsPtr = getStreamSetBlockPtr(kernelStuctParam, "matchResults", blockNo);   
    61     Value * matches = iBuilder->CreateBlockAlignedLoad(matchResultsPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    62     Value * linebreaks = iBuilder->CreateBlockAlignedLoad(matchResultsPtr, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     61    Value * matches = iBuilder->CreateBlockAlignedLoad(getStream(kernelStuctParam, "matchResults", blockNo, iBuilder->getInt32(0)));
     62    Value * linebreaks = iBuilder->CreateBlockAlignedLoad(getStream(kernelStuctParam, "matchResults", blockNo, iBuilder->getInt32(1)));
    6363    Value * matchWordVector = iBuilder->CreateBitCast(matches, scanwordVectorType);
    6464    Value * breakWordVector = iBuilder->CreateBitCast(linebreaks, scanwordVectorType);
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5256 r5260  
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 */
    5 #include <kernels/stdout_kernel.h>
    6 #include <kernels/kernel.h>
     5#include "stdout_kernel.h"
     6#include <llvm/IR/Module.h>
    77#include <IR_Gen/idisa_builder.h>
     8
     9using namespace llvm;
    810
    911namespace kernel {
     
    5153   
    5254    Value * blockNo = getScalarField(self, blockNoScalar);
    53     //iBuilder->CallPrintInt("blockNo", blockNo);
    54     Value * basePtr = getStreamSetBlockPtr(self, "codeUnitBuffer", blockNo);
    55     //iBuilder->CallPrintInt("basePtr", iBuilder->CreatePtrToInt(basePtr, iBuilder->getInt64Ty()));
    5655    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    57     Value * bytePtr = iBuilder->CreateGEP(iBuilder->CreateBitCast(basePtr, i8PtrTy), byteOffset);
    58 
     56    Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
    5957    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
    6058
     
    7270    Module * m = iBuilder->getModule();
    7371    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
    74     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    75    
     72    Type * i8PtrTy = iBuilder->getInt8PtrTy();   
    7673    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_flush", finalBlockFunction, 0));
    7774    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
     
    8380    Value * itemsAvail = iBuilder->CreateSub(producerPos, processed);
    8481    Value * blockNo = getScalarField(self, blockNoScalar);
    85     Value * basePtr = getStreamSetBlockPtr(self, "codeUnitBuffer", blockNo);
    8682    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    87     Value * bytePtr = iBuilder->CreateGEP(iBuilder->CreateBitCast(basePtr, i8PtrTy), byteOffset);
     83    Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
    8884    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsAvail, itemBytes));
    8985    setProcessedItemCount(self, "codeUnitBuffer", producerPos);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5246 r5260  
    44 */
    55
    6    
    7 #include <kernels/streamset.h>
    8 #include <vector>
    9 #include <IR_Gen/idisa_builder.h>
    10 #include <llvm/IR/Type.h>
     6#include "streamset.h"
     7#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
     8#include <IR_Gen/types/streamtype.h>
     9#include <assert.h>                // for assert
     10#include <llvm/IR/Type.h>          // for Type
     11#include <stdexcept>               // for runtime_error
     12#include <llvm/IR/BasicBlock.h>    // for BasicBlock
     13#include <llvm/IR/Constants.h>     // for ConstantInt
     14#include <llvm/IR/DataLayout.h>    // for DataLayout
     15#include <llvm/IR/DerivedTypes.h>  // for IntegerType (ptr only), PointerType
     16#include <llvm/IR/Module.h>        // for Module
     17#include <llvm/IR/Value.h>         // for Value
     18namespace llvm { class Constant; }
     19namespace llvm { class Function; }
    1120
    1221using namespace parabix;
     22using namespace llvm;
     23using namespace IDISA;
    1324
    1425enum SS_struct_index {iProducer_pos = 0, iConsumer_pos = 1, iEnd_of_input = 2, iBuffer_ptr = 3};
    1526
    16 llvm::Value * StreamSetBuffer::getProducerPosPtr(Value * bufferStructPtr) {
    17     return iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)});
    18 }
    19 
    20 void StreamSetBuffer::setProducerPos(Value * bufferStructPtr, llvm::Value * pos) {
    21     iBuilder->CreateStore(pos, getProducerPosPtr(bufferStructPtr));
    22 }
    23 
    24 llvm::Value * StreamSetBuffer::getConsumerPosPtr(Value * bufferStructPtr) {
    25     return iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
    26 }
    27 
    28 void StreamSetBuffer::setConsumerPos(Value * bufferStructPtr, Value * pos) {
    29     iBuilder->CreateStore(pos, getConsumerPosPtr(bufferStructPtr));
    30 }
    31 
    32 llvm::Value * StreamSetBuffer::getEndOfInputPtr(Value * bufferStructPtr) {
    33     return iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)});
    34 }
    35 
    36 void StreamSetBuffer::setEndOfInput(Value * bufferStructPtr) {
    37     iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), getEndOfInputPtr(bufferStructPtr));
     27Value * StreamSetBuffer::getProducerPosPtr(Value * self) const {
     28    return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)});
     29}
     30
     31void StreamSetBuffer::setProducerPos(Value * self, Value * pos) const {
     32    iBuilder->CreateStore(pos, getProducerPosPtr(self));
     33}
     34
     35Value * StreamSetBuffer::getConsumerPosPtr(Value * self) const {
     36    return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
     37}
     38
     39void StreamSetBuffer::setConsumerPos(Value * self, Value * pos) const {
     40    iBuilder->CreateStore(pos, getConsumerPosPtr(self));
     41}
     42
     43Value * StreamSetBuffer::getEndOfInputPtr(Value * self) const {
     44    return iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)});
     45}
     46
     47void StreamSetBuffer::setEndOfInput(Value * self) const {
     48    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt1Ty(), 1), getEndOfInputPtr(self));
     49}
     50
     51Type * StreamSetBuffer::resolveStreamTypes(Type * type) {
     52    if (auto ty = dyn_cast<ArrayType>(type)) {
     53        unsigned numElems = ty->getNumElements();
     54        auto elemTy = ty->getElementType();
     55        if (isa<StreamType>(elemTy)) {
     56            return ArrayType::get(cast<StreamType>(elemTy)->resolveType(iBuilder), numElems);
     57        }
     58    }
     59    else if (auto ty = dyn_cast<StreamType>(type)) {
     60        return ty->resolveType(iBuilder);
     61    }
     62    return type;
    3863}
    3964
    4065void StreamSetBuffer::allocateBuffer() {
    41     Type * const size_ty = iBuilder->getSizeTy();
     66    Type * const sizeTy = iBuilder->getSizeTy();
    4267    Type * const int1ty = iBuilder->getInt1Ty();
    4368    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetType, iBuilder->getSize(mBufferBlocks));
    4469    mStreamSetStructPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetStructType);
    45     iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    46     iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     70    iBuilder->CreateStore(ConstantInt::get(sizeTy, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     71    iBuilder->CreateStore(ConstantInt::get(sizeTy, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
    4772    iBuilder->CreateStore(ConstantInt::get(int1ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
    4873    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
    4974}
    5075
     76
     77Value * StreamSetBuffer::getStream(Value * self, Value * blockNo, Value * index) const {
     78    return iBuilder->CreateGEP(getStreamSetPtr(self, blockNo), {iBuilder->getInt32(0), index});
     79}
     80
     81Value * StreamSetBuffer::getStream(Value * self, Value * blockNo, Value * index1, Value * index2) const {
     82    return iBuilder->CreateGEP(getStreamSetPtr(self, blockNo), {iBuilder->getInt32(0), index1, index2});
     83}
     84
     85Value * StreamSetBuffer::getStreamView(llvm::Value * self, Value * blockNo, llvm::Value * index) const {
     86    return iBuilder->CreateGEP(getStreamSetPtr(self, blockNo), index, "view");
     87}
     88
     89Value * StreamSetBuffer::getStreamView(llvm::Type * type, llvm::Value * self, Value * blockNo, llvm::Value * index) const {
     90    return iBuilder->CreateGEP(iBuilder->CreatePointerCast(getStreamSetPtr(self, blockNo), type), index, "view");
     91}
     92
    5193// Single Block Buffer
     94
    5295// For a single block buffer, the block pointer is always the buffer base pointer.
    53 llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value *) {
    54     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    55     return iBuilder->CreateLoad(handle);
    56 }
    57 
     96Value * SingleBlockBuffer::getStreamSetPtr(Value * self, Value *) const {
     97    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}), "sb");
     98}
    5899
    59100// External File Buffer
    60 
    61 void ExternalFileBuffer::setStreamSetBuffer(llvm::Value * ptr, Value * fileSize) {
     101void ExternalFileBuffer::setStreamSetBuffer(Value * ptr, Value * fileSize) {
    62102   
    63103    Type * const size_ty = iBuilder->getSizeTy();
     
    74114}
    75115
    76 void ExternalFileBuffer::setEmptyBuffer(llvm::Value * ptr) {
     116void ExternalFileBuffer::setEmptyBuffer(Value * ptr) {
    77117   
    78118    Type * const size_ty = iBuilder->getSizeTy();
     
    93133}
    94134
    95 llvm::Value * ExternalFileBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
    96     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     135Value * ExternalFileBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
     136    Value * handle = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}, "ef");
    97137    Value * bufPtr = iBuilder->CreateLoad(handle);
    98138    return iBuilder->CreateGEP(bufPtr, blockNo);
    99139}
    100140
    101 // Circular Stack Allocated Buffer
    102 
    103 llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
     141// Circular Buffer
     142
     143Value * CircularBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
    104144    assert (blockNo->getType()->isIntegerTy());
    105145
    106     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     146    Value * handle = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}, "cb");
    107147    Value * bufPtr = iBuilder->CreateLoad(handle);
    108148    Value * offset = nullptr;
     
    117157}
    118158
    119 llvm::Value * LinearCopybackBuffer::getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) {
    120     Constant * blockWidth = iBuilder->getSize(iBuilder->getStride());
    121     Value * consumerPos_ptr = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
     159// Linear Copyback Buffer
     160
     161Value * LinearCopybackBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
     162    Value * consumerPos_ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}, "lcb.c");
    122163    Value * consumerPos = iBuilder->CreateLoad(consumerPos_ptr);
    123     Value * consumerBlock = iBuilder->CreateUDiv(consumerPos, blockWidth);
    124     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     164    Value * consumerBlock = iBuilder->CreateUDiv(consumerPos, iBuilder->getSize(iBuilder->getStride()));
     165    consumerBlock = iBuilder->CreateZExtOrTrunc(consumerBlock, blockNo->getType());
     166    Value * handle = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}, "lcb.p");
    125167    Value * bufPtr = iBuilder->CreateLoad(handle);
    126168    return iBuilder->CreateGEP(bufPtr, iBuilder->CreateSub(blockNo, consumerBlock));
    127169}
    128170
    129 void LinearCopybackBuffer::setConsumerPos(Value * bufferStructPtr, Value * newConsumerPos) {
     171void LinearCopybackBuffer::setConsumerPos(Value * self, Value * newConsumerPos) const {
    130172    Type * const i8 = iBuilder->getInt8Ty();
    131173    Type * const i8_ptr = i8->getPointerTo(mAddrSpace);
     
    141183    Constant * const one = ConstantInt::get(sizeTy, 1);
    142184
    143     Value * const consumerPosPtr = getConsumerPosPtr(bufferStructPtr);
     185    Value * const consumerPosPtr = getConsumerPosPtr(self);
    144186    Value * const consumerPos = iBuilder->CreateLoad(consumerPosPtr);
    145187
    146188    // Ensure that the new consumer position is no less than the current position.
    147189    newConsumerPos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(newConsumerPos, consumerPos), consumerPos, newConsumerPos);
    148     Value * producerPos = iBuilder->CreateLoad(iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     190    Value * producerPos = iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    149191
    150192    // Ensure that the new consumer position is no greater than the current producer position.
     
    167209
    168210    // Must copy back one full block for each of the streams in the stream set.
    169     Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     211    Value * handle = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    170212    Value * bufferPtr = iBuilder->CreateLoad(handle);
    171213    Value * const consumerBlock = iBuilder->CreateUDiv(consumerPos, blockWidth);
     
    178220
    179221    iBuilder->CreateStore(newConsumerPos, consumerPosPtr);
    180 }   
     222}
     223
     224// Expandable Buffer
     225
     226Value * ExpandableBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
     227    return nullptr;
     228}
     229
     230llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const {
     231    return nullptr;
     232}
     233
     234llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, llvm::Value * blockNo, Value *index1, Value *index2) const {
     235    return nullptr;
     236}
     237
     238llvm::Value * ExpandableBuffer::getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const {
     239    return nullptr;
     240}
     241
     242llvm::Value * ExpandableBuffer::getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const {
     243    return nullptr;
     244}
     245
     246
     247// Constructors
     248
     249SingleBlockBuffer::SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type)
     250: StreamSetBuffer(BufferKind::BlockBuffer, b, type, 1, 0) {
     251
     252}
     253
     254ExternalFileBuffer::ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace)
     255: StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, 0, AddressSpace) {
     256
     257}
     258
     259CircularBuffer::CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace)
     260: StreamSetBuffer(BufferKind::CircularBuffer, b, type, bufferBlocks, AddressSpace) {
     261
     262}
     263
     264LinearCopybackBuffer::LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace)
     265: StreamSetBuffer(BufferKind::LinearCopybackBuffer, b, type, bufferBlocks, AddressSpace) {
     266
     267}
     268
     269ExpandableBuffer::ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace)
     270: StreamSetBuffer(BufferKind::ExpandableBuffer, b, type, bufferBlocks, AddressSpace) {
     271
     272}
     273
     274StreamSetBuffer::StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, Type * type, unsigned blocks, unsigned AddressSpace)
     275: mBufferKind(k)
     276, iBuilder(b)
     277, mStreamSetType(resolveStreamTypes(type))
     278, mBufferBlocks(blocks)
     279, mAddrSpace(AddressSpace)
     280, mStreamSetBufferPtr(nullptr)
     281, mStreamSetStructPtr(nullptr)
     282, mStreamSetStructType(StructType::get(b->getContext(),
     283                        {{b->getSizeTy(),
     284                          b->getSizeTy(),
     285                          b->getInt1Ty(),
     286                          PointerType::get(mStreamSetType, AddressSpace)}})) {
     287
     288}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5246 r5260  
    77#define STREAMSET_H
    88
    9 #include <string>
    10 #include <vector>
    11 #include <IR_Gen/idisa_builder.h>
    12 #include <llvm/IR/Type.h>
     9#include <llvm/IR/Type.h>  // for Type
     10namespace IDISA { class IDISA_Builder; }
     11namespace llvm { class PointerType; }
     12namespace llvm { class Value; }
     13namespace kernel { class KernelBuilder; }
    1314
    1415namespace parabix {
    1516   
    16 enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
    17 
    1817// Stream Set Structs hold information about the current state of a stream set buffer.
    1918
    20 llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    21 llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    22 llvm::Value * getEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    23 llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     19llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     20llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     21llvm::Value * getEndOfInputPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     22llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
    2423
    2524class StreamSetBuffer {
     25    friend class kernel::KernelBuilder;
     26
    2627public:
    2728
    28     enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer};
     29    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer, ExpandableBuffer};
    2930
    3031    inline BufferKind getBufferKind() const {
     
    4546
    4647    size_t getBufferSize() const { return mBufferBlocks; }
    47        
     48
    4849    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
    49    
     50
    5051    llvm::Value * getStreamSetStructPtr() const { return mStreamSetStructPtr; }
    5152
    5253    virtual void allocateBuffer();
    5354
    54     // Get the buffer pointer for a given block of the stream.
    55     virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) = 0;
     55    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
     56
     57    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
    5658   
    57     llvm::Value * getProducerPosPtr(Value * bufferStructPtr);
     59    virtual llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
    5860
    59     void setProducerPos(Value * bufferStructPtr, Value * pos);
     61    virtual llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
    6062
    61     llvm::Value * getConsumerPosPtr(Value * bufferStructPtr);
     63    llvm::Value * getProducerPosPtr(llvm::Value * self) const;
    6264
    63     virtual void setConsumerPos(Value * bufferStructPtr, Value * pos);
     65    void setProducerPos(llvm::Value * self, llvm::Value * pos) const;
    6466
    65     llvm::Value * getEndOfInputPtr(Value * bufferStructPtr);
     67    llvm::Value * getConsumerPosPtr(llvm::Value * self) const;
    6668
    67     void setEndOfInput(Value * bufferStructPtr);
     69    virtual void setConsumerPos(llvm::Value * self, llvm::Value * pos) const;
     70
     71    llvm::Value * getEndOfInputPtr(llvm::Value * self) const;
     72
     73    void setEndOfInput(llvm::Value * self) const;
    6874   
    69     llvm::Type * resolveStreamTypes(llvm::Type * type) {
    70         if (auto ty = dyn_cast<ArrayType>(type)) {
    71             unsigned numElems = ty->getNumElements();
    72             auto elemTy = ty->getElementType();
    73             if (isa<IDISA::StreamType>(elemTy)) {
    74                 return ArrayType::get(cast<IDISA::StreamType>(elemTy)->resolveType(iBuilder), numElems);
    75             }
    76         }
    77         else if (auto ty = dyn_cast<IDISA::StreamType>(type)) {
    78             return ty->resolveType(iBuilder);
    79         }
    80         return type;
    81     }
     75    llvm::Type * resolveStreamTypes(llvm::Type * type);
    8276   
    8377protected:
    84     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace = 0)
    85     : mBufferKind(k)
    86     , iBuilder(b)
    87     , mStreamSetType(resolveStreamTypes(type))
    88     , mBufferBlocks(blocks)
    89     , mAddrSpace(AddressSpace)
    90     , mStreamSetBufferPtr(nullptr)
    91     , mStreamSetStructPtr(nullptr)
    92     , mStreamSetStructType(StructType::get(b->getContext(),
    93                             {{b->getSizeTy(),
    94                               b->getSizeTy(),
    95                               b->getInt1Ty(),
    96                               PointerType::get(mStreamSetType, AddressSpace)}})) {
    9778
    98     }
     79    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace);
     80
     81    // Get the buffer pointer for a given block of the stream.
     82    virtual llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const = 0;
     83
    9984protected:
    100     const BufferKind        mBufferKind;
    101     IDISA::IDISA_Builder * iBuilder;
    102     llvm::Type * const      mStreamSetType;
    103     size_t                  mBufferBlocks;
    104     int                     mAddrSpace;
    105     llvm::Value *           mStreamSetBufferPtr;
    106     llvm::Value *           mStreamSetStructPtr;
    107     llvm::Type * const      mStreamSetStructType;
     85    const BufferKind                mBufferKind;
     86    IDISA::IDISA_Builder * const    iBuilder;
     87    llvm::Type * const              mStreamSetType;
     88    const size_t                    mBufferBlocks;
     89    const int                       mAddrSpace;
     90    llvm::Value *                   mStreamSetBufferPtr;
     91    llvm::Value *                   mStreamSetStructPtr;
     92    llvm::Type * const              mStreamSetStructType;
    10893};   
    10994
     
    11398        return b->getBufferKind() == BufferKind::BlockBuffer;
    11499    }   
    115     SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type)
    116     : StreamSetBuffer(BufferKind::BlockBuffer, b, type, 1, 0) {
    117100
    118     }
    119     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     101    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
     102
     103protected:
     104    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    120105};
    121106
     
    126111    }
    127112   
    128     ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0)
    129     : StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, 0, AddressSpace) {
    130 
    131     }
     113    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    132114
    133115    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
     116
    134117    void setEmptyBuffer(llvm::Value * buffer_ptr);
    135118
     
    137120    void allocateBuffer() override;
    138121
    139     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     122protected:
     123    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    140124};
    141125   
     
    146130    }
    147131 
    148     CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0)
    149     : StreamSetBuffer(BufferKind::CircularBuffer, b, type, bufferBlocks, AddressSpace) {
     132    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    150133
    151     }
    152 
    153     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     134protected:
     135    llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
    154136};
    155137   
     
    161143    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
    162144   
    163     LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0) :
    164         StreamSetBuffer(BufferKind::LinearCopybackBuffer, b, type, bufferBlocks, AddressSpace) {}
    165    
    166     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    167    
     145    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     146
    168147    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
    169148    // copying back any data beyond that position.
    170     void setConsumerPos(Value * bufferStructPtr, Value * newConsumerPos) override;
     149    void setConsumerPos(llvm::Value * self, llvm::Value * newConsumerPos) const override;
     150
     151protected:
     152    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     153};
     154
     155// ExpandableBuffers do not allow access to the base stream set but will automatically increase the number of streams
     156// within their set whenever the index exceeds its capacity
     157//
     158class ExpandableBuffer : public StreamSetBuffer {
     159public:
     160    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExpandableBuffer;}
     161
     162    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     163
     164    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     165
     166    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const override;
     167
     168    llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     169
     170    llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     171
     172protected:
     173
     174    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    171175};
    172176
Note: See TracChangeset for help on using the changeset viewer.