MLIR  16.0.0git
CodegenStrategy.cpp
Go to the documentation of this file.
1 //===- CodegenStrategy.cpp - Linalg programmable codegen strategy ---------===//
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 logic and helpers to expose Linalg transforms as
10 // composable rewrite patterns through a programmable CodegenStrategy object.
11 //
12 //===----------------------------------------------------------------------===//
13 
20 #include "mlir/Pass/PassManager.h"
22 #include "mlir/Transforms/Passes.h"
23 
24 using namespace mlir;
25 using namespace mlir::linalg;
26 
27 #define DEBUG_TYPE "linalg-codegen-strategy"
28 
30  OpPassManager &pm, MLIRContext *context, bool addEnablePass) const {
31  for (unsigned stepCount = 0, e = transformationSequence.size(); stepCount < e;
32  ++stepCount) {
33  const std::unique_ptr<Transformation> &t =
34  transformationSequence[stepCount];
35  std::string currentStr = std::to_string(stepCount);
36  auto currentState = StringAttr::get(context, currentStr);
37  std::string nextStr = std::to_string(stepCount + 1);
38  auto nextState = StringAttr::get(context, nextStr);
39  auto filter = (currentState.str() == std::to_string(0))
41  t->filter, ArrayRef<StringAttr>{}, nextState)
43  t->filter, currentState, nextState);
44  t->addToPassPipeline(pm, filter);
45  if (addEnablePass)
46  pm.addPass(createLinalgStrategyEnablePass(linalgEnablingOptions));
47  }
49 }
Include the generated interface declarations.
Helper class to control application of linalg transformation patterns.
Definition: Transforms.h:348
void configurePassPipeline(OpPassManager &pm, MLIRContext *context, bool addEnablePass=true) const
Apply the transformation patterns in sequence with cleanup transformations interleaved.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition: Pass.cpp:333
std::unique_ptr< OperationPass< func::FuncOp > > createLinalgStrategyEnablePass(linalg::LinalgEnablingOptions opt=linalg::LinalgEnablingOptions(), const linalg::LinalgTransformationFilter &filter=linalg::LinalgTransformationFilter())
Create a LinalgStrategyEnablePass.
std::unique_ptr< OperationPass< func::FuncOp > > createLinalgStrategyRemoveMarkersPass()
Create a LinalgStrategyRemoveMarkersPass.
This class represents a pass manager that runs passes on either a specific operation type...
Definition: PassManager.h:52