1 //===- TosaOptionalDecompositions.cpp
2 //------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Pass to apply the Tosa operations decompositions
11 // exposed as populate functions in
12 // include/mlir/Dialect/Tosa/Transforms/Passes.h
13 //
14 //===----------------------------------------------------------------------===//
15 
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/Pass/Pass.h"
20 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21 
22 using namespace mlir;
23 
24 namespace {
25 
26 struct TosaOptionalDecompositions
27     : public TosaOptionalDecompositionsBase<TosaOptionalDecompositions> {
28   void runOnOperation() override {
29     auto *ctx = &getContext();
30     RewritePatternSet patterns(ctx);
31     auto func = getOperation();
32 
33     mlir::tosa::populateTosaDecomposeConv2D(ctx, patterns);
34     mlir::tosa::populateTosaDecomposeTransposeConv(ctx, patterns);
35     mlir::tosa::populateTosaDecomposeDepthwise(ctx, patterns);
36 
37     if (applyPatternsAndFoldGreedily(func, std::move(patterns)).failed())
38       signalPassFailure();
39   }
40 };
41 
42 } // namespace
43 
44 std::unique_ptr<Pass> mlir::tosa::createTosaOptionalDecompositions() {
45   return std::make_unique<TosaOptionalDecompositions>();
46 }
47