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<>> { 24 25 void getDependentDialects(DialectRegistry ®istry) 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 RewritePatternSet patterns(context); 36 linalg::populateFuseTensorPadWithProducerLinalgOpPatterns(patterns); 37 if (failed( 38 applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) 39 return signalPassFailure(); 40 } 41 }; 42 } // namespace 43 44 namespace test { 45 void registerTestPadFusion() { PassRegistration<TestPadFusionPass>(); } 46 } // namespace test 47 48 } // namespace mlir 49