Skip to content

Commit bd2355d

Browse files
committed
[OpenMP] Add verifier and tests for workdistribute mlir op.
1 parent 98f5ec0 commit bd2355d

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

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

538538
case OMPD_teams_workdistribute:
539-
cp.processThreadLimit(stmtCtx, hostInfo.ops);
539+
cp.processThreadLimit(stmtCtx, hostInfo->ops);
540540
[[fallthrough]];
541541
case OMPD_target_teams_workdistribute:
542-
cp.processNumTeams(stmtCtx, hostInfo.ops);
542+
cp.processNumTeams(stmtCtx, hostInfo->ops);
543543
processSingleNestedIf([](Directive nestedDir) {
544544
return topDistributeSet.test(nestedDir) || topLoopSet.test(nestedDir);
545545
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,7 @@ def WorkdistributeOp : OpenMP_Op<"workdistribute"> {
22252225
```
22262226
}];
22272227
let regions = (region AnyRegion:$region);
2228+
let hasVerifier = 1;
22282229
let assemblyFormat = "$region attr-dict";
22292230
}
22302231

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,20 @@ llvm::LogicalResult omp::TargetAllocMemOp::verify() {
39743974
if (!mlir::dyn_cast<IntegerType>(outType))
39753975
return emitOpError("must be a integer type");
39763976
return mlir::success();
3977+
3978+
//===----------------------------------------------------------------------===//
3979+
// WorkdistributeOp
3980+
//===----------------------------------------------------------------------===//
3981+
3982+
LogicalResult WorkdistributeOp::verify() {
3983+
Region &region = getRegion();
3984+
if (!region.hasOneBlock())
3985+
return emitOpError("region must contain exactly one block");
3986+
3987+
Operation *parentOp = (*this)->getParentOp();
3988+
if (!llvm::dyn_cast<TeamsOp>(parentOp))
3989+
return emitOpError("workdistribute must be nested under teams");
3990+
return success();
39773991
}
39783992

39793993
#define GET_ATTRDEF_CLASSES

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)