MLIR  22.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 
19 #include "mlir/IR/PatternMatch.h"
21 
22 namespace mlir {
23 #define GEN_PASS_DEF_LINALGMORPHOPSPASS
24 #include "mlir/Dialect/Linalg/Passes.h.inc"
25 } // namespace mlir
26 
27 #define DEBUG_TYPE "linalg-morphism"
28 
29 using namespace mlir;
30 using namespace mlir::linalg;
31 
32 namespace {
33 struct LinalgMorphOpsPass
34  : public impl::LinalgMorphOpsPassBase<LinalgMorphOpsPass> {
35 
36  using impl::LinalgMorphOpsPassBase<
37  LinalgMorphOpsPass>::LinalgMorphOpsPassBase;
38 
39  void runOnOperation() override;
40 };
41 
42 void LinalgMorphOpsPass::runOnOperation() {
43 
45 
46  // Lowering paths (named -> category -> generic)
47  if (namedToCategory) {
49  }
50  if (namedToGeneric || categoryToGeneric) {
52  }
53 
54  // Lifting paths (named <- category <- generic)
55  if (genericToNamed) {
57  }
58 
59  if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
60  signalPassFailure();
61 }
62 } // namespace
static MLIRContext * getContext(OpFoldResult val)
void populateLinalgNamedOpsGeneralizationPatterns(RewritePatternSet &patterns)
Linalg generalization patterns.
void populateLinalgGenericOpsSpecializationPatterns(RewritePatternSet &patterns)
Populates patterns with patterns to convert linalg.generic ops to named ops where possible.
Definition: Specialize.cpp:344
void populateLinalgNamedToElementwisePatterns(RewritePatternSet &patterns)
Populates patterns that convert linalg named ops e.g.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition: Remarks.h:491
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...
const FrozenRewritePatternSet & patterns