Skip to content

Commit 318c013

Browse files
quartersdgjpienaar
authored andcommitted
Updating test attribute and test to model list of integers
1 parent b1d49a3 commit 318c013

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ def AttrWithTrait : Test_Attr<"AttrWithTrait", [TestAttrTrait]> {
8181
let mnemonic = "attr_with_trait";
8282
}
8383

84-
// An attribute of decimal formatted integer.
85-
def TestDecimalIntegerAttr : Test_Attr<"TestDecimalInteger"> {
86-
let mnemonic = "decimal_integer";
84+
// An attribute of a list of decimal formatted integers in similar format to shapes.
85+
def TestDecimalShapeAttr : Test_Attr<"TestDecimalShape"> {
86+
let mnemonic = "decimal_shape";
8787

88-
let parameters = (ins "int64_t":$value);
88+
let parameters = (ins ArrayRefParameter<"int64_t">:$shape);
8989

9090
let hasCustomAssemblyFormat = 1;
9191
}

mlir/test/lib/Dialect/Test/TestAttributes.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "TestAttributes.h"
1515
#include "TestDialect.h"
1616
#include "TestTypes.h"
17+
#include "mlir/IR/Attributes.h"
1718
#include "mlir/IR/Builders.h"
1819
#include "mlir/IR/DialectImplementation.h"
1920
#include "mlir/IR/ExtensibleDialect.h"
@@ -66,22 +67,37 @@ void CompoundAAttr::print(AsmPrinter &printer) const {
6667
//===----------------------------------------------------------------------===//
6768

6869

69-
Attribute TestDecimalIntegerAttr::parse(AsmParser &parser, Type type) {
70+
Attribute TestDecimalShapeAttr::parse(AsmParser &parser, Type type) {
7071
if (parser.parseLess()){
7172
return Attribute();
7273
}
73-
uint64_t intVal;
74-
if (failed(*parser.parseOptionalDecimalInteger(intVal))) {
75-
return Attribute();
76-
}
77-
if (parser.parseGreater()) {
78-
return Attribute();
74+
SmallVector<int64_t> shape;
75+
if (parser.parseOptionalGreater()) {
76+
auto parseDecimal = [&]() {
77+
shape.emplace_back();
78+
auto parseResult = parser.parseOptionalDecimalInteger(shape.back());
79+
if (!parseResult.has_value() || failed(*parseResult)) {
80+
parser.emitError(parser.getCurrentLocation()) << "expected an integer";
81+
return failure();
82+
}
83+
return success();
84+
};
85+
if (failed(parseDecimal())) {
86+
return Attribute();
87+
}
88+
while (failed(parser.parseOptionalGreater())) {
89+
if (failed(parser.parseXInDimensionList()) || failed(parseDecimal())) {
90+
return Attribute();
91+
}
92+
}
7993
}
80-
return get(parser.getContext(), intVal);
94+
return get(parser.getContext(), shape);
8195
}
8296

83-
void TestDecimalIntegerAttr::print(AsmPrinter &printer) const {
84-
printer << "<" << getValue() << ">";
97+
void TestDecimalShapeAttr::print(AsmPrinter &printer) const {
98+
printer << "<";
99+
llvm::interleave(getShape(), printer, "x");
100+
printer << ">";
85101
}
86102

87103
Attribute TestI64ElementsAttr::parse(AsmParser &parser, Type type) {

mlir/test/mlir-tblgen/testdialect-attrdefs.mlir

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,27 @@ func.func private @overriddenAttr() attributes {
2020
foo = #test.override_builder<5>
2121
}
2222

23-
// CHECK-LABEL: @decimalInteger
24-
// CHECK-SAME: foo = #test.decimal_integer<5>
25-
func.func private @decimalInteger() attributes {
26-
foo = #test.decimal_integer<5>
23+
// CHECK-LABEL: @decimalIntegerShapeEmpty
24+
// CHECK-SAME: foo = #test.decimal_shape<>
25+
func.func private @decimalIntegerShapeEmpty() attributes {
26+
foo = #test.decimal_shape<>
27+
}
28+
29+
// CHECK-LABEL: @decimalIntegerShape
30+
// CHECK-SAME: foo = #test.decimal_shape<5>
31+
func.func private @decimalIntegerShape() attributes {
32+
foo = #test.decimal_shape<5>
33+
}
34+
35+
// CHECK-LABEL: @decimalIntegerShapeMultiple
36+
// CHECK-SAME: foo = #test.decimal_shape<0x3x7>
37+
func.func private @decimalIntegerShapeMultiple() attributes {
38+
foo = #test.decimal_shape<0x3x7>
2739
}
2840

2941
// -----
3042

3143
func.func private @hexdecimalInteger() attributes {
32-
// expected-error @below {{expected '>'}}
33-
foo = #test.decimal_integer<0x5>
44+
// expected-error @below {{expected an integer}}
45+
sdg = #test.decimal_shape<1x0xb>
3446
}

0 commit comments

Comments
 (0)