Files
clang-p2996/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp
River Riddle a70aa7bb0d [mlir:Transforms] Move out the remaining non-dialect independent transforms and utilities
This has been a major TODO for a very long time, and is necessary for establishing a proper
dialect-free dependency layering for the Transforms library. Code was moved to effectively
two main locations:

* Affine/
There was quite a bit of affine dialect related code in Transforms/ do to historical reasons
(of a time way into MLIR's past). The following headers were moved to:
Transforms/LoopFusionUtils.h -> Dialect/Affine/LoopFusionUtils.h
Transforms/LoopUtils.h -> Dialect/Affine/LoopUtils.h
Transforms/Utils.h -> Dialect/Affine/Utils.h

The following transforms were also moved:
AffineLoopFusion, AffinePipelineDataTransfer, LoopCoalescing

* SCF/
Only one SCF pass was in Transforms/ (likely accidentally placed here): ParallelLoopCollapsing
The SCF specific utilities in LoopUtils have been moved to SCF/Utils.h

* Misc:
mlir::moveLoopInvariantCode was also moved to LoopLikeInterface.h given
that it is a simple utility defined in terms of LoopLikeOpInterface.

Differential Revision: https://reviews.llvm.org/D117848
2022-01-24 19:25:53 -08:00

50 lines
2.1 KiB
C++

//===- CodegenStrategy.cpp - Linalg programmable codegen strategy ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements logic and helpers to expose Linalg transforms as
// composable rewrite patterns through a programmable CodegenStrategy object.
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Linalg/Transforms/CodegenStrategy.h"
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Dialect/Linalg/Transforms/Hoisting.h"
#include "mlir/Dialect/SCF/Transforms.h"
#include "mlir/Dialect/Vector/VectorOps.h"
#include "mlir/Dialect/Vector/VectorTransforms.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/Passes.h"
using namespace mlir;
using namespace mlir::linalg;
#define DEBUG_TYPE "linalg-codegen-strategy"
void mlir::linalg::CodegenStrategy::configurePassPipeline(
OpPassManager &pm, MLIRContext *context, bool addEnablePass) const {
for (unsigned stepCount = 0, e = transformationSequence.size(); stepCount < e;
++stepCount) {
const std::unique_ptr<Transformation> &t =
transformationSequence[stepCount];
std::string currentStr = std::to_string(stepCount);
auto currentState = StringAttr::get(context, currentStr);
std::string nextStr = std::to_string(stepCount + 1);
auto nextState = StringAttr::get(context, nextStr);
auto filter = (currentState.str() == std::to_string(0))
? linalg::LinalgTransformationFilter(
t->filter, ArrayRef<StringAttr>{}, nextState)
: linalg::LinalgTransformationFilter(
t->filter, currentState, nextState);
t->addToPassPipeline(pm, filter);
if (addEnablePass)
pm.addPass(createLinalgStrategyEnablePass(linalgEnablingOptions));
}
pm.addPass(createLinalgStrategyRemoveMarkersPass());
}