Skip to content

Commit 14297f4

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 008a334 commit 14297f4

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,12 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
12981298
TypeAttr:$var_type,
12991299
Optional<OpenMP_PointerLikeType>:$var_ptr_ptr,
13001300
Variadic<OpenMP_PointerLikeType>:$members,
1301+
OptionalAttr<I64ArrayAttr>:$members_index,
13011302
Variadic<DataBoundsType>:$bounds, /* rank-0 to rank-{n-1} */
13021303
OptionalAttr<UI64Attr>:$map_type,
13031304
OptionalAttr<VariableCaptureKindAttr>:$map_capture_type,
1304-
OptionalAttr<StrAttr>:$name);
1305+
OptionalAttr<StrAttr>:$name,
1306+
DefaultValuedAttr<BoolAttr, "false">:$partial_map);
13051307
let results = (outs OpenMP_PointerLikeType:$omp_ptr);
13061308

13071309
let description = [{
@@ -1337,10 +1339,14 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13371339
- `var_type`: The type of the variable to copy.
13381340
- `var_ptr_ptr`: Used when the variable copied is a member of a class, structure
13391341
or derived type and refers to the originating struct.
1340-
- `members`: Used to indicate mapped child members for the current MapInfoOp,
1342+
- `members`: Used to indicate mapped child members for the current MapInfoOp,
13411343
represented as other MapInfoOp's, utilised in cases where a parent structure
13421344
type and members of the structure type are being mapped at the same time.
1343-
For example: map(to: parent, parent->member, parent->member2[:10])
1345+
For example: map(to: parent, parent->member, parent->member2[:10])
1346+
- `members_index`: Used to indicate the ordering of members within the containing
1347+
parent (generally a record type such as a structure, class or derived type),
1348+
e.g. struct {int x, float y, double z}, x would be 0, y would be 1, and z
1349+
would be 2. This aids the mapping
13441350
- `bounds`: Used when copying slices of array's, pointers or pointer members of
13451351
objects (e.g. derived types or classes), indicates the bounds to be copied
13461352
of the variable. When it's an array slice it is in rank order where rank 0
@@ -1351,6 +1357,8 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13511357
- 'map_capture_type': Capture type for the variable e.g. this, byref, byvalue, byvla
13521358
this can affect how the variable is lowered.
13531359
- `name`: Holds the name of variable as specified in user clause (including bounds).
1360+
- `partial_map`: The record type being mapped will not be mapped in its entirety,
1361+
it may be used however, in a mapping to bind it's mapped components together.
13541362
}];
13551363

13561364
let assemblyFormat = [{
@@ -1359,7 +1367,7 @@ def MapInfoOp : OpenMP_Op<"map_info", [AttrSizedOperandSegments]> {
13591367
`var_ptr_ptr` `(` $var_ptr_ptr `:` type($var_ptr_ptr) `)`
13601368
| `map_clauses` `(` custom<MapClause>($map_type) `)`
13611369
| `capture` `(` custom<CaptureType>($map_capture_type) `)`
1362-
| `members` `(` $members `:` type($members) `)`
1370+
| `members` `(` $members `:` type($members) `:` $members_index `)`
13631371
| `bounds` `(` $bounds `)`
13641372
) `->` type($omp_ptr) attr-dict
13651373
}];

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)