Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5191 r5202  
    1616enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
    1717
    18 class StreamSetType {
    19 public:
    20     StreamSetType(int count, int width) : mStreamCount(count), mFieldWidth(width) {}
    21     int StreamCount() { return mStreamCount;}
    22     int StreamFieldWidth() { return mFieldWidth;}
    23     bool operator== (StreamSetType& other) {return (mStreamCount == other.mStreamCount) && (mFieldWidth == other.mFieldWidth);}
    24    
    25     llvm::Type * getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder);
    26    
    27 private:
    28     int mStreamCount;
    29     int mFieldWidth;
    30 };
     18inline llvm::Type * StreamSetType(IDISA::IDISA_Builder * iBuilder, const unsigned count, const unsigned width) {
     19    llvm::Type * streamType = ((width == 1) ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), width));
     20    return ArrayType::get(streamType, count);
     21}
    3122
    32    
    3323// Stream Set Structs hold information about the current state
    3424// of a stream set buffer.
    35    
    36 llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
     25
     26llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    3727llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    38 llvm::Value * hasEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
    39 llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
    40    
     28llvm::Value * hasEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     29llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     30
    4131class StreamSetBuffer {
    4232public:
     33
    4334    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer};
     35
    4436    inline BufferKind getBufferKind() const {return mBufferKind;}
    45     inline StreamSetType& getBufferStreamSetType() {return mStreamSetType;}
     37
     38    inline llvm::Type * getBufferStreamSetType() {return mStreamSetType;}
    4639
    4740    llvm::PointerType * getStreamBufferPointerType();
     
    7568   
    7669protected:
    77     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned blocks, unsigned AddressSpace = 0) :
    78         mBufferKind(k), iBuilder(b), mStreamSetType(ss_type), mBufferBlocks(blocks), mAddrSpace(AddressSpace), mStreamSetBufferPtr(nullptr) {
     70    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace = 0) :
     71        mBufferKind(k), iBuilder(b), mStreamSetType(type), mBufferBlocks(blocks), mAddrSpace(AddressSpace), mStreamSetBufferPtr(nullptr) {
    7972            mStreamSetStructType =
    8073                StructType::get(iBuilder->getContext(),
     
    8275                                                    iBuilder->getSizeTy(),
    8376                                                    iBuilder->getInt1Ty(),
    84                                                     PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), AddressSpace)}));
     77                                                    PointerType::get(type, AddressSpace)}));
    8578    }
    86    
    87     const BufferKind       mBufferKind;
    88     IDISA::IDISA_Builder * iBuilder;
    89     StreamSetType mStreamSetType;
    90     size_t mBufferBlocks;
    91     unsigned mAddrSpace;
    92     llvm::Value * mStreamSetBufferPtr;
    93     llvm::Value * mStreamSetStructPtr;
    94     llvm::Type * mStreamSetStructType;
     79protected:
     80    const BufferKind        mBufferKind;
     81    IDISA::IDISA_Builder *  iBuilder;
     82    llvm::Type *            mStreamSetType;
     83    size_t                  mBufferBlocks;
     84    int                    mAddrSpace;
     85    llvm::Value *           mStreamSetBufferPtr;
     86    llvm::Value *           mStreamSetStructPtr;
     87    llvm::Type *            mStreamSetStructType;
    9588};   
    96    
    9789
    9890class SingleBlockBuffer : public StreamSetBuffer {
    9991public:
    100     static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::BlockBuffer;}
    101    
    102     SingleBlockBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type) :
    103     StreamSetBuffer(BufferKind::BlockBuffer, b, ss_type, 1, 0) {}
    104     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     92    static inline bool classof(const StreamSetBuffer * b) {
     93        return b->getBufferKind() == BufferKind::BlockBuffer;
     94    }   
     95    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type)
     96    : StreamSetBuffer(BufferKind::BlockBuffer, b, type, 1, 0) {
     97
     98    }
     99    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
    105100};
    106    
     101
    107102class ExternalFileBuffer : public StreamSetBuffer {
    108103public:
    109     static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalFileBuffer;}
     104    static inline bool classof(const StreamSetBuffer * b) {
     105        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
     106    }
    110107   
    111     ExternalFileBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned AddressSpace = 0) :
    112         StreamSetBuffer(BufferKind::ExternalFileBuffer, b, ss_type, 0, AddressSpace) {}
     108    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0)
     109    : StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, 0, AddressSpace) {
     110
     111    }
    113112
    114113    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
    115114    void setEmptyBuffer(llvm::Value * buffer_ptr);
    116    
     115
    117116    // Can't allocate - raise an error. */
    118117    llvm::Value * allocateBuffer() override;
     
    123122class CircularBuffer : public StreamSetBuffer {
    124123public:
    125     static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularBuffer;}
     124    static inline bool classof(const StreamSetBuffer * b) {
     125        return b->getBufferKind() == BufferKind::CircularBuffer;
     126    }
    126127 
    127     CircularBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks, unsigned AddressSpace = 0) :
    128         StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type, bufferBlocks, AddressSpace) {
    129             if (((bufferBlocks - 1) & bufferBlocks) != 0) {
    130                 throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
    131             }
     128    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0)
     129    : StreamSetBuffer(BufferKind::CircularBuffer, b, type, bufferBlocks, AddressSpace) {
     130        if (((bufferBlocks - 1) & bufferBlocks) != 0) {
     131            throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
    132132        }
    133     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     133    }
     134
     135    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
    134136};
    135137   
     
    141143    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
    142144   
    143     LinearCopybackBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks, unsigned AddressSpace = 0) :
    144         StreamSetBuffer(BufferKind::LinearCopybackBuffer, b, ss_type, bufferBlocks, AddressSpace) {}
     145    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0) :
     146        StreamSetBuffer(BufferKind::LinearCopybackBuffer, b, type, bufferBlocks, AddressSpace) {}
    145147   
    146148    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     
    150152    void setConsumerPos(Value * bufferStructPtr, Value * new_consumer_pos) override;
    151153};
    152    
    153    
    154154
    155155}
Note: See TracChangeset for help on using the changeset viewer.