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/Pass/Pass.h" // from @llvm-project 22 #include "tensorflow/core/public/session.h" 23 24 namespace mlir { 25 namespace tf_saved_model { 26 27 // Creates a pass that optimizes tf_saved_model.global_tensor ops. 28 std::unique_ptr<OperationPass<ModuleOp>> CreateOptimizeGlobalTensorsPass(); 29 30 // Creates a pass that freezes tf_saved_model.global_tensor ops. 31 std::unique_ptr<OperationPass<ModuleOp>> CreateFreezeGlobalTensorsPass( 32 bool allow_mutable_tensors = false); 33 34 // Creates as pass that removes variables in the session initializer. 35 // This job is required with lifting variable passes. Originally, the session 36 // initializer function does assigning variables. However, the read-only 37 // variable assignments will be done via lifting variables pass by converting 38 // the read-only variables to constant ops, instead. This pass removes the 39 // redundant operations. This pass should be located in front of the pass for 40 // lifting read-only variables. 41 std::unique_ptr<OperationPass<ModuleOp>> 42 CreateRemoveVariablesInSessionInitializerPass(); 43 44 // Creates as pass that creates GlobalTensorOp for each variable from function 45 // arguments and converts the function arguments to the corresponding saved 46 // model arguments. 47 std::unique_ptr<OperationPass<ModuleOp>> CreateLiftVariablesPass( 48 ::tensorflow::Session* session); 49 50 // Creates a pass that removes duplicate 'tf_saved_model.bound_input' bindings. 51 std::unique_ptr<OperationPass<FuncOp>> CreateDedupBoundInputBindingPass(); 52 53 } // namespace tf_saved_model 54 } // namespace mlir 55 56 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_TF_SAVED_MODEL_PASSES_H_ 57