[Mlir-commits] [mlir] [MLIR] Add support for IntArrayProp<I32Prop> (PR #146685)
Mehdi Amini
llvmlistbot at llvm.org
Sun Jul 6 02:54:54 PDT 2025
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/146685
>From 4858f4dbf668b005514aa25b64a04360c13a23d5 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 2 Jul 2025 05:56:58 -0700
Subject: [PATCH 1/2] [MLIR] Add support for IntArrayProp<I32Prop>
The conversion to attribute was missing.
---
mlir/include/mlir/IR/ODSSupport.h | 3 +++
mlir/lib/IR/ODSSupport.cpp | 5 +++++
mlir/test/IR/properties.mlir | 6 +++---
mlir/test/Transforms/test-legalizer.mlir | 2 +-
mlir/test/lib/Dialect/Test/TestOps.td | 6 ++++--
5 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/mlir/include/mlir/IR/ODSSupport.h b/mlir/include/mlir/IR/ODSSupport.h
index b24a2470470ff..036ce4e5b725f 100644
--- a/mlir/include/mlir/IR/ODSSupport.h
+++ b/mlir/include/mlir/IR/ODSSupport.h
@@ -118,6 +118,9 @@ convertFromAttribute(SmallVectorImpl<int32_t> &storage, Attribute attr,
/// Convert the provided ArrayRef<int64_t> to a DenseI64ArrayAttr attribute.
Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int64_t> storage);
+/// Convert the provided ArrayRef<int32_t> to a DenseI32ArrayAttr attribute.
+Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int32_t> storage);
+
} // namespace mlir
#endif // MLIR_IR_ODSSUPPORT_H
diff --git a/mlir/lib/IR/ODSSupport.cpp b/mlir/lib/IR/ODSSupport.cpp
index 5b0a3e22139e1..69b4a563e6b75 100644
--- a/mlir/lib/IR/ODSSupport.cpp
+++ b/mlir/lib/IR/ODSSupport.cpp
@@ -173,3 +173,8 @@ Attribute mlir::convertToAttribute(MLIRContext *ctx,
ArrayRef<int64_t> storage) {
return DenseI64ArrayAttr::get(ctx, storage);
}
+
+Attribute mlir::convertToAttribute(MLIRContext *ctx,
+ ArrayRef<int32_t> storage) {
+ return DenseI32ArrayAttr::get(ctx, storage);
+}
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index dde9100cde142..b541447e85c7b 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -2,10 +2,10 @@
// # RUN: mlir-opt %s -mlir-print-op-generic -split-input-file | mlir-opt -mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC
// CHECK: test.with_properties
-// CHECK-SAME: a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]{{$}}
+// CHECK-SAME: a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]{{$}}
// GENERIC: "test.with_properties"()
-// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo", c = "bar", flag = true}> : () -> ()
-test.with_properties a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]
+// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, array32 = array<i32: 5, 6>, b = "foo", c = "bar", flag = true}> : () -> ()
+test.with_properties a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]
// CHECK: test.with_nice_properties
// CHECK-SAME: "foo bar" is -3{{$}}
diff --git a/mlir/test/Transforms/test-legalizer.mlir b/mlir/test/Transforms/test-legalizer.mlir
index 79518b04e7158..40ab3fc974cb4 100644
--- a/mlir/test/Transforms/test-legalizer.mlir
+++ b/mlir/test/Transforms/test-legalizer.mlir
@@ -434,7 +434,7 @@ func.func @test_properties_rollback() {
// CHECK: test.with_properties a = 32,
// expected-remark @below{{op 'test.with_properties' is not legalizable}}
test.with_properties
- a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]
+ a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]
{modify_inplace}
"test.return"() : () -> ()
}
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 0ad5bfa9a58ab..97469d29ec961 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -3179,13 +3179,15 @@ def TestOpWithProperties : TEST_Op<"with_properties"> {
`b` `=` $b `,`
`c` `=` $c `,`
`flag` `=` $flag `,`
- `array` `=` $array attr-dict}];
+ `array` `=` $array `,`
+ `array32` `=` $array32 attr-dict}];
let arguments = (ins
I64Prop:$a,
StrAttr:$b, // Attributes can directly be used here.
StringProp:$c,
BoolProp:$flag,
- IntArrayProp<I64Prop>:$array // example of an array
+ IntArrayProp<I64Prop>:$array, // example of an array
+ IntArrayProp<I32Prop>:$array32 // example of an array
);
}
>From 6844e7943a5433117d9b46a9479e98c576a30094 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Sun, 6 Jul 2025 11:54:47 +0200
Subject: [PATCH 2/2] Update mlir/test/lib/Dialect/Test/TestOps.td
Co-authored-by: Oleksandr "Alex" Zinenko <azinenko at amd.com>
---
mlir/test/lib/Dialect/Test/TestOps.td | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 97469d29ec961..09974c3612962 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -3186,8 +3186,8 @@ def TestOpWithProperties : TEST_Op<"with_properties"> {
StrAttr:$b, // Attributes can directly be used here.
StringProp:$c,
BoolProp:$flag,
- IntArrayProp<I64Prop>:$array, // example of an array
- IntArrayProp<I32Prop>:$array32 // example of an array
+ IntArrayProp<I64Prop>:$array, // Example of an array.
+ IntArrayProp<I32Prop>:$array32 // Example of an array.
);
}
More information about the Mlir-commits
mailing list