Skip to content

Commit 82330e2

Browse files
committed
[MLIR][OpenMP] Add OMP Declare Mapper MLIR Op definition
This patch adds the OMP.DeclareMapperOp to MLIR.
1 parent 3f8e280 commit 82330e2

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
@@ -1749,6 +1749,34 @@ def ScanOp : OpenMP_Op<"scan", [
17491749
let hasVerifier = 1;
17501750
}
17511751

1752+
//===----------------------------------------------------------------------===//
1753+
// 2.19.7.3 Declare Mapper Directive
1754+
//===----------------------------------------------------------------------===//
1755+
def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
1756+
Symbol], clauses = [
1757+
OpenMP_MapClause
1758+
]> {
1759+
let summary = "declare mapper directive";
1760+
let description = [{
1761+
The declare mapper directive declares a user-defined mapper for a given
1762+
type, and may define a mapper-identifier that can be used in a map clause.
1763+
}] # clausesDescription;
1764+
1765+
let arguments = !con((ins SymbolNameAttr:$sym_name,
1766+
OpenMP_PointerLikeType:$var_ptr,
1767+
TypeAttr:$var_type), clausesArgs);
1768+
1769+
let builders = [
1770+
OpBuilder<(ins CArg<"const DeclareMapperOperands &">:$clauses)>
1771+
];
1772+
1773+
// Override clause-based assemblyFormat.
1774+
let assemblyFormat = "$sym_name `:` $var_ptr `:` type($var_ptr) `:` $var_type" # " oilist(" #
1775+
clausesOptAssemblyFormat # ") attr-dict";
1776+
1777+
let hasVerifier = 1;
1778+
}
1779+
17521780
//===----------------------------------------------------------------------===//
17531781
// 2.19.5.7 declare reduction Directive
17541782
//===----------------------------------------------------------------------===//

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,14 @@ LogicalResult DistributeOp::verifyRegions() {
24322432
return success();
24332433
}
24342434

2435+
//===----------------------------------------------------------------------===//
2436+
// DeclareMapperOp
2437+
//===----------------------------------------------------------------------===//
2438+
2439+
LogicalResult DeclareMapperOp::verify() {
2440+
return verifyMapClause(*this, getMapVars());
2441+
}
2442+
24352443
//===----------------------------------------------------------------------===//
24362444
// DeclareReductionOp
24372445
//===----------------------------------------------------------------------===//

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)