Skip to content

Commit d030f24

Browse files
committed
Add verification and descriptions
1 parent 7376fd4 commit d030f24

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
@@ -301,6 +301,10 @@ def WorkshareOp : OpenMP_Op<"workshare", traits = [
301301
block into separate units of work, and causes the threads of the team to
302302
share the work such that each unit is executed only once by one thread, in
303303
the context of its implicit task
304+
305+
This operation is used for the intermediate representation of the workshare
306+
block before the work gets divided between the threads. See the flang
307+
LowerWorkshare pass for details.
304308
}] # clausesDescription;
305309

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

322332
//===----------------------------------------------------------------------===//

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

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

1695+
//===----------------------------------------------------------------------===//
1696+
// WorkshareLoopWrapperOp
1697+
//===----------------------------------------------------------------------===//
1698+
1699+
LogicalResult WorkshareLoopWrapperOp::verify() {
1700+
if (!isWrapper())
1701+
return emitOpError() << "must be a loop wrapper";
1702+
if (getNestedWrapper())
1703+
return emitError() << "nested wrappers not supported";
1704+
if (!(*this)->getParentOfType<WorkshareOp>())
1705+
return emitError() << "must be nested in an omp.workshare";
1706+
return success();
1707+
}
1708+
16951709
//===----------------------------------------------------------------------===//
16961710
// WsloopOp
16971711
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,3 +2383,45 @@ func.func @masked_arg_count_mismatch(%arg0: i32, %arg1: i32) {
23832383
}) : (i32, i32) -> ()
23842384
return
23852385
}
2386+
2387+
// -----
2388+
func.func @nested_wrapper(%idx : index) {
2389+
omp.workshare {
2390+
// expected-error @below {{nested wrappers not supported}}
2391+
omp.workshare_loop_wrapper {
2392+
omp.simd {
2393+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2394+
omp.yield
2395+
}
2396+
omp.terminator
2397+
}
2398+
omp.terminator
2399+
}
2400+
omp.terminator
2401+
}
2402+
return
2403+
}
2404+
2405+
// -----
2406+
func.func @not_wrapper() {
2407+
omp.workshare {
2408+
// expected-error @below {{must be a loop wrapper}}
2409+
omp.workshare_loop_wrapper {
2410+
omp.terminator
2411+
}
2412+
omp.terminator
2413+
}
2414+
return
2415+
}
2416+
2417+
// -----
2418+
func.func @missing_workshare(%idx : index) {
2419+
// expected-error @below {{must be nested in an omp.workshare}}
2420+
omp.workshare_loop_wrapper {
2421+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2422+
omp.yield
2423+
}
2424+
omp.terminator
2425+
}
2426+
return
2427+
}

mlir/test/Dialect/OpenMP/ops.mlir

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

28272827
// CHECK-LABEL: func @omp_workshare_loop_wrapper
28282828
func.func @omp_workshare_loop_wrapper(%idx : index) {
2829-
// CHECK-NEXT: omp.workshare_loop_wrapper
2830-
omp.workshare_loop_wrapper {
2831-
// CHECK-NEXT: omp.loop_nest
2832-
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2833-
omp.yield
2829+
// CHECK-NEXT: omp.workshare {
2830+
omp.workshare {
2831+
// CHECK-NEXT: omp.workshare_loop_wrapper
2832+
omp.workshare_loop_wrapper {
2833+
// CHECK-NEXT: omp.loop_nest
2834+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2835+
omp.yield
2836+
}
2837+
omp.terminator
28342838
}
28352839
omp.terminator
28362840
}
@@ -2839,14 +2843,18 @@ func.func @omp_workshare_loop_wrapper(%idx : index) {
28392843

28402844
// CHECK-LABEL: func @omp_workshare_loop_wrapper_attrs
28412845
func.func @omp_workshare_loop_wrapper_attrs(%idx : index) {
2842-
// CHECK-NEXT: omp.workshare_loop_wrapper {
2843-
omp.workshare_loop_wrapper {
2844-
// CHECK-NEXT: omp.loop_nest
2845-
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2846-
omp.yield
2847-
}
2846+
// CHECK-NEXT: omp.workshare {
2847+
omp.workshare {
2848+
// CHECK-NEXT: omp.workshare_loop_wrapper {
2849+
omp.workshare_loop_wrapper {
2850+
// CHECK-NEXT: omp.loop_nest
2851+
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
2852+
omp.yield
2853+
}
2854+
omp.terminator
2855+
// CHECK: } {attr_in_dict}
2856+
} {attr_in_dict}
28482857
omp.terminator
2849-
// CHECK: } {attr_in_dict}
2850-
} {attr_in_dict}
2858+
}
28512859
return
28522860
}

0 commit comments

Comments
 (0)