Skip to content

Commit 740f674

Browse files
[mlir][acc] Fix extraneous space when printing acc.loop (#137839)
The acc.loop printer inserted two spaces after the operation. This occurred because the custom combined loop attribute printer was not conditional - and thus the tablegen inserted an automatic space before invoking the custom printer. Then for each additional attribute it also inserted a space in beginning. Since lit tests were not sensitive to this, no tests need updated. But the issue with the extraneous space is resolved.
1 parent e17122f commit 740f674

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
21972197

21982198
let hasCustomAssemblyFormat = 1;
21992199
let assemblyFormat = [{
2200-
custom<CombinedConstructsLoop>($combined)
2200+
( `combined` `(` custom<CombinedConstructsLoop>($combined)^ `)` )?
22012201
oilist(
22022202
`gang` `` custom<GangClause>($gangOperands, type($gangOperands),
22032203
$gangOperandsArgType, $gangOperandsDeviceType,

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,25 +1686,19 @@ static void printDeviceTypeOperandsWithKeywordOnly(
16861686
static ParseResult
16871687
parseCombinedConstructsLoop(mlir::OpAsmParser &parser,
16881688
mlir::acc::CombinedConstructsTypeAttr &attr) {
1689-
if (succeeded(parser.parseOptionalKeyword("combined"))) {
1690-
if (parser.parseLParen())
1691-
return failure();
1692-
if (succeeded(parser.parseOptionalKeyword("kernels"))) {
1693-
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1694-
parser.getContext(), mlir::acc::CombinedConstructsType::KernelsLoop);
1695-
} else if (succeeded(parser.parseOptionalKeyword("parallel"))) {
1696-
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1697-
parser.getContext(), mlir::acc::CombinedConstructsType::ParallelLoop);
1698-
} else if (succeeded(parser.parseOptionalKeyword("serial"))) {
1699-
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1700-
parser.getContext(), mlir::acc::CombinedConstructsType::SerialLoop);
1701-
} else {
1702-
parser.emitError(parser.getCurrentLocation(),
1703-
"expected compute construct name");
1704-
return failure();
1705-
}
1706-
if (parser.parseRParen())
1707-
return failure();
1689+
if (succeeded(parser.parseOptionalKeyword("kernels"))) {
1690+
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1691+
parser.getContext(), mlir::acc::CombinedConstructsType::KernelsLoop);
1692+
} else if (succeeded(parser.parseOptionalKeyword("parallel"))) {
1693+
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1694+
parser.getContext(), mlir::acc::CombinedConstructsType::ParallelLoop);
1695+
} else if (succeeded(parser.parseOptionalKeyword("serial"))) {
1696+
attr = mlir::acc::CombinedConstructsTypeAttr::get(
1697+
parser.getContext(), mlir::acc::CombinedConstructsType::SerialLoop);
1698+
} else {
1699+
parser.emitError(parser.getCurrentLocation(),
1700+
"expected compute construct name");
1701+
return failure();
17081702
}
17091703
return success();
17101704
}
@@ -1715,13 +1709,13 @@ printCombinedConstructsLoop(mlir::OpAsmPrinter &p, mlir::Operation *op,
17151709
if (attr) {
17161710
switch (attr.getValue()) {
17171711
case mlir::acc::CombinedConstructsType::KernelsLoop:
1718-
p << "combined(kernels)";
1712+
p << "kernels";
17191713
break;
17201714
case mlir::acc::CombinedConstructsType::ParallelLoop:
1721-
p << "combined(parallel)";
1715+
p << "parallel";
17221716
break;
17231717
case mlir::acc::CombinedConstructsType::SerialLoop:
1724-
p << "combined(serial)";
1718+
p << "serial";
17251719
break;
17261720
};
17271721
}

0 commit comments

Comments
 (0)