Debian Codegraph @

libgomp/testsuite/libgomp.fortran/defaultmap-8.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fdump-tree-gimple" }
3 !
4 ! PR fortran/92568
5 !
6 program main
7 implicit none
8 integer :: xa1, xa2, xp1, xp2, xat1, xat2, xt1, xt2, xi1, xi2
9 allocatable :: xa1, xa2, xat1, xat2
10 pointer :: xp1, xp2
11
12 allocate (xa1, xa2, xat1, xat2, xp1, xp2)
13
14 call foo (xa1, xa2, xp1, xp2, xat1, xat2, xt1, xt2, xi1, xi2)
15 call foo2 (xa1, xa2, xp1, xp2, xat1, xat2, xt1, xt2, xi1, xi2)
16 call foo3 (xa1, xa2, xp1, xp2, xat1, xat2, xt1, xt2, xi1, xi2)
17 call bar (xa1, xa2, xp1, xp2, xat1, xat2, xt1, xt2, xi1, xi2)
18
19 deallocate (xa1, xa2, xat1, xat2, xp1, xp2)
20 contains
21 ! Implicit mapping
22 subroutine foo (ia1, ia2, ip1, ip2, iat1, iat2, it1, it2, ii1, ii2)
23 implicit none
24 integer :: ia1, ia2, ia3, ip1, ip2, ip3, iat1, iat2, iat3, it1, it2, it3, ii1, ii2, ii3
25 allocatable :: ia1, ia2, ia3, iat1, iat2, iat3
26 pointer :: ip1, ip2, ip3
27 target :: iat1, iat2, iat3, it1, it2, it3
28 optional :: ia1, ip1, iat1, it1, ii1
29
30 allocate(ia3, iat3, ip3)
31
32 ia1 = 2; ia2 = 2; ia3 = 2; ip1 = 2; ip2 = 2; ip3 = 2;
33 iat1 = 2; iat2 = 2; iat3 = 2; it1 = 2; it2 = 2; it3 = 2
34 ii1 = 2; ii2 = 2; ii3 = 2
35
36 ! Implicitly, scalars are 'firstprivate' except
37 ! if target, allocatable, pointer they are always tofrom.
38 !$omp target
39 if (ia1 /= 2) stop 1
40 if (ia2 /= 2) stop 2
41 if (ia3 /= 2) stop 3
42 if (ip1 /= 2) stop 4
43 if (ip2 /= 2) stop 5
44 if (ip3 /= 2) stop 6
45 if (iat1 /= 2) stop 7
46 if (iat2 /= 2) stop 8
47 if (iat3 /= 2) stop 9
48 if (it1 /= 2) stop 10
49 if (it2 /= 2) stop 11
50 if (it3 /= 2) stop 12
51 if (ii1 /= 2) stop 13
52 if (ii2 /= 2) stop 14
53 if (ii3 /= 2) stop 15
54
55 ia1 = 1; ia2 = 1; ia3 = 1; ip1 = 1; ip2 = 1; ip3 = 1;
56 iat1 = 1; iat2 = 1; iat3 = 1; it1 = 1; it2 = 1; it3 = 1
57 ii1 = 1; ii2 = 1; ii3 = 1
58 !$omp end target
59
60 ! (target,allocatable,pointer) -> tofrom
61 if (ia1 /= 1) stop 16
62 if (ia2 /= 1) stop 17
63 if (ia3 /= 1) stop 18
64 if (ip1 /= 1) stop 19
65 if (ip2 /= 1) stop 20
66 if (ip3 /= 1) stop 21
67 if (iat1 /= 1) stop 22
68 if (iat2 /= 1) stop 23
69 if (iat3 /= 1) stop 24
70 if (it1 /= 1) stop 25
71 if (it2 /= 1) stop 26
72 if (it3 /= 1) stop 27
73 ! non-(target,allocatable,pointer) -> firstprivate
74 !if (ii1 /= 2) stop 28 ! FIXME: optional scalar wrongly mapped as tofrom, PR fortran/100991
75 if (ii2 /= 2) stop 29
76 if (ii3 /= 2) stop 30
77
78 deallocate(ia3, iat3, ip3)
79 end
80
81 ! Implicit mapping likewise even though there is defaultmap
82 subroutine foo2 (ia1, ia2, ip1, ip2, iat1, iat2, it1, it2, ii1, ii2)
83 implicit none
84 integer :: ia1, ia2, ia3, ip1, ip2, ip3, iat1, iat2, iat3, it1, it2, it3, ii1, ii2, ii3
85 allocatable :: ia1, ia2, ia3, iat1, iat2, iat3
86 pointer :: ip1, ip2, ip3
87 target :: iat1, iat2, iat3, it1, it2, it3
88 optional :: ia1, ip1, iat1, it1, ii1
89
90 allocate(ia3, iat3, ip3)
91
92 ia1 = 2; ia2 = 2; ia3 = 2; ip1 = 2; ip2 = 2; ip3 = 2;
93 iat1 = 2; iat2 = 2; iat3 = 2; it1 = 2; it2 = 2; it3 = 2
94 ii1 = 2; ii2 = 2; ii3 = 2
95
96 ! Implicitly, scalars are 'firstprivate' except
97 ! if target, allocatable, pointer they are always tofrom.
98 !$omp target defaultmap(default)
99 if (ia1 /= 2) stop 31
100 if (ia2 /= 2) stop 32
101 if (ia3 /= 2) stop 33
102 if (ip1 /= 2) stop 34
103 if (ip2 /= 2) stop 35
104 if (ip3 /= 2) stop 36
105 if (iat1 /= 2) stop 37
106 if (iat2 /= 2) stop 38
107 if (iat3 /= 2) stop 39
108 if (it1 /= 2) stop 40
109 if (it2 /= 2) stop 41
110 if (it3 /= 2) stop 42
111 if (ii1 /= 2) stop 43
112 if (ii2 /= 2) stop 44
113 if (ii3 /= 2) stop 45
114
115 ia1 = 1; ia2 = 1; ia3 = 1; ip1 = 1; ip2 = 1; ip3 = 1;
116 iat1 = 1; iat2 = 1; iat3 = 1; it1 = 1; it2 = 1; it3 = 1
117 ii1 = 1; ii2 = 1; ii3 = 1
118 !$omp end target
119
120 ! (target,allocatable,pointer) -> tofrom
121 if (ia1 /= 1) stop 46
122 if (ia2 /= 1) stop 47
123 if (ia3 /= 1) stop 48
124 if (ip1 /= 1) stop 49
125 if (ip2 /= 1) stop 50
126 if (ip3 /= 1) stop 51
127 if (iat1 /= 1) stop 52
128 if (iat2 /= 1) stop 53
129 if (iat3 /= 1) stop 54
130 if (it1 /= 1) stop 55
131 if (it2 /= 1) stop 56
132 if (it3 /= 1) stop 57
133 ! non-(target,allocatable,pointer) -> firstprivate
134 !if (ii1 /= 2) stop 58 ! FIXME: optional scalar wrongly mapped as tofrom, PR fortran/100991
135 if (ii2 /= 2) stop 59
136 if (ii3 /= 2) stop 60
137
138 deallocate(ia3, iat3, ip3)
139 end
140
141 ! Implicit mapping likewise even though there is defaultmap
142 subroutine foo3 (ia1, ia2, ip1, ip2, iat1, iat2, it1, it2, ii1, ii2)
143 implicit none
144 integer :: ia1, ia2, ia3, ip1, ip2, ip3, iat1, iat2, iat3, it1, it2, it3, ii1, ii2, ii3
145 allocatable :: ia1, ia2, ia3, iat1, iat2, iat3
146 pointer :: ip1, ip2, ip3
147 target :: iat1, iat2, iat3, it1, it2, it3
148 optional :: ia1, ip1, iat1, it1, ii1
149
150 allocate(ia3, iat3, ip3)
151
152 ia1 = 2; ia2 = 2; ia3 = 2; ip1 = 2; ip2 = 2; ip3 = 2;
153 iat1 = 2; iat2 = 2; iat3 = 2; it1 = 2; it2 = 2; it3 = 2
154 ii1 = 2; ii2 = 2; ii3 = 2
155
156 ! Implicitly, scalars are 'firstprivate' except
157 ! if target, allocatable, pointer they are always tofrom.
158 !$omp target defaultmap(none:aggregate)
159 if (ia1 /= 2) stop 61
160 if (ia2 /= 2) stop 62
161 if (ia3 /= 2) stop 63
162 if (ip1 /= 2) stop 64
163 if (ip2 /= 2) stop 65
164 if (ip3 /= 2) stop 66
165 if (iat1 /= 2) stop 67
166 if (iat2 /= 2) stop 68
167 if (iat3 /= 2) stop 69
168 if (it1 /= 2) stop 70
169 if (it2 /= 2) stop 71
170 if (it3 /= 2) stop 72
171 if (ii1 /= 2) stop 73
172 if (ii2 /= 2) stop 74
173 if (ii3 /= 2) stop 75
174
175 ia1 = 1; ia2 = 1; ia3 = 1; ip1 = 1; ip2 = 1; ip3 = 1;
176 iat1 = 1; iat2 = 1; iat3 = 1; it1 = 1; it2 = 1; it3 = 1
177 ii1 = 1; ii2 = 1; ii3 = 1
178 !$omp end target
179
180 ! (target,allocatable,pointer) -> tofrom
181 if (ia1 /= 1) stop 76
182 if (ia2 /= 1) stop 77
183 if (ia3 /= 1) stop 78
184 if (ip1 /= 1) stop 79
185 if (ip2 /= 1) stop 80
186 if (ip3 /= 1) stop 81
187 if (iat1 /= 1) stop 82
188 if (iat2 /= 1) stop 83
189 if (iat3 /= 1) stop 84
190 if (it1 /= 1) stop 85
191 if (it2 /= 1) stop 86
192 if (it3 /= 1) stop 87
193 ! non-(target,allocatable,pointer) -> firstprivate
194 !if (ii1 /= 2) stop 88 ! FIXME: optional scalar wrongly mapped as tofrom, PR fortran/100991
195 if (ii2 /= 2) stop 89
196 if (ii3 /= 2) stop 90
197
198 deallocate(ia3, iat3, ip3)
199 end
200
201 subroutine bar (ea1, ea2, ep1, ep2, eat1, eat2, et1, et2, ei1, ei2)
202 implicit none
203 integer :: ea1, ea2, ea3, ep1, ep2, ep3, eat1, eat2, eat3, et1, et2, et3, ei1, ei2, ei3
204 allocatable :: ea1, ea2, ea3, eat1, eat2, eat3
205 pointer :: ep1, ep2, ep3
206 target :: eat1, eat2, eat3, et1, et2, et3
207 optional :: ea1, ep1, eat1, et1, ei1
208 logical :: shared_memory
209
210 allocate(ea3, eat3, ep3)
211
212 ea1 = 2; ea2 = 2; ea3 = 2; ep1 = 2; ep2 = 2; ep3 = 2;
213 eat1 = 2; eat2 = 2; eat3 = 2; et1 = 2; et2 = 2; et3 = 2
214 ei1 = 2; ei2 = 2; ei3 = 2
215
216 shared_memory = .false.
217 !$omp target map(to: shared_memory)
218 shared_memory = .true.
219 !$omp end target
220
221 ! While here 'scalar' implies nonallocatable/nonpointer and
222 ! the target attribute plays no role.
223 !$omp target defaultmap(tofrom:scalar) defaultmap(firstprivate:allocatable) &
224 !$omp& defaultmap(none:aggregate) defaultmap(firstprivate:pointer) &
225 !$omp& map(always, to: shared_memory)
226 if (shared_memory) then
227 ! Due to fortran/90742 this fails when doing non-shared memory offloading
228 if (ea1 /= 2) stop 91
229 if (ea2 /= 2) stop 92
230 if (ea3 /= 2) stop 93
231 if (ep1 /= 2) stop 94
232 if (ep2 /= 2) stop 95
233 if (ep3 /= 2) stop 96
234 if (eat1 /= 2) stop 97
235 if (eat2 /= 2) stop 98
236 if (eat3 /= 2) stop 99
237 end if
238 if (et1 /= 2) stop 100
239 if (et2 /= 2) stop 101
240 if (et3 /= 2) stop 102
241 if (ei1 /= 2) stop 103
242 if (ei2 /= 2) stop 104
243 if (ei3 /= 2) stop 105
244 ep1 => null(); ep2 => null(); ep3 => null()
245 if (shared_memory) then
246 ! Due to fortran/90742 this fails when doing non-shared memory offloading
247 ea1 = 1; ea2 = 1; ea3 = 1
248 eat1 = 1; eat2 = 1; eat3 = 1
249 end if
250 et1 = 1; et2 = 1; et3 = 1
251 ei1 = 1; ei2 = 1; ei3 = 1
252 !$omp end target
253 ! (allocatable,pointer) -> firstprivate
254
255 ! FIXME: allocatables not properly privatized, cf. PR fortran/90742
256
257 ! if (ea1 /= 2) stop 106
258 ! if (ea2 /= 2) stop 107
259 ! if (ea3 /= 2) stop 108
260 ! if (eat1 /= 2) stop 112
261 ! if (eat2 /= 2) stop 113
262 ! if (eat3 /= 2) stop 114
263 if (ep1 /= 2) stop 109
264 if (ep2 /= 2) stop 110
265 if (ep3 /= 2) stop 111
266 ! (scalar) -> tofrom
267 !if (et1 /= 1) stop 115 ! FIXME: optional scalar wrongly mapped as 'firstprivate', PR fortran/100991
268 if (et2 /= 1) stop 116
269 if (et3 /= 1) stop 117
270 !if (ei1 /= 1) stop 118 ! FIXME: optional scalar wrongly mapped as 'firstprivate', PR fortran/100991
271 if (ei2 /= 1) stop 119
272 if (ei3 /= 1) stop 120
273
274 deallocate(ea3, eat3, ep3)
275 end
276
277 end
278
279 ! FIXME/xfail: Optional scalars wrongly classified, PR fortran/100991
280 ! { dg-final { scan-tree-dump-times "firstprivate\\(ii1\\)" 3 "gimple" { xfail *-*-* } } }
281 ! { dg-final { scan-tree-dump-not "firstprivate\\(et1\\)" "gimple" { xfail *-*-* } } }
282 ! { dg-final { scan-tree-dump-not "firstprivate\\(ei1\\)" "gimple" { xfail *-*-* } } }
283
284 ! { dg-final { scan-tree-dump-times "firstprivate\\(ea1\\)" 1 "gimple" } }
285 ! { dg-final { scan-tree-dump-times "firstprivate\\(ea2\\)" 1 "gimple" } }
286 ! { dg-final { scan-tree-dump-times "firstprivate\\(ea3\\)" 1 "gimple" } }
287 ! { dg-final { scan-tree-dump-times "firstprivate\\(eat1\\)" 1 "gimple" } }
288 ! { dg-final { scan-tree-dump-times "firstprivate\\(eat2\\)" 1 "gimple" } }
289 ! { dg-final { scan-tree-dump-times "firstprivate\\(eat3\\)" 1 "gimple" } }
290 ! { dg-final { scan-tree-dump-times "firstprivate\\(ep1\\)" 1 "gimple" } }
291 ! { dg-final { scan-tree-dump-times "firstprivate\\(ep2\\)" 1 "gimple" } }
292 ! { dg-final { scan-tree-dump-times "firstprivate\\(ep3\\)" 1 "gimple" } }