Skip to content

Commit ca297cd

Browse files
authored
[MLIR] Add support for IntArrayProp<I32Prop> (#146685)
The conversion to attribute was missing.
1 parent 6c257f7 commit ca297cd

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

mlir/include/mlir/IR/ODSSupport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ convertFromAttribute(SmallVectorImpl<int32_t> &storage, Attribute attr,
118118
/// Convert the provided ArrayRef<int64_t> to a DenseI64ArrayAttr attribute.
119119
Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int64_t> storage);
120120

121+
/// Convert the provided ArrayRef<int32_t> to a DenseI32ArrayAttr attribute.
122+
Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int32_t> storage);
123+
121124
} // namespace mlir
122125

123126
#endif // MLIR_IR_ODSSUPPORT_H

mlir/lib/IR/ODSSupport.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,8 @@ Attribute mlir::convertToAttribute(MLIRContext *ctx,
173173
ArrayRef<int64_t> storage) {
174174
return DenseI64ArrayAttr::get(ctx, storage);
175175
}
176+
177+
Attribute mlir::convertToAttribute(MLIRContext *ctx,
178+
ArrayRef<int32_t> storage) {
179+
return DenseI32ArrayAttr::get(ctx, storage);
180+
}

mlir/test/IR/properties.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// # RUN: mlir-opt %s -mlir-print-op-generic -split-input-file | mlir-opt -mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC
33

44
// CHECK: test.with_properties
5-
// CHECK-SAME: a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]{{$}}
5+
// CHECK-SAME: a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]{{$}}
66
// GENERIC: "test.with_properties"()
7-
// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo", c = "bar", flag = true}> : () -> ()
8-
test.with_properties a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]
7+
// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, array32 = array<i32: 5, 6>, b = "foo", c = "bar", flag = true}> : () -> ()
8+
test.with_properties a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]
99

1010
// CHECK: test.with_nice_properties
1111
// CHECK-SAME: "foo bar" is -3{{$}}

mlir/test/Transforms/test-legalizer.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func.func @test_properties_rollback() {
442442
// CHECK: test.with_properties a = 32,
443443
// expected-remark @below{{op 'test.with_properties' is not legalizable}}
444444
test.with_properties
445-
a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4]
445+
a = 32, b = "foo", c = "bar", flag = true, array = [1, 2, 3, 4], array32 = [5, 6]
446446
{modify_inplace}
447447
"test.return"() : () -> ()
448448
}

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,13 +3179,15 @@ def TestOpWithProperties : TEST_Op<"with_properties"> {
31793179
`b` `=` $b `,`
31803180
`c` `=` $c `,`
31813181
`flag` `=` $flag `,`
3182-
`array` `=` $array attr-dict}];
3182+
`array` `=` $array `,`
3183+
`array32` `=` $array32 attr-dict}];
31833184
let arguments = (ins
31843185
I64Prop:$a,
31853186
StrAttr:$b, // Attributes can directly be used here.
31863187
StringProp:$c,
31873188
BoolProp:$flag,
3188-
IntArrayProp<I64Prop>:$array // example of an array
3189+
IntArrayProp<I64Prop>:$array, // Example of an array.
3190+
IntArrayProp<I32Prop>:$array32 // Example of an array.
31893191
);
31903192
}
31913193

0 commit comments

Comments
 (0)