Skip to content

Commit afcc130

Browse files
committed
[MLIR][OpenMP] Add OMP Declare Mapper MLIR Op definition
This patch adds the OMP.DeclareMapperOp to MLIR.
1 parent aee3f5b commit afcc130

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,34 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
16521652
let hasVerifier = 1;
16531653
}
16541654

1655+
//===----------------------------------------------------------------------===//
1656+
// 2.19.7.3 Declare Mapper Directive
1657+
//===----------------------------------------------------------------------===//
1658+
def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
1659+
Symbol], clauses = [
1660+
OpenMP_MapClause
1661+
]> {
1662+
let summary = "declare mapper directive";
1663+
let description = [{
1664+
The declare mapper directive declares a user-defined mapper for a given
1665+
type, and may define a mapper-identifier that can be used in a map clause.
1666+
}] # clausesDescription;
1667+
1668+
let arguments = !con((ins SymbolNameAttr:$sym_name,
1669+
OpenMP_PointerLikeType:$var_ptr,
1670+
TypeAttr:$var_type), clausesArgs);
1671+
1672+
let builders = [
1673+
OpBuilder<(ins CArg<"const DeclareMapperOperands &">:$clauses)>
1674+
];
1675+
1676+
// Override clause-based assemblyFormat.
1677+
let assemblyFormat = "$sym_name `:` $var_ptr `:` type($var_ptr) `:` $var_type" # " oilist(" #
1678+
clausesOptAssemblyFormat # ") attr-dict";
1679+
1680+
let hasVerifier = 1;
1681+
}
1682+
16551683
//===----------------------------------------------------------------------===//
16561684
// 2.19.5.7 declare reduction Directive
16571685
//===----------------------------------------------------------------------===//

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,14 @@ LogicalResult DistributeOp::verifyRegions() {
21372137
return success();
21382138
}
21392139

2140+
//===----------------------------------------------------------------------===//
2141+
// DeclareMapperOp
2142+
//===----------------------------------------------------------------------===//
2143+
2144+
LogicalResult DeclareMapperOp::verify() {
2145+
return verifyMapClause(*this, getMapVars());
2146+
}
2147+
21402148
//===----------------------------------------------------------------------===//
21412149
// DeclareReductionOp
21422150
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,14 @@ cleanup {
879879
omp.yield
880880
}
881881

882+
// CHECK: %[[DECL_VAR:.*]] = llvm.alloca %{{.*}}
883+
// CHECK: %[[DECL_MAP_INFO:.*]] = omp.map.info var_ptr(%[[DECL_VAR]] : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
884+
// CHECK: omp.declare_mapper @my_mapper : %[[DECL_VAR]] : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
885+
%decl_c1 = arith.constant 1 : i64
886+
%decl_var = llvm.alloca %decl_c1 x !llvm.struct<"my_type", (i32)> : (i64) -> !llvm.ptr
887+
%decl_map_info = omp.map.info var_ptr(%decl_var : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
888+
omp.declare_mapper @my_mapper : %decl_var : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%decl_map_info : !llvm.ptr)
889+
882890
// CHECK-LABEL: func @wsloop_reduction
883891
func.func @wsloop_reduction(%lb : index, %ub : index, %step : index) {
884892
%c1 = arith.constant 1 : i32

0 commit comments

Comments
 (0)