message: Rewrite tail recursion in loop optimizer as loop to avoid stack overflow.
diff: @@ -320,9 +320,16 @@ Status LoopInvariantNodeMotionOptimizer::RevertInvariantNodes() {
  return Status::OK();
  }
  -Status LoopInvariantNodeMotionOptimizer::FindInvariantNodes(NodeDef* node) {
  +Status LoopInvariantNodeMotionOptimizer::FindInvariantNodes(
  + NodeDef* start_node) {
  + std::vector<NodeDef*> stack;
  + stack.reserve(32);
  + stack.push_back(start_node);
  + while (!stack.empty()) {
  + NodeDef* node = stack.back();
  + stack.pop_back();
  auto consumers = node_map_->GetOutputs(node->name());
  - invariant_nodes_.insert(std::make_pair(node, consumers.size()));
  + invariant_nodes_.emplace(node, consumers.size());
  for (auto* consumer : consumers) {
  if (invariant_nodes_.count(consumer) || ModifiesFrameInfo(*consumer)) {
  continue;
  @@ -355,7 +362,8 @@ Status LoopInvariantNodeMotionOptimizer::FindInvariantNodes(NodeDef* node) {
  --iter->second;
  }
  }
  - TF_RETURN_IF_ERROR(FindInvariantNodes(consumer));
  + stack.push_back(consumer);
  + }
  }
  }
  return Status::OK();
  