Debian Codegraph @

mlir/lib/Conversion/TosaToTensor/TosaToTensorPass.cpp

raw
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/Transforms/DialectConversion.h"
21
22 namespace mlir {
23 #define GEN_PASS_DEF_TOSATOTENSORPASS
24 #include "mlir/Conversion/Passes.h.inc"
25 } // namespace mlir
26
27 using namespace mlir;
28 using namespace tosa;
29
30 namespace {
31 struct TosaToTensor : public impl::TosaToTensorPassBase<TosaToTensor> {
32 public:
33 void runOnOperation() override {
34 RewritePatternSet patterns(&getContext());
35 ConversionTarget target(getContext());
36 target.addIllegalOp<tosa::ConcatOp>();
37 target.addIllegalOp<tosa::ReshapeOp>();
38 target.addIllegalOp<tosa::SliceOp>();
39 target.addIllegalOp<tosa::PadOp>();
40 target.addLegalDialect<arith::ArithDialect>();
41 target.addLegalDialect<tensor::TensorDialect>();
42
43 TypeConverter converter;
44 mlir::tosa::populateTosaTypeConversion(converter);
45
46 mlir::tosa::populateTosaToTensorConversionPatterns(converter, &patterns);
47
48 if (failed(applyPartialConversion(getOperation(), target,
49 std::move(patterns))))
50 signalPassFailure();
51 }
52 };
53 } // namespace