MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
dot.cpp
Go to the documentation of this file.
1
#include "
pbqp/dot.h
"
2
3
#include <cassert>
4
5
#include <print>
6
7
namespace
pbqp
{
8
9
namespace
{
10
11
constexpr
const
char
* kChosen = R
"( bgcolor="palegreen")";
12
13
void
print_cell(std::ostream& out,
Cost
cost,
bool
chosen) {
14
const
char
*
const
attr = chosen ? kChosen :
""
;
15
if
(
cost
.is_inf())
16
std::print(out,
"<td{}>∞</td>"
, attr);
17
else
18
std::print(out,
"<td{}>{}</td>"
, attr,
cost
.value());
19
}
20
21
}
// namespace
22
23
void
write_dot
(std::ostream& out,
const
Graph
& graph, fe::View<OptionId> choices) {
24
const
bool
highlight = !choices.empty();
25
assert((!highlight || choices.size() >= graph.
num_nodes
()) &&
"write_dot: choices must cover every node id"
);
26
27
std::println(out,
"graph pbqp {{"
);
28
std::println(out,
" node [shape=plain];"
);
29
std::println(out,
" edge [fontsize=10];"
);
30
31
for
(
const
auto
n : graph.
nodes
()) {
32
const
auto
costs = graph.
node_costs
(n);
33
std::print(
34
out,
35
R
"( n{} [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td colspan="{}"><b>n{}</b></td></tr><tr>)",
36
n, costs.size(), n);
37
for
(
OptionId
i = 0; i < costs.size(); ++i)
38
print_cell(out, costs[i], highlight && choices[n] == i);
39
std::println(out,
"</tr></table>>];"
);
40
}
41
42
for
(
const
auto
e : graph.
edges
()) {
43
const
auto
[src, dst] = graph.
edge
(e);
44
const
MatrixView
matrix = graph.
edge_matrix
(e);
45
std::print(
46
out,
47
R
"( n{} -- n{} [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td colspan="{}">n{} × n{}</td></tr>)",
48
src, dst, matrix.
cols
(), src, dst);
49
for
(
OptionId
i = 0; i < matrix.
rows
(); ++i) {
50
std::print(out,
"<tr>"
);
51
for
(
OptionId
j = 0; j < matrix.
cols
(); ++j)
52
print_cell(out, matrix[i, j], highlight && choices[src] == i && choices[dst] == j);
53
std::print(out,
"</tr>"
);
54
}
55
std::println(out,
"</table>>];"
);
56
}
57
58
std::println(out,
"}}"
);
59
}
60
61
}
// namespace pbqp
pbqp::BasicMatrix::rows
constexpr size_t rows() const
Definition
graph.h:88
pbqp::BasicMatrix::cols
constexpr size_t cols() const
Definition
graph.h:89
pbqp::Cost
A saturating cost; Cost::inf forbids an option or option pair.
Definition
graph.h:31
pbqp::Graph
A PBQP problem graph.
Definition
graph.h:252
pbqp::Graph::edge
Ends edge(EdgeId e) const
Definition
graph.h:303
pbqp::Graph::num_nodes
size_t num_nodes() const
Definition
graph.h:312
pbqp::Graph::edge_matrix
MatrixView edge_matrix(EdgeId e) const
Row-major with the src option as the row.
Definition
graph.h:287
pbqp::Graph::node_costs
fe::View< Cost > node_costs(NodeId n) const
Definition
graph.h:284
pbqp::Graph::nodes
auto nodes() const
All node ids.
Definition
graph.h:309
pbqp::Graph::edges
auto edges() const
All edge ids.
Definition
graph.h:310
dot.h
mim::plug::arm::insn::cost
u32 cost(const App *app)
The cost of the instruction app: its latency plus one, so of two equally fast covers the shorter wins...
Definition
insn.h:24
pbqp
Definition
dot.h:9
pbqp::OptionId
size_t OptionId
Index of an option within a node's cost vector.
Definition
graph.h:27
pbqp::MatrixView
BasicMatrix< const Cost > MatrixView
Definition
graph.h:186
pbqp::write_dot
void write_dot(std::ostream &out, const Graph &graph, fe::View< OptionId > choices={})
Write graph in Graphviz DOT format with cost vectors and matrices as HTML-like labels.
Definition
dot.cpp:23
src
pbqp
dot.cpp
Generated by
1.18.0