[Mlir-commits] [mlir] [MLIR] Add support for IntArrayProp<I32Prop> (PR #146685)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 2 05:59:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Mehdi Amini (joker-eph)
<details>
<summary>Changes</summary>
The conversion to attribute was missing.
---
Full diff: https://github.com/llvm/llvm-project/pull/146685.diff
5 Files Affected:
- (modified) mlir/include/mlir/IR/ODSSupport.h (+3)
- (modified) mlir/lib/IR/ODSSupport.cpp (+5)
- (modified) mlir/test/IR/properties.mlir (+3-3)
- (modified) mlir/test/Transforms/test-legalizer.mlir (+1-1)
- (modified) mlir/test/lib/Dialect/Test/TestOps.td (+4-2)
``````````diff
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
);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/146685
More information about the Mlir-commits
mailing list