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_MLIR_BRIDGE_PASS_H_ 17 #define TENSORFLOW_COMPILER_TF2XLA_MLIR_BRIDGE_PASS_H_ 18 19 #include "tensorflow/compiler/mlir/mlir_bridge_rollout_policy.h" 20 #include "llvm/ADT/StringRef.h" 21 #include "tensorflow/compiler/jit/flags.h" 22 #include "tensorflow/compiler/mlir/mlir_graph_optimization_pass.h" 23 24 namespace tensorflow { 25 26 // This pass uses MLIR to implement all the conversion steps to target XLA from 27 // a TensorFlow Function Graph. It is meant to expose a very limited set of 28 // functionalities during the bring-up of MLIR-based bridge. 29 class MlirBridgePass : public MlirOptimizationPass { 30 public: name()31 llvm::StringRef name() const override { return "bridge"; } 32 33 MlirOptimizationPassState GetPassState(const DeviceSet* device_set, 34 const ConfigProto& config_proto, 35 const Graph& graph) const override; 36 37 // This should be used as a thin mapper around mlir::ModulePass::runOnModule 38 // API integrated with the Tensorflow runtime. 39 Status Run(const ConfigProto& config_proto, mlir::ModuleOp module, 40 const Graph& graph) override; 41 }; 42 43 // This pass uses MLIR to implement all the conversion steps to target XLA from 44 // a TensorFlow V1 Graph. It is meant to expose a very limited set of 45 // functionalities during the bring-up of MLIR-based bridge. 46 class MlirBridgeV1CompatPass : public MlirV1CompatOptimizationPass { 47 public: name()48 llvm::StringRef name() const override { return "bridge"; } 49 50 bool IsEnabled(const DeviceSet* device_set, const ConfigProto& config_proto, 51 const Graph& graph) const override; 52 53 // This should be used as a thin mapper around mlir::ModulePass::runOnModule 54 // API integrated with the Tensorflow runtime. 55 Status Run(const GraphOptimizationPassOptions& options, 56 mlir::ModuleOp module) override; 57 }; 58 59 } // namespace tensorflow 60 61 #endif // TENSORFLOW_COMPILER_TF2XLA_MLIR_BRIDGE_PASS_H_ 62