From 01f4ca0a15cd69299598679ff50e6d6750d92101 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Tue, 19 Aug 2025 19:11:00 +0100 Subject: [PATCH 1/5] [MLIR][Linalg] Rename convolution pass (with deprecation notice) Rename the pass `LinalgNamedOpConversionPass` to `SimplifyDepthwiseConvPass` to avoid conflating it with the new morphisms we are creating between the norms. Keep the old pass/function as deprecated for now, and agree on a timing to remove it from the tree at some point in the future. --- mlir/include/mlir/Dialect/Linalg/Passes.td | 8 ++++++- .../Dialect/Linalg/Transforms/Transforms.h | 8 +++++-- .../Dialect/Linalg/Transforms/CMakeLists.txt | 2 +- ...versions.cpp => SimplifyDepthwiseConv.cpp} | 24 +++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) rename mlir/lib/Dialect/Linalg/Transforms/{NamedOpConversions.cpp => SimplifyDepthwiseConv.cpp} (88%) diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td index 0b2c9c94dc73d..9aa199f140796 100644 --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -86,13 +86,19 @@ def LinalgSpecializeGenericOpsPass : Pass<"linalg-specialize-generic-ops">, let dependentDialects = ["linalg::LinalgDialect"]; } -def LinalgNamedOpConversionPass: Pass<"linalg-named-op-conversion"> { +def LinalgNamedOpConversionPass: Pass<"linalg-named-op-conversion">, + Deprecated<"Use 'simplify-depthwise-conv' instead."> { let summary = "Convert from one named linalg op to another."; let dependentDialects = ["linalg::LinalgDialect", "tensor::TensorDialect"]; } // ------------------ End of "form" conversions +def SimplifyDepthwiseConvPass: Pass<"simplify-depthwise-conv"> { + let summary = "Simplify depthwise convolution."; + let dependentDialects = ["linalg::LinalgDialect", "tensor::TensorDialect"]; +} + def ConvertElementwiseToLinalgPass : Pass<"convert-elementwise-to-linalg", ""> { let summary = "Convert ElementwiseMappable ops to linalg"; let description = [{ diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h index 8d5306dca43e3..d757779a60015 100644 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -24,6 +24,7 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/TilingInterface.h" #include "mlir/Transforms/DialectConversion.h" +#include "llvm/Support/Compiler.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallSet.h" @@ -1962,8 +1963,11 @@ void populateFoldAddIntoDestPatterns(RewritePatternSet &patterns); void populateFuseTensorPadWithProducerLinalgOpPatterns( RewritePatternSet &patterns); -/// Patterns to convert from one named op to another. These can be seen as -/// canonicalizations of named ops into another named op. +/// Patterns to simplify depthwise convolutions. +void populateSimplifyDepthwiseConvPatterns(RewritePatternSet &patterns); + +/// Patterns to convert from one named op to another. So far only used on +/// depthwise convolutions, so deprecated. Use the pattern avove. void populateLinalgNamedOpConversionPatterns(RewritePatternSet &patterns); /// Patterns to fold unit-extent dimensions in operands/results of linalg ops on diff --git a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt index 6ec2e9fd0be7d..fb39e18691e03 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt @@ -26,7 +26,7 @@ add_mlir_dialect_library(MLIRLinalgTransforms MorphOps.cpp TransposeMatmul.cpp ShardingInterfaceImpl.cpp - NamedOpConversions.cpp + SimplifyDepthwiseConv.cpp NamedToElementwise.cpp BlockPackMatmul.cpp PackAndUnpackPatterns.cpp diff --git a/mlir/lib/Dialect/Linalg/Transforms/NamedOpConversions.cpp b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp similarity index 88% rename from mlir/lib/Dialect/Linalg/Transforms/NamedOpConversions.cpp rename to mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp index a2bd9d92815a0..1d918d7c1663a 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/NamedOpConversions.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp @@ -22,6 +22,7 @@ namespace mlir { #define GEN_PASS_DEF_LINALGNAMEDOPCONVERSIONPASS +#define GEN_PASS_DEF_SIMPLIFYDEPTHWISECONVPASS #include "mlir/Dialect/Linalg/Passes.h.inc" } // namespace mlir @@ -143,6 +144,22 @@ struct SimplifyDepthwiseConvQOp } }; +struct SimplifyDepthwiseConvPass + : public impl::SimplifyDepthwiseConvPassBase< + SimplifyDepthwiseConvPass> { + using impl::SimplifyDepthwiseConvPassBase< + SimplifyDepthwiseConvPass>::SimplifyDepthwiseConvPassBase; + + void runOnOperation() override { + Operation *op = getOperation(); + RewritePatternSet patterns(op->getContext()); + populateSimplifyDepthwiseConvPatterns(patterns); + if (failed(applyPatternsGreedily(op, std::move(patterns)))) + return signalPassFailure(); + } +}; + +// Deprecated, use the one above struct LinalgNamedOpConversionPass : public impl::LinalgNamedOpConversionPassBase< LinalgNamedOpConversionPass> { @@ -159,6 +176,13 @@ struct LinalgNamedOpConversionPass }; } // namespace +void mlir::linalg::populateSimplifyDepthwiseConvPatterns( + RewritePatternSet &patterns) { + patterns.add( + patterns.getContext()); +} + +// Deprecated, use the one above void mlir::linalg::populateLinalgNamedOpConversionPatterns( RewritePatternSet &patterns) { patterns.add( From a30dc70feb47ceef49317a95800e2396d0c0fb38 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Tue, 19 Aug 2025 19:17:42 +0100 Subject: [PATCH 2/5] format --- mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp index 1d918d7c1663a..e3f7f62a1256c 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp @@ -145,8 +145,7 @@ struct SimplifyDepthwiseConvQOp }; struct SimplifyDepthwiseConvPass - : public impl::SimplifyDepthwiseConvPassBase< - SimplifyDepthwiseConvPass> { + : public impl::SimplifyDepthwiseConvPassBase { using impl::SimplifyDepthwiseConvPassBase< SimplifyDepthwiseConvPass>::SimplifyDepthwiseConvPassBase; From 563d8da2e658c9850dbe062353026fbc7c5f7f17 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Tue, 19 Aug 2025 19:41:53 +0100 Subject: [PATCH 3/5] format2 --- mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h index d757779a60015..8948d8e4f3e9c 100644 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -24,9 +24,9 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/TilingInterface.h" #include "mlir/Transforms/DialectConversion.h" -#include "llvm/Support/Compiler.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/Support/Compiler.h" namespace mlir { namespace bufferization { From efab9b8ed5731465a9df8b9097a664f46f1db078 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Wed, 20 Aug 2025 11:53:40 +0100 Subject: [PATCH 4/5] just move without deprecation --- mlir/include/mlir/Dialect/Linalg/Passes.td | 6 ----- .../Dialect/Linalg/Transforms/Transforms.h | 4 ---- .../Transforms/SimplifyDepthwiseConv.cpp | 24 ------------------- ...sion.mlir => simplify-depthwise-conv.mlir} | 2 +- 4 files changed, 1 insertion(+), 35 deletions(-) rename mlir/test/Dialect/Linalg/{namedop_conversion.mlir => simplify-depthwise-conv.mlir} (96%) diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td index 9aa199f140796..44da2965e6892 100644 --- a/mlir/include/mlir/Dialect/Linalg/Passes.td +++ b/mlir/include/mlir/Dialect/Linalg/Passes.td @@ -86,12 +86,6 @@ def LinalgSpecializeGenericOpsPass : Pass<"linalg-specialize-generic-ops">, let dependentDialects = ["linalg::LinalgDialect"]; } -def LinalgNamedOpConversionPass: Pass<"linalg-named-op-conversion">, - Deprecated<"Use 'simplify-depthwise-conv' instead."> { - let summary = "Convert from one named linalg op to another."; - let dependentDialects = ["linalg::LinalgDialect", "tensor::TensorDialect"]; -} - // ------------------ End of "form" conversions def SimplifyDepthwiseConvPass: Pass<"simplify-depthwise-conv"> { diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h index 8948d8e4f3e9c..f1920dc814a12 100644 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -1966,10 +1966,6 @@ void populateFuseTensorPadWithProducerLinalgOpPatterns( /// Patterns to simplify depthwise convolutions. void populateSimplifyDepthwiseConvPatterns(RewritePatternSet &patterns); -/// Patterns to convert from one named op to another. So far only used on -/// depthwise convolutions, so deprecated. Use the pattern avove. -void populateLinalgNamedOpConversionPatterns(RewritePatternSet &patterns); - /// Patterns to fold unit-extent dimensions in operands/results of linalg ops on /// tensors via reassociative reshape ops. void populateFoldUnitExtentDimsPatterns(RewritePatternSet &patterns, diff --git a/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp index e3f7f62a1256c..27ccf3c2ba148 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/SimplifyDepthwiseConv.cpp @@ -21,7 +21,6 @@ #include "llvm/ADT/TypeSwitch.h" namespace mlir { -#define GEN_PASS_DEF_LINALGNAMEDOPCONVERSIONPASS #define GEN_PASS_DEF_SIMPLIFYDEPTHWISECONVPASS #include "mlir/Dialect/Linalg/Passes.h.inc" } // namespace mlir @@ -157,22 +156,6 @@ struct SimplifyDepthwiseConvPass return signalPassFailure(); } }; - -// Deprecated, use the one above -struct LinalgNamedOpConversionPass - : public impl::LinalgNamedOpConversionPassBase< - LinalgNamedOpConversionPass> { - using impl::LinalgNamedOpConversionPassBase< - LinalgNamedOpConversionPass>::LinalgNamedOpConversionPassBase; - - void runOnOperation() override { - Operation *op = getOperation(); - RewritePatternSet patterns(op->getContext()); - populateLinalgNamedOpConversionPatterns(patterns); - if (failed(applyPatternsGreedily(op, std::move(patterns)))) - return signalPassFailure(); - } -}; } // namespace void mlir::linalg::populateSimplifyDepthwiseConvPatterns( @@ -180,10 +163,3 @@ void mlir::linalg::populateSimplifyDepthwiseConvPatterns( patterns.add( patterns.getContext()); } - -// Deprecated, use the one above -void mlir::linalg::populateLinalgNamedOpConversionPatterns( - RewritePatternSet &patterns) { - patterns.add( - patterns.getContext()); -} diff --git a/mlir/test/Dialect/Linalg/namedop_conversion.mlir b/mlir/test/Dialect/Linalg/simplify-depthwise-conv.mlir similarity index 96% rename from mlir/test/Dialect/Linalg/namedop_conversion.mlir rename to mlir/test/Dialect/Linalg/simplify-depthwise-conv.mlir index 4f2f2720037cd..70e68e787242e 100644 --- a/mlir/test/Dialect/Linalg/namedop_conversion.mlir +++ b/mlir/test/Dialect/Linalg/simplify-depthwise-conv.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -linalg-named-op-conversion -split-input-file | FileCheck %s +// RUN: mlir-opt %s --simplify-depthwise-conv -split-input-file | FileCheck %s // CHECK-LABEL: @depthwise_conv func.func @depthwise_conv(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { From 304549b9d12e20c01cead909b503793784eaabba Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Wed, 20 Aug 2025 11:57:16 +0100 Subject: [PATCH 5/5] remove unused header --- mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h | 1 - 1 file changed, 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h index f1920dc814a12..0cfc8821c0add 100644 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -26,7 +26,6 @@ #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallSet.h" -#include "llvm/Support/Compiler.h" namespace mlir { namespace bufferization {