Skip to content

Commit dd3b43a

Browse files
authored
[mlir][OpenMP][NFC] clean up optional reduction region parsing (#105644)
This can be handled in ODS instead of writing custom parsing/printing code. Thanks for the idea @skatrak
1 parent 7e3f9dd commit dd3b43a

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -1576,11 +1576,11 @@ def DeclareReductionOp : OpenMP_Op<"declare_reduction", [IsolatedFromAbove,
15761576
AnyRegion:$cleanupRegion);
15771577

15781578
let assemblyFormat = "$sym_name `:` $type attr-dict-with-keyword "
1579-
"custom<AllocReductionRegion>($allocRegion) "
1579+
"( `alloc` $allocRegion^ )? "
15801580
"`init` $initializerRegion "
15811581
"`combiner` $reductionRegion "
1582-
"custom<AtomicReductionRegion>($atomicReductionRegion) "
1583-
"custom<CleanupReductionRegion>($cleanupRegion)";
1582+
"( `atomic` $atomicReductionRegion^ )? "
1583+
"( `cleanup` $cleanupRegion^ )? ";
15841584

15851585
let extraClassDeclaration = [{
15861586
PointerLikeType getAccumulatorType() {

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

-46
Original file line numberDiff line numberDiff line change
@@ -1883,52 +1883,6 @@ LogicalResult DistributeOp::verify() {
18831883
// DeclareReductionOp
18841884
//===----------------------------------------------------------------------===//
18851885

1886-
static ParseResult parseOptionalReductionRegion(OpAsmParser &parser,
1887-
Region &region,
1888-
StringRef keyword) {
1889-
if (parser.parseOptionalKeyword(keyword))
1890-
return success();
1891-
return parser.parseRegion(region);
1892-
}
1893-
1894-
static void printOptionalReductionRegion(OpAsmPrinter &printer, Region &region,
1895-
StringRef keyword) {
1896-
if (region.empty())
1897-
return;
1898-
printer << keyword << " ";
1899-
printer.printRegion(region);
1900-
}
1901-
1902-
static ParseResult parseAllocReductionRegion(OpAsmParser &parser,
1903-
Region &region) {
1904-
return parseOptionalReductionRegion(parser, region, "alloc");
1905-
}
1906-
1907-
static void printAllocReductionRegion(OpAsmPrinter &printer,
1908-
DeclareReductionOp op, Region &region) {
1909-
printOptionalReductionRegion(printer, region, "alloc");
1910-
}
1911-
1912-
static ParseResult parseAtomicReductionRegion(OpAsmParser &parser,
1913-
Region &region) {
1914-
return parseOptionalReductionRegion(parser, region, "atomic");
1915-
}
1916-
1917-
static void printAtomicReductionRegion(OpAsmPrinter &printer,
1918-
DeclareReductionOp op, Region &region) {
1919-
printOptionalReductionRegion(printer, region, "atomic");
1920-
}
1921-
1922-
static ParseResult parseCleanupReductionRegion(OpAsmParser &parser,
1923-
Region &region) {
1924-
return parseOptionalReductionRegion(parser, region, "cleanup");
1925-
}
1926-
1927-
static void printCleanupReductionRegion(OpAsmPrinter &printer,
1928-
DeclareReductionOp op, Region &region) {
1929-
printOptionalReductionRegion(printer, region, "cleanup");
1930-
}
1931-
19321886
LogicalResult DeclareReductionOp::verifyRegions() {
19331887
if (!getAllocRegion().empty()) {
19341888
for (YieldOp yieldOp : getAllocRegion().getOps<YieldOp>()) {

0 commit comments

Comments
 (0)