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 using namespace mlir; 20 21 namespace { 22 struct TestPadFusionPass 23 : public PassWrapper<TestPadFusionPass, OperationPass<>> { 24 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPadFusionPass) 25 26 void getDependentDialects(DialectRegistry ®istry) const override { 27 registry 28 .insert<AffineDialect, linalg::LinalgDialect, tensor::TensorDialect>(); 29 } 30 31 StringRef getArgument() const final { return "test-linalg-pad-fusion"; } 32 StringRef getDescription() const final { return "Test PadOp fusion"; } 33 34 void runOnOperation() override { 35 MLIRContext *context = &getContext(); 36 RewritePatternSet patterns(context); 37 linalg::populateFuseTensorPadWithProducerLinalgOpPatterns(patterns); 38 if (failed( 39 applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) 40 return signalPassFailure(); 41 } 42 }; 43 } // namespace 44 45 namespace mlir { 46 namespace test { 47 void registerTestPadFusion() { PassRegistration<TestPadFusionPass>(); } 48 } // namespace test 49 } // namespace mlir 50