1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_CONTROL_FLOW_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_CONTROL_FLOW_H_
18 
19 #include "tensorflow/compiler/xla/status_macros.h"
20 #include "tensorflow/core/common_runtime/optimization_registry.h"
21 #include "tensorflow/core/framework/function.h"
22 #include "tensorflow/core/graph/graph.h"
23 
24 namespace tensorflow {
25 
26 // Transformation that converts tf.while_loop() loops into functional While
27 // operators and tf.cond() conditionals into function If operators, suitable for
28 // XLA compilation. If lookup_library is provided, use it to make the library
29 // for control flow self-contained.
30 Status FunctionalizeControlFlow(Graph* graph,
31                                 FunctionLibraryDefinition* library);
32 Status FunctionalizeControlFlow(const FunctionLibraryDefinition* lookup_library,
33                                 Graph* graph,
34                                 FunctionLibraryDefinition* library);
35 
36 Status FunctionalizeControlFlowForGraphDef(GraphDef* graph_def,
37                                            FunctionLibraryDefinition* library);
38 Status FunctionalizeControlFlowForGraphDef(
39     const FunctionLibraryDefinition* lookup_library, GraphDef* graph_def,
40     FunctionLibraryDefinition* library);
41 
42 // This pass looks at the graph and all associated FunctionDefs, and turns
43 // traditional control flow structure (Switch/Merge/etc.) into functional
44 // control flow structure (If/While).
45 class FunctionalizeControlFlowPass : public GraphOptimizationPass {
46  public:
47   Status Run(const GraphOptimizationPassOptions& options) override;
48 };
49 
50 }  // namespace tensorflow
51 
52 #endif  // TENSORFLOW_COMPILER_TF2XLA_FUNCTIONALIZE_CONTROL_FLOW_H_
53