[PATCH] D76779: [mlir] Provide CustomOpAsmParser::parseOptionalOperand

Alex Zinenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 08:37:26 PDT 2020


ftynse created this revision.
ftynse added reviewers: rriddle, nicolasvasilache.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, burmako, jpienaar, mehdi_amini.
Herald added 1 blocking reviewer(s): rriddle.
Herald added a project: LLVM.

Some operations have custom syntax where an operand is always followed by a
specific token of streams if the operand is present. Parsing such operations
requires the ability to optionally parse an operand. Provide a relevant
function in the custom Op parser.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76779

Files:
  mlir/include/mlir/IR/OpImplementation.h
  mlir/lib/Parser/Parser.cpp


Index: mlir/lib/Parser/Parser.cpp
===================================================================
--- mlir/lib/Parser/Parser.cpp
+++ mlir/lib/Parser/Parser.cpp
@@ -4234,6 +4234,13 @@
     return success();
   }
 
+  /// Parse a single operand if present.
+  OptionalParseResult parseOptionalOperand(OperandType &result) override {
+    if (parser.getToken().is(Token::percent_identifier))
+      return parseOperand(result);
+    return llvm::None;
+  }
+
   /// Parse zero or more SSA comma-separated operand references with a specified
   /// surrounding delimiter, and an optional required operand count.
   ParseResult parseOperandList(SmallVectorImpl<OperandType> &result,
Index: mlir/include/mlir/IR/OpImplementation.h
===================================================================
--- mlir/include/mlir/IR/OpImplementation.h
+++ mlir/include/mlir/IR/OpImplementation.h
@@ -452,6 +452,9 @@
   /// Parse a single operand.
   virtual ParseResult parseOperand(OperandType &result) = 0;
 
+  /// Parse a single operand if present.
+  virtual OptionalParseResult parseOptionalOperand(OperandType &result) = 0;
+
   /// These are the supported delimiters around operand lists and region
   /// argument lists, used by parseOperandList and parseRegionArgumentList.
   enum class Delimiter {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76779.252584.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/e7e31017/attachment.bin>


More information about the llvm-commits mailing list