1 | //===- TosaToArithPass.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 Arith dialect. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "mlir/Conversion/TosaToArith/TosaToArith.h" |
14 | |
15 | #include "mlir/Dialect/Arith/IR/Arith.h" |
16 | #include "mlir/Dialect/Tosa/IR/TosaOps.h" |
17 | #include "mlir/Dialect/Tosa/Transforms/Passes.h" |
18 | #include "mlir/IR/PatternMatch.h" |
19 | #include "mlir/Pass/PassManager.h" |
20 | #include "mlir/Transforms/DialectConversion.h" |
21 | #include "mlir/Transforms/GreedyPatternRewriteDriver.h" |
22 | |
23 | namespace mlir { |
24 | #define GEN_PASS_DEF_TOSATOARITHPASS |
25 | #include "mlir/Conversion/Passes.h.inc" |
26 | } // namespace mlir |
27 | |
28 | using namespace mlir; |
29 | using namespace tosa; |
30 | |
31 | namespace { |
32 | struct TosaToArith : public impl::TosaToArithPassBase<TosaToArith> { |
33 | using Base::Base; |
34 | |
35 | void runOnOperation() override { |
36 | RewritePatternSet patterns(&getContext()); |
37 | ConversionTarget target(getContext()); |
38 | target.addIllegalOp<tosa::ConstOp>(); |
39 | target.addLegalDialect<arith::ArithDialect>(); |
40 | |
41 | mlir::tosa::populateTosaToArithConversionPatterns(patterns: &patterns); |
42 | |
43 | if (this->includeApplyRescale) { |
44 | mlir::tosa::populateTosaRescaleToArithConversionPatterns(patterns: &patterns, |
45 | include32Bit: this->use32Bit); |
46 | target.addIllegalOp<tosa::ApplyScaleOp>(); |
47 | } |
48 | |
49 | if (failed(applyPartialConversion(getOperation(), target, |
50 | std::move(patterns)))) |
51 | signalPassFailure(); |
52 | } |
53 | }; |
54 | } // namespace |
55 |