Skip to content

Commit 8271c8e

Browse files
committed
R3: Updating the op definition according to new clause definitions
1 parent 21263f2 commit 8271c8e

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,4 +1204,32 @@ class OpenMP_UseDevicePtrClauseSkip<
12041204

12051205
def OpenMP_UseDevicePtrClause : OpenMP_UseDevicePtrClauseSkip<>;
12061206

1207+
//===----------------------------------------------------------------------===//
1208+
// V5.2: [10.5.1] `filter` clause
1209+
//===----------------------------------------------------------------------===//
1210+
1211+
class OpenMP_FilterClauseSkip<
1212+
bit traits = false, bit arguments = false, bit assemblyFormat = false,
1213+
bit description = false, bit extraClassDeclaration = false
1214+
> : OpenMP_Clause</*isRequired=*/false, traits, arguments, assemblyFormat,
1215+
description, extraClassDeclaration> {
1216+
let arguments = (ins
1217+
Optional<IntLikeType>:$filtered_thread_id
1218+
);
1219+
1220+
let assemblyFormat = [{
1221+
`filter` `(` $filtered_thread_id `:` type($filtered_thread_id) `)`
1222+
}];
1223+
1224+
let description = [{
1225+
If `filter` is specified, the masked construct masks the execution of
1226+
the region to only the thread id filtered. Other threads executing the
1227+
parallel region are not expected to execute the region specified within
1228+
the `masked` directive. If `filter` is not specified, master thread is
1229+
expected to execute the region enclosed within `masked` directive.
1230+
}];
1231+
}
1232+
1233+
def OpenMP_FilterClause : OpenMP_FilterClauseSkip<>;
1234+
12071235
#endif // OPENMP_CLAUSES

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,22 +1580,20 @@ def DeclareReductionOp : OpenMP_Op<"declare_reduction", [IsolatedFromAbove,
15801580
//===----------------------------------------------------------------------===//
15811581
// [Spec 5.2] 10.5 masked Construct
15821582
//===----------------------------------------------------------------------===//
1583-
def MaskedOp : OpenMP_Op<"masked"> {
1583+
def MaskedOp : OpenMP_Op<"masked", clauses = [
1584+
OpenMP_FilterClause
1585+
], singleRegion = 1> {
15841586
let summary = "masked construct";
15851587
let description = [{
15861588
Masked construct allows to specify a structured block to be executed by a subset of
1587-
threads of the current team. Filter clause allows to select the threads expected to
1588-
execute the region
1589-
}];
1589+
threads of the current team.
1590+
}] # clausesDescription;
15901591

1591-
let arguments = (ins Optional<I32>:$filteredThreadId);
15921592
let regions = (region AnyRegion:$region);
15931593

1594-
let assemblyFormat = [{
1595-
oilist(
1596-
`filter` `(` $filteredThreadId `:` type($filteredThreadId) `)`
1597-
) $region attr-dict
1598-
}];
1594+
let builders = [
1595+
OpBuilder<(ins CArg<"const MaskedClauseOps &">:$clauses)>
1596+
];
15991597
}
16001598

16011599
#endif // OPENMP_OPS

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,3 +2358,21 @@ func.func @byref_in_private(%arg0: index) {
23582358

23592359
return
23602360
}
2361+
2362+
// -----
2363+
func.func @masked_arg_type_mismatch(%arg0: f32) {
2364+
// expected-error @below {{'omp.masked' op operand #0 must be integer or index, but got 'f32'}}
2365+
"omp.masked"(%arg0) ({
2366+
omp.terminator
2367+
}) : (f32) -> ()
2368+
return
2369+
}
2370+
2371+
// -----
2372+
func.func @masked_arg_count_mismatch(%arg0: i32, %arg1: i32) {
2373+
// expected-error @below {{'omp.masked' op operand group starting at #0 requires 0 or 1 element, but found 2}}
2374+
"omp.masked"(%arg0, %arg1) ({
2375+
omp.terminator
2376+
}) : (i32, i32) -> ()
2377+
return
2378+
}

0 commit comments

Comments
 (0)