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

source code of mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp