message: Implement DFS using a loop instead of recursion to avoid stack overflow.
diff: @@ -430,18 +430,28 @@ Status SimpleGraphView::Initialize(const GraphDef& graph, bool dedup_inputs,
  }
  void SimpleGraphView::DepthFirstSearch(
  - const std::unordered_set<string>& op_types_to_traverse, int node_idx,
  + const std::unordered_set<string>& op_types_to_traverse, int root_node,
  std::set<int>* nodes_found) const {
  - if (nodes_found->find(node_idx) != nodes_found->end()) {
  + nodes_found->clear();
  + const string& op_type = graph_->node(root_node).op();
  + if (op_types_to_traverse.find(op_type) == op_types_to_traverse.end()) {
  return;
  }
  + std::vector<int> stack;
  + stack.reserve(32);
  + stack.push_back(root_node);
  + while (!stack.empty()) {
  + const int node_idx = stack.back();
  + stack.pop_back();
  nodes_found->insert(node_idx);
  const string& op_type = graph_->node(node_idx).op();
  - if (op_types_to_traverse.find(op_type) == op_types_to_traverse.end()) {
  - return;
  - }
  + if (op_types_to_traverse.find(op_type) != op_types_to_traverse.end()) {
  for (auto output_idx : this->outputs(node_idx)) {
  - DepthFirstSearch(op_types_to_traverse, output_idx, nodes_found);
  + if (nodes_found->find(output_idx) == nodes_found->end()) {
  + stack.push_back(output_idx);
  + }
  + }
  + }
  }
  }
  