63 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements conversions between linalg ops:10// named <--> category (elementwise, contraction, ..) <--> generic.11//===----------------------------------------------------------------------===//12 13#include "mlir/Dialect/Complex/IR/Complex.h"14#include "mlir/Dialect/Linalg/IR/Linalg.h"15#include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h"16#include "mlir/Dialect/Linalg/Passes.h"17#include "mlir/Dialect/Linalg/Transforms/Transforms.h"18#include "mlir/Dialect/Math/IR/Math.h"19#include "mlir/IR/PatternMatch.h"20#include "mlir/Transforms/GreedyPatternRewriteDriver.h"21 22namespace mlir {23#define GEN_PASS_DEF_LINALGMORPHOPSPASS24#include "mlir/Dialect/Linalg/Passes.h.inc"25} // namespace mlir26 27#define DEBUG_TYPE "linalg-morphism"28 29using namespace mlir;30using namespace mlir::linalg;31 32namespace {33struct LinalgMorphOpsPass34 : public impl::LinalgMorphOpsPassBase<LinalgMorphOpsPass> {35 36 using impl::LinalgMorphOpsPassBase<37 LinalgMorphOpsPass>::LinalgMorphOpsPassBase;38 39 void runOnOperation() override;40};41 42void LinalgMorphOpsPass::runOnOperation() {43 44 RewritePatternSet patterns(&getContext());45 46 // Lowering paths (named -> category -> generic)47 if (namedToCategory) {48 populateLinalgNamedToElementwisePatterns(patterns);49 }50 if (namedToGeneric || categoryToGeneric) {51 populateLinalgNamedOpsGeneralizationPatterns(patterns);52 }53 54 // Lifting paths (named <- category <- generic)55 if (genericToNamed) {56 populateLinalgGenericOpsSpecializationPatterns(patterns);57 }58 59 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))60 signalPassFailure();61}62} // namespace63