[Mlir-commits] [mlir] [MLIR] Clone attrs of unregistered ops (PR #151847)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Aug 2 21:18:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-core
Author: Boyana Norris (brnorris03)
<details>
<summary>Changes</summary>
`Operation::clone` does not clone the properties of unregistered ops. This patch copies the opaque properties after the new operation is built.
fixes #<!-- -->151640
---
Full diff: https://github.com/llvm/llvm-project/pull/151847.diff
2 Files Affected:
- (modified) mlir/lib/IR/Operation.cpp (+9-2)
- (modified) mlir/test/IR/test-clone.mlir (+33-1)
``````````diff
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 8bcfa465e4a22..75e1f408e3256 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -732,8 +732,15 @@ Operation *Operation::clone(IRMapping &mapper, CloneOptions options) {
successors.push_back(mapper.lookupOrDefault(successor));
// Create the new operation.
- auto *newOp = create(getLoc(), getName(), getResultTypes(), operands, attrs,
- getPropertiesStorage(), successors, getNumRegions());
+ auto *newOp = create(getLoc(), getName(), getResultTypes(), operands,
+ getAttrDictionary(), getPropertiesStorage(), successors,
+ getNumRegions());
+
+ // The builder overwrites the opaque properties with the attributes; hence,
+ // copy them after building the operation.
+ if (!isRegistered())
+ newOp->copyProperties(getPropertiesStorage());
+
mapper.map(this, newOp);
// Clone the regions.
diff --git a/mlir/test/IR/test-clone.mlir b/mlir/test/IR/test-clone.mlir
index 0c07593aef32d..6bfc690bd1dbe 100644
--- a/mlir/test/IR/test-clone.mlir
+++ b/mlir/test/IR/test-clone.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(func.func(test-clone))" | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(func.func(test-clone))" --split-input-file | FileCheck %s
module {
func.func @fixpoint(%arg1 : i32) -> i32 {
@@ -33,3 +33,35 @@ module {
// CHECK-NEXT: }) : (i32) -> i32
// CHECK-NEXT: return %[[i1]] : i32
// CHECK-NEXT: }
+
+// -----
+
+func.func @clone_unregistered_with_attrs() {
+ "unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = 3.14 : f32}> : () -> ()
+ "unregistered.bar"() : () -> ()
+ "unregistered.empty_dict"() <{}> : () -> ()
+ "unregistered.complex"() <{
+ array = [1, 2, 3],
+ dict = {key1 = 42 : i32, key2 = "value"},
+ nested = {inner = {deep = 100 : i64}}
+ }> : () -> ()
+ return
+}
+
+// CHECK: notifyOperationInserted: unregistered.foo
+// CHECK-NEXT: notifyOperationInserted: unregistered.bar
+// CHECK-NEXT: notifyOperationInserted: unregistered.empty_dict
+// CHECK-NEXT: notifyOperationInserted: unregistered.complex
+// CHECK-NEXT: notifyOperationInserted: func.return
+
+// CHECK: func @clone_unregistered_with_attrs() {
+// CHECK-NEXT: "unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = [[PI:.+]] : f32}> : () -> ()
+// CHECK-NEXT: "unregistered.bar"() : () -> ()
+// CHECK-NEXT: "unregistered.empty_dict"() <{}> : () -> ()
+// CHECK-NEXT: "unregistered.complex"() <{array = [1, 2, 3], dict = {key1 = 42 : i32, key2 = "value"}, nested = {inner = {deep = 100 : i64}}}> : () -> ()
+// CHECK-NEXT: "unregistered.foo"() <{bar = 1 : i64, flag = true, name = "test", value = [[PI]] : f32}> : () -> ()
+// CHECK-NEXT: "unregistered.bar"() : () -> ()
+// CHECK-NEXT: "unregistered.empty_dict"() <{}> : () -> ()
+// CHECK-NEXT: "unregistered.complex"() <{array = [1, 2, 3], dict = {key1 = 42 : i32, key2 = "value"}, nested = {inner = {deep = 100 : i64}}}> : () -> ()
+// CHECK-NEXT: return
+// CHECK-NEXT: }
``````````
</details>
https://github.com/llvm/llvm-project/pull/151847
More information about the Mlir-commits
mailing list