1af5be38aSNicolas Vasilache //===- CodegenStrategy.cpp - Linalg programmable codegen strategy ---------===//
2af5be38aSNicolas Vasilache //
3af5be38aSNicolas Vasilache // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4af5be38aSNicolas Vasilache // See https://llvm.org/LICENSE.txt for license information.
5af5be38aSNicolas Vasilache // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6af5be38aSNicolas Vasilache //
7af5be38aSNicolas Vasilache //===----------------------------------------------------------------------===//
8af5be38aSNicolas Vasilache //
9af5be38aSNicolas Vasilache // This file implements logic and helpers to expose Linalg transforms as
10af5be38aSNicolas Vasilache // composable rewrite patterns through a programmable CodegenStrategy object.
11af5be38aSNicolas Vasilache //
12af5be38aSNicolas Vasilache //===----------------------------------------------------------------------===//
13af5be38aSNicolas Vasilache
14af5be38aSNicolas Vasilache #include "mlir/Dialect/Linalg/Transforms/CodegenStrategy.h"
1592ea624aSNicolas Vasilache #include "mlir/Dialect/Linalg/Passes.h"
16af5be38aSNicolas Vasilache #include "mlir/Dialect/Linalg/Transforms/Hoisting.h"
17*8b68da2cSAlex Zinenko #include "mlir/Dialect/SCF/Transforms/Transforms.h"
1899ef9eebSMatthias Springer #include "mlir/Dialect/Vector/IR/VectorOps.h"
1999ef9eebSMatthias Springer #include "mlir/Dialect/Vector/Transforms/VectorTransforms.h"
20af5be38aSNicolas Vasilache #include "mlir/Pass/PassManager.h"
21b6eb26fdSRiver Riddle #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
22af5be38aSNicolas Vasilache #include "mlir/Transforms/Passes.h"
23af5be38aSNicolas Vasilache
24af5be38aSNicolas Vasilache using namespace mlir;
25af5be38aSNicolas Vasilache using namespace mlir::linalg;
26af5be38aSNicolas Vasilache
27af5be38aSNicolas Vasilache #define DEBUG_TYPE "linalg-codegen-strategy"
28af5be38aSNicolas Vasilache
configurePassPipeline(OpPassManager & pm,MLIRContext * context,bool addEnablePass) const2992ea624aSNicolas Vasilache void mlir::linalg::CodegenStrategy::configurePassPipeline(
30ba2ac9c9STobias Gysi OpPassManager &pm, MLIRContext *context, bool addEnablePass) const {
3192ea624aSNicolas Vasilache for (unsigned stepCount = 0, e = transformationSequence.size(); stepCount < e;
3292ea624aSNicolas Vasilache ++stepCount) {
3392ea624aSNicolas Vasilache const std::unique_ptr<Transformation> &t =
3492ea624aSNicolas Vasilache transformationSequence[stepCount];
3592ea624aSNicolas Vasilache std::string currentStr = std::to_string(stepCount);
36195730a6SRiver Riddle auto currentState = StringAttr::get(context, currentStr);
3792ea624aSNicolas Vasilache std::string nextStr = std::to_string(stepCount + 1);
38195730a6SRiver Riddle auto nextState = StringAttr::get(context, nextStr);
3992ea624aSNicolas Vasilache auto filter = (currentState.str() == std::to_string(0))
40299cc5daSNicolas Vasilache ? linalg::LinalgTransformationFilter(
41195730a6SRiver Riddle t->filter, ArrayRef<StringAttr>{}, nextState)
42299cc5daSNicolas Vasilache : linalg::LinalgTransformationFilter(
43299cc5daSNicolas Vasilache t->filter, currentState, nextState);
4492ea624aSNicolas Vasilache t->addToPassPipeline(pm, filter);
45ba2ac9c9STobias Gysi if (addEnablePass)
461b702eeaSNicolas Vasilache pm.addPass(createLinalgStrategyEnablePass(linalgEnablingOptions));
4792ea624aSNicolas Vasilache }
4889d55d3cSNicolas Vasilache pm.addPass(createLinalgStrategyRemoveMarkersPass());
49af5be38aSNicolas Vasilache }
50