From 15faa55f6576a85e7878354961fa881b08f13174 Mon Sep 17 00:00:00 2001 From: Nicolas Vasilache Date: Wed, 12 Oct 2022 03:26:55 -0700 Subject: [PATCH] [mlir][Linalg] NFC - Drop CodegenStrategy and remaining strategy passes Differential Revision: https://reviews.llvm.org/D135759 --- mlir/include/mlir/Dialect/Linalg/Passes.h | 14 ---- mlir/include/mlir/Dialect/Linalg/Passes.td | 11 ---- .../Dialect/Linalg/Transforms/CodegenStrategy.h | 57 ----------------- mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt | 2 - .../Dialect/Linalg/Transforms/CodegenStrategy.cpp | 47 -------------- .../Linalg/Transforms/LinalgStrategyPasses.cpp | 74 ---------------------- 6 files changed, 205 deletions(-) delete mode 100644 mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h delete mode 100644 mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp delete mode 100644 mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h index 40ca027..f2b5788 100644 --- a/mlir/include/mlir/Dialect/Linalg/Passes.h +++ b/mlir/include/mlir/Dialect/Linalg/Passes.h @@ -69,20 +69,6 @@ std::unique_ptr> createLinalgGeneralizationPass(); std::unique_ptr createLinalgDetensorizePass(); //===----------------------------------------------------------------------===// -/// Linalg strategy passes. -//===----------------------------------------------------------------------===// -/// Create a LinalgStrategyTilePass. -std::unique_ptr> createLinalgStrategyTilePass( - StringRef opName = "", - const linalg::LinalgTilingOptions &opt = linalg::LinalgTilingOptions(), - const linalg::LinalgTransformationFilter &filter = - linalg::LinalgTransformationFilter()); - -/// Create a LinalgStrategyRemoveMarkersPass. -std::unique_ptr> -createLinalgStrategyRemoveMarkersPass(); - -//===----------------------------------------------------------------------===// // Registration //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td index 73fd30b..550feef 100644 --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -146,15 +146,4 @@ def LinalgDetensorize : Pass<"linalg-detensorize", ""> { ]; } -def LinalgStrategyRemoveMarkersPass - : Pass<"linalg-strategy-remove-markers-pass", "func::FuncOp"> { - let summary = "Cleanup pass that drops markers."; - let constructor = "mlir::createLinalgStrategyRemoveMarkersPass()"; - let dependentDialects = ["linalg::LinalgDialect"]; - let options = [ - Option<"anchorFuncName", "anchor-func", "std::string", /*default=*/"", - "Which func op is the anchor to latch on.">, - ]; -} - #endif // MLIR_DIALECT_LINALG_PASSES diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h b/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h deleted file mode 100644 index ae3df32..0000000 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h +++ /dev/null @@ -1,57 +0,0 @@ -//===- CodegenStrategy.h - Linalg programmable codegen strategy -*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef MLIR_DIALECT_LINALG_TRANSFORMS_CODEGENSTRATEGY_H_ -#define MLIR_DIALECT_LINALG_TRANSFORMS_CODEGENSTRATEGY_H_ - -#include - -#include "mlir/Conversion/VectorToSCF/VectorToSCF.h" -#include "mlir/Dialect/Linalg/Passes.h" -#include "mlir/Pass/PassManager.h" - -namespace mlir { - -namespace linalg { - -/// Abstract Transformation class applied in a sequence that also handles state -/// through markers. -struct Transformation { - explicit Transformation(LinalgTransformationFilter::FilterFunction f) - : filter(std::move(f)) {} - virtual ~Transformation() = default; - virtual void addToPassPipeline(OpPassManager &pm, - LinalgTransformationFilter m) const = 0; - LinalgTransformationFilter::FilterFunction filter = nullptr; -}; - -/// Codegen strategy controls how a Linalg op is progressively lowered. -struct CodegenStrategy { - /// Configure the post staged-patterns global enabling passes options. - CodegenStrategy & - setVectorTransferToSCFOptions(LinalgEnablingOptions options) { - linalgEnablingOptions = options; - return *this; - } - - /// Apply the transformation patterns in sequence with cleanup - /// transformations interleaved. - void configurePassPipeline(OpPassManager &pm, MLIRContext *context, - bool addEnablePass = true) const; - -private: - LogicalResult postPatternTransforms(Operation *func) const; - - LinalgEnablingOptions linalgEnablingOptions; - SmallVector, 4> transformationSequence; -}; - -} // namespace linalg -} // namespace mlir - -#endif // MLIR_DIALECT_LINALG_TRANSFORMS_CODEGENSTRATEGY_H_ diff --git a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt index c218ad2..24048c2 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt @@ -2,7 +2,6 @@ add_mlir_dialect_library(MLIRLinalgTransforms BubbleUpExtractSlice.cpp BufferizableOpInterfaceImpl.cpp Bufferize.cpp - CodegenStrategy.cpp ConstantFold.cpp DecomposeLinalgOps.cpp Detensorize.cpp @@ -18,7 +17,6 @@ add_mlir_dialect_library(MLIRLinalgTransforms InlineScalarOperands.cpp Interchange.cpp Loops.cpp - LinalgStrategyPasses.cpp NamedOpConversions.cpp Promotion.cpp Split.cpp diff --git a/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp b/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp deleted file mode 100644 index 6787de3..0000000 --- a/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===- 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/Transforms.h" -#include "mlir/Dialect/Vector/IR/VectorOps.h" -#include "mlir/Dialect/Vector/Transforms/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 &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{}, nextState) - : linalg::LinalgTransformationFilter( - t->filter, currentState, nextState); - t->addToPassPipeline(pm, filter); - } - pm.addPass(createLinalgStrategyRemoveMarkersPass()); -} diff --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp deleted file mode 100644 index 39a9c7f..0000000 --- a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//===- LinalgStrategyPasses.cpp - Implementation of Linalg passes ---------===// -// -// 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 a configurable pass that can apply patterns liberally -// and be plugged in a pass pipeline. -// -//===----------------------------------------------------------------------===// - -#include "mlir/Dialect/Linalg/Passes.h" - -#include "mlir/Analysis/SliceAnalysis.h" -#include "mlir/Dialect/Affine/IR/AffineOps.h" -#include "mlir/Dialect/Affine/LoopUtils.h" -#include "mlir/Dialect/Affine/Utils.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/Dialect/Linalg/IR/Linalg.h" -#include "mlir/Dialect/Linalg/Transforms/Hoisting.h" -#include "mlir/Dialect/Linalg/Transforms/Transforms.h" -#include "mlir/Dialect/Linalg/Utils/Utils.h" -#include "mlir/Dialect/SCF/Transforms/Transforms.h" -#include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/Dialect/Vector/Transforms/VectorTransforms.h" -#include "mlir/IR/AffineExpr.h" -#include "mlir/IR/AffineMap.h" -#include "mlir/Pass/PassManager.h" -#include "mlir/Support/LLVM.h" -#include "mlir/Transforms/GreedyPatternRewriteDriver.h" -#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h" -#include "mlir/Transforms/Passes.h" -#include - -namespace mlir { -#define GEN_PASS_DEF_LINALGSTRATEGYTILEANDFUSEPASS -#define GEN_PASS_DEF_LINALGSTRATEGYTILEPASS -#define GEN_PASS_DEF_LINALGSTRATEGYPADPASS -#define GEN_PASS_DEF_LINALGSTRATEGYDECOMPOSEPASS -#define GEN_PASS_DEF_LINALGSTRATEGYPEELPASS -#define GEN_PASS_DEF_LINALGSTRATEGYLOWERVECTORSPASS -#define GEN_PASS_DEF_LINALGSTRATEGYREMOVEMARKERSPASS -#include "mlir/Dialect/Linalg/Passes.h.inc" -} // namespace mlir - -using namespace mlir; -using namespace mlir::vector; -using namespace linalg; - -namespace { - -/// Configurable pass to lower vector operations. -struct LinalgStrategyRemoveMarkersPass - : public impl::LinalgStrategyRemoveMarkersPassBase< - LinalgStrategyRemoveMarkersPass> { - - void runOnOperation() override { - auto funcOp = getOperation(); - if (!anchorFuncName.empty() && funcOp.getName() != anchorFuncName) - return; - funcOp.walk([](LinalgOp op) { - op->removeAttr(LinalgTransforms::kLinalgTransformMarker); - }); - } -}; -} // namespace - -/// Create a LinalgStrategyRemoveMarkersPass. -std::unique_ptr> -mlir::createLinalgStrategyRemoveMarkersPass() { - return std::make_unique(); -} -- 2.7.4