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();
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();
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.
}
/// 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,
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
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
//===--------------------------------------------------------------------===//
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.
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") ||
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();
}
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();
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());
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();
}
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);
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();
}
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);
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();
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;
// 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();
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.
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.
OpAsmParser::UnresolvedOperand laneId;
// Parse predicate operand.
- if (parser.parseLParen() || parser.parseRegionArgument(laneId) ||
+ if (parser.parseLParen() ||
+ parser.parseOperand(laneId, /*allowResultNumber=*/false) ||
parser.parseRParen())
return failure();
// 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");
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.
///
/// 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();
// 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
//===--------------------------------------------------------------------===//
/// 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, {}};
}
/// 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;
}
/// 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.
auto parseOneOperand = [&]() -> ParseResult {
UnresolvedOperand operandOrArg;
- if (isOperandList ? parseOperand(operandOrArg)
- : parseRegionArgument(operandOrArg))
+ if (parseOperand(operandOrArg, allowResultNumber))
return failure();
result.push_back(operandOrArg);
return success();
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
//===--------------------------------------------------------------------===//
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);
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);
}
return %res : f32
}
+
+
+// -----
+
+func.func @result_number() {
+ // expected-error@+1 {{result number not allowed}}
+ affine.for %n0#0 = 0 to 7 {
+ }
+ return
+}
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.