diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/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 { diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -4253,6 +4253,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 &result,