Skip to content

Commit 8503797

Browse files
committed
Add verification and descriptions
1 parent 7bd2871 commit 8503797

File tree

4 files changed

+87
-13
lines changed

4 files changed

+87
-13
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def WorkshareOp : OpenMP_Op<"workshare", traits = [
302302
block into separate units of work, and causes the threads of the team to
303303
share the work such that each unit is executed only once by one thread, in
304304
the context of its implicit task
305+
306+
This operation is used for the intermediate representation of the workshare
307+
block before the work gets divided between the threads. See the flang
308+
LowerWorkshare pass for details.
305309
}] # clausesDescription;
306310

307311
let builders = [
@@ -314,10 +318,16 @@ def WorkshareLoopWrapperOp : OpenMP_Op<"workshare_loop_wrapper", traits = [
314318
RecursiveMemoryEffects, SingleBlock
315319
], singleRegion = true> {
316320
let summary = "contains loop nests to be parallelized by workshare";
321+
let description = [{
322+
This operation wraps a loop nest that is marked for dividing into units of
323+
work by an encompassing omp.workshare operation.
324+
}];
325+
317326
let builders = [
318327
OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>
319328
];
320329
let assemblyFormat = "$region attr-dict";
330+
let hasVerifier = 1;
321331
}
322332

323333
//===----------------------------------------------------------------------===//

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,20 @@ void WorkshareOp::build(OpBuilder &builder, OperationState &state,
16981698
WorkshareOp::build(builder, state, clauses.nowait);
16991699
}
17001700

1701+
//===----------------------------------------------------------------------===//
1702+
// WorkshareLoopWrapperOp
1703+
//===----------------------------------------------------------------------===//
1704+
1705+
LogicalResult WorkshareLoopWrapperOp::verify() {
1706+
if (!isWrapper())
1707+
return emitOpError() << "must be a loop wrapper";
1708+
if (getNestedWrapper())
1709+
return emitError() << "nested wrappers not supported";
1710+
if (!(*this)->getParentOfType<WorkshareOp>())
1711+
return emitError() << "must be nested in an omp.workshare";
1712+
return success();
1713+
}
1714+
17011715
//===----------------------------------------------------------------------===//
17021716
// WsloopOp
17031717
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,3 +2545,45 @@ func.func @omp_taskloop_invalid_composite(%lb: index, %ub: index, %step: index)
25452545
} {omp.composite}
25462546
return
25472547
}
2548+
2549+
// -----
2550+
func.func @nested_wrapper(%idx : index) {
2551+
omp.workshare {
2552+
// expected-error @below {{nested wrappers not supported}}
2553+
omp.workshare_loop_wrapper {
2554+
omp.simd {
2555+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2556+
omp.yield
2557+
}
2558+
omp.terminator
2559+
}
2560+
omp.terminator
2561+
}
2562+
omp.terminator
2563+
}
2564+
return
2565+
}
2566+
2567+
// -----
2568+
func.func @not_wrapper() {
2569+
omp.workshare {
2570+
// expected-error @below {{must be a loop wrapper}}
2571+
omp.workshare_loop_wrapper {
2572+
omp.terminator
2573+
}
2574+
omp.terminator
2575+
}
2576+
return
2577+
}
2578+
2579+
// -----
2580+
func.func @missing_workshare(%idx : index) {
2581+
// expected-error @below {{must be nested in an omp.workshare}}
2582+
omp.workshare_loop_wrapper {
2583+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2584+
omp.yield
2585+
}
2586+
omp.terminator
2587+
}
2588+
return
2589+
}

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,11 +2847,15 @@ func.func @omp_workshare_multiple_blocks() {
28472847

28482848
// CHECK-LABEL: func @omp_workshare_loop_wrapper
28492849
func.func @omp_workshare_loop_wrapper(%idx : index) {
2850-
// CHECK-NEXT: omp.workshare_loop_wrapper
2851-
omp.workshare_loop_wrapper {
2852-
// CHECK-NEXT: omp.loop_nest
2853-
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2854-
omp.yield
2850+
// CHECK-NEXT: omp.workshare {
2851+
omp.workshare {
2852+
// CHECK-NEXT: omp.workshare_loop_wrapper
2853+
omp.workshare_loop_wrapper {
2854+
// CHECK-NEXT: omp.loop_nest
2855+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2856+
omp.yield
2857+
}
2858+
omp.terminator
28552859
}
28562860
omp.terminator
28572861
}
@@ -2860,14 +2864,18 @@ func.func @omp_workshare_loop_wrapper(%idx : index) {
28602864

28612865
// CHECK-LABEL: func @omp_workshare_loop_wrapper_attrs
28622866
func.func @omp_workshare_loop_wrapper_attrs(%idx : index) {
2863-
// CHECK-NEXT: omp.workshare_loop_wrapper {
2864-
omp.workshare_loop_wrapper {
2865-
// CHECK-NEXT: omp.loop_nest
2866-
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2867-
omp.yield
2868-
}
2867+
// CHECK-NEXT: omp.workshare {
2868+
omp.workshare {
2869+
// CHECK-NEXT: omp.workshare_loop_wrapper {
2870+
omp.workshare_loop_wrapper {
2871+
// CHECK-NEXT: omp.loop_nest
2872+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2873+
omp.yield
2874+
}
2875+
omp.terminator
2876+
// CHECK: } {attr_in_dict}
2877+
} {attr_in_dict}
28692878
omp.terminator
2870-
// CHECK: } {attr_in_dict}
2871-
} {attr_in_dict}
2879+
}
28722880
return
28732881
}

0 commit comments

Comments
 (0)