[Mlir-commits] [mlir] 96da738 - [mlir] Remove colon from empty dense array syntax
Jeff Niu
llvmlistbot at llvm.org
Fri Aug 12 19:36:57 PDT 2022
Author: Jeff Niu
Date: 2022-08-12T22:36:54-04:00
New Revision: 96da738dc516e8a183c3a6ac7091ab2da7ce5732
URL: https://github.com/llvm/llvm-project/commit/96da738dc516e8a183c3a6ac7091ab2da7ce5732
DIFF: https://github.com/llvm/llvm-project/commit/96da738dc516e8a183c3a6ac7091ab2da7ce5732.diff
LOG: [mlir] Remove colon from empty dense array syntax
E.g. `array<i32:>` -> `array<i32>`
Reviewed By: rriddle, jpienaar
Differential Revision: https://reviews.llvm.org/D131823
Added:
Modified:
mlir/include/mlir/IR/BuiltinAttributes.td
mlir/lib/AsmParser/AttributeParser.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/test/IR/attribute.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index 293a7b9197707..467a0437d9493 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinAttributes.td
@@ -176,7 +176,7 @@ def Builtin_DenseArrayBase : Builtin_Attr<
Examples:
```mlir
- array<i8:>
+ array<i8>
array<i32: 10, 42>
array<f64: 42., 12.>
```
diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index 817624980f89b..8e7a83a7d2732 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -838,16 +838,16 @@ class CustomAsmParser : public AsmParserImpl<AsmParser> {
Attribute Parser::parseDenseArrayAttr(Type type) {
consumeToken(Token::kw_array);
SMLoc typeLoc = getToken().getLoc();
- if (parseToken(Token::less, "expected '<' after 'array'"))
- return {};
- if (!type &&
- (!(type = parseType()) ||
- parseToken(Token::colon, "expected ':' after dense array type")))
+ if (parseToken(Token::less, "expected '<' after 'array'") ||
+ (!type && !(type = parseType())))
return {};
CustomAsmParser parser(*this);
Attribute result;
// Check for empty list.
bool isEmptyList = getToken().is(Token::greater);
+ if (!isEmptyList &&
+ parseToken(Token::colon, "expected ':' after dense array type"))
+ return {};
if (auto intType = type.dyn_cast<IntegerType>()) {
switch (type.getIntOrFloatBitWidth()) {
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 4e04e661ca8bd..009ce07025c70 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -1860,9 +1860,9 @@ void AsmPrinter::Impl::printAttribute(Attribute attr,
}
} else if (auto denseArrayAttr = attr.dyn_cast<DenseArrayBaseAttr>()) {
typeElision = AttrTypeElision::Must;
- os << "array<" << denseArrayAttr.getType().getElementType() << ":";
+ os << "array<" << denseArrayAttr.getType().getElementType();
if (denseArrayAttr.size())
- os << " ";
+ os << ": ";
denseArrayAttr.printWithoutBraces(os);
os << ">";
} else if (auto resourceAttr = attr.dyn_cast<DenseResourceElementsAttr>()) {
diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir
index 14c9002076bb9..cf2d5332351e2 100644
--- a/mlir/test/IR/attribute.mlir
+++ b/mlir/test/IR/attribute.mlir
@@ -522,20 +522,20 @@ func.func @simple_scalar_example() {
// CHECK-LABEL: func @dense_array_attr
func.func @dense_array_attr() attributes {
-// CHECK-SAME: emptyf32attr = array<f32:>,
- emptyf32attr = array<f32:>,
-// CHECK-SAME: emptyf64attr = array<f64:>,
- emptyf64attr = array<f64:>,
-// CHECK-SAME: emptyi16attr = array<i16:>,
- emptyi16attr = array<i16:>,
-// CHECK-SAME: emptyi1attr = array<i1:>,
- emptyi1attr = array<i1:>,
-// CHECK-SAME: emptyi32attr = array<i32:>,
- emptyi32attr = array<i32:>,
-// CHECK-SAME: emptyi64attr = array<i64:>,
- emptyi64attr = array<i64:>,
-// CHECK-SAME: emptyi8attr = array<i8:>,
- emptyi8attr = array<i8:>,
+// CHECK-SAME: emptyf32attr = array<f32>,
+ emptyf32attr = array<f32>,
+// CHECK-SAME: emptyf64attr = array<f64>,
+ emptyf64attr = array<f64>,
+// CHECK-SAME: emptyi16attr = array<i16>,
+ emptyi16attr = array<i16>,
+// CHECK-SAME: emptyi1attr = array<i1>,
+ emptyi1attr = array<i1>,
+// CHECK-SAME: emptyi32attr = array<i32>,
+ emptyi32attr = array<i32>,
+// CHECK-SAME: emptyi64attr = array<i64>,
+ emptyi64attr = array<i64>,
+// CHECK-SAME: emptyi8attr = array<i8>,
+ emptyi8attr = array<i8>,
// CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>,
f32attr = array<f32: 1024., 453., -6435.>,
// CHECK-SAME: f64attr = array<f64: -1.420000e+02>,
More information about the Mlir-commits
mailing list