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

daisytuner / sdfglib / 20764569418

06 Jan 2026 10:50PM UTC coverage: 62.168% (+21.4%) from 40.764%
20764569418

push

github

web-flow
Merge pull request #433 from daisytuner/clang-coverage

updates clang coverage flags

14988 of 24109 relevant lines covered (62.17%)

88.57 hits per line

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

84.46
/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

14
namespace sdfg {
15
namespace visualizer {
16

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

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

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

25
void DotVisualizer::visualizeBlock(const StructuredSDFG& sdfg, const structured_control_flow::Block& block) {
26✔
26
    auto id = escapeDotId(block.element_id(), "block_");
26✔
27
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
26✔
28
    this->stream_.setIndent(this->stream_.indent() + 4);
26✔
29
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"\";" << std::endl;
26✔
30
    this->last_comp_name_cluster_ = "cluster_" + id;
26✔
31
    if (block.dataflow().nodes().empty()) {
26✔
32
        this->stream_ << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
2✔
33
        this->stream_.setIndent(this->stream_.indent() - 4);
2✔
34
        this->stream_ << "}" << std::endl;
2✔
35
        this->last_comp_name_ = id;
2✔
36
        return;
2✔
37
    }
2✔
38
    this->last_comp_name_.clear();
24✔
39
    std::list<const data_flow::DataFlowNode*> nodes = block.dataflow().topological_sort();
24✔
40
    for (const data_flow::DataFlowNode* node : nodes) {
77✔
41
        std::vector<std::string> in_connectors;
77✔
42
        bool is_access_node = false;
77✔
43
        bool node_will_show_literal_connectors = false;
77✔
44
        auto nodeId = escapeDotId(node->element_id(), "n_");
77✔
45
        if (this->last_comp_name_.empty()) this->last_comp_name_ = nodeId;
77✔
46
        if (const data_flow::Tasklet* tasklet = dynamic_cast<const data_flow::Tasklet*>(node)) {
77✔
47
            this->stream_ << nodeId << " [shape=octagon,label=\"" << tasklet->output() << " = ";
26✔
48
            this->visualizeTasklet(*tasklet);
26✔
49
            this->stream_ << "\"];" << std::endl;
26✔
50

51
            in_connectors = tasklet->inputs();
26✔
52
            node_will_show_literal_connectors = true;
26✔
53
        } else if (const data_flow::ConstantNode* constant_node = dynamic_cast<const data_flow::ConstantNode*>(node)) {
51✔
54
            this->stream_ << nodeId << " [";
7✔
55
            this->stream_ << "penwidth=3.0,";
7✔
56
            if (sdfg.is_transient(constant_node->data())) this->stream_ << "style=\"dashed,filled\",";
7✔
57
            this->stream_ << "label=\"" << constant_node->data() << "\"];" << std::endl;
7✔
58
            is_access_node = true;
7✔
59
        } else if (const data_flow::AccessNode* access_node = dynamic_cast<const data_flow::AccessNode*>(node)) {
44✔
60
            this->stream_ << nodeId << " [";
44✔
61
            this->stream_ << "penwidth=3.0,";
44✔
62
            if (sdfg.is_transient(access_node->data())) this->stream_ << "style=\"dashed,filled\",";
44✔
63
            this->stream_ << "label=\"" << access_node->data() << "\"];" << std::endl;
44✔
64
            is_access_node = true;
44✔
65
        } else if (const data_flow::LibraryNode* libnode = dynamic_cast<const data_flow::LibraryNode*>(node)) {
44✔
66
            this->stream_ << nodeId << " [shape=doubleoctagon,label=\"" << libnode->toStr() << "\"];" << std::endl;
×
67
            in_connectors = libnode->inputs();
×
68
        }
×
69

70
        std::unordered_set<std::string> unused_connectors(in_connectors.begin(), in_connectors.end());
77✔
71
        for (const data_flow::Memlet& iedge : block.dataflow().in_edges(*node)) {
77✔
72
            auto& src = iedge.src();
53✔
73
            auto& dst_conn = iedge.dst_conn();
53✔
74
            bool nonexistent_conn = false;
53✔
75

76
            if (!is_access_node) {
53✔
77
                auto it = unused_connectors.find(dst_conn);
27✔
78
                if (it != unused_connectors.end()) {
27✔
79
                    unused_connectors.erase(it); // remove connector from in_connectors, so it is not used again
27✔
80
                } else {
27✔
81
                    nonexistent_conn = true;
×
82
                }
×
83
            }
27✔
84

85
            this->stream_ << escapeDotId(src.element_id(), "n_") << " -> " << nodeId << " [label=\"   ";
53✔
86
            bool dstIsVoid = dst_conn == "void";
53✔
87
            bool dstIsRef = dst_conn == "ref";
53✔
88
            bool dstIsDeref = dst_conn == "deref";
53✔
89
            auto& src_conn = iedge.src_conn();
53✔
90
            bool srcIsVoid = src_conn == "void";
53✔
91
            bool srcIsDeref = src_conn == "deref";
53✔
92

93
            if (nonexistent_conn) {
53✔
94
                this->stream_ << "!!"; // this should not happen, but if it does, we can still visualize the memlet
×
95
            }
×
96

97
            if (dstIsVoid || dstIsRef || dstIsDeref) { // subset applies to dst
53✔
98
                auto& dstVar = dynamic_cast<data_flow::AccessNode const&>(iedge.dst()).data();
26✔
99
                bool subsetOnDst = false;
26✔
100
                if (srcIsDeref && dstIsVoid) { // Pure Store by Memlet definition (Dereference Memlet Store)
26✔
101
                    auto& subset = iedge.subset();
×
102
                    if (subset.size() == 1 && symbolic::eq(subset[0], symbolic::integer(0))) {
×
103
                        this->stream_ << "*" << dstVar; // store to pointer without further address calc
×
104
                    } else { // fallback, this should not be allowed to happen
×
105
                        this->stream_ << dstVar; // use access node name instead of connector-name
×
106
                        subsetOnDst = true;
×
107
                    }
×
108
                } else if (dstIsVoid) { // computational memlet / output from tasklet / memory store
26✔
109
                    this->stream_ << dstVar; // use access node name instead of connector-name
26✔
110
                    subsetOnDst = true;
26✔
111
                } else {
26✔
112
                    this->stream_ << dstVar; // use access node name instead of connector-name
×
113
                }
×
114
                if (subsetOnDst) {
26✔
115
                    this->visualizeSubset(sdfg, iedge.subset(), &iedge.base_type());
26✔
116
                }
26✔
117
            } else { // dst is a tasklet/library node
27✔
118
                this->stream_ << dst_conn;
27✔
119
            }
27✔
120

121
            this->stream_ << " = ";
53✔
122

123
            if (srcIsVoid || srcIsDeref) { // subset applies to src, could be computational, reference or dereference
53✔
124
                                           // memlet
125
                auto& srcVar = dynamic_cast<data_flow::AccessNode const&>(src).data();
27✔
126
                bool subsetOnSrc = false;
27✔
127
                if (srcIsVoid && dstIsRef) { // reference memlet / address-of / get-element-ptr equivalent
27✔
128
                    this->stream_ << "&";
×
129
                    subsetOnSrc = true;
×
130
                } else if (srcIsVoid && dstIsDeref) { // Dereference memlet / load from address
27✔
131
                    this->stream_ << "*";
×
132
                    auto& subset = iedge.subset();
×
133
                    if (subset.size() != 1 && symbolic::eq(subset[0], symbolic::integer(0))) { // does not match memlet
×
134
                                                                                               // definition -> fallback
135
                        subsetOnSrc = true;
×
136
                    }
×
137
                } else if (srcIsVoid) {
27✔
138
                    subsetOnSrc = true;
27✔
139
                }
27✔
140
                this->stream_ << srcVar;
27✔
141
                if (subsetOnSrc) {
27✔
142
                    this->visualizeSubset(sdfg, iedge.subset(), &iedge.base_type());
27✔
143
                }
27✔
144
            } else {
27✔
145
                this->stream_ << src_conn;
26✔
146
            }
26✔
147
            this->stream_ << "   \"];" << std::endl;
53✔
148
        }
53✔
149

150
        if (!node_will_show_literal_connectors) {
77✔
151
            for (uint64_t i = 0; i < in_connectors.size(); ++i) {
51✔
152
                auto& in_conn = in_connectors[i];
×
153
                auto it = unused_connectors.find(in_conn);
×
154
                if (it != unused_connectors.end()) {
×
155
                    auto literal_id = escapeDotId(node->element_id(), "n_") + "_" + escapeDotId(i, "in");
×
156
                    this->stream_ << literal_id << " [style=\"dotted\", label=\"" << in_conn << "\"];" << std::endl;
×
157
                    this->stream_ << literal_id << " -> " << nodeId << " [label=\"" << i << "\"]" << ";" << std::endl;
×
158
                }
×
159
            }
×
160
        }
51✔
161
    }
77✔
162
    this->stream_.setIndent(this->stream_.indent() - 4);
24✔
163
    this->stream_ << "}" << std::endl;
24✔
164
}
24✔
165

166
void DotVisualizer::visualizeSequence(const StructuredSDFG& sdfg, const structured_control_flow::Sequence& sequence) {
39✔
167
    std::string last_comp_name_tmp, last_comp_name_cluster_tmp;
39✔
168
    for (size_t i = 0; i < sequence.size(); ++i) {
86✔
169
        std::pair<const structured_control_flow::ControlFlowNode&, const structured_control_flow::Transition&> child =
47✔
170
            sequence.at(i);
47✔
171
        this->visualizeNode(sdfg, child.first);
47✔
172
        if ((i > 0) && !last_comp_name_tmp.empty() && !this->last_comp_name_.empty() &&
47✔
173
            last_comp_name_tmp != this->last_comp_name_) {
47✔
174
            this->stream_ << last_comp_name_tmp << " -> " << this->last_comp_name_ << " [";
8✔
175
            if (!last_comp_name_cluster_tmp.empty()) this->stream_ << "ltail=\"" << last_comp_name_cluster_tmp << "\",";
8✔
176
            if (!this->last_comp_name_cluster_.empty())
8✔
177
                this->stream_ << "lhead=\"" << this->last_comp_name_cluster_ << "\",";
6✔
178
            this->stream_ << "minlen=3]"
8✔
179
                          << ";" << std::endl;
8✔
180
        }
8✔
181
        last_comp_name_tmp = this->last_comp_name_;
47✔
182
        last_comp_name_cluster_tmp = this->last_comp_name_cluster_;
47✔
183
    }
47✔
184
}
39✔
185

186
void DotVisualizer::visualizeIfElse(const StructuredSDFG& sdfg, const structured_control_flow::IfElse& if_else) {
3✔
187
    auto id = escapeDotId(if_else.element_id(), "if_");
3✔
188
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
3✔
189
    this->stream_.setIndent(this->stream_.indent() + 4);
3✔
190
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"if:\";" << std::endl
3✔
191
                  << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
3✔
192
    for (size_t i = 0; i < if_else.size(); ++i) {
9✔
193
        this->stream_ << "subgraph cluster_" << id << "_" << std::to_string(i) << " {" << std::endl;
6✔
194
        this->stream_.setIndent(this->stream_.indent() + 4);
6✔
195
        this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\""
6✔
196
                      << this->expression(if_else.at(i).second->__str__()) << "\";" << std::endl;
6✔
197
        this->visualizeSequence(sdfg, if_else.at(i).first);
6✔
198
        this->stream_.setIndent(this->stream_.indent() - 4);
6✔
199
        this->stream_ << "}" << std::endl;
6✔
200
    }
6✔
201
    this->stream_.setIndent(this->stream_.indent() - 4);
3✔
202
    this->stream_ << "}" << std::endl;
3✔
203
    this->last_comp_name_ = id;
3✔
204
    this->last_comp_name_cluster_ = "cluster_" + id;
3✔
205
}
3✔
206

207
void DotVisualizer::visualizeWhile(const StructuredSDFG& sdfg, const structured_control_flow::While& while_loop) {
2✔
208
    auto id = escapeDotId(while_loop.element_id(), "while_");
2✔
209
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
2✔
210
    this->stream_.setIndent(this->stream_.indent() + 4);
2✔
211
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"while:\";" << std::endl
2✔
212
                  << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
2✔
213
    this->visualizeSequence(sdfg, while_loop.root());
2✔
214
    this->stream_.setIndent(this->stream_.indent() - 4);
2✔
215
    this->stream_ << "}" << std::endl;
2✔
216
    this->last_comp_name_ = id;
2✔
217
    this->last_comp_name_cluster_ = "cluster_" + id;
2✔
218
}
2✔
219

220
void DotVisualizer::visualizeFor(const StructuredSDFG& sdfg, const structured_control_flow::For& loop) {
10✔
221
    auto id = escapeDotId(loop.element_id(), "for_");
10✔
222
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
10✔
223
    this->stream_.setIndent(this->stream_.indent() + 4);
10✔
224
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"for: ";
10✔
225
    this->visualizeForBounds(loop.indvar(), loop.init(), loop.condition(), loop.update());
10✔
226
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
10✔
227
    this->visualizeSequence(sdfg, loop.root());
10✔
228
    this->stream_.setIndent(this->stream_.indent() - 4);
10✔
229
    this->stream_ << "}" << std::endl;
10✔
230
    this->last_comp_name_ = id;
10✔
231
    this->last_comp_name_cluster_ = "cluster_" + id;
10✔
232
}
10✔
233

234
void DotVisualizer::visualizeReturn(const StructuredSDFG& sdfg, const structured_control_flow::Return& return_node) {
1✔
235
    auto id = escapeDotId(return_node.element_id(), "return_");
1✔
236
    this->stream_ << id << " [shape=cds,label=\" return  \"];" << std::endl;
1✔
237
    this->last_comp_name_ = id;
1✔
238
    this->last_comp_name_cluster_.clear();
1✔
239
}
1✔
240
void DotVisualizer::visualizeBreak(const StructuredSDFG& sdfg, const structured_control_flow::Break& break_node) {
1✔
241
    auto id = escapeDotId(break_node.element_id(), "break_");
1✔
242
    this->stream_ << id << " [shape=cds,label=\" break  \"];" << std::endl;
1✔
243
    this->last_comp_name_ = id;
1✔
244
    this->last_comp_name_cluster_.clear();
1✔
245
}
1✔
246

247
void DotVisualizer::visualizeContinue(const StructuredSDFG& sdfg, const structured_control_flow::Continue& continue_node) {
1✔
248
    auto id = escapeDotId(continue_node.element_id(), "cont_");
1✔
249
    this->stream_ << id << " [shape=cds,label=\" continue  \"];" << std::endl;
1✔
250
    this->last_comp_name_ = id;
1✔
251
    this->last_comp_name_cluster_.clear();
1✔
252
}
1✔
253

254
void DotVisualizer::visualizeMap(const StructuredSDFG& sdfg, const structured_control_flow::Map& map_node) {
3✔
255
    auto id = escapeDotId(map_node.element_id(), "map_");
3✔
256
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
3✔
257
    this->stream_.setIndent(this->stream_.indent() + 4);
3✔
258
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"map: ";
3✔
259
    this->visualizeForBounds(map_node.indvar(), map_node.init(), map_node.condition(), map_node.update());
3✔
260
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
3✔
261
    this->visualizeSequence(sdfg, map_node.root());
3✔
262
    this->stream_.setIndent(this->stream_.indent() - 4);
3✔
263
    this->stream_ << "}" << std::endl;
3✔
264
    this->last_comp_name_ = id;
3✔
265
    this->last_comp_name_cluster_ = "cluster_" + id;
3✔
266
}
3✔
267

268
void DotVisualizer::visualize() {
18✔
269
    this->stream_.clear();
18✔
270
    this->stream_ << "digraph " << escapeDotId(this->sdfg_.name()) << " {" << std::endl;
18✔
271
    this->stream_.setIndent(4);
18✔
272
    this->stream_ << "graph [compound=true];" << std::endl;
18✔
273
    this->stream_ << "subgraph cluster_" << escapeDotId(this->sdfg_.name()) << " {" << std::endl;
18✔
274
    this->stream_.setIndent(8);
18✔
275
    this->stream_ << "node [style=filled,fillcolor=white];" << std::endl
18✔
276
                  << "style=filled;color=lightblue;label=\"\";" << std::endl;
18✔
277
    this->visualizeSequence(this->sdfg_, this->sdfg_.root());
18✔
278
    this->stream_.setIndent(4);
18✔
279
    this->stream_ << "}" << std::endl;
18✔
280
    this->stream_.setIndent(0);
18✔
281
    this->stream_ << "}" << std::endl;
18✔
282
}
18✔
283

284
void DotVisualizer::writeToFile(const StructuredSDFG& sdfg, const std::filesystem::path* file) {
×
285
    DotVisualizer viz(sdfg);
×
286
    viz.visualize();
×
287

288
    std::filesystem::path fileName = file ? *file : std::filesystem::path(sdfg.name() + ".dot");
×
289

290
    std::ofstream dotOutput(fileName, std::ofstream::out);
×
291

292
    dotOutput << viz.getStream().str();
×
293
    dotOutput.close();
×
294
}
×
295

296
} // namespace visualizer
297
} // 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