[Mlir-commits] [mlir] ac74c51 - [mlir] Add `parseEllipsis`

Jeff Niu llvmlistbot at llvm.org
Thu Sep 22 19:36:23 PDT 2022


Author: Jeff Niu
Date: 2022-09-22T19:36:15-07:00
New Revision: ac74c51c35a4ed6f50170c5fc4ec051780623829

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

LOG: [mlir] Add `parseEllipsis`

To `AsmParser` and also to the assembly format

Reviewed By: rriddle

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpImplementation.h
    mlir/lib/AsmParser/AsmParserImpl.h
    mlir/test/lib/Dialect/Test/TestOps.td
    mlir/test/mlir-tblgen/op-format.mlir
    mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
    mlir/tools/mlir-tblgen/FormatGen.cpp
    mlir/tools/mlir-tblgen/OpFormatGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index 541b3c9caab0d..42d12efc0491a 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -593,6 +593,9 @@ class AsmParser {
   /// Parse a `]` token if present.
   virtual ParseResult parseOptionalRSquare() = 0;
 
+  /// Parse a `...` token.
+  virtual ParseResult parseEllipsis() = 0;
+
   /// Parse a `...` token if present;
   virtual ParseResult parseOptionalEllipsis() = 0;
 

diff  --git a/mlir/lib/AsmParser/AsmParserImpl.h b/mlir/lib/AsmParser/AsmParserImpl.h
index 5bc6c79faf94e..bb0fe5c56df0d 100644
--- a/mlir/lib/AsmParser/AsmParserImpl.h
+++ b/mlir/lib/AsmParser/AsmParserImpl.h
@@ -114,6 +114,11 @@ class AsmParserImpl : public BaseT {
     return success(parser.consumeIf(Token::comma));
   }
 
+  /// Parses a `...`.
+  ParseResult parseEllipsis() override {
+    return parser.parseToken(Token::ellipsis, "expected '...'");
+  }
+
   /// Parses a `...` if present.
   ParseResult parseOptionalEllipsis() override {
     return success(parser.consumeIf(Token::ellipsis));

diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 86ae51e3461d6..4df9caa347ed9 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -797,6 +797,13 @@ def OIListAllowedLiteral : TEST_Op<"oilist_allowed_literal"> {
   }];
 }
 
+def TestEllipsisOp : TEST_Op<"ellipsis"> {
+  let arguments = (ins Variadic<AnyType>:$operands, UnitAttr:$variadic);
+  let assemblyFormat = [{
+    `(` $operands (`...` $variadic^)? `)` attr-dict `:` type($operands) `...`
+  }];
+}
+
 def ElseAnchorOp : TEST_Op<"else_anchor"> {
   let arguments = (ins Optional<AnyType>:$a);
   let assemblyFormat = "`(` (`?`) : (`` $a^ `:` type($a))? `)` attr-dict";

diff  --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir
index 68ed88c136c96..fb390d14bc960 100644
--- a/mlir/test/mlir-tblgen/op-format.mlir
+++ b/mlir/test/mlir-tblgen/op-format.mlir
@@ -392,6 +392,12 @@ func.func @foo() {
 // CHECK: test.format_literal_following_optional_group(5 : i32) : i32 {a}
 test.format_literal_following_optional_group(5 : i32) : i32 {a}
 
+func.func @variadic(%a: i32) {
+  // CHECK: test.ellipsis(%{{.*}} ...) : i32 ...
+  test.ellipsis(%a ...) : i32 ...
+  return
+}
+
 //===----------------------------------------------------------------------===//
 // Format trait type inference
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
index c8b75b012f33a..72fa3cbfc6a08 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
@@ -392,6 +392,7 @@ void DefFormat::genLiteralParser(StringRef value, FmtContext &ctx,
               .Case("?", "Question")
               .Case("+", "Plus")
               .Case("*", "Star")
+              .Case("...", "Ellipsis")
        << "()";
   }
   if (isOptional) {

diff  --git a/mlir/tools/mlir-tblgen/FormatGen.cpp b/mlir/tools/mlir-tblgen/FormatGen.cpp
index 5948415dc4876..a756587803889 100644
--- a/mlir/tools/mlir-tblgen/FormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/FormatGen.cpp
@@ -483,6 +483,8 @@ bool mlir::tblgen::isValidLiteral(StringRef value,
   // Check the punctuation that are larger than a single character.
   if (value == "->")
     return true;
+  if (value == "...")
+    return true;
 
   // Otherwise, this must be an identifier.
   return canFormatStringAsKeyword(value, emitError);

diff  --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 90b69c1925af2..262125e65e5b2 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -760,7 +760,8 @@ static void genLiteralParser(StringRef value, MethodBody &body) {
               .Case("]", "RSquare()")
               .Case("?", "Question()")
               .Case("+", "Plus()")
-              .Case("*", "Star()");
+              .Case("*", "Star()")
+              .Case("...", "Ellipsis()");
 }
 
 /// Generate the storage code required for parsing the given element.


        


More information about the Mlir-commits mailing list