xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/tf2xla/mlir_bridge_pass.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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/tf2xla/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(
34       const DeviceSet* device_set, const ConfigProto& config_proto,
35       const Graph& graph,
36       const FunctionLibraryDefinition& function_library) const override;
37 
38   // This should be used as a thin mapper around mlir::ModulePass::runOnModule
39   // API integrated with the Tensorflow runtime.
40   Status Run(const ConfigProto& config_proto, mlir::ModuleOp module,
41              const Graph& graph,
42              const FunctionLibraryDefinition& function_library) override;
43 };
44 
45 // This pass uses MLIR to implement all the conversion steps to target XLA from
46 // a TensorFlow V1 Graph. It is meant to expose a very limited set of
47 // functionalities during the bring-up of MLIR-based bridge.
48 class MlirBridgeV1CompatPass : public MlirV1CompatOptimizationPass {
49  public:
name()50   llvm::StringRef name() const override { return "bridge"; }
51 
52   MlirOptimizationPassState GetPassState(
53       const DeviceSet* device_set, const ConfigProto& config_proto,
54       const Graph& graph,
55       const FunctionLibraryDefinition& function_library) const override;
56 
57   // This should be used as a thin mapper around mlir::ModulePass::runOnModule
58   // API integrated with the Tensorflow runtime.
59   Status Run(const GraphOptimizationPassOptions& options,
60              mlir::ModuleOp module) override;
61 };
62 
63 }  // namespace tensorflow
64 
65 #endif  // TENSORFLOW_COMPILER_TF2XLA_MLIR_BRIDGE_PASS_H_
66