[Mlir-commits] [mlir] dd3b43a - [mlir][OpenMP][NFC] clean up optional reduction region parsing (#105644)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Aug 22 06:28:38 PDT 2024


Author: Tom Eccles
Date: 2024-08-22T14:28:35+01:00
New Revision: dd3b43a455793e79b84171b8d522fc4d86dea61d

URL: https://github.com/llvm/llvm-project/commit/dd3b43a455793e79b84171b8d522fc4d86dea61d
DIFF: https://github.com/llvm/llvm-project/commit/dd3b43a455793e79b84171b8d522fc4d86dea61d.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
    mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 739b1f67be7cb2..5a7dae0b5f3074 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1576,11 +1576,11 @@ def DeclareReductionOp : OpenMP_Op<"declare_reduction", [IsolatedFromAbove,
                         AnyRegion:$cleanupRegion);
 
   let assemblyFormat = "$sym_name `:` $type attr-dict-with-keyword "
-                       "custom<AllocReductionRegion>($allocRegion) "
+                       "( `alloc` $allocRegion^ )? "
                        "`init` $initializerRegion "
                        "`combiner` $reductionRegion "
-                       "custom<AtomicReductionRegion>($atomicReductionRegion) "
-                       "custom<CleanupReductionRegion>($cleanupRegion)";
+                       "( `atomic` $atomicReductionRegion^ )? "
+                       "( `cleanup` $cleanupRegion^ )? ";
 
   let extraClassDeclaration = [{
     PointerLikeType getAccumulatorType() {

diff  --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 273f49b8b12b67..eb4f9cb041841b 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1883,52 +1883,6 @@ LogicalResult DistributeOp::verify() {
 // DeclareReductionOp
 //===----------------------------------------------------------------------===//
 
-static ParseResult parseOptionalReductionRegion(OpAsmParser &parser,
-                                                Region &region,
-                                                StringRef keyword) {
-  if (parser.parseOptionalKeyword(keyword))
-    return success();
-  return parser.parseRegion(region);
-}
-
-static void printOptionalReductionRegion(OpAsmPrinter &printer, Region &region,
-                                         StringRef keyword) {
-  if (region.empty())
-    return;
-  printer << keyword << " ";
-  printer.printRegion(region);
-}
-
-static ParseResult parseAllocReductionRegion(OpAsmParser &parser,
-                                             Region &region) {
-  return parseOptionalReductionRegion(parser, region, "alloc");
-}
-
-static void printAllocReductionRegion(OpAsmPrinter &printer,
-                                      DeclareReductionOp op, Region &region) {
-  printOptionalReductionRegion(printer, region, "alloc");
-}
-
-static ParseResult parseAtomicReductionRegion(OpAsmParser &parser,
-                                              Region &region) {
-  return parseOptionalReductionRegion(parser, region, "atomic");
-}
-
-static void printAtomicReductionRegion(OpAsmPrinter &printer,
-                                       DeclareReductionOp op, Region &region) {
-  printOptionalReductionRegion(printer, region, "atomic");
-}
-
-static ParseResult parseCleanupReductionRegion(OpAsmParser &parser,
-                                               Region &region) {
-  return parseOptionalReductionRegion(parser, region, "cleanup");
-}
-
-static void printCleanupReductionRegion(OpAsmPrinter &printer,
-                                        DeclareReductionOp op, Region &region) {
-  printOptionalReductionRegion(printer, region, "cleanup");
-}
-
 LogicalResult DeclareReductionOp::verifyRegions() {
   if (!getAllocRegion().empty()) {
     for (YieldOp yieldOp : getAllocRegion().getOps<YieldOp>()) {


        


More information about the Mlir-commits mailing list