//===- TestLinalgDecomposeOps.cpp - Test Linalg decomposition ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements a pass for testing decomposition of Linalg ops. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Linalg/Transforms/Transforms.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; namespace { struct TestLinalgDecomposeOps : public PassWrapper> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgDecomposeOps) TestLinalgDecomposeOps() = default; TestLinalgDecomposeOps(const TestLinalgDecomposeOps &pass) : PassWrapper(pass){}; void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); } StringRef getArgument() const final { return "test-linalg-decompose-ops"; } StringRef getDescription() const final { return "Test Linalg decomposition patterns"; } Option removeDeadArgsAndResults{ *this, "remove-dead-args-and-results", llvm::cl::desc("Test patterns to erase unused operands and results"), llvm::cl::init(false)}; void runOnOperation() override { MLIRContext *context = &this->getContext(); RewritePatternSet decompositionPatterns(context); linalg::populateDecomposeLinalgOpsPattern(decompositionPatterns, removeDeadArgsAndResults); if (failed(applyPatternsAndFoldGreedily( getOperation(), std::move(decompositionPatterns)))) { return signalPassFailure(); } } }; } // namespace namespace mlir { namespace test { void registerTestLinalgDecomposeOps() { PassRegistration(); } } // namespace test } // namespace mlir