Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flow][Stream][NFC] Use parser.parseArgument() for custom parsers. #20333

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions compiler/src/iree/compiler/Dialect/Flow/IR/FlowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ namespace mlir::iree_compiler::IREE::Flow {
// Op utilities used within the Flow dialect
//===----------------------------------------------------------------------===//

// TODO(hanchung): Have a better fix. This is a fix for
// https://reviews.llvm.org/D124649
static void createArgs(ArrayRef<OpAsmParser::UnresolvedOperand> operands,
ArrayRef<Type> types,
SmallVector<OpAsmParser::Argument> &args) {
for (auto [operand, type] : llvm::zip_equal(operands, types)) {
auto &arg = args.emplace_back();
arg.ssaName = operand;
arg.type = type;
}
}

// Verifies that a dispatch |op|'s |workload| matches that of the |exportOp|.
static LogicalResult
verifyDispatchWorkload(Operation *op, IREE::Flow::ExecutableExportOp exportOp,
Expand Down Expand Up @@ -1032,28 +1020,23 @@ static ParseResult parseDispatchWorkgroupBody(OpAsmParser &parser,
TypeRange operandTypes,
TypeRange resultTypes,
Region &body) {
SmallVector<OpAsmParser::UnresolvedOperand> regionArgs;
SmallVector<Type> regionArgTypes;
SmallVector<OpAsmParser::Argument> args;
if (failed(parser.parseLParen())) {
return failure();
}
if (failed(parser.parseOptionalRParen())) {
do {
// Reserve entries in the lists.
regionArgs.emplace_back();
regionArgTypes.emplace_back();
if (failed(parser.parseOperand(regionArgs.back(),
/*allowResultNumber=*/false)) ||
failed(parser.parseColonType(regionArgTypes.back()))) {
args.emplace_back();
if (failed(parser.parseArgument(args.back(),
/*allowType=*/true))) {
return failure();
}
} while (succeeded(parser.parseOptionalComma()));
if (failed(parser.parseRParen())) {
return failure();
}
}
SmallVector<OpAsmParser::Argument> args;
createArgs(regionArgs, regionArgTypes, args);
return parser.parseRegion(body, args, /*enableNameShadowing=*/true);
}

Expand Down
36 changes: 12 additions & 24 deletions compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ namespace mlir::iree_compiler::IREE::Stream {
// Op utilities used within the stream dialect
//===----------------------------------------------------------------------===//

// TODO(hanchung): Have a better fix. This is a fix for
// https://reviews.llvm.org/D124649
static void createArgs(ArrayRef<OpAsmParser::UnresolvedOperand> operands,
ArrayRef<Type> types,
SmallVector<OpAsmParser::Argument> &args) {
for (auto [operand, type] : llvm::zip_equal(operands, types)) {
auto &arg = args.emplace_back();
arg.ssaName = operand;
arg.type = type;
}
}

// Verifies that a dispatch |op|'s |workload| matches that of the |exportOp|.
static LogicalResult
verifyDispatchWorkload(Operation *op, IREE::Stream::ExecutableExportOp exportOp,
Expand Down Expand Up @@ -1078,7 +1066,7 @@ static ParseResult parseResourceRegion(
SmallVectorImpl<Type> &resultTypes,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &resultSizes,
ArrayAttr &tiedOperands, Region &body) {
SmallVector<OpAsmParser::UnresolvedOperand, 16> regionArgs;
SmallVector<OpAsmParser::Argument, 16> regionArgs;
if (failed(parser.parseLParen())) {
return failure();
}
Expand All @@ -1091,8 +1079,7 @@ static ParseResult parseResourceRegion(
regionArgs.emplace_back();
if (failed(parser.parseOperand(operands.back())) ||
failed(parser.parseKeyword("as")) ||
failed(parser.parseOperand(regionArgs.back(),
/*allowResultNumber=*/false)) ||
failed(parser.parseArgument(regionArgs.back())) ||
failed(parser.parseColon()) ||
failed(parseSizeAwareType(parser, operandTypes.back(),
operandSizes.back()))) {
Expand Down Expand Up @@ -1123,9 +1110,10 @@ static ParseResult parseResourceRegion(
}
}

SmallVector<OpAsmParser::Argument> args;
createArgs(regionArgs, operandTypes, args);
return parser.parseRegion(body, args);
for (auto [iterArg, type] : llvm::zip_equal(regionArgs, operandTypes)) {
iterArg.type = type;
}
return parser.parseRegion(body, regionArgs);
}

static void printResourceRegion(OpAsmPrinter &p, Operation *op,
Expand Down Expand Up @@ -1174,7 +1162,7 @@ static ParseResult parseExplicitResourceRegion(
SmallVectorImpl<Type> &operandTypes,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operandSizes,
Region &body) {
SmallVector<OpAsmParser::UnresolvedOperand, 16> regionArgs;
SmallVector<OpAsmParser::Argument, 16> regionArgs;
if (failed(parser.parseLParen())) {
return failure();
}
Expand All @@ -1187,8 +1175,7 @@ static ParseResult parseExplicitResourceRegion(
regionArgs.emplace_back();
if (failed(parser.parseOperand(operands.back())) ||
failed(parser.parseKeyword("as")) ||
failed(parser.parseOperand(regionArgs.back(),
/*allowResultNumber=*/false)) ||
failed(parser.parseArgument(regionArgs.back())) ||
failed(parser.parseColon()) ||
failed(parseSizeAwareType(parser, operandTypes.back(),
operandSizes.back()))) {
Expand All @@ -1199,9 +1186,10 @@ static ParseResult parseExplicitResourceRegion(
return failure();
}
}
SmallVector<OpAsmParser::Argument> args;
createArgs(regionArgs, operandTypes, args);
if (failed(parser.parseRegion(body, args))) {
for (auto [iterArg, type] : llvm::zip_equal(regionArgs, operandTypes)) {
iterArg.type = type;
}
if (failed(parser.parseRegion(body, regionArgs))) {
return failure();
}
// HACK: I can't figure out how to make this work with the default parsing -
Expand Down
Loading