Skip to content

Commit 1eaf736

Browse files
authored
[mlir] Clone attrs of unregistered dialect ops (#151847)
`Operation::clone` does not clone the properties of unregistered ops. This patch modifies the property initialization for unregistered ops to initialize properties as attributes. fixes #151640 --------- Signed-off-by: Boyana Norris <[email protected]>
1 parent df3f629 commit 1eaf736

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

mlir/lib/IR/MLIRContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ int OperationName::UnregisteredOpModel::getOpPropertyByteSize() {
884884
void OperationName::UnregisteredOpModel::initProperties(
885885
OperationName opName, OpaqueProperties storage, OpaqueProperties init) {
886886
new (storage.as<Attribute *>()) Attribute();
887+
if (init)
888+
*storage.as<Attribute *>() = *init.as<Attribute *>();
887889
}
888890
void OperationName::UnregisteredOpModel::deleteProperties(
889891
OpaqueProperties prop) {

mlir/test/IR/test-clone.mlir

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(func.func(test-clone))" | FileCheck %s
1+
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(func.func(test-clone))" --split-input-file | FileCheck %s
22

33
module {
44
func.func @fixpoint(%arg1 : i32) -> i32 {
@@ -18,7 +18,8 @@ module {
1818
// CHECK-NEXT: notifyOperationInserted: test.yield
1919
// CHECK-NEXT: notifyOperationInserted: func.return
2020

21-
// CHECK: func @fixpoint(%[[arg0:.+]]: i32) -> i32 {
21+
// CHECK-LABEL: func @fixpoint
22+
// CHECK-SAME: (%[[arg0:.+]]: i32) -> i32 {
2223
// CHECK-NEXT: %[[i0:.+]] = "test.use"(%[[arg0]]) ({
2324
// CHECK-NEXT: %[[r2:.+]] = "test.use2"(%[[arg0]]) ({
2425
// CHECK-NEXT: "test.yield2"(%[[arg0]]) : (i32) -> ()
@@ -33,3 +34,33 @@ module {
3334
// CHECK-NEXT: }) : (i32) -> i32
3435
// CHECK-NEXT: return %[[i1]] : i32
3536
// CHECK-NEXT: }
37+
38+
// -----
39+
40+
func.func @clone_unregistered_with_attrs() {
41+
"unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = 3.14 : f32}> : () -> ()
42+
"unregistered.bar"() : () -> ()
43+
"unregistered.empty_dict"() <{}> : () -> ()
44+
"unregistered.complex"() <{
45+
array = [1, 2, 3],
46+
dict = {key1 = 42 : i32, key2 = "value"},
47+
nested = {inner = {deep = 100 : i64}}
48+
}> : () -> ()
49+
return
50+
}
51+
52+
// CHECK: notifyOperationInserted: unregistered.foo
53+
// CHECK-NEXT: notifyOperationInserted: unregistered.bar
54+
// CHECK-NEXT: notifyOperationInserted: unregistered.empty_dict
55+
// CHECK-NEXT: notifyOperationInserted: unregistered.complex
56+
// CHECK-NEXT: notifyOperationInserted: func.return
57+
58+
// CHECK-LABEL: func @clone_unregistered_with_attrs() {
59+
// CHECK-NEXT: "unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = [[PI:.+]] : f32}> : () -> ()
60+
// CHECK-NEXT: "unregistered.bar"() : () -> ()
61+
// CHECK-NEXT: "unregistered.empty_dict"() <{}> : () -> ()
62+
// CHECK-NEXT: "unregistered.complex"() <{array = [1, 2, 3], dict = {key1 = 42 : i32, key2 = "value"}, nested = {inner = {deep = 100 : i64}}}> : () -> ()
63+
// CHECK-NEXT: "unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = [[PI]] : f32}> : () -> ()
64+
// CHECK-NEXT: "unregistered.bar"() : () -> ()
65+
// CHECK-NEXT: "unregistered.empty_dict"() <{}> : () -> ()
66+
// CHECK-NEXT: "unregistered.complex"() <{array = [1, 2, 3], dict = {key1 = 42 : i32, key2 = "value"}, nested = {inner = {deep = 100 : i64}}}> : () -> ()

0 commit comments

Comments
 (0)