| 125 | } |
| 126 | |
| 127 | std::vector<NodeID> dfs(Graph &g) |
| 128 | { |
| 129 | std::vector<NodeID> dfs_order_vector; |
| 130 | |
| 131 | // Created visited vector |
| 132 | std::vector<bool> visited(g.nodes().size(), false); |
| 133 | |
| 134 | // Create DFS stack |
| 135 | std::stack<NodeID> stack; |
| 136 | |
| 137 | // Push inputs and mark as visited |
| 138 | for (auto &input : g.nodes(NodeType::Input)) |
| 139 | { |
| 140 | if (input != EmptyNodeID) |
| 141 | { |
| 142 | visited[input] = true; |
| 143 | stack.push(input); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Push const nodes and mark as visited |
| 148 | for (auto &const_node : g.nodes(NodeType::Const)) |
| 149 | { |
| 150 | if (const_node != EmptyNodeID) |
| 151 | { |
| 152 | visited[const_node] = true; |
| 153 | stack.push(const_node); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Iterate over vector and edges |
| 158 | while (!stack.empty()) |
| 159 | { |
| 160 | // Pop a node from stack and process |
| 161 | NodeID n = stack.top(); |
| 162 | dfs_order_vector.push_back(n); |
| 163 | stack.pop(); |
| 164 | |
| 165 | // Mark node as visited |
| 166 | if (!visited[n]) |
| 167 | { |
| 168 | visited[n] = true; |
| 169 | } |
| 170 | |
| 171 | const INode *node = g.node(n); |
| 172 | ARM_COMPUTE_ERROR_ON(node == nullptr); |
| 173 | // Reverse iterate to push branches from right to left and pop on the opposite order |
| 174 | for (const auto &eid : arm_compute::utils::iterable::reverse_iterate(node->output_edges())) |
| 175 | { |
| 176 | const Edge *e = g.edge(eid); |
| 177 | ARM_COMPUTE_ERROR_ON(e == nullptr); |
| 178 | if (!visited[e->consumer_id()] && detail::all_inputs_are_visited(e->consumer(), visited)) |
| 179 | { |
| 180 | stack.push(e->consumer_id()); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 |
no test coverage detected