Skip to content

Commit

Permalink
[mlir] don't hardcode PDL_Operation in TestTransformDialectExtensions
Browse files Browse the repository at this point in the history
Update operations in Transform dialect extensions used for testing to
use the more generic `TransformHandleTypeInterface` type constraint
instead of hardcoding `PDL_Operation`. See
https://discourse.llvm.org/t/rfc-type-system-for-the-transform-dialect/65702
for motivation. This is particularly important as these tests are often
used as source of best practices.

Update tests to use `!transform.any_op` instead of `!pdl.operation`.

Depends On D150785

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D150786
  • Loading branch information
ftynse committed May 22, 2023
1 parent 9813c18 commit 46af120
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 420 deletions.
82 changes: 41 additions & 41 deletions mlir/test/Dialect/Transform/check-use-after-free.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

func.func @use_after_free_branching_control_flow() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
Expand All @@ -11,14 +11,14 @@ func.func @use_after_free_branching_control_flow() {
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb1:
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand"
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb3:
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !pdl.operation failures(propagate) {
^bb0(%arg0: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
"transform.test_branching_transform_op_terminator"() : () -> ()
}
Expand All @@ -29,7 +29,7 @@ func.func @use_after_free_branching_control_flow() {

func.func @use_after_free_in_nested_op() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
// expected-note @below {{freed here}}
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
Expand All @@ -38,16 +38,16 @@ func.func @use_after_free_in_nested_op() {
^bb0:
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb1:
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand"
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb3:
"transform.test_branching_transform_op_terminator"() : () -> ()
}
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !pdl.operation failures(propagate) {
^bb0(%arg0: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
return
}
Expand All @@ -56,29 +56,29 @@ func.func @use_after_free_in_nested_op() {

func.func @use_after_free_recursive_side_effects() {
transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation):
^bb0(%arg0: !transform.any_op):
// expected-note @below {{allocated here}}
%0 = transform.sequence %arg0 : !pdl.operation -> !pdl.operation failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !pdl.operation):
yield %arg1 : !pdl.operation
%0 = transform.sequence %arg0 : !transform.any_op -> !transform.any_op failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !transform.any_op):
yield %arg1 : !transform.any_op
}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !transform.any_op):
}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !transform.any_op):
}

// `transform.sequence` has recursive side effects so it has the same "free"
// as the child op it contains.
// expected-note @below {{freed here}}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 4 } {
^bb4(%arg4: !pdl.operation):
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence"
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 4 } {
^bb4(%arg4: !transform.any_op):
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence" : !transform.any_op
}
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !transform.any_op):
}
}
return
Expand All @@ -88,24 +88,24 @@ func.func @use_after_free_recursive_side_effects() {

func.func @use_after_free() {
transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation):
^bb0(%arg0: !transform.any_op):
// expected-note @below {{allocated here}}
%0 = transform.sequence %arg0 : !pdl.operation -> !pdl.operation failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !pdl.operation):
yield %arg1 : !pdl.operation
%0 = transform.sequence %arg0 : !transform.any_op -> !transform.any_op failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !transform.any_op):
yield %arg1 : !transform.any_op
}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !transform.any_op):
}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !transform.any_op):
}

// expected-note @below {{freed here}}
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence"
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence" : !transform.any_op
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !pdl.operation failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !transform.any_op):
}
}
return
Expand All @@ -118,7 +118,7 @@ func.func @use_after_free() {
// be reported as use-after-free.
func.func @use_after_free_self_cycle() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
Expand All @@ -127,12 +127,12 @@ func.func @use_after_free_self_cycle() {
"transform.test_branching_transform_op_terminator"()[^bb1] : () -> ()
^bb1:
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !pdl.operation failures(propagate) {
^bb0(%arg0: !pdl.operation):
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
// expected-warning @below {{operand #0 may be used after free}}
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand"
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"() : () -> ()
Expand All @@ -147,7 +147,7 @@ func.func @use_after_free_self_cycle() {
// use-after-free.
func.func @use_after_free_cycle() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
Expand All @@ -157,7 +157,7 @@ func.func @use_after_free_cycle() {
^bb1:
// expected-warning @below {{operand #0 may be used after free}}
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand"
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb2, ^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb1] : () -> ()
Expand All @@ -172,8 +172,8 @@ func.func @use_after_free_cycle() {
// This should not crash.

transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation):
alternatives %arg0 : !pdl.operation {
^bb0(%arg1: !pdl.operation):
^bb0(%arg0: !transform.any_op):
alternatives %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
}
}
56 changes: 28 additions & 28 deletions mlir/test/Dialect/Transform/expensive-checks.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ func.func @func() {
}

transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
^bb0(%arg0: !transform.any_op):
pdl.pattern @return : benefit(1) {
%0 = operands
%1 = types
%2 = operation "func.return"(%0 : !pdl.range<value>) -> (%1 : !pdl.range<type>)
rewrite %2 with "transform.dialect"
}

sequence %arg0 : !pdl.operation failures(propagate) {
^bb1(%arg1: !pdl.operation):
sequence %arg0 : !transform.any_op failures(propagate) {
^bb1(%arg1: !transform.any_op):
// expected-note @below {{handle to invalidated ops}}
%0 = pdl_match @return in %arg1 : (!pdl.operation) -> !pdl.operation
%1 = get_closest_isolated_parent %0 : (!pdl.operation) -> !pdl.operation
%0 = pdl_match @return in %arg1 : (!transform.any_op) -> !transform.any_op
%1 = get_closest_isolated_parent %0 : (!transform.any_op) -> !transform.any_op
// expected-note @below {{invalidated by this transform op that consumes its operand #0}}
test_consume_operand %1 : !pdl.operation
test_consume_operand %1 : !transform.any_op
// expected-error @below {{op uses a handle invalidated by a previously executed transform op}}
test_print_remark_at_operand %0, "remark" : !pdl.operation
test_print_remark_at_operand %0, "remark" : !transform.any_op
}
}

Expand All @@ -36,7 +36,7 @@ func.func @func1() {
func.func private @func2()

transform.with_pdl_patterns {
^bb0(%arg0: !pdl.operation):
^bb0(%arg0: !transform.any_op):
pdl.pattern @func : benefit(1) {
%0 = operands
%1 = types
Expand All @@ -50,14 +50,14 @@ transform.with_pdl_patterns {
rewrite %2 with "transform.dialect"
}

sequence %arg0 : !pdl.operation failures(propagate) {
^bb1(%arg1: !pdl.operation):
%0 = pdl_match @func in %arg1 : (!pdl.operation) -> !pdl.operation
%1 = pdl_match @return in %arg1 : (!pdl.operation) -> !pdl.operation
%2 = replicate num(%0) %1 : !pdl.operation, !pdl.operation
sequence %arg0 : !transform.any_op failures(propagate) {
^bb1(%arg1: !transform.any_op):
%0 = pdl_match @func in %arg1 : (!transform.any_op) -> !transform.any_op
%1 = pdl_match @return in %arg1 : (!transform.any_op) -> !transform.any_op
%2 = replicate num(%0) %1 : !transform.any_op, !transform.any_op
// expected-error @below {{a handle passed as operand #0 and consumed by this operation points to a payload entity more than once}}
test_consume_operand %2 : !pdl.operation
test_print_remark_at_operand %0, "remark" : !pdl.operation
test_consume_operand %2 : !transform.any_op
test_print_remark_at_operand %0, "remark" : !transform.any_op
}
}

Expand All @@ -69,14 +69,14 @@ transform.with_pdl_patterns {
module {

transform.sequence failures(propagate) {
^bb0(%0: !pdl.operation):
%1 = transform.test_copy_payload %0
^bb0(%0: !transform.any_op):
%1 = transform.test_copy_payload %0 : (!transform.any_op) -> !transform.any_op
// expected-note @below {{handle to invalidated ops}}
%2 = transform.test_copy_payload %0
%2 = transform.test_copy_payload %0 : (!transform.any_op) ->!transform.any_op
// expected-note @below {{invalidated by this transform op that consumes its operand #0}}
transform.test_consume_operand %1 : !pdl.operation
transform.test_consume_operand %1 : !transform.any_op
// expected-error @below {{op uses a handle invalidated by a previously executed transform op}}
transform.test_consume_operand %2 : !pdl.operation
transform.test_consume_operand %2 : !transform.any_op
}
}

Expand All @@ -87,16 +87,16 @@ module {
module {

transform.sequence failures(propagate) {
^bb0(%0: !pdl.operation):
%1 = transform.test_copy_payload %0
^bb0(%0: !transform.any_op):
%1 = transform.test_copy_payload %0 : (!transform.any_op) -> !transform.any_op
// expected-note @below {{handle to invalidated ops}}
%2 = transform.test_copy_payload %0
%2 = transform.test_copy_payload %0 : (!transform.any_op) -> !transform.any_op
// Consuming two handles in the same operation is invalid if they point
// to overlapping sets of payload IR ops.
//
// expected-error @below {{op uses a handle invalidated by a previously executed transform op}}
// expected-note @below {{invalidated by this transform op that consumes its operand #0 and invalidates all handles to payload IR entities}}
transform.test_consume_operand %1, %2 : !pdl.operation
transform.test_consume_operand %1, %2 : !transform.any_op, !transform.any_op
}
}

Expand All @@ -107,10 +107,10 @@ module {
module {

transform.sequence failures(propagate) {
^bb0(%0: !pdl.operation):
%1 = transform.test_copy_payload %0
%2 = transform.test_copy_payload %0
transform.merge_handles %1, %2 { deduplicate } : !pdl.operation
^bb0(%0: !transform.any_op):
%1 = transform.test_copy_payload %0 : (!transform.any_op) -> !transform.any_op
%2 = transform.test_copy_payload %0 : (!transform.any_op) -> !transform.any_op
transform.merge_handles %1, %2 { deduplicate } : !transform.any_op
}
}
// -----
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Dialect/Transform/multi-arg-top-level-params.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: --split-input-file --verify-diagnostics

transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation, %arg1: !transform.param<i64>, %arg2: !transform.param<i64>):
^bb0(%arg0: !transform.any_op, %arg1: !transform.param<i64>, %arg2: !transform.param<i64>):
// expected-remark @below {{1 : i64, 2 : i64, 3 : i64}}
transform.test_print_param %arg1 : !transform.param<i64>
// expected-remark @below {{42 : i64, 45 : i64}}
Expand All @@ -12,13 +12,13 @@ transform.sequence failures(propagate) {
// -----

transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation, %arg1: !transform.any_op, %arg2: !transform.param<i64>):
^bb0(%arg0: !transform.any_op, %arg1: !transform.any_op, %arg2: !transform.param<i64>):
// expected-error @above {{wrong kind of value provided for top-level operation handle}}
}

// -----

// expected-error @below {{operation expects 3 extra value bindings, but 2 were provided to the interpreter}}
transform.sequence failures(propagate) {
^bb0(%arg0: !pdl.operation, %arg1: !transform.param<i64>, %arg2: !transform.param<i64>, %arg3: !transform.param<i64>):
^bb0(%arg0: !transform.any_op, %arg1: !transform.param<i64>, %arg2: !transform.param<i64>, %arg3: !transform.param<i64>):
}
Loading

0 comments on commit 46af120

Please sign in to comment.