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

daisytuner / docc / 27232600826

09 Jun 2026 08:06PM UTC coverage: 61.329% (+0.05%) from 61.275%
27232600826

Pull #741

github

web-flow
Merge 56267e327 into aacd50c09
Pull Request #741: replaces MemAccessRangeAnalysis with MemoryLayoutAnalysis

384 of 424 new or added lines in 11 files covered. (90.57%)

36 existing lines in 9 files now uncovered.

35654 of 58136 relevant lines covered (61.33%)

763.04 hits per line

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

80.72
/sdfg/src/visualizer/dot_visualizer.cpp
1
#include "sdfg/visualizer/dot_visualizer.h"
2

3
#include <cstddef>
4
#include <string>
5
#include <utility>
6

7
#include <regex>
8
#include "sdfg/data_flow/access_node.h"
9
#include "sdfg/data_flow/memlet.h"
10
#include "sdfg/structured_control_flow/control_flow_node.h"
11
#include "sdfg/structured_control_flow/sequence.h"
12
#include "sdfg/structured_sdfg.h"
13
#include "sdfg/symbolic/symbolic.h"
14

15
namespace sdfg {
16
namespace visualizer {
17

18
static std::regex dotIdBadChars("[^a-zA-Z0-9_]+");
19

20
static std::string escapeDotId(size_t id, const std::string& prefix = "") { return prefix + std::to_string(id); }
125✔
21

22
static std::string escapeDotId(const std::string& id, const std::string& prefix = "") {
24✔
23
    return prefix + std::regex_replace(id, dotIdBadChars, "_");
24✔
24
}
24✔
25

26
void DotVisualizer::visualizeSDFG(const SDFG& sdfg) {
1✔
27
    this->stream_.clear();
1✔
28
    this->stream_ << "digraph SDFG {\n";
1✔
29
    this->stream_.setIndent(4);
1✔
30
    this->stream_ << "graph [compound=true];" << std::endl << "node [style=filled,fillcolor=white];" << std::endl;
1✔
31

32
    // State identifier in DOT
33
    std::unordered_map<size_t, std::string> node_ids;
1✔
34

35
    // States as nodes
36
    for (auto& state : sdfg.states()) {
4✔
37
        auto id = escapeDotId(state.element_id(), "state_");
4✔
38
        this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
4✔
39
        this->stream_.setIndent(this->stream_.indent() + 4);
4✔
40
        this->stream_ << "style=filled;fillcolor=white;color=black;label=\"State " << state.element_id() << "\";"
4✔
41
                      << std::endl;
4✔
42
        if (auto* return_state = dynamic_cast<const control_flow::ReturnState*>(&state)) {
4✔
43
            this->stream_ << id << " [shape=cds,label=\" return " << return_state->data() << " \"];" << std::endl;
×
44
        } else {
4✔
45
            this->stream_ << id << " [shape=point,style=invis;label=\"\"];" << std::endl;
4✔
46
            this->visualizeDataFlowGraph(id, state.dataflow());
4✔
47
        }
4✔
48
        this->stream_.setIndent(this->stream_.indent() - 4);
4✔
49
        this->stream_ << "}" << std::endl;
4✔
50
        node_ids.insert({state.element_id(), id});
4✔
51
    }
4✔
52

53
    // Edges
54
    for (auto& edge : sdfg.edges()) {
4✔
55
        auto& src_id = node_ids.at(edge.src().element_id());
4✔
56
        auto& dst_id = node_ids.at(edge.dst().element_id());
4✔
57
        this->stream_ << src_id << " -> " << dst_id << " [ltail=cluster_" << src_id << ",lhead=cluster_" << dst_id
4✔
58
                      << ",label=\"";
4✔
59

60
        // Condition
61
        bool print_condition = !symbolic::eq(edge.condition(), symbolic::__true__());
4✔
62
        if (print_condition) {
4✔
63
            this->stream_ << edge.condition()->__str__();
2✔
64
        }
2✔
65

66
        // Assignments
67
        if (!edge.assignments().empty()) {
4✔
68
            if (print_condition) {
1✔
69
                this->stream_ << ",\\n";
×
70
            }
×
71
            this->stream_ << "{";
1✔
72
            bool first = true;
1✔
73
            for (auto& [var, expr] : edge.assignments()) {
1✔
74
                if (!first) {
1✔
75
                    this->stream_ << "; ";
×
76
                }
×
77
                this->stream_ << var->get_name() << " = " << expr->__str__();
1✔
78
                first = false;
1✔
79
            }
1✔
80
            this->stream_ << "}";
1✔
81
        }
1✔
82
        this->stream_ << "\"];" << std::endl;
4✔
83
    }
4✔
84

85
    this->stream_.setIndent(0);
1✔
86
    this->stream_ << "}" << std::endl;
1✔
87
}
1✔
88

89
void DotVisualizer::visualizeStructuredSDFG(const StructuredSDFG& sdfg) {
12✔
90
    this->stream_.clear();
12✔
91
    this->stream_ << "digraph " << escapeDotId(sdfg.name()) << " {" << std::endl;
12✔
92
    this->stream_.setIndent(4);
12✔
93
    this->stream_ << "graph [compound=true];" << std::endl;
12✔
94
    this->stream_ << "subgraph cluster_" << escapeDotId(sdfg.name()) << " {" << std::endl;
12✔
95
    this->stream_.setIndent(8);
12✔
96
    this->stream_ << "node [style=filled,fillcolor=white];" << std::endl
12✔
97
                  << "style=filled;color=lightblue;label=\"\";" << std::endl;
12✔
98
    this->visualizeSequence(sdfg, sdfg.root());
12✔
99
    this->stream_.setIndent(4);
12✔
100
    this->stream_ << "}" << std::endl;
12✔
101
    this->stream_.setIndent(0);
12✔
102
    this->stream_ << "}" << std::endl;
12✔
103
}
12✔
104

105
void DotVisualizer::visualizeBlock(const StructuredSDFG& sdfg, const structured_control_flow::Block& block) {
18✔
106
    auto id = escapeDotId(block.element_id(), "block_");
18✔
107
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
18✔
108
    this->stream_.setIndent(this->stream_.indent() + 4);
18✔
109
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"";
18✔
110
    if (show_block_ids) {
18✔
111
        this->stream_ << "#" << block.element_id() << " ";
×
112
    }
×
113
    this->stream_ << "\";" << std::endl;
18✔
114
    this->visualizeDataFlowGraph(id, block.dataflow());
18✔
115
    this->stream_.setIndent(this->stream_.indent() - 4);
18✔
116
    this->stream_ << "}" << std::endl;
18✔
117
}
18✔
118

119
void DotVisualizer::visualizeSequence(const StructuredSDFG& sdfg, const structured_control_flow::Sequence& sequence) {
26✔
120
    std::string last_comp_name_tmp, last_comp_name_cluster_tmp;
26✔
121
    for (size_t i = 0; i < sequence.size(); ++i) {
59✔
122
        std::pair<const structured_control_flow::ControlFlowNode&, const structured_control_flow::Transition&> child =
33✔
123
            sequence.at(i);
33✔
124
        this->visualizeNode(sdfg, child.first);
33✔
125
        if ((i > 0) && !last_comp_name_tmp.empty() && !this->last_comp_name_.empty() &&
33✔
126
            last_comp_name_tmp != this->last_comp_name_) {
33✔
127
            this->stream_ << last_comp_name_tmp << " -> " << this->last_comp_name_ << " [";
7✔
128
            if (!last_comp_name_cluster_tmp.empty()) this->stream_ << "ltail=\"" << last_comp_name_cluster_tmp << "\",";
7✔
129
            if (!this->last_comp_name_cluster_.empty())
7✔
130
                this->stream_ << "lhead=\"" << this->last_comp_name_cluster_ << "\",";
4✔
131
            this->stream_ << "minlen=3]"
7✔
132
                          << ";" << std::endl;
7✔
133
        }
7✔
134
        last_comp_name_tmp = this->last_comp_name_;
33✔
135
        last_comp_name_cluster_tmp = this->last_comp_name_cluster_;
33✔
136
    }
33✔
137
}
26✔
138

139
void DotVisualizer::visualizeIfElse(const StructuredSDFG& sdfg, const structured_control_flow::IfElse& if_else) {
3✔
140
    auto id = escapeDotId(if_else.element_id(), "if_");
3✔
141
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
3✔
142
    this->stream_.setIndent(this->stream_.indent() + 4);
3✔
143
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"";
3✔
144
    if (show_block_ids) {
3✔
145
        this->stream_ << "#" << if_else.element_id() << " ";
×
146
    }
×
147
    this->stream_ << "if:\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
3✔
148
    for (size_t i = 0; i < if_else.size(); ++i) {
9✔
149
        this->stream_ << "subgraph cluster_" << id << "_" << std::to_string(i) << " {" << std::endl;
6✔
150
        this->stream_.setIndent(this->stream_.indent() + 4);
6✔
151
        this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\""
6✔
152
                      << this->expression(if_else.at(i).second->__str__()) << "\";" << std::endl;
6✔
153
        this->visualizeSequence(sdfg, if_else.at(i).first);
6✔
154
        this->stream_.setIndent(this->stream_.indent() - 4);
6✔
155
        this->stream_ << "}" << std::endl;
6✔
156
    }
6✔
157
    this->stream_.setIndent(this->stream_.indent() - 4);
3✔
158
    this->stream_ << "}" << std::endl;
3✔
159
    this->last_comp_name_ = id;
3✔
160
    this->last_comp_name_cluster_ = "cluster_" + id;
3✔
161
}
3✔
162

163
void DotVisualizer::visualizeWhile(const StructuredSDFG& sdfg, const structured_control_flow::While& while_loop) {
2✔
164
    auto id = escapeDotId(while_loop.element_id(), "while_");
2✔
165
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
2✔
166
    this->stream_.setIndent(this->stream_.indent() + 4);
2✔
167
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"";
2✔
168
    if (show_block_ids) {
2✔
169
        this->stream_ << "#" << while_loop.element_id() << " ";
×
170
    }
×
171
    this->stream_ << "while:\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
2✔
172
    this->visualizeSequence(sdfg, while_loop.root());
2✔
173
    this->stream_.setIndent(this->stream_.indent() - 4);
2✔
174
    this->stream_ << "}" << std::endl;
2✔
175
    this->last_comp_name_ = id;
2✔
176
    this->last_comp_name_cluster_ = "cluster_" + id;
2✔
177
}
2✔
178

179
void DotVisualizer::visualizeFor(const StructuredSDFG& sdfg, const structured_control_flow::For& loop) {
6✔
180
    auto id = escapeDotId(loop.element_id(), "for_");
6✔
181
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
6✔
182
    this->stream_.setIndent(this->stream_.indent() + 4);
6✔
183
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"";
6✔
184
    if (show_block_ids) {
6✔
185
        this->stream_ << "#" << loop.element_id() << " ";
×
186
    }
×
187
    this->stream_ << "for: ";
6✔
188
    this->visualizeForBounds(loop.indvar(), loop.init(), loop.condition(), loop.update());
6✔
189
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
6✔
190
    this->visualizeSequence(sdfg, loop.root());
6✔
191
    this->stream_.setIndent(this->stream_.indent() - 4);
6✔
192
    this->stream_ << "}" << std::endl;
6✔
193
    this->last_comp_name_ = id;
6✔
194
    this->last_comp_name_cluster_ = "cluster_" + id;
6✔
195
}
6✔
196

197
void DotVisualizer::visualizeReturn(const StructuredSDFG& sdfg, const structured_control_flow::Return& return_node) {
2✔
198
    auto id = escapeDotId(return_node.element_id(), "return_");
2✔
199
    this->stream_ << id << " [shape=cds,label=\" return " << return_node.data() << "\"];" << std::endl;
2✔
200
    this->last_comp_name_ = id;
2✔
201
    this->last_comp_name_cluster_.clear();
2✔
202
}
2✔
203
void DotVisualizer::visualizeBreak(const StructuredSDFG& sdfg, const structured_control_flow::Break& break_node) {
1✔
204
    auto id = escapeDotId(break_node.element_id(), "break_");
1✔
205
    this->stream_ << id << " [shape=cds,label=\" break  \"];" << std::endl;
1✔
206
    this->last_comp_name_ = id;
1✔
207
    this->last_comp_name_cluster_.clear();
1✔
208
}
1✔
209

210
void DotVisualizer::visualizeContinue(const StructuredSDFG& sdfg, const structured_control_flow::Continue& continue_node) {
1✔
211
    auto id = escapeDotId(continue_node.element_id(), "cont_");
1✔
212
    this->stream_ << id << " [shape=cds,label=\" continue  \"];" << std::endl;
1✔
213
    this->last_comp_name_ = id;
1✔
214
    this->last_comp_name_cluster_.clear();
1✔
215
}
1✔
216

UNCOV
217
void DotVisualizer::visualizeMap(const StructuredSDFG& sdfg, const structured_control_flow::Map& map_node) {
×
UNCOV
218
    auto id = escapeDotId(map_node.element_id(), "map_");
×
UNCOV
219
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
×
UNCOV
220
    this->stream_.setIndent(this->stream_.indent() + 4);
×
UNCOV
221
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"";
×
UNCOV
222
    if (show_block_ids) {
×
223
        this->stream_ << "#" << map_node.element_id() << " ";
×
224
    }
×
UNCOV
225
    this->stream_ << "map: ";
×
UNCOV
226
    this->visualizeForBounds(map_node.indvar(), map_node.init(), map_node.condition(), map_node.update());
×
227

UNCOV
228
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
×
UNCOV
229
    this->visualizeSequence(sdfg, map_node.root());
×
UNCOV
230
    this->stream_.setIndent(this->stream_.indent() - 4);
×
UNCOV
231
    this->stream_ << "}" << std::endl;
×
UNCOV
232
    this->last_comp_name_ = id;
×
UNCOV
233
    this->last_comp_name_cluster_ = "cluster_" + id;
×
UNCOV
234
}
×
235

236
void DotVisualizer::visualizeDataFlowGraph(const std::string& id, const data_flow::DataFlowGraph& dfg) {
22✔
237
    this->last_comp_name_cluster_ = "cluster_" + id;
22✔
238
    if (dfg.nodes().empty()) {
22✔
239
        this->stream_ << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
5✔
240
        this->last_comp_name_ = id;
5✔
241
        return;
5✔
242
    }
5✔
243
    this->last_comp_name_.clear();
17✔
244
    std::list<const data_flow::DataFlowNode*> nodes = dfg.topological_sort();
17✔
245
    for (const data_flow::DataFlowNode* node : nodes) {
52✔
246
        std::vector<std::string> in_connectors;
52✔
247
        bool is_access_node = false;
52✔
248
        bool node_will_show_literal_connectors = false;
52✔
249
        auto nodeId = escapeDotId(node->element_id(), "id");
52✔
250
        if (this->last_comp_name_.empty()) {
52✔
251
            this->last_comp_name_ = nodeId;
17✔
252
        }
17✔
253
        if (const data_flow::Tasklet* tasklet = dynamic_cast<const data_flow::Tasklet*>(node)) {
52✔
254
            this->stream_ << nodeId << " [shape=octagon,label=\"" << tasklet->output() << " = ";
17✔
255
            this->visualizeTasklet(*tasklet);
17✔
256
            this->stream_ << "\"];" << std::endl;
17✔
257

258
            in_connectors = tasklet->inputs();
17✔
259
            node_will_show_literal_connectors = true;
17✔
260
        } else if (const data_flow::ConstantNode* constant_node = dynamic_cast<const data_flow::ConstantNode*>(node)) {
35✔
261
            this->stream_ << nodeId << " [";
3✔
262
            this->stream_ << "penwidth=3.0,";
3✔
263
            if (this->sdfg_.is_transient(constant_node->data())) this->stream_ << "style=\"dashed,filled\",";
3✔
264
            this->stream_ << "label=\"" << constant_node->data() << "\"];" << std::endl;
3✔
265
            is_access_node = true;
3✔
266
        } else if (const data_flow::AccessNode* access_node = dynamic_cast<const data_flow::AccessNode*>(node)) {
32✔
267
            this->stream_ << nodeId << " [";
31✔
268
            this->stream_ << "penwidth=3.0,";
31✔
269
            if (this->sdfg_.is_transient(access_node->data())) this->stream_ << "style=\"dashed,filled\",";
31✔
270
            this->stream_ << "label=\"" << access_node->data() << "\"];" << std::endl;
31✔
271
            is_access_node = true;
31✔
272
        } else if (const data_flow::LibraryNode* libnode = dynamic_cast<const data_flow::LibraryNode*>(node)) {
31✔
273
            this->stream_ << nodeId << " [shape=doubleoctagon,label=\"" << libnode->toStr() << "\"];" << std::endl;
1✔
274
            in_connectors = libnode->inputs();
1✔
275
        }
1✔
276

277
        std::unordered_set<std::string> unused_connectors(in_connectors.begin(), in_connectors.end());
52✔
278
        for (const data_flow::Memlet& iedge : dfg.in_edges(*node)) {
52✔
279
            auto& src = iedge.src();
36✔
280
            auto& dst_conn = iedge.dst_conn();
36✔
281
            bool nonexistent_conn = false;
36✔
282

283
            if (!is_access_node) {
36✔
284
                auto it = unused_connectors.find(dst_conn);
18✔
285
                if (it != unused_connectors.end()) {
18✔
286
                    unused_connectors.erase(it); // remove connector from in_connectors, so it is not used again
18✔
287
                } else {
18✔
288
                    nonexistent_conn = true;
×
289
                }
×
290
            }
18✔
291

292
            this->stream_ << escapeDotId(src.element_id(), "id") << " -> " << nodeId << " [label=\"   ";
36✔
293
            bool dstIsVoid = dst_conn == "void";
36✔
294
            bool dstIsRef = dst_conn == "ref";
36✔
295
            bool dstIsDeref = dst_conn == "deref";
36✔
296
            auto& src_conn = iedge.src_conn();
36✔
297
            bool srcIsVoid = src_conn == "void";
36✔
298
            bool srcIsDeref = src_conn == "deref";
36✔
299

300
            if (nonexistent_conn) {
36✔
301
                this->stream_ << "!!"; // this should not happen, but if it does, we can still visualize the memlet
×
302
            }
×
303

304
            if (dstIsVoid || dstIsRef || dstIsDeref) { // subset applies to dst
36✔
305
                auto& dstVar = dynamic_cast<data_flow::AccessNode const&>(iedge.dst()).data();
18✔
306
                bool subsetOnDst = false;
18✔
307
                if (srcIsDeref && dstIsVoid) { // Pure Store by Memlet definition (Dereference Memlet Store)
18✔
308
                    auto& subset = iedge.subset();
×
309
                    if (subset.size() == 1 && symbolic::eq(subset[0], symbolic::integer(0))) {
×
310
                        this->stream_ << "*" << dstVar; // store to pointer without further address calc
×
311
                    } else { // fallback, this should not be allowed to happen
×
312
                        this->stream_ << dstVar; // use access node name instead of connector-name
×
313
                        subsetOnDst = true;
×
314
                    }
×
315
                } else if (dstIsVoid) { // computational memlet / output from tasklet / memory store
18✔
316
                    this->stream_ << dstVar; // use access node name instead of connector-name
18✔
317
                    subsetOnDst = true;
18✔
318
                } else {
18✔
319
                    this->stream_ << dstVar; // use access node name instead of connector-name
×
320
                }
×
321
                if (subsetOnDst) {
18✔
322
                    this->visualizeSubset(iedge.subset(), &iedge.base_type());
18✔
323
                }
18✔
324
            } else { // dst is a tasklet/library node
18✔
325
                this->stream_ << dst_conn;
18✔
326
            }
18✔
327

328
            this->stream_ << " = ";
36✔
329

330
            if (srcIsVoid || srcIsDeref) { // subset applies to src, could be computational, reference or dereference
36✔
331
                                           // memlet
332
                auto& srcVar = dynamic_cast<data_flow::AccessNode const&>(src).data();
18✔
333
                bool subsetOnSrc = false;
18✔
334
                if (srcIsVoid && dstIsRef) { // reference memlet / address-of / get-element-ptr equivalent
18✔
335
                    this->stream_ << "&";
×
336
                    subsetOnSrc = true;
×
337
                } else if (srcIsVoid && dstIsDeref) { // Dereference memlet / load from address
18✔
338
                    this->stream_ << "*";
×
339
                    auto& subset = iedge.subset();
×
340
                    if (subset.size() != 1 && symbolic::eq(subset[0], symbolic::integer(0))) { // does not match memlet
×
341
                                                                                               // definition -> fallback
342
                        subsetOnSrc = true;
×
343
                    }
×
344
                } else if (srcIsVoid) {
18✔
345
                    subsetOnSrc = true;
18✔
346
                }
18✔
347
                this->stream_ << srcVar;
18✔
348
                if (subsetOnSrc) {
18✔
349
                    this->visualizeSubset(iedge.subset(), &iedge.base_type());
18✔
350
                }
18✔
351
            } else {
18✔
352
                this->stream_ << src_conn;
18✔
353
            }
18✔
354
            this->stream_ << "   \"];" << std::endl;
36✔
355
        }
36✔
356

357
        if (!node_will_show_literal_connectors) {
52✔
358
            for (uint64_t i = 0; i < in_connectors.size(); ++i) {
35✔
359
                auto& in_conn = in_connectors[i];
×
360
                auto it = unused_connectors.find(in_conn);
×
361
                if (it != unused_connectors.end()) {
×
362
                    auto literal_id = escapeDotId(node->element_id(), "id") + "_" + escapeDotId(i, "in");
×
363
                    this->stream_ << literal_id << " [style=\"invis\", label=\"\"];" << std::endl;
×
364
                    this->stream_ << literal_id << " -> " << nodeId << " [style=\"dotted\", label=\"" << i << ":"
×
365
                                  << in_conn << "\"]" << ";" << std::endl;
×
366
                }
×
367
            }
×
368
        }
35✔
369
    }
52✔
370
}
17✔
371

372
void DotVisualizer::writeToFile(const Function& sdfg, const std::filesystem::path& file) { writeToFile(sdfg, &file); }
×
373

374
void DotVisualizer::writeToFile(const Function& sdfg, const std::filesystem::path* file) {
1✔
375
    DotVisualizer viz(sdfg);
1✔
376
    viz.visualize();
1✔
377

378
    std::filesystem::path fileName = file ? *file : std::filesystem::path(sdfg.name() + ".dot");
1✔
379

380
    auto parent_path = fileName.parent_path();
1✔
381
    if (!parent_path.empty()) {
1✔
382
        std::filesystem::create_directories(fileName.parent_path());
×
383
    }
×
384

385
    std::ofstream dotOutput(fileName, std::ofstream::out);
1✔
386
    if (!dotOutput.is_open()) {
1✔
387
        std::cerr << "Could not open file " << fileName << " for writing DOT output." << std::endl;
×
388
    }
×
389

390
    dotOutput << viz.getStream().str();
1✔
391
    dotOutput.close();
1✔
392
}
1✔
393

394
} // namespace visualizer
395
} // 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