1 //===- TestLinalgDecomposeOps.cpp - Test Linalg decomposition ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements a pass for testing decomposition of Linalg ops.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Dialect/Affine/IR/AffineOps.h"
14 #include "mlir/Dialect/Linalg/Transforms/Transforms.h"
15 #include "mlir/Pass/Pass.h"
16 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21 struct TestLinalgDecomposeOps
22 : public PassWrapper
<TestLinalgDecomposeOps
, OperationPass
<>> {
23 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgDecomposeOps
)
25 TestLinalgDecomposeOps() = default;
26 TestLinalgDecomposeOps(const TestLinalgDecomposeOps
&pass
)
27 : PassWrapper(pass
){};
28 void getDependentDialects(DialectRegistry
®istry
) const override
{
29 registry
.insert
<affine::AffineDialect
, linalg::LinalgDialect
>();
31 StringRef
getArgument() const final
{ return "test-linalg-decompose-ops"; }
32 StringRef
getDescription() const final
{
33 return "Test Linalg decomposition patterns";
36 Option
<bool> removeDeadArgsAndResults
{
37 *this, "remove-dead-args-and-results",
38 llvm::cl::desc("Test patterns to erase unused operands and results"),
39 llvm::cl::init(false)};
41 void runOnOperation() override
{
42 MLIRContext
*context
= &this->getContext();
43 RewritePatternSet
decompositionPatterns(context
);
44 linalg::populateDecomposeLinalgOpsPattern(decompositionPatterns
,
45 removeDeadArgsAndResults
);
46 if (failed(applyPatternsAndFoldGreedily(
47 getOperation(), std::move(decompositionPatterns
)))) {
48 return signalPassFailure();
56 void registerTestLinalgDecomposeOps() {
57 PassRegistration
<TestLinalgDecomposeOps
>();