source: icGREP/icgrep-devel/icgrep/kernels/relationship.h @ 6297

Last change on this file since 6297 was 6296, checked in by cameron, 7 months ago

Merge branch 'master' of https://cs-git-research.cs.surrey.sfu.ca/cameron/parabix-devel

File size: 3.3 KB
Line 
1#ifndef ABSTRACT_STREAMSET_H
2#define ABSTRACT_STREAMSET_H
3
4#include <vector>
5#include <memory>
6#include <llvm/Support/Compiler.h>
7#include <util/not_null.h>
8#include <util/slab_allocator.h>
9
10namespace llvm { class Constant; }
11namespace llvm { class LLVMContext; }
12namespace llvm { class Type; }
13
14namespace kernel {
15
16class Kernel;
17
18// NOTE: Relationships themselves do not store producer/consumer information. When a PipelineKernel is compiled,
19// it recalculates the data based on the existence of a relationship. The problem is that internally, a pipeline
20// is considered to produce its inputs and consume its outputs whereas a kernel within a pipeline consumes its
21// inputs and produces its outputs. However, a PipelineKernel would simply be another kernel if nested within
22// another pipeline and it would become more difficult to reason about global buffer requirements if we
23// considered them independently. Moreover, maintaining this information only adds additional bookkeeping work
24// when the appropriate cached pipeline kernel already exists.
25
26class Relationship {
27    friend class Kernel;
28    friend class PipelineKernel;
29public:
30
31    using Allocator = ProxyAllocator<Relationship *>;
32
33    static inline bool classof(const Relationship *) {
34        return true;
35    }
36    static inline bool classof(const void *) {
37        return false;
38    }
39
40    enum class ClassTypeId {
41        StreamSet
42        , Scalar
43        , ScalarConstant
44    };
45
46    ClassTypeId getClassTypeId() const noexcept {
47        return mClassTypeId;
48    }
49
50    llvm::Type * getType() const noexcept {
51        return mType;
52    }
53
54    void* operator new (std::size_t size, Allocator & A) noexcept {
55        return A.allocate<uint8_t>(size);
56    }
57
58    bool isConstant() const {
59        return mClassTypeId == ClassTypeId::ScalarConstant;
60    }
61
62protected:
63
64    Relationship(const ClassTypeId typeId, llvm::Type * type) noexcept
65    : mClassTypeId(typeId)
66    , mType(type) {
67    }
68
69protected:
70    const ClassTypeId   mClassTypeId;
71    llvm::Type * const  mType;
72};
73
74class StreamSet : public Relationship {
75public:
76    static bool classof(const Relationship * e) {
77        return e->getClassTypeId() == ClassTypeId::StreamSet;
78    }
79    static bool classof(const void *) {
80        return false;
81    }
82    LLVM_READNONE unsigned getNumElements() const;
83
84    LLVM_READNONE unsigned getFieldWidth() const;
85
86    StreamSet(llvm::LLVMContext & C, const unsigned NumElements, const unsigned FieldWidth) noexcept;
87
88};
89
90using StreamSets = std::vector<StreamSet *>;
91
92class Scalar : public Relationship {
93public:
94    static bool classof(const Relationship * e) {
95        return e->getClassTypeId() == ClassTypeId::Scalar || e->getClassTypeId() == ClassTypeId::ScalarConstant;;
96    }
97    static bool classof(const void *) {
98        return false;
99    }
100    Scalar(not_null<llvm::Type *> type) noexcept;
101protected:
102    Scalar(const ClassTypeId typeId, llvm::Type *type) noexcept;
103};
104
105class ScalarConstant : public Scalar {
106public:
107    static bool classof(const Relationship * e) {
108        return e->getClassTypeId() == ClassTypeId::ScalarConstant;
109    }
110    static bool classof(const void *) {
111        return false;
112    }
113    llvm::Constant * value() const {
114        return mConstant;
115    }
116    ScalarConstant(not_null<llvm::Constant *> constant) noexcept;
117private:
118    llvm::Constant * const mConstant;
119};
120
121}
122
123#endif // ABSTRACT_STREAMSET_H
Note: See TracBrowser for help on using the repository browser.