Skip to content

Commit

Permalink
Add verification and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Aug 21, 2024
1 parent 1b97840 commit 45a8aa4
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
10 changes: 10 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def WorkshareOp : OpenMP_Op<"workshare", traits = [
block into separate units of work, and causes the threads of the team to
share the work such that each unit is executed only once by one thread, in
the context of its implicit task

This operation is used for the intermediate representation of the workshare
block before the work gets divided between the threads. See the flang
LowerWorkshare pass for details.
}] # clausesDescription;

let builders = [
Expand All @@ -314,10 +318,16 @@ def WorkshareLoopWrapperOp : OpenMP_Op<"workshare_loop_wrapper", traits = [
RecursiveMemoryEffects, SingleBlock
], singleRegion = true> {
let summary = "contains loop nests to be parallelized by workshare";
let description = [{
This operation wraps a loop nest that is marked for dividing into units of
work by an encompassing omp.workshare operation.
}];

let builders = [
OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>
];
let assemblyFormat = "$region attr-dict";
let hasVerifier = 1;
}

//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,20 @@ void WorkshareOp::build(OpBuilder &builder, OperationState &state,
WorkshareOp::build(builder, state, clauses.nowait);
}

//===----------------------------------------------------------------------===//
// WorkshareLoopWrapperOp
//===----------------------------------------------------------------------===//

LogicalResult WorkshareLoopWrapperOp::verify() {
if (!isWrapper())
return emitOpError() << "must be a loop wrapper";
if (getNestedWrapper())
return emitError() << "nested wrappers not supported";
if (!(*this)->getParentOfType<WorkshareOp>())
return emitError() << "must be nested in an omp.workshare";
return success();
}

//===----------------------------------------------------------------------===//
// WsloopOp
//===----------------------------------------------------------------------===//
Expand Down
42 changes: 42 additions & 0 deletions mlir/test/Dialect/OpenMP/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2545,3 +2545,45 @@ func.func @omp_taskloop_invalid_composite(%lb: index, %ub: index, %step: index)
} {omp.composite}
return
}

// -----
func.func @nested_wrapper(%idx : index) {
omp.workshare {
// expected-error @below {{nested wrappers not supported}}
omp.workshare_loop_wrapper {
omp.simd {
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
}
omp.terminator
}
omp.terminator
}
omp.terminator
}
return
}

// -----
func.func @not_wrapper() {
omp.workshare {
// expected-error @below {{must be a loop wrapper}}
omp.workshare_loop_wrapper {
omp.terminator
}
omp.terminator
}
return
}

// -----
func.func @missing_workshare(%idx : index) {
// expected-error @below {{must be nested in an omp.workshare}}
omp.workshare_loop_wrapper {
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
}
omp.terminator
}
return
}
34 changes: 21 additions & 13 deletions mlir/test/Dialect/OpenMP/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2847,11 +2847,15 @@ func.func @omp_workshare_multiple_blocks() {

// CHECK-LABEL: func @omp_workshare_loop_wrapper
func.func @omp_workshare_loop_wrapper(%idx : index) {
// CHECK-NEXT: omp.workshare_loop_wrapper
omp.workshare_loop_wrapper {
// CHECK-NEXT: omp.loop_nest
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
// CHECK-NEXT: omp.workshare {
omp.workshare {
// CHECK-NEXT: omp.workshare_loop_wrapper
omp.workshare_loop_wrapper {
// CHECK-NEXT: omp.loop_nest
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
}
omp.terminator
}
omp.terminator
}
Expand All @@ -2860,14 +2864,18 @@ func.func @omp_workshare_loop_wrapper(%idx : index) {

// CHECK-LABEL: func @omp_workshare_loop_wrapper_attrs
func.func @omp_workshare_loop_wrapper_attrs(%idx : index) {
// CHECK-NEXT: omp.workshare_loop_wrapper {
omp.workshare_loop_wrapper {
// CHECK-NEXT: omp.loop_nest
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
}
// CHECK-NEXT: omp.workshare {
omp.workshare {
// CHECK-NEXT: omp.workshare_loop_wrapper {
omp.workshare_loop_wrapper {
// CHECK-NEXT: omp.loop_nest
omp.loop_nest (%iv) : index = (%idx) to (%idx) step (%idx) {
omp.yield
}
omp.terminator
// CHECK: } {attr_in_dict}
} {attr_in_dict}
omp.terminator
// CHECK: } {attr_in_dict}
} {attr_in_dict}
}
return
}

0 comments on commit 45a8aa4

Please sign in to comment.