For an "If" node in graph `g`, if it has Const node inputs, rewrite its then/else branch function to replace _Arg nodes with those Const inputs.
| 215 | // For an "If" node in graph `g`, if it has Const node inputs, rewrite its |
| 216 | // then/else branch function to replace _Arg nodes with those Const inputs. |
| 217 | Status PropagateConstIntoIfNode(Graph* g, Node* if_node, |
| 218 | const FunctionLibraryDefinition* lookup_fld, |
| 219 | FunctionLibraryDefinition* fld) { |
| 220 | // Notice that first input for If node is predicate; other inputs are function |
| 221 | // inputs. |
| 222 | std::unordered_map<int, const Node*> const_input_index_to_node; |
| 223 | for (int i = 1; i < if_node->num_inputs(); i++) { |
| 224 | const Node* input_node; |
| 225 | TF_RETURN_IF_ERROR(if_node->input_node(i, &input_node)); |
| 226 | if (input_node->type_string() == "Const") { |
| 227 | const_input_index_to_node[i - 1] = input_node; |
| 228 | } |
| 229 | } |
| 230 | if (const_input_index_to_node.empty()) { |
| 231 | return Status::OK(); |
| 232 | } |
| 233 | |
| 234 | // Rewrite "then_branch" and "else_branch" function, replace usage of those |
| 235 | // _Arg nodes with corresponding const node. |
| 236 | for (const auto& attr_name : |
| 237 | std::vector<string>{"then_branch", "else_branch"}) { |
| 238 | TF_RETURN_IF_ERROR(PropagateConstIntoFuncAttr( |
| 239 | if_node, attr_name, const_input_index_to_node, lookup_fld, fld)); |
| 240 | } |
| 241 | |
| 242 | return Status::OK(); |
| 243 | } |
| 244 | |
| 245 | // For a "While" node in graph `g`, if it has Const node inputs, rewrite its |
| 246 | // cond/body function to replace _Arg nodes with those Const inputs. |
no test coverage detected