Skip to content

Commit 3e75c14

Browse files
TIFitiswldfngrs
authored andcommitted
[MLIR][OpenMP] Add OMP Declare Mapper MLIR Op definition (llvm#117045)
This patch adds the OMP.DeclareMapperOp to MLIR. The HLFIR/FIR lowering for Declare Mapper is available here llvm#117046.
1 parent 5773b95 commit 3e75c14

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

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

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def DistributeOp : OpenMP_Op<"distribute", traits = [
653653
will be executed in parallel by threads in the current context. These
654654
iterations are spread across threads that already exist in the enclosing
655655
region.
656-
656+
657657
The body region can only contain a single block which must contain a single
658658
operation. This operation must be another compatible loop wrapper or an
659659
`omp.loop_nest`.
@@ -1749,6 +1749,62 @@ 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", [
1756+
IsolatedFromAbove,
1757+
RecipeInterface,
1758+
SingleBlock,
1759+
Symbol
1760+
]> {
1761+
let summary = "declare mapper directive";
1762+
let description = [{
1763+
The declare mapper directive declares a user-defined mapper for a given
1764+
type, and defines a mapper-identifier that can be used in a map clause.
1765+
}] # clausesDescription;
1766+
1767+
let arguments = (ins SymbolNameAttr:$sym_name,
1768+
TypeAttr:$type);
1769+
1770+
let regions = (region AnyRegion:$body);
1771+
1772+
let assemblyFormat = "$sym_name `:` $type $body attr-dict";
1773+
1774+
let extraClassDeclaration = [{
1775+
/// Get DeclareMapperInfoOp.
1776+
DeclareMapperInfoOp getDeclareMapperInfo(){
1777+
return cast<DeclareMapperInfoOp>(getRegion().getBlocks().front().getTerminator());
1778+
}
1779+
1780+
/// Get SymVal block argument
1781+
BlockArgument getSymVal(){
1782+
return getRegion().getArgument(0);
1783+
}
1784+
}];
1785+
1786+
let hasRegionVerifier = 1;
1787+
}
1788+
1789+
def DeclareMapperInfoOp : OpenMP_Op<"declare_mapper.info", [
1790+
HasParent<"DeclareMapperOp">,
1791+
Terminator
1792+
], clauses = [
1793+
OpenMP_MapClause
1794+
]> {
1795+
let summary = "declare mapper info";
1796+
let description = [{
1797+
This Op is used to capture the map information related to it's
1798+
parent DeclareMapperOp.
1799+
}] # clausesDescription;
1800+
1801+
let builders = [
1802+
OpBuilder<(ins CArg<"const DeclareMapperInfoOperands &">:$clauses)>
1803+
];
1804+
1805+
let hasVerifier = 1;
1806+
}
1807+
17521808
//===----------------------------------------------------------------------===//
17531809
// 2.19.5.7 declare reduction Directive
17541810
//===----------------------------------------------------------------------===//
@@ -1861,7 +1917,7 @@ def MaskedOp : OpenMP_Op<"masked", clauses = [
18611917
], singleRegion = 1> {
18621918
let summary = "masked construct";
18631919
let description = [{
1864-
Masked construct allows to specify a structured block to be executed by a subset of
1920+
Masked construct allows to specify a structured block to be executed by a subset of
18651921
threads of the current team.
18661922
}] # clausesDescription;
18671923

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

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

2435+
//===----------------------------------------------------------------------===//
2436+
// DeclareMapperOp / DeclareMapperInfoOp
2437+
//===----------------------------------------------------------------------===//
2438+
2439+
LogicalResult DeclareMapperInfoOp::verify() {
2440+
return verifyMapClause(*this, getMapVars());
2441+
}
2442+
2443+
LogicalResult DeclareMapperOp::verifyRegions() {
2444+
if (!llvm::isa_and_present<DeclareMapperInfoOp>(
2445+
getRegion().getBlocks().front().getTerminator()))
2446+
return emitOpError() << "expected terminator to be a DeclareMapperInfoOp";
2447+
2448+
return success();
2449+
}
2450+
24352451
//===----------------------------------------------------------------------===//
24362452
// DeclareReductionOp
24372453
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,3 +2842,10 @@ func.func @missing_workshare(%idx : index) {
28422842
}
28432843
return
28442844
}
2845+
2846+
// -----
2847+
// expected-error @below {{op expected terminator to be a DeclareMapperInfoOp}}
2848+
omp.declare_mapper @missing_declareMapperInfo : !llvm.struct<"mytype", (array<1024 x i32>)> {
2849+
^bb0(%arg0: !llvm.ptr):
2850+
omp.terminator
2851+
}

mlir/test/Dialect/OpenMP/ops.mlir

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

882+
// CHECK: omp.declare_mapper @my_mapper : !llvm.struct<"my_type", (i32)>
883+
omp.declare_mapper @my_mapper : !llvm.struct<"my_type", (i32)> {
884+
^bb0(%arg: !llvm.ptr):
885+
// CHECK: %[[DECL_MAP_INFO:.*]] = omp.map.info var_ptr(%{{.*}} : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
886+
%decl_map_info = omp.map.info var_ptr(%arg : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
887+
// CHECK: omp.declare_mapper.info map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
888+
omp.declare_mapper.info map_entries(%decl_map_info : !llvm.ptr)
889+
}
890+
882891
// CHECK-LABEL: func @wsloop_reduction
883892
func.func @wsloop_reduction(%lb : index, %ub : index, %step : index) {
884893
%c1 = arith.constant 1 : i32

0 commit comments

Comments
 (0)