[mlir][OpenMP] Added assemblyformat for TargetOp
authorShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Fri, 18 Feb 2022 19:44:01 +0000 (01:14 +0530)
committerShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Fri, 18 Feb 2022 19:52:59 +0000 (01:22 +0530)
This patch removes custom parser/printer for `omp.target` and adds
assemblyformat.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120138

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/test/Dialect/OpenMP/ops.mlir

index 5933326..ec535ed 100644 (file)
@@ -372,7 +372,13 @@ def TargetOp : OpenMP_Op<"target",[AttrSizedOperandSegments]> {
 
   let regions = (region AnyRegion:$region);
 
-  let hasCustomAssemblyFormat = 1;
+  let assemblyFormat = [{
+    oilist( `if` `(` $if_expr `)`
+          | `device` `(` $device `:` type($device) `)`
+          | `thread_limit` `(` $thread_limit `:` type($thread_limit) `)`
+          | `nowait`
+    ) $region attr-dict
+  }];
 }
 
 
index b6f45bf..bc3b595 100644 (file)
@@ -145,23 +145,6 @@ void ParallelOp::print(OpAsmPrinter &p) {
   p.printRegion(getRegion());
 }
 
-void TargetOp::print(OpAsmPrinter &p) {
-  p << " ";
-  if (auto ifCond = if_expr())
-    p << "if(" << ifCond << " : " << ifCond.getType() << ") ";
-
-  if (auto device = this->device())
-    p << "device(" << device << " : " << device.getType() << ") ";
-
-  if (auto threads = thread_limit())
-    p << "thread_limit(" << threads << " : " << threads.getType() << ") ";
-
-  if (nowait())
-    p << "nowait ";
-
-  p.printRegion(getRegion());
-}
-
 //===----------------------------------------------------------------------===//
 // Parser and printer for Linear Clause
 //===----------------------------------------------------------------------===//
@@ -846,33 +829,6 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) {
   return success();
 }
 
-/// Parses a target operation.
-///
-/// operation ::= `omp.target` clause-list
-/// clause-list ::= clause | clause clause-list
-/// clause ::= if | device | thread_limit | nowait
-///
-ParseResult TargetOp::parse(OpAsmParser &parser, OperationState &result) {
-  SmallVector<ClauseType> clauses = {ifClause, deviceClause, threadLimitClause,
-                                     nowaitClause};
-
-  SmallVector<int> segments;
-
-  if (failed(parseClauses(parser, result, clauses, segments)))
-    return failure();
-
-  result.addAttribute(
-      TargetOp::AttrSizedOperandSegments::getOperandSegmentSizeAttr(),
-      parser.getBuilder().getI32VectorAttr(segments));
-
-  Region *body = result.addRegion();
-  SmallVector<OpAsmParser::OperandType> regionArgs;
-  SmallVector<Type> regionArgTypes;
-  if (parser.parseRegion(*body, regionArgs, regionArgTypes))
-    return failure();
-  return success();
-}
-
 //===----------------------------------------------------------------------===//
 // Parser, printer and verifier for SectionsOp
 //===----------------------------------------------------------------------===//
index 1c16ae7..573b036 100644 (file)
@@ -307,7 +307,7 @@ func @omp_target(%if_cond : i1, %device : si32,  %num_threads : si32) -> () {
     "omp.target"(%if_cond, %device, %num_threads) ({
        // CHECK: omp.terminator
        omp.terminator
-    }) {operand_segment_sizes = dense<[1,1,1]>: vector<3xi32>, nowait } : ( i1, si32, si32 ) -> ()
+    }) {if, device, nowait, operand_segment_sizes = dense<[1,1,1]>: vector<3xi32>, thread_limit} : ( i1, si32, si32 ) -> ()
 
     // CHECK: omp.barrier
     omp.barrier
@@ -318,12 +318,12 @@ func @omp_target(%if_cond : i1, %device : si32,  %num_threads : si32) -> () {
 // CHECK-LABEL: omp_target_pretty
 func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : si32) -> () {
     // CHECK: omp.target if({{.*}}) device({{.*}})
-    omp.target if(%if_cond : i1) device(%device : si32) {
+    omp.target if(%if_cond) device(%device : si32) {
       omp.terminator
     }
 
     // CHECK: omp.target if({{.*}}) device({{.*}}) nowait
-    omp.target if(%if_cond : i1) device(%device : si32) thread_limit(%num_threads : si32) nowait {
+    omp.target if(%if_cond) device(%device : si32) thread_limit(%num_threads : si32) nowait {
       omp.terminator
     }