Skip to content

[MLIR][DialectConversion] Export isOpIgnored in ConversionPatternRewriter #154300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wsmoses
Copy link
Member

@wsmoses wsmoses commented Aug 19, 2025

This is particularly helpful for more complex dialect conversion patterns which conditionally apply given the subject of an analysis of the non-deleted operations

@wsmoses wsmoses requested review from ftynse and joker-eph August 19, 2025 09:31
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Aug 19, 2025
@wsmoses wsmoses requested a review from chelini August 19, 2025 09:32
@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2025

@llvm/pr-subscribers-mlir

Author: William Moses (wsmoses)

Changes

This is particularly helpful for more complex dialect conversion patterns which conditionally apply given the subject of an analysis of the non-deleted operations


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

2 Files Affected:

  • (modified) mlir/include/mlir/Transforms/DialectConversion.h (+3)
  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+4)
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index 536b23f5c33c1..5de58b89130a2 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -862,6 +862,9 @@ class ConversionPatternRewriter final : public PatternRewriter {
   /// Return a reference to the internal implementation.
   detail::ConversionPatternRewriterImpl &getImpl();
 
+  /// Return "true" if the given operation was replaced or erased.
+  bool isOpIgnored(Operation *op) const;
+
 private:
   // Allow OperationConverter to construct new rewriters.
   friend struct OperationConverter;
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 7494ca9ec3784..f95340c718409 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2245,6 +2245,10 @@ detail::ConversionPatternRewriterImpl &ConversionPatternRewriter::getImpl() {
   return *impl;
 }
 
+bool ConversionPatternRewriter::isOpIgnored(Operation *op) const {
+  return getImpl()->isOpIgnored(op);
+}
+
 //===----------------------------------------------------------------------===//
 // ConversionPattern
 //===----------------------------------------------------------------------===//

@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2025

@llvm/pr-subscribers-mlir-core

Author: William Moses (wsmoses)

Changes

This is particularly helpful for more complex dialect conversion patterns which conditionally apply given the subject of an analysis of the non-deleted operations


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

2 Files Affected:

  • (modified) mlir/include/mlir/Transforms/DialectConversion.h (+3)
  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+4)
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index 536b23f5c33c1..5de58b89130a2 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -862,6 +862,9 @@ class ConversionPatternRewriter final : public PatternRewriter {
   /// Return a reference to the internal implementation.
   detail::ConversionPatternRewriterImpl &getImpl();
 
+  /// Return "true" if the given operation was replaced or erased.
+  bool isOpIgnored(Operation *op) const;
+
 private:
   // Allow OperationConverter to construct new rewriters.
   friend struct OperationConverter;
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 7494ca9ec3784..f95340c718409 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2245,6 +2245,10 @@ detail::ConversionPatternRewriterImpl &ConversionPatternRewriter::getImpl() {
   return *impl;
 }
 
+bool ConversionPatternRewriter::isOpIgnored(Operation *op) const {
+  return getImpl()->isOpIgnored(op);
+}
+
 //===----------------------------------------------------------------------===//
 // ConversionPattern
 //===----------------------------------------------------------------------===//

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a test upstream?

I don't quite get the usage of this right now.

@matthias-springer
Copy link
Member

matthias-springer commented Aug 19, 2025

Can you describe a bit when this function is useful? This is an implementation detail of the conversion driver and we should expose it only if needed. (E.g., "ignoredOps" in the new conversion driver (allowPatternRollback = false) has a slightly different meaning because ops are immediately erased.)

Can you work with ConversionTarget::isLegal(Operation *) instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants