Skip to content

Commit ffced03

Browse files
committed
[OpenMP][MLIR] Add new arguments to map_info to help support record type maps
This PR adds two new fields to omp.map_info, one BoolAttr and one I64ArrayAttr. The BoolAttr is named partial_map, and is a flag that indicates if the record type captured by the map_info operation is a partial map, or if it is mapped in its entirety, this currently helps the later lowering determine the type of map entries that need to be generated. The I64ArrayAttr named members_index is intended to track the placement of each member map_info operations (and by extension mapped member variable) placement in the parent record type. This may need to be extended to an N-D array for nested member mapping. Pull Request: llvm#82851
1 parent 8465779 commit ffced03

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,10 +1308,12 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13081308
TypeAttr:$var_type,
13091309
Optional<OpenMP_PointerLikeType>:$var_ptr_ptr,
13101310
Variadic<OpenMP_PointerLikeType>:$members,
1311+
OptionalAttr<I64ArrayAttr>:$members_index,
13111312
Variadic<DataBoundsType>:$bounds, /* rank-0 to rank-{n-1} */
13121313
OptionalAttr<UI64Attr>:$map_type,
13131314
OptionalAttr<VariableCaptureKindAttr>:$map_capture_type,
1314-
OptionalAttr<StrAttr>:$name);
1315+
OptionalAttr<StrAttr>:$name,
1316+
DefaultValuedAttr<BoolAttr, "false">:$partial_map);
13151317
let results = (outs OpenMP_PointerLikeType:$omp_ptr);
13161318

13171319
let description = [{
@@ -1347,10 +1349,14 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13471349
- `var_type`: The type of the variable to copy.
13481350
- `var_ptr_ptr`: Used when the variable copied is a member of a class, structure
13491351
or derived type and refers to the originating struct.
1350-
- `members`: Used to indicate mapped child members for the current MapInfoOp,
1351-
represented as other MapInfoOp's, utilised in cases where a parent structure
1352-
type and members of the structure type are being mapped at the same time.
1352+
- `members`: Used to indicate mapped child members for the current MapInfoOp,
1353+
represented as other MapInfoOp's, utilised in cases where a parent structure
1354+
type and members of the structure type are being mapped at the same time.
13531355
For example: map(to: parent, parent->member, parent->member2[:10])
1356+
- `members_index`: Used to indicate the ordering of members within the containing
1357+
parent (generally a record type such as a structure, class or derived type),
1358+
e.g. struct {int x, float y, double z}, x would be 0, y would be 1, and z
1359+
would be 2. This aids the mapping
13541360
- `bounds`: Used when copying slices of array's, pointers or pointer members of
13551361
objects (e.g. derived types or classes), indicates the bounds to be copied
13561362
of the variable. When it's an array slice it is in rank order where rank 0
@@ -1361,6 +1367,8 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13611367
- 'map_capture_type': Capture type for the variable e.g. this, byref, byvalue, byvla
13621368
this can affect how the variable is lowered.
13631369
- `name`: Holds the name of variable as specified in user clause (including bounds).
1370+
- `partial_map`: The record type being mapped will not be mapped in its entirety,
1371+
it may be used however, in a mapping to bind it's mapped components together.
13641372
}];
13651373

13661374
let assemblyFormat = [{
@@ -1369,7 +1377,7 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13691377
`var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)`
13701378
| `map_clauses` `(` custom<MapClause>($map_type) `)`
13711379
| `capture` `(` custom<CaptureType>($map_capture_type) `)`
1372-
| `members` `(` $members `:` type($members) `)`
1380+
| `members` `(` $members `:` type($members) `:` $members_index `)`
13731381
| `bounds` `(` $bounds `)`
13741382
) `->` type($omp_ptr) attr-dict
13751383
}];

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,9 @@ static ParseResult parseMapClause(OpAsmParser &parser, IntegerAttr &mapType) {
915915
if (mapTypeMod == "delete")
916916
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
917917

918+
if (mapTypeMod == "ptr_and_obj")
919+
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
920+
918921
return success();
919922
};
920923

@@ -951,6 +954,10 @@ static void printMapClause(OpAsmPrinter &p, Operation *op,
951954
if (mapTypeToBitFlag(mapTypeBits,
952955
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PRESENT))
953956
mapTypeStrs.push_back("present");
957+
if (mapTypeToBitFlag(
958+
mapTypeBits,
959+
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ))
960+
mapTypeStrs.push_back("ptr_and_obj");
954961

955962
// special handling of to/from/tofrom/delete and release/alloc, release +
956963
// alloc are the abscense of one of the other flags, whereas tofrom requires

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,6 @@ func.func @omp_requires_multiple() -> ()
20632063
return
20642064
}
20652065

2066-
// -----
2067-
20682066
// CHECK-LABEL: @opaque_pointers_atomic_rwu
20692067
// CHECK-SAME: (%[[v:.*]]: !llvm.ptr, %[[x:.*]]: !llvm.ptr)
20702068
func.func @opaque_pointers_atomic_rwu(%v: !llvm.ptr, %x: !llvm.ptr) {
@@ -2171,10 +2169,10 @@ func.func @omp_target_update_data (%if_cond : i1, %device : si32, %map1: memref<
21712169
// CHECK-LABEL: omp_targets_is_allocatable
21722170
// CHECK-SAME: (%[[ARG0:.*]]: !llvm.ptr, %[[ARG1:.*]]: !llvm.ptr)
21732171
func.func @omp_targets_is_allocatable(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> () {
2174-
// CHECK: %[[MAP0:.*]] = omp.map_info var_ptr(%[[ARG0]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
2175-
%mapv1 = omp.map_info var_ptr(%arg0 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
2176-
// CHECK: %[[MAP1:.*]] = omp.map_info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP0]] : !llvm.ptr) -> !llvm.ptr {name = ""}
2177-
%mapv2 = omp.map_info var_ptr(%arg1 : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(tofrom) capture(ByRef) members(%mapv1 : !llvm.ptr) -> !llvm.ptr {name = ""}
2172+
// CHECK: %[[MAP0:.*]] = omp.map_info var_ptr(%[[ARG0]] : !llvm.ptr, i32) map_clauses(ptr_and_obj, tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
2173+
%mapv1 = omp.map_info var_ptr(%arg0 : !llvm.ptr, i32) map_clauses(ptr_and_obj, tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
2174+
// CHECK: %[[MAP1:.*]] = omp.map_info var_ptr(%[[ARG1]] : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP0]] : !llvm.ptr : [0]) -> !llvm.ptr {name = ""}
2175+
%mapv2 = omp.map_info var_ptr(%arg1 : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(tofrom) capture(ByRef) members(%mapv1 : !llvm.ptr : [0]) -> !llvm.ptr {name = ""}
21782176
// CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr)
21792177
omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) {
21802178
^bb0(%arg2: !llvm.ptr, %arg3 : !llvm.ptr):
@@ -2229,6 +2227,25 @@ func.func @omp_target_enter_update_exit_data_depend(%a: memref<?xi32>, %b: memre
22292227
}
22302228
// CHECK: omp.target_exit_data map_entries([[MAP2]] : memref<?xi32>) depend(taskdependin -> [[ARG2]] : memref<?xi32>)
22312229
omp.target_exit_data map_entries(%map_c : memref<?xi32>) depend(taskdependin -> %c : memref<?xi32>)
2230+
2231+
return
2232+
}
2233+
2234+
// CHECK-LABEL: omp_map_with_members
2235+
// CHECK-SAME: (%[[ARG0:.*]]: !llvm.ptr, %[[ARG1:.*]]: !llvm.ptr, %[[ARG2:.*]]: !llvm.ptr)
2236+
func.func @omp_map_with_members(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> () {
2237+
// CHECK: %[[MAP0:.*]] = omp.map_info var_ptr(%[[ARG0]] : !llvm.ptr, i32) map_clauses(to) capture(ByRef) -> !llvm.ptr {name = ""}
2238+
%mapv1 = omp.map_info var_ptr(%arg0 : !llvm.ptr, i32) map_clauses(to) capture(ByRef) -> !llvm.ptr {name = ""}
2239+
2240+
// CHECK: %[[MAP1:.*]] = omp.map_info var_ptr(%[[ARG1]] : !llvm.ptr, f32) map_clauses(to) capture(ByRef) -> !llvm.ptr {name = ""}
2241+
%mapv2 = omp.map_info var_ptr(%arg1 : !llvm.ptr, f32) map_clauses(to) capture(ByRef) -> !llvm.ptr {name = ""}
2242+
2243+
// CHECK: %[[MAP2:.*]] = omp.map_info var_ptr(%[[ARG2]] : !llvm.ptr, !llvm.struct<(i32, f32)>) map_clauses(to) capture(ByRef) members(%[[MAP0]], %[[MAP1]] : !llvm.ptr, !llvm.ptr : [0, 1]) -> !llvm.ptr {name = "", partial_map = true}
2244+
%mapv3 = omp.map_info var_ptr(%arg2 : !llvm.ptr, !llvm.struct<(i32, f32)>) map_clauses(to) capture(ByRef) members(%mapv1, %mapv2 : !llvm.ptr, !llvm.ptr : [0, 1]) -> !llvm.ptr {name = "", partial_map = true}
2245+
2246+
// CHECK: omp.target_enter_data map_entries(%[[MAP0]], %[[MAP1]], %[[MAP2]] : !llvm.ptr, !llvm.ptr, !llvm.ptr)
2247+
omp.target_enter_data map_entries(%mapv1, %mapv2, %mapv3 : !llvm.ptr, !llvm.ptr, !llvm.ptr){}
2248+
22322249
return
22332250
}
22342251

0 commit comments

Comments
 (0)