| 243 | } |
| 244 | |
| 245 | bool FixupSourceAndSinkEdges(Graph* g) { |
| 246 | // Connect all nodes with no incoming edges to source. |
| 247 | // Connect all nodes with no outgoing edges to sink. |
| 248 | bool changed = false; |
| 249 | for (Node* n : g->nodes()) { |
| 250 | if (!n->IsSource() && n->in_edges().empty()) { |
| 251 | g->AddControlEdge(g->source_node(), n, |
| 252 | true /* skip test for duplicates */); |
| 253 | changed = true; |
| 254 | } |
| 255 | if (!n->IsSink() && n->out_edges().empty()) { |
| 256 | g->AddControlEdge(n, g->sink_node(), true /* skip test for duplicates */); |
| 257 | changed = true; |
| 258 | } |
| 259 | } |
| 260 | return changed; |
| 261 | } |
| 262 | |
| 263 | std::unordered_set<const Node*> FindExcludeDuplicationNodes(Graph* g, |
| 264 | std::unordered_set<const Node*>& visited) { |