Debian Codegraph @

gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90

raw
1 ! { dg-do compile }
2 ! { dg-additional-options "-foffload=disable -fdump-tree-original -fdump-tree-gimple" }
3
4 program main
5 implicit none
6
7 integer, parameter :: N = 10
8 double precision, parameter :: S = 2.0
9 double precision :: a(N)
10
11 call init (N, a)
12 call f1 (N, a, S)
13 call check (N, a, S)
14
15 call init (N, a)
16 call f2 (N, a, S)
17 call check (N, a, S)
18
19 call init (N, a)
20 call f3 (N, a, S)
21 call check (N, a, S)
22
23 call init (N, a)
24 call f4 (N, a, S)
25 call check (N, a, S)
26
27 call init (N, a)
28 call f5 (N, a, S)
29 call check (N, a, S)
30
31 call init (N, a)
32 call f6 (N, a, S)
33 call check (N, a, S)
34
35 call init (N, a)
36 call f7 (N, a, S)
37 call check (N, a, S)
38
39 call init (N, a)
40 call f8 (N, a, S)
41 call check (N, a, S)
42
43 call init (N, a)
44 call f9 (N, a, S)
45 call check (N, a, S)
46
47 contains
48
49 subroutine init (n, a)
50 implicit none
51 integer :: n
52 double precision :: a(n)
53 integer :: i
54 do i = 1, n
55 a(i) = i
56 end do
57 end subroutine
58
59 subroutine check (n, a, s)
60 implicit none
61 integer :: n
62 double precision :: a(n)
63 double precision :: s
64 integer :: i
65 do i = 1, n
66 if (a(i) /= i * s) error stop
67 end do
68 end subroutine
69
70 ! Check various combinations for enforcing correct ordering of
71 ! construct matches.
72 subroutine f1 (n, a, s)
73 implicit none
74 integer :: n
75 double precision :: a(n)
76 double precision :: s
77 integer :: i
78 !$omp target teams
79 !$omp parallel
80 !$omp metadirective &
81 !$omp & when (construct={target} &
82 !$omp & : do) &
83 !$omp & default (error at(execution) message("f1 match failed"))
84 do i = 1, n
85 a(i) = a(i) * s
86 end do
87 !$omp end parallel
88 !$omp end target teams
89 end subroutine
90
91 subroutine f2 (n, a, s)
92 implicit none
93 integer :: n
94 double precision :: a(n)
95 double precision :: s
96 integer :: i
97 !$omp target teams
98 !$omp parallel
99 !$omp metadirective &
100 !$omp & when (construct={teams, parallel} &
101 !$omp & : do) &
102 !$omp & default (error at(execution) message("f2 match failed"))
103 do i = 1, n
104 a(i) = a(i) * s
105 end do
106 !$omp end parallel
107 !$omp end target teams
108 end subroutine
109
110 subroutine f3 (n, a, s)
111 implicit none
112 integer :: n
113 double precision :: a(n)
114 double precision :: s
115 integer :: i
116 !$omp target teams
117 !$omp parallel
118 !$omp metadirective &
119 !$omp & when (construct={target, teams, parallel} &
120 !$omp & : do) &
121 !$omp & default (error at(execution) message("f3 match failed"))
122 do i = 1, n
123 a(i) = a(i) * s
124 end do
125 !$omp end parallel
126 !$omp end target teams
127 end subroutine
128
129 subroutine f4 (n, a, s)
130 implicit none
131 integer :: n
132 double precision :: a(n)
133 double precision :: s
134 integer :: i
135 !$omp target teams
136 !$omp parallel
137 !$omp metadirective &
138 !$omp & when (construct={target, parallel} &
139 !$omp & : do) &
140 !$omp & default (error at(execution) message("f4 match failed"))
141 do i = 1, n
142 a(i) = a(i) * s
143 end do
144 !$omp end parallel
145 !$omp end target teams
146 end subroutine
147
148 subroutine f5 (n, a, s)
149 implicit none
150 integer :: n
151 double precision :: a(n)
152 double precision :: s
153 integer :: i
154 !$omp target teams
155 !$omp parallel
156 !$omp metadirective &
157 !$omp & when (construct={target, teams} &
158 !$omp & : do) &
159 !$omp & default (error at(execution) message("f5 match failed"))
160 do i = 1, n
161 a(i) = a(i) * s
162 end do
163 !$omp end parallel
164 !$omp end target teams
165 end subroutine
166
167 ! Next batch is for things where the construct doesn't match the context.
168 subroutine f6 (n, a, s)
169 implicit none
170 integer :: n
171 double precision :: a(n)
172 double precision :: s
173 integer :: i
174 !$omp target
175 !$omp teams
176 !$omp metadirective &
177 !$omp & when (construct={parallel} &
178 !$omp & : error at(execution) message("f6 match failed")) &
179 !$omp & default (parallel do)
180 do i = 1, n
181 a(i) = a(i) * s
182 end do
183 !$omp end teams
184 !$omp end target
185 end subroutine
186
187 subroutine f7 (n, a, s)
188 implicit none
189 integer :: n
190 double precision :: a(n)
191 double precision :: s
192 integer :: i
193 !$omp target
194 !$omp teams
195 !$omp metadirective &
196 !$omp & when (construct={target, parallel} &
197 !$omp & : error at(execution) message("f7 match failed")) &
198 !$omp & default (parallel do)
199 do i = 1, n
200 a(i) = a(i) * s
201 end do
202 !$omp end teams
203 !$omp end target
204 end subroutine
205
206 subroutine f8 (n, a, s)
207 implicit none
208 integer :: n
209 double precision :: a(n)
210 double precision :: s
211 integer :: i
212 !$omp target
213 !$omp teams
214 !$omp metadirective &
215 !$omp & when (construct={parallel, target} &
216 !$omp & : error at(execution) message("f8 match failed")) &
217 !$omp & default (parallel do)
218 do i = 1, n
219 a(i) = a(i) * s
220 end do
221 !$omp end teams
222 !$omp end target
223 end subroutine
224
225 ! Next test choosing the best alternative when there are multiple
226 ! matches.
227 subroutine f9 (n, a, s)
228 implicit none
229 integer :: n
230 double precision :: a(n)
231 double precision :: s
232 integer :: i
233 !$omp target teams
234 !$omp parallel
235 !$omp metadirective &
236 !$omp & when (construct={teams, parallel} &
237 !$omp & : error at(execution) message("f9 match incorrect 1")) &
238 !$omp & when (construct={target, teams, parallel} &
239 !$omp & : do) &
240 !$omp & when (construct={target, teams} &
241 !$omp & : error at(execution) message("f9 match incorrect 2")) &
242 !$omp & default (error at(execution) message("f9 match failed"))
243 do i = 1, n
244 a(i) = a(i) * s
245 end do
246 !$omp end parallel
247 !$omp end target teams
248 end subroutine
249
250 end program
251
252 ! Note there are no tests for the matching the extended simd clause
253 ! syntax, which is only useful for "declare variant".
254
255
256 ! After parsing, there should be a runtime error call for each of the
257 ! failure cases, but they should all be optimized away during OMP
258 ! lowering.
259 ! { dg-final { scan-tree-dump-times "__builtin_GOMP_error" 11 "original" } }
260 ! { dg-final { scan-tree-dump-not "__builtin_GOMP_error" "gimple" } }