Skip to content

[mlir][Transforms] Dialect Conversion: Simplify block-inline handling #145308

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

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

matthias-springer
Copy link
Member

When a block is getting inlined, the destination block does not have to be legalized. That's because the signature of the destination block does not change by inlining.

This commit makes the implementation consistent with this comment:

  // If the pattern moved or created any blocks, make sure the types of block
  // arguments get legalized.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-mlir

Author: Matthias Springer (matthias-springer)

Changes

When a block is getting inlined, the destination block does not have to be legalized. That's because the signature of the destination block does not change by inlining.

This commit makes the implementation consistent with this comment:

  // If the pattern moved or created any blocks, make sure the types of block
  // arguments get legalized.

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

1 Files Affected:

  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+1-1)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 9cb6f2ba1eaae..7cfe7250d02c3 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2301,7 +2301,7 @@ LogicalResult OperationLegalizer::legalizePatternBlockRewrites(
       continue;
     Block *block = rewrite->getBlock();
     if (isa<BlockTypeConversionRewrite, EraseBlockRewrite,
-            ReplaceBlockArgRewrite>(rewrite))
+            ReplaceBlockArgRewrite, InlineBlockRewrite>(rewrite))
       continue;
     // Only check blocks outside of the current operation.
     Operation *parentOp = block->getParentOp();

@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

Changes

When a block is getting inlined, the destination block does not have to be legalized. That's because the signature of the destination block does not change by inlining.

This commit makes the implementation consistent with this comment:

  // If the pattern moved or created any blocks, make sure the types of block
  // arguments get legalized.

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

1 Files Affected:

  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+1-1)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 9cb6f2ba1eaae..7cfe7250d02c3 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2301,7 +2301,7 @@ LogicalResult OperationLegalizer::legalizePatternBlockRewrites(
       continue;
     Block *block = rewrite->getBlock();
     if (isa<BlockTypeConversionRewrite, EraseBlockRewrite,
-            ReplaceBlockArgRewrite>(rewrite))
+            ReplaceBlockArgRewrite, InlineBlockRewrite>(rewrite))
       continue;
     // Only check blocks outside of the current operation.
     Operation *parentOp = block->getParentOp();

@matthias-springer matthias-springer merged commit c5972da into main Jun 24, 2025
10 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/inline_block_rew branch June 24, 2025 06:52
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
…llvm#145308)

When a block is getting inlined, the destination block does not have to
be legalized. That's because the signature of the destination block does
not change by inlining.

This commit makes the implementation consistent with this comment:
```
  // If the pattern moved or created any blocks, make sure the types of block
  // arguments get legalized.
```
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…llvm#145308)

When a block is getting inlined, the destination block does not have to
be legalized. That's because the signature of the destination block does
not change by inlining.

This commit makes the implementation consistent with this comment:
```
  // If the pattern moved or created any blocks, make sure the types of block
  // arguments get legalized.
```
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.

3 participants