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 : public PassWrapper<TestPadFusionPass, FunctionPass> { 23 24 void getDependentDialects(DialectRegistry ®istry) const override { 25 registry 26 .insert<AffineDialect, linalg::LinalgDialect, tensor::TensorDialect>(); 27 } 28 29 StringRef getArgument() const final { return "test-linalg-pad-fusion"; } 30 StringRef getDescription() const final { return "Test PadOp fusion"; } 31 32 void runOnFunction() override { 33 MLIRContext *context = &getContext(); 34 FuncOp funcOp = getFunction(); 35 RewritePatternSet patterns(context); 36 linalg::populateFusePadTensorWithProducerLinalgOpPatterns(patterns); 37 if (failed(applyPatternsAndFoldGreedily(funcOp.getBody(), 38 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