[flang-commits] [flang] 5dedf91 - [AsmParser] Rework logic around "region argument parsing"
Chris Lattner via flang-commits
flang-commits at lists.llvm.org
Thu Apr 28 11:20:46 PDT 2022
Author: Chris Lattner
Date: 2022-04-28T11:12:44-07:00
New Revision: 5dedf911deb409f6293c71ef6ef524359740f1f0
URL: https://github.com/llvm/llvm-project/commit/5dedf911deb409f6293c71ef6ef524359740f1f0
DIFF: https://github.com/llvm/llvm-project/commit/5dedf911deb409f6293c71ef6ef524359740f1f0.diff
LOG: [AsmParser] Rework logic around "region argument parsing"
The asm parser had a notional distinction between parsing an
operand (like "%foo" or "%4#3") and parsing a region argument
(which isn't supposed to allow a result number like #3).
Unfortunately the implementation has two problems:
1) It didn't actually check for the result number and reject
it. parseRegionArgument and parseOperand were identical.
2) It had a lot of machinery built up around it that paralleled
operand parsing. This also was functionally identical, but
also had some subtle differences (e.g. the parseOptional
stuff had a different result type).
I thought about just removing all of this, but decided that the
missing error checking was important, so I reimplemented it with
a `allowResultNumber` flag on parseOperand. This keeps the
codepaths unified and adds the missing error checks.
Differential Revision: https://reviews.llvm.org/D124470
Added:
Modified:
flang/lib/Optimizer/Dialect/FIROps.cpp
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
mlir/lib/Dialect/SCF/SCF.cpp
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
mlir/lib/IR/FunctionImplementation.cpp
mlir/lib/Parser/Parser.cpp
mlir/test/Dialect/Affine/invalid.mlir
mlir/test/lib/Dialect/Test/TestDialect.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index e88a5f6c9dd6f..29cbbcfb9d288 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1563,7 +1563,8 @@ mlir::ParseResult fir::IterWhileOp::parse(mlir::OpAsmParser &parser,
mlir::OperationState &result) {
auto &builder = parser.getBuilder();
mlir::OpAsmParser::UnresolvedOperand inductionVariable, lb, ub, step;
- if (parser.parseLParen() || parser.parseRegionArgument(inductionVariable) ||
+ if (parser.parseLParen() ||
+ parser.parseOperand(inductionVariable, /*allowResultNumber=*/false) ||
parser.parseEqual())
return mlir::failure();
@@ -1581,8 +1582,9 @@ mlir::ParseResult fir::IterWhileOp::parse(mlir::OpAsmParser &parser,
mlir::OpAsmParser::UnresolvedOperand iterateVar, iterateInput;
if (parser.parseKeyword("and") || parser.parseLParen() ||
- parser.parseRegionArgument(iterateVar) || parser.parseEqual() ||
- parser.parseOperand(iterateInput) || parser.parseRParen() ||
+ parser.parseOperand(iterateVar, /*allowResultNumber=*/false) ||
+ parser.parseEqual() || parser.parseOperand(iterateInput) ||
+ parser.parseRParen() ||
parser.resolveOperand(iterateInput, i1Type, result.operands))
return mlir::failure();
@@ -1876,7 +1878,8 @@ mlir::ParseResult fir::DoLoopOp::parse(mlir::OpAsmParser &parser,
auto &builder = parser.getBuilder();
mlir::OpAsmParser::UnresolvedOperand inductionVariable, lb, ub, step;
// Parse the induction variable followed by '='.
- if (parser.parseRegionArgument(inductionVariable) || parser.parseEqual())
+ if (parser.parseOperand(inductionVariable, /*allowResultNumber=*/false) ||
+ parser.parseEqual())
return mlir::failure();
// Parse loop bounds.
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index 8bdab5739f30b..e7123228e835d 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -584,7 +584,7 @@ class AsmParser {
}
/// These are the supported delimiters around operand lists and region
- /// argument lists, used by parseOperandList and parseRegionArgumentList.
+ /// argument lists, used by parseOperandList.
enum class Delimiter {
/// Zero or more operands with no delimiters.
None,
@@ -1110,22 +1110,27 @@ class OpAsmParser : public AsmParser {
Optional<ArrayRef<NamedAttribute>> parsedAttributes = llvm::None,
Optional<FunctionType> parsedFnType = llvm::None) = 0;
- /// Parse a single operand.
- virtual ParseResult parseOperand(UnresolvedOperand &result) = 0;
+ /// Parse a single SSA value operand name along with a result number if
+ /// `allowResultNumber` is true.
+ virtual ParseResult parseOperand(UnresolvedOperand &result,
+ bool allowResultNumber = true) = 0;
/// Parse a single operand if present.
virtual OptionalParseResult
- parseOptionalOperand(UnresolvedOperand &result) = 0;
+ parseOptionalOperand(UnresolvedOperand &result,
+ bool allowResultNumber = true) = 0;
/// Parse zero or more SSA comma-separated operand references with a specified
/// surrounding delimiter, and an optional required operand count.
- virtual ParseResult
- parseOperandList(SmallVectorImpl<UnresolvedOperand> &result,
- int requiredOperandCount = -1,
- Delimiter delimiter = Delimiter::None) = 0;
+ virtual ParseResult parseOperandList(
+ SmallVectorImpl<UnresolvedOperand> &result, int requiredOperandCount = -1,
+ Delimiter delimiter = Delimiter::None, bool allowResultNumber = true) = 0;
+
ParseResult parseOperandList(SmallVectorImpl<UnresolvedOperand> &result,
- Delimiter delimiter) {
- return parseOperandList(result, /*requiredOperandCount=*/-1, delimiter);
+ Delimiter delimiter,
+ bool allowResultNumber = true) {
+ return parseOperandList(result, /*requiredOperandCount=*/-1, delimiter,
+ allowResultNumber);
}
/// Parse zero or more trailing SSA comma-separated trailing operand
@@ -1243,29 +1248,6 @@ class OpAsmParser : public AsmParser {
ArrayRef<Type> argTypes = {},
bool enableNameShadowing = false) = 0;
- /// Parse a region argument, this argument is resolved when calling
- /// 'parseRegion'.
- virtual ParseResult parseRegionArgument(UnresolvedOperand &argument) = 0;
-
- /// Parse zero or more region arguments with a specified surrounding
- /// delimiter, and an optional required argument count. Region arguments
- /// define new values; so this also checks if values with the same names have
- /// not been defined yet.
- virtual ParseResult
- parseRegionArgumentList(SmallVectorImpl<UnresolvedOperand> &result,
- int requiredOperandCount = -1,
- Delimiter delimiter = Delimiter::None) = 0;
- virtual ParseResult
- parseRegionArgumentList(SmallVectorImpl<UnresolvedOperand> &result,
- Delimiter delimiter) {
- return parseRegionArgumentList(result, /*requiredOperandCount=*/-1,
- delimiter);
- }
-
- /// Parse a region argument if present.
- virtual ParseResult
- parseOptionalRegionArgument(UnresolvedOperand &argument) = 0;
-
//===--------------------------------------------------------------------===//
// Successor Parsing
//===--------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index d6534900a2546..b37e4f2d47ce9 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1433,7 +1433,8 @@ ParseResult AffineForOp::parse(OpAsmParser &parser, OperationState &result) {
auto &builder = parser.getBuilder();
OpAsmParser::UnresolvedOperand inductionVariable;
// Parse the induction variable followed by '='.
- if (parser.parseRegionArgument(inductionVariable) || parser.parseEqual())
+ if (parser.parseOperand(inductionVariable, /*allowResultNumber=*/false) ||
+ parser.parseEqual())
return failure();
// Parse loop bounds.
@@ -3527,8 +3528,8 @@ ParseResult AffineParallelOp::parse(OpAsmParser &parser,
auto &builder = parser.getBuilder();
auto indexType = builder.getIndexType();
SmallVector<OpAsmParser::UnresolvedOperand, 4> ivs;
- if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
- OpAsmParser::Delimiter::Paren) ||
+ if (parser.parseOperandList(ivs, OpAsmParser::Delimiter::Paren,
+ /*allowResultNumber=*/false) ||
parser.parseEqual() ||
parseAffineMapWithMinMax(parser, result, MinMaxKind::Max) ||
parser.parseKeyword("to") ||
diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
index 9085ce7e86e89..9030013b05683 100644
--- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
@@ -489,7 +489,8 @@ static ParseResult parseSwitchOpCases(
parser.parseSuccessor(defaultDestination))
return failure();
if (succeeded(parser.parseOptionalLParen())) {
- if (parser.parseRegionArgumentList(defaultOperands) ||
+ if (parser.parseOperandList(defaultOperands, OpAsmParser::Delimiter::None,
+ /*allowResultNumber=*/false) ||
parser.parseColonTypeList(defaultOperandTypes) || parser.parseRParen())
return failure();
}
@@ -509,7 +510,8 @@ static ParseResult parseSwitchOpCases(
failed(parser.parseSuccessor(destination)))
return failure();
if (succeeded(parser.parseOptionalLParen())) {
- if (failed(parser.parseRegionArgumentList(operands)) ||
+ if (failed(parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
+ /*allowResultNumber=*/false)) ||
failed(parser.parseColonTypeList(operandTypes)) ||
failed(parser.parseRParen()))
return failure();
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 255ae0e05bc76..4cd5b1f5a0d60 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -539,8 +539,8 @@ parseSizeAssignment(OpAsmParser &parser,
MutableArrayRef<OpAsmParser::UnresolvedOperand> indices) {
assert(indices.size() == 3 && "space for three indices expected");
SmallVector<OpAsmParser::UnresolvedOperand, 3> args;
- if (parser.parseRegionArgumentList(args, /*requiredOperandCount=*/3,
- OpAsmParser::Delimiter::Paren) ||
+ if (parser.parseOperandList(args, OpAsmParser::Delimiter::Paren,
+ /*allowResultNumber=*/false) ||
parser.parseKeyword("in") || parser.parseLParen())
return failure();
std::move(args.begin(), args.end(), indices.begin());
@@ -548,8 +548,8 @@ parseSizeAssignment(OpAsmParser &parser,
for (int i = 0; i < 3; ++i) {
if (i != 0 && parser.parseComma())
return failure();
- if (parser.parseRegionArgument(regionSizes[i]) || parser.parseEqual() ||
- parser.parseOperand(sizes[i]))
+ if (parser.parseOperand(regionSizes[i], /*allowResultNumber=*/false) ||
+ parser.parseEqual() || parser.parseOperand(sizes[i]))
return failure();
}
@@ -869,7 +869,8 @@ parseAttributions(OpAsmParser &parser, StringRef keyword,
OpAsmParser::UnresolvedOperand arg;
Type type;
- if (parser.parseRegionArgument(arg) || parser.parseColonType(type))
+ if (parser.parseOperand(arg, /*allowResultNumber=*/false) ||
+ parser.parseColonType(type))
return failure();
args.push_back(arg);
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 5d2fe276e1b61..c8188cac5a628 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -332,7 +332,8 @@ static ParseResult parseSwitchOpCases(
if (parser.parseColon() || parser.parseSuccessor(destination))
return failure();
if (!parser.parseOptionalLParen()) {
- if (parser.parseRegionArgumentList(operands) ||
+ if (parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
+ /*allowResultNumber=*/false) ||
parser.parseColonTypeList(operandTypes) || parser.parseRParen())
return failure();
}
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index e4c881a8376a9..2a25cefceea69 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -70,7 +70,8 @@ parseOperandList(OpAsmParser &parser, StringRef keyword,
OpAsmParser::UnresolvedOperand arg;
Type type;
- if (parser.parseRegionArgument(arg) || parser.parseColonType(type))
+ if (parser.parseOperand(arg, /*allowResultNumber=*/false) ||
+ parser.parseColonType(type))
return failure();
args.push_back(arg);
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 7ba9af22c6e50..64aecf81e3eb7 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -524,8 +524,8 @@ parseWsLoopControl(OpAsmParser &parser, Region ®ion,
SmallVectorImpl<Type> &loopVarTypes, UnitAttr &inclusive) {
// Parse an opening `(` followed by induction variables followed by `)`
SmallVector<OpAsmParser::UnresolvedOperand> ivs;
- if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
- OpAsmParser::Delimiter::Paren))
+ if (parser.parseOperandList(ivs, OpAsmParser::Delimiter::Paren,
+ /*allowResultNumber=*/false))
return failure();
size_t numIVs = ivs.size();
@@ -587,8 +587,8 @@ void printWsLoopControl(OpAsmPrinter &p, Operation *op, Region ®ion,
ParseResult SimdLoopOp::parse(OpAsmParser &parser, OperationState &result) {
// Parse an opening `(` followed by induction variables followed by `)`
SmallVector<OpAsmParser::UnresolvedOperand> ivs;
- if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
- OpAsmParser::Delimiter::Paren))
+ if (parser.parseOperandList(ivs, OpAsmParser::Delimiter::Paren,
+ /*allowResultNumber=*/false))
return failure();
int numIVs = static_cast<int>(ivs.size());
Type loopVarType;
diff --git a/mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp b/mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
index a5415e59dbb63..185b91eae935e 100644
--- a/mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
+++ b/mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
@@ -103,7 +103,7 @@ ParseResult ForEachOp::parse(OpAsmParser &parser, OperationState &result) {
// Parse the loop variable followed by type.
OpAsmParser::UnresolvedOperand loopVariable;
Type loopVariableType;
- if (parser.parseRegionArgument(loopVariable) ||
+ if (parser.parseOperand(loopVariable, /*allowResultNumber=*/false) ||
parser.parseColonType(loopVariableType))
return failure();
diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp
index dfeef70af7073..16de538b36af8 100644
--- a/mlir/lib/Dialect/SCF/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/SCF.cpp
@@ -401,7 +401,8 @@ ParseResult ForOp::parse(OpAsmParser &parser, OperationState &result) {
auto &builder = parser.getBuilder();
OpAsmParser::UnresolvedOperand inductionVariable, lb, ub, step;
// Parse the induction variable followed by '='.
- if (parser.parseRegionArgument(inductionVariable) || parser.parseEqual())
+ if (parser.parseOperand(inductionVariable, /*allowResultNumber=*/false) ||
+ parser.parseEqual())
return failure();
// Parse loop bounds.
@@ -1975,8 +1976,8 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) {
auto &builder = parser.getBuilder();
// Parse an opening `(` followed by induction variables followed by `)`
SmallVector<OpAsmParser::UnresolvedOperand, 4> ivs;
- if (parser.parseRegionArgumentList(ivs, /*requiredOperandCount=*/-1,
- OpAsmParser::Delimiter::Paren))
+ if (parser.parseOperandList(ivs, OpAsmParser::Delimiter::Paren,
+ /*allowResultNumber=*/false))
return failure();
// Parse loop bounds.
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 3d24b7c655cd3..d101cdfad5b01 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -4698,7 +4698,8 @@ ParseResult WarpExecuteOnLane0Op::parse(OpAsmParser &parser,
OpAsmParser::UnresolvedOperand laneId;
// Parse predicate operand.
- if (parser.parseLParen() || parser.parseRegionArgument(laneId) ||
+ if (parser.parseLParen() ||
+ parser.parseOperand(laneId, /*allowResultNumber=*/false) ||
parser.parseRParen())
return failure();
diff --git a/mlir/lib/IR/FunctionImplementation.cpp b/mlir/lib/IR/FunctionImplementation.cpp
index e33150d7fe4a5..45751daf811a1 100644
--- a/mlir/lib/IR/FunctionImplementation.cpp
+++ b/mlir/lib/IR/FunctionImplementation.cpp
@@ -30,8 +30,12 @@ ParseResult mlir::function_interface_impl::parseFunctionArgumentList(
// Parse argument name if present.
OpAsmParser::UnresolvedOperand argument;
Type argumentType;
- if (succeeded(parser.parseOptionalRegionArgument(argument)) &&
- !argument.name.empty()) {
+ auto hadSSAValue = parser.parseOptionalOperand(argument,
+ /*allowResultNumber=*/false);
+ if (hadSSAValue.hasValue()) {
+ if (failed(hadSSAValue.getValue()))
+ return failure(); // Argument was present but malformed.
+
// Reject this if the preceding argument was missing a name.
if (argNames.empty() && !argTypes.empty())
return parser.emitError(loc, "expected type instead of SSA identifier");
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 9aa6976721403..c3a9056af403a 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -268,8 +268,10 @@ class OperationParser : public Parser {
ParseResult
parseOptionalSSAUseList(SmallVectorImpl<UnresolvedOperand> &results);
- /// Parse a single SSA use into 'result'.
- ParseResult parseSSAUse(UnresolvedOperand &result);
+ /// Parse a single SSA use into 'result'. If 'allowResultNumber' is true then
+ /// we allow #42 syntax.
+ ParseResult parseSSAUse(UnresolvedOperand &result,
+ bool allowResultNumber = true);
/// Given a reference to an SSA value and its type, return a reference. This
/// returns null on failure.
@@ -699,7 +701,8 @@ ParseResult OperationParser::parseOptionalSSAUseList(
///
/// ssa-use ::= ssa-id
///
-ParseResult OperationParser::parseSSAUse(UnresolvedOperand &result) {
+ParseResult OperationParser::parseSSAUse(UnresolvedOperand &result,
+ bool allowResultNumber) {
result.name = getTokenSpelling();
result.number = 0;
result.location = getToken().getLoc();
@@ -708,6 +711,9 @@ ParseResult OperationParser::parseSSAUse(UnresolvedOperand &result) {
// If we have an attribute ID, it is a result number.
if (getToken().is(Token::hash_identifier)) {
+ if (!allowResultNumber)
+ return emitError("result number not allowed in argument list");
+
if (auto value = getToken().getHashIdentifierNumber())
result.number = value.getValue();
else
@@ -1267,9 +1273,10 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
//===--------------------------------------------------------------------===//
/// Parse a single operand.
- ParseResult parseOperand(UnresolvedOperand &result) override {
+ ParseResult parseOperand(UnresolvedOperand &result,
+ bool allowResultNumber = true) override {
OperationParser::UnresolvedOperand useInfo;
- if (parser.parseSSAUse(useInfo))
+ if (parser.parseSSAUse(useInfo, allowResultNumber))
return failure();
result = {useInfo.location, useInfo.name, useInfo.number, {}};
@@ -1279,9 +1286,11 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
}
/// Parse a single operand if present.
- OptionalParseResult parseOptionalOperand(UnresolvedOperand &result) override {
+ OptionalParseResult
+ parseOptionalOperand(UnresolvedOperand &result,
+ bool allowResultNumber = true) override {
if (parser.getToken().is(Token::percent_identifier))
- return parseOperand(result);
+ return parseOperand(result, allowResultNumber);
return llvm::None;
}
@@ -1289,17 +1298,8 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
/// surrounding delimiter, and an optional required operand count.
ParseResult parseOperandList(SmallVectorImpl<UnresolvedOperand> &result,
int requiredOperandCount = -1,
- Delimiter delimiter = Delimiter::None) override {
- return parseOperandOrRegionArgList(result, /*isOperandList=*/true,
- requiredOperandCount, delimiter);
- }
-
- /// Parse zero or more SSA comma-separated operand or region arguments with
- /// optional surrounding delimiter and required operand count.
- ParseResult
- parseOperandOrRegionArgList(SmallVectorImpl<UnresolvedOperand> &result,
- bool isOperandList, int requiredOperandCount = -1,
- Delimiter delimiter = Delimiter::None) {
+ Delimiter delimiter = Delimiter::None,
+ bool allowResultNumber = true) override {
auto startLoc = parser.getToken().getLoc();
// The no-delimiter case has some special handling for better diagnostics.
@@ -1322,8 +1322,7 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
auto parseOneOperand = [&]() -> ParseResult {
UnresolvedOperand operandOrArg;
- if (isOperandList ? parseOperand(operandOrArg)
- : parseRegionArgument(operandOrArg))
+ if (parseOperand(operandOrArg, allowResultNumber))
return failure();
result.push_back(operandOrArg);
return success();
@@ -1472,28 +1471,6 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
return success();
}
- /// Parse a region argument. The type of the argument will be resolved later
- /// by a call to `parseRegion`.
- ParseResult parseRegionArgument(UnresolvedOperand &argument) override {
- return parseOperand(argument);
- }
-
- /// Parse a region argument if present.
- ParseResult
- parseOptionalRegionArgument(UnresolvedOperand &argument) override {
- if (parser.getToken().isNot(Token::percent_identifier))
- return success();
- return parseRegionArgument(argument);
- }
-
- ParseResult
- parseRegionArgumentList(SmallVectorImpl<UnresolvedOperand> &result,
- int requiredOperandCount = -1,
- Delimiter delimiter = Delimiter::None) override {
- return parseOperandOrRegionArgList(result, /*isOperandList=*/false,
- requiredOperandCount, delimiter);
- }
-
//===--------------------------------------------------------------------===//
// Successor Parsing
//===--------------------------------------------------------------------===//
@@ -1539,8 +1516,8 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
auto parseElt = [&]() -> ParseResult {
UnresolvedOperand regionArg, operand;
- if (parseRegionArgument(regionArg) || parseEqual() ||
- parseOperand(operand))
+ if (parseOperand(regionArg, /*allowResultNumber=*/false) ||
+ parseEqual() || parseOperand(operand))
return failure();
lhs.push_back(regionArg);
rhs.push_back(operand);
@@ -1561,8 +1538,9 @@ class CustomOpAsmParser : public AsmParserImpl<OpAsmParser> {
auto parseElt = [&]() -> ParseResult {
UnresolvedOperand regionArg, operand;
Type type;
- if (parseRegionArgument(regionArg) || parseEqual() ||
- parseOperand(operand) || parseColon() || parseType(type))
+ if (parseOperand(regionArg, /*allowResultNumber=*/false) ||
+ parseEqual() || parseOperand(operand) || parseColon() ||
+ parseType(type))
return failure();
lhs.push_back(regionArg);
rhs.push_back(operand);
diff --git a/mlir/test/Dialect/Affine/invalid.mlir b/mlir/test/Dialect/Affine/invalid.mlir
index 80c2fd7206f4b..79cdeb9588fc9 100644
--- a/mlir/test/Dialect/Affine/invalid.mlir
+++ b/mlir/test/Dialect/Affine/invalid.mlir
@@ -380,3 +380,13 @@ func.func @affine_for_iter_args_mismatch(%buffer: memref<1024xf32>) -> f32 {
}
return %res : f32
}
+
+
+// -----
+
+func.func @result_number() {
+ // expected-error at +1 {{result number not allowed}}
+ affine.for %n0#0 = 0 to 7 {
+ }
+ return
+}
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp
index 0f8cfd8a167fa..0978e27634f7c 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.cpp
+++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp
@@ -932,7 +932,8 @@ void PrettyPrintedRegionOp::print(OpAsmPrinter &p) {
ParseResult PolyForOp::parse(OpAsmParser &parser, OperationState &result) {
SmallVector<OpAsmParser::UnresolvedOperand, 4> ivsInfo;
// Parse list of region arguments without a delimiter.
- if (parser.parseRegionArgumentList(ivsInfo))
+ if (parser.parseOperandList(ivsInfo, OpAsmParser::Delimiter::None,
+ /*allowResultNumber=*/false))
return failure();
// Parse the body region.
More information about the flang-commits
mailing list