| 704 | } |
| 705 | |
| 706 | xla::StatusOr<Node*> ReplaceNode(Graph* g, Node* n, const NodeDef& node_def) { |
| 707 | // Create the replacement node. |
| 708 | Status s; |
| 709 | Node* new_node = g->AddNode(node_def, &s); |
| 710 | if (!s.ok()) { |
| 711 | return s; |
| 712 | } |
| 713 | |
| 714 | // Record original node's output edges and remove them first. This is to avoid |
| 715 | // multiple producers for dst nodes' input. |
| 716 | std::vector<OutEdgeInfo> out_edge_info; |
| 717 | std::vector<const Edge*> out_edges; |
| 718 | for (const Edge* edge : n->out_edges()) { |
| 719 | out_edges.push_back(edge); |
| 720 | out_edge_info.push_back( |
| 721 | {edge->dst(), edge->src_output(), edge->dst_input()}); |
| 722 | } |
| 723 | for (const Edge* edge : out_edges) { |
| 724 | g->RemoveEdge(edge); |
| 725 | } |
| 726 | |
| 727 | // Add original node's input and output edges to the replacement node. |
| 728 | for (const Edge* in_edge : n->in_edges()) { |
| 729 | g->AddEdge(in_edge->src(), in_edge->src_output(), new_node, |
| 730 | in_edge->dst_input()); |
| 731 | } |
| 732 | for (const OutEdgeInfo& out_edge : out_edge_info) { |
| 733 | g->AddEdge(new_node, out_edge.src_output, out_edge.dst, out_edge.dst_input); |
| 734 | } |
| 735 | |
| 736 | // Remove the original node. |
| 737 | g->RemoveNode(n); |
| 738 | |
| 739 | return new_node; |
| 740 | } |
| 741 | |
| 742 | xla::StatusOr<Node*> BuildIdentityNode( |
| 743 | Graph* graph, const string& node_name, DataType dtype, const Node* input, |
no test coverage detected