1 // Copyright (C) 2018 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
6 #ifndef TOPOLOGICAL_SORT_HPP
7 #define TOPOLOGICAL_SORT_HPP
14 #include "typed_graph.hpp"
15 #include "passes/pass_base.hpp"
17 #include "util/range.hpp"
18 #include "util/filter_range.hpp"
25 struct TopologicalSortData final
27 struct NodesFilter final
29 bool operator()(const ade::NodeHandle& node) const
31 return nullptr != node;
35 using NodesList = std::vector<NodeHandle>;
36 using NodesRange = util::FilterRange<util::IterRange<NodesList::const_iterator>, NodesFilter>;
38 TopologicalSortData(const NodesList& nodes):
41 TopologicalSortData(NodesList&& nodes):
42 m_nodes(std::move(nodes)) {}
44 NodesRange nodes() const
46 return util::filter<NodesFilter>(util::toRange(m_nodes));
49 static const char* name();
55 struct TopologicalSort final
57 void operator()(TypedPassContext<TopologicalSortData> context) const;
58 static const char* name();
61 struct LazyTopologicalSortChecker final
63 bool nodeCreated(const Graph& graph, const NodeHandle& node);
64 bool nodeAboutToBeDestroyed(const Graph& graph, const NodeHandle& node);
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);
77 #endif // TOPOLOGICAL_SORT_HPP