Skip to content

Commit ff980db

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

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
@@ -1689,6 +1689,34 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
16891689
let hasVerifier = 1;
16901690
}
16911691

1692+
//===----------------------------------------------------------------------===//
1693+
// 2.19.7.3 Declare Mapper Directive
1694+
//===----------------------------------------------------------------------===//
1695+
def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
1696+
Symbol], clauses = [
1697+
OpenMP_MapClause
1698+
]> {
1699+
let summary = "declare mapper directive";
1700+
let description = [{
1701+
The declare mapper directive declares a user-defined mapper for a given
1702+
type, and may define a mapper-identifier that can be used in a map clause.
1703+
}] # clausesDescription;
1704+
1705+
let arguments = !con((ins SymbolNameAttr:$sym_name,
1706+
OpenMP_PointerLikeType:$var_ptr,
1707+
TypeAttr:$var_type), clausesArgs);
1708+
1709+
let builders = [
1710+
OpBuilder<(ins CArg<"const DeclareMapperOperands &">:$clauses)>
1711+
];
1712+
1713+
// Override clause-based assemblyFormat.
1714+
let assemblyFormat = "$sym_name `:` $var_ptr `:` type($var_ptr) `:` $var_type" # " oilist(" #
1715+
clausesOptAssemblyFormat # ") attr-dict";
1716+
1717+
let hasVerifier = 1;
1718+
}
1719+
16921720
//===----------------------------------------------------------------------===//
16931721
// 2.19.5.7 declare reduction Directive
16941722
//===----------------------------------------------------------------------===//

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,14 @@ LogicalResult DistributeOp::verifyRegions() {
22042204
return success();
22052205
}
22062206

2207+
//===----------------------------------------------------------------------===//
2208+
// DeclareMapperOp
2209+
//===----------------------------------------------------------------------===//
2210+
2211+
LogicalResult DeclareMapperOp::verify() {
2212+
return verifyMapClause(*this, getMapVars());
2213+
}
2214+
22072215
//===----------------------------------------------------------------------===//
22082216
// DeclareReductionOp
22092217
//===----------------------------------------------------------------------===//

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)