[Mlir-commits] [mlir] ec74867 - [mlir] Provide CustomOpAsmParser::parseOptionalOperand
Alex Zinenko
llvmlistbot at llvm.org
Wed Mar 25 13:03:19 PDT 2020
Author: Alex Zinenko
Date: 2020-03-25T21:03:11+01:00
New Revision: ec74867c5e6a8ea38ea848f47ee2025ebb727397
URL: https://github.com/llvm/llvm-project/commit/ec74867c5e6a8ea38ea848f47ee2025ebb727397
DIFF: https://github.com/llvm/llvm-project/commit/ec74867c5e6a8ea38ea848f47ee2025ebb727397.diff
LOG: [mlir] Provide CustomOpAsmParser::parseOptionalOperand
Summary:
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.
Differential Revision: https://reviews.llvm.org/D76779
Added:
Modified:
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/Parser/Parser.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index f471e6ca0cc5..0a2602544112 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -452,6 +452,9 @@ class OpAsmParser {
/// 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 {
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 437803388e99..06eb2cfc8aa9 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -4253,6 +4253,13 @@ class CustomOpAsmParser : public OpAsmParser {
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,
More information about the Mlir-commits
mailing list