source: icGREP/icgrep-devel/icgrep/kernels/streamset.h @ 5260

Last change on this file since 5260 was 5260, checked in by nmedfort, 2 years ago

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

File size: 6.5 KB
RevLine 
[5044]1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
[4986]6#ifndef STREAMSET_H
7#define STREAMSET_H
8
[5260]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; }
[5191]14
[5100]15namespace parabix {
16   
[5217]17// Stream Set Structs hold information about the current state of a stream set buffer.
[4986]18
[5260]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);
[5202]23
[5044]24class StreamSetBuffer {
[5260]25    friend class kernel::KernelBuilder;
26
[5044]27public:
[5202]28
[5260]29    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer, ExpandableBuffer};
[5202]30
[5217]31    inline BufferKind getBufferKind() const {
32        return mBufferKind;
33    }
[5133]34
[5217]35    inline llvm::Type * getBufferStreamSetType() const {
36        return mStreamSetType;
37    }
[5202]38
[5217]39    llvm::PointerType * getStreamBufferPointerType() const {
40        return mStreamSetType->getPointerTo(mAddrSpace);
41    }
[4986]42
[5217]43    llvm::PointerType * getStreamSetStructPointerType() const {
44        return mStreamSetStructType->getPointerTo();
45    }
46
47    size_t getBufferSize() const { return mBufferBlocks; }
[5260]48
[5217]49    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
[5260]50
[5217]51    llvm::Value * getStreamSetStructPtr() const { return mStreamSetStructPtr; }
52
53    virtual void allocateBuffer();
54
[5260]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;
[5044]58   
[5260]59    virtual llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
[5135]60
[5260]61    virtual llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
[5135]62
[5260]63    llvm::Value * getProducerPosPtr(llvm::Value * self) const;
[5135]64
[5260]65    void setProducerPos(llvm::Value * self, llvm::Value * pos) const;
[5135]66
[5260]67    llvm::Value * getConsumerPosPtr(llvm::Value * self) const;
[5135]68
[5260]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;
[5185]74   
[5260]75    llvm::Type * resolveStreamTypes(llvm::Type * type);
[5229]76   
[5217]77protected:
[5135]78
[5260]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
[5202]84protected:
[5260]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;
[5100]93};   
[4986]94
[5100]95class SingleBlockBuffer : public StreamSetBuffer {
96public:
[5202]97    static inline bool classof(const StreamSetBuffer * b) {
98        return b->getBufferKind() == BufferKind::BlockBuffer;
99    }   
100
[5260]101    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
102
103protected:
104    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
[5044]105};
[5202]106
[5142]107class ExternalFileBuffer : public StreamSetBuffer {
[5100]108public:
[5202]109    static inline bool classof(const StreamSetBuffer * b) {
110        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
111    }
[5100]112   
[5260]113    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
[5123]114
[5260]115    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
[5202]116
[5190]117    void setEmptyBuffer(llvm::Value * buffer_ptr);
[5202]118
[5100]119    // Can't allocate - raise an error. */
[5217]120    void allocateBuffer() override;
121
[5260]122protected:
123    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
[5100]124};
[5191]125   
[5100]126class CircularBuffer : public StreamSetBuffer {
127public:
[5202]128    static inline bool classof(const StreamSetBuffer * b) {
129        return b->getBufferKind() == BufferKind::CircularBuffer;
130    }
[5100]131 
[5260]132    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
[5217]133
[5260]134protected:
135    llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
[5100]136};
[5185]137   
138// Linear buffers extending from the current ConsumerPos forward.   Within the buffer, the
139// offset of the block containing the current consumer position is always zero.
140//
[5191]141class LinearCopybackBuffer : public StreamSetBuffer {
[5185]142public:
[5191]143    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
[5185]144   
[5260]145    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
146
[5185]147    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
148    // copying back any data beyond that position.
[5260]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;
[5185]153};
[5100]154
[5260]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;
175};
176
[4986]177}
178#endif // STREAMSET_H
Note: See TracBrowser for help on using the repository browser.