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

daisytuner / sdfglib / 15099123388

18 May 2025 07:05PM UTC coverage: 63.603% (-0.005%) from 63.608%
15099123388

push

github

web-flow
Merge pull request #18 from daisytuner/structured-control-flow

reduce recursion depth for structured control flow conversion

68 of 83 new or added lines in 2 files covered. (81.93%)

2 existing lines in 2 files now uncovered.

8643 of 13589 relevant lines covered (63.6%)

480.94 hits per line

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

84.33
/src/builder/sdfg_builder.cpp
1
#include "sdfg/builder/sdfg_builder.h"
2

3
namespace sdfg {
4
namespace builder {
5

6
Function& SDFGBuilder::function() const { return static_cast<Function&>(*this->sdfg_); };
56✔
7

8
SDFGBuilder::SDFGBuilder(std::unique_ptr<SDFG>& sdfg)
×
9
    : FunctionBuilder(), sdfg_(std::move(sdfg)) {
×
10

11
      };
×
12

13
SDFGBuilder::SDFGBuilder(const std::string& name)
50✔
14
    : FunctionBuilder(), sdfg_(new SDFG(name)) {
50✔
15

16
      };
50✔
17

18
SDFG& SDFGBuilder::subject() const { return *this->sdfg_; };
14✔
19

20
std::unique_ptr<SDFG> SDFGBuilder::move() { return std::move(this->sdfg_); };
32✔
21

22
/***** Section: Control-Flow Graph *****/
23

24
control_flow::State& SDFGBuilder::add_state(bool is_start_state, const DebugInfo& debug_info) {
67✔
25
    auto vertex = boost::add_vertex(this->sdfg_->graph_);
67✔
26
    auto res = this->sdfg_->states_.insert(
67✔
27
        {vertex, std::unique_ptr<control_flow::State>(
67✔
28
                     new control_flow::State(this->element_counter_, debug_info, vertex))});
67✔
29
    this->element_counter_++;
67✔
30
    assert(res.second);
67✔
31
    (*res.first).second->dataflow_->parent_ = (*res.first).second.get();
67✔
32

33
    if (is_start_state) {
67✔
34
        this->sdfg_->start_state_ = (*res.first).second.get();
14✔
35
    }
14✔
36

37
    return *(*res.first).second;
67✔
38
};
×
39

40
control_flow::State& SDFGBuilder::add_state_before(const control_flow::State& state,
1✔
41
                                                   bool is_start_state,
42
                                                   const DebugInfo& debug_info) {
43
    auto& new_state = this->add_state(false, debug_info);
1✔
44

45
    std::vector<const control_flow::InterstateEdge*> to_redirect;
1✔
46
    for (auto& e : this->sdfg_->in_edges(state)) to_redirect.push_back(&e);
2✔
47

48
    // Redirect control-flow
49
    for (auto edge : to_redirect) {
2✔
50
        this->add_edge(edge->src(), new_state, edge->condition());
1✔
51

52
        auto desc = edge->edge();
1✔
53
        this->sdfg_->edges_.erase(desc);
1✔
54
        boost::remove_edge(desc, this->sdfg_->graph_);
1✔
55
    }
56
    this->add_edge(new_state, state);
1✔
57

58
    if (is_start_state) {
1✔
59
        this->sdfg_->start_state_ = &new_state;
×
60
    }
×
61

62
    return new_state;
1✔
63
};
1✔
64

65
control_flow::State& SDFGBuilder::add_state_after(const control_flow::State& state,
5✔
66
                                                  bool connect_states,
67
                                                  const DebugInfo& debug_info) {
68
    auto& new_state = this->add_state(false, debug_info);
5✔
69

70
    std::vector<const control_flow::InterstateEdge*> to_redirect;
5✔
71
    for (auto& e : this->sdfg_->out_edges(state)) to_redirect.push_back(&e);
6✔
72

73
    // Redirect control-flow
74
    for (auto& edge : to_redirect) {
6✔
75
        this->add_edge(new_state, edge->dst(), edge->condition());
1✔
76

77
        auto desc = edge->edge();
1✔
78
        this->sdfg_->edges_.erase(desc);
1✔
79
        boost::remove_edge(desc, this->sdfg_->graph_);
1✔
80
    }
81
    if (connect_states) {
5✔
82
        this->add_edge(state, new_state);
4✔
83
    }
4✔
84

85
    return new_state;
5✔
86
};
5✔
87

88
control_flow::InterstateEdge& SDFGBuilder::add_edge(const control_flow::State& src,
44✔
89
                                                    const control_flow::State& dst,
90
                                                    const DebugInfo& debug_info) {
91
    return this->add_edge(src, dst, symbolic::Assignments{}, SymEngine::boolTrue, debug_info);
44✔
92
};
×
93

94
control_flow::InterstateEdge& SDFGBuilder::add_edge(const control_flow::State& src,
8✔
95
                                                    const control_flow::State& dst,
96
                                                    const symbolic::Condition condition,
97
                                                    const DebugInfo& debug_info) {
98
    return this->add_edge(src, dst, symbolic::Assignments{}, condition, debug_info);
8✔
99
};
×
100

101
control_flow::InterstateEdge& SDFGBuilder::add_edge(const control_flow::State& src,
2✔
102
                                                    const control_flow::State& dst,
103
                                                    const symbolic::Assignments& assignments,
104
                                                    const DebugInfo& debug_info) {
105
    return this->add_edge(src, dst, assignments, SymEngine::boolTrue, debug_info);
2✔
106
};
×
107

108
control_flow::InterstateEdge& SDFGBuilder::add_edge(const control_flow::State& src,
56✔
109
                                                    const control_flow::State& dst,
110
                                                    const symbolic::Assignments& assignments,
111
                                                    const symbolic::Condition condition,
112
                                                    const DebugInfo& debug_info) {
113
    auto edge = boost::add_edge(src.vertex_, dst.vertex_, this->sdfg_->graph_);
56✔
114
    assert(edge.second);
56✔
115

116
    auto res = this->sdfg_->edges_.insert(
56✔
117
        {edge.first,
56✔
118
         std::unique_ptr<control_flow::InterstateEdge>(new control_flow::InterstateEdge(
112✔
119
             this->element_counter_, debug_info, edge.first, src, dst, condition, assignments))});
56✔
120
    this->element_counter_++;
56✔
121
    assert(res.second);
56✔
122

123
    return *(*res.first).second;
56✔
124
};
×
125

126
void SDFGBuilder::remove_edge(const control_flow::InterstateEdge& edge) {
×
NEW
127
    auto desc = edge.edge();
×
NEW
128
    size_t erased = this->sdfg_->edges_.erase(desc);
×
UNCOV
129
    assert(erased == 1);
×
130

NEW
131
    boost::remove_edge(desc, this->sdfg_->graph_);
×
132
};
×
133

134
std::tuple<control_flow::State&, control_flow::State&, control_flow::State&> SDFGBuilder::add_loop(
1✔
135
    const control_flow::State& state, sdfg::symbolic::Symbol iterator,
136
    sdfg::symbolic::Expression init, sdfg::symbolic::Condition cond,
137
    sdfg::symbolic::Expression update, const DebugInfo& debug_info) {
138
    // Init: iterator = init
139
    auto& init_state = this->add_state_after(state, true, debug_info);
1✔
140
    const graph::Edge init_edge_desc = (*this->sdfg_->in_edges(init_state).begin()).edge_;
1✔
141
    auto& init_edge = this->sdfg_->edges_[init_edge_desc];
1✔
142
    init_edge->assignments_.insert({iterator, init});
1✔
143

144
    // Final state
145
    auto& final_state = this->add_state_after(init_state, false, debug_info);
1✔
146

147
    // Init -> early_exit -> final
148
    auto& early_exit_state = this->add_state(false, debug_info);
1✔
149
    this->add_edge(init_state, early_exit_state, symbolic::Not(cond));
1✔
150
    this->add_edge(early_exit_state, final_state);
1✔
151

152
    // Init -> header -> body
153
    auto& header_state = this->add_state(false, debug_info);
1✔
154
    this->add_edge(init_state, header_state, cond);
1✔
155

156
    auto& body_state = this->add_state(false, debug_info);
1✔
157
    this->add_edge(header_state, body_state);
1✔
158

159
    auto& update_state = this->add_state(false, debug_info);
1✔
160
    this->add_edge(body_state, update_state, {{iterator, update}});
1✔
161

162
    // Back edge and exit edge
163
    this->add_edge(update_state, header_state, cond);
1✔
164
    this->add_edge(update_state, final_state, symbolic::Not(cond));
1✔
165

166
    return {init_state, body_state, final_state};
1✔
167
};
×
168

169
/***** Section: Dataflow Graph *****/
170

171
data_flow::AccessNode& SDFGBuilder::add_access(control_flow::State& state, const std::string& data,
6✔
172
                                               const DebugInfo& debug_info) {
173
    auto& dataflow = state.dataflow();
6✔
174

175
    auto vertex = boost::add_vertex(dataflow.graph_);
6✔
176
    auto res = dataflow.nodes_.insert(
6✔
177
        {vertex, std::unique_ptr<data_flow::AccessNode>(new data_flow::AccessNode(
12✔
178
                     this->element_counter_, debug_info, vertex, dataflow, data))});
6✔
179
    this->element_counter_++;
6✔
180
    return dynamic_cast<data_flow::AccessNode&>(*(res.first->second));
6✔
181
};
×
182

183
data_flow::Tasklet& SDFGBuilder::add_tasklet(
3✔
184
    control_flow::State& state, const data_flow::TaskletCode code,
185
    const std::pair<std::string, sdfg::types::Scalar>& output,
186
    const std::vector<std::pair<std::string, sdfg::types::Scalar>>& inputs,
187
    const DebugInfo& debug_info) {
188
    auto& dataflow = state.dataflow();
3✔
189

190
    auto vertex = boost::add_vertex(dataflow.graph_);
3✔
191
    auto res =
192
        dataflow.nodes_.insert({vertex, std::unique_ptr<data_flow::Tasklet>(new data_flow::Tasklet(
3✔
193
                                            this->element_counter_, debug_info, vertex, dataflow,
3✔
194
                                            code, output, inputs, symbolic::__true__()))});
3✔
195
    this->element_counter_++;
3✔
196
    return dynamic_cast<data_flow::Tasklet&>(*(res.first->second));
3✔
197
};
×
198

199
data_flow::Memlet& SDFGBuilder::add_memlet(control_flow::State& state, data_flow::DataFlowNode& src,
6✔
200
                                           const std::string& src_conn,
201
                                           data_flow::DataFlowNode& dst,
202
                                           const std::string& dst_conn,
203
                                           const data_flow::Subset& subset,
204
                                           const DebugInfo& debug_info) {
205
    auto& dataflow = state.dataflow();
6✔
206

207
    auto edge = boost::add_edge(src.vertex_, dst.vertex_, dataflow.graph_);
6✔
208
    auto res = dataflow.edges_.insert(
6✔
209
        {edge.first, std::unique_ptr<data_flow::Memlet>(
6✔
210
                         new data_flow::Memlet(this->element_counter_, debug_info, edge.first,
12✔
211
                                               dataflow, src, src_conn, dst, dst_conn, subset))});
6✔
212
    this->element_counter_++;
6✔
213
    return dynamic_cast<data_flow::Memlet&>(*(res.first->second));
6✔
214
};
×
215

216
data_flow::LibraryNode& SDFGBuilder::add_library_node(
2✔
217
    control_flow::State& state, const data_flow::LibraryNodeType& call,
218
    const std::vector<std::pair<std::string, sdfg::types::Scalar>>& outputs,
219
    const std::vector<std::pair<std::string, sdfg::types::Scalar>>& inputs,
220
    const bool has_side_effect, const DebugInfo& debug_info) {
221
    auto& dataflow = state.dataflow();
2✔
222

223
    auto vertex = boost::add_vertex(dataflow.graph_);
2✔
224
    auto res = dataflow.nodes_.insert(
2✔
225
        {vertex, std::unique_ptr<data_flow::LibraryNode>(new data_flow::LibraryNode(
4✔
226
                     this->element_counter_, debug_info, vertex, dataflow, outputs, inputs, call,
2✔
227
                     has_side_effect))});
2✔
228
    this->element_counter_++;
2✔
229
    return dynamic_cast<data_flow::LibraryNode&>(*(res.first->second));
2✔
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