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

daisytuner / sdfglib / 16069945621

04 Jul 2025 08:56AM UTC coverage: 64.375% (-0.2%) from 64.606%
16069945621

push

github

web-flow
Merge pull request #137 from daisytuner/clang-format

runs clang-format on codebase

609 of 827 new or added lines in 63 files covered. (73.64%)

46 existing lines in 30 files now uncovered.

8578 of 13325 relevant lines covered (64.38%)

177.24 hits per line

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

85.71
/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_]+");
2✔
18

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

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

25
void DotVisualizer::visualizeBlock(const StructuredSDFG& sdfg, const structured_control_flow::Block& block) {
217✔
26
    auto id = escapeDotId(block.element_id(), "block_");
217✔
27
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
217✔
28
    this->stream_.setIndent(this->stream_.indent() + 4);
181✔
29
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"\";" << std::endl;
181✔
30
    this->last_comp_name_cluster_ = "cluster_" + id;
181✔
31
    if (block.dataflow().nodes().empty()) {
181✔
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
    }
38
    this->last_comp_name_.clear();
179✔
39
    std::list<const data_flow::DataFlowNode*> nodes = block.dataflow().topological_sort();
179✔
40
    for (const data_flow::DataFlowNode* node : nodes) {
557✔
41
        auto nodeId = escapeDotId(node->element_id(), "n_");
378✔
42
        if (this->last_comp_name_.empty()) this->last_comp_name_ = nodeId;
378✔
43
        if (const data_flow::Tasklet* tasklet = dynamic_cast<const data_flow::Tasklet*>(node)) {
378✔
44
            this->stream_ << nodeId << " [shape=octagon,label=\"" << tasklet->output().first << " = ";
181✔
45
            this->visualizeTasklet(*tasklet);
181✔
46
            this->stream_ << "\"];" << std::endl;
181✔
47
        } else if (const data_flow::AccessNode* access_node = dynamic_cast<const data_flow::AccessNode*>(node)) {
378✔
48
            this->stream_ << nodeId << " [";
197✔
49
            if (!sdfg.is_internal(access_node->data())) this->stream_ << "penwidth=3.0,";
197✔
50
            if (sdfg.is_transient(access_node->data())) this->stream_ << "style=\"dashed,filled\",";
197✔
51
            this->stream_ << "label=\"" << access_node->data() << "\"];" << std::endl;
197✔
52
        } else if (const data_flow::LibraryNode* libnode = dynamic_cast<const data_flow::LibraryNode*>(node)) {
197✔
NEW
53
            this->stream_ << nodeId << " [shape=doubleoctagon,label=\"" << libnode->toStr() << "\"];" << std::endl;
×
54
        }
×
55
        for (const data_flow::Memlet& iedge : block.dataflow().in_edges(*node)) {
577✔
56
            auto& src = iedge.src();
199✔
57

58
            this->stream_ << escapeDotId(src.element_id(), "n_") << " -> " << nodeId << " [label=\"   ";
199✔
59
            auto& dst_conn = iedge.dst_conn();
199✔
60
            bool dstIsVoid = dst_conn == "void";
199✔
61
            bool dstIsRef = dst_conn == "refs";
199✔
62
            auto& src_conn = iedge.src_conn();
199✔
63
            bool srcIsVoid = src_conn == "void";
199✔
64
            bool srcIsRef = src_conn == "refs";
199✔
65

66
            if (dstIsVoid || dstIsRef) {
199✔
67
                auto& dstVar = dynamic_cast<data_flow::AccessNode const&>(iedge.dst()).data();
181✔
68
                this->stream_ << dstVar;
181✔
69
                if (dstIsVoid) {
181✔
70
                    types::IType const* dstTypePtr = sdfg.exists(dstVar) ? &sdfg.type(dstVar) : nullptr;
181✔
71
                    this->visualizeSubset(sdfg, iedge.subset(), dstTypePtr);
181✔
72
                }
181✔
73
            } else {
181✔
74
                this->stream_ << dst_conn;
18✔
75
            }
76

77
            this->stream_ << " = ";
199✔
78

79
            if (srcIsVoid) {
199✔
80
                auto& srcVar = dynamic_cast<data_flow::AccessNode const&>(src).data();
18✔
81
                if (srcIsRef || dstIsRef) {
18✔
82
                    this->stream_ << "&";
18✔
83
                }
×
84
                this->stream_ << srcVar;
×
85
                if (srcIsVoid) {
18✔
86
                    types::IType const* srcTypePtr = sdfg.exists(srcVar) ? &sdfg.type(srcVar) : nullptr;
18✔
87
                    this->visualizeSubset(sdfg, iedge.subset(), srcTypePtr);
18✔
88
                }
18✔
89
            } else {
18✔
90
                this->stream_ << src_conn;
181✔
91
            }
92
            this->stream_ << "   \"];" << std::endl;
199✔
93
        }
94
    }
342✔
95
    this->stream_.setIndent(this->stream_.indent() - 4);
179✔
96
    this->stream_ << "}" << std::endl;
179✔
97
}
325✔
98

99
void DotVisualizer::visualizeSequence(const StructuredSDFG& sdfg, const structured_control_flow::Sequence& sequence) {
191✔
100
    std::string last_comp_name_tmp, last_comp_name_cluster_tmp;
191✔
101
    for (size_t i = 0; i < sequence.size(); ++i) {
390✔
102
        std::pair<const structured_control_flow::ControlFlowNode&, const structured_control_flow::Transition&> child =
103
            sequence.at(i);
199✔
104
        this->visualizeNode(sdfg, child.first);
199✔
105
        if ((i > 0) && !last_comp_name_tmp.empty() && !this->last_comp_name_.empty()) {
199✔
106
            this->stream_ << last_comp_name_tmp << " -> " << this->last_comp_name_ << " [";
8✔
107
            if (!last_comp_name_cluster_tmp.empty()) this->stream_ << "ltail=\"" << last_comp_name_cluster_tmp << "\",";
8✔
108
            if (!this->last_comp_name_cluster_.empty())
8✔
109
                this->stream_ << "lhead=\"" << this->last_comp_name_cluster_ << "\",";
6✔
110
            this->stream_ << "minlen=3]"
8✔
111
                          << ";" << std::endl;
8✔
112
        }
8✔
113
        last_comp_name_tmp = this->last_comp_name_;
199✔
114
        this->last_comp_name_.clear();
199✔
115
        last_comp_name_cluster_tmp = this->last_comp_name_cluster_;
199✔
116
        this->last_comp_name_cluster_.clear();
199✔
117
    }
199✔
118
}
191✔
119

120
void DotVisualizer::visualizeIfElse(const StructuredSDFG& sdfg, const structured_control_flow::IfElse& if_else) {
3✔
121
    auto id = escapeDotId(if_else.element_id(), "if_");
3✔
122
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
3✔
123
    this->stream_.setIndent(this->stream_.indent() + 4);
3✔
124
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"if:\";" << std::endl
3✔
125
                  << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
3✔
126
    for (size_t i = 0; i < if_else.size(); ++i) {
9✔
127
        this->stream_ << "subgraph cluster_" << id << "_" << std::to_string(i) << " {" << std::endl;
6✔
128
        this->stream_.setIndent(this->stream_.indent() + 4);
6✔
129
        this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\""
12✔
130
                      << this->expression(if_else.at(i).second->__str__()) << "\";" << std::endl;
6✔
131
        this->visualizeSequence(sdfg, if_else.at(i).first);
6✔
132
        this->stream_.setIndent(this->stream_.indent() - 4);
6✔
133
        this->stream_ << "}" << std::endl;
6✔
134
    }
6✔
135
    this->stream_.setIndent(this->stream_.indent() - 4);
3✔
136
    this->stream_ << "}" << std::endl;
3✔
137
    this->last_comp_name_ = id;
3✔
138
    this->last_comp_name_cluster_ = "cluster_" + id;
3✔
139
}
3✔
140

141
void DotVisualizer::visualizeWhile(const StructuredSDFG& sdfg, const structured_control_flow::While& while_loop) {
2✔
142
    auto id = escapeDotId(while_loop.element_id(), "while_");
2✔
143
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
2✔
144
    this->stream_.setIndent(this->stream_.indent() + 4);
2✔
145
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"while:\";" << std::endl
2✔
146
                  << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
2✔
147
    this->visualizeSequence(sdfg, while_loop.root());
2✔
148
    this->stream_.setIndent(this->stream_.indent() - 4);
2✔
149
    this->stream_ << "}" << std::endl;
2✔
150
    this->last_comp_name_ = id;
2✔
151
    this->last_comp_name_cluster_ = "cluster_" + id;
2✔
152
}
2✔
153

154
void DotVisualizer::visualizeFor(const StructuredSDFG& sdfg, const structured_control_flow::For& loop) {
10✔
155
    auto id = escapeDotId(loop.element_id(), "for_");
10✔
156
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
10✔
157
    this->stream_.setIndent(this->stream_.indent() + 4);
10✔
158
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"for: ";
10✔
159
    this->visualizeForBounds(loop.indvar(), loop.init(), loop.condition(), loop.update());
10✔
160
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
10✔
161
    this->visualizeSequence(sdfg, loop.root());
10✔
162
    this->stream_.setIndent(this->stream_.indent() - 4);
10✔
163
    this->stream_ << "}" << std::endl;
10✔
164
    this->last_comp_name_ = id;
10✔
165
    this->last_comp_name_cluster_ = "cluster_" + id;
10✔
166
}
10✔
167

168
void DotVisualizer::visualizeReturn(const StructuredSDFG& sdfg, const structured_control_flow::Return& return_node) {
1✔
169
    auto id = escapeDotId(return_node.element_id(), "return_");
1✔
170
    this->stream_ << id << " [shape=cds,label=\" return  \"];" << std::endl;
1✔
171
    this->last_comp_name_ = id;
1✔
172
    this->last_comp_name_cluster_.clear();
1✔
173
}
1✔
174
void DotVisualizer::visualizeBreak(const StructuredSDFG& sdfg, const structured_control_flow::Break& break_node) {
1✔
175
    auto id = escapeDotId(break_node.element_id(), "break_");
1✔
176
    this->stream_ << id << " [shape=cds,label=\" break  \"];" << std::endl;
1✔
177
    this->last_comp_name_ = id;
1✔
178
    this->last_comp_name_cluster_.clear();
1✔
179
}
1✔
180

181
void DotVisualizer::visualizeContinue(const StructuredSDFG& sdfg, const structured_control_flow::Continue& continue_node) {
1✔
182
    auto id = escapeDotId(continue_node.element_id(), "cont_");
1✔
183
    this->stream_ << id << " [shape=cds,label=\" continue  \"];" << std::endl;
1✔
184
    this->last_comp_name_ = id;
1✔
185
    this->last_comp_name_cluster_.clear();
1✔
186
}
1✔
187

188
void DotVisualizer::visualizeMap(const StructuredSDFG& sdfg, const structured_control_flow::Map& map_node) {
×
189
    auto id = escapeDotId(map_node.element_id(), "map_");
×
190
    this->stream_ << "subgraph cluster_" << id << " {" << std::endl;
×
191
    this->stream_.setIndent(this->stream_.indent() + 4);
×
192
    this->stream_ << "style=filled;shape=box;fillcolor=white;color=black;label=\"map: ";
×
NEW
193
    this->visualizeForBounds(map_node.indvar(), map_node.init(), map_node.condition(), map_node.update());
×
NEW
194
    this->stream_ << "\";" << std::endl << id << " [shape=point,style=invis,label=\"\"];" << std::endl;
×
195
    this->visualizeSequence(sdfg, map_node.root());
×
196
    this->stream_.setIndent(this->stream_.indent() - 4);
×
197
    this->stream_ << "}" << std::endl;
×
198
    this->last_comp_name_ = id;
×
199
    this->last_comp_name_cluster_ = "cluster_" + id;
×
200
}
×
201

202
void DotVisualizer::visualize() {
173✔
203
    this->stream_.clear();
173✔
204
    this->stream_ << "digraph " << escapeDotId(this->sdfg_.name()) << " {" << std::endl;
173✔
205
    this->stream_.setIndent(4);
173✔
206
    this->stream_ << "graph [compound=true];" << std::endl;
173✔
207
    this->stream_ << "subgraph cluster_" << escapeDotId(this->sdfg_.name()) << " {" << std::endl;
173✔
208
    this->stream_.setIndent(8);
173✔
209
    this->stream_ << "node [style=filled,fillcolor=white];" << std::endl
173✔
210
                  << "style=filled;color=lightblue;label=\"\";" << std::endl;
173✔
211
    this->visualizeSequence(this->sdfg_, this->sdfg_.root());
173✔
212
    this->stream_.setIndent(4);
173✔
213
    this->stream_ << "}" << std::endl;
173✔
214
    this->stream_.setIndent(0);
173✔
215
    this->stream_ << "}" << std::endl;
173✔
216
}
173✔
217

218
void DotVisualizer::writeToFile(const StructuredSDFG& sdfg, std::filesystem::path* file) {
×
219
    DotVisualizer viz(sdfg);
×
220
    viz.visualize();
×
221

NEW
222
    std::filesystem::path fileName = file ? *file : std::filesystem::path(sdfg.name() + ".dot");
×
223

224
    std::ofstream dotOutput(fileName, std::ofstream::out);
×
225

226
    dotOutput << viz.getStream().str();
×
227
    dotOutput.close();
×
228
    std::cout << "Wrote graph to : " << fileName << std::endl;
×
229
}
×
230
} // namespace visualizer
231
} // 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

© 2025 Coveralls, Inc