MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PropagateConstIntoIfNode

Function PropagateConstIntoIfNode

tensorflow/compiler/tf2xla/tf2xla_util.cc:217–243  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
217Status 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.

Callers 1

Calls 4

input_nodeMethod · 0.80
num_inputsMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected