Replace checks for rank -1 with direct calls to hasRank
authorGeoffrey Martin-Noble <gcmn@google.com>
Sat, 25 May 2019 00:46:58 +0000 (17:46 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jun 2019 03:01:33 +0000 (20:01 -0700)
    Also removed a redundant check for rank after already checking for static shape (which implies rank)

--

PiperOrigin-RevId: 249927636

mlir/lib/IR/Operation.cpp
mlir/lib/Parser/Parser.cpp
mlir/test/IR/invalid.mlir

index 582fb39..f6fc3ee 100644 (file)
@@ -783,7 +783,7 @@ static LogicalResult verifyShapeMatch(Type type1, Type type2) {
   if (!sType1)
     return success(!sType2);
 
-  if (sType1.getRank() == -1 || sType2.getRank() == -1)
+  if (!sType1.hasRank() || !sType2.hasRank())
     return success();
 
   return success(sType1.getShape() == sType2.getShape());
index 1f37d2e..c2761a2 100644 (file)
@@ -1383,7 +1383,7 @@ DenseElementsAttr Parser::parseDenseElementsAttr(ShapedType type) {
 ///
 ///   shaped-type ::= vector-type | tensor-type
 ///
-/// This method also checks the type has static shape and ranked.
+/// This method also checks the type has static shape.
 ShapedType Parser::parseShapedType() {
   auto elementType = parseType();
   if (!elementType)
@@ -1397,9 +1397,8 @@ ShapedType Parser::parseShapedType() {
   if (parseToken(Token::comma, "expected ','"))
     return nullptr;
 
-  if (!type.hasStaticShape() || type.getRank() == -1) {
-    return (emitError("shaped literal must be ranked and have static shape"),
-            nullptr);
+  if (!type.hasStaticShape()) {
+    return (emitError("shaped literal must have static shape"), nullptr);
   }
   return type;
 }
index 0b69c04..fef4119 100644 (file)
@@ -598,7 +598,7 @@ func @elementsattr_non_tensor_type() -> () {
 
 func @elementsattr_non_ranked() -> () {
 ^bb0:
-  "foo"(){bar: dense<tensor<?xi32>, [4]>} : () -> () // expected-error {{shaped literal must be ranked and have static shape}}
+  "foo"(){bar: dense<tensor<?xi32>, [4]>} : () -> () // expected-error {{shaped literal must have static shape}}
 }
 
 // -----