Rob Suderman | 16abaca | 2021-02-26 02:08:29 | [diff] [blame] | 1 | //===- TosaToStandardPass.cpp - Lowering Tosa to Linalg Dialect -----------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This transformation pass legalizes Tosa operations to the Standard dialect. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "../PassDetail.h" |
| 14 | #include "mlir/Conversion/TosaToStandard/TosaToStandard.h" |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 15 | #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" |
River Riddle | 23aa5a7 | 2022-02-26 22:49:54 | [diff] [blame^] | 16 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
Rob Suderman | 16abaca | 2021-02-26 02:08:29 | [diff] [blame] | 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" |
| 18 | #include "mlir/Dialect/Tosa/IR/TosaOps.h" |
| 19 | #include "mlir/Dialect/Tosa/Transforms/PassDetail.h" |
| 20 | #include "mlir/Dialect/Tosa/Transforms/Passes.h" |
| 21 | #include "mlir/IR/PatternMatch.h" |
| 22 | #include "mlir/Pass/PassManager.h" |
| 23 | #include "mlir/Transforms/DialectConversion.h" |
| 24 | #include "mlir/Transforms/GreedyPatternRewriteDriver.h" |
| 25 | |
| 26 | using namespace mlir; |
| 27 | using namespace tosa; |
| 28 | |
| 29 | namespace { |
| 30 | struct TosaToStandard : public TosaToStandardBase<TosaToStandard> { |
| 31 | public: |
| 32 | void runOnOperation() override { |
Chris Lattner | dc4e913 | 2021-03-22 23:58:34 | [diff] [blame] | 33 | RewritePatternSet patterns(&getContext()); |
Rob Suderman | 16abaca | 2021-02-26 02:08:29 | [diff] [blame] | 34 | ConversionTarget target(getContext()); |
| 35 | target.addIllegalOp<tosa::ConstOp>(); |
Rob Suderman | f4bb076 | 2021-03-17 22:53:18 | [diff] [blame] | 36 | target.addIllegalOp<tosa::SliceOp>(); |
Rob Suderman | 286a9d4 | 2021-03-18 23:14:05 | [diff] [blame] | 37 | target.addIllegalOp<tosa::ApplyScaleOp>(); |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 38 | target.addLegalDialect<arith::ArithmeticDialect>(); |
River Riddle | 23aa5a7 | 2022-02-26 22:49:54 | [diff] [blame^] | 39 | target.addLegalDialect<func::FuncDialect>(); |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 40 | target.addLegalDialect<tensor::TensorDialect>(); |
Rob Suderman | 16abaca | 2021-02-26 02:08:29 | [diff] [blame] | 41 | |
Chris Lattner | 3a506b3 | 2021-03-20 23:29:41 | [diff] [blame] | 42 | mlir::tosa::populateTosaToStandardConversionPatterns(&patterns); |
| 43 | if (failed(applyPartialConversion(getOperation(), target, |
| 44 | std::move(patterns)))) |
Rob Suderman | 16abaca | 2021-02-26 02:08:29 | [diff] [blame] | 45 | signalPassFailure(); |
| 46 | } |
| 47 | }; |
| 48 | } // namespace |
| 49 | |
| 50 | std::unique_ptr<Pass> mlir::tosa::createTosaToStandard() { |
| 51 | return std::make_unique<TosaToStandard>(); |
| 52 | } |
| 53 | |
| 54 | void mlir::tosa::addTosaToStandardPasses(OpPassManager &pm) { |
| 55 | pm.addNestedPass<FuncOp>(createTosaToStandard()); |
| 56 | } |