Skip to content

Commit fe2a447

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

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
@@ -619,10 +619,10 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
619619
break;
620620

621621
case OMPD_teams_workdistribute:
622-
cp.processThreadLimit(stmtCtx, hostInfo.ops);
622+
cp.processThreadLimit(stmtCtx, hostInfo->ops);
623623
[[fallthrough]];
624624
case OMPD_target_teams_workdistribute:
625-
cp.processNumTeams(stmtCtx, hostInfo.ops);
625+
cp.processNumTeams(stmtCtx, hostInfo->ops);
626626
processSingleNestedIf([](Directive nestedDir) {
627627
return topDistributeSet.test(nestedDir) || topLoopSet.test(nestedDir);
628628
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,7 @@ def WorkdistributeOp : OpenMP_Op<"workdistribute"> {
21322132
```
21332133
}];
21342134
let regions = (region AnyRegion:$region);
2135+
let hasVerifier = 1;
21352136
let assemblyFormat = "$region attr-dict";
21362137
}
21372138

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,6 +3878,21 @@ LogicalResult AllocateDirOp::verify() {
38783878
return success();
38793879
}
38803880

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

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
@@ -3230,3 +3230,15 @@ func.func @omp_allocate_dir(%arg0 : memref<i32>, %arg1 : memref<i32>) -> () {
32303230
return
32313231
}
32323232

3233+
// CHECK-LABEL: func.func @omp_workdistribute
3234+
func.func @omp_workdistribute() {
3235+
// CHECK: omp.teams
3236+
omp.teams {
3237+
// CHECK: omp.workdistribute
3238+
omp.workdistribute {
3239+
omp.terminator
3240+
}
3241+
omp.terminator
3242+
}
3243+
return
3244+
}

0 commit comments

Comments
 (0)