blob: fb1e9f3d10799f999b412284a8c35262b47fed63 [file] [log] [blame]
Rob Suderman16abaca2021-02-26 02:08:291//===- TosaToStandardPass.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 Standard dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "../PassDetail.h"
14#include "mlir/Conversion/TosaToStandard/TosaToStandard.h"
Mogballa54f4ea2021-10-12 23:14:5715#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
River Riddle23aa5a72022-02-26 22:49:5416#include "mlir/Dialect/Func/IR/FuncOps.h"
Rob Suderman16abaca2021-02-26 02:08:2917#include "mlir/Dialect/Tensor/IR/Tensor.h"
18#include "mlir/Dialect/Tosa/IR/TosaOps.h"
19#include "mlir/Dialect/Tosa/Transforms/PassDetail.h"
20#include "mlir/Dialect/Tosa/Transforms/Passes.h"
21#include "mlir/IR/PatternMatch.h"
22#include "mlir/Pass/PassManager.h"
23#include "mlir/Transforms/DialectConversion.h"
24#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
25
26using namespace mlir;
27using namespace tosa;
28
29namespace {
30struct TosaToStandard : public TosaToStandardBase<TosaToStandard> {
31public:
32 void runOnOperation() override {
Chris Lattnerdc4e9132021-03-22 23:58:3433 RewritePatternSet patterns(&getContext());
Rob Suderman16abaca2021-02-26 02:08:2934 ConversionTarget target(getContext());
35 target.addIllegalOp<tosa::ConstOp>();
Rob Sudermanf4bb0762021-03-17 22:53:1836 target.addIllegalOp<tosa::SliceOp>();
Rob Suderman286a9d42021-03-18 23:14:0537 target.addIllegalOp<tosa::ApplyScaleOp>();
Mogballa54f4ea2021-10-12 23:14:5738 target.addLegalDialect<arith::ArithmeticDialect>();
River Riddle23aa5a72022-02-26 22:49:5439 target.addLegalDialect<func::FuncDialect>();
Matthias Springer060208b2021-06-22 07:49:0840 target.addLegalDialect<tensor::TensorDialect>();
Rob Suderman16abaca2021-02-26 02:08:2941
Chris Lattner3a506b32021-03-20 23:29:4142 mlir::tosa::populateTosaToStandardConversionPatterns(&patterns);
43 if (failed(applyPartialConversion(getOperation(), target,
44 std::move(patterns))))
Rob Suderman16abaca2021-02-26 02:08:2945 signalPassFailure();
46 }
47};
48} // namespace
49
50std::unique_ptr<Pass> mlir::tosa::createTosaToStandard() {
51 return std::make_unique<TosaToStandard>();
52}
53
54void mlir::tosa::addTosaToStandardPasses(OpPassManager &pm) {
55 pm.addNestedPass<FuncOp>(createTosaToStandard());
56}