• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_XLA_MODULE_IMPORTER_H_
17 #define TENSORFLOW_COMPILER_MLIR_XLA_MODULE_IMPORTER_H_
18 
19 #include <unordered_map>
20 
21 #include "mlir/IR/Builders.h"  // from @llvm-project
22 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
23 #include "mlir/IR/MLIRContext.h"  // from @llvm-project
24 #include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
25 #include "tensorflow/compiler/mlir/tensorflow/utils/error_util.h"
26 #include "tensorflow/compiler/xla/status.h"
27 #include "tensorflow/compiler/xla/xla_data.pb.h"
28 
29 namespace xla {
30 class HloModule;
31 class HloModuleProto;
32 class HloComputation;
33 class HloInstruction;
34 class Shape;
35 
36 // Importer that takes an HloModule and imports it as an MLIR module in the XLA
37 // dialect. HloModuleImporter does not take ownership.
38 class HloModuleImporter {
39  public:
40   explicit HloModuleImporter(mlir::ModuleOp module,
41                              bool import_all_computation = false);
42 
43   // Import the HloModule into the MLIR Module.
44   Status Import(const xla::HloModule& module);
45 
46   // Import the HloModuleProto into the MLIR Module.
47   Status Import(const xla::HloModuleProto& module);
48 
49  private:
50   bool import_all_computation_;
51   mlir::ModuleOp module_;
52   mlir::Builder builder_;
53 
54   // Map for tracking which MLIR function map to which HLO Computation. This
55   // tracks functions as they are imported and provides a quick lookup for
56   // functions invoked by control flow related operations (e.g. while, call).
57   std::unordered_map<const xla::HloComputation*, mlir::FuncOp> function_map_;
58 };
59 
60 }  // namespace xla
61 
62 #endif  // TENSORFLOW_COMPILER_MLIR_XLA_MODULE_IMPORTER_H_
63