[Mlir-commits] [mlir] a44e630 - [AsmParser] Fix support for zero bit integer types.

Chris Lattner llvmlistbot at llvm.org
Sat Dec 12 21:24:42 PST 2020


Author: Chris Lattner
Date: 2020-12-12T21:24:18-08:00
New Revision: a44e630353b83fea89b7d6e61cba5d34800d86d5

URL: https://github.com/llvm/llvm-project/commit/a44e630353b83fea89b7d6e61cba5d34800d86d5
DIFF: https://github.com/llvm/llvm-project/commit/a44e630353b83fea89b7d6e61cba5d34800d86d5.diff

LOG: [AsmParser] Fix support for zero bit integer types.

Zero bit integer types are supported by IntegerType for consistency,
but the asmparser never got updated. Allow them to be parsed, as
required to fix CIRCT issue #316

Differential Revision: https://reviews.llvm.org/D93089

Added: 
    

Modified: 
    mlir/lib/Parser/Token.cpp
    mlir/test/Dialect/Quant/parse-any-invalid.mlir
    mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
    mlir/test/IR/invalid.mlir
    mlir/test/IR/parser.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Parser/Token.cpp b/mlir/lib/Parser/Token.cpp
index b4ac30f2c388..00bc7dbd6bd9 100644
--- a/mlir/lib/Parser/Token.cpp
+++ b/mlir/lib/Parser/Token.cpp
@@ -60,9 +60,7 @@ Optional<unsigned> Token::getIntTypeBitwidth() const {
   assert(getKind() == inttype);
   unsigned bitwidthStart = (spelling[0] == 'i' ? 1 : 2);
   unsigned result = 0;
-  if (spelling[bitwidthStart] == '0' ||
-      spelling.drop_front(bitwidthStart).getAsInteger(10, result) ||
-      result == 0)
+  if (spelling.drop_front(bitwidthStart).getAsInteger(10, result))
     return None;
   return result;
 }

diff  --git a/mlir/test/Dialect/Quant/parse-any-invalid.mlir b/mlir/test/Dialect/Quant/parse-any-invalid.mlir
index d90423ef4085..850174b4bd98 100644
--- a/mlir/test/Dialect/Quant/parse-any-invalid.mlir
+++ b/mlir/test/Dialect/Quant/parse-any-invalid.mlir
@@ -36,9 +36,9 @@
 !qalias = type !quant.any<i1024<-4:3>:f32>
 
 // -----
-// Unrecognized storage type: storage size == 0
+// Unrecognized storage type: storage size
 // expected-error at +1 {{invalid integer width}}
-!qalias = type !quant.any<i0<-4:3>:f32>
+!qalias = type !quant.any<i0123123123123123<-4:3>:f32>
 
 // -----
 // Illegal storage min/max: max - min < 0

diff  --git a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
index 114ab7dc0d7b..f43496f85e0f 100644
--- a/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
+++ b/mlir/test/Dialect/Quant/parse-uniform-invalid.mlir
@@ -56,9 +56,9 @@
 !qalias = type !quant.uniform<i-1<-4:3>:f32, 0.99872:127>
 
 // -----
-// Unrecognized storage type: storage size == 0
+// Unrecognized storage type: storage size
 // expected-error at +1 {{invalid integer width}}
-!qalias = type !quant.uniform<i0<-4:3>:f32, 0.99872:127>
+!qalias = type !quant.uniform<i123123123120<-4:3>:f32, 0.99872:127>
 
 // -----
 // Illegal storage min/max: max - min < 0

diff  --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 6b28b33e7c78..86245ad25c3b 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -201,7 +201,7 @@ func @no_terminator() {
 
 // -----
 
-func @illegaltype(i0) // expected-error {{invalid integer width}}
+func @illegaltype(i21312312323120) // expected-error {{invalid integer width}}
 
 // -----
 

diff  --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir
index 9098e9ace5fa..8fcb7863726f 100644
--- a/mlir/test/IR/parser.mlir
+++ b/mlir/test/IR/parser.mlir
@@ -58,8 +58,8 @@ func private @baz() -> (i1, index, f32)
 // CHECK: func private @missingReturn()
 func private @missingReturn()
 
-// CHECK: func private @int_types(i1, i2, i4, i7, i87) -> (i1, index, i19)
-func private @int_types(i1, i2, i4, i7, i87) -> (i1, index, i19)
+// CHECK: func private @int_types(i0, i1, i2, i4, i7, i87) -> (i1, index, i19)
+func private @int_types(i0, i1, i2, i4, i7, i87) -> (i1, index, i19)
 
 // CHECK: func private @sint_types(si2, si4) -> (si7, si1023)
 func private @sint_types(si2, si4) -> (si7, si1023)


        


More information about the Mlir-commits mailing list