1 //===- TestPadFusion.cpp - Test fusion of pad op with Linalg ops ---------===//
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 file implements a pass for testing fusion of pad ops with its producer
10 // Linalg op.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "mlir/Dialect/Linalg/Transforms/Transforms.h"
15 #include "mlir/Pass/Pass.h"
16 #include "mlir/Pass/PassManager.h"
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18 
19 namespace mlir {
20 
21 namespace {
22 struct TestPadFusionPass
23     : public PassWrapper<TestPadFusionPass, OperationPass<FuncOp>> {
24 
25   void getDependentDialects(DialectRegistry &registry) const override {
26     registry
27         .insert<AffineDialect, linalg::LinalgDialect, tensor::TensorDialect>();
28   }
29 
30   StringRef getArgument() const final { return "test-linalg-pad-fusion"; }
31   StringRef getDescription() const final { return "Test PadOp fusion"; }
32 
33   void runOnOperation() override {
34     MLIRContext *context = &getContext();
35     FuncOp funcOp = getOperation();
36     RewritePatternSet patterns(context);
37     linalg::populateFusePadTensorWithProducerLinalgOpPatterns(patterns);
38     if (failed(applyPatternsAndFoldGreedily(funcOp.getBody(),
39                                             std::move(patterns))))
40       return signalPassFailure();
41   }
42 };
43 } // namespace
44 
45 namespace test {
46 void registerTestPadFusion() { PassRegistration<TestPadFusionPass>(); }
47 } // namespace test
48 
49 } // namespace mlir
50