-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[mlir][Transforms] Dialect Conversion: Convert entry block only #165180
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
matthias-springer
merged 2 commits into
main
from
users/matthias-springer/func_convert_entry_block
Nov 3, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
mlir/test/Transforms/test-legalizer-no-materializations.mlir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-legalize-patterns="allow-pattern-rollback=0 build-materializations=0 attach-debug-materialization-kind=1" -verify-diagnostics %s | FileCheck %s --check-prefix=CHECK-KIND | ||
|
|
||
| // CHECK-LABEL: func @dropped_input_in_use | ||
| // CHECK-KIND-LABEL: func @dropped_input_in_use | ||
| func.func @dropped_input_in_use(%arg: i16, %arg2: i64) { | ||
| // CHECK-NEXT: %[[cast:.*]] = "test.cast"() : () -> i16 | ||
| // CHECK-NEXT: "work"(%[[cast]]) : (i16) | ||
| // CHECK-KIND-NEXT: %[[cast:.*]] = builtin.unrealized_conversion_cast to i16 {__kind__ = "source"} | ||
| // CHECK-KIND-NEXT: "work"(%[[cast]]) : (i16) | ||
| // expected-remark@+1 {{op 'work' is not legalizable}} | ||
| "work"(%arg) : (i16) -> () | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK-KIND-LABEL: func @test_lookup_without_converter | ||
| // CHECK-KIND: %[[producer:.*]] = "test.valid_producer"() : () -> i16 | ||
| // CHECK-KIND: %[[cast:.*]] = builtin.unrealized_conversion_cast %[[producer]] : i16 to f64 {__kind__ = "target"} | ||
| // CHECK-KIND: "test.valid_consumer"(%[[cast]]) : (f64) -> () | ||
| // CHECK-KIND: "test.valid_consumer"(%[[producer]]) : (i16) -> () | ||
| func.func @test_lookup_without_converter() { | ||
| %0 = "test.replace_with_valid_producer"() {type = i16} : () -> (i64) | ||
| "test.replace_with_valid_consumer"(%0) {with_converter} : (i64) -> () | ||
| // Make sure that the second "replace_with_valid_consumer" lowering does not | ||
| // lookup the materialization that was created for the above op. | ||
| "test.replace_with_valid_consumer"(%0) : (i64) -> () | ||
| // expected-remark@+1 {{op 'func.return' is not legalizable}} | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK-LABEL: func @remap_moved_region_args | ||
| func.func @remap_moved_region_args() { | ||
| // CHECK-NEXT: return | ||
| // CHECK-NEXT: ^bb1(%[[arg0:.*]]: i64, %[[arg1:.*]]: i16, %[[arg2:.*]]: i64, %[[arg3:.*]]: f32): | ||
| // CHECK-NEXT: %[[cast1:.*]]:2 = builtin.unrealized_conversion_cast %[[arg3]] : f32 to f16, f16 | ||
| // CHECK-NEXT: %[[cast2:.*]] = builtin.unrealized_conversion_cast %[[arg2]] : i64 to f64 | ||
| // CHECK-NEXT: %[[cast3:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to f64 | ||
| // CHECK-NEXT: %[[cast4:.*]] = "test.cast"(%[[cast1]]#0, %[[cast1]]#1) : (f16, f16) -> f32 | ||
| // CHECK-NEXT: "test.valid"(%[[cast3]], %[[cast2]], %[[cast4]]) : (f64, f64, f32) | ||
| "test.region"() ({ | ||
| ^bb1(%i0: i64, %unused: i16, %i1: i64, %2: f32): | ||
| "test.invalid"(%i0, %i1, %2) : (i64, i64, f32) -> () | ||
| }) : () -> () | ||
| // expected-remark@+1 {{op 'func.return' is not legalizable}} | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK-LABEL: func @remap_cloned_region_args | ||
| func.func @remap_cloned_region_args() { | ||
| // CHECK-NEXT: return | ||
| // CHECK-NEXT: ^bb1(%[[arg0:.*]]: i64, %[[arg1:.*]]: i16, %[[arg2:.*]]: i64, %[[arg3:.*]]: f32): | ||
| // CHECK-NEXT: %[[cast1:.*]]:2 = builtin.unrealized_conversion_cast %[[arg3]] : f32 to f16, f16 | ||
| // CHECK-NEXT: %[[cast2:.*]] = builtin.unrealized_conversion_cast %[[arg2]] : i64 to f64 | ||
| // CHECK-NEXT: %[[cast3:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to f64 | ||
| // CHECK-NEXT: %[[cast4:.*]] = "test.cast"(%[[cast1]]#0, %[[cast1]]#1) : (f16, f16) -> f32 | ||
| // CHECK-NEXT: "test.valid"(%[[cast3]], %[[cast2]], %[[cast4]]) : (f64, f64, f32) | ||
| "test.region"() ({ | ||
| ^bb1(%i0: i64, %unused: i16, %i1: i64, %2: f32): | ||
| "test.invalid"(%i0, %i1, %2) : (i64, i64, f32) -> () | ||
| }) {legalizer.should_clone} : () -> () | ||
| // expected-remark@+1 {{op 'func.return' is not legalizable}} | ||
| return | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting up the legalization test looks unrelated, do we have to do it as a part of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last two test cases that I moved produce different IR and error messages when running with
build-materializations=0. That's because the block signatures are no longer getting converted. (And the blocks are dead, so they are not converted by the CF structural type conversion pattern.)