MLIR 24.0.0git
MorphOps.cpp
Go to the documentation of this file.
1//===- MorphOps.cpp - conversion between named,category and generic 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 conversions between linalg ops:
10// named <--> category (elementwise, contraction, ..) <--> generic.
11//===----------------------------------------------------------------------===//
12
21
22namespace mlir {
23#define GEN_PASS_DEF_LINALGMORPHOPSPASS
24#define GEN_PASS_DEF_LINALGCATEGORIZEOPSPASS
25#include "mlir/Dialect/Linalg/Passes.h.inc"
26} // namespace mlir
27
28#define DEBUG_TYPE "linalg-morphism"
29
30using namespace mlir;
31using namespace mlir::linalg;
32
33namespace {
34struct LinalgMorphOpsPass
35 : public impl::LinalgMorphOpsPassBase<LinalgMorphOpsPass> {
36
37 using impl::LinalgMorphOpsPassBase<
38 LinalgMorphOpsPass>::LinalgMorphOpsPassBase;
39
40 void runOnOperation() override;
41};
42
43void LinalgMorphOpsPass::runOnOperation() {
44
45 RewritePatternSet patterns(&getContext());
46
47 // Lowering paths (named -> category -> generic)
48 if (namedToGeneric || categoryToGeneric)
50
51 // Lifting paths (named <- category <- generic)
52 if (genericToNamed || categoryToNamed)
54
55 // Category paths (named -> category <- generic)
56 if (genericToCategory)
58 if (namedToCategory)
60
61 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
62 signalPassFailure();
63}
64
65struct LinalgCategorizeOpsPass
66 : public impl::LinalgCategorizeOpsPassBase<LinalgCategorizeOpsPass> {
67
68 using impl::LinalgCategorizeOpsPassBase<
69 LinalgCategorizeOpsPass>::LinalgCategorizeOpsPassBase;
70
71 void runOnOperation() override;
72};
73
74void LinalgCategorizeOpsPass::runOnOperation() {
75 RewritePatternSet patterns(&getContext());
77
78 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
79 signalPassFailure();
80}
81} // namespace
b getContext())
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
void populateLinalgGenericOpsSpecializationPatterns(RewritePatternSet &patterns, bool emitCategoryOps=false)
Populates patterns with patterns to convert linalg.generic ops to named or category ops where possibl...
void populateLinalgNamedOpsGeneralizationPatterns(RewritePatternSet &patterns, bool emitCategoryOps=false)
Linalg generalization patterns.
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region &region, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...