1 /* Copyright 2020 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_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
18 
19 #include <memory>
20 
21 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
22 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
23 #include "mlir/Pass/Pass.h"  // from @llvm-project
24 #include "tensorflow/core/public/session.h"
25 
26 namespace mlir {
27 namespace tf_saved_model {
28 
29 // Creates a pass that optimizes tf_saved_model.global_tensor ops.
30 std::unique_ptr<OperationPass<ModuleOp>> CreateOptimizeGlobalTensorsPass();
31 
32 // Creates a pass that freezes tf_saved_model.global_tensor ops.
33 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeGlobalTensorsPass(
34     bool allow_mutable_tensors = false);
35 
36 // Creates a pass that freezes tf_saved_model.asset ops.
37 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeAssetsPass(
38     std::string saved_model_dir = "");
39 
40 // Creates as pass that removes variables in the session initializer.
41 // This job is required with lifting variable passes. Originally, the session
42 // initializer function does assigning variables. However, the read-only
43 // variable assignments will be done via lifting variables pass by converting
44 // the read-only variables to constant ops, instead. This pass removes the
45 // redundant operations. This pass should be located in front of the pass for
46 // lifting read-only variables.
47 std::unique_ptr<OperationPass<ModuleOp>>
48 CreateRemoveVariablesInSessionInitializerPass();
49 
50 // Creates a pass that removes duplicate 'tf_saved_model.bound_input' bindings.
51 std::unique_ptr<OperationPass<func::FuncOp>> CreateDedupBoundInputBindingPass();
52 
53 #define GEN_PASS_REGISTRATION
54 #include "tensorflow/compiler/mlir/tensorflow/transforms/tf_savedmodel_passes.h.inc"
55 
56 }  // namespace tf_saved_model
57 
58 }  // namespace mlir
59 
60 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_
61