brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · b927767 Raw
50 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a pass for testing fusion of pad ops with its producer10// 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 TestPadFusionPass24    : 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(applyPatternsGreedily(getOperation(), std::move(patterns))))40      return signalPassFailure();41  }42};43} // namespace44 45namespace mlir {46namespace test {47void registerTestPadFusion() { PassRegistration<TestPadFusionPass>(); }48} // namespace test49} // namespace mlir50