1//===- TosaToTensorPass.cpp - Lowering Tosa to Tensor 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 Tensor dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Conversion/TosaToTensor/TosaToTensor.h"
14
15#include "mlir/Dialect/Arith/IR/Arith.h"
16#include "mlir/Dialect/Tensor/IR/Tensor.h"
17#include "mlir/Dialect/Tosa/IR/TosaOps.h"
18#include "mlir/Dialect/Tosa/Transforms/Passes.h"
19#include "mlir/IR/PatternMatch.h"
20#include "mlir/Pass/PassManager.h"
21#include "mlir/Transforms/DialectConversion.h"
22#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
23
24namespace mlir {
25#define GEN_PASS_DEF_TOSATOTENSOR
26#include "mlir/Conversion/Passes.h.inc"
27} // namespace mlir
28
29using namespace mlir;
30using namespace tosa;
31
32namespace {
33struct TosaToTensor : public impl::TosaToTensorBase<TosaToTensor> {
34public:
35 void runOnOperation() override {
36 RewritePatternSet patterns(&getContext());
37 ConversionTarget target(getContext());
38 target.addIllegalOp<tosa::ConcatOp>();
39 target.addIllegalOp<tosa::ReshapeOp>();
40 target.addIllegalOp<tosa::SliceOp>();
41 target.addIllegalOp<tosa::PadOp>();
42 target.addLegalDialect<arith::ArithDialect>();
43 target.addLegalDialect<tensor::TensorDialect>();
44
45 mlir::tosa::populateTosaToTensorConversionPatterns(patterns: &patterns);
46
47 if (failed(applyPartialConversion(getOperation(), target,
48 std::move(patterns))))
49 signalPassFailure();
50 }
51};
52} // namespace
53
54std::unique_ptr<Pass> mlir::tosa::createTosaToTensor() {
55 return std::make_unique<TosaToTensor>();
56}
57

source code of mlir/lib/Conversion/TosaToTensor/TosaToTensorPass.cpp