Skip to content

Commit c805ef4

Browse files
committed
[OpenMP] Add verifier and tests for workdistribute mlir op.
1 parent 1c01409 commit c805ef4

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
534534
break;
535535

536536
case OMPD_teams_workdistribute:
537-
cp.processThreadLimit(stmtCtx, hostInfo.ops);
537+
cp.processThreadLimit(stmtCtx, hostInfo->ops);
538538
[[fallthrough]];
539539
case OMPD_target_teams_workdistribute:
540-
cp.processNumTeams(stmtCtx, hostInfo.ops);
540+
cp.processNumTeams(stmtCtx, hostInfo->ops);
541541
processSingleNestedIf([](Directive nestedDir) {
542542
return topDistributeSet.test(nestedDir) || topLoopSet.test(nestedDir);
543543
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,7 @@ def WorkdistributeOp : OpenMP_Op<"workdistribute"> {
21342134
```
21352135
}];
21362136
let regions = (region AnyRegion:$region);
2137+
let hasVerifier = 1;
21372138
let assemblyFormat = "$region attr-dict";
21382139
}
21392140

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,21 @@ LogicalResult AllocateDirOp::verify() {
38743874
return success();
38753875
}
38763876

3877+
//===----------------------------------------------------------------------===//
3878+
// WorkdistributeOp
3879+
//===----------------------------------------------------------------------===//
3880+
3881+
LogicalResult WorkdistributeOp::verify() {
3882+
Region &region = getRegion();
3883+
if (!region.hasOneBlock())
3884+
return emitOpError("region must contain exactly one block");
3885+
3886+
Operation *parentOp = (*this)->getParentOp();
3887+
if (!llvm::dyn_cast<TeamsOp>(parentOp))
3888+
return emitOpError("workdistribute must be nested under teams");
3889+
return success();
3890+
}
3891+
38773892
#define GET_ATTRDEF_CLASSES
38783893
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
38793894

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,3 +3017,26 @@ func.func @invalid_allocate_allocator(%arg0 : memref<i32>) -> () {
30173017

30183018
return
30193019
}
3020+
3021+
// -----
3022+
func.func @invalid_workdistribute() -> () {
3023+
// expected-error @below {{workdistribute must be nested under teams}}
3024+
omp.workdistribute {
3025+
omp.terminator
3026+
}
3027+
return
3028+
}
3029+
3030+
// -----
3031+
func.func @invalid_workdistribute_with_multiple_blocks() -> () {
3032+
omp.teams {
3033+
// expected-error @below {{region must contain exactly one block}}
3034+
omp.workdistribute {
3035+
cf.br ^bb1
3036+
^bb1:
3037+
omp.terminator
3038+
}
3039+
omp.terminator
3040+
}
3041+
return
3042+
}

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,3 +3238,15 @@ func.func @omp_allocate_dir(%arg0 : memref<i32>, %arg1 : memref<i32>) -> () {
32383238
return
32393239
}
32403240

3241+
// CHECK-LABEL: func.func @omp_workdistribute
3242+
func.func @omp_workdistribute() {
3243+
// CHECK: omp.teams
3244+
omp.teams {
3245+
// CHECK: omp.workdistribute
3246+
omp.workdistribute {
3247+
omp.terminator
3248+
}
3249+
omp.terminator
3250+
}
3251+
return
3252+
}

0 commit comments

Comments
 (0)