source: icGREP/icgrep-devel/icgrep/kernels/binding.cpp @ 6184

Last change on this file since 6184 was 6184, checked in by nmedfort, 9 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 4.3 KB
Line 
1#include "binding.h"
2#include <kernels/relationship.h>
3#include <llvm/Support/ErrorHandling.h>
4#include <llvm/Support/Casting.h>
5#include <llvm/Support/raw_ostream.h>
6#include <llvm/IR/Type.h>
7
8const auto NULL_RELATIONSHIP_ERROR = "cannot set binding relationship to null without a fixed binding type";
9
10const auto NON_MATCHING_TYPE_ERROR = "value type did not match the given binding type";
11
12const auto NOT_STREAM_SET = "binding relationship does not refer to a stream set type";
13
14namespace kernel {
15
16Binding::Binding(std::string name, Relationship * const value, ProcessingRate r)
17: AttributeSet()
18, mName(std::move(name))
19, mRate(std::move(r))
20, mType(value->getType())
21, mValue(value) {
22
23}
24
25Binding::Binding(std::string name, Relationship * const value, ProcessingRate r, Attribute && attribute)
26: AttributeSet(std::move(attribute))
27, mName(std::move(name))
28, mRate(std::move(r))
29, mType(value->getType())
30, mValue(value) {
31
32}
33
34Binding::Binding(std::string name, Relationship * const value, ProcessingRate r, std::initializer_list<Attribute> attributes)
35: AttributeSet(attributes)
36, mName(std::move(name))
37, mRate(std::move(r))
38, mType(value->getType())
39, mValue(value) {
40
41}
42
43Binding::Binding(llvm::Type * const scalarType, std::string name, ProcessingRate r)
44: AttributeSet()
45, mName(std::move(name))
46, mRate(std::move(r))
47, mType(scalarType)
48, mValue(nullptr) {
49
50}
51
52Binding::Binding(llvm::Type * const scalarType, std::string name, ProcessingRate r, Attribute && attribute)
53: AttributeSet(std::move(attribute))
54, mName(std::move(name))
55, mRate(std::move(r))
56, mType(scalarType)
57, mValue(nullptr) {
58
59}
60
61Binding::Binding(llvm::Type * const scalarType, std::string name, ProcessingRate r, std::initializer_list<Attribute> attributes)
62: AttributeSet(attributes)
63, mName(std::move(name))
64, mRate(std::move(r))
65, mType(scalarType)
66, mValue(nullptr) {
67
68}
69
70Binding::Binding(llvm::Type * const type, std::string name, Relationship * const value, ProcessingRate r)
71: AttributeSet()
72, mName(std::move(name))
73, mRate(std::move(r))
74, mType(type)
75, mValue(value) {
76    if (LLVM_UNLIKELY(value == nullptr && type == nullptr)) {
77        llvm::report_fatal_error(NULL_RELATIONSHIP_ERROR);
78    }
79    if (LLVM_UNLIKELY(type && value && value->getType() != type)) {
80        llvm::report_fatal_error(NON_MATCHING_TYPE_ERROR);
81    }
82}
83
84Binding::Binding(llvm::Type * const type, std::string name, Relationship * const value, ProcessingRate r, Attribute && attribute)
85: AttributeSet(std::move(attribute))
86, mName(std::move(name))
87, mRate(std::move(r))
88, mType(type)
89, mValue(value) {
90    if (LLVM_UNLIKELY(value == nullptr && type == nullptr)) {
91        llvm::report_fatal_error(NULL_RELATIONSHIP_ERROR);
92    }
93    if (LLVM_UNLIKELY(type && value && value->getType() != type)) {
94        llvm::report_fatal_error(NON_MATCHING_TYPE_ERROR);
95    }
96}
97
98Binding::Binding(llvm::Type * const type, std::string name, Relationship * const value, ProcessingRate r, std::initializer_list<Attribute> attributes)
99: AttributeSet(attributes)
100, mName(std::move(name))
101, mRate(std::move(r))
102, mType(type)
103, mValue(value) {
104    if (LLVM_UNLIKELY(value == nullptr && type == nullptr)) {
105        llvm::report_fatal_error(NULL_RELATIONSHIP_ERROR);
106    }
107    if (LLVM_UNLIKELY(type && value && value->getType() != type)) {
108        llvm::report_fatal_error(NON_MATCHING_TYPE_ERROR);
109    }
110}
111
112void Binding::setRelationship(Relationship * const value) {
113    if (LLVM_UNLIKELY(value == nullptr && mType == nullptr)) {
114        llvm::report_fatal_error(NULL_RELATIONSHIP_ERROR);
115    }
116    if (LLVM_UNLIKELY(mType && value && value->getType() != mType)) {
117        llvm::report_fatal_error(NON_MATCHING_TYPE_ERROR);
118    }
119    mValue = value;
120}
121
122unsigned Binding::getNumElements() const {
123    StreamSet * const ss = llvm::dyn_cast_or_null<StreamSet>(mValue);
124    if (LLVM_UNLIKELY(ss == nullptr)) {
125        llvm::report_fatal_error(NOT_STREAM_SET);
126    }
127    return ss->getNumElements();
128}
129
130unsigned Binding::getFieldWidth() const {
131    StreamSet * const ss = llvm::dyn_cast_or_null<StreamSet>(mValue);
132    if (LLVM_UNLIKELY(ss == nullptr)) {
133        llvm::report_fatal_error(NOT_STREAM_SET);
134    }
135    return ss->getFieldWidth();
136}
137
138void Binding::print(const Kernel * kernel, llvm::raw_ostream & out) const noexcept {
139    mRate.print(kernel, out);
140    AttributeSet::print(out);
141    getType()->print(out);
142}
143
144}
Note: See TracBrowser for help on using the repository browser.