Skip to content

Conversation

Hardcode84
Copy link
Contributor

These are relics from the times when PatternRewriter was not instantiable directly, I suppose.

@llvmbot
Copy link
Member

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-mlir-linalg

Author: Ivan Butygin (Hardcode84)

Changes

These are relics from the times when PatternRewriter was not instantiable directly, I suppose.


Full diff: https://github.com/llvm/llvm-project/pull/155248.diff

3 Files Affected:

  • (modified) mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp (+1-6)
  • (modified) mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp (+1-6)
  • (modified) mlir/unittests/Rewrite/PatternBenefit.cpp (+1-6)
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 639e0feabc9bd..f0c1f4485b054 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -70,12 +70,7 @@ static FailureOr<LinalgOp> tryApply(Operation *operation, Args &&...args) {
   PatternTy pattern(operation->getContext(), std::forward<Args>(args)...);
   // We want to discourage direct use of PatternRewriter in APIs but In this
   // very specific case, an IRRewriter is not enough.
-  struct TrivialPatternRewriter : public PatternRewriter {
-  public:
-    explicit TrivialPatternRewriter(MLIRContext *context)
-        : PatternRewriter(context) {}
-  };
-  TrivialPatternRewriter rewriter(operation->getContext());
+  PatternRewriter rewriter(operation->getContext());
   rewriter.setInsertionPoint(operation);
   auto result = pattern.returningMatchAndRewrite(op, rewriter);
   if (failed(result))
diff --git a/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp b/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
index 41955c8a278f2..3ced1a6582ce3 100644
--- a/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
+++ b/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
@@ -100,12 +100,7 @@ LogicalResult PatternApplicatorExtension::findAllMatches(
   PatternApplicator applicator(it->second);
   // We want to discourage direct use of PatternRewriter in APIs but In this
   // very specific case, an IRRewriter is not enough.
-  struct TrivialPatternRewriter : public PatternRewriter {
-  public:
-    explicit TrivialPatternRewriter(MLIRContext *context)
-        : PatternRewriter(context) {}
-  };
-  TrivialPatternRewriter rewriter(root->getContext());
+  PatternRewriter rewriter(root->getContext());
   applicator.applyDefaultCostModel();
   root->walk([&](Operation *op) {
     if (succeeded(applicator.matchAndRewrite(op, rewriter)))
diff --git a/mlir/unittests/Rewrite/PatternBenefit.cpp b/mlir/unittests/Rewrite/PatternBenefit.cpp
index 65ea4ee6683db..e4363f9f4b8bb 100644
--- a/mlir/unittests/Rewrite/PatternBenefit.cpp
+++ b/mlir/unittests/Rewrite/PatternBenefit.cpp
@@ -66,12 +66,7 @@ TEST(PatternBenefitTest, BenefitOrder) {
   PatternApplicator pa(frozenPatterns);
   pa.applyDefaultCostModel();
 
-  class MyPatternRewriter : public PatternRewriter {
-  public:
-    MyPatternRewriter(MLIRContext *ctx) : PatternRewriter(ctx) {}
-  };
-
-  MyPatternRewriter rewriter(&context);
+  PatternRewriter rewriter(&context);
   (void)pa.matchAndRewrite(*module, rewriter);
 
   EXPECT_TRUE(called1);

@llvmbot
Copy link
Member

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-mlir

Author: Ivan Butygin (Hardcode84)

Changes

These are relics from the times when PatternRewriter was not instantiable directly, I suppose.


Full diff: https://github.com/llvm/llvm-project/pull/155248.diff

3 Files Affected:

  • (modified) mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp (+1-6)
  • (modified) mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp (+1-6)
  • (modified) mlir/unittests/Rewrite/PatternBenefit.cpp (+1-6)
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 639e0feabc9bd..f0c1f4485b054 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -70,12 +70,7 @@ static FailureOr<LinalgOp> tryApply(Operation *operation, Args &&...args) {
   PatternTy pattern(operation->getContext(), std::forward<Args>(args)...);
   // We want to discourage direct use of PatternRewriter in APIs but In this
   // very specific case, an IRRewriter is not enough.
-  struct TrivialPatternRewriter : public PatternRewriter {
-  public:
-    explicit TrivialPatternRewriter(MLIRContext *context)
-        : PatternRewriter(context) {}
-  };
-  TrivialPatternRewriter rewriter(operation->getContext());
+  PatternRewriter rewriter(operation->getContext());
   rewriter.setInsertionPoint(operation);
   auto result = pattern.returningMatchAndRewrite(op, rewriter);
   if (failed(result))
diff --git a/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp b/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
index 41955c8a278f2..3ced1a6582ce3 100644
--- a/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
+++ b/mlir/lib/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp
@@ -100,12 +100,7 @@ LogicalResult PatternApplicatorExtension::findAllMatches(
   PatternApplicator applicator(it->second);
   // We want to discourage direct use of PatternRewriter in APIs but In this
   // very specific case, an IRRewriter is not enough.
-  struct TrivialPatternRewriter : public PatternRewriter {
-  public:
-    explicit TrivialPatternRewriter(MLIRContext *context)
-        : PatternRewriter(context) {}
-  };
-  TrivialPatternRewriter rewriter(root->getContext());
+  PatternRewriter rewriter(root->getContext());
   applicator.applyDefaultCostModel();
   root->walk([&](Operation *op) {
     if (succeeded(applicator.matchAndRewrite(op, rewriter)))
diff --git a/mlir/unittests/Rewrite/PatternBenefit.cpp b/mlir/unittests/Rewrite/PatternBenefit.cpp
index 65ea4ee6683db..e4363f9f4b8bb 100644
--- a/mlir/unittests/Rewrite/PatternBenefit.cpp
+++ b/mlir/unittests/Rewrite/PatternBenefit.cpp
@@ -66,12 +66,7 @@ TEST(PatternBenefitTest, BenefitOrder) {
   PatternApplicator pa(frozenPatterns);
   pa.applyDefaultCostModel();
 
-  class MyPatternRewriter : public PatternRewriter {
-  public:
-    MyPatternRewriter(MLIRContext *ctx) : PatternRewriter(ctx) {}
-  };
-
-  MyPatternRewriter rewriter(&context);
+  PatternRewriter rewriter(&context);
   (void)pa.matchAndRewrite(*module, rewriter);
 
   EXPECT_TRUE(called1);

@amd-eochoalo
Copy link
Contributor

@Hardcode84 there's also DummyRewriter in flang/lib/Optimizer/Transforms/SimplifyRegionLite.cpp

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Aug 25, 2025
@Hardcode84 Hardcode84 merged commit 02540b2 into llvm:main Aug 25, 2025
11 checks passed
@Hardcode84 Hardcode84 deleted the trivial-rewriter branch August 25, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category mlir:linalg mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants