Skip to content

Commit 01d969a

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent cd1d4d8 commit 01d969a

23 files changed

+890
-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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
end type scalar
20+
21+
type(scalar) :: in
22+
type(scalar) :: out
23+
in%ix = 10
24+
in%rx = 2.0
25+
in%zx = (2, 10)
26+
27+
!$omp target map(from:out) map(to:in)
28+
out = in
29+
!$omp end target
30+
31+
print*, in%ix
32+
print*, in%rx
33+
write (*,*) in%zx
34+
35+
print*, out%ix
36+
print*, out%rx
37+
write (*,*) out%zx
38+
end program main
39+
40+
!CHECK: 10
41+
!CHECK: 2.
42+
!CHECK: (2.,10.)
43+
!CHECK: 10
44+
!CHECK: 2.
45+
!CHECK: (2.,10.)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped to
3+
! target and assigning to individual members
4+
! REQUIRES: flang, amdgcn-amd-amdhsa
5+
! UNSUPPORTED: nvptx64-nvidia-cuda
6+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
7+
! UNSUPPORTED: aarch64-unknown-linux-gnu
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
9+
! UNSUPPORTED: x86_64-pc-linux-gnu
10+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
11+
12+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
13+
program main
14+
type :: scalar
15+
integer(4) :: ix = 0
16+
real(4) :: rx = 0.0
17+
complex(4) :: zx = (0,0)
18+
integer(4) :: array(5)
19+
end type scalar
20+
21+
type(scalar) :: out
22+
type(scalar) :: in
23+
24+
in%ix = 10
25+
in%rx = 2.0
26+
in%zx = (2, 10)
27+
28+
do i = 1, 5
29+
in%array(i) = i
30+
end do
31+
32+
!$omp target map(from:out) map(to:in)
33+
out%ix = in%ix
34+
out%rx = in%rx
35+
out%zx = in%zx
36+
37+
do i = 1, 5
38+
out%array(i) = in%array(i)
39+
end do
40+
!$omp end target
41+
42+
print*, in%ix
43+
print*, in%rx
44+
print*, in%array
45+
write (*,*) in%zx
46+
47+
print*, out%ix
48+
print*, out%rx
49+
print*, out%array
50+
write (*,*) out%zx
51+
end program main
52+
53+
!CHECK: 10
54+
!CHECK: 2.
55+
!CHECK: 1 2 3 4 5
56+
!CHECK: (2.,10.)
57+
!CHECK: 10
58+
!CHECK: 2.
59+
!CHECK: 1 2 3 4 5
60+
!CHECK: (2.,10.)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
! Offloading test checking interaction of an
2+
! implicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
end type scalar
20+
21+
type(scalar) :: in
22+
type(scalar) :: out
23+
in%ix = 10
24+
in%rx = 2.0
25+
in%zx = (2, 10)
26+
27+
!$omp target map(from:out)
28+
out = in
29+
!$omp end target
30+
31+
print*, in%ix
32+
print*, in%rx
33+
write (*,*) in%zx
34+
35+
print*, out%ix
36+
print*, out%rx
37+
write (*,*) out%zx
38+
end program main
39+
40+
!CHECK: 10
41+
!CHECK: 2.
42+
!CHECK: (2.,10.)
43+
!CHECK: 10
44+
!CHECK: 2.
45+
!CHECK: (2.,10.)
46+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type mapping when mapped
3+
! to target and assinging one derived type
4+
! to another
5+
! REQUIRES: flang, amdgcn-amd-amdhsa
6+
! UNSUPPORTED: nvptx64-nvidia-cuda
7+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
8+
! UNSUPPORTED: aarch64-unknown-linux-gnu
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
10+
! UNSUPPORTED: x86_64-pc-linux-gnu
11+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
12+
13+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
14+
program main
15+
type :: scalar
16+
integer(4) :: ix = 0
17+
real(4) :: rx = 0.0
18+
complex(4) :: zx = (0,0)
19+
integer(4) :: array(5)
20+
end type scalar
21+
22+
type(scalar) :: out
23+
type(scalar) :: in
24+
25+
in%ix = 10
26+
in%rx = 2.0
27+
in%zx = (2, 10)
28+
29+
do i = 1, 5
30+
in%array(i) = i
31+
end do
32+
33+
!$omp target
34+
out%ix = in%ix
35+
out%rx = in%rx
36+
out%zx = in%zx
37+
38+
do i = 1, 5
39+
out%array(i) = in%array(i)
40+
end do
41+
!$omp end target
42+
43+
print*, in%ix
44+
print*, in%rx
45+
print*, in%array
46+
write (*,*) in%zx
47+
48+
print*, out%ix
49+
print*, out%rx
50+
print*, out%array
51+
write (*,*) out%zx
52+
end program main
53+
54+
!CHECK: 10
55+
!CHECK: 2.
56+
!CHECK: 1 2 3 4 5
57+
!CHECK: (2.,10.)
58+
!CHECK: 10
59+
!CHECK: 2.
60+
!CHECK: 1 2 3 4 5
61+
!CHECK: (2.,10.)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
! Offloading test checking interaction of an
2+
! explicit derived type member mapping of
3+
! an array with bounds when mapped to
4+
! target using a combination of update,
5+
! enter and exit directives.
6+
! REQUIRES: flang, amdgcn-amd-amdhsa
7+
! UNSUPPORTED: nvptx64-nvidia-cuda
8+
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
9+
! UNSUPPORTED: aarch64-unknown-linux-gnu
10+
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
11+
! UNSUPPORTED: x86_64-pc-linux-gnu
12+
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
13+
14+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
15+
program main
16+
type :: scalar_array
17+
integer(4) :: array(10)
18+
end type scalar_array
19+
20+
type(scalar_array) :: scalar_arr
21+
22+
do I = 1, 10
23+
scalar_arr%array(I) = I + I
24+
end do
25+
26+
!$omp target enter data map(to: scalar_arr%array(3:6))
27+
28+
! overwrite our target data with an update.
29+
do I = 1, 10
30+
scalar_arr%array(I) = 10
31+
end do
32+
33+
!$omp target update to(scalar_arr%array(3:6))
34+
35+
! The compiler/runtime is less friendly about read/write out of
36+
! bounds when using enter and exit, we have to specifically loop
37+
! over the correct range
38+
!$omp target
39+
do i=3,6
40+
scalar_arr%array(i) = scalar_arr%array(i) + i
41+
end do
42+
!$omp end target
43+
44+
!$omp target exit data map(from: scalar_arr%array(3:6))
45+
46+
print*, scalar_arr%array
47+
end program
48+
49+
!CHECK: 10 10 13 14 15 16 10 10 10 10

0 commit comments

Comments
 (0)