1 /* Copyright 2021 Google Inc. 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 #include "mlir/IR/Dialect.h" // from @llvm-project
17 #include "mlir/IR/MLIRContext.h" // from @llvm-project
18 #include "mlir/IR/PatternMatch.h" // from @llvm-project
19 #include "mlir/InitAllDialects.h" // from @llvm-project
20 #include "mlir/InitAllPasses.h" // from @llvm-project
21 #include "mlir/Reducer/ReductionPatternInterface.h" // from @llvm-project
22 #include "mlir/Tools/mlir-reduce/MlirReduceMain.h" // from @llvm-project
23 #include "tensorflow/compiler/mlir/init_mlir.h"
24 #include "tensorflow/compiler/mlir/lite/ir/tfl_ops.h"
25 #include "tensorflow/compiler/mlir/tensorflow/dialect_registration.h"
26 #include "tensorflow/compiler/mlir/tensorflow/transforms/passes.h"
27 #include "tensorflow/compiler/mlir/tools/kernel_gen/ir/tf_framework_ops.h"
28 #include "tensorflow/compiler/mlir/xla/transforms/passes.h"
29 #include "tensorflow/compiler/mlir/xla/transforms/xla_passes.h"
30 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Dialect/lhlo/transforms/register_passes.h"
31 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Dialect/mhlo/IR/register.h"
32 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Dialect/mhlo/transforms/register_passes.h"
33
34 namespace {
35
36 #include "tensorflow/compiler/mlir/tensorflow/transforms/reducer/tf_reduce_patterns.inc"
37
38 struct TFReductionPatternInterface
39 : public mlir::DialectReductionPatternInterface {
40 public:
TFReductionPatternInterface__anon5e6f59740111::TFReductionPatternInterface41 explicit TFReductionPatternInterface(mlir::Dialect *dialect)
42 : DialectReductionPatternInterface(dialect) {}
43
populateReductionPatterns__anon5e6f59740111::TFReductionPatternInterface44 void populateReductionPatterns(
45 mlir::RewritePatternSet &patterns) const final {
46 populateWithGenerated(patterns);
47 }
48 };
49
50 } // namespace
51
main(int argc,char * argv[])52 int main(int argc, char *argv[]) {
53 tensorflow::InitMlir y(&argc, &argv);
54
55 mlir::registerAllPasses();
56 mlir::registerTensorFlowPasses();
57 mlir::TFDevice::registerTensorFlowDevicePasses();
58 mlir::mhlo::registerAllMhloPasses();
59 mlir::lmhlo::registerAllLmhloPasses();
60 // These are in compiler/mlir/xla and not part of the above MHLO passes.
61 mlir::mhlo::registerTfXlaPasses();
62 mlir::mhlo::registerXlaPasses();
63 mlir::mhlo::registerLegalizeTFPass();
64 mlir::mhlo::registerLegalizeTFControlFlowPass();
65 mlir::mhlo::registerLegalizeTfTypesPassPass();
66
67 mlir::DialectRegistry registry;
68 mlir::registerAllDialects(registry);
69 mlir::RegisterAllTensorFlowDialects(registry);
70 registry.addExtension(
71 +[](mlir::MLIRContext *ctx, mlir::TF::TensorFlowDialect *dialect) {
72 dialect->addInterfaces<TFReductionPatternInterface>();
73 });
74 mlir::mhlo::registerAllMhloDialects(registry);
75 registry.insert<mlir::TFL::TensorFlowLiteDialect>();
76 registry.insert<mlir::kernel_gen::tf_framework::TFFrameworkDialect>();
77
78 mlir::MLIRContext context(registry);
79
80 return failed(mlirReduceMain(argc, argv, context));
81 }
82