[Mlir-commits] [mlir] ca297cd - [MLIR] Add support for IntArrayProp<I32Prop> (#146685)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jul 6 02:55:05 PDT 2025
Author: Mehdi Amini
Date: 2025-07-06T11:55:02+02:00
New Revision: ca297cd6e4ada67a764a16f3c8312e041d6e4e75
URL: https://github.com/llvm/llvm-project/commit/ca297cd6e4ada67a764a16f3c8312e041d6e4e75
DIFF: https://github.com/llvm/llvm-project/commit/ca297cd6e4ada67a764a16f3c8312e041d6e4e75.diff
LOG: [MLIR] Add support for IntArrayProp<I32Prop> (#146685)
The conversion to attribute was missing.
Added:
Modified:
mlir/include/mlir/IR/ODSSupport.h
mlir/lib/IR/ODSSupport.cpp
mlir/test/IR/properties.mlir
mlir/test/Transforms/test-legalizer.mlir
mlir/test/lib/Dialect/Test/TestOps.td
Removed:
################################################################################
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 07ad5507610c0..68c863cff69bf 100644
--- a/mlir/test/Transforms/test-legalizer.mlir
+++ b/mlir/test/Transforms/test-legalizer.mlir
@@ -442,7 +442,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 5320ba4ea3829..535f5e9b4a15d 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.
);
}
More information about the Mlir-commits
mailing list