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

source code of mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp