[mlir][OpenMP] Added assemblyformat for TargetOp

This patch removes custom parser/printer for `omp.target` and adds
assemblyformat.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120138
This commit is contained in:
Shraiysh Vaishay 2022-02-19 01:14:01 +05:30
parent 5ee500acbb
commit 60210f9acb
3 changed files with 10 additions and 48 deletions

View 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
}];
}

View 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
//===----------------------------------------------------------------------===//

View 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
}