Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / ade / ade / include / passes / topological_sort.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #ifndef TOPOLOGICAL_SORT_HPP
7 #define TOPOLOGICAL_SORT_HPP
8
9 #include <vector>
10 #include "utility"
11
12 #include "node.hpp"
13
14 #include "typed_graph.hpp"
15 #include "passes/pass_base.hpp"
16
17 #include "util/range.hpp"
18 #include "util/filter_range.hpp"
19
20 namespace ade
21 {
22 namespace passes
23 {
24
25 struct TopologicalSortData final
26 {
27     struct NodesFilter final
28     {
29         bool operator()(const ade::NodeHandle& node) const
30         {
31             return nullptr != node;
32         }
33     };
34
35     using NodesList = std::vector<NodeHandle>;
36     using NodesRange = util::FilterRange<util::IterRange<NodesList::const_iterator>, NodesFilter>;
37
38     TopologicalSortData(const NodesList& nodes):
39         m_nodes(nodes) {}
40
41     TopologicalSortData(NodesList&& nodes):
42         m_nodes(std::move(nodes)) {}
43
44     NodesRange nodes() const
45     {
46         return util::filter<NodesFilter>(util::toRange(m_nodes));
47     }
48
49     static const char* name();
50
51 private:
52     NodesList m_nodes;
53 };
54
55 struct TopologicalSort final
56 {
57     void operator()(TypedPassContext<TopologicalSortData> context) const;
58     static const char* name();
59 };
60
61 struct LazyTopologicalSortChecker final
62 {
63     bool nodeCreated(const Graph& graph, const NodeHandle& node);
64     bool nodeAboutToBeDestroyed(const Graph& graph, const NodeHandle& node);
65
66     bool edgeCreated(const Graph&, const EdgeHandle& edge);
67     bool edgeAboutToBeDestroyed(const Graph& graph, const EdgeHandle& edge);
68     bool edgeAboutToBeRelinked(const Graph& graph,
69                                const EdgeHandle& edge,
70                                const NodeHandle& newSrcNode,
71                                const NodeHandle& newDstNode);
72 };
73
74 }
75 }
76
77 #endif // TOPOLOGICAL_SORT_HPP