docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/graph/graphviz.hpp>
4#include <boost/lexical_cast.hpp>
5#include <cassert>
6#include <functional>
7#include <iostream>
8#include <list>
9#include <memory>
10#include <ranges>
11#include <string>
12#include <unordered_map>
13#include <unordered_set>
14
15#include "function.h"
23#include "sdfg/function.h"
24#include "sdfg/graph/graph.h"
26
27namespace sdfg {
28
29namespace builder {
30class SDFGBuilder;
32} // namespace builder
33
34class SDFG : public Function {
37
38private:
39 // Control-Flow Graph
40 graph::Graph graph_;
41 std::unordered_map<graph::Vertex, std::unique_ptr<control_flow::State>, boost::hash<graph::Vertex>> states_;
42 std::unordered_map<graph::Edge, std::unique_ptr<control_flow::InterstateEdge>, boost::hash<graph::Edge>> edges_;
43
44 const control_flow::State* start_state_;
45
46public:
47 SDFG(const std::string& name, FunctionType type);
48 SDFG(const std::string& name, FunctionType type, const types::IType& return_type);
49
50 SDFG(const SDFG& sdfg) = delete;
51 SDFG& operator=(const SDFG&) = delete;
52
53 void validate() const override;
54
55 /***** Section: Graph *****/
56
57 auto states() const {
58 return std::views::values(this->states_) | std::views::transform(helpers::indirect<control_flow::State>) |
59 std::views::transform(helpers::add_const<control_flow::State>);
60 };
61
62 auto edges() const {
63 return std::views::values(this->edges_) |
66 };
67
68 auto in_edges(const control_flow::State& state) const {
69 auto [eb, ee] = boost::in_edges(state.vertex(), this->graph_);
70 auto edges = std::ranges::subrange(eb, ee);
71
72 // Convert Edge to const InterstateEdge&
73 auto interstate_edges =
74 std::views::transform(
75 edges,
76 [&lookup_table = this->edges_](const graph::Edge& edge) -> control_flow::InterstateEdge& {
77 return *(lookup_table.find(edge)->second);
78 }
79 ) |
81
82 return interstate_edges;
83 };
84
85 auto out_edges(const control_flow::State& state) const {
86 auto [eb, ee] = boost::out_edges(state.vertex(), this->graph_);
87 auto edges = std::ranges::subrange(eb, ee);
88
89 // Convert Edge to const InterstateEdge&
90 auto interstate_edges =
91 std::views::transform(
92 edges,
93 [&lookup_table = this->edges_](const graph::Edge& edge) -> control_flow::InterstateEdge& {
94 return *(lookup_table.find(edge)->second);
95 }
96 ) |
98
99 return interstate_edges;
100 };
101
103
104 auto terminal_states() const {
105 return this->states() | std::views::filter([this](const control_flow::State& state) {
106 return this->out_degree(state) == 0;
107 });
108 };
109
110 size_t in_degree(const control_flow::State& state) const;
111
112 size_t out_degree(const control_flow::State& state) const;
113
114 bool is_adjacent(const control_flow::State& src, const control_flow::State& dst) const;
115
117
118 std::unordered_map<const control_flow::State*, const control_flow::State*> dominator_tree() const;
119
120 std::unordered_map<const control_flow::State*, const control_flow::State*> post_dominator_tree();
121
122 std::list<const control_flow::InterstateEdge*> back_edges() const;
123
124 std::list<std::list<const control_flow::InterstateEdge*>>
126
127 void as_dot(std::ostream& out) const;
128};
129
130} // namespace sdfg
Access nodes for reading/writing data in the dataflow graph.
const types::IType & return_type() const
FunctionType type() const
Function(const std::string &name, FunctionType type)
const std::string & name() const
SDFG(const std::string &name, FunctionType type, const types::IType &return_type)
const control_flow::InterstateEdge & edge(const control_flow::State &src, const control_flow::State &dst) const
auto terminal_states() const
Definition sdfg.h:104
std::unordered_map< const control_flow::State *, const control_flow::State * > dominator_tree() const
SDFG(const SDFG &sdfg)=delete
auto edges() const
Definition sdfg.h:62
bool is_adjacent(const control_flow::State &src, const control_flow::State &dst) const
size_t in_degree(const control_flow::State &state) const
void as_dot(std::ostream &out) const
std::list< const control_flow::InterstateEdge * > back_edges() const
auto states() const
Definition sdfg.h:57
void validate() const override
Validates the function.
auto in_edges(const control_flow::State &state) const
Definition sdfg.h:68
const control_flow::State & start_state() const
size_t out_degree(const control_flow::State &state) const
std::list< std::list< const control_flow::InterstateEdge * > > all_simple_paths(const control_flow::State &src, const control_flow::State &dst) const
auto out_edges(const control_flow::State &state) const
Definition sdfg.h:85
std::unordered_map< const control_flow::State *, const control_flow::State * > post_dominator_tree()
SDFG & operator=(const SDFG &)=delete
SDFG(const std::string &name, FunctionType type)
Definition sdfg_builder.h:13
Note: Even though the class references unique_ptr, it will never delete an SDFG it has a reference to...
Definition structured_sdfg_builder.h:44
An edge connecting two states in an SDFG control-flow graph.
Definition interstate_edge.h:71
A state in a Stateful DataFlow Graph (SDFG).
Definition state.h:38
graph::Vertex vertex() const
Returns the graph vertex representing this state.
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
Base class for all nodes in the dataflow graph.
Edges in the dataflow graph representing data movement.
Definition function_builder.h:10
boost::graph_traits< Graph >::edge_descriptor Edge
Definition graph.h:26
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS > Graph
Definition graph.h:24
const T & add_const(T &s)
Definition helpers.h:44
T & indirect(const std::unique_ptr< T > &ptr)
Definition helpers.h:39
Definition analysis.h:7
StringEnum FunctionType
Definition function.h:37
Simple computational operations in the dataflow graph.