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 "../PassDetail.h"
14 #include "mlir/Conversion/TosaToTensor/TosaToTensor.h"
15 #include "mlir/Dialect/Tensor/IR/Tensor.h"
16 #include "mlir/Dialect/Tosa/IR/TosaOps.h"
17 #include "mlir/Dialect/Tosa/Transforms/PassDetail.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 
24 using namespace mlir;
25 using namespace tosa;
26 
27 namespace {
28 struct TosaToTensor : public TosaToTensorBase<TosaToTensor> {
29 public:
30   void runOnOperation() override {
31     RewritePatternSet patterns(&getContext());
32     ConversionTarget target(getContext());
33     target.addIllegalOp<tosa::SliceOp>();
34     target.addLegalDialect<tensor::TensorDialect>();
35 
36     mlir::tosa::populateTosaToTensorConversionPatterns(&patterns);
37 
38     if (failed(applyPartialConversion(getOperation(), target,
39                                       std::move(patterns))))
40       signalPassFailure();
41   }
42 };
43 } // namespace
44 
45 std::unique_ptr<Pass> mlir::tosa::createTosaToTensor() {
46   return std::make_unique<TosaToTensor>();
47 }
48