• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / docc / 21873449786

10 Feb 2026 04:31PM UTC coverage: 66.315% (-0.2%) from 66.496%
21873449786

Pull #513

github

web-flow
Merge 55ce04c5d into 5750a460e
Pull Request #513: adds tensor type

244 of 431 new or added lines in 18 files covered. (56.61%)

186 existing lines in 15 files now uncovered.

23488 of 35419 relevant lines covered (66.31%)

372.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.85
/sdfg/src/builder/function_builder.cpp
1
#include "sdfg/builder/function_builder.h"
2

3
namespace sdfg {
4
namespace builder {
5

6
void check_name(const std::string& name) {
3,309✔
7
    if (name.find(".") != std::string::npos) {
3,309✔
8
        throw InvalidSDFGException("Container name " + name + " contains a dot");
×
9
    } else if (name.find(" ") != std::string::npos) {
3,309✔
10
        throw InvalidSDFGException("Container name " + name + " contains a space");
×
11
    } else if (name.find("(") != std::string::npos) {
3,309✔
12
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
13
    } else if (name.find(")") != std::string::npos) {
3,309✔
14
        throw InvalidSDFGException("Container name " + name + " contains a parenthesis");
×
15
    } else if (name.find("[") != std::string::npos) {
3,309✔
16
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
17
    } else if (name.find("]") != std::string::npos) {
3,309✔
18
        throw InvalidSDFGException("Container name " + name + " contains a bracket");
×
19
    } else if (name.find("*") != std::string::npos) {
3,309✔
20
        throw InvalidSDFGException("Container name " + name + " contains a star");
×
21
    } else if (name.find("&") != std::string::npos) {
3,309✔
22
        throw InvalidSDFGException("Container name " + name + " contains a ampersand");
×
23
    } else if (name.find("!") != std::string::npos) {
3,309✔
24
        throw InvalidSDFGException("Container name " + name + " contains a bang");
×
25
    } else if (name.find("~") != std::string::npos) {
3,309✔
26
        throw InvalidSDFGException("Container name " + name + " contains a tilde");
×
27
    } else if (name.find("`") != std::string::npos) {
3,309✔
28
        throw InvalidSDFGException("Container name " + name + " contains a backtick");
×
29
    } else if (name.find("\"") != std::string::npos) {
3,309✔
30
        throw InvalidSDFGException("Container name " + name + " contains a quote");
×
31
    } else if (name.find("'") != std::string::npos) {
3,309✔
32
        throw InvalidSDFGException("Container name " + name + " contains a single quote");
×
33
    } else if (name.find(";") != std::string::npos) {
3,309✔
34
        throw InvalidSDFGException("Container name " + name + " contains a semicolon");
×
35
    } else if (name.find(":") != std::string::npos) {
3,309✔
36
        throw InvalidSDFGException("Container name " + name + " contains a colon");
×
37
    } else if (name.find(",") != std::string::npos) {
3,309✔
38
        throw InvalidSDFGException("Container name " + name + " contains a comma");
×
39
    } else if (name.find("=") != std::string::npos) {
3,309✔
40
        throw InvalidSDFGException("Container name " + name + " contains a equal sign");
×
41
    } else if (name.find("+") != std::string::npos) {
3,309✔
42
        throw InvalidSDFGException("Container name " + name + " contains a plus sign");
×
43
    } else if (name.find("-") != std::string::npos) {
3,309✔
44
        throw InvalidSDFGException("Container name " + name + " contains a minus sign");
×
45
    } else if (name.find("/") != std::string::npos) {
3,309✔
46
        throw InvalidSDFGException("Container name " + name + " contains a slash");
×
47
    } else if (name.find("%") != std::string::npos) {
3,309✔
48
        throw InvalidSDFGException("Container name " + name + " contains a percent sign");
×
49
    } else if (name.find("^") != std::string::npos) {
3,309✔
50
        throw InvalidSDFGException("Container name " + name + " contains a caret");
×
51
    } else if (name.find("|") != std::string::npos) {
3,309✔
52
        throw InvalidSDFGException("Container name " + name + " contains a pipe");
×
53
    }
×
54
};
3,309✔
55

56
size_t FunctionBuilder::new_element_id() const { return ++this->function().element_counter_; };
15,305✔
57

58
void FunctionBuilder::set_element_counter(size_t element_counter) {
54✔
59
    this->function().element_counter_ = element_counter;
54✔
60
};
54✔
61

62
void FunctionBuilder::set_return_type(const types::IType& type) const { this->function().return_type_ = type.clone(); };
×
63

64
const types::IType& FunctionBuilder::
65
    add_container(const std::string& name, const types::IType& type, bool is_argument, bool is_external) const {
3,297✔
66
    if (type.type_id() == types::TypeID::Tensor) {
3,297✔
NEW
67
        throw InvalidSDFGException(
×
NEW
68
            "Tensor types are virtual types, add a pointer instead and use the tensor type on memlets"
×
NEW
69
        );
×
NEW
70
    }
×
71

72
    if (is_argument && is_external) {
3,297✔
73
        throw InvalidSDFGException("Container " + name + " cannot be both an argument and an external");
×
74
    }
×
75
    // Legal name
76
    check_name(name);
3,297✔
77

78
    auto res = this->function().containers_.insert({name, type.clone()});
3,297✔
79
    if (!res.second) {
3,297✔
80
        throw InvalidSDFGException("Container " + name + " already exists");
×
81
    }
×
82

83
    if (is_argument) {
3,297✔
84
        this->function().arguments_.push_back(name);
775✔
85
    }
775✔
86
    if (is_external) {
3,297✔
87
        this->function().externals_.push_back(name);
13✔
88
        this->function().externals_linkage_types_[name] = LinkageType_External;
13✔
89
    }
13✔
90
    if (type.is_symbol()) {
3,297✔
91
        auto sym = symbolic::symbol(name);
2,632✔
92
        this->function().assumptions_.insert({sym, symbolic::Assumption::create(sym, type)});
2,632✔
93
    }
2,632✔
94

95
    return *(*res.first).second;
3,297✔
96
};
3,297✔
97

98
const types::IType& FunctionBuilder::
99
    add_external(const std::string& name, const types::IType& type, LinkageType linkage_type) const {
12✔
100
    check_name(name);
12✔
101

102
    auto res = this->function().containers_.insert({name, type.clone()});
12✔
103
    if (!res.second) {
12✔
104
        throw InvalidSDFGException("Container " + name + " already exists");
×
105
    }
×
106

107
    this->function().externals_.push_back(name);
12✔
108
    this->function().externals_linkage_types_[name] = linkage_type;
12✔
109

110
    return *(*res.first).second;
12✔
111
};
12✔
112

113
void FunctionBuilder::remove_container(const std::string& name) const {
10✔
114
    auto& function = this->function();
10✔
115
    if (!function.is_transient(name)) {
10✔
116
        throw InvalidSDFGException("Container " + name + " is not transient");
2✔
117
    }
2✔
118
    if (this->function().containers_.find(name) == this->function().containers_.end()) {
8✔
119
        throw InvalidSDFGException("Container " + name + " does not exist");
×
120
    }
×
121

122
    auto& type = function.containers_[name];
8✔
123
    if (type->is_symbol() && dynamic_cast<const types::Scalar*>(type.get())) {
8✔
124
        function.assumptions_.erase(symbolic::symbol(name));
6✔
125
    }
6✔
126

127
    function.containers_.erase(name);
8✔
128
};
8✔
129

130
void FunctionBuilder::rename_container(const std::string& old_name, const std::string& new_name) const {
×
131
    auto& function = this->function();
×
132
    if (!function.exists(old_name)) {
×
133
        throw InvalidSDFGException("Container " + old_name + " does not exist");
×
134
    }
×
135

136
    // Move type
137
    function.containers_[new_name] = std::move(function.containers_[old_name]);
×
138
    function.containers_.erase(old_name);
×
139

140
    // Handling of argument
141
    if (function.is_argument(old_name)) {
×
142
        auto it = std::find(function.arguments_.begin(), function.arguments_.end(), old_name);
×
143
        assert(it != function.arguments_.end());
×
144
        *it = new_name;
×
145
    }
×
146
    // Handling of external
147
    if (function.is_external(old_name)) {
×
148
        auto it = std::find(function.externals_.begin(), function.externals_.end(), old_name);
×
149
        assert(it != function.externals_.end());
×
150
        *it = new_name;
×
151
        function.externals_linkage_types_[new_name] = function.externals_linkage_types_[old_name];
×
152
        function.externals_linkage_types_.erase(old_name);
×
153
    }
×
154
    // Handling of assumption
155
    if (function.assumptions().find(symbolic::symbol(old_name)) != function.assumptions().end()) {
×
156
        auto assumption = function.assumption(symbolic::symbol(old_name));
×
157

158
        symbolic::Assumption new_assumption(symbolic::symbol(new_name));
×
159
        new_assumption.lower_bound_deprecated(assumption.lower_bound_deprecated());
×
160
        new_assumption.upper_bound_deprecated(assumption.upper_bound_deprecated());
×
161
        new_assumption.tight_lower_bound(assumption.tight_lower_bound());
×
162
        new_assumption.tight_upper_bound(assumption.tight_upper_bound());
×
163
        for (auto& lb : assumption.lower_bounds()) {
×
164
            new_assumption.add_lower_bound(lb);
×
165
        }
×
166
        for (auto& ub : assumption.upper_bounds()) {
×
167
            new_assumption.add_upper_bound(ub);
×
168
        }
×
169

170
        new_assumption.constant(assumption.constant());
×
171
        new_assumption.map(assumption.map());
×
172

173
        function.assumptions_.erase(symbolic::symbol(old_name));
×
174
        function.assumptions_.insert({new_assumption.symbol(), new_assumption});
×
175
    }
×
176
};
×
177

178
void FunctionBuilder::change_type(const std::string& name, const types::IType& type) const {
15✔
179
    auto& function = this->function();
15✔
180
    if (function.containers_.find(name) == function.containers_.end()) {
15✔
181
        throw InvalidSDFGException("Container " + name + " does not exist");
×
182
    }
×
183

184
    function.containers_[name] = type.clone();
15✔
185
};
15✔
186

187
types::StructureDefinition& FunctionBuilder::add_structure(const std::string& name, bool is_packed) const {
20✔
188
    if (this->function().structures_.find(name) != this->function().structures_.end()) {
20✔
189
        throw InvalidSDFGException("Structure " + name + " already exists");
×
190
    }
×
191

192
    auto res = this->function().structures_.insert({name, std::make_unique<types::StructureDefinition>(name, is_packed)}
20✔
193
    );
20✔
194
    if (!res.second) {
20✔
195
        throw InvalidSDFGException("Structure " + name + " already exists");
×
196
    }
×
197

198
    return *(*res.first).second;
20✔
199
};
20✔
200

201
std::string FunctionBuilder::find_new_name(std::string prefix) const {
355✔
202
    size_t i = 0;
355✔
203
    std::string new_name = prefix + std::to_string(i);
355✔
204
    while (this->function().exists(new_name)) {
575✔
205
        i++;
220✔
206
        new_name = prefix + std::to_string(i);
220✔
207
    }
220✔
208
    return new_name;
355✔
209
};
355✔
210

211
void FunctionBuilder::update_tasklet(data_flow::Tasklet& tasklet, const data_flow::TaskletCode code) {
×
212
    tasklet.code_ = code;
×
213
}
×
214

215
std::unique_ptr<types::Structure> FunctionBuilder::
216
    create_vector_type(const types::Scalar& element_type, size_t vector_size) {
×
217
    std::string struct_name = "__daisy_vec_" + std::to_string(element_type.primitive_type()) + "_" +
×
218
                              std::to_string(vector_size);
×
219
    auto defined_structures = this->function().structures();
×
220
    if (std::find(defined_structures.begin(), defined_structures.end(), struct_name) != defined_structures.end()) {
×
221
        return std::make_unique<types::Structure>(struct_name);
×
222
    }
×
223

224
    auto& struct_def = this->add_structure(struct_name, true);
×
225
    for (size_t i = 0; i < vector_size; i++) {
×
226
        struct_def.add_member(element_type);
×
227
    }
×
228

229
    return std::make_unique<types::Structure>(struct_name);
×
230
}
×
231

232
} // namespace builder
233
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc