| 70 | } // namespace detail |
| 71 | |
| 72 | std::vector<NodeID> bfs(Graph &g) |
| 73 | { |
| 74 | std::vector<NodeID> bfs_order_vector; |
| 75 | |
| 76 | // Created visited vector |
| 77 | std::vector<bool> visited(g.nodes().size(), false); |
| 78 | |
| 79 | // Create BFS queue |
| 80 | std::list<NodeID> queue; |
| 81 | |
| 82 | // Push inputs and mark as visited |
| 83 | for (auto &input : g.nodes(NodeType::Input)) |
| 84 | { |
| 85 | if (input != EmptyNodeID) |
| 86 | { |
| 87 | visited[input] = true; |
| 88 | queue.push_back(input); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Push const nodes and mark as visited |
| 93 | for (auto &const_node : g.nodes(NodeType::Const)) |
| 94 | { |
| 95 | if (const_node != EmptyNodeID) |
| 96 | { |
| 97 | visited[const_node] = true; |
| 98 | queue.push_back(const_node); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Iterate over vector and edges |
| 103 | while (!queue.empty()) |
| 104 | { |
| 105 | // Dequeue a node from queue and process |
| 106 | NodeID n = queue.front(); |
| 107 | bfs_order_vector.push_back(n); |
| 108 | queue.pop_front(); |
| 109 | |
| 110 | const INode *node = g.node(n); |
| 111 | ARM_COMPUTE_ERROR_ON(node == nullptr); |
| 112 | for (const auto &eid : node->output_edges()) |
| 113 | { |
| 114 | const Edge *e = g.edge(eid); |
| 115 | ARM_COMPUTE_ERROR_ON(e == nullptr); |
| 116 | if (!visited[e->consumer_id()] && detail::all_inputs_are_visited(e->consumer(), visited)) |
| 117 | { |
| 118 | visited[e->consumer_id()] = true; |
| 119 | queue.push_back(e->consumer_id()); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return bfs_order_vector; |
| 125 | } |
| 126 | |
| 127 | std::vector<NodeID> dfs(Graph &g) |
| 128 | { |
nothing calls this directly
no test coverage detected