Skip to content

Commit

Permalink
[mlir][OpenMP] Added assemblyformat for TargetOp
Browse files Browse the repository at this point in the history
This patch removes custom parser/printer for `omp.target` and adds
assemblyformat.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120138
  • Loading branch information
shraiysh committed Feb 18, 2022
1 parent 5ee500a commit 60210f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
8 changes: 7 additions & 1 deletion mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
Expand Up @@ -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
}];
}


Expand Down
44 changes: 0 additions & 44 deletions mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Dialect/OpenMP/ops.mlir
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 60210f9

Please sign in to comment.