| 844 | } |
| 845 | |
| 846 | bool MutableGraphView::AddFaninInternal(NodeDef* node, |
| 847 | const OutputPort& fanin) { |
| 848 | int num_regular_fanins = |
| 849 | NumFanins(*node, /*include_controlling_nodes=*/false); |
| 850 | bool input_is_control = IsOutputPortControlling(fanin); |
| 851 | bool can_dedup_control_with_regular_input = |
| 852 | CanDedupControlWithRegularInput(*this, *fanin.node); |
| 853 | // Don't add duplicate control dependencies. |
| 854 | if (input_is_control) { |
| 855 | const int start = |
| 856 | can_dedup_control_with_regular_input ? 0 : num_regular_fanins; |
| 857 | for (int i = start; i < node->input_size(); ++i) { |
| 858 | if (ParseTensorName(node->input(i)).node() == fanin.node->name()) { |
| 859 | return false; |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | InputPort input; |
| 865 | input.node = node; |
| 866 | input.port_id = input_is_control ? Graph::kControlSlot : num_regular_fanins; |
| 867 | |
| 868 | node->add_input(TensorIdToString({fanin.node->name(), fanin.port_id})); |
| 869 | if (!input_is_control) { |
| 870 | const int last_node_input = node->input_size() - 1; |
| 871 | // If there are control dependencies in node, move newly inserted fanin to |
| 872 | // be before such control dependencies. |
| 873 | if (num_regular_fanins < last_node_input) { |
| 874 | node->mutable_input()->SwapElements(last_node_input, num_regular_fanins); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | fanouts()[fanin].insert(input); |
| 879 | if (max_regular_output_port()[fanin.node] < fanin.port_id) { |
| 880 | max_regular_output_port()[fanin.node] = fanin.port_id; |
| 881 | } |
| 882 | |
| 883 | // Update max input port and dedup control dependencies. |
| 884 | if (!input_is_control) { |
| 885 | max_regular_input_port()[node] = num_regular_fanins; |
| 886 | if (can_dedup_control_with_regular_input) { |
| 887 | RemoveControllingFaninInternal(node, fanin.node); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | return true; |
| 892 | } |
| 893 | |
| 894 | Status MutableGraphView::AddRegularFanin(absl::string_view node_name, |
| 895 | const TensorId& fanin) { |
nothing calls this directly
no test coverage detected