Branch data Line data Source code
1 : : /* OpenMP directive translation -- generate GCC trees from gfc_code.
2 : : Copyright (C) 2005-2025 Free Software Foundation, Inc.
3 : : Contributed by Jakub Jelinek <jakub@redhat.com>
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : :
22 : : #include "config.h"
23 : : #include "system.h"
24 : : #include "coretypes.h"
25 : : #include "options.h"
26 : : #include "tree.h"
27 : : #include "gfortran.h"
28 : : #include "basic-block.h"
29 : : #include "tree-ssa.h"
30 : : #include "function.h"
31 : : #include "gimple.h"
32 : : #include "gimple-expr.h"
33 : : #include "trans.h"
34 : : #include "stringpool.h"
35 : : #include "fold-const.h"
36 : : #include "gimplify.h" /* For create_tmp_var_raw. */
37 : : #include "trans-stmt.h"
38 : : #include "trans-types.h"
39 : : #include "trans-array.h"
40 : : #include "trans-const.h"
41 : : #include "arith.h"
42 : : #include "constructor.h"
43 : : #include "gomp-constants.h"
44 : : #include "omp-general.h"
45 : : #include "omp-low.h"
46 : : #include "memmodel.h" /* For MEMMODEL_ enums. */
47 : : #include "dependency.h"
48 : : #include "gimple-iterator.h" /* For gsi_iterator_update. */
49 : : #include "gimplify-me.h" /* For force_gimple_operand. */
50 : :
51 : : #undef GCC_DIAG_STYLE
52 : : #define GCC_DIAG_STYLE __gcc_tdiag__
53 : : #include "diagnostic-core.h"
54 : : #undef GCC_DIAG_STYLE
55 : : #define GCC_DIAG_STYLE __gcc_gfc__
56 : : #include "attribs.h"
57 : : #include "function.h"
58 : :
59 : : int ompws_flags;
60 : :
61 : : /* True if OpenMP should regard this DECL as being a scalar which has Fortran's
62 : : allocatable or pointer attribute. */
63 : :
64 : : bool
65 : 5944 : gfc_omp_is_allocatable_or_ptr (const_tree decl)
66 : : {
67 : 5944 : return (DECL_P (decl)
68 : 5944 : && (GFC_DECL_GET_SCALAR_POINTER (decl)
69 : 4213 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)));
70 : : }
71 : :
72 : : /* True if the argument is an optional argument; except that false is also
73 : : returned for arguments with the value attribute (nonpointers) and for
74 : : assumed-shape variables (decl is a local variable containing arg->data).
75 : : Note that for 'procedure(), optional' the value false is used as that's
76 : : always a pointer and no additional indirection is used.
77 : : Note that pvoid_type_node is for 'type(c_ptr), value' (and c_funloc). */
78 : :
79 : : static bool
80 : 46168 : gfc_omp_is_optional_argument (const_tree decl)
81 : : {
82 : : /* Note: VAR_DECL can occur with BIND(C) and array descriptors. */
83 : 30381 : return ((TREE_CODE (decl) == PARM_DECL || VAR_P (decl))
84 : 46168 : && DECL_LANG_SPECIFIC (decl)
85 : 20861 : && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
86 : 20677 : && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
87 : 20442 : && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != FUNCTION_TYPE
88 : 66585 : && GFC_DECL_OPTIONAL_ARGUMENT (decl));
89 : : }
90 : :
91 : : /* Check whether this DECL belongs to a Fortran optional argument.
92 : : With 'for_present_check' set to false, decls which are optional parameters
93 : : themselves are returned as tree - or a NULL_TREE otherwise. Those decls are
94 : : always pointers. With 'for_present_check' set to true, the decl for checking
95 : : whether an argument is present is returned; for arguments with value
96 : : attribute this is the hidden argument and of BOOLEAN_TYPE. If the decl is
97 : : unrelated to optional arguments, NULL_TREE is returned. */
98 : :
99 : : tree
100 : 22007 : gfc_omp_check_optional_argument (tree decl, bool for_present_check)
101 : : {
102 : 22007 : if (!for_present_check)
103 : 2172 : return gfc_omp_is_optional_argument (decl) ? decl : NULL_TREE;
104 : :
105 : 19835 : if (!DECL_LANG_SPECIFIC (decl))
106 : : return NULL_TREE;
107 : :
108 : 5384 : tree orig_decl = decl;
109 : :
110 : : /* For assumed-shape arrays, a local decl with arg->data is used. */
111 : 5384 : if (TREE_CODE (decl) != PARM_DECL
112 : 5384 : && (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
113 : 1980 : || GFC_ARRAY_TYPE_P (TREE_TYPE (decl))))
114 : 744 : decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
115 : :
116 : : /* Note: With BIND(C), array descriptors are converted to a VAR_DECL. */
117 : 5384 : if (decl == NULL_TREE
118 : 5247 : || (TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != VAR_DECL)
119 : 5247 : || !DECL_LANG_SPECIFIC (decl)
120 : 10227 : || !GFC_DECL_OPTIONAL_ARGUMENT (decl))
121 : : return NULL_TREE;
122 : :
123 : : /* Scalars with VALUE attribute which are passed by value use a hidden
124 : : argument to denote the present status. They are passed as nonpointer type
125 : : with one exception: 'type(c_ptr), value' as 'void*'. */
126 : : /* Cf. trans-expr.cc's gfc_conv_expr_present. */
127 : 2834 : if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
128 : 2834 : || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
129 : : {
130 : 205 : char name[GFC_MAX_SYMBOL_LEN + 2];
131 : 205 : tree tree_name;
132 : :
133 : 205 : name[0] = '.';
134 : 205 : strcpy (&name[1], IDENTIFIER_POINTER (DECL_NAME (decl)));
135 : 205 : tree_name = get_identifier (name);
136 : :
137 : : /* Walk function argument list to find the hidden arg. */
138 : 205 : decl = DECL_ARGUMENTS (DECL_CONTEXT (decl));
139 : 1437 : for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
140 : 1437 : if (DECL_NAME (decl) == tree_name
141 : 1437 : && DECL_ARTIFICIAL (decl))
142 : : break;
143 : :
144 : 205 : gcc_assert (decl);
145 : 205 : return decl;
146 : : }
147 : :
148 : 2629 : return fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
149 : 2629 : orig_decl, null_pointer_node);
150 : : }
151 : :
152 : :
153 : : /* Returns tree with NULL if it is not an array descriptor and with the tree to
154 : : access the 'data' component otherwise. With type_only = true, it returns the
155 : : TREE_TYPE without creating a new tree. */
156 : :
157 : : tree
158 : 18698 : gfc_omp_array_data (tree decl, bool type_only)
159 : : {
160 : 18698 : tree type = TREE_TYPE (decl);
161 : :
162 : 18698 : if (POINTER_TYPE_P (type))
163 : 10175 : type = TREE_TYPE (type);
164 : :
165 : 18698 : if (!GFC_DESCRIPTOR_TYPE_P (type))
166 : : return NULL_TREE;
167 : :
168 : 4548 : if (type_only)
169 : 3328 : return GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
170 : :
171 : 1220 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
172 : 414 : decl = build_fold_indirect_ref (decl);
173 : :
174 : 1220 : decl = gfc_conv_descriptor_data_get (decl);
175 : 1220 : STRIP_NOPS (decl);
176 : 1220 : return decl;
177 : : }
178 : :
179 : : /* Return the byte-size of the passed array descriptor. */
180 : :
181 : : tree
182 : 18 : gfc_omp_array_size (tree decl, gimple_seq *pre_p)
183 : : {
184 : 18 : stmtblock_t block;
185 : 18 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
186 : 18 : decl = build_fold_indirect_ref (decl);
187 : 18 : tree type = TREE_TYPE (decl);
188 : 18 : gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
189 : 18 : bool allocatable = (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
190 : 2 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
191 : 18 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT);
192 : 18 : gfc_init_block (&block);
193 : 54 : tree size = gfc_full_array_size (&block, decl,
194 : 18 : GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)));
195 : 18 : size = fold_convert (size_type_node, size);
196 : 18 : tree elemsz = gfc_get_element_type (TREE_TYPE (decl));
197 : 18 : if (TREE_CODE (elemsz) == ARRAY_TYPE && TYPE_STRING_FLAG (elemsz))
198 : 6 : elemsz = gfc_conv_descriptor_elem_len (decl);
199 : : else
200 : 12 : elemsz = TYPE_SIZE_UNIT (elemsz);
201 : 18 : size = fold_build2 (MULT_EXPR, size_type_node, size, elemsz);
202 : 18 : if (!allocatable)
203 : 0 : gimplify_and_add (gfc_finish_block (&block), pre_p);
204 : : else
205 : : {
206 : 18 : tree var = create_tmp_var (size_type_node);
207 : 18 : gfc_add_expr_to_block (&block, build2 (MODIFY_EXPR, sizetype, var, size));
208 : 18 : tree tmp = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
209 : : gfc_conv_descriptor_data_get (decl),
210 : : null_pointer_node);
211 : 18 : tmp = build3_loc (input_location, COND_EXPR, void_type_node, tmp,
212 : : gfc_finish_block (&block),
213 : : build2 (MODIFY_EXPR, sizetype, var, size_zero_node));
214 : 18 : gimplify_and_add (tmp, pre_p);
215 : 18 : size = var;
216 : : }
217 : 18 : return size;
218 : : }
219 : :
220 : :
221 : : /* True if OpenMP should privatize what this DECL points to rather
222 : : than the DECL itself. */
223 : :
224 : : bool
225 : 456897 : gfc_omp_privatize_by_reference (const_tree decl)
226 : : {
227 : 456897 : tree type = TREE_TYPE (decl);
228 : :
229 : 456897 : if (TREE_CODE (type) == REFERENCE_TYPE
230 : 456897 : && (!DECL_ARTIFICIAL (decl) || TREE_CODE (decl) == PARM_DECL))
231 : : return true;
232 : :
233 : 433629 : if (TREE_CODE (type) == POINTER_TYPE
234 : 433629 : && gfc_omp_is_optional_argument (decl))
235 : : return true;
236 : :
237 : 424543 : if (TREE_CODE (type) == POINTER_TYPE)
238 : : {
239 : 32743 : while (TREE_CODE (decl) == COMPONENT_REF)
240 : 0 : decl = TREE_OPERAND (decl, 1);
241 : :
242 : : /* Array POINTER/ALLOCATABLE have aggregate types, all user variables
243 : : that have POINTER_TYPE type and aren't scalar pointers, scalar
244 : : allocatables, Cray pointees or C pointers are supposed to be
245 : : privatized by reference. */
246 : 32743 : if (GFC_DECL_GET_SCALAR_POINTER (decl)
247 : 31228 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
248 : 28836 : || GFC_DECL_CRAY_POINTEE (decl)
249 : 28830 : || GFC_DECL_ASSOCIATE_VAR_P (decl)
250 : 38250 : || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
251 : : return false;
252 : :
253 : 20859 : if (!DECL_ARTIFICIAL (decl)
254 : 20859 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
255 : : return true;
256 : :
257 : : /* Some arrays are expanded as DECL_ARTIFICIAL pointers
258 : : by the frontend. */
259 : 13486 : if (DECL_LANG_SPECIFIC (decl)
260 : 13486 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
261 : : return true;
262 : : }
263 : :
264 : : return false;
265 : : }
266 : :
267 : : /* OMP_CLAUSE_DEFAULT_UNSPECIFIED unless OpenMP sharing attribute
268 : : of DECL is predetermined. */
269 : :
270 : : enum omp_clause_default_kind
271 : 8421 : gfc_omp_predetermined_sharing (tree decl)
272 : : {
273 : : /* Associate names preserve the association established during ASSOCIATE.
274 : : As they are implemented either as pointers to the selector or array
275 : : descriptor and shouldn't really change in the ASSOCIATE region,
276 : : this decl can be either shared or firstprivate. If it is a pointer,
277 : : use firstprivate, as it is cheaper that way, otherwise make it shared. */
278 : 8421 : if (GFC_DECL_ASSOCIATE_VAR_P (decl))
279 : : {
280 : 45 : if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
281 : : return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
282 : : else
283 : 18 : return OMP_CLAUSE_DEFAULT_SHARED;
284 : : }
285 : :
286 : 8376 : if (DECL_ARTIFICIAL (decl)
287 : 1580 : && ! GFC_DECL_RESULT (decl)
288 : 9932 : && ! (DECL_LANG_SPECIFIC (decl)
289 : 375 : && GFC_DECL_SAVED_DESCRIPTOR (decl)))
290 : : return OMP_CLAUSE_DEFAULT_SHARED;
291 : :
292 : : /* Cray pointees shouldn't be listed in any clauses and should be
293 : : gimplified to dereference of the corresponding Cray pointer.
294 : : Make them all private, so that they are emitted in the debug
295 : : information. */
296 : 7146 : if (GFC_DECL_CRAY_POINTEE (decl))
297 : : return OMP_CLAUSE_DEFAULT_PRIVATE;
298 : :
299 : : /* Assumed-size arrays are predetermined shared. */
300 : 7110 : if (TREE_CODE (decl) == PARM_DECL
301 : 1952 : && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
302 : 711 : && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
303 : 7821 : && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
304 : : GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
305 : : == NULL)
306 : : return OMP_CLAUSE_DEFAULT_SHARED;
307 : :
308 : : /* Dummy procedures aren't considered variables by OpenMP, thus are
309 : : disallowed in OpenMP clauses. They are represented as PARM_DECLs
310 : : in the middle-end, so return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE here
311 : : to avoid complaining about their uses with default(none). */
312 : 7042 : if (TREE_CODE (decl) == PARM_DECL
313 : 1884 : && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
314 : 7822 : && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
315 : : return OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
316 : :
317 : : /* COMMON and EQUIVALENCE decls are shared. They
318 : : are only referenced through DECL_VALUE_EXPR of the variables
319 : : contained in them. If those are privatized, they will not be
320 : : gimplified to the COMMON or EQUIVALENCE decls. */
321 : 7026 : if (GFC_DECL_COMMON_OR_EQUIV (decl) && ! DECL_HAS_VALUE_EXPR_P (decl))
322 : : return OMP_CLAUSE_DEFAULT_SHARED;
323 : :
324 : 6997 : if (GFC_DECL_RESULT (decl) && ! DECL_HAS_VALUE_EXPR_P (decl))
325 : : return OMP_CLAUSE_DEFAULT_SHARED;
326 : :
327 : : /* These are either array or derived parameters, or vtables.
328 : : In the former cases, the OpenMP standard doesn't consider them to be
329 : : variables at all (they can't be redefined), but they can nevertheless appear
330 : : in parallel/task regions and for default(none) purposes treat them as shared.
331 : : For vtables likely the same handling is desirable. */
332 : 5105 : if (VAR_P (decl) && TREE_READONLY (decl)
333 : 6976 : && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
334 : 3 : return OMP_CLAUSE_DEFAULT_SHARED;
335 : :
336 : : return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
337 : : }
338 : :
339 : :
340 : : /* OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED unless OpenMP mapping attribute
341 : : of DECL is predetermined. */
342 : :
343 : : enum omp_clause_defaultmap_kind
344 : 3894 : gfc_omp_predetermined_mapping (tree decl)
345 : : {
346 : 3894 : if (DECL_ARTIFICIAL (decl)
347 : 878 : && ! GFC_DECL_RESULT (decl)
348 : 4766 : && ! (DECL_LANG_SPECIFIC (decl)
349 : 72 : && GFC_DECL_SAVED_DESCRIPTOR (decl)))
350 : : return OMP_CLAUSE_DEFAULTMAP_TO;
351 : :
352 : : /* Dummy procedures aren't considered variables by OpenMP, thus are
353 : : disallowed in OpenMP clauses. They are represented as PARM_DECLs
354 : : in the middle-end, so return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE here
355 : : to avoid complaining about their uses with defaultmap(none). */
356 : 3065 : if (TREE_CODE (decl) == PARM_DECL
357 : 1809 : && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
358 : 3442 : && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
359 : : return OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
360 : :
361 : : /* These are either array or derived parameters, or vtables. */
362 : 1256 : if (VAR_P (decl) && TREE_READONLY (decl)
363 : 3058 : && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
364 : 0 : return OMP_CLAUSE_DEFAULTMAP_TO;
365 : :
366 : : return OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
367 : : }
368 : :
369 : :
370 : : /* Return decl that should be used when reporting DEFAULT(NONE)
371 : : diagnostics. */
372 : :
373 : : tree
374 : 128 : gfc_omp_report_decl (tree decl)
375 : : {
376 : 128 : if (DECL_ARTIFICIAL (decl)
377 : 3 : && DECL_LANG_SPECIFIC (decl)
378 : 131 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
379 : 3 : return GFC_DECL_SAVED_DESCRIPTOR (decl);
380 : :
381 : : return decl;
382 : : }
383 : :
384 : : /* Return true if TYPE has any allocatable components;
385 : : if ptr_ok, the decl itself is permitted to have the POINTER attribute.
386 : : if shallow_alloc_only, returns only true if any of the fields is an
387 : : allocatable; called with true by gfc_omp_replace_alloc_by_to_mapping. */
388 : :
389 : : static bool
390 : 121030 : gfc_has_alloc_comps (tree type, tree decl, bool ptr_ok,
391 : : bool shallow_alloc_only=false)
392 : : {
393 : 121030 : tree field, ftype;
394 : :
395 : 121030 : if (POINTER_TYPE_P (type))
396 : : {
397 : 3458 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
398 : 3458 : || (ptr_ok && GFC_DECL_GET_SCALAR_POINTER (decl)))
399 : 2380 : type = TREE_TYPE (type);
400 : 1078 : else if (GFC_DECL_GET_SCALAR_POINTER (decl))
401 : : return false;
402 : : }
403 : :
404 : 120847 : if (!ptr_ok
405 : 98534 : && GFC_DESCRIPTOR_TYPE_P (type)
406 : 123993 : && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
407 : 2886 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
408 : : return false;
409 : :
410 : 120584 : if (GFC_DESCRIPTOR_TYPE_P (type) || GFC_ARRAY_TYPE_P (type))
411 : 12232 : type = gfc_get_element_type (type);
412 : :
413 : 120584 : if (TREE_CODE (type) != RECORD_TYPE)
414 : : return false;
415 : :
416 : 9874 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
417 : : {
418 : 8870 : ftype = TREE_TYPE (field);
419 : 8870 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
420 : : return true;
421 : 8036 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
422 : 8036 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
423 : : return true;
424 : 5969 : if (!shallow_alloc_only
425 : 5969 : && gfc_has_alloc_comps (ftype, field, false))
426 : : return true;
427 : : }
428 : : return false;
429 : : }
430 : :
431 : : /* gfc_omp_replace_alloc_by_to_mapping is used with gfc_omp_deep_mapping... to
432 : : handle the following:
433 : :
434 : : For map(alloc: dt), the array descriptors of allocatable components should
435 : : be mapped as 'to'; this could be done by (A) adding 'map(to: dt%alloc_comp)'
436 : : for each component (and avoiding to increment the reference count).
437 : : Or (B) by just mapping all of 'dt' as 'to'.
438 : :
439 : : If 'dt' contains several allocatable components and not much other data,
440 : : (A) is more efficient. If 'dt' contains a large const-size array, (A) will
441 : : copy it to the device instead of only 'alloc'ating it.
442 : :
443 : : IMPLEMENTATION CHOICE: We do (A). It avoids the ref-count issue and it is
444 : : expected that, for real-world code, derived types with allocatable
445 : : components only have few other components and either no const-size arrays.
446 : : This copying is done irrespectively whether the allocatables are allocated.
447 : :
448 : : If users wanted to save memory, they have to use 'map(alloc:dt%comp)' as
449 : : also with 'map(alloc:dt)' all components get copied.
450 : :
451 : : For the copy to the device, only allocatable arrays are relevant as their
452 : : the bounds are required; the pointer is set separately (GOMP_MAP_ATTACH)
453 : : and the only setting required for scalars. However, when later copying out
454 : : of the device, an unallocated allocatable must remain unallocated/NULL on
455 : : the host; to achieve this we also must have it set to NULL on the device
456 : : to avoid issues with uninitialized memory being copied back for the pointer
457 : : address. If we could set the pointer to NULL, gfc_has_alloc_comps's
458 : : shallow_alloc_only could be restricted to return true only for arrays.
459 : :
460 : : We only need to return true if there are allocatable-array components. */
461 : :
462 : : static bool
463 : 62 : gfc_omp_replace_alloc_by_to_mapping (tree type, tree decl, bool ptr_ok)
464 : : {
465 : 18 : return gfc_has_alloc_comps (type, decl, ptr_ok, true);
466 : : }
467 : :
468 : :
469 : : /* Return true if TYPE is polymorphic but not with pointer attribute. */
470 : :
471 : : static bool
472 : 64974 : gfc_is_polymorphic_nonptr (tree type)
473 : : {
474 : 64974 : if (POINTER_TYPE_P (type))
475 : 3650 : type = TREE_TYPE (type);
476 : 64974 : return GFC_CLASS_TYPE_P (type);
477 : : }
478 : :
479 : : /* Return true if TYPE is unlimited polymorphic but not with pointer attribute;
480 : : unlimited means also intrinsic types are handled and _len is used. */
481 : :
482 : : static bool
483 : 107 : gfc_is_unlimited_polymorphic_nonptr (tree type)
484 : : {
485 : 107 : if (POINTER_TYPE_P (type))
486 : 0 : type = TREE_TYPE (type);
487 : 107 : if (!GFC_CLASS_TYPE_P (type))
488 : : return false;
489 : :
490 : 107 : tree field = TYPE_FIELDS (type); /* _data */
491 : 107 : gcc_assert (field);
492 : 107 : field = DECL_CHAIN (field); /* _vptr */
493 : 107 : gcc_assert (field);
494 : 107 : field = DECL_CHAIN (field);
495 : 107 : if (!field)
496 : : return false;
497 : 26 : gcc_assert (strcmp ("_len", IDENTIFIER_POINTER (DECL_NAME (field))) == 0);
498 : : return true;
499 : : }
500 : :
501 : : /* Return true if the DECL is for an allocatable array or scalar. */
502 : :
503 : : bool
504 : 3894 : gfc_omp_allocatable_p (tree decl)
505 : : {
506 : 3894 : if (!DECL_P (decl))
507 : : return false;
508 : :
509 : 3894 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
510 : : return true;
511 : :
512 : 3660 : tree type = TREE_TYPE (decl);
513 : 3660 : if (gfc_omp_privatize_by_reference (decl))
514 : 1796 : type = TREE_TYPE (type);
515 : :
516 : 3660 : if (GFC_DESCRIPTOR_TYPE_P (type)
517 : 3660 : && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
518 : : return true;
519 : :
520 : : return false;
521 : : }
522 : :
523 : :
524 : : /* Return true if DECL in private clause needs
525 : : OMP_CLAUSE_PRIVATE_OUTER_REF on the private clause. */
526 : : bool
527 : 14439 : gfc_omp_private_outer_ref (tree decl)
528 : : {
529 : 14439 : tree type = TREE_TYPE (decl);
530 : :
531 : 14439 : if (gfc_omp_privatize_by_reference (decl))
532 : 617 : type = TREE_TYPE (type);
533 : :
534 : 14439 : if (GFC_DESCRIPTOR_TYPE_P (type)
535 : 14439 : && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
536 : : return true;
537 : :
538 : 14313 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
539 : : return true;
540 : :
541 : 14227 : if (gfc_has_alloc_comps (type, decl, false))
542 : : return true;
543 : :
544 : : return false;
545 : : }
546 : :
547 : : /* Callback for gfc_omp_unshare_expr. */
548 : :
549 : : static tree
550 : 92286 : gfc_omp_unshare_expr_r (tree *tp, int *walk_subtrees, void *)
551 : : {
552 : 92286 : tree t = *tp;
553 : 92286 : enum tree_code code = TREE_CODE (t);
554 : :
555 : : /* Stop at types, decls, constants like copy_tree_r. */
556 : 92286 : if (TREE_CODE_CLASS (code) == tcc_type
557 : : || TREE_CODE_CLASS (code) == tcc_declaration
558 : 92286 : || TREE_CODE_CLASS (code) == tcc_constant
559 : 61181 : || code == BLOCK)
560 : 31105 : *walk_subtrees = 0;
561 : 61181 : else if (handled_component_p (t)
562 : 46252 : || TREE_CODE (t) == MEM_REF)
563 : : {
564 : 14989 : *tp = unshare_expr (t);
565 : 14989 : *walk_subtrees = 0;
566 : : }
567 : :
568 : 92286 : return NULL_TREE;
569 : : }
570 : :
571 : : /* Unshare in expr anything that the FE which normally doesn't
572 : : care much about tree sharing (because during gimplification
573 : : everything is unshared) could cause problems with tree sharing
574 : : at omp-low.cc time. */
575 : :
576 : : static tree
577 : 5067 : gfc_omp_unshare_expr (tree expr)
578 : : {
579 : 5067 : walk_tree (&expr, gfc_omp_unshare_expr_r, NULL, NULL);
580 : 5067 : return expr;
581 : : }
582 : :
583 : : enum walk_alloc_comps
584 : : {
585 : : WALK_ALLOC_COMPS_DTOR,
586 : : WALK_ALLOC_COMPS_DEFAULT_CTOR,
587 : : WALK_ALLOC_COMPS_COPY_CTOR
588 : : };
589 : :
590 : : /* Handle allocatable components in OpenMP clauses. */
591 : :
592 : : static tree
593 : 2801 : gfc_walk_alloc_comps (tree decl, tree dest, tree var,
594 : : enum walk_alloc_comps kind)
595 : : {
596 : 2801 : stmtblock_t block, tmpblock;
597 : 2801 : tree type = TREE_TYPE (decl), then_b, tem, field;
598 : 2801 : gfc_init_block (&block);
599 : :
600 : 2801 : if (GFC_ARRAY_TYPE_P (type) || GFC_DESCRIPTOR_TYPE_P (type))
601 : : {
602 : 1092 : if (GFC_DESCRIPTOR_TYPE_P (type))
603 : : {
604 : 548 : gfc_init_block (&tmpblock);
605 : 1644 : tem = gfc_full_array_size (&tmpblock, decl,
606 : 548 : GFC_TYPE_ARRAY_RANK (type));
607 : 548 : then_b = gfc_finish_block (&tmpblock);
608 : 548 : gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (then_b));
609 : 548 : tem = gfc_omp_unshare_expr (tem);
610 : 548 : tem = fold_build2_loc (input_location, MINUS_EXPR,
611 : : gfc_array_index_type, tem,
612 : : gfc_index_one_node);
613 : : }
614 : : else
615 : : {
616 : 544 : bool compute_nelts = false;
617 : 544 : if (!TYPE_DOMAIN (type)
618 : 544 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
619 : 544 : || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
620 : 1088 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
621 : : compute_nelts = true;
622 : 544 : else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
623 : : {
624 : 80 : tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
625 : 80 : if (lookup_attribute ("omp dummy var", a))
626 : : compute_nelts = true;
627 : : }
628 : : if (compute_nelts)
629 : : {
630 : 80 : tem = fold_build2 (EXACT_DIV_EXPR, sizetype,
631 : : TYPE_SIZE_UNIT (type),
632 : : TYPE_SIZE_UNIT (TREE_TYPE (type)));
633 : 80 : tem = size_binop (MINUS_EXPR, tem, size_one_node);
634 : : }
635 : : else
636 : 464 : tem = array_type_nelts_minus_one (type);
637 : 544 : tem = fold_convert (gfc_array_index_type, tem);
638 : : }
639 : :
640 : 1092 : tree nelems = gfc_evaluate_now (tem, &block);
641 : 1092 : tree index = gfc_create_var (gfc_array_index_type, "S");
642 : :
643 : 1092 : gfc_init_block (&tmpblock);
644 : 1092 : tem = gfc_conv_array_data (decl);
645 : 1092 : tree declvar = build_fold_indirect_ref_loc (input_location, tem);
646 : 1092 : tree declvref = gfc_build_array_ref (declvar, index, NULL);
647 : 1092 : tree destvar, destvref = NULL_TREE;
648 : 1092 : if (dest)
649 : : {
650 : 546 : tem = gfc_conv_array_data (dest);
651 : 546 : destvar = build_fold_indirect_ref_loc (input_location, tem);
652 : 546 : destvref = gfc_build_array_ref (destvar, index, NULL);
653 : : }
654 : 1092 : gfc_add_expr_to_block (&tmpblock,
655 : : gfc_walk_alloc_comps (declvref, destvref,
656 : : var, kind));
657 : :
658 : 1092 : gfc_loopinfo loop;
659 : 1092 : gfc_init_loopinfo (&loop);
660 : 1092 : loop.dimen = 1;
661 : 1092 : loop.from[0] = gfc_index_zero_node;
662 : 1092 : loop.loopvar[0] = index;
663 : 1092 : loop.to[0] = nelems;
664 : 1092 : gfc_trans_scalarizing_loops (&loop, &tmpblock);
665 : 1092 : gfc_add_block_to_block (&block, &loop.pre);
666 : 1092 : return gfc_finish_block (&block);
667 : : }
668 : 1709 : else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (var))
669 : : {
670 : 536 : decl = build_fold_indirect_ref_loc (input_location, decl);
671 : 536 : if (dest)
672 : 268 : dest = build_fold_indirect_ref_loc (input_location, dest);
673 : 536 : type = TREE_TYPE (decl);
674 : : }
675 : :
676 : 1709 : gcc_assert (TREE_CODE (type) == RECORD_TYPE);
677 : 11488 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
678 : : {
679 : 9779 : tree ftype = TREE_TYPE (field);
680 : 9779 : tree declf, destf = NULL_TREE;
681 : 9779 : bool has_alloc_comps = gfc_has_alloc_comps (ftype, field, false);
682 : 9779 : if ((!GFC_DESCRIPTOR_TYPE_P (ftype)
683 : 1708 : || GFC_TYPE_ARRAY_AKIND (ftype) != GFC_ARRAY_ALLOCATABLE)
684 : 8071 : && !GFC_DECL_GET_SCALAR_ALLOCATABLE (field)
685 : 16153 : && !has_alloc_comps)
686 : 5950 : continue;
687 : 3829 : declf = fold_build3_loc (input_location, COMPONENT_REF, ftype,
688 : : decl, field, NULL_TREE);
689 : 3829 : if (dest)
690 : 1915 : destf = fold_build3_loc (input_location, COMPONENT_REF, ftype,
691 : : dest, field, NULL_TREE);
692 : :
693 : 3829 : tem = NULL_TREE;
694 : 3829 : switch (kind)
695 : : {
696 : : case WALK_ALLOC_COMPS_DTOR:
697 : : break;
698 : 961 : case WALK_ALLOC_COMPS_DEFAULT_CTOR:
699 : 961 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
700 : 961 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
701 : : {
702 : 430 : gfc_add_modify (&block, unshare_expr (destf),
703 : : unshare_expr (declf));
704 : 430 : tem = gfc_duplicate_allocatable_nocopy
705 : 430 : (destf, declf, ftype,
706 : 430 : GFC_TYPE_ARRAY_RANK (ftype));
707 : : }
708 : 531 : else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
709 : 425 : tem = gfc_duplicate_allocatable_nocopy (destf, declf, ftype, 0);
710 : : break;
711 : 954 : case WALK_ALLOC_COMPS_COPY_CTOR:
712 : 954 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
713 : 954 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
714 : 848 : tem = gfc_duplicate_allocatable (destf, declf, ftype,
715 : 424 : GFC_TYPE_ARRAY_RANK (ftype),
716 : : NULL_TREE);
717 : 530 : else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
718 : 424 : tem = gfc_duplicate_allocatable (destf, declf, ftype, 0,
719 : : NULL_TREE);
720 : : break;
721 : : }
722 : 1703 : if (tem)
723 : 1703 : gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
724 : 3829 : if (has_alloc_comps)
725 : : {
726 : 1272 : gfc_init_block (&tmpblock);
727 : 1272 : gfc_add_expr_to_block (&tmpblock,
728 : : gfc_walk_alloc_comps (declf, destf,
729 : : field, kind));
730 : 1272 : then_b = gfc_finish_block (&tmpblock);
731 : 1272 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
732 : 1272 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
733 : 424 : tem = gfc_conv_descriptor_data_get (unshare_expr (declf));
734 : 848 : else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
735 : 424 : tem = unshare_expr (declf);
736 : : else
737 : : tem = NULL_TREE;
738 : 848 : if (tem)
739 : : {
740 : 848 : tem = fold_convert (pvoid_type_node, tem);
741 : 848 : tem = fold_build2_loc (input_location, NE_EXPR,
742 : : logical_type_node, tem,
743 : : null_pointer_node);
744 : 848 : then_b = build3_loc (input_location, COND_EXPR, void_type_node,
745 : : tem, then_b,
746 : : build_empty_stmt (input_location));
747 : : }
748 : 1272 : gfc_add_expr_to_block (&block, then_b);
749 : : }
750 : 3829 : if (kind == WALK_ALLOC_COMPS_DTOR)
751 : : {
752 : 1914 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
753 : 1914 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
754 : : {
755 : 854 : tem = gfc_conv_descriptor_data_get (unshare_expr (declf));
756 : 854 : tem = gfc_deallocate_with_status (tem, NULL_TREE, NULL_TREE,
757 : : NULL_TREE, NULL_TREE, true,
758 : : NULL,
759 : : GFC_CAF_COARRAY_NOCOARRAY);
760 : 854 : gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
761 : : }
762 : 1060 : else if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
763 : : {
764 : 848 : tem = gfc_call_free (unshare_expr (declf));
765 : 848 : gfc_add_expr_to_block (&block, gfc_omp_unshare_expr (tem));
766 : : }
767 : : }
768 : : }
769 : :
770 : 1709 : return gfc_finish_block (&block);
771 : : }
772 : :
773 : : /* Return code to initialize DECL with its default constructor, or
774 : : NULL if there's nothing to do. */
775 : :
776 : : tree
777 : 20347 : gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer)
778 : : {
779 : 20347 : tree type = TREE_TYPE (decl), size, ptr, cond, then_b, else_b;
780 : 20347 : stmtblock_t block, cond_block;
781 : :
782 : 20347 : switch (OMP_CLAUSE_CODE (clause))
783 : : {
784 : : case OMP_CLAUSE__LOOPTEMP_:
785 : : case OMP_CLAUSE__REDUCTEMP_:
786 : : case OMP_CLAUSE__CONDTEMP_:
787 : : case OMP_CLAUSE__SCANTEMP_:
788 : : return NULL;
789 : 20320 : case OMP_CLAUSE_PRIVATE:
790 : 20320 : case OMP_CLAUSE_LASTPRIVATE:
791 : 20320 : case OMP_CLAUSE_LINEAR:
792 : 20320 : case OMP_CLAUSE_REDUCTION:
793 : 20320 : case OMP_CLAUSE_IN_REDUCTION:
794 : 20320 : case OMP_CLAUSE_TASK_REDUCTION:
795 : 20320 : break;
796 : 0 : default:
797 : 0 : gcc_unreachable ();
798 : : }
799 : :
800 : 20320 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
801 : 263 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
802 : 20339 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
803 : 85 : || !POINTER_TYPE_P (type)))
804 : : {
805 : 19991 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
806 : : {
807 : 51 : gcc_assert (outer);
808 : 51 : gfc_start_block (&block);
809 : 102 : tree tem = gfc_walk_alloc_comps (outer, decl,
810 : 51 : OMP_CLAUSE_DECL (clause),
811 : : WALK_ALLOC_COMPS_DEFAULT_CTOR);
812 : 51 : gfc_add_expr_to_block (&block, tem);
813 : 51 : return gfc_finish_block (&block);
814 : : }
815 : : return NULL_TREE;
816 : : }
817 : :
818 : 329 : gcc_assert (outer != NULL_TREE);
819 : :
820 : : /* Allocatable arrays and scalars in PRIVATE clauses need to be set to
821 : : "not currently allocated" allocation status if outer
822 : : array is "not currently allocated", otherwise should be allocated. */
823 : 329 : gfc_start_block (&block);
824 : :
825 : 329 : gfc_init_block (&cond_block);
826 : :
827 : 329 : if (GFC_DESCRIPTOR_TYPE_P (type))
828 : : {
829 : 244 : gfc_add_modify (&cond_block, decl, outer);
830 : 244 : tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
831 : 244 : size = gfc_conv_descriptor_ubound_get (decl, rank);
832 : 244 : size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
833 : : size,
834 : : gfc_conv_descriptor_lbound_get (decl, rank));
835 : 244 : size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
836 : : size, gfc_index_one_node);
837 : 244 : if (GFC_TYPE_ARRAY_RANK (type) > 1)
838 : 130 : size = fold_build2_loc (input_location, MULT_EXPR,
839 : : gfc_array_index_type, size,
840 : : gfc_conv_descriptor_stride_get (decl, rank));
841 : 244 : tree esize = fold_convert (gfc_array_index_type,
842 : : TYPE_SIZE_UNIT (gfc_get_element_type (type)));
843 : 244 : size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
844 : : size, esize);
845 : 244 : size = unshare_expr (size);
846 : 244 : size = gfc_evaluate_now (fold_convert (size_type_node, size),
847 : : &cond_block);
848 : : }
849 : : else
850 : 85 : size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
851 : 329 : ptr = gfc_create_var (pvoid_type_node, NULL);
852 : 329 : gfc_allocate_using_malloc (&cond_block, ptr, size, NULL_TREE);
853 : 329 : if (GFC_DESCRIPTOR_TYPE_P (type))
854 : 244 : gfc_conv_descriptor_data_set (&cond_block, unshare_expr (decl), ptr);
855 : : else
856 : 85 : gfc_add_modify (&cond_block, unshare_expr (decl),
857 : 85 : fold_convert (TREE_TYPE (decl), ptr));
858 : 329 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
859 : : {
860 : 124 : tree tem = gfc_walk_alloc_comps (outer, decl,
861 : 62 : OMP_CLAUSE_DECL (clause),
862 : : WALK_ALLOC_COMPS_DEFAULT_CTOR);
863 : 62 : gfc_add_expr_to_block (&cond_block, tem);
864 : : }
865 : 329 : then_b = gfc_finish_block (&cond_block);
866 : :
867 : : /* Reduction clause requires allocated ALLOCATABLE. */
868 : 329 : if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_REDUCTION
869 : 185 : && OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_IN_REDUCTION
870 : 514 : && OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_TASK_REDUCTION)
871 : : {
872 : 185 : gfc_init_block (&cond_block);
873 : 185 : if (GFC_DESCRIPTOR_TYPE_P (type))
874 : 124 : gfc_conv_descriptor_data_set (&cond_block, unshare_expr (decl),
875 : : null_pointer_node);
876 : : else
877 : 61 : gfc_add_modify (&cond_block, unshare_expr (decl),
878 : 61 : build_zero_cst (TREE_TYPE (decl)));
879 : 185 : else_b = gfc_finish_block (&cond_block);
880 : :
881 : 185 : tree tem = fold_convert (pvoid_type_node,
882 : : GFC_DESCRIPTOR_TYPE_P (type)
883 : : ? gfc_conv_descriptor_data_get (outer) : outer);
884 : 185 : tem = unshare_expr (tem);
885 : 185 : cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
886 : : tem, null_pointer_node);
887 : 185 : gfc_add_expr_to_block (&block,
888 : : build3_loc (input_location, COND_EXPR,
889 : : void_type_node, cond, then_b,
890 : : else_b));
891 : : /* Avoid -W*uninitialized warnings. */
892 : 185 : if (DECL_P (decl))
893 : 146 : suppress_warning (decl, OPT_Wuninitialized);
894 : : }
895 : : else
896 : 144 : gfc_add_expr_to_block (&block, then_b);
897 : :
898 : 329 : return gfc_finish_block (&block);
899 : : }
900 : :
901 : : /* Build and return code for a copy constructor from SRC to DEST. */
902 : :
903 : : tree
904 : 9196 : gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
905 : : {
906 : 9196 : tree type = TREE_TYPE (dest), ptr, size, call;
907 : 9196 : tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
908 : 9196 : tree cond, then_b, else_b;
909 : 9196 : stmtblock_t block, cond_block;
910 : :
911 : 9196 : gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE
912 : : || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
913 : :
914 : : /* Privatize pointer, only; cf. gfc_omp_predetermined_sharing. */
915 : 9196 : if (DECL_P (OMP_CLAUSE_DECL (clause))
916 : 9196 : && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
917 : 27 : return build2 (MODIFY_EXPR, TREE_TYPE (dest), dest, src);
918 : :
919 : 9169 : if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
920 : 6137 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
921 : 9350 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
922 : 167 : decl_type
923 : 167 : = TREE_TYPE (GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)));
924 : :
925 : 9169 : if (gfc_is_polymorphic_nonptr (decl_type))
926 : : {
927 : 40 : if (POINTER_TYPE_P (decl_type))
928 : 27 : decl_type = TREE_TYPE (decl_type);
929 : 40 : decl_type = TREE_TYPE (TYPE_FIELDS (decl_type));
930 : 40 : if (GFC_DESCRIPTOR_TYPE_P (decl_type) || GFC_ARRAY_TYPE_P (decl_type))
931 : 4 : fatal_error (input_location,
932 : : "Sorry, polymorphic arrays not yet supported for "
933 : : "firstprivate");
934 : 36 : tree src_len;
935 : 36 : tree nelems = build_int_cst (size_type_node, 1); /* Scalar. */
936 : 36 : tree src_data = gfc_class_data_get (unshare_expr (src));
937 : 36 : tree dest_data = gfc_class_data_get (unshare_expr (dest));
938 : 36 : bool unlimited = gfc_is_unlimited_polymorphic_nonptr (type);
939 : :
940 : 36 : gfc_start_block (&block);
941 : 36 : gfc_add_modify (&block, gfc_class_vptr_get (dest),
942 : : gfc_class_vptr_get (src));
943 : 36 : gfc_init_block (&cond_block);
944 : :
945 : 36 : if (unlimited)
946 : : {
947 : 24 : src_len = gfc_class_len_get (src);
948 : 24 : gfc_add_modify (&cond_block, gfc_class_len_get (unshare_expr (dest)), src_len);
949 : : }
950 : :
951 : : /* Use: size = class._vtab._size * (class._len > 0 ? class._len : 1). */
952 : 36 : size = fold_convert (size_type_node, gfc_class_vtab_size_get (src));
953 : 36 : if (unlimited)
954 : : {
955 : 24 : cond = fold_build2_loc (input_location, GT_EXPR, boolean_type_node,
956 : : unshare_expr (src_len),
957 : 24 : build_zero_cst (TREE_TYPE (src_len)));
958 : 24 : cond = build3_loc (input_location, COND_EXPR, size_type_node, cond,
959 : : fold_convert (size_type_node,
960 : : unshare_expr (src_len)),
961 : : build_int_cst (size_type_node, 1));
962 : 24 : size = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
963 : : size, cond);
964 : : }
965 : :
966 : : /* Malloc memory + call class->_vpt->_copy. */
967 : 36 : call = builtin_decl_explicit (BUILT_IN_MALLOC);
968 : 36 : call = build_call_expr_loc (input_location, call, 1, size);
969 : 36 : gfc_add_modify (&cond_block, dest_data,
970 : 36 : fold_convert (TREE_TYPE (dest_data), call));
971 : 36 : gfc_add_expr_to_block (&cond_block,
972 : : gfc_copy_class_to_class (src, dest, nelems,
973 : : unlimited));
974 : :
975 : 36 : gcc_assert (TREE_CODE (dest_data) == COMPONENT_REF);
976 : 36 : if (!GFC_DECL_GET_SCALAR_ALLOCATABLE (TREE_OPERAND (dest_data, 1)))
977 : : {
978 : 12 : gfc_add_block_to_block (&block, &cond_block);
979 : : }
980 : : else
981 : : {
982 : : /* Create: if (class._data != 0) <cond_block> else class._data = NULL; */
983 : 24 : cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
984 : : src_data, null_pointer_node);
985 : 24 : gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
986 : : void_type_node, cond,
987 : : gfc_finish_block (&cond_block),
988 : : fold_build2_loc (input_location, MODIFY_EXPR, void_type_node,
989 : : unshare_expr (dest_data), null_pointer_node)));
990 : : }
991 : 36 : return gfc_finish_block (&block);
992 : : }
993 : :
994 : 9129 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
995 : 138 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
996 : 9153 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
997 : 77 : || !POINTER_TYPE_P (type)))
998 : : {
999 : 8940 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1000 : : {
1001 : 20 : gfc_start_block (&block);
1002 : 20 : gfc_add_modify (&block, dest, src);
1003 : 20 : tree tem = gfc_walk_alloc_comps (src, dest, OMP_CLAUSE_DECL (clause),
1004 : : WALK_ALLOC_COMPS_COPY_CTOR);
1005 : 20 : gfc_add_expr_to_block (&block, tem);
1006 : 20 : return gfc_finish_block (&block);
1007 : : }
1008 : : else
1009 : 8920 : return build2_v (MODIFY_EXPR, dest, src);
1010 : : }
1011 : :
1012 : : /* Allocatable arrays in FIRSTPRIVATE clauses need to be allocated
1013 : : and copied from SRC. */
1014 : 189 : gfc_start_block (&block);
1015 : :
1016 : 189 : gfc_init_block (&cond_block);
1017 : :
1018 : 189 : gfc_add_modify (&cond_block, dest, fold_convert (TREE_TYPE (dest), src));
1019 : 189 : if (GFC_DESCRIPTOR_TYPE_P (type))
1020 : : {
1021 : 114 : tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
1022 : 114 : size = gfc_conv_descriptor_ubound_get (dest, rank);
1023 : 114 : size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
1024 : : size,
1025 : : gfc_conv_descriptor_lbound_get (dest, rank));
1026 : 114 : size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
1027 : : size, gfc_index_one_node);
1028 : 114 : if (GFC_TYPE_ARRAY_RANK (type) > 1)
1029 : 42 : size = fold_build2_loc (input_location, MULT_EXPR,
1030 : : gfc_array_index_type, size,
1031 : : gfc_conv_descriptor_stride_get (dest, rank));
1032 : 114 : tree esize = fold_convert (gfc_array_index_type,
1033 : : TYPE_SIZE_UNIT (gfc_get_element_type (type)));
1034 : 114 : size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
1035 : : size, esize);
1036 : 114 : size = unshare_expr (size);
1037 : 114 : size = gfc_evaluate_now (fold_convert (size_type_node, size),
1038 : : &cond_block);
1039 : : }
1040 : : else
1041 : 75 : size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
1042 : 189 : ptr = gfc_create_var (pvoid_type_node, NULL);
1043 : 189 : gfc_allocate_using_malloc (&cond_block, ptr, size, NULL_TREE);
1044 : 189 : if (GFC_DESCRIPTOR_TYPE_P (type))
1045 : 114 : gfc_conv_descriptor_data_set (&cond_block, unshare_expr (dest), ptr);
1046 : : else
1047 : 75 : gfc_add_modify (&cond_block, unshare_expr (dest),
1048 : 75 : fold_convert (TREE_TYPE (dest), ptr));
1049 : :
1050 : 189 : tree srcptr = GFC_DESCRIPTOR_TYPE_P (type)
1051 : 189 : ? gfc_conv_descriptor_data_get (src) : src;
1052 : 189 : srcptr = unshare_expr (srcptr);
1053 : 189 : srcptr = fold_convert (pvoid_type_node, srcptr);
1054 : 189 : call = build_call_expr_loc (input_location,
1055 : : builtin_decl_explicit (BUILT_IN_MEMCPY), 3, ptr,
1056 : : srcptr, size);
1057 : 189 : gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
1058 : 189 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1059 : : {
1060 : 48 : tree tem = gfc_walk_alloc_comps (src, dest,
1061 : 24 : OMP_CLAUSE_DECL (clause),
1062 : : WALK_ALLOC_COMPS_COPY_CTOR);
1063 : 24 : gfc_add_expr_to_block (&cond_block, tem);
1064 : : }
1065 : 189 : then_b = gfc_finish_block (&cond_block);
1066 : :
1067 : 189 : gfc_init_block (&cond_block);
1068 : 189 : if (GFC_DESCRIPTOR_TYPE_P (type))
1069 : 114 : gfc_conv_descriptor_data_set (&cond_block, unshare_expr (dest),
1070 : : null_pointer_node);
1071 : : else
1072 : 75 : gfc_add_modify (&cond_block, unshare_expr (dest),
1073 : 75 : build_zero_cst (TREE_TYPE (dest)));
1074 : 189 : else_b = gfc_finish_block (&cond_block);
1075 : :
1076 : 189 : cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
1077 : : unshare_expr (srcptr), null_pointer_node);
1078 : 189 : gfc_add_expr_to_block (&block,
1079 : : build3_loc (input_location, COND_EXPR,
1080 : : void_type_node, cond, then_b, else_b));
1081 : : /* Avoid -W*uninitialized warnings. */
1082 : 189 : if (DECL_P (dest))
1083 : 121 : suppress_warning (dest, OPT_Wuninitialized);
1084 : :
1085 : 189 : return gfc_finish_block (&block);
1086 : : }
1087 : :
1088 : : /* Similarly, except use an intrinsic or pointer assignment operator
1089 : : instead. */
1090 : :
1091 : : tree
1092 : 6341 : gfc_omp_clause_assign_op (tree clause, tree dest, tree src)
1093 : : {
1094 : 6341 : tree type = TREE_TYPE (dest), ptr, size, call, nonalloc;
1095 : 6341 : tree cond, then_b, else_b;
1096 : 6341 : stmtblock_t block, cond_block, cond_block2, inner_block;
1097 : :
1098 : 6341 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
1099 : 234 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
1100 : 12479 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
1101 : 136 : || !POINTER_TYPE_P (type)))
1102 : : {
1103 : 6002 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1104 : : {
1105 : 30 : gfc_start_block (&block);
1106 : : /* First dealloc any allocatable components in DEST. */
1107 : 60 : tree tem = gfc_walk_alloc_comps (dest, NULL_TREE,
1108 : 30 : OMP_CLAUSE_DECL (clause),
1109 : : WALK_ALLOC_COMPS_DTOR);
1110 : 30 : gfc_add_expr_to_block (&block, tem);
1111 : : /* Then copy over toplevel data. */
1112 : 30 : gfc_add_modify (&block, dest, src);
1113 : : /* Finally allocate any allocatable components and copy. */
1114 : 30 : tem = gfc_walk_alloc_comps (src, dest, OMP_CLAUSE_DECL (clause),
1115 : : WALK_ALLOC_COMPS_COPY_CTOR);
1116 : 30 : gfc_add_expr_to_block (&block, tem);
1117 : 30 : return gfc_finish_block (&block);
1118 : : }
1119 : : else
1120 : 5972 : return build2_v (MODIFY_EXPR, dest, src);
1121 : : }
1122 : :
1123 : 339 : gfc_start_block (&block);
1124 : :
1125 : 339 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1126 : : {
1127 : 32 : then_b = gfc_walk_alloc_comps (dest, NULL_TREE, OMP_CLAUSE_DECL (clause),
1128 : : WALK_ALLOC_COMPS_DTOR);
1129 : 32 : tree tem = fold_convert (pvoid_type_node,
1130 : : GFC_DESCRIPTOR_TYPE_P (type)
1131 : : ? gfc_conv_descriptor_data_get (dest) : dest);
1132 : 32 : tem = unshare_expr (tem);
1133 : 32 : cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
1134 : : tem, null_pointer_node);
1135 : 32 : tem = build3_loc (input_location, COND_EXPR, void_type_node, cond,
1136 : : then_b, build_empty_stmt (input_location));
1137 : 32 : gfc_add_expr_to_block (&block, tem);
1138 : : }
1139 : :
1140 : 339 : gfc_init_block (&cond_block);
1141 : :
1142 : 339 : if (GFC_DESCRIPTOR_TYPE_P (type))
1143 : : {
1144 : 203 : tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
1145 : 203 : size = gfc_conv_descriptor_ubound_get (src, rank);
1146 : 203 : size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
1147 : : size,
1148 : : gfc_conv_descriptor_lbound_get (src, rank));
1149 : 203 : size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
1150 : : size, gfc_index_one_node);
1151 : 203 : if (GFC_TYPE_ARRAY_RANK (type) > 1)
1152 : 88 : size = fold_build2_loc (input_location, MULT_EXPR,
1153 : : gfc_array_index_type, size,
1154 : : gfc_conv_descriptor_stride_get (src, rank));
1155 : 203 : tree esize = fold_convert (gfc_array_index_type,
1156 : : TYPE_SIZE_UNIT (gfc_get_element_type (type)));
1157 : 203 : size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
1158 : : size, esize);
1159 : 203 : size = unshare_expr (size);
1160 : 203 : size = gfc_evaluate_now (fold_convert (size_type_node, size),
1161 : : &cond_block);
1162 : : }
1163 : : else
1164 : 136 : size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
1165 : 339 : ptr = gfc_create_var (pvoid_type_node, NULL);
1166 : :
1167 : 339 : tree destptr = GFC_DESCRIPTOR_TYPE_P (type)
1168 : 339 : ? gfc_conv_descriptor_data_get (dest) : dest;
1169 : 339 : destptr = unshare_expr (destptr);
1170 : 339 : destptr = fold_convert (pvoid_type_node, destptr);
1171 : 339 : gfc_add_modify (&cond_block, ptr, destptr);
1172 : :
1173 : 339 : nonalloc = fold_build2_loc (input_location, EQ_EXPR, logical_type_node,
1174 : : destptr, null_pointer_node);
1175 : 339 : cond = nonalloc;
1176 : 339 : if (GFC_DESCRIPTOR_TYPE_P (type))
1177 : : {
1178 : : int i;
1179 : 494 : for (i = 0; i < GFC_TYPE_ARRAY_RANK (type); i++)
1180 : : {
1181 : 291 : tree rank = gfc_rank_cst[i];
1182 : 291 : tree tem = gfc_conv_descriptor_ubound_get (src, rank);
1183 : 291 : tem = fold_build2_loc (input_location, MINUS_EXPR,
1184 : : gfc_array_index_type, tem,
1185 : : gfc_conv_descriptor_lbound_get (src, rank));
1186 : 291 : tem = fold_build2_loc (input_location, PLUS_EXPR,
1187 : : gfc_array_index_type, tem,
1188 : : gfc_conv_descriptor_lbound_get (dest, rank));
1189 : 291 : tem = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
1190 : : tem, gfc_conv_descriptor_ubound_get (dest,
1191 : : rank));
1192 : 291 : cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR,
1193 : : logical_type_node, cond, tem);
1194 : : }
1195 : : }
1196 : :
1197 : 339 : gfc_init_block (&cond_block2);
1198 : :
1199 : 339 : if (GFC_DESCRIPTOR_TYPE_P (type))
1200 : : {
1201 : 203 : gfc_init_block (&inner_block);
1202 : 203 : gfc_allocate_using_malloc (&inner_block, ptr, size, NULL_TREE);
1203 : 203 : then_b = gfc_finish_block (&inner_block);
1204 : :
1205 : 203 : gfc_init_block (&inner_block);
1206 : 203 : gfc_add_modify (&inner_block, ptr,
1207 : : gfc_call_realloc (&inner_block, ptr, size));
1208 : 203 : else_b = gfc_finish_block (&inner_block);
1209 : :
1210 : 203 : gfc_add_expr_to_block (&cond_block2,
1211 : : build3_loc (input_location, COND_EXPR,
1212 : : void_type_node,
1213 : : unshare_expr (nonalloc),
1214 : : then_b, else_b));
1215 : 203 : gfc_add_modify (&cond_block2, dest, src);
1216 : 203 : gfc_conv_descriptor_data_set (&cond_block2, unshare_expr (dest), ptr);
1217 : : }
1218 : : else
1219 : : {
1220 : 136 : gfc_allocate_using_malloc (&cond_block2, ptr, size, NULL_TREE);
1221 : 136 : gfc_add_modify (&cond_block2, unshare_expr (dest),
1222 : : fold_convert (type, ptr));
1223 : : }
1224 : 339 : then_b = gfc_finish_block (&cond_block2);
1225 : 339 : else_b = build_empty_stmt (input_location);
1226 : :
1227 : 339 : gfc_add_expr_to_block (&cond_block,
1228 : : build3_loc (input_location, COND_EXPR,
1229 : : void_type_node, unshare_expr (cond),
1230 : : then_b, else_b));
1231 : :
1232 : 339 : tree srcptr = GFC_DESCRIPTOR_TYPE_P (type)
1233 : 339 : ? gfc_conv_descriptor_data_get (src) : src;
1234 : 339 : srcptr = unshare_expr (srcptr);
1235 : 339 : srcptr = fold_convert (pvoid_type_node, srcptr);
1236 : 339 : call = build_call_expr_loc (input_location,
1237 : : builtin_decl_explicit (BUILT_IN_MEMCPY), 3, ptr,
1238 : : srcptr, size);
1239 : 339 : gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
1240 : 339 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1241 : : {
1242 : 64 : tree tem = gfc_walk_alloc_comps (src, dest,
1243 : 32 : OMP_CLAUSE_DECL (clause),
1244 : : WALK_ALLOC_COMPS_COPY_CTOR);
1245 : 32 : gfc_add_expr_to_block (&cond_block, tem);
1246 : : }
1247 : 339 : then_b = gfc_finish_block (&cond_block);
1248 : :
1249 : 339 : if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_COPYIN)
1250 : : {
1251 : 66 : gfc_init_block (&cond_block);
1252 : 66 : if (GFC_DESCRIPTOR_TYPE_P (type))
1253 : : {
1254 : 48 : tree tmp = gfc_conv_descriptor_data_get (unshare_expr (dest));
1255 : 48 : tmp = gfc_deallocate_with_status (tmp, NULL_TREE, NULL_TREE,
1256 : : NULL_TREE, NULL_TREE, true, NULL,
1257 : : GFC_CAF_COARRAY_NOCOARRAY);
1258 : 48 : gfc_add_expr_to_block (&cond_block, tmp);
1259 : : }
1260 : : else
1261 : : {
1262 : 18 : destptr = gfc_evaluate_now (destptr, &cond_block);
1263 : 18 : gfc_add_expr_to_block (&cond_block, gfc_call_free (destptr));
1264 : 18 : gfc_add_modify (&cond_block, unshare_expr (dest),
1265 : 18 : build_zero_cst (TREE_TYPE (dest)));
1266 : : }
1267 : 66 : else_b = gfc_finish_block (&cond_block);
1268 : :
1269 : 66 : cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
1270 : : unshare_expr (srcptr), null_pointer_node);
1271 : 66 : gfc_add_expr_to_block (&block,
1272 : : build3_loc (input_location, COND_EXPR,
1273 : : void_type_node, cond,
1274 : : then_b, else_b));
1275 : : }
1276 : : else
1277 : 273 : gfc_add_expr_to_block (&block, then_b);
1278 : :
1279 : 339 : return gfc_finish_block (&block);
1280 : : }
1281 : :
1282 : : static void
1283 : 84 : gfc_omp_linear_clause_add_loop (stmtblock_t *block, tree dest, tree src,
1284 : : tree add, tree nelems)
1285 : : {
1286 : 84 : stmtblock_t tmpblock;
1287 : 84 : tree desta, srca, index = gfc_create_var (gfc_array_index_type, "S");
1288 : 84 : nelems = gfc_evaluate_now (nelems, block);
1289 : :
1290 : 84 : gfc_init_block (&tmpblock);
1291 : 84 : if (TREE_CODE (TREE_TYPE (dest)) == ARRAY_TYPE)
1292 : : {
1293 : 60 : desta = gfc_build_array_ref (dest, index, NULL);
1294 : 60 : srca = gfc_build_array_ref (src, index, NULL);
1295 : : }
1296 : : else
1297 : : {
1298 : 24 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (dest)));
1299 : 24 : tree idx = fold_build2 (MULT_EXPR, sizetype,
1300 : : fold_convert (sizetype, index),
1301 : : TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (dest))));
1302 : 24 : desta = build_fold_indirect_ref (fold_build2 (POINTER_PLUS_EXPR,
1303 : : TREE_TYPE (dest), dest,
1304 : : idx));
1305 : 24 : srca = build_fold_indirect_ref (fold_build2 (POINTER_PLUS_EXPR,
1306 : : TREE_TYPE (src), src,
1307 : : idx));
1308 : : }
1309 : 84 : gfc_add_modify (&tmpblock, desta,
1310 : 84 : fold_build2 (PLUS_EXPR, TREE_TYPE (desta),
1311 : : srca, add));
1312 : :
1313 : 84 : gfc_loopinfo loop;
1314 : 84 : gfc_init_loopinfo (&loop);
1315 : 84 : loop.dimen = 1;
1316 : 84 : loop.from[0] = gfc_index_zero_node;
1317 : 84 : loop.loopvar[0] = index;
1318 : 84 : loop.to[0] = nelems;
1319 : 84 : gfc_trans_scalarizing_loops (&loop, &tmpblock);
1320 : 84 : gfc_add_block_to_block (block, &loop.pre);
1321 : 84 : }
1322 : :
1323 : : /* Build and return code for a constructor of DEST that initializes
1324 : : it to SRC plus ADD (ADD is scalar integer). */
1325 : :
1326 : : tree
1327 : 108 : gfc_omp_clause_linear_ctor (tree clause, tree dest, tree src, tree add)
1328 : : {
1329 : 108 : tree type = TREE_TYPE (dest), ptr, size, nelems = NULL_TREE;
1330 : 108 : stmtblock_t block;
1331 : :
1332 : 108 : gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
1333 : :
1334 : 108 : gfc_start_block (&block);
1335 : 108 : add = gfc_evaluate_now (add, &block);
1336 : :
1337 : 108 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
1338 : 24 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
1339 : 192 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
1340 : 24 : || !POINTER_TYPE_P (type)))
1341 : : {
1342 : 60 : bool compute_nelts = false;
1343 : 60 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1344 : 60 : if (!TYPE_DOMAIN (type)
1345 : 60 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
1346 : 60 : || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
1347 : 120 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
1348 : : compute_nelts = true;
1349 : 60 : else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
1350 : : {
1351 : 48 : tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
1352 : 48 : if (lookup_attribute ("omp dummy var", a))
1353 : : compute_nelts = true;
1354 : : }
1355 : : if (compute_nelts)
1356 : : {
1357 : 48 : nelems = fold_build2 (EXACT_DIV_EXPR, sizetype,
1358 : : TYPE_SIZE_UNIT (type),
1359 : : TYPE_SIZE_UNIT (TREE_TYPE (type)));
1360 : 48 : nelems = size_binop (MINUS_EXPR, nelems, size_one_node);
1361 : : }
1362 : : else
1363 : 12 : nelems = array_type_nelts_minus_one (type);
1364 : 60 : nelems = fold_convert (gfc_array_index_type, nelems);
1365 : :
1366 : 60 : gfc_omp_linear_clause_add_loop (&block, dest, src, add, nelems);
1367 : 60 : return gfc_finish_block (&block);
1368 : : }
1369 : :
1370 : : /* Allocatable arrays in LINEAR clauses need to be allocated
1371 : : and copied from SRC. */
1372 : 48 : gfc_add_modify (&block, dest, src);
1373 : 48 : if (GFC_DESCRIPTOR_TYPE_P (type))
1374 : : {
1375 : 24 : tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1];
1376 : 24 : size = gfc_conv_descriptor_ubound_get (dest, rank);
1377 : 24 : size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
1378 : : size,
1379 : : gfc_conv_descriptor_lbound_get (dest, rank));
1380 : 24 : size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
1381 : : size, gfc_index_one_node);
1382 : 24 : if (GFC_TYPE_ARRAY_RANK (type) > 1)
1383 : 0 : size = fold_build2_loc (input_location, MULT_EXPR,
1384 : : gfc_array_index_type, size,
1385 : : gfc_conv_descriptor_stride_get (dest, rank));
1386 : 24 : tree esize = fold_convert (gfc_array_index_type,
1387 : : TYPE_SIZE_UNIT (gfc_get_element_type (type)));
1388 : 24 : nelems = gfc_evaluate_now (unshare_expr (size), &block);
1389 : 24 : size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
1390 : : nelems, unshare_expr (esize));
1391 : 24 : size = gfc_evaluate_now (fold_convert (size_type_node, size),
1392 : : &block);
1393 : 24 : nelems = fold_build2_loc (input_location, MINUS_EXPR,
1394 : : gfc_array_index_type, nelems,
1395 : : gfc_index_one_node);
1396 : : }
1397 : : else
1398 : 24 : size = fold_convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (type)));
1399 : 48 : ptr = gfc_create_var (pvoid_type_node, NULL);
1400 : 48 : gfc_allocate_using_malloc (&block, ptr, size, NULL_TREE);
1401 : 48 : if (GFC_DESCRIPTOR_TYPE_P (type))
1402 : : {
1403 : 24 : gfc_conv_descriptor_data_set (&block, unshare_expr (dest), ptr);
1404 : 24 : tree etype = gfc_get_element_type (type);
1405 : 24 : ptr = fold_convert (build_pointer_type (etype), ptr);
1406 : 24 : tree srcptr = gfc_conv_descriptor_data_get (unshare_expr (src));
1407 : 24 : srcptr = fold_convert (build_pointer_type (etype), srcptr);
1408 : 24 : gfc_omp_linear_clause_add_loop (&block, ptr, srcptr, add, nelems);
1409 : : }
1410 : : else
1411 : : {
1412 : 24 : gfc_add_modify (&block, unshare_expr (dest),
1413 : 24 : fold_convert (TREE_TYPE (dest), ptr));
1414 : 24 : ptr = fold_convert (TREE_TYPE (dest), ptr);
1415 : 24 : tree dstm = build_fold_indirect_ref (ptr);
1416 : 24 : tree srcm = build_fold_indirect_ref (unshare_expr (src));
1417 : 24 : gfc_add_modify (&block, dstm,
1418 : 24 : fold_build2 (PLUS_EXPR, TREE_TYPE (add), srcm, add));
1419 : : }
1420 : 48 : return gfc_finish_block (&block);
1421 : : }
1422 : :
1423 : : /* Build and return code destructing DECL. Return NULL if nothing
1424 : : to be done. */
1425 : :
1426 : : tree
1427 : 32013 : gfc_omp_clause_dtor (tree clause, tree decl)
1428 : : {
1429 : 32013 : tree type = TREE_TYPE (decl), tem;
1430 : 32013 : tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
1431 : :
1432 : : /* Only pointer was privatized; cf. gfc_omp_clause_copy_ctor. */
1433 : 32013 : if (DECL_P (OMP_CLAUSE_DECL (clause))
1434 : 32013 : && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
1435 : : return NULL_TREE;
1436 : :
1437 : 31986 : if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
1438 : 11864 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
1439 : 32339 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
1440 : 339 : decl_type
1441 : 339 : = TREE_TYPE (GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)));
1442 : 31986 : if (gfc_is_polymorphic_nonptr (decl_type))
1443 : : {
1444 : 37 : if (POINTER_TYPE_P (decl_type))
1445 : 24 : decl_type = TREE_TYPE (decl_type);
1446 : 37 : decl_type = TREE_TYPE (TYPE_FIELDS (decl_type));
1447 : 37 : if (GFC_DESCRIPTOR_TYPE_P (decl_type) || GFC_ARRAY_TYPE_P (decl_type))
1448 : 0 : fatal_error (input_location,
1449 : : "Sorry, polymorphic arrays not yet supported for "
1450 : : "firstprivate");
1451 : 37 : stmtblock_t block, cond_block;
1452 : 37 : gfc_start_block (&block);
1453 : 37 : gfc_init_block (&cond_block);
1454 : 37 : tree final = gfc_class_vtab_final_get (decl);
1455 : 37 : tree size = fold_convert (size_type_node, gfc_class_vtab_size_get (decl));
1456 : 37 : gfc_se se;
1457 : 37 : gfc_init_se (&se, NULL);
1458 : 37 : symbol_attribute attr = {};
1459 : 37 : tree data = gfc_class_data_get (decl);
1460 : 37 : tree desc = gfc_conv_scalar_to_descriptor (&se, data, attr);
1461 : :
1462 : : /* Call class->_vpt->_finalize + free. */
1463 : 37 : tree call = build_fold_indirect_ref (final);
1464 : 37 : call = build_call_expr_loc (input_location, call, 3,
1465 : : gfc_build_addr_expr (NULL, desc),
1466 : : size, boolean_false_node);
1467 : 37 : gfc_add_block_to_block (&cond_block, &se.pre);
1468 : 37 : gfc_add_expr_to_block (&cond_block, fold_convert (void_type_node, call));
1469 : 37 : gfc_add_block_to_block (&cond_block, &se.post);
1470 : : /* Create: if (_vtab && _final) <cond_block> */
1471 : 37 : tree cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
1472 : : gfc_class_vptr_get (decl),
1473 : : null_pointer_node);
1474 : 37 : tree cond2 = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
1475 : : final, null_pointer_node);
1476 : 37 : cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR,
1477 : : boolean_type_node, cond, cond2);
1478 : 37 : gfc_add_expr_to_block (&block, build3_loc (input_location, COND_EXPR,
1479 : : void_type_node, cond,
1480 : : gfc_finish_block (&cond_block), NULL_TREE));
1481 : 37 : call = builtin_decl_explicit (BUILT_IN_FREE);
1482 : 37 : call = build_call_expr_loc (input_location, call, 1, data);
1483 : 37 : gfc_add_expr_to_block (&block, fold_convert (void_type_node, call));
1484 : 37 : return gfc_finish_block (&block);
1485 : : }
1486 : :
1487 : 31949 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
1488 : 433 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
1489 : 32000 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
1490 : 186 : || !POINTER_TYPE_P (type)))
1491 : : {
1492 : 31383 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1493 : 140 : return gfc_walk_alloc_comps (decl, NULL_TREE,
1494 : 70 : OMP_CLAUSE_DECL (clause),
1495 : 70 : WALK_ALLOC_COMPS_DTOR);
1496 : : return NULL_TREE;
1497 : : }
1498 : :
1499 : 566 : if (GFC_DESCRIPTOR_TYPE_P (type))
1500 : : {
1501 : : /* Allocatable arrays in FIRSTPRIVATE/LASTPRIVATE etc. clauses need
1502 : : to be deallocated if they were allocated. */
1503 : 382 : tem = gfc_conv_descriptor_data_get (decl);
1504 : 382 : tem = gfc_deallocate_with_status (tem, NULL_TREE, NULL_TREE, NULL_TREE,
1505 : : NULL_TREE, true, NULL,
1506 : : GFC_CAF_COARRAY_NOCOARRAY);
1507 : : }
1508 : : else
1509 : 184 : tem = gfc_call_free (decl);
1510 : 566 : tem = gfc_omp_unshare_expr (tem);
1511 : :
1512 : 566 : if (gfc_has_alloc_comps (type, OMP_CLAUSE_DECL (clause), false))
1513 : : {
1514 : 86 : stmtblock_t block;
1515 : 86 : tree then_b;
1516 : :
1517 : 86 : gfc_init_block (&block);
1518 : 172 : gfc_add_expr_to_block (&block,
1519 : : gfc_walk_alloc_comps (decl, NULL_TREE,
1520 : 86 : OMP_CLAUSE_DECL (clause),
1521 : : WALK_ALLOC_COMPS_DTOR));
1522 : 86 : gfc_add_expr_to_block (&block, tem);
1523 : 86 : then_b = gfc_finish_block (&block);
1524 : :
1525 : 86 : tem = fold_convert (pvoid_type_node,
1526 : : GFC_DESCRIPTOR_TYPE_P (type)
1527 : : ? gfc_conv_descriptor_data_get (decl) : decl);
1528 : 86 : tem = unshare_expr (tem);
1529 : 86 : tree cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
1530 : : tem, null_pointer_node);
1531 : 86 : tem = build3_loc (input_location, COND_EXPR, void_type_node, cond,
1532 : : then_b, build_empty_stmt (input_location));
1533 : : }
1534 : : return tem;
1535 : : }
1536 : :
1537 : : /* Build a conditional expression in BLOCK. If COND_VAL is not
1538 : : null, then the block THEN_B is executed, otherwise ELSE_VAL
1539 : : is assigned to VAL. */
1540 : :
1541 : : static void
1542 : 1026 : gfc_build_cond_assign (stmtblock_t *block, tree val, tree cond_val,
1543 : : tree then_b, tree else_val)
1544 : : {
1545 : 1026 : stmtblock_t cond_block;
1546 : 1026 : tree else_b = NULL_TREE;
1547 : 1026 : tree val_ty = TREE_TYPE (val);
1548 : :
1549 : 1026 : if (else_val)
1550 : : {
1551 : 1026 : gfc_init_block (&cond_block);
1552 : 1026 : gfc_add_modify (&cond_block, val, fold_convert (val_ty, else_val));
1553 : 1026 : else_b = gfc_finish_block (&cond_block);
1554 : : }
1555 : 1026 : gfc_add_expr_to_block (block,
1556 : : build3_loc (input_location, COND_EXPR, void_type_node,
1557 : : cond_val, then_b, else_b));
1558 : 1026 : }
1559 : :
1560 : : /* Build a conditional expression in BLOCK, returning a temporary
1561 : : variable containing the result. If COND_VAL is not null, then
1562 : : THEN_VAL will be assigned to the variable, otherwise ELSE_VAL
1563 : : is assigned.
1564 : : */
1565 : :
1566 : : static tree
1567 : 1025 : gfc_build_cond_assign_expr (stmtblock_t *block, tree cond_val,
1568 : : tree then_val, tree else_val)
1569 : : {
1570 : 1025 : tree val;
1571 : 1025 : tree val_ty = TREE_TYPE (then_val);
1572 : 1025 : stmtblock_t cond_block;
1573 : :
1574 : 1025 : val = create_tmp_var (val_ty);
1575 : :
1576 : 1025 : gfc_init_block (&cond_block);
1577 : 1025 : gfc_add_modify (&cond_block, val, then_val);
1578 : 1025 : tree then_b = gfc_finish_block (&cond_block);
1579 : :
1580 : 1025 : gfc_build_cond_assign (block, val, cond_val, then_b, else_val);
1581 : :
1582 : 1025 : return val;
1583 : : }
1584 : :
1585 : : void
1586 : 28576 : gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc)
1587 : : {
1588 : 28576 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
1589 : : return;
1590 : :
1591 : 6922 : tree decl = OMP_CLAUSE_DECL (c);
1592 : 6922 : location_t loc = OMP_CLAUSE_LOCATION (c);
1593 : :
1594 : : /* Assumed-size arrays can't be mapped implicitly, they have to be
1595 : : mapped explicitly using array sections. */
1596 : 6922 : if (TREE_CODE (decl) == PARM_DECL
1597 : 1045 : && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
1598 : 369 : && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
1599 : 7291 : && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
1600 : : GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
1601 : : == NULL)
1602 : : {
1603 : 1 : error_at (OMP_CLAUSE_LOCATION (c),
1604 : : "implicit mapping of assumed size array %qD", decl);
1605 : 1 : return;
1606 : : }
1607 : :
1608 : 6921 : tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
1609 : 6921 : tree present = gfc_omp_check_optional_argument (decl, true);
1610 : 6921 : tree orig_decl = NULL_TREE;
1611 : 6921 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
1612 : : {
1613 : 1297 : if (!gfc_omp_privatize_by_reference (decl)
1614 : 167 : && !GFC_DECL_GET_SCALAR_POINTER (decl)
1615 : 103 : && !GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
1616 : 3 : && !GFC_DECL_CRAY_POINTEE (decl)
1617 : 1300 : && !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
1618 : : return;
1619 : 1294 : orig_decl = decl;
1620 : :
1621 : 1294 : c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1622 : 1294 : OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
1623 : 1294 : OMP_CLAUSE_DECL (c4) = decl;
1624 : 1294 : OMP_CLAUSE_SIZE (c4) = size_int (0);
1625 : 1294 : decl = build_fold_indirect_ref (decl);
1626 : 1294 : if (present
1627 : 1294 : && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
1628 : 269 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
1629 : : {
1630 : 67 : c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
1631 : 67 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER);
1632 : 67 : OMP_CLAUSE_DECL (c2) = unshare_expr (decl);
1633 : 67 : OMP_CLAUSE_SIZE (c2) = size_int (0);
1634 : :
1635 : 67 : stmtblock_t block;
1636 : 67 : gfc_start_block (&block);
1637 : 67 : tree ptr = gfc_build_cond_assign_expr (&block, present,
1638 : : unshare_expr (decl),
1639 : : null_pointer_node);
1640 : 67 : gimplify_and_add (gfc_finish_block (&block), pre_p);
1641 : 67 : ptr = build_fold_indirect_ref (ptr);
1642 : 67 : OMP_CLAUSE_DECL (c) = ptr;
1643 : 67 : OMP_CLAUSE_SIZE (c) = TYPE_SIZE_UNIT (TREE_TYPE (ptr));
1644 : : }
1645 : : else
1646 : : {
1647 : 1227 : OMP_CLAUSE_DECL (c) = decl;
1648 : 1227 : OMP_CLAUSE_SIZE (c) = NULL_TREE;
1649 : : }
1650 : 1294 : if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
1651 : 1294 : && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
1652 : 391 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
1653 : : {
1654 : 67 : c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1655 : 67 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_POINTER);
1656 : 67 : OMP_CLAUSE_DECL (c3) = decl;
1657 : 67 : OMP_CLAUSE_SIZE (c3) = size_int (0);
1658 : 67 : decl = build_fold_indirect_ref (decl);
1659 : 67 : OMP_CLAUSE_DECL (c) = unshare_expr (decl);
1660 : : }
1661 : : }
1662 : 6918 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
1663 : : {
1664 : 1732 : stmtblock_t block;
1665 : 1732 : gfc_start_block (&block);
1666 : 1732 : tree type = TREE_TYPE (decl);
1667 : 1732 : tree ptr = gfc_conv_descriptor_data_get (decl);
1668 : :
1669 : : /* OpenMP: automatically map pointer targets with the pointer;
1670 : : hence, always update the descriptor/pointer itself.
1671 : : NOTE: This also remaps the pointer for allocatable arrays with
1672 : : 'target' attribute which also don't have the 'restrict' qualifier. */
1673 : 1732 : bool always_modifier = false;
1674 : :
1675 : 1732 : if (!openacc
1676 : 1732 : && !(TYPE_QUALS (TREE_TYPE (ptr)) & TYPE_QUAL_RESTRICT))
1677 : : always_modifier = true;
1678 : :
1679 : 1732 : if (present)
1680 : 56 : ptr = gfc_build_cond_assign_expr (&block, present, ptr,
1681 : : null_pointer_node);
1682 : 1732 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
1683 : 1732 : ptr = build_fold_indirect_ref (ptr);
1684 : 1732 : OMP_CLAUSE_DECL (c) = ptr;
1685 : 1732 : c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
1686 : 1732 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_TO_PSET);
1687 : 1732 : if (present)
1688 : : {
1689 : 56 : ptr = create_tmp_var (TREE_TYPE (TREE_OPERAND (decl, 0)));
1690 : 56 : gfc_add_modify (&block, ptr, TREE_OPERAND (decl, 0));
1691 : :
1692 : 56 : OMP_CLAUSE_DECL (c2) = build_fold_indirect_ref (ptr);
1693 : : }
1694 : : else
1695 : 1676 : OMP_CLAUSE_DECL (c2) = decl;
1696 : 1732 : OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (type);
1697 : 1732 : c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1698 : 3250 : OMP_CLAUSE_SET_MAP_KIND (c3, always_modifier ? GOMP_MAP_ALWAYS_POINTER
1699 : : : GOMP_MAP_POINTER);
1700 : 1732 : if (present)
1701 : : {
1702 : 56 : ptr = gfc_conv_descriptor_data_get (unshare_expr (decl));
1703 : 56 : ptr = gfc_build_addr_expr (NULL, ptr);
1704 : 56 : ptr = gfc_build_cond_assign_expr (&block, present,
1705 : : ptr, null_pointer_node);
1706 : 56 : ptr = build_fold_indirect_ref (ptr);
1707 : 56 : OMP_CLAUSE_DECL (c3) = ptr;
1708 : : }
1709 : : else
1710 : 1676 : OMP_CLAUSE_DECL (c3) = gfc_conv_descriptor_data_get (decl);
1711 : 1732 : OMP_CLAUSE_SIZE (c3) = size_int (0);
1712 : 1732 : tree size = create_tmp_var (gfc_array_index_type);
1713 : 1732 : tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
1714 : 1732 : elemsz = fold_convert (gfc_array_index_type, elemsz);
1715 : :
1716 : 1732 : if (orig_decl == NULL_TREE)
1717 : 1498 : orig_decl = decl;
1718 : 1732 : if (!openacc
1719 : 1732 : && gfc_has_alloc_comps (type, orig_decl, true))
1720 : : {
1721 : : /* Save array descriptor for use in gfc_omp_deep_mapping{,_p,_cnt};
1722 : : force evaluate to ensure that it is not gimplified + is a decl. */
1723 : 3 : gfc_allocate_lang_decl (size);
1724 : 3 : GFC_DECL_SAVED_DESCRIPTOR (size) = orig_decl;
1725 : : }
1726 : 1732 : enum gfc_array_kind akind = GFC_TYPE_ARRAY_AKIND (type);
1727 : 1732 : if (akind == GFC_ARRAY_ALLOCATABLE
1728 : : || akind == GFC_ARRAY_POINTER
1729 : 1732 : || akind == GFC_ARRAY_POINTER_CONT
1730 : 1732 : || akind == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
1731 : : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER
1732 : 1 : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT)
1733 : : {
1734 : 1731 : stmtblock_t cond_block;
1735 : 1731 : tree tem, then_b, else_b, zero, cond;
1736 : :
1737 : 1731 : int rank = ((akind == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
1738 : : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER
1739 : 1731 : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT)
1740 : 1731 : ? -1 : GFC_TYPE_ARRAY_RANK (type));
1741 : 1731 : gfc_init_block (&cond_block);
1742 : 1731 : tem = gfc_full_array_size (&cond_block, unshare_expr (decl), rank);
1743 : 1731 : gfc_add_modify (&cond_block, size, tem);
1744 : 1731 : gfc_add_modify (&cond_block, size,
1745 : : fold_build2 (MULT_EXPR, gfc_array_index_type,
1746 : : size, elemsz));
1747 : 1731 : then_b = gfc_finish_block (&cond_block);
1748 : 1731 : gfc_init_block (&cond_block);
1749 : 1731 : zero = build_int_cst (gfc_array_index_type, 0);
1750 : 1731 : gfc_add_modify (&cond_block, size, zero);
1751 : 1731 : else_b = gfc_finish_block (&cond_block);
1752 : 1731 : tem = gfc_conv_descriptor_data_get (unshare_expr (decl));
1753 : 1731 : tem = fold_convert (pvoid_type_node, tem);
1754 : 1731 : cond = fold_build2_loc (loc, NE_EXPR,
1755 : : boolean_type_node, tem, null_pointer_node);
1756 : 1731 : if (present)
1757 : : {
1758 : 55 : cond = fold_build2_loc (loc, TRUTH_ANDIF_EXPR,
1759 : : boolean_type_node, present, cond);
1760 : : }
1761 : 1731 : gfc_add_expr_to_block (&block, build3_loc (loc, COND_EXPR,
1762 : : void_type_node, cond,
1763 : : then_b, else_b));
1764 : 1731 : }
1765 : 1 : else if (present)
1766 : : {
1767 : 1 : stmtblock_t cond_block;
1768 : 1 : tree then_b;
1769 : :
1770 : 1 : int rank = ((akind == GFC_ARRAY_ASSUMED_RANK
1771 : 1 : || akind == GFC_ARRAY_ASSUMED_RANK_CONT)
1772 : 1 : ? -1 : GFC_TYPE_ARRAY_RANK (type));
1773 : 1 : gfc_init_block (&cond_block);
1774 : 1 : gfc_add_modify (&cond_block, size,
1775 : : gfc_full_array_size (&cond_block, unshare_expr (decl),
1776 : : rank));
1777 : 1 : gfc_add_modify (&cond_block, size,
1778 : : fold_build2 (MULT_EXPR, gfc_array_index_type,
1779 : : size, elemsz));
1780 : 1 : then_b = gfc_finish_block (&cond_block);
1781 : :
1782 : 1 : gfc_build_cond_assign (&block, size, present, then_b,
1783 : : build_int_cst (gfc_array_index_type, 0));
1784 : : }
1785 : : else
1786 : : {
1787 : 0 : int rank = ((akind == GFC_ARRAY_ASSUMED_RANK
1788 : 0 : || akind == GFC_ARRAY_ASSUMED_RANK_CONT)
1789 : 0 : ? -1 : GFC_TYPE_ARRAY_RANK (type));
1790 : 0 : gfc_add_modify (&block, size,
1791 : : gfc_full_array_size (&block, unshare_expr (decl),
1792 : : rank));
1793 : 0 : gfc_add_modify (&block, size,
1794 : : fold_build2 (MULT_EXPR, gfc_array_index_type,
1795 : : size, elemsz));
1796 : : }
1797 : 1732 : OMP_CLAUSE_SIZE (c) = size;
1798 : 1732 : tree stmt = gfc_finish_block (&block);
1799 : 1732 : gimplify_and_add (stmt, pre_p);
1800 : : }
1801 : : else
1802 : : {
1803 : 5186 : if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
1804 : 1203 : OMP_CLAUSE_SIZE (c)
1805 : 3399 : = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
1806 : 993 : : TYPE_SIZE_UNIT (TREE_TYPE (decl));
1807 : :
1808 : 5186 : tree type = TREE_TYPE (decl);
1809 : 5186 : if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE (type)))
1810 : 0 : type = TREE_TYPE (type);
1811 : 5186 : if (!openacc
1812 : 5186 : && orig_decl != NULL_TREE
1813 : 5186 : && gfc_has_alloc_comps (type, orig_decl, true))
1814 : : {
1815 : : /* Save array descriptor for use in gfc_omp_deep_mapping{,_p,_cnt};
1816 : : force evaluate to ensure that it is not gimplified + is a decl. */
1817 : 28 : tree size = create_tmp_var (TREE_TYPE (OMP_CLAUSE_SIZE (c)));
1818 : 28 : gfc_allocate_lang_decl (size);
1819 : 28 : GFC_DECL_SAVED_DESCRIPTOR (size) = orig_decl;
1820 : 28 : gimplify_assign (size, OMP_CLAUSE_SIZE (c), pre_p);
1821 : 28 : OMP_CLAUSE_SIZE (c) = size;
1822 : : }
1823 : : }
1824 : 6918 : tree last = c;
1825 : 6918 : if (gimplify_expr (&OMP_CLAUSE_SIZE (c), pre_p,
1826 : : NULL, is_gimple_val, fb_rvalue) == GS_ERROR)
1827 : 0 : OMP_CLAUSE_SIZE (c) = size_int (0);
1828 : 6918 : if (c2)
1829 : : {
1830 : 1799 : OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (last);
1831 : 1799 : OMP_CLAUSE_CHAIN (last) = c2;
1832 : 1799 : last = c2;
1833 : : }
1834 : 6918 : if (c3)
1835 : : {
1836 : 1799 : OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (last);
1837 : 1799 : OMP_CLAUSE_CHAIN (last) = c3;
1838 : 1799 : last = c3;
1839 : : }
1840 : 6918 : if (c4)
1841 : : {
1842 : 1294 : OMP_CLAUSE_CHAIN (c4) = OMP_CLAUSE_CHAIN (last);
1843 : 1294 : OMP_CLAUSE_CHAIN (last) = c4;
1844 : : }
1845 : : }
1846 : :
1847 : :
1848 : : /* map(<flag>: data [len: <size>])
1849 : : map(attach: &data [bias: <bias>])
1850 : : offset += 2; offset_data += 2 */
1851 : : static void
1852 : 509 : gfc_omp_deep_mapping_map (tree data, tree size, unsigned HOST_WIDE_INT tkind,
1853 : : location_t loc, tree data_array, tree sizes_array,
1854 : : tree kinds_array, tree offset_data, tree offset,
1855 : : gimple_seq *seq, const gimple *ctx)
1856 : : {
1857 : 509 : tree one = build_int_cst (size_type_node, 1);
1858 : :
1859 : 509 : STRIP_NOPS (data);
1860 : 509 : if (!POINTER_TYPE_P (TREE_TYPE (data)))
1861 : : {
1862 : 275 : gcc_assert (TREE_CODE (data) == INDIRECT_REF);
1863 : 275 : data = TREE_OPERAND (data, 0);
1864 : : }
1865 : :
1866 : : /* data_array[offset_data] = data; */
1867 : 509 : tree tmp = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (data_array)),
1868 : : unshare_expr (data_array), offset_data,
1869 : : NULL_TREE, NULL_TREE);
1870 : 509 : gimplify_assign (tmp, data, seq);
1871 : :
1872 : : /* offset_data++ */
1873 : 509 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset_data, one);
1874 : 509 : gimplify_assign (offset_data, tmp, seq);
1875 : :
1876 : : /* data_array[offset_data] = &data; */
1877 : 509 : tmp = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (data_array)),
1878 : : unshare_expr (data_array),
1879 : : offset_data, NULL_TREE, NULL_TREE);
1880 : 509 : gimplify_assign (tmp, build_fold_addr_expr (data), seq);
1881 : :
1882 : : /* offset_data++ */
1883 : 509 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset_data, one);
1884 : 509 : gimplify_assign (offset_data, tmp, seq);
1885 : :
1886 : : /* sizes_array[offset] = size */
1887 : 509 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1888 : 509 : TYPE_SIZE_UNIT (size_type_node), offset);
1889 : 509 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (sizes_array),
1890 : : sizes_array, tmp);
1891 : 509 : gimple_seq seq2 = NULL;
1892 : 509 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1893 : 509 : gimple_seq_add_seq (seq, seq2);
1894 : 509 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1895 : 509 : gimplify_assign (tmp, size, seq);
1896 : :
1897 : : /* FIXME: tkind |= talign << talign_shift; */
1898 : : /* kinds_array[offset] = tkind. */
1899 : 509 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1900 : 509 : TYPE_SIZE_UNIT (short_unsigned_type_node), offset);
1901 : 509 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (kinds_array),
1902 : : kinds_array, tmp);
1903 : 509 : seq2 = NULL;
1904 : 509 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1905 : 509 : gimple_seq_add_seq (seq, seq2);
1906 : 509 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1907 : 509 : gimplify_assign (tmp, build_int_cst (short_unsigned_type_node, tkind), seq);
1908 : :
1909 : : /* offset++ */
1910 : 509 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset, one);
1911 : 509 : gimplify_assign (offset, tmp, seq);
1912 : :
1913 : : /* sizes_array[offset] = bias (= 0). */
1914 : 509 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1915 : 509 : TYPE_SIZE_UNIT (size_type_node), offset);
1916 : 509 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (sizes_array),
1917 : : sizes_array, tmp);
1918 : 509 : seq2 = NULL;
1919 : 509 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1920 : 509 : gimple_seq_add_seq (seq, seq2);
1921 : 509 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1922 : 509 : gimplify_assign (tmp, build_zero_cst (size_type_node), seq);
1923 : :
1924 : 509 : gcc_assert (gimple_code (ctx) == GIMPLE_OMP_TARGET);
1925 : 509 : tkind = (gimple_omp_target_kind (ctx) == GF_OMP_TARGET_KIND_EXIT_DATA
1926 : 509 : ? GOMP_MAP_DETACH : GOMP_MAP_ATTACH);
1927 : :
1928 : : /* kinds_array[offset] = tkind. */
1929 : 509 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1930 : 509 : TYPE_SIZE_UNIT (short_unsigned_type_node), offset);
1931 : 509 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (kinds_array),
1932 : : kinds_array, tmp);
1933 : 509 : seq2 = NULL;
1934 : 509 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1935 : 509 : gimple_seq_add_seq (seq, seq2);
1936 : 509 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1937 : 509 : gimplify_assign (tmp, build_int_cst (short_unsigned_type_node, tkind), seq);
1938 : :
1939 : : /* offset++ */
1940 : 509 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset, one);
1941 : 509 : gimplify_assign (offset, tmp, seq);
1942 : 509 : }
1943 : :
1944 : : static void gfc_omp_deep_mapping_item (bool, bool, bool, location_t, tree,
1945 : : tree *, unsigned HOST_WIDE_INT, tree,
1946 : : tree, tree, tree, tree, tree,
1947 : : gimple_seq *, const gimple *, bool *);
1948 : :
1949 : : /* Map allocatable components. */
1950 : : static void
1951 : 1050 : gfc_omp_deep_mapping_comps (bool is_cnt, location_t loc, tree decl,
1952 : : tree *token, unsigned HOST_WIDE_INT tkind,
1953 : : tree data_array, tree sizes_array, tree kinds_array,
1954 : : tree offset_data, tree offset, tree num,
1955 : : gimple_seq *seq, const gimple *ctx,
1956 : : bool *poly_warned)
1957 : : {
1958 : 1050 : tree type = TREE_TYPE (decl);
1959 : 1050 : if (TREE_CODE (type) != RECORD_TYPE)
1960 : : return;
1961 : 2670 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1962 : : {
1963 : 1624 : type = TREE_TYPE (field);
1964 : 1624 : if (gfc_is_polymorphic_nonptr (type)
1965 : 1222 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (field)
1966 : 2548 : || (GFC_DESCRIPTOR_TYPE_P (type)
1967 : 258 : && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE))
1968 : : {
1969 : 958 : tree tmp = fold_build3_loc (loc, COMPONENT_REF, TREE_TYPE (field),
1970 : : decl, field, NULL_TREE);
1971 : 958 : gfc_omp_deep_mapping_item (is_cnt, true, true, loc, tmp, token,
1972 : : tkind, data_array, sizes_array,
1973 : : kinds_array, offset_data, offset, num,
1974 : : seq, ctx, poly_warned);
1975 : : }
1976 : 666 : else if (GFC_DECL_GET_SCALAR_POINTER (field)
1977 : 666 : || GFC_DESCRIPTOR_TYPE_P (type))
1978 : 0 : continue;
1979 : 666 : else if (gfc_has_alloc_comps (TREE_TYPE (field), field, false))
1980 : : {
1981 : 160 : tree tmp = fold_build3_loc (loc, COMPONENT_REF, TREE_TYPE (field),
1982 : : decl, field, NULL_TREE);
1983 : 160 : if (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1984 : 80 : gfc_omp_deep_mapping_item (is_cnt, false, false, loc, tmp,
1985 : : token, tkind, data_array, sizes_array,
1986 : : kinds_array, offset_data, offset, num,
1987 : : seq, ctx, poly_warned);
1988 : : else
1989 : 80 : gfc_omp_deep_mapping_comps (is_cnt, loc, tmp, token, tkind,
1990 : : data_array, sizes_array, kinds_array,
1991 : : offset_data, offset, num, seq, ctx,
1992 : : poly_warned);
1993 : : }
1994 : : }
1995 : : }
1996 : :
1997 : : static void
1998 : 760 : gfc_omp_gen_simple_loop (tree var, tree begin, tree end, enum tree_code cond,
1999 : : tree step, location_t loc, gimple_seq *seq1,
2000 : : gimple_seq *seq2)
2001 : : {
2002 : 760 : tree tmp;
2003 : :
2004 : : /* var = begin. */
2005 : 760 : gimplify_assign (var, begin, seq1);
2006 : :
2007 : : /* Loop: for (var = begin; var <cond> end; var += step). */
2008 : 760 : tree label_loop = create_artificial_label (loc);
2009 : 760 : tree label_cond = create_artificial_label (loc);
2010 : :
2011 : 760 : gimplify_and_add (fold_build1_loc (loc, GOTO_EXPR, void_type_node,
2012 : : label_cond), seq1);
2013 : 760 : gimple_seq_add_stmt (seq1, gimple_build_label (label_loop));
2014 : :
2015 : : /* Everything above is seq1; place loop body here. */
2016 : :
2017 : : /* End of loop body -> put into seq2. */
2018 : 760 : tmp = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (var), var, step);
2019 : 760 : gimplify_assign (var, tmp, seq2);
2020 : 760 : gimple_seq_add_stmt (seq2, gimple_build_label (label_cond));
2021 : 760 : tmp = fold_build2_loc (loc, cond, boolean_type_node, var, end);
2022 : 760 : tmp = build3_v (COND_EXPR, tmp, build1_v (GOTO_EXPR, label_loop),
2023 : : build_empty_stmt (loc));
2024 : 760 : gimplify_and_add (tmp, seq2);
2025 : 760 : }
2026 : :
2027 : : /* Return size variable with the size of an array. */
2028 : : static tree
2029 : 392 : gfc_omp_get_array_size (location_t loc, tree desc, gimple_seq *seq)
2030 : : {
2031 : 392 : tree tmp;
2032 : 392 : gimple_seq seq1 = NULL, seq2 = NULL;
2033 : 392 : tree size = build_decl (loc, VAR_DECL, create_tmp_var_name ("size"),
2034 : : size_type_node);
2035 : 392 : tree extent = build_decl (loc, VAR_DECL, create_tmp_var_name ("extent"),
2036 : : gfc_array_index_type);
2037 : 392 : tree idx = build_decl (loc, VAR_DECL, create_tmp_var_name ("idx"),
2038 : : signed_char_type_node);
2039 : :
2040 : 392 : tree begin = build_zero_cst (signed_char_type_node);
2041 : 392 : tree end;
2042 : 392 : if (GFC_TYPE_ARRAY_AKIND (TREE_TYPE (desc)) == GFC_ARRAY_ASSUMED_SHAPE_CONT
2043 : 392 : || GFC_TYPE_ARRAY_AKIND (TREE_TYPE (desc)) == GFC_ARRAY_ASSUMED_SHAPE)
2044 : 8 : end = gfc_conv_descriptor_rank (desc);
2045 : : else
2046 : 384 : end = build_int_cst (signed_char_type_node,
2047 : 384 : GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc)));
2048 : 392 : tree step = build_int_cst (signed_char_type_node, 1);
2049 : :
2050 : : /* size = 0
2051 : : for (idx = 0; idx < rank; idx++)
2052 : : extent = gfc->dim[i].ubound - gfc->dim[i].lbound + 1
2053 : : if (extent < 0) extent = 0
2054 : : size *= extent. */
2055 : 392 : gimplify_assign (size, build_int_cst (size_type_node, 1), seq);
2056 : :
2057 : 392 : gfc_omp_gen_simple_loop (idx, begin, end, LT_EXPR, step, loc, &seq1, &seq2);
2058 : 392 : gimple_seq_add_seq (seq, seq1);
2059 : :
2060 : 392 : tmp = fold_build2_loc (loc, MINUS_EXPR, gfc_array_index_type,
2061 : : gfc_conv_descriptor_ubound_get (desc, idx),
2062 : : gfc_conv_descriptor_lbound_get (desc, idx));
2063 : 392 : tmp = fold_build2_loc (loc, PLUS_EXPR, gfc_array_index_type,
2064 : : tmp, gfc_index_one_node);
2065 : 392 : gimplify_assign (extent, tmp, seq);
2066 : 392 : tmp = fold_build2_loc (loc, LT_EXPR, boolean_type_node,
2067 : : extent, gfc_index_zero_node);
2068 : 392 : tmp = build3_v (COND_EXPR, tmp,
2069 : : fold_build2_loc (loc, MODIFY_EXPR,
2070 : : gfc_array_index_type,
2071 : : extent, gfc_index_zero_node),
2072 : : build_empty_stmt (loc));
2073 : 392 : gimplify_and_add (tmp, seq);
2074 : : /* size *= extent. */
2075 : 392 : gimplify_assign (size, fold_build2_loc (loc, MULT_EXPR, size_type_node, size,
2076 : : fold_convert (size_type_node,
2077 : : extent)), seq);
2078 : 392 : gimple_seq_add_seq (seq, seq2);
2079 : 392 : return size;
2080 : : }
2081 : :
2082 : : /* Generate loop to access every array element; takes addr of first element
2083 : : (decl's data comp); returns loop code in seq1 + seq2
2084 : : and the pointer to the element as return value. */
2085 : : static tree
2086 : 368 : gfc_omp_elmental_loop (location_t loc, tree decl, tree size, tree elem_len,
2087 : : gimple_seq *seq1, gimple_seq *seq2)
2088 : : {
2089 : 368 : tree idx = build_decl (loc, VAR_DECL, create_tmp_var_name ("idx"),
2090 : : size_type_node);
2091 : 368 : tree begin = build_zero_cst (size_type_node);
2092 : 368 : tree end = size;
2093 : 368 : tree step = build_int_cst (size_type_node, 1);
2094 : 368 : tree ptr;
2095 : :
2096 : 368 : gfc_omp_gen_simple_loop (idx, begin, end, LT_EXPR, step, loc, seq1, seq2);
2097 : :
2098 : 368 : tree type = TREE_TYPE (decl);
2099 : 368 : if (POINTER_TYPE_P (type))
2100 : : {
2101 : 284 : type = TREE_TYPE (type);
2102 : 284 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2103 : 284 : decl = fold_convert (build_pointer_type (TREE_TYPE (type)), decl);
2104 : : }
2105 : : else
2106 : : {
2107 : 84 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2108 : 84 : decl = build_fold_addr_expr_loc (loc, decl);
2109 : : }
2110 : 368 : decl = fold_convert (build_pointer_type (TREE_TYPE (type)), decl);
2111 : 368 : tree tmp = build2_loc (loc, MULT_EXPR, size_type_node, idx,
2112 : : fold_convert (size_type_node, elem_len));
2113 : 368 : ptr = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (decl), decl, tmp);
2114 : 368 : gimple_seq seq3 = NULL;
2115 : 368 : ptr = force_gimple_operand (ptr, &seq3, true, NULL_TREE);
2116 : 368 : gimple_seq_add_seq (seq1, seq3);
2117 : :
2118 : 368 : return ptr;
2119 : : }
2120 : :
2121 : :
2122 : : /* If do_copy, copy data pointer and vptr (if applicable) as well.
2123 : : Otherwise, only handle allocatable components.
2124 : : do_copy == false can happen only with nonpolymorphic arguments
2125 : : to a copy clause.
2126 : : if (is_cnt) token ... offset is ignored and num is used, otherwise
2127 : : num is NULL_TREE and unused. */
2128 : :
2129 : : static void
2130 : 1404 : gfc_omp_deep_mapping_item (bool is_cnt, bool do_copy, bool do_alloc_check,
2131 : : location_t loc, tree decl, tree *token,
2132 : : unsigned HOST_WIDE_INT tkind, tree data_array,
2133 : : tree sizes_array, tree kinds_array, tree offset_data,
2134 : : tree offset, tree num, gimple_seq *seq,
2135 : : const gimple *ctx, bool *poly_warned)
2136 : : {
2137 : 1404 : tree tmp;
2138 : 1404 : tree type = TREE_TYPE (decl);
2139 : 1404 : if (POINTER_TYPE_P (type))
2140 : 496 : type = TREE_TYPE (type);
2141 : 1404 : tree end_label = NULL_TREE;
2142 : 1404 : tree size = NULL_TREE, elem_len = NULL_TREE;
2143 : :
2144 : 1404 : bool poly = gfc_is_polymorphic_nonptr (type);
2145 : 1404 : if (poly && is_cnt && !*poly_warned)
2146 : : {
2147 : 71 : if (gfc_is_unlimited_polymorphic_nonptr (type))
2148 : 2 : error_at (loc,
2149 : : "Mapping of unlimited polymorphic list item %qD is "
2150 : : "unspecified behavior and unsupported", decl);
2151 : :
2152 : : else
2153 : 69 : warning_at (loc, OPT_Wopenmp,
2154 : : "Mapping of polymorphic list item %qD is "
2155 : : "unspecified behavior", decl);
2156 : 71 : *poly_warned = true;
2157 : : }
2158 : 1404 : if (do_alloc_check)
2159 : : {
2160 : 1216 : tree then_label = create_artificial_label (loc);
2161 : 1216 : end_label = create_artificial_label (loc);
2162 : 1216 : tmp = decl;
2163 : 1216 : if (TREE_CODE (TREE_TYPE (tmp)) == REFERENCE_TYPE
2164 : 1216 : || (POINTER_TYPE_P (TREE_TYPE (tmp))
2165 : 476 : && (POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (tmp)))
2166 : 476 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (tmp))))))
2167 : 8 : tmp = build_fold_indirect_ref_loc (loc, tmp);
2168 : 1216 : if (poly)
2169 : 462 : tmp = gfc_class_data_get (tmp);
2170 : 1216 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
2171 : 492 : tmp = gfc_conv_descriptor_data_get (tmp);
2172 : 1216 : gimple_seq seq2 = NULL;
2173 : 1216 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
2174 : 1216 : gimple_seq_add_seq (seq, seq2);
2175 : :
2176 : 1216 : gimple_seq_add_stmt (seq,
2177 : 1216 : gimple_build_cond (NE_EXPR, tmp, null_pointer_node,
2178 : : then_label, end_label));
2179 : 1216 : gimple_seq_add_stmt (seq, gimple_build_label (then_label));
2180 : : }
2181 : 1404 : tree class_decl = decl;
2182 : 1404 : if (poly)
2183 : : {
2184 : 462 : decl = gfc_class_data_get (decl);
2185 : 462 : type = TREE_TYPE (decl);
2186 : : }
2187 : 1404 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
2188 : : {
2189 : 748 : decl = build_fold_indirect_ref (decl);
2190 : 748 : type = TREE_TYPE (decl);
2191 : : }
2192 : :
2193 : 1404 : if (is_cnt && do_copy)
2194 : : {
2195 : 509 : tree tmp = fold_build2_loc (loc, PLUS_EXPR, size_type_node,
2196 : : num, build_int_cst (size_type_node, 1));
2197 : 509 : gimplify_assign (num, tmp, seq);
2198 : : }
2199 : 895 : else if (do_copy)
2200 : : {
2201 : : /* copy data pointer */
2202 : 509 : tree bytesize;
2203 : 509 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2204 : : {
2205 : : /* TODO: Optimization: Shouldn't this be an expr. const, except for
2206 : : deferred-length strings. (Cf. also below). */
2207 : 234 : elem_len = (poly ? gfc_class_vtab_size_get (class_decl)
2208 : 129 : : gfc_conv_descriptor_elem_len (decl));
2209 : 468 : tmp = (POINTER_TYPE_P (TREE_TYPE (decl))
2210 : 234 : ? build_fold_indirect_ref (decl) : decl);
2211 : 234 : size = gfc_omp_get_array_size (loc, tmp, seq);
2212 : 234 : bytesize = fold_build2_loc (loc, MULT_EXPR, size_type_node,
2213 : : fold_convert (size_type_node, size),
2214 : : fold_convert (size_type_node, elem_len));
2215 : 234 : tmp = gfc_conv_descriptor_data_get (decl);
2216 : : }
2217 : 275 : else if (poly)
2218 : : {
2219 : 126 : tmp = decl;
2220 : 126 : bytesize = fold_convert (size_type_node,
2221 : : gfc_class_vtab_size_get (class_decl));
2222 : : }
2223 : : else
2224 : : {
2225 : 149 : tmp = decl;
2226 : 149 : bytesize = TYPE_SIZE_UNIT (TREE_TYPE (decl));
2227 : : }
2228 : 509 : unsigned HOST_WIDE_INT tkind2 = tkind;
2229 : 509 : if (!is_cnt
2230 : 509 : && (tkind == GOMP_MAP_ALLOC
2231 : 481 : || (tkind == GOMP_MAP_FROM
2232 : 88 : && (gimple_omp_target_kind (ctx)
2233 : : != GF_OMP_TARGET_KIND_EXIT_DATA)))
2234 : 553 : && gfc_omp_replace_alloc_by_to_mapping (TREE_TYPE (decl), decl, true))
2235 : 12 : tkind2 = tkind == GOMP_MAP_ALLOC ? GOMP_MAP_TO : GOMP_MAP_TOFROM;
2236 : :
2237 : 509 : gfc_omp_deep_mapping_map (tmp, bytesize, tkind2, loc, data_array,
2238 : : sizes_array, kinds_array, offset_data,
2239 : : offset, seq, ctx);
2240 : : }
2241 : :
2242 : 1404 : tmp = decl;
2243 : 1404 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
2244 : 0 : while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
2245 : 0 : tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2246 : 1404 : if (poly || gfc_has_alloc_comps (type, tmp, true))
2247 : : {
2248 : 970 : gimple_seq seq2 = NULL;
2249 : 970 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2250 : : {
2251 : 284 : if (elem_len == NULL_TREE)
2252 : : {
2253 : 158 : elem_len = gfc_conv_descriptor_elem_len (decl);
2254 : 158 : size = fold_convert (size_type_node,
2255 : : gfc_omp_get_array_size (loc, decl, seq));
2256 : : }
2257 : 284 : decl = gfc_conv_descriptor_data_get (decl);
2258 : 284 : decl = gfc_omp_elmental_loop (loc, decl, size, elem_len, seq, &seq2);
2259 : 284 : decl = build_fold_indirect_ref_loc (loc, decl);
2260 : : }
2261 : 686 : else if (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2262 : : {
2263 : 84 : type = TREE_TYPE (tmp);
2264 : : /* FIXME: PR95868 - for var%str of deferred length, elem_len == 0;
2265 : : len is stored as var%_str_length, but not in GFC_DECL_STRING_LEN
2266 : : nor in TYPE_SIZE_UNIT as expression. */
2267 : 84 : elem_len = TYPE_SIZE_UNIT (TREE_TYPE (type));
2268 : 84 : size = fold_convert (size_type_node, GFC_TYPE_ARRAY_SIZE (type));
2269 : 84 : decl = gfc_omp_elmental_loop (loc, decl, size, elem_len, seq, &seq2);
2270 : 84 : decl = build_fold_indirect_ref_loc (loc, decl);
2271 : : }
2272 : 602 : else if (POINTER_TYPE_P (TREE_TYPE (decl)))
2273 : 0 : decl = build_fold_indirect_ref (decl);
2274 : :
2275 : 970 : gfc_omp_deep_mapping_comps (is_cnt, loc, decl, token, tkind,
2276 : : data_array, sizes_array, kinds_array,
2277 : : offset_data, offset, num, seq, ctx,
2278 : : poly_warned);
2279 : 970 : gimple_seq_add_seq (seq, seq2);
2280 : : }
2281 : 1404 : if (end_label)
2282 : 1216 : gimple_seq_add_stmt (seq, gimple_build_label (end_label));
2283 : 1404 : }
2284 : :
2285 : :
2286 : : /* Which map types to check/handle for deep mapping. */
2287 : : static bool
2288 : 37186 : gfc_omp_deep_map_kind_p (tree clause)
2289 : : {
2290 : 37186 : switch (OMP_CLAUSE_CODE (clause))
2291 : : {
2292 : 33630 : case OMP_CLAUSE_MAP:
2293 : 33630 : break;
2294 : : case OMP_CLAUSE_FIRSTPRIVATE:
2295 : : case OMP_CLAUSE_TO:
2296 : : case OMP_CLAUSE_FROM:
2297 : : return true;
2298 : 0 : default:
2299 : 0 : gcc_unreachable ();
2300 : : }
2301 : :
2302 : 33630 : switch (OMP_CLAUSE_MAP_KIND (clause))
2303 : : {
2304 : : case GOMP_MAP_TO:
2305 : : case GOMP_MAP_FROM:
2306 : : case GOMP_MAP_TOFROM:
2307 : : case GOMP_MAP_ALWAYS_TO:
2308 : : case GOMP_MAP_ALWAYS_FROM:
2309 : : case GOMP_MAP_ALWAYS_TOFROM:
2310 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
2311 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
2312 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
2313 : : case GOMP_MAP_FIRSTPRIVATE:
2314 : : case GOMP_MAP_ALLOC:
2315 : : return true;
2316 : : case GOMP_MAP_POINTER:
2317 : : case GOMP_MAP_TO_PSET:
2318 : : case GOMP_MAP_FORCE_PRESENT:
2319 : : case GOMP_MAP_DELETE:
2320 : : case GOMP_MAP_FORCE_DEVICEPTR:
2321 : : case GOMP_MAP_DEVICE_RESIDENT:
2322 : : case GOMP_MAP_LINK:
2323 : : case GOMP_MAP_IF_PRESENT:
2324 : : case GOMP_MAP_PRESENT_ALLOC:
2325 : : case GOMP_MAP_PRESENT_FROM:
2326 : : case GOMP_MAP_PRESENT_TO:
2327 : : case GOMP_MAP_PRESENT_TOFROM:
2328 : : case GOMP_MAP_FIRSTPRIVATE_INT:
2329 : : case GOMP_MAP_USE_DEVICE_PTR:
2330 : : case GOMP_MAP_ZERO_LEN_ARRAY_SECTION:
2331 : : case GOMP_MAP_FORCE_ALLOC:
2332 : : case GOMP_MAP_FORCE_TO:
2333 : : case GOMP_MAP_FORCE_FROM:
2334 : : case GOMP_MAP_FORCE_TOFROM:
2335 : : case GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT:
2336 : : case GOMP_MAP_STRUCT:
2337 : : case GOMP_MAP_STRUCT_UNORD:
2338 : : case GOMP_MAP_ALWAYS_POINTER:
2339 : : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
2340 : : case GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION:
2341 : : case GOMP_MAP_RELEASE:
2342 : : case GOMP_MAP_ATTACH:
2343 : : case GOMP_MAP_DETACH:
2344 : : case GOMP_MAP_FORCE_DETACH:
2345 : : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
2346 : : case GOMP_MAP_FIRSTPRIVATE_POINTER:
2347 : : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
2348 : : case GOMP_MAP_ATTACH_DETACH:
2349 : : break;
2350 : 0 : default:
2351 : 0 : gcc_unreachable ();
2352 : : }
2353 : : return false;
2354 : : }
2355 : :
2356 : : /* Three OpenMP deep-mapping lang hooks: gfc_omp_deep_mapping{_p,_cnt,}. */
2357 : :
2358 : : /* Common check for gfc_omp_deep_mapping_p and gfc_omp_deep_mapping_do. */
2359 : :
2360 : : static tree
2361 : 88452 : gfc_omp_deep_mapping_int_p (const gimple *ctx, tree clause)
2362 : : {
2363 : 88452 : if (is_gimple_omp_oacc (ctx) || !gfc_omp_deep_map_kind_p (clause))
2364 : : return NULL_TREE;
2365 : 20425 : tree decl = OMP_CLAUSE_DECL (clause);
2366 : 20425 : if (OMP_CLAUSE_SIZE (clause) != NULL_TREE
2367 : 20415 : && DECL_P (OMP_CLAUSE_SIZE (clause))
2368 : 6649 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_SIZE (clause))
2369 : 20814 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (clause)))
2370 : : /* Saved decl. */
2371 : 389 : decl = GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (clause));
2372 : 20036 : else if (TREE_CODE (decl) == MEM_REF || TREE_CODE (decl) == INDIRECT_REF)
2373 : : /* The following can happen for, e.g., class(t) :: var(..) */
2374 : 11520 : decl = TREE_OPERAND (decl, 0);
2375 : 20425 : if (TREE_CODE (decl) == INDIRECT_REF)
2376 : : /* The following can happen for, e.g., class(t) :: var(..) */
2377 : 132 : decl = TREE_OPERAND (decl, 0);
2378 : 20425 : if (DECL_P (decl)
2379 : 12565 : && DECL_LANG_SPECIFIC (decl)
2380 : 22673 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
2381 : 62 : decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
2382 : : /* Handle map(to: var.desc) map([to/from/tofrom:] var.desc.data)
2383 : : to get proper map kind by skipping to the next item. */
2384 : 20425 : tree tmp = OMP_CLAUSE_CHAIN (clause);
2385 : 20425 : if (tmp != NULL_TREE
2386 : 15171 : && OMP_CLAUSE_CODE (tmp) == OMP_CLAUSE_CODE (clause)
2387 : 13645 : && OMP_CLAUSE_SIZE (tmp) != NULL_TREE
2388 : 13645 : && DECL_P (OMP_CLAUSE_SIZE (tmp))
2389 : 1390 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_SIZE (tmp))
2390 : 20497 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (tmp)) == decl)
2391 : : return NULL_TREE;
2392 : 20425 : if (DECL_P (decl)
2393 : 12565 : && DECL_LANG_SPECIFIC (decl)
2394 : 22640 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
2395 : 29 : decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
2396 : 20425 : tree type = TREE_TYPE (decl);
2397 : 20425 : if (POINTER_TYPE_P (type))
2398 : 12540 : type = TREE_TYPE (type);
2399 : 20425 : if (POINTER_TYPE_P (type))
2400 : 140 : type = TREE_TYPE (type);
2401 : 20425 : tmp = decl;
2402 : 22082 : while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
2403 : 2212 : tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2404 : 20425 : if (!gfc_is_polymorphic_nonptr (type)
2405 : 20425 : && !gfc_has_alloc_comps (type, tmp, true))
2406 : : return NULL_TREE;
2407 : : return decl;
2408 : : }
2409 : :
2410 : : /* Return true if there is deep mapping, even if the number of mapping is known
2411 : : at compile time. */
2412 : : bool
2413 : 42749 : gfc_omp_deep_mapping_p (const gimple *ctx, tree clause)
2414 : : {
2415 : 42749 : tree decl = gfc_omp_deep_mapping_int_p (ctx, clause);
2416 : 42749 : if (decl == NULL_TREE)
2417 : 42625 : return false;
2418 : : return true;
2419 : : }
2420 : :
2421 : : /* Handle gfc_omp_deep_mapping{,_cnt} */
2422 : : static tree
2423 : 45679 : gfc_omp_deep_mapping_do (bool is_cnt, const gimple *ctx, tree clause,
2424 : : unsigned HOST_WIDE_INT tkind, tree data, tree sizes,
2425 : : tree kinds, tree offset_data, tree offset,
2426 : : gimple_seq *seq)
2427 : : {
2428 : 45679 : tree num = NULL_TREE;
2429 : 45679 : location_t loc = OMP_CLAUSE_LOCATION (clause);
2430 : 45679 : tree decl = gfc_omp_deep_mapping_int_p (ctx, clause);
2431 : 45679 : bool poly_warned = false;
2432 : 45679 : if (decl == NULL_TREE)
2433 : : return NULL_TREE;
2434 : : /* Handle: map(alloc:dt%cmp [len: ptr_size]) map(tofrom: D.0123...),
2435 : : where GFC_DECL_SAVED_DESCRIPTOR(D.0123) is the same (here: dt%cmp). */
2436 : 378 : if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
2437 : 378 : && (OMP_CLAUSE_MAP_KIND (clause) == GOMP_MAP_ALLOC
2438 : 334 : || OMP_CLAUSE_MAP_KIND (clause) == GOMP_MAP_PRESENT_ALLOC))
2439 : : {
2440 : : tree c = clause;
2441 : 84 : while ((c = OMP_CLAUSE_CHAIN (c)) != NULL_TREE)
2442 : : {
2443 : 60 : if (!gfc_omp_deep_map_kind_p (c))
2444 : 36 : continue;
2445 : 24 : tree d = gfc_omp_deep_mapping_int_p (ctx, c);
2446 : 24 : if (d != NULL_TREE && operand_equal_p (decl, d, 0))
2447 : : return NULL_TREE;
2448 : : }
2449 : : }
2450 : 366 : tree type = TREE_TYPE (decl);
2451 : 366 : if (POINTER_TYPE_P (type))
2452 : 198 : type = TREE_TYPE (type);
2453 : 366 : if (POINTER_TYPE_P (type))
2454 : 8 : type = TREE_TYPE (type);
2455 : 366 : bool poly = gfc_is_polymorphic_nonptr (type);
2456 : :
2457 : 366 : if (is_cnt)
2458 : : {
2459 : 183 : num = build_decl (loc, VAR_DECL,
2460 : : create_tmp_var_name ("n_deepmap"), size_type_node);
2461 : 183 : tree tmp = fold_build2_loc (loc, MODIFY_EXPR, size_type_node, num,
2462 : : build_int_cst (size_type_node, 0));
2463 : 183 : gimple_add_tmp_var (num);
2464 : 183 : gimplify_and_add (tmp, seq);
2465 : : }
2466 : : else
2467 : 183 : gcc_assert (short_unsigned_type_node == TREE_TYPE (TREE_TYPE (kinds)));
2468 : :
2469 : 366 : bool do_copy = poly;
2470 : 366 : bool do_alloc_check = false;
2471 : 366 : tree token = NULL_TREE;
2472 : 366 : tree tmp = decl;
2473 : 366 : if (poly)
2474 : : {
2475 : 60 : tmp = TYPE_FIELDS (type);
2476 : 60 : type = TREE_TYPE (tmp);
2477 : : }
2478 : : else
2479 : 346 : while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
2480 : 48 : tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2481 : 366 : if (TREE_CODE (tmp) == MEM_REF)
2482 : 4 : tmp = TREE_OPERAND (tmp, 0);
2483 : 366 : if (TREE_CODE (tmp) == SSA_NAME)
2484 : : {
2485 : 4 : gimple *def_stmt = SSA_NAME_DEF_STMT (tmp);
2486 : 4 : if (gimple_code (def_stmt) == GIMPLE_ASSIGN)
2487 : : {
2488 : 4 : tmp = gimple_assign_rhs1 (def_stmt);
2489 : 4 : if (poly)
2490 : : {
2491 : 0 : tmp = TYPE_FIELDS (type);
2492 : 0 : type = TREE_TYPE (tmp);
2493 : : }
2494 : : else
2495 : 8 : while (TREE_CODE (tmp) == COMPONENT_REF
2496 : 8 : || TREE_CODE (tmp) == ARRAY_REF)
2497 : 4 : tmp = TREE_OPERAND (tmp,
2498 : : TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2499 : : }
2500 : : }
2501 : : /* If the clause argument is nonallocatable, skip is-allocate check. */
2502 : 366 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (tmp)
2503 : 158 : || GFC_DECL_GET_SCALAR_POINTER (tmp)
2504 : 380 : || (GFC_DESCRIPTOR_TYPE_P (type)
2505 : 42 : && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
2506 : 24 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
2507 : 8 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT)))
2508 : : do_alloc_check = true;
2509 : :
2510 : 366 : if (!is_cnt
2511 : 183 : && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
2512 : 179 : && (tkind == GOMP_MAP_ALLOC
2513 : 167 : || (tkind == GOMP_MAP_FROM
2514 : 29 : && (gimple_omp_target_kind (ctx)
2515 : : != GF_OMP_TARGET_KIND_EXIT_DATA)))
2516 : 402 : && (poly || gfc_omp_replace_alloc_by_to_mapping (type, tmp, true)))
2517 : 24 : OMP_CLAUSE_SET_MAP_KIND (clause, tkind == GOMP_MAP_ALLOC ? GOMP_MAP_TO
2518 : : : GOMP_MAP_TOFROM);
2519 : :
2520 : : /* TODO: For map(a(:)), we know it is present & allocated. */
2521 : :
2522 : 366 : tree present = (DECL_P (decl) ? gfc_omp_check_optional_argument (decl, true)
2523 : : : NULL_TREE);
2524 : 550 : if (POINTER_TYPE_P (TREE_TYPE (decl))
2525 : 382 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
2526 : 8 : decl = build_fold_indirect_ref (decl);
2527 : 366 : if (present)
2528 : : {
2529 : 16 : tree then_label = create_artificial_label (loc);
2530 : 16 : tree end_label = create_artificial_label (loc);
2531 : 16 : gimple_seq seq2 = NULL;
2532 : 16 : tmp = force_gimple_operand (present, &seq2, true, NULL_TREE);
2533 : 16 : gimple_seq_add_seq (seq, seq2);
2534 : 16 : gimple_seq_add_stmt (seq,
2535 : 16 : gimple_build_cond_from_tree (present,
2536 : : then_label, end_label));
2537 : 16 : gimple_seq_add_stmt (seq, gimple_build_label (then_label));
2538 : 16 : gfc_omp_deep_mapping_item (is_cnt, do_copy, do_alloc_check, loc, decl,
2539 : : &token, tkind, data, sizes, kinds,
2540 : : offset_data, offset, num, seq, ctx,
2541 : : &poly_warned);
2542 : 16 : gimple_seq_add_stmt (seq, gimple_build_label (end_label));
2543 : : }
2544 : : else
2545 : 350 : gfc_omp_deep_mapping_item (is_cnt, do_copy, do_alloc_check, loc, decl,
2546 : : &token, tkind, data, sizes, kinds, offset_data,
2547 : : offset, num, seq, ctx, &poly_warned);
2548 : : /* Multiply by 2 as there are two mappings: data + pointer assign. */
2549 : 366 : if (is_cnt)
2550 : 183 : gimplify_assign (num,
2551 : : fold_build2_loc (loc, MULT_EXPR,
2552 : : size_type_node, num,
2553 : : build_int_cst (size_type_node, 2)), seq);
2554 : : return num;
2555 : : }
2556 : :
2557 : : /* Return tree with a variable which contains the count of deep-mappyings
2558 : : (value depends, e.g., on allocation status) */
2559 : : tree
2560 : 45294 : gfc_omp_deep_mapping_cnt (const gimple *ctx, tree clause, gimple_seq *seq)
2561 : : {
2562 : 45294 : return gfc_omp_deep_mapping_do (true, ctx, clause, 0, NULL_TREE, NULL_TREE,
2563 : 45294 : NULL_TREE, NULL_TREE, NULL_TREE, seq);
2564 : : }
2565 : :
2566 : : /* Does the actual deep mapping. */
2567 : : void
2568 : 385 : gfc_omp_deep_mapping (const gimple *ctx, tree clause,
2569 : : unsigned HOST_WIDE_INT tkind, tree data,
2570 : : tree sizes, tree kinds, tree offset_data, tree offset,
2571 : : gimple_seq *seq)
2572 : : {
2573 : 385 : (void) gfc_omp_deep_mapping_do (false, ctx, clause, tkind, data, sizes, kinds,
2574 : : offset_data, offset, seq);
2575 : 385 : }
2576 : :
2577 : : /* Return true if DECL is a scalar variable (for the purpose of
2578 : : implicit firstprivatization/mapping). Only if 'ptr_alloc_ok.'
2579 : : is true, allocatables and pointers are permitted. */
2580 : :
2581 : : bool
2582 : 3646 : gfc_omp_scalar_p (tree decl, bool ptr_alloc_ok)
2583 : : {
2584 : 3646 : tree type = TREE_TYPE (decl);
2585 : 3646 : if (TREE_CODE (type) == REFERENCE_TYPE)
2586 : 1347 : type = TREE_TYPE (type);
2587 : 3646 : if (TREE_CODE (type) == POINTER_TYPE)
2588 : : {
2589 : 587 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
2590 : 587 : || GFC_DECL_GET_SCALAR_POINTER (decl))
2591 : : {
2592 : 150 : if (!ptr_alloc_ok)
2593 : : return false;
2594 : 0 : type = TREE_TYPE (type);
2595 : : }
2596 : 437 : if (GFC_ARRAY_TYPE_P (type)
2597 : 437 : || GFC_CLASS_TYPE_P (type))
2598 : : return false;
2599 : : }
2600 : 3098 : if ((TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE)
2601 : 5541 : && TYPE_STRING_FLAG (type))
2602 : : return false;
2603 : 3174 : if (INTEGRAL_TYPE_P (type)
2604 : 3174 : || SCALAR_FLOAT_TYPE_P (type)
2605 : 3174 : || COMPLEX_FLOAT_TYPE_P (type))
2606 : 2642 : return true;
2607 : : return false;
2608 : : }
2609 : :
2610 : :
2611 : : /* Return true if DECL is a scalar with target attribute but does not have the
2612 : : allocatable (or pointer) attribute (for the purpose of implicit mapping). */
2613 : :
2614 : : bool
2615 : 3538 : gfc_omp_scalar_target_p (tree decl)
2616 : : {
2617 : 3538 : return (DECL_P (decl) && GFC_DECL_GET_SCALAR_TARGET (decl)
2618 : 3639 : && gfc_omp_scalar_p (decl, false));
2619 : : }
2620 : :
2621 : :
2622 : : /* Return true if DECL's DECL_VALUE_EXPR (if any) should be
2623 : : disregarded in OpenMP construct, because it is going to be
2624 : : remapped during OpenMP lowering. SHARED is true if DECL
2625 : : is going to be shared, false if it is going to be privatized. */
2626 : :
2627 : : bool
2628 : 1618490 : gfc_omp_disregard_value_expr (tree decl, bool shared)
2629 : : {
2630 : 1618490 : if (GFC_DECL_COMMON_OR_EQUIV (decl)
2631 : 1618490 : && DECL_HAS_VALUE_EXPR_P (decl))
2632 : : {
2633 : 3030 : tree value = DECL_VALUE_EXPR (decl);
2634 : :
2635 : 3030 : if (TREE_CODE (value) == COMPONENT_REF
2636 : 3030 : && VAR_P (TREE_OPERAND (value, 0))
2637 : 6060 : && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
2638 : : {
2639 : : /* If variable in COMMON or EQUIVALENCE is privatized, return
2640 : : true, as just that variable is supposed to be privatized,
2641 : : not the whole COMMON or whole EQUIVALENCE.
2642 : : For shared variables in COMMON or EQUIVALENCE, let them be
2643 : : gimplified to DECL_VALUE_EXPR, so that for multiple shared vars
2644 : : from the same COMMON or EQUIVALENCE just one sharing of the
2645 : : whole COMMON or EQUIVALENCE is enough. */
2646 : 3030 : return ! shared;
2647 : : }
2648 : : }
2649 : :
2650 : 1615460 : if (GFC_DECL_RESULT (decl) && DECL_HAS_VALUE_EXPR_P (decl))
2651 : 334 : return ! shared;
2652 : :
2653 : : return false;
2654 : : }
2655 : :
2656 : : /* Return true if DECL that is shared iff SHARED is true should
2657 : : be put into OMP_CLAUSE_PRIVATE with OMP_CLAUSE_PRIVATE_DEBUG
2658 : : flag set. */
2659 : :
2660 : : bool
2661 : 38309 : gfc_omp_private_debug_clause (tree decl, bool shared)
2662 : : {
2663 : 38309 : if (GFC_DECL_CRAY_POINTEE (decl))
2664 : : return true;
2665 : :
2666 : 38273 : if (GFC_DECL_COMMON_OR_EQUIV (decl)
2667 : 38273 : && DECL_HAS_VALUE_EXPR_P (decl))
2668 : : {
2669 : 326 : tree value = DECL_VALUE_EXPR (decl);
2670 : :
2671 : 326 : if (TREE_CODE (value) == COMPONENT_REF
2672 : 326 : && VAR_P (TREE_OPERAND (value, 0))
2673 : 652 : && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
2674 : : return shared;
2675 : : }
2676 : :
2677 : : return false;
2678 : : }
2679 : :
2680 : : /* Register language specific type size variables as potentially OpenMP
2681 : : firstprivate variables. */
2682 : :
2683 : : void
2684 : 21650 : gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *ctx, tree type)
2685 : : {
2686 : 21650 : if (GFC_ARRAY_TYPE_P (type) || GFC_DESCRIPTOR_TYPE_P (type))
2687 : : {
2688 : 3965 : int r;
2689 : :
2690 : 3965 : gcc_assert (TYPE_LANG_SPECIFIC (type) != NULL);
2691 : 9128 : for (r = 0; r < GFC_TYPE_ARRAY_RANK (type); r++)
2692 : : {
2693 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_LBOUND (type, r));
2694 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_UBOUND (type, r));
2695 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_STRIDE (type, r));
2696 : : }
2697 : 3965 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_SIZE (type));
2698 : 3965 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_OFFSET (type));
2699 : : }
2700 : 21650 : }
2701 : :
2702 : :
2703 : : static inline tree
2704 : 73734 : gfc_trans_add_clause (tree node, tree tail)
2705 : : {
2706 : 73734 : OMP_CLAUSE_CHAIN (node) = tail;
2707 : 73734 : return node;
2708 : : }
2709 : :
2710 : : static tree
2711 : 42742 : gfc_trans_omp_variable (gfc_symbol *sym, bool declare_simd)
2712 : : {
2713 : 42742 : if (declare_simd)
2714 : : {
2715 : 182 : int cnt = 0;
2716 : 182 : gfc_symbol *proc_sym;
2717 : 182 : gfc_formal_arglist *f;
2718 : :
2719 : 182 : gcc_assert (sym->attr.dummy);
2720 : 182 : proc_sym = sym->ns->proc_name;
2721 : 182 : if (proc_sym->attr.entry_master)
2722 : 0 : ++cnt;
2723 : 182 : if (gfc_return_by_reference (proc_sym))
2724 : : {
2725 : 0 : ++cnt;
2726 : 0 : if (proc_sym->ts.type == BT_CHARACTER)
2727 : 0 : ++cnt;
2728 : : }
2729 : 349 : for (f = gfc_sym_get_dummy_args (proc_sym); f; f = f->next)
2730 : 349 : if (f->sym == sym)
2731 : : break;
2732 : 167 : else if (f->sym)
2733 : 167 : ++cnt;
2734 : 182 : gcc_assert (f);
2735 : 182 : return build_int_cst (integer_type_node, cnt);
2736 : : }
2737 : :
2738 : 42560 : tree t = gfc_get_symbol_decl (sym);
2739 : 42560 : tree parent_decl;
2740 : 42560 : int parent_flag;
2741 : 42560 : bool return_value;
2742 : 42560 : bool alternate_entry;
2743 : 42560 : bool entry_master;
2744 : :
2745 : 42560 : return_value = sym->attr.function && sym->result == sym;
2746 : 164 : alternate_entry = sym->attr.function && sym->attr.entry
2747 : 42594 : && sym->result == sym;
2748 : 85120 : entry_master = sym->attr.result
2749 : 172 : && sym->ns->proc_name->attr.entry_master
2750 : 42572 : && !gfc_return_by_reference (sym->ns->proc_name);
2751 : 42560 : parent_decl = current_function_decl
2752 : 42560 : ? DECL_CONTEXT (current_function_decl) : NULL_TREE;
2753 : :
2754 : 42560 : if ((t == parent_decl && return_value)
2755 : 42553 : || (sym->ns && sym->ns->proc_name
2756 : 42553 : && sym->ns->proc_name->backend_decl == parent_decl
2757 : 2170 : && (alternate_entry || entry_master)))
2758 : : parent_flag = 1;
2759 : : else
2760 : 42551 : parent_flag = 0;
2761 : :
2762 : : /* Special case for assigning the return value of a function.
2763 : : Self recursive functions must have an explicit return value. */
2764 : 42560 : if (return_value && (t == current_function_decl || parent_flag))
2765 : 94 : t = gfc_get_fake_result_decl (sym, parent_flag);
2766 : :
2767 : : /* Similarly for alternate entry points. */
2768 : 42466 : else if (alternate_entry
2769 : 32 : && (sym->ns->proc_name->backend_decl == current_function_decl
2770 : 0 : || parent_flag))
2771 : : {
2772 : 32 : gfc_entry_list *el = NULL;
2773 : :
2774 : 51 : for (el = sym->ns->entries; el; el = el->next)
2775 : 51 : if (sym == el->sym)
2776 : : {
2777 : 32 : t = gfc_get_fake_result_decl (sym, parent_flag);
2778 : 32 : break;
2779 : : }
2780 : : }
2781 : :
2782 : 42434 : else if (entry_master
2783 : 12 : && (sym->ns->proc_name->backend_decl == current_function_decl
2784 : 0 : || parent_flag))
2785 : 12 : t = gfc_get_fake_result_decl (sym, parent_flag);
2786 : :
2787 : : return t;
2788 : : }
2789 : :
2790 : : static tree
2791 : 11636 : gfc_trans_omp_variable_list (enum omp_clause_code code,
2792 : : gfc_omp_namelist *namelist, tree list,
2793 : : bool declare_simd)
2794 : : {
2795 : 30020 : for (; namelist != NULL; namelist = namelist->next)
2796 : 18384 : if (namelist->sym->attr.referenced || declare_simd)
2797 : : {
2798 : 18384 : tree t = gfc_trans_omp_variable (namelist->sym, declare_simd);
2799 : 18384 : if (t != error_mark_node)
2800 : : {
2801 : 18384 : tree node;
2802 : 18384 : node = build_omp_clause (input_location, code);
2803 : 18384 : OMP_CLAUSE_DECL (node) = t;
2804 : 18384 : list = gfc_trans_add_clause (node, list);
2805 : :
2806 : 18384 : if (code == OMP_CLAUSE_LASTPRIVATE
2807 : 2864 : && namelist->u.lastprivate_conditional)
2808 : 88 : OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (node) = 1;
2809 : : }
2810 : : }
2811 : 11636 : return list;
2812 : : }
2813 : :
2814 : : struct omp_udr_find_orig_data
2815 : : {
2816 : : gfc_omp_udr *omp_udr;
2817 : : bool omp_orig_seen;
2818 : : };
2819 : :
2820 : : static int
2821 : 678 : omp_udr_find_orig (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
2822 : : void *data)
2823 : : {
2824 : 678 : struct omp_udr_find_orig_data *cd = (struct omp_udr_find_orig_data *) data;
2825 : 678 : if ((*e)->expr_type == EXPR_VARIABLE
2826 : 366 : && (*e)->symtree->n.sym == cd->omp_udr->omp_orig)
2827 : 72 : cd->omp_orig_seen = true;
2828 : :
2829 : 678 : return 0;
2830 : : }
2831 : :
2832 : : static void
2833 : 683 : gfc_trans_omp_array_reduction_or_udr (tree c, gfc_omp_namelist *n, locus where)
2834 : : {
2835 : 683 : gfc_symbol *sym = n->sym;
2836 : 683 : gfc_symtree *root1 = NULL, *root2 = NULL, *root3 = NULL, *root4 = NULL;
2837 : 683 : gfc_symtree *symtree1, *symtree2, *symtree3, *symtree4 = NULL;
2838 : 683 : gfc_symbol init_val_sym, outer_sym, intrinsic_sym;
2839 : 683 : gfc_symbol omp_var_copy[4];
2840 : 683 : gfc_expr *e1, *e2, *e3, *e4;
2841 : 683 : gfc_ref *ref;
2842 : 683 : tree decl, backend_decl, stmt, type, outer_decl;
2843 : 683 : locus old_loc = gfc_current_locus;
2844 : 683 : const char *iname;
2845 : 683 : bool t;
2846 : 683 : gfc_omp_udr *udr = n->u2.udr ? n->u2.udr->udr : NULL;
2847 : :
2848 : 683 : decl = OMP_CLAUSE_DECL (c);
2849 : 683 : gfc_current_locus = where;
2850 : 683 : type = TREE_TYPE (decl);
2851 : 683 : outer_decl = create_tmp_var_raw (type);
2852 : 683 : if (TREE_CODE (decl) == PARM_DECL
2853 : 31 : && TREE_CODE (type) == REFERENCE_TYPE
2854 : 12 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
2855 : 695 : && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (type)) == GFC_ARRAY_ALLOCATABLE)
2856 : : {
2857 : 12 : decl = build_fold_indirect_ref (decl);
2858 : 12 : type = TREE_TYPE (type);
2859 : : }
2860 : :
2861 : : /* Create a fake symbol for init value. */
2862 : 683 : memset (&init_val_sym, 0, sizeof (init_val_sym));
2863 : 683 : init_val_sym.ns = sym->ns;
2864 : 683 : init_val_sym.name = sym->name;
2865 : 683 : init_val_sym.ts = sym->ts;
2866 : 683 : init_val_sym.attr.referenced = 1;
2867 : 683 : init_val_sym.declared_at = where;
2868 : 683 : init_val_sym.attr.flavor = FL_VARIABLE;
2869 : 683 : if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
2870 : 283 : backend_decl = omp_reduction_init (c, gfc_sym_type (&init_val_sym));
2871 : 400 : else if (udr->initializer_ns)
2872 : : backend_decl = NULL;
2873 : : else
2874 : 130 : switch (sym->ts.type)
2875 : : {
2876 : 15 : case BT_LOGICAL:
2877 : 15 : case BT_INTEGER:
2878 : 15 : case BT_REAL:
2879 : 15 : case BT_COMPLEX:
2880 : 15 : backend_decl = build_zero_cst (gfc_sym_type (&init_val_sym));
2881 : 15 : break;
2882 : : default:
2883 : : backend_decl = NULL_TREE;
2884 : : break;
2885 : : }
2886 : 683 : init_val_sym.backend_decl = backend_decl;
2887 : :
2888 : : /* Create a fake symbol for the outer array reference. */
2889 : 683 : outer_sym = *sym;
2890 : 683 : if (sym->as)
2891 : 426 : outer_sym.as = gfc_copy_array_spec (sym->as);
2892 : 683 : outer_sym.attr.dummy = 0;
2893 : 683 : outer_sym.attr.result = 0;
2894 : 683 : outer_sym.attr.flavor = FL_VARIABLE;
2895 : 683 : outer_sym.backend_decl = outer_decl;
2896 : 683 : if (decl != OMP_CLAUSE_DECL (c))
2897 : 12 : outer_sym.backend_decl = build_fold_indirect_ref (outer_decl);
2898 : :
2899 : : /* Create fake symtrees for it. */
2900 : 683 : symtree1 = gfc_new_symtree (&root1, sym->name);
2901 : 683 : symtree1->n.sym = sym;
2902 : 683 : gcc_assert (symtree1 == root1);
2903 : :
2904 : 683 : symtree2 = gfc_new_symtree (&root2, sym->name);
2905 : 683 : symtree2->n.sym = &init_val_sym;
2906 : 683 : gcc_assert (symtree2 == root2);
2907 : :
2908 : 683 : symtree3 = gfc_new_symtree (&root3, sym->name);
2909 : 683 : symtree3->n.sym = &outer_sym;
2910 : 683 : gcc_assert (symtree3 == root3);
2911 : :
2912 : 683 : memset (omp_var_copy, 0, sizeof omp_var_copy);
2913 : 683 : if (udr)
2914 : : {
2915 : 400 : omp_var_copy[0] = *udr->omp_out;
2916 : 400 : omp_var_copy[1] = *udr->omp_in;
2917 : 400 : *udr->omp_out = outer_sym;
2918 : 400 : *udr->omp_in = *sym;
2919 : 400 : if (udr->initializer_ns)
2920 : : {
2921 : 270 : omp_var_copy[2] = *udr->omp_priv;
2922 : 270 : omp_var_copy[3] = *udr->omp_orig;
2923 : 270 : *udr->omp_priv = *sym;
2924 : 270 : *udr->omp_orig = outer_sym;
2925 : : }
2926 : : }
2927 : :
2928 : : /* Create expressions. */
2929 : 683 : e1 = gfc_get_expr ();
2930 : 683 : e1->expr_type = EXPR_VARIABLE;
2931 : 683 : e1->where = where;
2932 : 683 : e1->symtree = symtree1;
2933 : 683 : e1->ts = sym->ts;
2934 : 683 : if (sym->attr.dimension)
2935 : : {
2936 : 426 : e1->ref = ref = gfc_get_ref ();
2937 : 426 : ref->type = REF_ARRAY;
2938 : 426 : ref->u.ar.where = where;
2939 : 426 : ref->u.ar.as = sym->as;
2940 : 426 : ref->u.ar.type = AR_FULL;
2941 : 426 : ref->u.ar.dimen = 0;
2942 : : }
2943 : 683 : t = gfc_resolve_expr (e1);
2944 : 683 : gcc_assert (t);
2945 : :
2946 : 683 : e2 = NULL;
2947 : 683 : if (backend_decl != NULL_TREE)
2948 : : {
2949 : 298 : e2 = gfc_get_expr ();
2950 : 298 : e2->expr_type = EXPR_VARIABLE;
2951 : 298 : e2->where = where;
2952 : 298 : e2->symtree = symtree2;
2953 : 298 : e2->ts = sym->ts;
2954 : 298 : t = gfc_resolve_expr (e2);
2955 : 298 : gcc_assert (t);
2956 : : }
2957 : 385 : else if (udr->initializer_ns == NULL)
2958 : : {
2959 : 115 : gcc_assert (sym->ts.type == BT_DERIVED);
2960 : 115 : e2 = gfc_default_initializer (&sym->ts);
2961 : 115 : gcc_assert (e2);
2962 : 115 : t = gfc_resolve_expr (e2);
2963 : 115 : gcc_assert (t);
2964 : : }
2965 : 270 : else if (n->u2.udr->initializer->op == EXEC_ASSIGN)
2966 : : {
2967 : 204 : e2 = gfc_copy_expr (n->u2.udr->initializer->expr2);
2968 : 204 : t = gfc_resolve_expr (e2);
2969 : 204 : gcc_assert (t);
2970 : : }
2971 : 683 : if (udr && udr->initializer_ns)
2972 : : {
2973 : 270 : struct omp_udr_find_orig_data cd;
2974 : 270 : cd.omp_udr = udr;
2975 : 270 : cd.omp_orig_seen = false;
2976 : 270 : gfc_code_walker (&n->u2.udr->initializer,
2977 : : gfc_dummy_code_callback, omp_udr_find_orig, &cd);
2978 : 270 : if (cd.omp_orig_seen)
2979 : 72 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
2980 : : }
2981 : :
2982 : 683 : e3 = gfc_copy_expr (e1);
2983 : 683 : e3->symtree = symtree3;
2984 : 683 : t = gfc_resolve_expr (e3);
2985 : 683 : gcc_assert (t);
2986 : :
2987 : 683 : iname = NULL;
2988 : 683 : e4 = NULL;
2989 : 683 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
2990 : : {
2991 : 159 : case PLUS_EXPR:
2992 : 159 : case MINUS_EXPR:
2993 : 159 : e4 = gfc_add (e3, e1);
2994 : 159 : break;
2995 : 26 : case MULT_EXPR:
2996 : 26 : e4 = gfc_multiply (e3, e1);
2997 : 26 : break;
2998 : 6 : case TRUTH_ANDIF_EXPR:
2999 : 6 : e4 = gfc_and (e3, e1);
3000 : 6 : break;
3001 : 6 : case TRUTH_ORIF_EXPR:
3002 : 6 : e4 = gfc_or (e3, e1);
3003 : 6 : break;
3004 : 6 : case EQ_EXPR:
3005 : 6 : e4 = gfc_eqv (e3, e1);
3006 : 6 : break;
3007 : 6 : case NE_EXPR:
3008 : 6 : e4 = gfc_neqv (e3, e1);
3009 : 6 : break;
3010 : : case MIN_EXPR:
3011 : : iname = "min";
3012 : : break;
3013 : : case MAX_EXPR:
3014 : : iname = "max";
3015 : : break;
3016 : : case BIT_AND_EXPR:
3017 : : iname = "iand";
3018 : : break;
3019 : : case BIT_IOR_EXPR:
3020 : : iname = "ior";
3021 : : break;
3022 : : case BIT_XOR_EXPR:
3023 : : iname = "ieor";
3024 : : break;
3025 : 400 : case ERROR_MARK:
3026 : 400 : if (n->u2.udr->combiner->op == EXEC_ASSIGN)
3027 : : {
3028 : 334 : gfc_free_expr (e3);
3029 : 334 : e3 = gfc_copy_expr (n->u2.udr->combiner->expr1);
3030 : 334 : e4 = gfc_copy_expr (n->u2.udr->combiner->expr2);
3031 : 334 : t = gfc_resolve_expr (e3);
3032 : 334 : gcc_assert (t);
3033 : 334 : t = gfc_resolve_expr (e4);
3034 : 334 : gcc_assert (t);
3035 : : }
3036 : : break;
3037 : 0 : default:
3038 : 0 : gcc_unreachable ();
3039 : : }
3040 : 209 : if (iname != NULL)
3041 : : {
3042 : 74 : memset (&intrinsic_sym, 0, sizeof (intrinsic_sym));
3043 : 74 : intrinsic_sym.ns = sym->ns;
3044 : 74 : intrinsic_sym.name = iname;
3045 : 74 : intrinsic_sym.ts = sym->ts;
3046 : 74 : intrinsic_sym.attr.referenced = 1;
3047 : 74 : intrinsic_sym.attr.intrinsic = 1;
3048 : 74 : intrinsic_sym.attr.function = 1;
3049 : 74 : intrinsic_sym.attr.implicit_type = 1;
3050 : 74 : intrinsic_sym.result = &intrinsic_sym;
3051 : 74 : intrinsic_sym.declared_at = where;
3052 : :
3053 : 74 : symtree4 = gfc_new_symtree (&root4, iname);
3054 : 74 : symtree4->n.sym = &intrinsic_sym;
3055 : 74 : gcc_assert (symtree4 == root4);
3056 : :
3057 : 74 : e4 = gfc_get_expr ();
3058 : 74 : e4->expr_type = EXPR_FUNCTION;
3059 : 74 : e4->where = where;
3060 : 74 : e4->symtree = symtree4;
3061 : 74 : e4->value.function.actual = gfc_get_actual_arglist ();
3062 : 74 : e4->value.function.actual->expr = e3;
3063 : 74 : e4->value.function.actual->next = gfc_get_actual_arglist ();
3064 : 74 : e4->value.function.actual->next->expr = e1;
3065 : : }
3066 : 683 : if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
3067 : : {
3068 : : /* e1 and e3 have been stored as arguments of e4, avoid sharing. */
3069 : 283 : e1 = gfc_copy_expr (e1);
3070 : 283 : e3 = gfc_copy_expr (e3);
3071 : 283 : t = gfc_resolve_expr (e4);
3072 : 283 : gcc_assert (t);
3073 : : }
3074 : :
3075 : : /* Create the init statement list. */
3076 : 683 : pushlevel ();
3077 : 683 : if (e2)
3078 : 617 : stmt = gfc_trans_assignment (e1, e2, false, false);
3079 : : else
3080 : 66 : stmt = gfc_trans_call (n->u2.udr->initializer, false,
3081 : : NULL_TREE, NULL_TREE, false);
3082 : 683 : if (TREE_CODE (stmt) != BIND_EXPR)
3083 : 196 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
3084 : : else
3085 : 487 : poplevel (0, 0);
3086 : 683 : OMP_CLAUSE_REDUCTION_INIT (c) = stmt;
3087 : :
3088 : : /* Create the merge statement list. */
3089 : 683 : pushlevel ();
3090 : 683 : if (e4)
3091 : 617 : stmt = gfc_trans_assignment (e3, e4, false, true);
3092 : : else
3093 : 66 : stmt = gfc_trans_call (n->u2.udr->combiner, false,
3094 : : NULL_TREE, NULL_TREE, false);
3095 : 683 : if (TREE_CODE (stmt) != BIND_EXPR)
3096 : 233 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
3097 : : else
3098 : 450 : poplevel (0, 0);
3099 : 683 : OMP_CLAUSE_REDUCTION_MERGE (c) = stmt;
3100 : :
3101 : : /* And stick the placeholder VAR_DECL into the clause as well. */
3102 : 683 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = outer_decl;
3103 : :
3104 : 683 : gfc_current_locus = old_loc;
3105 : :
3106 : 683 : gfc_free_expr (e1);
3107 : 683 : if (e2)
3108 : 617 : gfc_free_expr (e2);
3109 : 683 : gfc_free_expr (e3);
3110 : 683 : if (e4)
3111 : 617 : gfc_free_expr (e4);
3112 : 683 : free (symtree1);
3113 : 683 : free (symtree2);
3114 : 683 : free (symtree3);
3115 : 683 : free (symtree4);
3116 : 683 : if (outer_sym.as)
3117 : 426 : gfc_free_array_spec (outer_sym.as);
3118 : :
3119 : 683 : if (udr)
3120 : : {
3121 : 400 : *udr->omp_out = omp_var_copy[0];
3122 : 400 : *udr->omp_in = omp_var_copy[1];
3123 : 400 : if (udr->initializer_ns)
3124 : : {
3125 : 270 : *udr->omp_priv = omp_var_copy[2];
3126 : 270 : *udr->omp_orig = omp_var_copy[3];
3127 : : }
3128 : : }
3129 : 683 : }
3130 : :
3131 : : static tree
3132 : 3840 : gfc_trans_omp_reduction_list (int kind, gfc_omp_namelist *namelist, tree list,
3133 : : locus where, bool mark_addressable)
3134 : : {
3135 : 3840 : omp_clause_code clause = OMP_CLAUSE_REDUCTION;
3136 : 3840 : switch (kind)
3137 : : {
3138 : : case OMP_LIST_REDUCTION:
3139 : : case OMP_LIST_REDUCTION_INSCAN:
3140 : : case OMP_LIST_REDUCTION_TASK:
3141 : : break;
3142 : : case OMP_LIST_IN_REDUCTION:
3143 : : clause = OMP_CLAUSE_IN_REDUCTION;
3144 : : break;
3145 : : case OMP_LIST_TASK_REDUCTION:
3146 : : clause = OMP_CLAUSE_TASK_REDUCTION;
3147 : : break;
3148 : 0 : default:
3149 : 0 : gcc_unreachable ();
3150 : : }
3151 : 8624 : for (; namelist != NULL; namelist = namelist->next)
3152 : 4784 : if (namelist->sym->attr.referenced)
3153 : : {
3154 : 4784 : tree t = gfc_trans_omp_variable (namelist->sym, false);
3155 : 4784 : if (t != error_mark_node)
3156 : : {
3157 : 4784 : tree node = build_omp_clause (gfc_get_location (&namelist->where),
3158 : : clause);
3159 : 4784 : OMP_CLAUSE_DECL (node) = t;
3160 : 4784 : if (mark_addressable)
3161 : 38 : TREE_ADDRESSABLE (t) = 1;
3162 : 4784 : if (kind == OMP_LIST_REDUCTION_INSCAN)
3163 : 20 : OMP_CLAUSE_REDUCTION_INSCAN (node) = 1;
3164 : 4784 : if (kind == OMP_LIST_REDUCTION_TASK)
3165 : 91 : OMP_CLAUSE_REDUCTION_TASK (node) = 1;
3166 : 4784 : switch (namelist->u.reduction_op)
3167 : : {
3168 : 2338 : case OMP_REDUCTION_PLUS:
3169 : 2338 : OMP_CLAUSE_REDUCTION_CODE (node) = PLUS_EXPR;
3170 : 2338 : break;
3171 : 197 : case OMP_REDUCTION_MINUS:
3172 : 197 : OMP_CLAUSE_REDUCTION_CODE (node) = MINUS_EXPR;
3173 : 197 : break;
3174 : 254 : case OMP_REDUCTION_TIMES:
3175 : 254 : OMP_CLAUSE_REDUCTION_CODE (node) = MULT_EXPR;
3176 : 254 : break;
3177 : 92 : case OMP_REDUCTION_AND:
3178 : 92 : OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ANDIF_EXPR;
3179 : 92 : break;
3180 : 785 : case OMP_REDUCTION_OR:
3181 : 785 : OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ORIF_EXPR;
3182 : 785 : break;
3183 : 86 : case OMP_REDUCTION_EQV:
3184 : 86 : OMP_CLAUSE_REDUCTION_CODE (node) = EQ_EXPR;
3185 : 86 : break;
3186 : 86 : case OMP_REDUCTION_NEQV:
3187 : 86 : OMP_CLAUSE_REDUCTION_CODE (node) = NE_EXPR;
3188 : 86 : break;
3189 : 218 : case OMP_REDUCTION_MAX:
3190 : 218 : OMP_CLAUSE_REDUCTION_CODE (node) = MAX_EXPR;
3191 : 218 : break;
3192 : 201 : case OMP_REDUCTION_MIN:
3193 : 201 : OMP_CLAUSE_REDUCTION_CODE (node) = MIN_EXPR;
3194 : 201 : break;
3195 : 40 : case OMP_REDUCTION_IAND:
3196 : 40 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_AND_EXPR;
3197 : 40 : break;
3198 : 49 : case OMP_REDUCTION_IOR:
3199 : 49 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_IOR_EXPR;
3200 : 49 : break;
3201 : 38 : case OMP_REDUCTION_IEOR:
3202 : 38 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_XOR_EXPR;
3203 : 38 : break;
3204 : 400 : case OMP_REDUCTION_USER:
3205 : 400 : OMP_CLAUSE_REDUCTION_CODE (node) = ERROR_MARK;
3206 : 400 : break;
3207 : 0 : default:
3208 : 0 : gcc_unreachable ();
3209 : : }
3210 : 4784 : if (namelist->sym->attr.dimension
3211 : 4358 : || namelist->u.reduction_op == OMP_REDUCTION_USER
3212 : 4114 : || namelist->sym->attr.allocatable)
3213 : 683 : gfc_trans_omp_array_reduction_or_udr (node, namelist, where);
3214 : 4784 : list = gfc_trans_add_clause (node, list);
3215 : : }
3216 : : }
3217 : 3840 : return list;
3218 : : }
3219 : :
3220 : : static inline tree
3221 : 3375 : gfc_convert_expr_to_tree (stmtblock_t *block, gfc_expr *expr)
3222 : : {
3223 : 3375 : gfc_se se;
3224 : 3375 : tree result;
3225 : :
3226 : 3375 : gfc_init_se (&se, NULL );
3227 : 3375 : gfc_conv_expr (&se, expr);
3228 : 3375 : gfc_add_block_to_block (block, &se.pre);
3229 : 3375 : result = gfc_evaluate_now (se.expr, block);
3230 : 3375 : gfc_add_block_to_block (block, &se.post);
3231 : :
3232 : 3375 : return result;
3233 : : }
3234 : :
3235 : : static vec<tree, va_heap, vl_embed> *doacross_steps;
3236 : :
3237 : :
3238 : : /* Translate an array section or array element. */
3239 : :
3240 : : static void
3241 : 3982 : gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op,
3242 : : gfc_omp_namelist *n, tree decl, bool element,
3243 : : bool openmp, gomp_map_kind ptr_kind, tree &node,
3244 : : tree &node2, tree &node3, tree &node4)
3245 : : {
3246 : 3982 : gfc_se se;
3247 : 3982 : tree ptr, ptr2;
3248 : 3982 : tree elemsz = NULL_TREE;
3249 : :
3250 : 3982 : gfc_init_se (&se, NULL);
3251 : 3982 : if (element)
3252 : : {
3253 : 174 : gfc_conv_expr_reference (&se, n->expr);
3254 : 174 : gfc_add_block_to_block (block, &se.pre);
3255 : 174 : ptr = se.expr;
3256 : : }
3257 : : else
3258 : : {
3259 : 3808 : gfc_conv_expr_descriptor (&se, n->expr);
3260 : 3808 : ptr = gfc_conv_array_data (se.expr);
3261 : : }
3262 : 3982 : if (n->expr->ts.type == BT_CHARACTER && n->expr->ts.deferred)
3263 : : {
3264 : 0 : gcc_assert (se.string_length);
3265 : 0 : tree len = gfc_evaluate_now (se.string_length, block);
3266 : 0 : elemsz = gfc_get_char_type (n->expr->ts.kind);
3267 : 0 : elemsz = TYPE_SIZE_UNIT (elemsz);
3268 : 0 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
3269 : : fold_convert (size_type_node, len), elemsz);
3270 : : }
3271 : 3982 : if (element)
3272 : : {
3273 : 174 : if (!elemsz)
3274 : 174 : elemsz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
3275 : 174 : OMP_CLAUSE_SIZE (node) = elemsz;
3276 : : }
3277 : : else
3278 : : {
3279 : 3808 : tree type = TREE_TYPE (se.expr);
3280 : 3808 : gfc_add_block_to_block (block, &se.pre);
3281 : 3808 : OMP_CLAUSE_SIZE (node) = gfc_full_array_size (block, se.expr,
3282 : 3808 : GFC_TYPE_ARRAY_RANK (type));
3283 : 3808 : if (!elemsz)
3284 : 3808 : elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
3285 : 3808 : elemsz = fold_convert (gfc_array_index_type, elemsz);
3286 : 3808 : OMP_CLAUSE_SIZE (node) = fold_build2 (MULT_EXPR, gfc_array_index_type,
3287 : : OMP_CLAUSE_SIZE (node), elemsz);
3288 : 3808 : if (n->expr->ts.type == BT_DERIVED
3289 : 21 : && n->expr->ts.u.derived->attr.alloc_comp)
3290 : : {
3291 : : /* Save array descriptor for use in gfc_omp_deep_mapping{,_p,_cnt};
3292 : : force evaluate to ensure that it is not gimplified + is a decl. */
3293 : 15 : tree tmp = OMP_CLAUSE_SIZE (node);
3294 : 15 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
3295 : 15 : gfc_add_modify_loc (input_location, block, var, tmp);
3296 : 15 : OMP_CLAUSE_SIZE (node) = var;
3297 : 15 : gfc_allocate_lang_decl (var);
3298 : 15 : GFC_DECL_SAVED_DESCRIPTOR (var) = se.expr;
3299 : : }
3300 : : }
3301 : 3982 : gcc_assert (se.post.head == NULL_TREE);
3302 : 3982 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
3303 : 3982 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
3304 : 3982 : ptr = fold_convert (ptrdiff_type_node, ptr);
3305 : :
3306 : 7702 : if (POINTER_TYPE_P (TREE_TYPE (decl))
3307 : 340 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
3308 : 78 : && ptr_kind == GOMP_MAP_POINTER
3309 : 78 : && op != EXEC_OMP_TARGET_EXIT_DATA
3310 : 78 : && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_RELEASE
3311 : 4060 : && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_DELETE)
3312 : :
3313 : : {
3314 : 78 : node4 = build_omp_clause (input_location,
3315 : : OMP_CLAUSE_MAP);
3316 : 78 : OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
3317 : 78 : OMP_CLAUSE_DECL (node4) = decl;
3318 : 78 : OMP_CLAUSE_SIZE (node4) = size_int (0);
3319 : 78 : decl = build_fold_indirect_ref (decl);
3320 : : }
3321 : 3904 : else if (ptr_kind == GOMP_MAP_ALWAYS_POINTER
3322 : 0 : && n->expr->ts.type == BT_CHARACTER
3323 : 0 : && n->expr->ts.deferred)
3324 : : {
3325 : 0 : gomp_map_kind map_kind;
3326 : 0 : if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE)
3327 : 0 : map_kind = OMP_CLAUSE_MAP_KIND (node);
3328 : 0 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
3329 : 0 : || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE)
3330 : : map_kind = GOMP_MAP_RELEASE;
3331 : : else
3332 : : map_kind = GOMP_MAP_TO;
3333 : 0 : gcc_assert (se.string_length);
3334 : 0 : node4 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3335 : 0 : OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
3336 : 0 : OMP_CLAUSE_DECL (node4) = se.string_length;
3337 : 0 : OMP_CLAUSE_SIZE (node4) = TYPE_SIZE_UNIT (gfc_charlen_type_node);
3338 : : }
3339 : 3982 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
3340 : : {
3341 : 2709 : tree type = TREE_TYPE (decl);
3342 : 2709 : ptr2 = gfc_conv_descriptor_data_get (decl);
3343 : 2709 : node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3344 : 2709 : OMP_CLAUSE_DECL (node2) = decl;
3345 : 2709 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
3346 : 2709 : if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE
3347 : 2708 : || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE
3348 : 2499 : || op == EXEC_OMP_TARGET_EXIT_DATA
3349 : 5208 : || op == EXEC_OACC_EXIT_DATA)
3350 : : {
3351 : 392 : gomp_map_kind map_kind
3352 : 392 : = OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE ? GOMP_MAP_DELETE
3353 : 391 : : GOMP_MAP_RELEASE;
3354 : 392 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
3355 : 392 : OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
3356 : : }
3357 : : else
3358 : 2317 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
3359 : 2709 : node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3360 : 2709 : OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
3361 : 2709 : OMP_CLAUSE_DECL (node3) = gfc_conv_descriptor_data_get (decl);
3362 : : /* This purposely does not include GOMP_MAP_ALWAYS_POINTER. The extra
3363 : : cast prevents gimplify.cc from recognising it as being part of the
3364 : : struct - and adding an 'alloc: for the 'desc.data' pointer, which
3365 : : would break as the 'desc' (the descriptor) is also mapped
3366 : : (see node4 above). */
3367 : 2709 : if (ptr_kind == GOMP_MAP_ATTACH_DETACH && !openmp)
3368 : 141 : STRIP_NOPS (OMP_CLAUSE_DECL (node3));
3369 : : }
3370 : : else
3371 : : {
3372 : 1273 : if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3373 : : {
3374 : 1011 : tree offset;
3375 : 1011 : ptr2 = build_fold_addr_expr (decl);
3376 : 1011 : offset = fold_build2 (MINUS_EXPR, ptrdiff_type_node, ptr,
3377 : : fold_convert (ptrdiff_type_node, ptr2));
3378 : 1011 : offset = build2 (TRUNC_DIV_EXPR, ptrdiff_type_node,
3379 : : offset, fold_convert (ptrdiff_type_node, elemsz));
3380 : 1011 : offset = build4_loc (input_location, ARRAY_REF,
3381 : 1011 : TREE_TYPE (TREE_TYPE (decl)),
3382 : : decl, offset, NULL_TREE, NULL_TREE);
3383 : 1011 : OMP_CLAUSE_DECL (node) = offset;
3384 : :
3385 : 1011 : if (ptr_kind == GOMP_MAP_ATTACH_DETACH && openmp)
3386 : 145 : return;
3387 : : }
3388 : : else
3389 : : {
3390 : 262 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
3391 : : ptr2 = decl;
3392 : : }
3393 : 1128 : node3 = build_omp_clause (input_location,
3394 : : OMP_CLAUSE_MAP);
3395 : 1128 : OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
3396 : 1128 : OMP_CLAUSE_DECL (node3) = decl;
3397 : : }
3398 : 3837 : ptr2 = fold_convert (ptrdiff_type_node, ptr2);
3399 : 3837 : OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, ptrdiff_type_node,
3400 : : ptr, ptr2);
3401 : : }
3402 : :
3403 : : static tree
3404 : 43 : handle_iterator (gfc_namespace *ns, stmtblock_t *iter_block, tree block)
3405 : : {
3406 : 43 : tree list = NULL_TREE;
3407 : 88 : for (gfc_symbol *sym = ns->omp_affinity_iterators; sym; sym = sym->tlink)
3408 : : {
3409 : 45 : gfc_constructor *c;
3410 : 45 : gfc_se se;
3411 : :
3412 : 45 : tree last = make_tree_vec (6);
3413 : 45 : tree iter_var = gfc_get_symbol_decl (sym);
3414 : 45 : tree type = TREE_TYPE (iter_var);
3415 : 45 : TREE_VEC_ELT (last, 0) = iter_var;
3416 : 45 : DECL_CHAIN (iter_var) = BLOCK_VARS (block);
3417 : 45 : BLOCK_VARS (block) = iter_var;
3418 : :
3419 : : /* begin */
3420 : 45 : c = gfc_constructor_first (sym->value->value.constructor);
3421 : 45 : gfc_init_se (&se, NULL);
3422 : 45 : gfc_conv_expr (&se, c->expr);
3423 : 45 : gfc_add_block_to_block (iter_block, &se.pre);
3424 : 45 : gfc_add_block_to_block (iter_block, &se.post);
3425 : 45 : TREE_VEC_ELT (last, 1) = fold_convert (type,
3426 : : gfc_evaluate_now (se.expr,
3427 : : iter_block));
3428 : : /* end */
3429 : 45 : c = gfc_constructor_next (c);
3430 : 45 : gfc_init_se (&se, NULL);
3431 : 45 : gfc_conv_expr (&se, c->expr);
3432 : 45 : gfc_add_block_to_block (iter_block, &se.pre);
3433 : 45 : gfc_add_block_to_block (iter_block, &se.post);
3434 : 45 : TREE_VEC_ELT (last, 2) = fold_convert (type,
3435 : : gfc_evaluate_now (se.expr,
3436 : : iter_block));
3437 : : /* step */
3438 : 45 : c = gfc_constructor_next (c);
3439 : 45 : tree step;
3440 : 45 : if (c)
3441 : : {
3442 : 5 : gfc_init_se (&se, NULL);
3443 : 5 : gfc_conv_expr (&se, c->expr);
3444 : 5 : gfc_add_block_to_block (iter_block, &se.pre);
3445 : 5 : gfc_add_block_to_block (iter_block, &se.post);
3446 : 5 : gfc_conv_expr (&se, c->expr);
3447 : 5 : step = fold_convert (type,
3448 : : gfc_evaluate_now (se.expr,
3449 : : iter_block));
3450 : : }
3451 : : else
3452 : 40 : step = build_int_cst (type, 1);
3453 : 45 : TREE_VEC_ELT (last, 3) = step;
3454 : : /* orig_step */
3455 : 45 : TREE_VEC_ELT (last, 4) = save_expr (step);
3456 : 45 : TREE_CHAIN (last) = list;
3457 : 45 : list = last;
3458 : : }
3459 : 43 : return list;
3460 : : }
3461 : :
3462 : : /* To alleviate quadratic behaviour in checking each entry of a
3463 : : gfc_omp_namelist against every other entry, we build a hashtable indexed by
3464 : : gfc_symbol pointer, which we can use in the usual case that a map
3465 : : expression has a symbol as its root term. Return a namelist based on the
3466 : : root symbol used by N, building a new table in SYM_ROOTED_NL using the
3467 : : gfc_omp_namelist N2 (all clauses) if we haven't done so already. */
3468 : :
3469 : : static gfc_omp_namelist *
3470 : 573 : get_symbol_rooted_namelist (hash_map<gfc_symbol *,
3471 : : gfc_omp_namelist *> *&sym_rooted_nl,
3472 : : gfc_omp_namelist *n,
3473 : : gfc_omp_namelist *n2, bool *sym_based)
3474 : : {
3475 : : /* Early-out if we have a NULL clause list (e.g. for OpenACC). */
3476 : 573 : if (!n2)
3477 : : return NULL;
3478 : :
3479 : 536 : gfc_symbol *use_sym = NULL;
3480 : :
3481 : : /* We're only interested in cases where we have an expression, e.g. a
3482 : : component access. */
3483 : 536 : if (n->expr && n->expr->expr_type == EXPR_VARIABLE && n->expr->symtree)
3484 : 536 : use_sym = n->expr->symtree->n.sym;
3485 : :
3486 : 536 : *sym_based = false;
3487 : :
3488 : 536 : if (!use_sym)
3489 : : return n2;
3490 : :
3491 : 536 : if (!sym_rooted_nl)
3492 : : {
3493 : 252 : sym_rooted_nl = new hash_map<gfc_symbol *, gfc_omp_namelist *> ();
3494 : :
3495 : 1212 : for (; n2 != NULL; n2 = n2->next)
3496 : : {
3497 : 960 : if (!n2->expr
3498 : 959 : || n2->expr->expr_type != EXPR_VARIABLE
3499 : 959 : || !n2->expr->symtree)
3500 : 1 : continue;
3501 : :
3502 : 959 : gfc_omp_namelist *nl_copy = gfc_get_omp_namelist ();
3503 : 959 : memcpy (nl_copy, n2, sizeof *nl_copy);
3504 : 959 : nl_copy->u2.duplicate_of = n2;
3505 : 959 : nl_copy->next = NULL;
3506 : :
3507 : 959 : gfc_symbol *idx_sym = n2->expr->symtree->n.sym;
3508 : :
3509 : 959 : bool existed;
3510 : 959 : gfc_omp_namelist *&entry
3511 : 959 : = sym_rooted_nl->get_or_insert (idx_sym, &existed);
3512 : 959 : if (existed)
3513 : 650 : nl_copy->next = entry;
3514 : 959 : entry = nl_copy;
3515 : : }
3516 : : }
3517 : :
3518 : 536 : gfc_omp_namelist **n2_sym = sym_rooted_nl->get (use_sym);
3519 : :
3520 : 536 : if (n2_sym)
3521 : : {
3522 : 536 : *sym_based = true;
3523 : 536 : return *n2_sym;
3524 : : }
3525 : :
3526 : : return NULL;
3527 : : }
3528 : :
3529 : : static tree
3530 : 31372 : gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
3531 : : locus where, bool declare_simd = false,
3532 : : bool openacc = false, gfc_exec_op op = EXEC_NOP)
3533 : : {
3534 : 31372 : tree omp_clauses = NULL_TREE, prev_clauses, chunk_size, c;
3535 : 31372 : tree iterator = NULL_TREE;
3536 : 31372 : tree tree_block = NULL_TREE;
3537 : 31372 : stmtblock_t iter_block;
3538 : 31372 : int list, ifc;
3539 : 31372 : enum omp_clause_code clause_code;
3540 : 31372 : gfc_omp_namelist *prev = NULL;
3541 : 31372 : gfc_se se;
3542 : :
3543 : 31372 : if (clauses == NULL)
3544 : : return NULL_TREE;
3545 : :
3546 : 31360 : hash_map<gfc_symbol *, gfc_omp_namelist *> *sym_rooted_nl = NULL;
3547 : :
3548 : 1223040 : for (list = 0; list < OMP_LIST_NUM; list++)
3549 : : {
3550 : 1191680 : gfc_omp_namelist *n = clauses->lists[list];
3551 : :
3552 : 1191680 : if (n == NULL)
3553 : 1164199 : continue;
3554 : 27481 : switch (list)
3555 : : {
3556 : 3840 : case OMP_LIST_REDUCTION:
3557 : 3840 : case OMP_LIST_REDUCTION_INSCAN:
3558 : 3840 : case OMP_LIST_REDUCTION_TASK:
3559 : 3840 : case OMP_LIST_IN_REDUCTION:
3560 : 3840 : case OMP_LIST_TASK_REDUCTION:
3561 : : /* An OpenACC async clause indicates the need to set reduction
3562 : : arguments addressable, to allow asynchronous copy-out. */
3563 : 3840 : omp_clauses = gfc_trans_omp_reduction_list (list, n, omp_clauses,
3564 : 3840 : where, clauses->async);
3565 : 3840 : break;
3566 : 6448 : case OMP_LIST_PRIVATE:
3567 : 6448 : clause_code = OMP_CLAUSE_PRIVATE;
3568 : 6448 : goto add_clause;
3569 : 1067 : case OMP_LIST_SHARED:
3570 : 1067 : clause_code = OMP_CLAUSE_SHARED;
3571 : 1067 : goto add_clause;
3572 : 1037 : case OMP_LIST_FIRSTPRIVATE:
3573 : 1037 : clause_code = OMP_CLAUSE_FIRSTPRIVATE;
3574 : 1037 : goto add_clause;
3575 : 1661 : case OMP_LIST_LASTPRIVATE:
3576 : 1661 : clause_code = OMP_CLAUSE_LASTPRIVATE;
3577 : 1661 : goto add_clause;
3578 : 96 : case OMP_LIST_COPYIN:
3579 : 96 : clause_code = OMP_CLAUSE_COPYIN;
3580 : 96 : goto add_clause;
3581 : 74 : case OMP_LIST_COPYPRIVATE:
3582 : 74 : clause_code = OMP_CLAUSE_COPYPRIVATE;
3583 : 74 : goto add_clause;
3584 : 61 : case OMP_LIST_UNIFORM:
3585 : 61 : clause_code = OMP_CLAUSE_UNIFORM;
3586 : 61 : goto add_clause;
3587 : 50 : case OMP_LIST_USE_DEVICE:
3588 : 50 : case OMP_LIST_USE_DEVICE_PTR:
3589 : 50 : clause_code = OMP_CLAUSE_USE_DEVICE_PTR;
3590 : 50 : goto add_clause;
3591 : 922 : case OMP_LIST_USE_DEVICE_ADDR:
3592 : 922 : clause_code = OMP_CLAUSE_USE_DEVICE_ADDR;
3593 : 922 : goto add_clause;
3594 : 43 : case OMP_LIST_IS_DEVICE_PTR:
3595 : 43 : clause_code = OMP_CLAUSE_IS_DEVICE_PTR;
3596 : 43 : goto add_clause;
3597 : 100 : case OMP_LIST_HAS_DEVICE_ADDR:
3598 : 100 : clause_code = OMP_CLAUSE_HAS_DEVICE_ADDR;
3599 : 100 : goto add_clause;
3600 : 2 : case OMP_LIST_NONTEMPORAL:
3601 : 2 : clause_code = OMP_CLAUSE_NONTEMPORAL;
3602 : 2 : goto add_clause;
3603 : 9 : case OMP_LIST_SCAN_IN:
3604 : 9 : clause_code = OMP_CLAUSE_INCLUSIVE;
3605 : 9 : goto add_clause;
3606 : 7 : case OMP_LIST_SCAN_EX:
3607 : 7 : clause_code = OMP_CLAUSE_EXCLUSIVE;
3608 : 7 : goto add_clause;
3609 : 4 : case OMP_LIST_USE:
3610 : 4 : clause_code = OMP_CLAUSE_USE;
3611 : 4 : goto add_clause;
3612 : 55 : case OMP_LIST_INTEROP:
3613 : 55 : clause_code = OMP_CLAUSE_INTEROP;
3614 : 55 : goto add_clause;
3615 : :
3616 : 11636 : add_clause:
3617 : 11636 : omp_clauses
3618 : 11636 : = gfc_trans_omp_variable_list (clause_code, n, omp_clauses,
3619 : : declare_simd);
3620 : 11636 : break;
3621 : :
3622 : : case OMP_LIST_DESTROY:
3623 : 12 : for (; n != NULL; n = n->next)
3624 : 9 : if (n->sym->attr.referenced)
3625 : : {
3626 : 9 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3627 : 9 : if (t != error_mark_node)
3628 : : {
3629 : 9 : tree node
3630 : 9 : = build_omp_clause (input_location, OMP_CLAUSE_DESTROY);
3631 : 9 : OMP_CLAUSE_DECL (node) = t;
3632 : 9 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (node)) = 1;
3633 : 9 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3634 : : }
3635 : : }
3636 : : break;
3637 : :
3638 : : case OMP_LIST_INIT:
3639 : : {
3640 : : tree pref_type = NULL_TREE;
3641 : : const char *last = NULL;
3642 : 32 : for (; n != NULL; n = n->next)
3643 : 26 : if (n->sym->attr.referenced)
3644 : : {
3645 : 26 : tree t = gfc_trans_omp_variable (n->sym, false);
3646 : 26 : if (t == error_mark_node)
3647 : 0 : continue;
3648 : 26 : tree node = build_omp_clause (input_location,
3649 : : OMP_CLAUSE_INIT);
3650 : 26 : OMP_CLAUSE_DECL (node) = t;
3651 : 26 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (node)) = 1;
3652 : 26 : if (n->u.init.target)
3653 : 19 : OMP_CLAUSE_INIT_TARGET (node) = 1;
3654 : 26 : if (n->u.init.targetsync)
3655 : 10 : OMP_CLAUSE_INIT_TARGETSYNC (node) = 1;
3656 : 26 : if (last != n->u2.init_interop)
3657 : : {
3658 : 6 : last = n->u2.init_interop;
3659 : 6 : if (n->u2.init_interop == NULL)
3660 : : pref_type = NULL_TREE;
3661 : : else
3662 : : {
3663 : 5 : pref_type = build_string (n->u.init.len,
3664 : : n->u2.init_interop);
3665 : 5 : TREE_TYPE (pref_type)
3666 : 10 : = build_array_type_nelts (unsigned_char_type_node,
3667 : 5 : n->u.init.len);
3668 : : }
3669 : : }
3670 : 26 : OMP_CLAUSE_INIT_PREFER_TYPE (node) = pref_type;
3671 : 26 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3672 : : }
3673 : : break;
3674 : : }
3675 : :
3676 : : case OMP_LIST_ALIGNED:
3677 : 256 : for (; n != NULL; n = n->next)
3678 : 149 : if (n->sym->attr.referenced || declare_simd)
3679 : : {
3680 : 149 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3681 : 149 : if (t != error_mark_node)
3682 : : {
3683 : 149 : tree node = build_omp_clause (input_location,
3684 : : OMP_CLAUSE_ALIGNED);
3685 : 149 : OMP_CLAUSE_DECL (node) = t;
3686 : 149 : if (n->expr)
3687 : : {
3688 : 148 : tree alignment_var;
3689 : :
3690 : 148 : if (declare_simd)
3691 : 5 : alignment_var = gfc_conv_constant_to_tree (n->expr);
3692 : : else
3693 : : {
3694 : 143 : gfc_init_se (&se, NULL);
3695 : 143 : gfc_conv_expr (&se, n->expr);
3696 : 143 : gfc_add_block_to_block (block, &se.pre);
3697 : 143 : alignment_var = gfc_evaluate_now (se.expr, block);
3698 : 143 : gfc_add_block_to_block (block, &se.post);
3699 : : }
3700 : 148 : OMP_CLAUSE_ALIGNED_ALIGNMENT (node) = alignment_var;
3701 : : }
3702 : 149 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3703 : : }
3704 : : }
3705 : : break;
3706 : : case OMP_LIST_ALLOCATE:
3707 : : {
3708 : : tree allocator_ = NULL_TREE;
3709 : : gfc_expr *alloc_expr = NULL;
3710 : 582 : for (; n != NULL; n = n->next)
3711 : 377 : if (n->sym->attr.referenced)
3712 : : {
3713 : 377 : tree t = gfc_trans_omp_variable (n->sym, false);
3714 : 377 : if (t != error_mark_node)
3715 : : {
3716 : 377 : tree node = build_omp_clause (input_location,
3717 : : OMP_CLAUSE_ALLOCATE);
3718 : 377 : OMP_CLAUSE_DECL (node) = t;
3719 : 377 : if (n->u2.allocator)
3720 : : {
3721 : 242 : if (alloc_expr != n->u2.allocator)
3722 : : {
3723 : 125 : gfc_init_se (&se, NULL);
3724 : 125 : gfc_conv_expr (&se, n->u2.allocator);
3725 : 125 : gfc_add_block_to_block (block, &se.pre);
3726 : 125 : allocator_ = gfc_evaluate_now (se.expr, block);
3727 : 125 : gfc_add_block_to_block (block, &se.post);
3728 : : }
3729 : 242 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (node) = allocator_;
3730 : : }
3731 : 377 : alloc_expr = n->u2.allocator;
3732 : 377 : if (n->u.align)
3733 : : {
3734 : 3 : tree align_;
3735 : 3 : gfc_init_se (&se, NULL);
3736 : 3 : gfc_conv_expr (&se, n->u.align);
3737 : 3 : gcc_assert (CONSTANT_CLASS_P (se.expr)
3738 : : && se.pre.head == NULL
3739 : : && se.post.head == NULL);
3740 : 3 : align_ = se.expr;
3741 : 3 : OMP_CLAUSE_ALLOCATE_ALIGN (node) = align_;
3742 : : }
3743 : 377 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3744 : : }
3745 : : }
3746 : : else
3747 : 0 : alloc_expr = n->u2.allocator;
3748 : : }
3749 : : break;
3750 : : case OMP_LIST_LINEAR:
3751 : : {
3752 : : gfc_expr *last_step_expr = NULL;
3753 : : tree last_step = NULL_TREE;
3754 : : bool last_step_parm = false;
3755 : :
3756 : 1288 : for (; n != NULL; n = n->next)
3757 : : {
3758 : 795 : if (n->expr)
3759 : : {
3760 : 776 : last_step_expr = n->expr;
3761 : 776 : last_step = NULL_TREE;
3762 : 776 : last_step_parm = false;
3763 : : }
3764 : 795 : if (n->sym->attr.referenced || declare_simd)
3765 : : {
3766 : 795 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3767 : 795 : if (t != error_mark_node)
3768 : : {
3769 : 795 : tree node = build_omp_clause (input_location,
3770 : : OMP_CLAUSE_LINEAR);
3771 : 795 : OMP_CLAUSE_DECL (node) = t;
3772 : 795 : omp_clause_linear_kind kind;
3773 : 795 : switch (n->u.linear.op)
3774 : : {
3775 : : case OMP_LINEAR_DEFAULT:
3776 : : kind = OMP_CLAUSE_LINEAR_DEFAULT;
3777 : : break;
3778 : : case OMP_LINEAR_REF:
3779 : : kind = OMP_CLAUSE_LINEAR_REF;
3780 : : break;
3781 : : case OMP_LINEAR_VAL:
3782 : : kind = OMP_CLAUSE_LINEAR_VAL;
3783 : : break;
3784 : : case OMP_LINEAR_UVAL:
3785 : : kind = OMP_CLAUSE_LINEAR_UVAL;
3786 : : break;
3787 : 0 : default:
3788 : 0 : gcc_unreachable ();
3789 : : }
3790 : 795 : OMP_CLAUSE_LINEAR_KIND (node) = kind;
3791 : 795 : OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (node)
3792 : 795 : = n->u.linear.old_modifier;
3793 : 795 : if (last_step_expr && last_step == NULL_TREE)
3794 : : {
3795 : 776 : if (!declare_simd)
3796 : : {
3797 : 695 : gfc_init_se (&se, NULL);
3798 : 695 : gfc_conv_expr (&se, last_step_expr);
3799 : 695 : gfc_add_block_to_block (block, &se.pre);
3800 : 695 : last_step = gfc_evaluate_now (se.expr, block);
3801 : 695 : gfc_add_block_to_block (block, &se.post);
3802 : : }
3803 : 81 : else if (last_step_expr->expr_type == EXPR_VARIABLE)
3804 : : {
3805 : 2 : gfc_symbol *s = last_step_expr->symtree->n.sym;
3806 : 2 : last_step = gfc_trans_omp_variable (s, true);
3807 : 2 : last_step_parm = true;
3808 : : }
3809 : : else
3810 : 79 : last_step
3811 : 79 : = gfc_conv_constant_to_tree (last_step_expr);
3812 : : }
3813 : 795 : if (last_step_parm)
3814 : : {
3815 : 2 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (node) = 1;
3816 : 2 : OMP_CLAUSE_LINEAR_STEP (node) = last_step;
3817 : : }
3818 : : else
3819 : : {
3820 : 793 : if (kind == OMP_CLAUSE_LINEAR_REF)
3821 : : {
3822 : 34 : tree type;
3823 : 34 : if (n->sym->attr.flavor == FL_PROCEDURE)
3824 : : {
3825 : 0 : type = gfc_get_function_type (n->sym);
3826 : 0 : type = build_pointer_type (type);
3827 : : }
3828 : : else
3829 : 34 : type = gfc_sym_type (n->sym);
3830 : 34 : if (POINTER_TYPE_P (type))
3831 : 34 : type = TREE_TYPE (type);
3832 : : /* Otherwise to be determined what exactly
3833 : : should be done. */
3834 : 34 : tree t = fold_convert (sizetype, last_step);
3835 : 34 : t = size_binop (MULT_EXPR, t,
3836 : : TYPE_SIZE_UNIT (type));
3837 : 34 : OMP_CLAUSE_LINEAR_STEP (node) = t;
3838 : : }
3839 : : else
3840 : : {
3841 : 759 : tree type
3842 : 759 : = gfc_typenode_for_spec (&n->sym->ts);
3843 : 759 : OMP_CLAUSE_LINEAR_STEP (node)
3844 : 1518 : = fold_convert (type, last_step);
3845 : : }
3846 : : }
3847 : 795 : if (n->sym->attr.dimension || n->sym->attr.allocatable)
3848 : 222 : OMP_CLAUSE_LINEAR_ARRAY (node) = 1;
3849 : 795 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3850 : : }
3851 : : }
3852 : : }
3853 : : }
3854 : : break;
3855 : : case OMP_LIST_AFFINITY:
3856 : : case OMP_LIST_DEPEND:
3857 : : iterator = NULL_TREE;
3858 : : prev = NULL;
3859 : : prev_clauses = omp_clauses;
3860 : 1574 : for (; n != NULL; n = n->next)
3861 : : {
3862 : 853 : if (iterator && prev->u2.ns != n->u2.ns)
3863 : : {
3864 : 12 : BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
3865 : 12 : TREE_VEC_ELT (iterator, 5) = tree_block;
3866 : 26 : for (tree c = omp_clauses; c != prev_clauses;
3867 : 14 : c = OMP_CLAUSE_CHAIN (c))
3868 : 28 : OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
3869 : 14 : OMP_CLAUSE_DECL (c));
3870 : : prev_clauses = omp_clauses;
3871 : : iterator = NULL_TREE;
3872 : : }
3873 : 853 : if (n->u2.ns && (!prev || prev->u2.ns != n->u2.ns))
3874 : : {
3875 : 43 : gfc_init_block (&iter_block);
3876 : 43 : tree_block = make_node (BLOCK);
3877 : 43 : TREE_USED (tree_block) = 1;
3878 : 43 : BLOCK_VARS (tree_block) = NULL_TREE;
3879 : 43 : iterator = handle_iterator (n->u2.ns, block,
3880 : : tree_block);
3881 : : }
3882 : 853 : if (!iterator)
3883 : 801 : gfc_init_block (&iter_block);
3884 : 853 : prev = n;
3885 : 853 : if (list == OMP_LIST_DEPEND
3886 : 827 : && (n->u.depend_doacross_op == OMP_DOACROSS_SINK_FIRST
3887 : 827 : || n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST))
3888 : : {
3889 : 227 : tree vec = NULL_TREE;
3890 : 227 : unsigned int i;
3891 : 227 : bool is_depend
3892 : : = n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST;
3893 : 227 : for (i = 0; ; i++)
3894 : : {
3895 : 1218 : tree addend = integer_zero_node, t;
3896 : 1218 : bool neg = false;
3897 : 1218 : if (n->sym && n->expr)
3898 : : {
3899 : 558 : addend = gfc_conv_constant_to_tree (n->expr);
3900 : 558 : if (TREE_CODE (addend) == INTEGER_CST
3901 : 558 : && tree_int_cst_sgn (addend) == -1)
3902 : : {
3903 : 407 : neg = true;
3904 : 407 : addend = const_unop (NEGATE_EXPR,
3905 : 407 : TREE_TYPE (addend), addend);
3906 : : }
3907 : : }
3908 : :
3909 : 1218 : if (n->sym == NULL)
3910 : 0 : t = null_pointer_node; /* "omp_cur_iteration - 1". */
3911 : : else
3912 : 1218 : t = gfc_trans_omp_variable (n->sym, false);
3913 : 1218 : if (t != error_mark_node)
3914 : : {
3915 : 1218 : if (i < vec_safe_length (doacross_steps)
3916 : 426 : && !integer_zerop (addend)
3917 : 630 : && (*doacross_steps)[i])
3918 : : {
3919 : 204 : tree step = (*doacross_steps)[i];
3920 : 204 : addend = fold_convert (TREE_TYPE (step), addend);
3921 : 204 : addend = build2 (TRUNC_DIV_EXPR,
3922 : 204 : TREE_TYPE (step), addend, step);
3923 : : }
3924 : 1218 : vec = tree_cons (addend, t, vec);
3925 : 1218 : if (neg)
3926 : 407 : OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (vec) = 1;
3927 : : }
3928 : 1218 : if (n->next == NULL
3929 : 1057 : || n->next->u.depend_doacross_op != OMP_DOACROSS_SINK)
3930 : : break;
3931 : 991 : n = n->next;
3932 : 991 : }
3933 : 227 : if (vec == NULL_TREE)
3934 : 0 : continue;
3935 : :
3936 : 227 : tree node = build_omp_clause (input_location,
3937 : : OMP_CLAUSE_DOACROSS);
3938 : 227 : OMP_CLAUSE_DOACROSS_KIND (node) = OMP_CLAUSE_DOACROSS_SINK;
3939 : 227 : OMP_CLAUSE_DOACROSS_DEPEND (node) = is_depend;
3940 : 227 : OMP_CLAUSE_DECL (node) = nreverse (vec);
3941 : 227 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3942 : 227 : continue;
3943 : 227 : }
3944 : :
3945 : 626 : if (n->sym && !n->sym->attr.referenced)
3946 : 0 : continue;
3947 : :
3948 : 652 : tree node = build_omp_clause (input_location,
3949 : : list == OMP_LIST_DEPEND
3950 : : ? OMP_CLAUSE_DEPEND
3951 : : : OMP_CLAUSE_AFFINITY);
3952 : 626 : if (n->sym == NULL) /* omp_all_memory */
3953 : 9 : OMP_CLAUSE_DECL (node) = null_pointer_node;
3954 : 617 : else if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL)
3955 : : {
3956 : 404 : tree decl = gfc_trans_omp_variable (n->sym, false);
3957 : 404 : if (gfc_omp_privatize_by_reference (decl))
3958 : 62 : decl = build_fold_indirect_ref (decl);
3959 : 404 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
3960 : : {
3961 : 23 : decl = gfc_conv_descriptor_data_get (decl);
3962 : 23 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
3963 : 23 : decl = build_fold_indirect_ref (decl);
3964 : : }
3965 : 381 : else if (n->sym->attr.allocatable || n->sym->attr.pointer)
3966 : 22 : decl = build_fold_indirect_ref (decl);
3967 : 359 : else if (DECL_P (decl))
3968 : 326 : TREE_ADDRESSABLE (decl) = 1;
3969 : 404 : OMP_CLAUSE_DECL (node) = decl;
3970 : 404 : }
3971 : : else
3972 : : {
3973 : 213 : tree ptr;
3974 : 213 : gfc_init_se (&se, NULL);
3975 : 213 : if (n->expr->ref->u.ar.type == AR_ELEMENT)
3976 : : {
3977 : 133 : gfc_conv_expr_reference (&se, n->expr);
3978 : 133 : ptr = se.expr;
3979 : : }
3980 : : else
3981 : : {
3982 : 80 : gfc_conv_expr_descriptor (&se, n->expr);
3983 : 80 : ptr = gfc_conv_array_data (se.expr);
3984 : : }
3985 : 213 : gfc_add_block_to_block (&iter_block, &se.pre);
3986 : 213 : gfc_add_block_to_block (&iter_block, &se.post);
3987 : 213 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
3988 : 213 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
3989 : : }
3990 : 626 : if (list == OMP_LIST_DEPEND)
3991 : 600 : switch (n->u.depend_doacross_op)
3992 : : {
3993 : 227 : case OMP_DEPEND_IN:
3994 : 227 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_IN;
3995 : 227 : break;
3996 : 256 : case OMP_DEPEND_OUT:
3997 : 256 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_OUT;
3998 : 256 : break;
3999 : 55 : case OMP_DEPEND_INOUT:
4000 : 55 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUT;
4001 : 55 : break;
4002 : 9 : case OMP_DEPEND_INOUTSET:
4003 : 9 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUTSET;
4004 : 9 : break;
4005 : 15 : case OMP_DEPEND_MUTEXINOUTSET:
4006 : 15 : OMP_CLAUSE_DEPEND_KIND (node)
4007 : 15 : = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
4008 : 15 : break;
4009 : 38 : case OMP_DEPEND_DEPOBJ:
4010 : 38 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_DEPOBJ;
4011 : 38 : break;
4012 : 0 : default:
4013 : 0 : gcc_unreachable ();
4014 : : }
4015 : 626 : if (!iterator)
4016 : 574 : gfc_add_block_to_block (block, &iter_block);
4017 : 626 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
4018 : : }
4019 : 721 : if (iterator)
4020 : : {
4021 : 31 : BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
4022 : 31 : TREE_VEC_ELT (iterator, 5) = tree_block;
4023 : 70 : for (tree c = omp_clauses; c != prev_clauses;
4024 : 39 : c = OMP_CLAUSE_CHAIN (c))
4025 : 78 : OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
4026 : 39 : OMP_CLAUSE_DECL (c));
4027 : : }
4028 : : break;
4029 : : case OMP_LIST_MAP:
4030 : 23509 : for (; n != NULL; n = n->next)
4031 : : {
4032 : 14824 : if (!n->sym->attr.referenced)
4033 : 280 : continue;
4034 : :
4035 : 14824 : location_t map_loc = gfc_get_location (&n->where);
4036 : 14824 : bool always_modifier = false;
4037 : 14824 : tree node = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4038 : 14824 : tree node2 = NULL_TREE;
4039 : 14824 : tree node3 = NULL_TREE;
4040 : 14824 : tree node4 = NULL_TREE;
4041 : 14824 : tree node5 = NULL_TREE;
4042 : :
4043 : : /* OpenMP: automatically map pointer targets with the pointer;
4044 : : hence, always update the descriptor/pointer itself. */
4045 : 14824 : if (!openacc
4046 : 14824 : && ((n->expr == NULL && n->sym->attr.pointer)
4047 : 14036 : || (n->expr && gfc_expr_attr (n->expr).pointer)))
4048 : 1393 : always_modifier = true;
4049 : :
4050 : 14824 : if (n->u.map.readonly)
4051 : 22 : OMP_CLAUSE_MAP_READONLY (node) = 1;
4052 : :
4053 : 14824 : switch (n->u.map.op)
4054 : : {
4055 : 1073 : case OMP_MAP_ALLOC:
4056 : 1073 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALLOC);
4057 : 1073 : break;
4058 : 64 : case OMP_MAP_IF_PRESENT:
4059 : 64 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_IF_PRESENT);
4060 : 64 : break;
4061 : 62 : case OMP_MAP_ATTACH:
4062 : 62 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ATTACH);
4063 : 62 : break;
4064 : 4033 : case OMP_MAP_TO:
4065 : 4033 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TO);
4066 : 4033 : break;
4067 : 2849 : case OMP_MAP_FROM:
4068 : 2849 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FROM);
4069 : 2849 : break;
4070 : 4348 : case OMP_MAP_TOFROM:
4071 : 4348 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TOFROM);
4072 : 4348 : break;
4073 : 32 : case OMP_MAP_ALWAYS_TO:
4074 : 32 : always_modifier = true;
4075 : 32 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TO);
4076 : 32 : break;
4077 : 14 : case OMP_MAP_ALWAYS_FROM:
4078 : 14 : always_modifier = true;
4079 : 14 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_FROM);
4080 : 14 : break;
4081 : 171 : case OMP_MAP_ALWAYS_TOFROM:
4082 : 171 : always_modifier = true;
4083 : 171 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TOFROM);
4084 : 171 : break;
4085 : 6 : case OMP_MAP_PRESENT_ALLOC:
4086 : 6 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_ALLOC);
4087 : 6 : break;
4088 : 13 : case OMP_MAP_PRESENT_TO:
4089 : 13 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TO);
4090 : 13 : break;
4091 : 4 : case OMP_MAP_PRESENT_FROM:
4092 : 4 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_FROM);
4093 : 4 : break;
4094 : 2 : case OMP_MAP_PRESENT_TOFROM:
4095 : 2 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TOFROM);
4096 : 2 : break;
4097 : 8 : case OMP_MAP_ALWAYS_PRESENT_TO:
4098 : 8 : always_modifier = true;
4099 : 8 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TO);
4100 : 8 : break;
4101 : 4 : case OMP_MAP_ALWAYS_PRESENT_FROM:
4102 : 4 : always_modifier = true;
4103 : 4 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_FROM);
4104 : 4 : break;
4105 : 2 : case OMP_MAP_ALWAYS_PRESENT_TOFROM:
4106 : 2 : always_modifier = true;
4107 : 2 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TOFROM);
4108 : 2 : break;
4109 : 382 : case OMP_MAP_RELEASE:
4110 : 382 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_RELEASE);
4111 : 382 : break;
4112 : 56 : case OMP_MAP_DELETE:
4113 : 56 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DELETE);
4114 : 56 : break;
4115 : 40 : case OMP_MAP_DETACH:
4116 : 40 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DETACH);
4117 : 40 : break;
4118 : 64 : case OMP_MAP_FORCE_ALLOC:
4119 : 64 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_ALLOC);
4120 : 64 : break;
4121 : 465 : case OMP_MAP_FORCE_TO:
4122 : 465 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TO);
4123 : 465 : break;
4124 : 577 : case OMP_MAP_FORCE_FROM:
4125 : 577 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_FROM);
4126 : 577 : break;
4127 : 0 : case OMP_MAP_FORCE_TOFROM:
4128 : 0 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TOFROM);
4129 : 0 : break;
4130 : 545 : case OMP_MAP_FORCE_PRESENT:
4131 : 545 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_PRESENT);
4132 : 545 : break;
4133 : 10 : case OMP_MAP_FORCE_DEVICEPTR:
4134 : 10 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_DEVICEPTR);
4135 : 10 : break;
4136 : 0 : default:
4137 : 0 : gcc_unreachable ();
4138 : : }
4139 : :
4140 : 14824 : tree decl = gfc_trans_omp_variable (n->sym, false);
4141 : 14824 : if (DECL_P (decl))
4142 : 14824 : TREE_ADDRESSABLE (decl) = 1;
4143 : :
4144 : 14824 : gfc_ref *lastref = NULL;
4145 : :
4146 : 14824 : if (n->expr)
4147 : 12838 : for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
4148 : 7526 : if (ref->type == REF_COMPONENT || ref->type == REF_ARRAY)
4149 : 7526 : lastref = ref;
4150 : :
4151 : 5312 : bool allocatable = false, pointer = false;
4152 : :
4153 : 5312 : if (lastref && lastref->type == REF_COMPONENT)
4154 : : {
4155 : 457 : gfc_component *c = lastref->u.c.component;
4156 : :
4157 : 457 : if (c->ts.type == BT_CLASS)
4158 : : {
4159 : 24 : pointer = CLASS_DATA (c)->attr.class_pointer;
4160 : 24 : allocatable = CLASS_DATA (c)->attr.allocatable;
4161 : : }
4162 : : else
4163 : : {
4164 : 433 : pointer = c->attr.pointer;
4165 : 433 : allocatable = c->attr.allocatable;
4166 : : }
4167 : : }
4168 : :
4169 : 14824 : if (n->expr == NULL
4170 : 5312 : || (n->expr->ref->type == REF_ARRAY
4171 : 3549 : && n->expr->ref->u.ar.type == AR_FULL))
4172 : : {
4173 : 9512 : gomp_map_kind map_kind;
4174 : 9512 : tree type = TREE_TYPE (decl);
4175 : 9512 : if (n->sym->ts.type == BT_CHARACTER
4176 : 218 : && n->sym->ts.deferred
4177 : 92 : && n->sym->attr.omp_declare_target
4178 : 8 : && (always_modifier || n->sym->attr.pointer)
4179 : 8 : && op != EXEC_OMP_TARGET_EXIT_DATA
4180 : 4 : && n->u.map.op != OMP_MAP_DELETE
4181 : 4 : && n->u.map.op != OMP_MAP_RELEASE)
4182 : : {
4183 : 4 : gcc_assert (n->sym->ts.u.cl->backend_decl);
4184 : 4 : node5 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4185 : 4 : OMP_CLAUSE_SET_MAP_KIND (node5, GOMP_MAP_ALWAYS_TO);
4186 : 4 : OMP_CLAUSE_DECL (node5) = n->sym->ts.u.cl->backend_decl;
4187 : 4 : OMP_CLAUSE_SIZE (node5)
4188 : 8 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4189 : : }
4190 : :
4191 : 9512 : tree present = gfc_omp_check_optional_argument (decl, true);
4192 : 9512 : if (openacc && n->sym->ts.type == BT_CLASS)
4193 : : {
4194 : 60 : if (n->sym->attr.optional)
4195 : 0 : sorry_at (gfc_get_location (&n->where),
4196 : : "optional class parameter");
4197 : 60 : tree ptr = gfc_class_data_get (decl);
4198 : 60 : ptr = build_fold_indirect_ref (ptr);
4199 : 60 : OMP_CLAUSE_DECL (node) = ptr;
4200 : 60 : OMP_CLAUSE_SIZE (node) = gfc_class_vtab_size_get (decl);
4201 : 60 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4202 : 60 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
4203 : 60 : OMP_CLAUSE_DECL (node2) = gfc_class_data_get (decl);
4204 : 60 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4205 : 60 : goto finalize_map_clause;
4206 : : }
4207 : 9452 : else if (POINTER_TYPE_P (type)
4208 : 9452 : && (gfc_omp_privatize_by_reference (decl)
4209 : 518 : || GFC_DECL_GET_SCALAR_POINTER (decl)
4210 : 347 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
4211 : 84 : || GFC_DECL_CRAY_POINTEE (decl)
4212 : 84 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
4213 : 84 : || (n->sym->ts.type == BT_DERIVED
4214 : 8 : && (n->sym->ts.u.derived->ts.f90_type
4215 : : != BT_VOID))))
4216 : : {
4217 : 3394 : tree orig_decl = decl;
4218 : :
4219 : : /* For nonallocatable, nonpointer arrays, a temporary
4220 : : variable is generated, but this one is only defined if
4221 : : the variable is present; hence, we now set it to NULL
4222 : : to avoid accessing undefined variables. We cannot use
4223 : : a temporary variable here as otherwise the replacement
4224 : : of the variables in omp-low.cc will not work. */
4225 : 3394 : if (present && GFC_ARRAY_TYPE_P (type))
4226 : : {
4227 : 284 : tree tmp = fold_build2_loc (input_location,
4228 : : MODIFY_EXPR,
4229 : : void_type_node, decl,
4230 : : null_pointer_node);
4231 : 284 : tree cond = fold_build1_loc (input_location,
4232 : : TRUTH_NOT_EXPR,
4233 : : boolean_type_node,
4234 : : present);
4235 : 284 : gfc_add_expr_to_block (block,
4236 : : build3_loc (input_location,
4237 : : COND_EXPR,
4238 : : void_type_node,
4239 : : cond, tmp,
4240 : : NULL_TREE));
4241 : : }
4242 : : /* For descriptor types, the unmapping happens below. */
4243 : 3394 : if (op != EXEC_OMP_TARGET_EXIT_DATA
4244 : 3394 : || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
4245 : : {
4246 : 3394 : enum gomp_map_kind gmk = GOMP_MAP_POINTER;
4247 : 3394 : if (op == EXEC_OMP_TARGET_EXIT_DATA
4248 : 57 : && n->u.map.op == OMP_MAP_DELETE)
4249 : : gmk = GOMP_MAP_DELETE;
4250 : 52 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4251 : 52 : gmk = GOMP_MAP_RELEASE;
4252 : 3394 : tree size;
4253 : 3394 : if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
4254 : 57 : size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
4255 : : else
4256 : 3337 : size = size_int (0);
4257 : 3394 : node4 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4258 : 3394 : OMP_CLAUSE_SET_MAP_KIND (node4, gmk);
4259 : 3394 : OMP_CLAUSE_DECL (node4) = decl;
4260 : 3394 : OMP_CLAUSE_SIZE (node4) = size;
4261 : : }
4262 : 3394 : decl = build_fold_indirect_ref (decl);
4263 : 3394 : if ((TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
4264 : 2167 : || gfc_omp_is_optional_argument (orig_decl))
4265 : 4446 : && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
4266 : 2109 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
4267 : : {
4268 : 408 : enum gomp_map_kind gmk;
4269 : 408 : if (op == EXEC_OMP_TARGET_EXIT_DATA
4270 : 8 : && n->u.map.op == OMP_MAP_DELETE)
4271 : : gmk = GOMP_MAP_DELETE;
4272 : 6 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4273 : : gmk = GOMP_MAP_RELEASE;
4274 : : else
4275 : : gmk = GOMP_MAP_POINTER;
4276 : 408 : tree size;
4277 : 408 : if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
4278 : 8 : size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
4279 : : else
4280 : 400 : size = size_int (0);
4281 : 408 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4282 : 408 : OMP_CLAUSE_SET_MAP_KIND (node3, gmk);
4283 : 408 : OMP_CLAUSE_DECL (node3) = decl;
4284 : 408 : OMP_CLAUSE_SIZE (node3) = size;
4285 : 408 : decl = build_fold_indirect_ref (decl);
4286 : : }
4287 : : }
4288 : 9452 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
4289 : : {
4290 : 1384 : tree type = TREE_TYPE (decl);
4291 : 1384 : tree ptr = gfc_conv_descriptor_data_get (decl);
4292 : 1384 : if (present)
4293 : 309 : ptr = gfc_build_cond_assign_expr (block, present, ptr,
4294 : : null_pointer_node);
4295 : 1384 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
4296 : 1384 : ptr = build_fold_indirect_ref (ptr);
4297 : 1384 : OMP_CLAUSE_DECL (node) = ptr;
4298 : 1384 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4299 : 1384 : OMP_CLAUSE_DECL (node2) = decl;
4300 : 1384 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
4301 : 1384 : if (n->u.map.op == OMP_MAP_DELETE)
4302 : : map_kind = GOMP_MAP_DELETE;
4303 : 1357 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
4304 : 1296 : || n->u.map.op == OMP_MAP_RELEASE)
4305 : : map_kind = GOMP_MAP_RELEASE;
4306 : : else
4307 : 1384 : map_kind = GOMP_MAP_TO_PSET;
4308 : 1384 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
4309 : :
4310 : 1384 : if (op != EXEC_OMP_TARGET_EXIT_DATA
4311 : 1296 : && n->u.map.op != OMP_MAP_DELETE
4312 : 1296 : && n->u.map.op != OMP_MAP_RELEASE)
4313 : : {
4314 : 1254 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4315 : 1254 : if (present)
4316 : : {
4317 : 309 : ptr = gfc_conv_descriptor_data_get (decl);
4318 : 309 : ptr = gfc_build_addr_expr (NULL, ptr);
4319 : 309 : ptr = gfc_build_cond_assign_expr (
4320 : : block, present, ptr, null_pointer_node);
4321 : 309 : ptr = build_fold_indirect_ref (ptr);
4322 : 309 : OMP_CLAUSE_DECL (node3) = ptr;
4323 : : }
4324 : : else
4325 : 945 : OMP_CLAUSE_DECL (node3)
4326 : 1890 : = gfc_conv_descriptor_data_get (decl);
4327 : 1254 : OMP_CLAUSE_SIZE (node3) = size_int (0);
4328 : :
4329 : 1254 : if (n->u.map.op == OMP_MAP_ATTACH)
4330 : : {
4331 : : /* Standalone attach clauses used with arrays with
4332 : : descriptors must copy the descriptor to the
4333 : : target, else they won't have anything to
4334 : : perform the attachment onto (see OpenACC 2.6,
4335 : : "2.6.3. Data Structures with Pointers"). */
4336 : 7 : OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH);
4337 : : /* We don't want to map PTR at all in this case,
4338 : : so delete its node and shuffle the others
4339 : : down. */
4340 : 7 : node = node2;
4341 : 7 : node2 = node3;
4342 : 7 : node3 = NULL;
4343 : 7 : goto finalize_map_clause;
4344 : : }
4345 : 1247 : else if (n->u.map.op == OMP_MAP_DETACH)
4346 : : {
4347 : 2 : OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_DETACH);
4348 : : /* Similarly to above, we don't want to unmap PTR
4349 : : here. */
4350 : 2 : node = node2;
4351 : 2 : node2 = node3;
4352 : 2 : node3 = NULL;
4353 : 2 : goto finalize_map_clause;
4354 : : }
4355 : : else
4356 : 2022 : OMP_CLAUSE_SET_MAP_KIND (node3,
4357 : : always_modifier
4358 : : ? GOMP_MAP_ALWAYS_POINTER
4359 : : : GOMP_MAP_POINTER);
4360 : : }
4361 : :
4362 : : /* We have to check for n->sym->attr.dimension because
4363 : : of scalar coarrays. */
4364 : 1375 : if ((n->sym->attr.pointer || n->sym->attr.allocatable)
4365 : 1375 : && n->sym->attr.dimension)
4366 : : {
4367 : 1375 : stmtblock_t cond_block;
4368 : 1375 : tree size
4369 : 1375 : = gfc_create_var (gfc_array_index_type, NULL);
4370 : 1375 : tree tem, then_b, else_b, zero, cond;
4371 : :
4372 : 1375 : gfc_init_block (&cond_block);
4373 : 1375 : tem
4374 : 2750 : = gfc_full_array_size (&cond_block, decl,
4375 : 1375 : GFC_TYPE_ARRAY_RANK (type));
4376 : 1375 : tree elemsz;
4377 : 1375 : if (n->sym->ts.type == BT_CHARACTER
4378 : 52 : && n->sym->ts.deferred)
4379 : : {
4380 : 44 : tree len = n->sym->ts.u.cl->backend_decl;
4381 : 44 : len = fold_convert (size_type_node, len);
4382 : 44 : elemsz = gfc_get_char_type (n->sym->ts.kind);
4383 : 44 : elemsz = TYPE_SIZE_UNIT (elemsz);
4384 : 44 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
4385 : : len, elemsz);
4386 : 44 : }
4387 : : else
4388 : 1331 : elemsz
4389 : 1331 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4390 : 1375 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4391 : 1375 : tem = fold_build2 (MULT_EXPR, gfc_array_index_type,
4392 : : tem, elemsz);
4393 : 1375 : gfc_add_modify (&cond_block, size, tem);
4394 : 1375 : then_b = gfc_finish_block (&cond_block);
4395 : 1375 : gfc_init_block (&cond_block);
4396 : 1375 : zero = build_int_cst (gfc_array_index_type, 0);
4397 : 1375 : gfc_add_modify (&cond_block, size, zero);
4398 : 1375 : else_b = gfc_finish_block (&cond_block);
4399 : 1375 : tem = gfc_conv_descriptor_data_get (decl);
4400 : 1375 : tem = fold_convert (pvoid_type_node, tem);
4401 : 1375 : cond = fold_build2_loc (input_location, NE_EXPR,
4402 : : boolean_type_node,
4403 : : tem, null_pointer_node);
4404 : 1375 : if (present)
4405 : 309 : cond = fold_build2_loc (input_location,
4406 : : TRUTH_ANDIF_EXPR,
4407 : : boolean_type_node,
4408 : : present, cond);
4409 : 1375 : gfc_add_expr_to_block (block,
4410 : : build3_loc (input_location,
4411 : : COND_EXPR,
4412 : : void_type_node,
4413 : : cond, then_b,
4414 : : else_b));
4415 : 1375 : OMP_CLAUSE_SIZE (node) = size;
4416 : 1375 : }
4417 : 0 : else if (n->sym->attr.dimension)
4418 : : {
4419 : 0 : stmtblock_t cond_block;
4420 : 0 : gfc_init_block (&cond_block);
4421 : 0 : tree size = gfc_full_array_size (&cond_block, decl,
4422 : 0 : GFC_TYPE_ARRAY_RANK (type));
4423 : 0 : tree elemsz
4424 : 0 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4425 : 0 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4426 : 0 : size = fold_build2 (MULT_EXPR, gfc_array_index_type,
4427 : : size, elemsz);
4428 : 0 : size = gfc_evaluate_now (size, &cond_block);
4429 : 0 : if (present)
4430 : : {
4431 : 0 : tree var = gfc_create_var (gfc_array_index_type,
4432 : : NULL);
4433 : 0 : gfc_add_modify (&cond_block, var, size);
4434 : 0 : tree cond_body = gfc_finish_block (&cond_block);
4435 : 0 : tree cond = build3_loc (input_location, COND_EXPR,
4436 : : void_type_node, present,
4437 : : cond_body, NULL_TREE);
4438 : 0 : gfc_add_expr_to_block (block, cond);
4439 : 0 : OMP_CLAUSE_SIZE (node) = var;
4440 : : }
4441 : : else
4442 : : {
4443 : 0 : gfc_add_block_to_block (block, &cond_block);
4444 : 0 : OMP_CLAUSE_SIZE (node) = size;
4445 : : }
4446 : : }
4447 : : }
4448 : 8068 : else if (present
4449 : 845 : && INDIRECT_REF_P (decl)
4450 : 8811 : && INDIRECT_REF_P (TREE_OPERAND (decl, 0)))
4451 : : {
4452 : : /* A single indirectref is handled by the middle end. */
4453 : 228 : gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
4454 : 228 : tree tmp = TREE_OPERAND (decl, 0);
4455 : 228 : tmp = gfc_build_cond_assign_expr (block, present, tmp,
4456 : : null_pointer_node);
4457 : 228 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (tmp);
4458 : : }
4459 : : else
4460 : 7840 : OMP_CLAUSE_DECL (node) = decl;
4461 : :
4462 : 9443 : if (!n->sym->attr.dimension
4463 : 5987 : && n->sym->ts.type == BT_CHARACTER
4464 : 144 : && n->sym->ts.deferred)
4465 : : {
4466 : 48 : if (!DECL_P (decl))
4467 : : {
4468 : 48 : gcc_assert (TREE_CODE (decl) == INDIRECT_REF);
4469 : 48 : decl = TREE_OPERAND (decl, 0);
4470 : : }
4471 : 48 : tree cond = fold_build2_loc (input_location, NE_EXPR,
4472 : : boolean_type_node,
4473 : : decl, null_pointer_node);
4474 : 48 : if (present)
4475 : 2 : cond = fold_build2_loc (input_location,
4476 : : TRUTH_ANDIF_EXPR,
4477 : : boolean_type_node,
4478 : : present, cond);
4479 : 48 : tree len = n->sym->ts.u.cl->backend_decl;
4480 : 48 : len = fold_convert (size_type_node, len);
4481 : 48 : tree size = gfc_get_char_type (n->sym->ts.kind);
4482 : 48 : size = TYPE_SIZE_UNIT (size);
4483 : 48 : size = fold_build2 (MULT_EXPR, size_type_node, len, size);
4484 : 48 : size = build3_loc (input_location,
4485 : : COND_EXPR,
4486 : : size_type_node,
4487 : : cond, size,
4488 : : size_zero_node);
4489 : 48 : size = gfc_evaluate_now (size, block);
4490 : 48 : OMP_CLAUSE_SIZE (node) = size;
4491 : : }
4492 : 9443 : if ((TREE_CODE (decl) != PARM_DECL
4493 : 186 : || DECL_ARTIFICIAL (OMP_CLAUSE_DECL (node)))
4494 : 9257 : && n->sym->ts.type == BT_DERIVED
4495 : 9972 : && n->sym->ts.u.derived->attr.alloc_comp)
4496 : : {
4497 : : /* Save array descriptor for use in
4498 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4499 : : to ensure that it is not gimplified + is a decl. */
4500 : 209 : tree tmp = OMP_CLAUSE_SIZE (node);
4501 : 209 : if (tmp == NULL_TREE)
4502 : 247 : tmp = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
4503 : 67 : : TYPE_SIZE_UNIT (TREE_TYPE (decl));
4504 : 209 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4505 : 209 : gfc_add_modify_loc (input_location, block, var, tmp);
4506 : 209 : OMP_CLAUSE_SIZE (node) = var;
4507 : 209 : gfc_allocate_lang_decl (var);
4508 : 209 : if (TREE_CODE (decl) == INDIRECT_REF)
4509 : 69 : decl = TREE_OPERAND (decl, 0);
4510 : 209 : if (TREE_CODE (decl) == INDIRECT_REF)
4511 : 2 : decl = TREE_OPERAND (decl, 0);
4512 : 209 : if (DECL_LANG_SPECIFIC (decl)
4513 : 209 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
4514 : 6 : GFC_DECL_SAVED_DESCRIPTOR (var)
4515 : 2 : = GFC_DECL_SAVED_DESCRIPTOR (decl);
4516 : : else
4517 : 207 : GFC_DECL_SAVED_DESCRIPTOR (var) = decl;
4518 : : }
4519 : : }
4520 : 5312 : else if (n->expr
4521 : 5312 : && n->expr->expr_type == EXPR_VARIABLE
4522 : 5312 : && n->expr->ref->type == REF_ARRAY
4523 : 3549 : && !n->expr->ref->next)
4524 : : {
4525 : : /* An array element or array section which is not part of a
4526 : : derived type, etc. */
4527 : 3294 : bool element = n->expr->ref->u.ar.type == AR_ELEMENT;
4528 : 3294 : tree type = TREE_TYPE (decl);
4529 : 3294 : gomp_map_kind k = GOMP_MAP_POINTER;
4530 : 3294 : if (!openacc
4531 : 443 : && !GFC_DESCRIPTOR_TYPE_P (type)
4532 : 3682 : && !(POINTER_TYPE_P (type)
4533 : 256 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))))
4534 : : k = GOMP_MAP_FIRSTPRIVATE_POINTER;
4535 : 3294 : gfc_trans_omp_array_section (block, op, n, decl, element,
4536 : 3294 : !openacc, k, node, node2,
4537 : : node3, node4);
4538 : 3294 : }
4539 : 2018 : else if (n->expr
4540 : 2018 : && n->expr->expr_type == EXPR_VARIABLE
4541 : 2018 : && (n->expr->ref->type == REF_COMPONENT
4542 : : || n->expr->ref->type == REF_ARRAY)
4543 : 2018 : && lastref
4544 : 2018 : && lastref->type == REF_COMPONENT
4545 : 457 : && lastref->u.c.component->ts.type != BT_CLASS
4546 : 433 : && lastref->u.c.component->ts.type != BT_DERIVED
4547 : 341 : && !lastref->u.c.component->attr.dimension)
4548 : : {
4549 : : /* Derived type access with last component being a scalar. */
4550 : 341 : gfc_init_se (&se, NULL);
4551 : :
4552 : 341 : gfc_conv_expr (&se, n->expr);
4553 : 341 : gfc_add_block_to_block (block, &se.pre);
4554 : : /* For BT_CHARACTER a pointer is returned. */
4555 : 341 : OMP_CLAUSE_DECL (node)
4556 : 588 : = POINTER_TYPE_P (TREE_TYPE (se.expr))
4557 : 341 : ? build_fold_indirect_ref (se.expr) : se.expr;
4558 : 341 : gfc_add_block_to_block (block, &se.post);
4559 : 341 : if (pointer || allocatable)
4560 : : {
4561 : : /* If it's a bare attach/detach clause, we just want
4562 : : to perform a single attach/detach operation, of the
4563 : : pointer itself, not of the pointed-to object. */
4564 : 161 : if (openacc
4565 : 68 : && (n->u.map.op == OMP_MAP_ATTACH
4566 : 50 : || n->u.map.op == OMP_MAP_DETACH))
4567 : : {
4568 : 36 : OMP_CLAUSE_DECL (node)
4569 : 36 : = build_fold_addr_expr (OMP_CLAUSE_DECL (node));
4570 : 36 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4571 : 36 : goto finalize_map_clause;
4572 : : }
4573 : :
4574 : 125 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4575 : 125 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
4576 : 125 : OMP_CLAUSE_DECL (node2)
4577 : 180 : = POINTER_TYPE_P (TREE_TYPE (se.expr))
4578 : 125 : ? se.expr
4579 : 55 : : gfc_build_addr_expr (NULL, se.expr);
4580 : 125 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4581 : 125 : if (!openacc
4582 : 93 : && n->expr->ts.type == BT_CHARACTER
4583 : 54 : && n->expr->ts.deferred)
4584 : : {
4585 : 54 : gcc_assert (se.string_length);
4586 : 54 : tree tmp
4587 : 54 : = gfc_get_char_type (n->expr->ts.kind);
4588 : 54 : OMP_CLAUSE_SIZE (node)
4589 : 54 : = fold_build2 (MULT_EXPR, size_type_node,
4590 : : fold_convert (size_type_node,
4591 : : se.string_length),
4592 : : TYPE_SIZE_UNIT (tmp));
4593 : 54 : gomp_map_kind kind;
4594 : 54 : if (n->u.map.op == OMP_MAP_DELETE)
4595 : : kind = GOMP_MAP_DELETE;
4596 : 54 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4597 : : kind = GOMP_MAP_RELEASE;
4598 : : else
4599 : 48 : kind = GOMP_MAP_TO;
4600 : 54 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4601 : 54 : OMP_CLAUSE_SET_MAP_KIND (node3, kind);
4602 : 54 : OMP_CLAUSE_DECL (node3) = se.string_length;
4603 : 54 : OMP_CLAUSE_SIZE (node3)
4604 : 108 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4605 : : }
4606 : 93 : if (!openacc
4607 : 93 : && n->expr->ts.type == BT_DERIVED
4608 : 0 : && n->expr->ts.u.derived->attr.alloc_comp)
4609 : : {
4610 : : /* Save array descriptor for use in
4611 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4612 : : to ensure that it is not gimplified + is a decl. */
4613 : 0 : tree tmp = OMP_CLAUSE_SIZE (node);
4614 : 0 : if (tmp == NULL_TREE)
4615 : 0 : tmp = (DECL_P (se.expr)
4616 : 0 : ? DECL_SIZE_UNIT (se.expr)
4617 : 0 : : TYPE_SIZE_UNIT (TREE_TYPE (se.expr)));
4618 : 0 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4619 : 0 : gfc_add_modify_loc (input_location, block, var, tmp);
4620 : 0 : OMP_CLAUSE_SIZE (node) = var;
4621 : 0 : gfc_allocate_lang_decl (var);
4622 : 0 : if (TREE_CODE (se.expr) == INDIRECT_REF)
4623 : 0 : se.expr = TREE_OPERAND (se.expr, 0);
4624 : 0 : if (DECL_LANG_SPECIFIC (se.expr)
4625 : 0 : && GFC_DECL_SAVED_DESCRIPTOR (se.expr))
4626 : 0 : GFC_DECL_SAVED_DESCRIPTOR (var)
4627 : 0 : = GFC_DECL_SAVED_DESCRIPTOR (se.expr);
4628 : : else
4629 : 0 : GFC_DECL_SAVED_DESCRIPTOR (var) = se.expr;
4630 : : }
4631 : : }
4632 : : }
4633 : 1677 : else if (n->expr
4634 : 1677 : && n->expr->expr_type == EXPR_VARIABLE
4635 : 1677 : && (n->expr->ref->type == REF_COMPONENT
4636 : : || n->expr->ref->type == REF_ARRAY))
4637 : : {
4638 : 1677 : gfc_init_se (&se, NULL);
4639 : 1677 : se.expr = gfc_maybe_dereference_var (n->sym, decl);
4640 : :
4641 : 5547 : for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
4642 : : {
4643 : 3870 : if (ref->type == REF_COMPONENT)
4644 : : {
4645 : 1934 : if (ref->u.c.sym->attr.extension)
4646 : 91 : conv_parent_component_references (&se, ref);
4647 : :
4648 : 1934 : gfc_conv_component_ref (&se, ref);
4649 : : }
4650 : 1936 : else if (ref->type == REF_ARRAY)
4651 : : {
4652 : 1936 : if (ref->u.ar.type == AR_ELEMENT && ref->next)
4653 : 375 : gfc_conv_array_ref (&se, &ref->u.ar, n->expr,
4654 : 375 : &n->expr->where);
4655 : : else
4656 : 1561 : gcc_assert (!ref->next);
4657 : : }
4658 : : else
4659 : 0 : sorry_at (gfc_get_location (&n->where),
4660 : : "unhandled expression type");
4661 : : }
4662 : :
4663 : 1677 : tree inner = se.expr;
4664 : :
4665 : : /* Last component is a derived type or class pointer. */
4666 : 1677 : if (lastref->type == REF_COMPONENT
4667 : 116 : && (lastref->u.c.component->ts.type == BT_DERIVED
4668 : 24 : || lastref->u.c.component->ts.type == BT_CLASS))
4669 : : {
4670 : 116 : if (pointer || allocatable)
4671 : : {
4672 : : /* If it's a bare attach/detach clause, we just want
4673 : : to perform a single attach/detach operation, of the
4674 : : pointer itself, not of the pointed-to object. */
4675 : 67 : if (openacc
4676 : 49 : && (n->u.map.op == OMP_MAP_ATTACH
4677 : 43 : || n->u.map.op == OMP_MAP_DETACH))
4678 : : {
4679 : 12 : OMP_CLAUSE_DECL (node)
4680 : 12 : = build_fold_addr_expr (inner);
4681 : 12 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4682 : 18 : goto finalize_map_clause;
4683 : : }
4684 : :
4685 : 18 : gfc_omp_namelist *n2
4686 : : = openacc ? NULL : clauses->lists[OMP_LIST_MAP];
4687 : :
4688 : 55 : bool sym_based;
4689 : 55 : n2 = get_symbol_rooted_namelist (sym_rooted_nl, n,
4690 : : n2, &sym_based);
4691 : :
4692 : : /* If the last reference is a pointer to a derived
4693 : : type ("foo%dt_ptr"), check if any subcomponents
4694 : : of the same derived type member are being mapped
4695 : : elsewhere in the clause list ("foo%dt_ptr%x",
4696 : : etc.). If we have such subcomponent mappings,
4697 : : we only create an ALLOC node for the pointer
4698 : : itself, and inhibit mapping the whole derived
4699 : : type. */
4700 : :
4701 : 103 : for (; n2 != NULL; n2 = n2->next)
4702 : : {
4703 : 54 : if ((!sym_based && n == n2)
4704 : 54 : || (sym_based && n == n2->u2.duplicate_of)
4705 : 42 : || !n2->expr)
4706 : 12 : continue;
4707 : :
4708 : 42 : if (!gfc_omp_expr_prefix_same (n->expr,
4709 : : n2->expr))
4710 : 36 : continue;
4711 : :
4712 : 6 : gfc_ref *ref1 = n->expr->ref;
4713 : 6 : gfc_ref *ref2 = n2->expr->ref;
4714 : :
4715 : 6 : while (ref1->next && ref2->next)
4716 : : {
4717 : : ref1 = ref1->next;
4718 : : ref2 = ref2->next;
4719 : : }
4720 : :
4721 : 6 : if (ref2->next)
4722 : : {
4723 : 6 : inner = build_fold_addr_expr (inner);
4724 : 6 : OMP_CLAUSE_SET_MAP_KIND (node,
4725 : : GOMP_MAP_ALLOC);
4726 : 6 : OMP_CLAUSE_DECL (node) = inner;
4727 : 6 : OMP_CLAUSE_SIZE (node)
4728 : 6 : = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4729 : 6 : goto finalize_map_clause;
4730 : : }
4731 : : }
4732 : :
4733 : 49 : tree data, size;
4734 : :
4735 : 49 : if (lastref->u.c.component->ts.type == BT_CLASS)
4736 : : {
4737 : 24 : data = gfc_class_data_get (inner);
4738 : 24 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (data)));
4739 : 24 : data = build_fold_indirect_ref (data);
4740 : 24 : size = gfc_class_vtab_size_get (inner);
4741 : : }
4742 : : else /* BT_DERIVED. */
4743 : : {
4744 : 25 : data = inner;
4745 : 25 : size = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4746 : : }
4747 : :
4748 : 49 : OMP_CLAUSE_DECL (node) = data;
4749 : 49 : OMP_CLAUSE_SIZE (node) = size;
4750 : 49 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4751 : 49 : OMP_CLAUSE_SET_MAP_KIND (node2,
4752 : : GOMP_MAP_ATTACH_DETACH);
4753 : 49 : OMP_CLAUSE_DECL (node2) = build_fold_addr_expr (data);
4754 : 49 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4755 : : }
4756 : : else
4757 : : {
4758 : 49 : OMP_CLAUSE_DECL (node) = inner;
4759 : 49 : OMP_CLAUSE_SIZE (node)
4760 : 98 : = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4761 : : }
4762 : 98 : if (!openacc
4763 : 14 : && n->expr->ts.type == BT_DERIVED
4764 : 14 : && n->expr->ts.u.derived->attr.alloc_comp)
4765 : : {
4766 : : /* Save array descriptor for use in
4767 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4768 : : to ensure that it is not gimplified + is a decl. */
4769 : 8 : tree tmp = OMP_CLAUSE_SIZE (node);
4770 : 8 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4771 : 8 : gfc_add_modify_loc (input_location, block, var, tmp);
4772 : 8 : OMP_CLAUSE_SIZE (node) = var;
4773 : 8 : gfc_allocate_lang_decl (var);
4774 : 8 : if (TREE_CODE (inner) == INDIRECT_REF)
4775 : 6 : inner = TREE_OPERAND (inner, 0);
4776 : 8 : GFC_DECL_SAVED_DESCRIPTOR (var) = inner;
4777 : : }
4778 : : }
4779 : 1561 : else if (lastref->type == REF_ARRAY
4780 : 1561 : && lastref->u.ar.type == AR_FULL)
4781 : : {
4782 : : /* Bare attach and detach clauses don't want any
4783 : : additional nodes. */
4784 : 873 : if ((n->u.map.op == OMP_MAP_ATTACH
4785 : 842 : || n->u.map.op == OMP_MAP_DETACH)
4786 : 887 : && (POINTER_TYPE_P (TREE_TYPE (inner))
4787 : 45 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner))))
4788 : : {
4789 : 45 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
4790 : : {
4791 : 45 : tree ptr = gfc_conv_descriptor_data_get (inner);
4792 : 45 : OMP_CLAUSE_DECL (node) = ptr;
4793 : : }
4794 : : else
4795 : 0 : OMP_CLAUSE_DECL (node) = inner;
4796 : 45 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4797 : 45 : goto finalize_map_clause;
4798 : : }
4799 : :
4800 : 828 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
4801 : : {
4802 : 658 : gomp_map_kind map_kind;
4803 : 658 : tree type = TREE_TYPE (inner);
4804 : 658 : tree ptr = gfc_conv_descriptor_data_get (inner);
4805 : 658 : ptr = build_fold_indirect_ref (ptr);
4806 : 658 : OMP_CLAUSE_DECL (node) = ptr;
4807 : 658 : int rank = GFC_TYPE_ARRAY_RANK (type);
4808 : 658 : OMP_CLAUSE_SIZE (node)
4809 : 658 : = gfc_full_array_size (block, inner, rank);
4810 : 658 : tree elemsz
4811 : 658 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4812 : 658 : map_kind = OMP_CLAUSE_MAP_KIND (node);
4813 : 658 : if (GOMP_MAP_COPY_TO_P (map_kind)
4814 : 116 : || map_kind == GOMP_MAP_ALLOC)
4815 : 569 : map_kind = ((GOMP_MAP_ALWAYS_P (map_kind)
4816 : 1066 : || gfc_expr_attr (n->expr).pointer)
4817 : 569 : ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO);
4818 : 89 : else if (n->u.map.op == OMP_MAP_RELEASE
4819 : 85 : || n->u.map.op == OMP_MAP_DELETE)
4820 : : ;
4821 : 84 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
4822 : 84 : || op == EXEC_OACC_EXIT_DATA)
4823 : : map_kind = GOMP_MAP_RELEASE;
4824 : : else
4825 : 29 : map_kind = GOMP_MAP_ALLOC;
4826 : 658 : if (!openacc
4827 : 518 : && n->expr->ts.type == BT_CHARACTER
4828 : 42 : && n->expr->ts.deferred)
4829 : : {
4830 : 42 : gcc_assert (se.string_length);
4831 : 42 : tree len = fold_convert (size_type_node,
4832 : : se.string_length);
4833 : 42 : elemsz = gfc_get_char_type (n->expr->ts.kind);
4834 : 42 : elemsz = TYPE_SIZE_UNIT (elemsz);
4835 : 42 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
4836 : : len, elemsz);
4837 : 42 : node4 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4838 : 42 : OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
4839 : 42 : OMP_CLAUSE_DECL (node4) = se.string_length;
4840 : 42 : OMP_CLAUSE_SIZE (node4)
4841 : 84 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4842 : : }
4843 : 658 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4844 : 658 : OMP_CLAUSE_SIZE (node)
4845 : 658 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
4846 : : OMP_CLAUSE_SIZE (node), elemsz);
4847 : 658 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4848 : 658 : if (map_kind == GOMP_MAP_RELEASE
4849 : 658 : || map_kind == GOMP_MAP_DELETE)
4850 : : {
4851 : 60 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
4852 : 60 : OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
4853 : : }
4854 : : else
4855 : 598 : OMP_CLAUSE_SET_MAP_KIND (node2,
4856 : : GOMP_MAP_TO_PSET);
4857 : 658 : OMP_CLAUSE_DECL (node2) = inner;
4858 : 658 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
4859 : 658 : if (!openacc)
4860 : : {
4861 : 518 : if (n->expr->ts.type == BT_DERIVED
4862 : 12 : && n->expr->ts.u.derived->attr.alloc_comp)
4863 : : {
4864 : : /* Save array descriptor for use
4865 : : in gfc_omp_deep_mapping{,_p,_cnt}; force
4866 : : evaluate to ensure that it is
4867 : : not gimplified + is a decl. */
4868 : 6 : tree tmp = OMP_CLAUSE_SIZE (node);
4869 : 6 : tree var = gfc_create_var (TREE_TYPE (tmp),
4870 : : NULL);
4871 : 6 : gfc_add_modify_loc (map_loc, block,
4872 : : var, tmp);
4873 : 6 : OMP_CLAUSE_SIZE (node) = var;
4874 : 6 : gfc_allocate_lang_decl (var);
4875 : 6 : GFC_DECL_SAVED_DESCRIPTOR (var) = inner;
4876 : : }
4877 : :
4878 : 518 : gfc_omp_namelist *n2
4879 : : = clauses->lists[OMP_LIST_MAP];
4880 : :
4881 : : /* If we don't have a mapping of a smaller part
4882 : : of the array -- or we can't prove that we do
4883 : : statically -- set this flag. If there is a
4884 : : mapping of a smaller part of the array after
4885 : : all, this will turn into a no-op at
4886 : : runtime. */
4887 : 518 : OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (node) = 1;
4888 : :
4889 : 518 : bool sym_based;
4890 : 518 : n2 = get_symbol_rooted_namelist (sym_rooted_nl,
4891 : : n, n2,
4892 : : &sym_based);
4893 : :
4894 : 518 : bool drop_mapping = false;
4895 : :
4896 : 1661 : for (; n2 != NULL; n2 = n2->next)
4897 : : {
4898 : 1423 : if ((!sym_based && n == n2)
4899 : 1423 : || (sym_based && n == n2->u2.duplicate_of)
4900 : 1167 : || !n2->expr)
4901 : 256 : continue;
4902 : :
4903 : 1167 : if (!gfc_omp_expr_prefix_same (n->expr,
4904 : : n2->expr))
4905 : 887 : continue;
4906 : :
4907 : 280 : gfc_ref *ref1 = n->expr->ref;
4908 : 280 : gfc_ref *ref2 = n2->expr->ref;
4909 : :
4910 : : /* We know ref1 and ref2 overlap. We're
4911 : : interested in whether ref2 describes a
4912 : : smaller part of the array than ref1, which
4913 : : we already know refers to the full
4914 : : array. */
4915 : :
4916 : 620 : while (ref1->next && ref2->next)
4917 : : {
4918 : : ref1 = ref1->next;
4919 : : ref2 = ref2->next;
4920 : : }
4921 : :
4922 : 280 : if (ref2->next
4923 : 280 : || (ref2->type == REF_ARRAY
4924 : 280 : && (ref2->u.ar.type == AR_ELEMENT
4925 : 280 : || (ref2->u.ar.type
4926 : : == AR_SECTION))))
4927 : : {
4928 : : drop_mapping = true;
4929 : : break;
4930 : : }
4931 : : }
4932 : 518 : if (drop_mapping)
4933 : 280 : continue;
4934 : : }
4935 : 378 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4936 : 378 : OMP_CLAUSE_SET_MAP_KIND (node3,
4937 : : GOMP_MAP_ATTACH_DETACH);
4938 : 378 : OMP_CLAUSE_DECL (node3)
4939 : 378 : = gfc_conv_descriptor_data_get (inner);
4940 : : /* Similar to gfc_trans_omp_array_section (details
4941 : : there), we add/keep the cast for OpenMP to prevent
4942 : : that an 'alloc:' gets added for node3 ('desc.data')
4943 : : as that is part of the whole descriptor (node3).
4944 : : TODO: Remove once the ME handles this properly. */
4945 : 378 : if (!openacc)
4946 : 238 : OMP_CLAUSE_DECL (node3)
4947 : 476 : = fold_convert (TREE_TYPE (TREE_OPERAND(ptr, 0)),
4948 : : OMP_CLAUSE_DECL (node3));
4949 : : else
4950 : 140 : STRIP_NOPS (OMP_CLAUSE_DECL (node3));
4951 : 378 : OMP_CLAUSE_SIZE (node3) = size_int (0);
4952 : : }
4953 : : else
4954 : 170 : OMP_CLAUSE_DECL (node) = inner;
4955 : : }
4956 : 688 : else if (lastref->type == REF_ARRAY)
4957 : : {
4958 : : /* An array element or section. */
4959 : 688 : bool element = lastref->u.ar.type == AR_ELEMENT;
4960 : 688 : gomp_map_kind kind = GOMP_MAP_ATTACH_DETACH;
4961 : 688 : gfc_trans_omp_array_section (block, op, n, inner, element,
4962 : 688 : !openacc, kind, node, node2,
4963 : : node3, node4);
4964 : : }
4965 : : else
4966 : 0 : gcc_unreachable ();
4967 : : }
4968 : : else
4969 : 0 : sorry_at (gfc_get_location (&n->where), "unhandled expression");
4970 : :
4971 : 14544 : finalize_map_clause:
4972 : :
4973 : 14544 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
4974 : 14544 : if (node2)
4975 : 4705 : omp_clauses = gfc_trans_add_clause (node2, omp_clauses);
4976 : 14544 : if (node3)
4977 : 5922 : omp_clauses = gfc_trans_add_clause (node3, omp_clauses);
4978 : 14544 : if (node4)
4979 : 3514 : omp_clauses = gfc_trans_add_clause (node4, omp_clauses);
4980 : 14544 : if (node5)
4981 : 4 : omp_clauses = gfc_trans_add_clause (node5, omp_clauses);
4982 : : }
4983 : : break;
4984 : : case OMP_LIST_TO:
4985 : : case OMP_LIST_FROM:
4986 : : case OMP_LIST_CACHE:
4987 : 3633 : for (; n != NULL; n = n->next)
4988 : : {
4989 : 1860 : if (!n->sym->attr.referenced)
4990 : 0 : continue;
4991 : :
4992 : 1860 : switch (list)
4993 : : {
4994 : : case OMP_LIST_TO:
4995 : : clause_code = OMP_CLAUSE_TO;
4996 : : break;
4997 : 1030 : case OMP_LIST_FROM:
4998 : 1030 : clause_code = OMP_CLAUSE_FROM;
4999 : 1030 : break;
5000 : 82 : case OMP_LIST_CACHE:
5001 : 82 : clause_code = OMP_CLAUSE__CACHE_;
5002 : 82 : break;
5003 : 0 : default:
5004 : 0 : gcc_unreachable ();
5005 : : }
5006 : 1860 : tree node = build_omp_clause (gfc_get_location (&n->where),
5007 : : clause_code);
5008 : 1860 : if (n->expr == NULL
5009 : 128 : || (n->expr->ref->type == REF_ARRAY
5010 : 116 : && n->expr->ref->u.ar.type == AR_FULL
5011 : 0 : && n->expr->ref->next == NULL))
5012 : : {
5013 : 1732 : tree decl = gfc_trans_omp_variable (n->sym, false);
5014 : 1732 : if (gfc_omp_privatize_by_reference (decl))
5015 : : {
5016 : 1047 : if (gfc_omp_is_allocatable_or_ptr (decl))
5017 : 240 : decl = build_fold_indirect_ref (decl);
5018 : 1047 : decl = build_fold_indirect_ref (decl);
5019 : : }
5020 : 685 : else if (DECL_P (decl))
5021 : 685 : TREE_ADDRESSABLE (decl) = 1;
5022 : 1732 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
5023 : : {
5024 : 597 : tree type = TREE_TYPE (decl);
5025 : 597 : tree ptr = gfc_conv_descriptor_data_get (decl);
5026 : 597 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
5027 : 597 : ptr = build_fold_indirect_ref (ptr);
5028 : 597 : OMP_CLAUSE_DECL (node) = ptr;
5029 : 597 : OMP_CLAUSE_SIZE (node)
5030 : 597 : = gfc_full_array_size (block, decl,
5031 : 597 : GFC_TYPE_ARRAY_RANK (type));
5032 : 597 : tree elemsz
5033 : 597 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
5034 : 597 : elemsz = fold_convert (gfc_array_index_type, elemsz);
5035 : 1194 : OMP_CLAUSE_SIZE (node)
5036 : 1194 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
5037 : : OMP_CLAUSE_SIZE (node), elemsz);
5038 : : }
5039 : : else
5040 : : {
5041 : 1135 : OMP_CLAUSE_DECL (node) = decl;
5042 : 1135 : if (gfc_omp_is_allocatable_or_ptr (decl))
5043 : 120 : OMP_CLAUSE_SIZE (node)
5044 : 240 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
5045 : : }
5046 : : }
5047 : : else
5048 : : {
5049 : 128 : tree ptr;
5050 : 128 : gfc_init_se (&se, NULL);
5051 : 128 : if (n->expr->rank == 0)
5052 : : {
5053 : 5 : gfc_conv_expr_reference (&se, n->expr);
5054 : 5 : ptr = se.expr;
5055 : 5 : gfc_add_block_to_block (block, &se.pre);
5056 : 5 : OMP_CLAUSE_SIZE (node)
5057 : 10 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
5058 : : }
5059 : : else
5060 : : {
5061 : 123 : gfc_conv_expr_descriptor (&se, n->expr);
5062 : 123 : ptr = gfc_conv_array_data (se.expr);
5063 : 123 : tree type = TREE_TYPE (se.expr);
5064 : 123 : gfc_add_block_to_block (block, &se.pre);
5065 : 123 : OMP_CLAUSE_SIZE (node)
5066 : 123 : = gfc_full_array_size (block, se.expr,
5067 : 123 : GFC_TYPE_ARRAY_RANK (type));
5068 : 123 : tree elemsz
5069 : 123 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
5070 : 123 : elemsz = fold_convert (gfc_array_index_type, elemsz);
5071 : 246 : OMP_CLAUSE_SIZE (node)
5072 : 246 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
5073 : : OMP_CLAUSE_SIZE (node), elemsz);
5074 : : }
5075 : 128 : gfc_add_block_to_block (block, &se.post);
5076 : 128 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
5077 : 128 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
5078 : : }
5079 : 1860 : if (n->u.present_modifier)
5080 : 5 : OMP_CLAUSE_MOTION_PRESENT (node) = 1;
5081 : 1860 : if (list == OMP_LIST_CACHE && n->u.map.readonly)
5082 : 16 : OMP_CLAUSE__CACHE__READONLY (node) = 1;
5083 : 1860 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
5084 : : }
5085 : : break;
5086 : : case OMP_LIST_USES_ALLOCATORS:
5087 : : /* Ignore pre-defined allocators as no special treatment is needed. */
5088 : 30 : for (; n != NULL; n = n->next)
5089 : 28 : if (n->sym->attr.flavor == FL_VARIABLE)
5090 : : break;
5091 : 12 : if (n != NULL)
5092 : 10 : sorry_at (input_location, "%<uses_allocators%> clause with traits "
5093 : : "and memory spaces");
5094 : : break;
5095 : : default:
5096 : : break;
5097 : : }
5098 : : }
5099 : :
5100 : : /* Free hashmap if we built it. */
5101 : 31360 : if (sym_rooted_nl)
5102 : : {
5103 : 252 : typedef hash_map<gfc_symbol *, gfc_omp_namelist *>::iterator hti;
5104 : 870 : for (hti it = sym_rooted_nl->begin (); it != sym_rooted_nl->end (); ++it)
5105 : : {
5106 : 309 : gfc_omp_namelist *&nl = (*it).second;
5107 : 1268 : while (nl)
5108 : : {
5109 : 959 : gfc_omp_namelist *next = nl->next;
5110 : 959 : free (nl);
5111 : 959 : nl = next;
5112 : : }
5113 : : }
5114 : 252 : delete sym_rooted_nl;
5115 : : }
5116 : :
5117 : 31360 : if (clauses->if_expr)
5118 : : {
5119 : 1109 : tree if_var;
5120 : :
5121 : 1109 : gfc_init_se (&se, NULL);
5122 : 1109 : gfc_conv_expr (&se, clauses->if_expr);
5123 : 1109 : gfc_add_block_to_block (block, &se.pre);
5124 : 1109 : if_var = gfc_evaluate_now (se.expr, block);
5125 : 1109 : gfc_add_block_to_block (block, &se.post);
5126 : :
5127 : 1109 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
5128 : 1109 : OMP_CLAUSE_IF_MODIFIER (c) = ERROR_MARK;
5129 : 1109 : OMP_CLAUSE_IF_EXPR (c) = if_var;
5130 : 1109 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5131 : : }
5132 : :
5133 : 344960 : for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
5134 : 313600 : if (clauses->if_exprs[ifc])
5135 : : {
5136 : 123 : tree if_var;
5137 : :
5138 : 123 : gfc_init_se (&se, NULL);
5139 : 123 : gfc_conv_expr (&se, clauses->if_exprs[ifc]);
5140 : 123 : gfc_add_block_to_block (block, &se.pre);
5141 : 123 : if_var = gfc_evaluate_now (se.expr, block);
5142 : 123 : gfc_add_block_to_block (block, &se.post);
5143 : :
5144 : 123 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
5145 : 123 : switch (ifc)
5146 : : {
5147 : 0 : case OMP_IF_CANCEL:
5148 : 0 : OMP_CLAUSE_IF_MODIFIER (c) = VOID_CST;
5149 : 0 : break;
5150 : 40 : case OMP_IF_PARALLEL:
5151 : 40 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL;
5152 : 40 : break;
5153 : 39 : case OMP_IF_SIMD:
5154 : 39 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_SIMD;
5155 : 39 : break;
5156 : 1 : case OMP_IF_TASK:
5157 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASK;
5158 : 1 : break;
5159 : 23 : case OMP_IF_TASKLOOP:
5160 : 23 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASKLOOP;
5161 : 23 : break;
5162 : 16 : case OMP_IF_TARGET:
5163 : 16 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET;
5164 : 16 : break;
5165 : 1 : case OMP_IF_TARGET_DATA:
5166 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_DATA;
5167 : 1 : break;
5168 : 1 : case OMP_IF_TARGET_UPDATE:
5169 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_UPDATE;
5170 : 1 : break;
5171 : 1 : case OMP_IF_TARGET_ENTER_DATA:
5172 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_ENTER_DATA;
5173 : 1 : break;
5174 : 1 : case OMP_IF_TARGET_EXIT_DATA:
5175 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_EXIT_DATA;
5176 : 1 : break;
5177 : : default:
5178 : : gcc_unreachable ();
5179 : : }
5180 : 123 : OMP_CLAUSE_IF_EXPR (c) = if_var;
5181 : 123 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5182 : : }
5183 : :
5184 : 31360 : if (clauses->self_expr)
5185 : : {
5186 : 159 : tree self_var;
5187 : :
5188 : 159 : gfc_init_se (&se, NULL);
5189 : 159 : gfc_conv_expr (&se, clauses->self_expr);
5190 : 159 : gfc_add_block_to_block (block, &se.pre);
5191 : 159 : self_var = gfc_evaluate_now (se.expr, block);
5192 : 159 : gfc_add_block_to_block (block, &se.post);
5193 : :
5194 : 159 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SELF);
5195 : 159 : OMP_CLAUSE_SELF_EXPR (c) = self_var;
5196 : 159 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5197 : : }
5198 : :
5199 : 31360 : if (clauses->final_expr)
5200 : : {
5201 : 64 : tree final_var;
5202 : :
5203 : 64 : gfc_init_se (&se, NULL);
5204 : 64 : gfc_conv_expr (&se, clauses->final_expr);
5205 : 64 : gfc_add_block_to_block (block, &se.pre);
5206 : 64 : final_var = gfc_evaluate_now (se.expr, block);
5207 : 64 : gfc_add_block_to_block (block, &se.post);
5208 : :
5209 : 64 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINAL);
5210 : 64 : OMP_CLAUSE_FINAL_EXPR (c) = final_var;
5211 : 64 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5212 : : }
5213 : :
5214 : 31360 : if (clauses->novariants)
5215 : : {
5216 : 8 : tree novariants_var;
5217 : :
5218 : 8 : gfc_init_se (&se, NULL);
5219 : 8 : gfc_conv_expr (&se, clauses->novariants);
5220 : 8 : gfc_add_block_to_block (block, &se.pre);
5221 : 8 : novariants_var = gfc_evaluate_now (se.expr, block);
5222 : 8 : gfc_add_block_to_block (block, &se.post);
5223 : :
5224 : 8 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOVARIANTS);
5225 : 8 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = novariants_var;
5226 : 8 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5227 : : }
5228 : :
5229 : 31360 : if (clauses->nocontext)
5230 : : {
5231 : 9 : tree nocontext_var;
5232 : :
5233 : 9 : gfc_init_se (&se, NULL);
5234 : 9 : gfc_conv_expr (&se, clauses->nocontext);
5235 : 9 : gfc_add_block_to_block (block, &se.pre);
5236 : 9 : nocontext_var = gfc_evaluate_now (se.expr, block);
5237 : 9 : gfc_add_block_to_block (block, &se.post);
5238 : :
5239 : 9 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOCONTEXT);
5240 : 9 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = nocontext_var;
5241 : 9 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5242 : : }
5243 : :
5244 : 31360 : if (clauses->num_threads)
5245 : : {
5246 : 943 : tree num_threads;
5247 : :
5248 : 943 : gfc_init_se (&se, NULL);
5249 : 943 : gfc_conv_expr (&se, clauses->num_threads);
5250 : 943 : gfc_add_block_to_block (block, &se.pre);
5251 : 943 : num_threads = gfc_evaluate_now (se.expr, block);
5252 : 943 : gfc_add_block_to_block (block, &se.post);
5253 : :
5254 : 943 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_THREADS);
5255 : 943 : OMP_CLAUSE_NUM_THREADS_EXPR (c) = num_threads;
5256 : 943 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5257 : : }
5258 : :
5259 : 31360 : chunk_size = NULL_TREE;
5260 : 31360 : if (clauses->chunk_size)
5261 : : {
5262 : 493 : gfc_init_se (&se, NULL);
5263 : 493 : gfc_conv_expr (&se, clauses->chunk_size);
5264 : 493 : gfc_add_block_to_block (block, &se.pre);
5265 : 493 : chunk_size = gfc_evaluate_now (se.expr, block);
5266 : 493 : gfc_add_block_to_block (block, &se.post);
5267 : : }
5268 : :
5269 : 31360 : if (clauses->sched_kind != OMP_SCHED_NONE)
5270 : : {
5271 : 782 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SCHEDULE);
5272 : 782 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
5273 : 782 : switch (clauses->sched_kind)
5274 : : {
5275 : 407 : case OMP_SCHED_STATIC:
5276 : 407 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
5277 : 407 : break;
5278 : 159 : case OMP_SCHED_DYNAMIC:
5279 : 159 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
5280 : 159 : break;
5281 : 125 : case OMP_SCHED_GUIDED:
5282 : 125 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
5283 : 125 : break;
5284 : 84 : case OMP_SCHED_RUNTIME:
5285 : 84 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
5286 : 84 : break;
5287 : 7 : case OMP_SCHED_AUTO:
5288 : 7 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
5289 : 7 : break;
5290 : 0 : default:
5291 : 0 : gcc_unreachable ();
5292 : : }
5293 : 782 : if (clauses->sched_monotonic)
5294 : 54 : OMP_CLAUSE_SCHEDULE_KIND (c)
5295 : 27 : = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
5296 : : | OMP_CLAUSE_SCHEDULE_MONOTONIC);
5297 : 755 : else if (clauses->sched_nonmonotonic)
5298 : 46 : OMP_CLAUSE_SCHEDULE_KIND (c)
5299 : 23 : = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
5300 : : | OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
5301 : 782 : if (clauses->sched_simd)
5302 : 17 : OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
5303 : 782 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5304 : : }
5305 : :
5306 : 31360 : if (clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
5307 : : {
5308 : 1075 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULT);
5309 : 1075 : switch (clauses->default_sharing)
5310 : : {
5311 : 665 : case OMP_DEFAULT_NONE:
5312 : 665 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_NONE;
5313 : 665 : break;
5314 : 183 : case OMP_DEFAULT_SHARED:
5315 : 183 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_SHARED;
5316 : 183 : break;
5317 : 24 : case OMP_DEFAULT_PRIVATE:
5318 : 24 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRIVATE;
5319 : 24 : break;
5320 : 8 : case OMP_DEFAULT_FIRSTPRIVATE:
5321 : 8 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
5322 : 8 : break;
5323 : 195 : case OMP_DEFAULT_PRESENT:
5324 : 195 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRESENT;
5325 : 195 : break;
5326 : 0 : default:
5327 : 0 : gcc_unreachable ();
5328 : : }
5329 : 1075 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5330 : : }
5331 : :
5332 : 31360 : if (clauses->nowait)
5333 : : {
5334 : 2054 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOWAIT);
5335 : 2054 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5336 : : }
5337 : :
5338 : 31360 : if (clauses->full)
5339 : : {
5340 : 47 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FULL);
5341 : 47 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5342 : : }
5343 : :
5344 : 31360 : if (clauses->partial)
5345 : : {
5346 : 259 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARTIAL);
5347 : 259 : OMP_CLAUSE_PARTIAL_EXPR (c)
5348 : 518 : = (clauses->partial > 0
5349 : 259 : ? build_int_cst (integer_type_node, clauses->partial)
5350 : : : NULL_TREE);
5351 : 259 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5352 : : }
5353 : :
5354 : 31360 : if (clauses->sizes_list)
5355 : : {
5356 : : tree list = NULL_TREE;
5357 : 344 : for (gfc_expr_list *el = clauses->sizes_list; el; el = el->next)
5358 : 224 : list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
5359 : : list);
5360 : :
5361 : 120 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIZES);
5362 : 120 : OMP_CLAUSE_SIZES_LIST (c) = nreverse (list);
5363 : 120 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5364 : : }
5365 : :
5366 : 31360 : if (clauses->ordered)
5367 : : {
5368 : 313 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDERED);
5369 : 313 : OMP_CLAUSE_ORDERED_EXPR (c)
5370 : 313 : = clauses->orderedc ? build_int_cst (integer_type_node,
5371 : 132 : clauses->orderedc) : NULL_TREE;
5372 : 313 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5373 : : }
5374 : :
5375 : 31360 : if (clauses->order_concurrent)
5376 : : {
5377 : 303 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDER);
5378 : 303 : OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = clauses->order_unconstrained;
5379 : 303 : OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = clauses->order_reproducible;
5380 : 303 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5381 : : }
5382 : :
5383 : 31360 : if (clauses->untied)
5384 : : {
5385 : 141 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_UNTIED);
5386 : 141 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5387 : : }
5388 : :
5389 : 31360 : if (clauses->mergeable)
5390 : : {
5391 : 32 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_MERGEABLE);
5392 : 32 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5393 : : }
5394 : :
5395 : 31360 : if (clauses->collapse)
5396 : : {
5397 : 1640 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_COLLAPSE);
5398 : 1640 : OMP_CLAUSE_COLLAPSE_EXPR (c)
5399 : 1640 : = build_int_cst (integer_type_node, clauses->collapse);
5400 : 1640 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5401 : : }
5402 : :
5403 : 31360 : if (clauses->inbranch)
5404 : : {
5405 : 18 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INBRANCH);
5406 : 18 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5407 : : }
5408 : :
5409 : 31360 : if (clauses->notinbranch)
5410 : : {
5411 : 23 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOTINBRANCH);
5412 : 23 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5413 : : }
5414 : :
5415 : 31360 : switch (clauses->cancel)
5416 : : {
5417 : : case OMP_CANCEL_UNKNOWN:
5418 : : break;
5419 : 0 : case OMP_CANCEL_PARALLEL:
5420 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARALLEL);
5421 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5422 : 0 : break;
5423 : 0 : case OMP_CANCEL_SECTIONS:
5424 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SECTIONS);
5425 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5426 : 0 : break;
5427 : 0 : case OMP_CANCEL_DO:
5428 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FOR);
5429 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5430 : 0 : break;
5431 : 0 : case OMP_CANCEL_TASKGROUP:
5432 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TASKGROUP);
5433 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5434 : 0 : break;
5435 : : }
5436 : :
5437 : 31360 : if (clauses->proc_bind != OMP_PROC_BIND_UNKNOWN)
5438 : : {
5439 : 64 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PROC_BIND);
5440 : 64 : switch (clauses->proc_bind)
5441 : : {
5442 : 1 : case OMP_PROC_BIND_PRIMARY:
5443 : 1 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_PRIMARY;
5444 : 1 : break;
5445 : 9 : case OMP_PROC_BIND_MASTER:
5446 : 9 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_MASTER;
5447 : 9 : break;
5448 : 53 : case OMP_PROC_BIND_SPREAD:
5449 : 53 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_SPREAD;
5450 : 53 : break;
5451 : 1 : case OMP_PROC_BIND_CLOSE:
5452 : 1 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_CLOSE;
5453 : 1 : break;
5454 : 0 : default:
5455 : 0 : gcc_unreachable ();
5456 : : }
5457 : 64 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5458 : : }
5459 : :
5460 : 31360 : if (clauses->safelen_expr)
5461 : : {
5462 : 89 : tree safelen_var;
5463 : :
5464 : 89 : gfc_init_se (&se, NULL);
5465 : 89 : gfc_conv_expr (&se, clauses->safelen_expr);
5466 : 89 : gfc_add_block_to_block (block, &se.pre);
5467 : 89 : safelen_var = gfc_evaluate_now (se.expr, block);
5468 : 89 : gfc_add_block_to_block (block, &se.post);
5469 : :
5470 : 89 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SAFELEN);
5471 : 89 : OMP_CLAUSE_SAFELEN_EXPR (c) = safelen_var;
5472 : 89 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5473 : : }
5474 : :
5475 : 31360 : if (clauses->simdlen_expr)
5476 : : {
5477 : 110 : if (declare_simd)
5478 : : {
5479 : 65 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
5480 : 65 : OMP_CLAUSE_SIMDLEN_EXPR (c)
5481 : 65 : = gfc_conv_constant_to_tree (clauses->simdlen_expr);
5482 : 65 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5483 : : }
5484 : : else
5485 : : {
5486 : 45 : tree simdlen_var;
5487 : :
5488 : 45 : gfc_init_se (&se, NULL);
5489 : 45 : gfc_conv_expr (&se, clauses->simdlen_expr);
5490 : 45 : gfc_add_block_to_block (block, &se.pre);
5491 : 45 : simdlen_var = gfc_evaluate_now (se.expr, block);
5492 : 45 : gfc_add_block_to_block (block, &se.post);
5493 : :
5494 : 45 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
5495 : 45 : OMP_CLAUSE_SIMDLEN_EXPR (c) = simdlen_var;
5496 : 45 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5497 : : }
5498 : : }
5499 : :
5500 : 31360 : if (clauses->num_teams_upper)
5501 : : {
5502 : 111 : tree num_teams_lower = NULL_TREE, num_teams_upper;
5503 : :
5504 : 111 : gfc_init_se (&se, NULL);
5505 : 111 : gfc_conv_expr (&se, clauses->num_teams_upper);
5506 : 111 : gfc_add_block_to_block (block, &se.pre);
5507 : 111 : num_teams_upper = gfc_evaluate_now (se.expr, block);
5508 : 111 : gfc_add_block_to_block (block, &se.post);
5509 : :
5510 : 111 : if (clauses->num_teams_lower)
5511 : : {
5512 : 21 : gfc_init_se (&se, NULL);
5513 : 21 : gfc_conv_expr (&se, clauses->num_teams_lower);
5514 : 21 : gfc_add_block_to_block (block, &se.pre);
5515 : 21 : num_teams_lower = gfc_evaluate_now (se.expr, block);
5516 : 21 : gfc_add_block_to_block (block, &se.post);
5517 : : }
5518 : 111 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TEAMS);
5519 : 111 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = num_teams_lower;
5520 : 111 : OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = num_teams_upper;
5521 : 111 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5522 : : }
5523 : :
5524 : 31360 : if (clauses->device)
5525 : : {
5526 : 277 : tree device;
5527 : :
5528 : 277 : gfc_init_se (&se, NULL);
5529 : 277 : gfc_conv_expr (&se, clauses->device);
5530 : 277 : gfc_add_block_to_block (block, &se.pre);
5531 : 277 : device = gfc_evaluate_now (se.expr, block);
5532 : 277 : gfc_add_block_to_block (block, &se.post);
5533 : :
5534 : 277 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEVICE);
5535 : 277 : OMP_CLAUSE_DEVICE_ID (c) = device;
5536 : :
5537 : 277 : if (clauses->ancestor)
5538 : 39 : OMP_CLAUSE_DEVICE_ANCESTOR (c) = 1;
5539 : :
5540 : 277 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5541 : : }
5542 : :
5543 : 31360 : if (clauses->thread_limit)
5544 : : {
5545 : 105 : tree thread_limit;
5546 : :
5547 : 105 : gfc_init_se (&se, NULL);
5548 : 105 : gfc_conv_expr (&se, clauses->thread_limit);
5549 : 105 : gfc_add_block_to_block (block, &se.pre);
5550 : 105 : thread_limit = gfc_evaluate_now (se.expr, block);
5551 : 105 : gfc_add_block_to_block (block, &se.post);
5552 : :
5553 : 105 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREAD_LIMIT);
5554 : 105 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit;
5555 : 105 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5556 : : }
5557 : :
5558 : 31360 : chunk_size = NULL_TREE;
5559 : 31360 : if (clauses->dist_chunk_size)
5560 : : {
5561 : 81 : gfc_init_se (&se, NULL);
5562 : 81 : gfc_conv_expr (&se, clauses->dist_chunk_size);
5563 : 81 : gfc_add_block_to_block (block, &se.pre);
5564 : 81 : chunk_size = gfc_evaluate_now (se.expr, block);
5565 : 81 : gfc_add_block_to_block (block, &se.post);
5566 : : }
5567 : :
5568 : 31360 : if (clauses->dist_sched_kind != OMP_SCHED_NONE)
5569 : : {
5570 : 94 : c = build_omp_clause (gfc_get_location (&where),
5571 : : OMP_CLAUSE_DIST_SCHEDULE);
5572 : 94 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
5573 : 94 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5574 : : }
5575 : :
5576 : 31360 : if (clauses->grainsize)
5577 : : {
5578 : 33 : tree grainsize;
5579 : :
5580 : 33 : gfc_init_se (&se, NULL);
5581 : 33 : gfc_conv_expr (&se, clauses->grainsize);
5582 : 33 : gfc_add_block_to_block (block, &se.pre);
5583 : 33 : grainsize = gfc_evaluate_now (se.expr, block);
5584 : 33 : gfc_add_block_to_block (block, &se.post);
5585 : :
5586 : 33 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GRAINSIZE);
5587 : 33 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = grainsize;
5588 : 33 : if (clauses->grainsize_strict)
5589 : 1 : OMP_CLAUSE_GRAINSIZE_STRICT (c) = 1;
5590 : 33 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5591 : : }
5592 : :
5593 : 31360 : if (clauses->num_tasks)
5594 : : {
5595 : 25 : tree num_tasks;
5596 : :
5597 : 25 : gfc_init_se (&se, NULL);
5598 : 25 : gfc_conv_expr (&se, clauses->num_tasks);
5599 : 25 : gfc_add_block_to_block (block, &se.pre);
5600 : 25 : num_tasks = gfc_evaluate_now (se.expr, block);
5601 : 25 : gfc_add_block_to_block (block, &se.post);
5602 : :
5603 : 25 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TASKS);
5604 : 25 : OMP_CLAUSE_NUM_TASKS_EXPR (c) = num_tasks;
5605 : 25 : if (clauses->num_tasks_strict)
5606 : 1 : OMP_CLAUSE_NUM_TASKS_STRICT (c) = 1;
5607 : 25 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5608 : : }
5609 : :
5610 : 31360 : if (clauses->priority)
5611 : : {
5612 : 34 : tree priority;
5613 : :
5614 : 34 : gfc_init_se (&se, NULL);
5615 : 34 : gfc_conv_expr (&se, clauses->priority);
5616 : 34 : gfc_add_block_to_block (block, &se.pre);
5617 : 34 : priority = gfc_evaluate_now (se.expr, block);
5618 : 34 : gfc_add_block_to_block (block, &se.post);
5619 : :
5620 : 34 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PRIORITY);
5621 : 34 : OMP_CLAUSE_PRIORITY_EXPR (c) = priority;
5622 : 34 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5623 : : }
5624 : :
5625 : 31360 : if (clauses->detach)
5626 : : {
5627 : 116 : tree detach;
5628 : :
5629 : 116 : gfc_init_se (&se, NULL);
5630 : 116 : gfc_conv_expr (&se, clauses->detach);
5631 : 116 : gfc_add_block_to_block (block, &se.pre);
5632 : 116 : detach = se.expr;
5633 : 116 : gfc_add_block_to_block (block, &se.post);
5634 : :
5635 : 116 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DETACH);
5636 : 116 : TREE_ADDRESSABLE (detach) = 1;
5637 : 116 : OMP_CLAUSE_DECL (c) = detach;
5638 : 116 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5639 : : }
5640 : :
5641 : 31360 : if (clauses->filter)
5642 : : {
5643 : 31 : tree filter;
5644 : :
5645 : 31 : gfc_init_se (&se, NULL);
5646 : 31 : gfc_conv_expr (&se, clauses->filter);
5647 : 31 : gfc_add_block_to_block (block, &se.pre);
5648 : 31 : filter = gfc_evaluate_now (se.expr, block);
5649 : 31 : gfc_add_block_to_block (block, &se.post);
5650 : :
5651 : 31 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FILTER);
5652 : 31 : OMP_CLAUSE_FILTER_EXPR (c) = filter;
5653 : 31 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5654 : : }
5655 : :
5656 : 31360 : if (clauses->hint)
5657 : : {
5658 : 8 : tree hint;
5659 : :
5660 : 8 : gfc_init_se (&se, NULL);
5661 : 8 : gfc_conv_expr (&se, clauses->hint);
5662 : 8 : gfc_add_block_to_block (block, &se.pre);
5663 : 8 : hint = gfc_evaluate_now (se.expr, block);
5664 : 8 : gfc_add_block_to_block (block, &se.post);
5665 : :
5666 : 8 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_HINT);
5667 : 8 : OMP_CLAUSE_HINT_EXPR (c) = hint;
5668 : 8 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5669 : : }
5670 : :
5671 : 31360 : if (clauses->simd)
5672 : : {
5673 : 22 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMD);
5674 : 22 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5675 : : }
5676 : 31360 : if (clauses->threads)
5677 : : {
5678 : 11 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREADS);
5679 : 11 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5680 : : }
5681 : 31360 : if (clauses->nogroup)
5682 : : {
5683 : 13 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOGROUP);
5684 : 13 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5685 : : }
5686 : :
5687 : 219520 : for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
5688 : : {
5689 : 188160 : if (clauses->defaultmap[i] == OMP_DEFAULTMAP_UNSET)
5690 : 188007 : continue;
5691 : 153 : enum omp_clause_defaultmap_kind behavior, category;
5692 : 153 : switch ((gfc_omp_defaultmap_category) i)
5693 : : {
5694 : : case OMP_DEFAULTMAP_CAT_UNCATEGORIZED:
5695 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
5696 : : break;
5697 : : case OMP_DEFAULTMAP_CAT_ALL:
5698 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL;
5699 : : break;
5700 : : case OMP_DEFAULTMAP_CAT_SCALAR:
5701 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
5702 : : break;
5703 : : case OMP_DEFAULTMAP_CAT_AGGREGATE:
5704 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
5705 : : break;
5706 : : case OMP_DEFAULTMAP_CAT_ALLOCATABLE:
5707 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE;
5708 : : break;
5709 : : case OMP_DEFAULTMAP_CAT_POINTER:
5710 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
5711 : : break;
5712 : : default: gcc_unreachable ();
5713 : : }
5714 : 153 : switch (clauses->defaultmap[i])
5715 : : {
5716 : : case OMP_DEFAULTMAP_ALLOC:
5717 : : behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
5718 : : break;
5719 : : case OMP_DEFAULTMAP_TO: behavior = OMP_CLAUSE_DEFAULTMAP_TO; break;
5720 : : case OMP_DEFAULTMAP_FROM: behavior = OMP_CLAUSE_DEFAULTMAP_FROM; break;
5721 : : case OMP_DEFAULTMAP_TOFROM:
5722 : : behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
5723 : : break;
5724 : : case OMP_DEFAULTMAP_FIRSTPRIVATE:
5725 : : behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
5726 : : break;
5727 : : case OMP_DEFAULTMAP_PRESENT:
5728 : : behavior = OMP_CLAUSE_DEFAULTMAP_PRESENT;
5729 : : break;
5730 : : case OMP_DEFAULTMAP_NONE: behavior = OMP_CLAUSE_DEFAULTMAP_NONE; break;
5731 : : case OMP_DEFAULTMAP_DEFAULT:
5732 : : behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
5733 : : break;
5734 : 0 : default: gcc_unreachable ();
5735 : : }
5736 : 153 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULTMAP);
5737 : 153 : OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
5738 : 153 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5739 : : }
5740 : :
5741 : 31360 : if (clauses->doacross_source)
5742 : : {
5743 : 131 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DOACROSS);
5744 : 131 : OMP_CLAUSE_DOACROSS_KIND (c) = OMP_CLAUSE_DOACROSS_SOURCE;
5745 : 131 : OMP_CLAUSE_DOACROSS_DEPEND (c) = clauses->depend_source;
5746 : 131 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5747 : : }
5748 : :
5749 : 31360 : if (clauses->async)
5750 : : {
5751 : 541 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ASYNC);
5752 : 541 : if (clauses->async_expr)
5753 : 541 : OMP_CLAUSE_ASYNC_EXPR (c)
5754 : 1082 : = gfc_convert_expr_to_tree (block, clauses->async_expr);
5755 : : else
5756 : 0 : OMP_CLAUSE_ASYNC_EXPR (c) = NULL;
5757 : 541 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5758 : : }
5759 : 31360 : if (clauses->seq)
5760 : : {
5761 : 140 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SEQ);
5762 : 140 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5763 : : }
5764 : 31360 : if (clauses->par_auto)
5765 : : {
5766 : 62 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_AUTO);
5767 : 62 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5768 : : }
5769 : 31360 : if (clauses->if_present)
5770 : : {
5771 : 23 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF_PRESENT);
5772 : 23 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5773 : : }
5774 : 31360 : if (clauses->finalize)
5775 : : {
5776 : 15 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINALIZE);
5777 : 15 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5778 : : }
5779 : 31360 : if (clauses->independent)
5780 : : {
5781 : 239 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INDEPENDENT);
5782 : 239 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5783 : : }
5784 : 31360 : if (clauses->wait_list)
5785 : : {
5786 : : gfc_expr_list *el;
5787 : :
5788 : 317 : for (el = clauses->wait_list; el; el = el->next)
5789 : : {
5790 : 172 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WAIT);
5791 : 172 : OMP_CLAUSE_DECL (c) = gfc_convert_expr_to_tree (block, el->expr);
5792 : 172 : OMP_CLAUSE_CHAIN (c) = omp_clauses;
5793 : 172 : omp_clauses = c;
5794 : : }
5795 : : }
5796 : 31360 : if (clauses->num_gangs_expr)
5797 : : {
5798 : 666 : tree num_gangs_var
5799 : 666 : = gfc_convert_expr_to_tree (block, clauses->num_gangs_expr);
5800 : 666 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_GANGS);
5801 : 666 : OMP_CLAUSE_NUM_GANGS_EXPR (c) = num_gangs_var;
5802 : 666 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5803 : : }
5804 : 31360 : if (clauses->num_workers_expr)
5805 : : {
5806 : 583 : tree num_workers_var
5807 : 583 : = gfc_convert_expr_to_tree (block, clauses->num_workers_expr);
5808 : 583 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_WORKERS);
5809 : 583 : OMP_CLAUSE_NUM_WORKERS_EXPR (c) = num_workers_var;
5810 : 583 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5811 : : }
5812 : 31360 : if (clauses->vector_length_expr)
5813 : : {
5814 : 553 : tree vector_length_var
5815 : 553 : = gfc_convert_expr_to_tree (block, clauses->vector_length_expr);
5816 : 553 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR_LENGTH);
5817 : 553 : OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = vector_length_var;
5818 : 553 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5819 : : }
5820 : 31360 : if (clauses->tile_list)
5821 : : {
5822 : : tree list = NULL_TREE;
5823 : 174 : for (gfc_expr_list *el = clauses->tile_list; el; el = el->next)
5824 : 114 : list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
5825 : : list);
5826 : :
5827 : 60 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TILE);
5828 : 60 : OMP_CLAUSE_TILE_LIST (c) = nreverse (list);
5829 : 60 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5830 : : }
5831 : 31360 : if (clauses->vector)
5832 : : {
5833 : 835 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR);
5834 : 835 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5835 : :
5836 : 835 : if (clauses->vector_expr)
5837 : : {
5838 : 119 : tree vector_var
5839 : 119 : = gfc_convert_expr_to_tree (block, clauses->vector_expr);
5840 : 119 : OMP_CLAUSE_VECTOR_EXPR (c) = vector_var;
5841 : :
5842 : : /* TODO: We're not capturing location information for individual
5843 : : clauses. However, if we have an expression attached to the
5844 : : clause, that one provides better location information. */
5845 : 238 : OMP_CLAUSE_LOCATION (c)
5846 : 119 : = gfc_get_location (&clauses->vector_expr->where);
5847 : : }
5848 : : }
5849 : 31360 : if (clauses->worker)
5850 : : {
5851 : 730 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WORKER);
5852 : 730 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5853 : :
5854 : 730 : if (clauses->worker_expr)
5855 : : {
5856 : 89 : tree worker_var
5857 : 89 : = gfc_convert_expr_to_tree (block, clauses->worker_expr);
5858 : 89 : OMP_CLAUSE_WORKER_EXPR (c) = worker_var;
5859 : :
5860 : : /* TODO: We're not capturing location information for individual
5861 : : clauses. However, if we have an expression attached to the
5862 : : clause, that one provides better location information. */
5863 : 178 : OMP_CLAUSE_LOCATION (c)
5864 : 89 : = gfc_get_location (&clauses->worker_expr->where);
5865 : : }
5866 : : }
5867 : 31360 : if (clauses->gang)
5868 : : {
5869 : 1010 : tree arg;
5870 : 1010 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GANG);
5871 : 1010 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5872 : :
5873 : 1010 : if (clauses->gang_num_expr)
5874 : : {
5875 : 101 : arg = gfc_convert_expr_to_tree (block, clauses->gang_num_expr);
5876 : 101 : OMP_CLAUSE_GANG_EXPR (c) = arg;
5877 : :
5878 : : /* TODO: We're not capturing location information for individual
5879 : : clauses. However, if we have an expression attached to the
5880 : : clause, that one provides better location information. */
5881 : 202 : OMP_CLAUSE_LOCATION (c)
5882 : 101 : = gfc_get_location (&clauses->gang_num_expr->where);
5883 : : }
5884 : :
5885 : 1010 : if (clauses->gang_static)
5886 : : {
5887 : 15 : arg = clauses->gang_static_expr
5888 : 104 : ? gfc_convert_expr_to_tree (block, clauses->gang_static_expr)
5889 : : : integer_minus_one_node;
5890 : 104 : OMP_CLAUSE_GANG_STATIC_EXPR (c) = arg;
5891 : : }
5892 : : }
5893 : 31360 : if (clauses->bind != OMP_BIND_UNSET)
5894 : : {
5895 : 30 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_BIND);
5896 : 30 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5897 : 30 : switch (clauses->bind)
5898 : : {
5899 : 10 : case OMP_BIND_TEAMS:
5900 : 10 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_TEAMS;
5901 : 10 : break;
5902 : 15 : case OMP_BIND_PARALLEL:
5903 : 15 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_PARALLEL;
5904 : 15 : break;
5905 : 5 : case OMP_BIND_THREAD:
5906 : 5 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_THREAD;
5907 : 5 : break;
5908 : 0 : default:
5909 : 0 : gcc_unreachable ();
5910 : : }
5911 : : }
5912 : : /* OpenACC 'nohost' clauses cannot appear here. */
5913 : 31360 : gcc_checking_assert (!clauses->nohost);
5914 : :
5915 : 31360 : return nreverse (omp_clauses);
5916 : : }
5917 : :
5918 : : /* Like gfc_trans_code, but force creation of a BIND_EXPR around it. */
5919 : :
5920 : : static tree
5921 : 20905 : gfc_trans_omp_code (gfc_code *code, bool force_empty)
5922 : : {
5923 : 20905 : tree stmt;
5924 : :
5925 : 20905 : pushlevel ();
5926 : 20905 : stmt = gfc_trans_code (code);
5927 : 20905 : if (TREE_CODE (stmt) != BIND_EXPR)
5928 : : {
5929 : 18650 : if (!IS_EMPTY_STMT (stmt) || force_empty)
5930 : : {
5931 : 18560 : tree block = poplevel (1, 0);
5932 : 18560 : stmt = build3_v (BIND_EXPR, NULL, stmt, block);
5933 : : }
5934 : : else
5935 : 90 : poplevel (0, 0);
5936 : : }
5937 : : else
5938 : 2255 : poplevel (0, 0);
5939 : 20905 : return stmt;
5940 : : }
5941 : :
5942 : : /* Translate OpenACC 'parallel', 'kernels', 'serial', 'data', 'host_data'
5943 : : construct. */
5944 : :
5945 : : static tree
5946 : 4168 : gfc_trans_oacc_construct (gfc_code *code)
5947 : : {
5948 : 4168 : stmtblock_t block;
5949 : 4168 : tree stmt, oacc_clauses;
5950 : 4168 : enum tree_code construct_code;
5951 : :
5952 : 4168 : switch (code->op)
5953 : : {
5954 : : case EXEC_OACC_PARALLEL:
5955 : : construct_code = OACC_PARALLEL;
5956 : : break;
5957 : : case EXEC_OACC_KERNELS:
5958 : : construct_code = OACC_KERNELS;
5959 : : break;
5960 : : case EXEC_OACC_SERIAL:
5961 : : construct_code = OACC_SERIAL;
5962 : : break;
5963 : : case EXEC_OACC_DATA:
5964 : : construct_code = OACC_DATA;
5965 : : break;
5966 : : case EXEC_OACC_HOST_DATA:
5967 : : construct_code = OACC_HOST_DATA;
5968 : : break;
5969 : 0 : default:
5970 : 0 : gcc_unreachable ();
5971 : : }
5972 : :
5973 : 4168 : gfc_start_block (&block);
5974 : 4168 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
5975 : : code->loc, false, true);
5976 : 4168 : pushlevel ();
5977 : 4168 : stmt = gfc_trans_omp_code (code->block->next, true);
5978 : 4168 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
5979 : 4168 : stmt = build2_loc (gfc_get_location (&code->loc), construct_code,
5980 : : void_type_node, stmt, oacc_clauses);
5981 : 4168 : gfc_add_expr_to_block (&block, stmt);
5982 : 4168 : return gfc_finish_block (&block);
5983 : : }
5984 : :
5985 : : /* update, enter_data, exit_data, cache. */
5986 : : static tree
5987 : 2075 : gfc_trans_oacc_executable_directive (gfc_code *code)
5988 : : {
5989 : 2075 : stmtblock_t block;
5990 : 2075 : tree stmt, oacc_clauses;
5991 : 2075 : enum tree_code construct_code;
5992 : :
5993 : 2075 : switch (code->op)
5994 : : {
5995 : : case EXEC_OACC_UPDATE:
5996 : : construct_code = OACC_UPDATE;
5997 : : break;
5998 : 767 : case EXEC_OACC_ENTER_DATA:
5999 : 767 : construct_code = OACC_ENTER_DATA;
6000 : 767 : break;
6001 : 545 : case EXEC_OACC_EXIT_DATA:
6002 : 545 : construct_code = OACC_EXIT_DATA;
6003 : 545 : break;
6004 : 74 : case EXEC_OACC_CACHE:
6005 : 74 : construct_code = OACC_CACHE;
6006 : 74 : break;
6007 : 0 : default:
6008 : 0 : gcc_unreachable ();
6009 : : }
6010 : :
6011 : 2075 : gfc_start_block (&block);
6012 : 2075 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
6013 : : code->loc, false, true, code->op);
6014 : 2075 : stmt = build1_loc (input_location, construct_code, void_type_node,
6015 : : oacc_clauses);
6016 : 2075 : gfc_add_expr_to_block (&block, stmt);
6017 : 2075 : return gfc_finish_block (&block);
6018 : : }
6019 : :
6020 : : static tree
6021 : 167 : gfc_trans_oacc_wait_directive (gfc_code *code)
6022 : : {
6023 : 167 : stmtblock_t block;
6024 : 167 : tree stmt, t;
6025 : 167 : vec<tree, va_gc> *args;
6026 : 167 : int nparms = 0;
6027 : 167 : gfc_expr_list *el;
6028 : 167 : gfc_omp_clauses *clauses = code->ext.omp_clauses;
6029 : 167 : location_t loc = input_location;
6030 : :
6031 : 291 : for (el = clauses->wait_list; el; el = el->next)
6032 : 124 : nparms++;
6033 : :
6034 : 167 : vec_alloc (args, nparms + 2);
6035 : 167 : stmt = builtin_decl_explicit (BUILT_IN_GOACC_WAIT);
6036 : :
6037 : 167 : gfc_start_block (&block);
6038 : :
6039 : 167 : if (clauses->async_expr)
6040 : 0 : t = gfc_convert_expr_to_tree (&block, clauses->async_expr);
6041 : : else
6042 : 167 : t = build_int_cst (integer_type_node, -2);
6043 : :
6044 : 167 : args->quick_push (t);
6045 : 167 : args->quick_push (build_int_cst (integer_type_node, nparms));
6046 : :
6047 : 291 : for (el = clauses->wait_list; el; el = el->next)
6048 : 124 : args->quick_push (gfc_convert_expr_to_tree (&block, el->expr));
6049 : :
6050 : 167 : stmt = build_call_expr_loc_vec (loc, stmt, args);
6051 : 167 : gfc_add_expr_to_block (&block, stmt);
6052 : :
6053 : 167 : vec_free (args);
6054 : :
6055 : 167 : return gfc_finish_block (&block);
6056 : : }
6057 : :
6058 : : static tree gfc_trans_omp_sections (gfc_code *, gfc_omp_clauses *);
6059 : : static tree gfc_trans_omp_workshare (gfc_code *, gfc_omp_clauses *);
6060 : :
6061 : : static tree
6062 : 34 : gfc_trans_omp_allocators (gfc_code *code)
6063 : : {
6064 : 34 : static bool warned = false;
6065 : 34 : gfc_omp_namelist *omp_allocate
6066 : 34 : = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
6067 : 34 : if (!flag_openmp_allocators && !warned)
6068 : : {
6069 : 2 : omp_allocate = NULL;
6070 : 2 : gfc_error ("%<!$OMP %s%> at %L requires %<-fopenmp-allocators%>",
6071 : 2 : code->op == EXEC_OMP_ALLOCATE ? "ALLOCATE" : "ALLOCATORS",
6072 : : &code->loc);
6073 : 2 : warning (0, "All files that might deallocate such a variable must be "
6074 : : "compiled with %<-fopenmp-allocators%>");
6075 : 2 : inform (UNKNOWN_LOCATION,
6076 : : "This includes explicit DEALLOCATE, reallocation on intrinsic "
6077 : : "assignment, INTENT(OUT) for allocatable dummy arguments, and "
6078 : : "reallocation of allocatable components allocated with an "
6079 : : "OpenMP allocator");
6080 : 2 : warned = true;
6081 : : }
6082 : 34 : return gfc_trans_allocate (code->block->next, omp_allocate);
6083 : : }
6084 : :
6085 : : static tree
6086 : 10 : gfc_trans_omp_assume (gfc_code *code)
6087 : : {
6088 : 10 : stmtblock_t block;
6089 : 10 : gfc_init_block (&block);
6090 : 10 : gfc_omp_assumptions *assume = code->ext.omp_clauses->assume;
6091 : 10 : if (assume)
6092 : 19 : for (gfc_expr_list *el = assume->holds; el; el = el->next)
6093 : : {
6094 : 9 : location_t loc = gfc_get_location (&el->expr->where);
6095 : 9 : gfc_se se;
6096 : 9 : gfc_init_se (&se, NULL);
6097 : 9 : gfc_conv_expr (&se, el->expr);
6098 : 9 : tree t;
6099 : 9 : if (se.pre.head == NULL_TREE && se.post.head == NULL_TREE)
6100 : 8 : t = se.expr;
6101 : : else
6102 : : {
6103 : 1 : tree var = create_tmp_var_raw (boolean_type_node);
6104 : 1 : DECL_CONTEXT (var) = current_function_decl;
6105 : 1 : stmtblock_t block2;
6106 : 1 : gfc_init_block (&block2);
6107 : 1 : gfc_add_block_to_block (&block2, &se.pre);
6108 : 1 : gfc_add_modify_loc (loc, &block2, var,
6109 : : fold_convert_loc (loc, boolean_type_node,
6110 : : se.expr));
6111 : 1 : gfc_add_block_to_block (&block2, &se.post);
6112 : 1 : t = gfc_finish_block (&block2);
6113 : 1 : t = build4 (TARGET_EXPR, boolean_type_node, var, t, NULL, NULL);
6114 : : }
6115 : 9 : t = build_call_expr_internal_loc (loc, IFN_ASSUME,
6116 : : void_type_node, 1, t);
6117 : 9 : gfc_add_expr_to_block (&block, t);
6118 : : }
6119 : 10 : gfc_add_expr_to_block (&block, gfc_trans_omp_code (code->block->next, true));
6120 : 10 : return gfc_finish_block (&block);
6121 : : }
6122 : :
6123 : : static tree
6124 : 2596 : gfc_trans_omp_atomic (gfc_code *code)
6125 : : {
6126 : 2596 : gfc_code *atomic_code = code->block;
6127 : 2596 : gfc_se lse;
6128 : 2596 : gfc_se rse;
6129 : 2596 : gfc_se vse;
6130 : 2596 : gfc_expr *expr1, *expr2, *e, *capture_expr1 = NULL, *capture_expr2 = NULL;
6131 : 2596 : gfc_symbol *var;
6132 : 2596 : stmtblock_t block;
6133 : 2596 : tree lhsaddr, type, rhs, x, compare = NULL_TREE, comp_tgt = NULL_TREE;
6134 : 2596 : enum tree_code op = ERROR_MARK;
6135 : 2596 : enum tree_code aop = OMP_ATOMIC;
6136 : 2596 : bool var_on_left = false, else_branch = false;
6137 : 2596 : enum omp_memory_order mo, fail_mo;
6138 : 2596 : switch (atomic_code->ext.omp_clauses->memorder)
6139 : : {
6140 : : case OMP_MEMORDER_UNSET: mo = OMP_MEMORY_ORDER_UNSPECIFIED; break;
6141 : : case OMP_MEMORDER_ACQ_REL: mo = OMP_MEMORY_ORDER_ACQ_REL; break;
6142 : : case OMP_MEMORDER_ACQUIRE: mo = OMP_MEMORY_ORDER_ACQUIRE; break;
6143 : : case OMP_MEMORDER_RELAXED: mo = OMP_MEMORY_ORDER_RELAXED; break;
6144 : : case OMP_MEMORDER_RELEASE: mo = OMP_MEMORY_ORDER_RELEASE; break;
6145 : : case OMP_MEMORDER_SEQ_CST: mo = OMP_MEMORY_ORDER_SEQ_CST; break;
6146 : 0 : default: gcc_unreachable ();
6147 : : }
6148 : 2596 : switch (atomic_code->ext.omp_clauses->fail)
6149 : : {
6150 : : case OMP_MEMORDER_UNSET: fail_mo = OMP_FAIL_MEMORY_ORDER_UNSPECIFIED; break;
6151 : 14 : case OMP_MEMORDER_ACQUIRE: fail_mo = OMP_FAIL_MEMORY_ORDER_ACQUIRE; break;
6152 : 26 : case OMP_MEMORDER_RELAXED: fail_mo = OMP_FAIL_MEMORY_ORDER_RELAXED; break;
6153 : 2 : case OMP_MEMORDER_SEQ_CST: fail_mo = OMP_FAIL_MEMORY_ORDER_SEQ_CST; break;
6154 : 0 : default: gcc_unreachable ();
6155 : : }
6156 : 2596 : mo = (omp_memory_order) (mo | fail_mo);
6157 : :
6158 : 2596 : code = code->block->next;
6159 : 2596 : if (atomic_code->ext.omp_clauses->compare)
6160 : : {
6161 : 144 : gfc_expr *comp_expr;
6162 : 144 : if (code->op == EXEC_IF)
6163 : : {
6164 : 125 : comp_expr = code->block->expr1;
6165 : 125 : gcc_assert (code->block->next->op == EXEC_ASSIGN);
6166 : 125 : expr1 = code->block->next->expr1;
6167 : 125 : expr2 = code->block->next->expr2;
6168 : 125 : if (code->block->block)
6169 : : {
6170 : 64 : gcc_assert (atomic_code->ext.omp_clauses->capture
6171 : : && code->block->block->next->op == EXEC_ASSIGN);
6172 : 64 : else_branch = true;
6173 : 64 : aop = OMP_ATOMIC_CAPTURE_OLD;
6174 : 64 : capture_expr1 = code->block->block->next->expr1;
6175 : 64 : capture_expr2 = code->block->block->next->expr2;
6176 : : }
6177 : 61 : else if (atomic_code->ext.omp_clauses->capture)
6178 : : {
6179 : 19 : gcc_assert (code->next->op == EXEC_ASSIGN);
6180 : 19 : aop = OMP_ATOMIC_CAPTURE_NEW;
6181 : 19 : capture_expr1 = code->next->expr1;
6182 : 19 : capture_expr2 = code->next->expr2;
6183 : : }
6184 : : }
6185 : : else
6186 : : {
6187 : 19 : gcc_assert (atomic_code->ext.omp_clauses->capture
6188 : : && code->op == EXEC_ASSIGN
6189 : : && code->next->op == EXEC_IF);
6190 : 19 : aop = OMP_ATOMIC_CAPTURE_OLD;
6191 : 19 : capture_expr1 = code->expr1;
6192 : 19 : capture_expr2 = code->expr2;
6193 : 19 : expr1 = code->next->block->next->expr1;
6194 : 19 : expr2 = code->next->block->next->expr2;
6195 : 19 : comp_expr = code->next->block->expr1;
6196 : : }
6197 : 144 : gfc_init_se (&lse, NULL);
6198 : 144 : gfc_conv_expr (&lse, comp_expr->value.op.op2);
6199 : 144 : gfc_add_block_to_block (&block, &lse.pre);
6200 : 144 : compare = lse.expr;
6201 : 144 : var = expr1->symtree->n.sym;
6202 : : }
6203 : : else
6204 : : {
6205 : 2452 : gcc_assert (code->op == EXEC_ASSIGN);
6206 : 2452 : expr1 = code->expr1;
6207 : 2452 : expr2 = code->expr2;
6208 : 2452 : if (atomic_code->ext.omp_clauses->capture
6209 : 463 : && (expr2->expr_type == EXPR_VARIABLE
6210 : 245 : || (expr2->expr_type == EXPR_FUNCTION
6211 : 113 : && expr2->value.function.isym
6212 : 113 : && expr2->value.function.isym->id == GFC_ISYM_CONVERSION
6213 : 41 : && (expr2->value.function.actual->expr->expr_type
6214 : : == EXPR_VARIABLE))))
6215 : : {
6216 : 235 : capture_expr1 = expr1;
6217 : 235 : capture_expr2 = expr2;
6218 : 235 : expr1 = code->next->expr1;
6219 : 235 : expr2 = code->next->expr2;
6220 : 235 : aop = OMP_ATOMIC_CAPTURE_OLD;
6221 : : }
6222 : 2217 : else if (atomic_code->ext.omp_clauses->capture)
6223 : : {
6224 : 228 : aop = OMP_ATOMIC_CAPTURE_NEW;
6225 : 228 : capture_expr1 = code->next->expr1;
6226 : 228 : capture_expr2 = code->next->expr2;
6227 : : }
6228 : 2452 : var = expr1->symtree->n.sym;
6229 : : }
6230 : :
6231 : 2596 : gfc_init_se (&lse, NULL);
6232 : 2596 : gfc_init_se (&rse, NULL);
6233 : 2596 : gfc_init_se (&vse, NULL);
6234 : 2596 : gfc_start_block (&block);
6235 : :
6236 : 2596 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6237 : : != GFC_OMP_ATOMIC_WRITE)
6238 : 2190 : && expr2->expr_type == EXPR_FUNCTION
6239 : 472 : && expr2->value.function.isym
6240 : 472 : && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
6241 : 139 : expr2 = expr2->value.function.actual->expr;
6242 : :
6243 : 2596 : if ((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6244 : : == GFC_OMP_ATOMIC_READ)
6245 : : {
6246 : 494 : gfc_conv_expr (&vse, expr1);
6247 : 494 : gfc_add_block_to_block (&block, &vse.pre);
6248 : :
6249 : 494 : gfc_conv_expr (&lse, expr2);
6250 : 494 : gfc_add_block_to_block (&block, &lse.pre);
6251 : 494 : type = TREE_TYPE (lse.expr);
6252 : 494 : lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
6253 : :
6254 : 494 : x = build1 (OMP_ATOMIC_READ, type, lhsaddr);
6255 : 494 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6256 : 494 : x = convert (TREE_TYPE (vse.expr), x);
6257 : 494 : gfc_add_modify (&block, vse.expr, x);
6258 : :
6259 : 494 : gfc_add_block_to_block (&block, &lse.pre);
6260 : 494 : gfc_add_block_to_block (&block, &rse.pre);
6261 : :
6262 : 494 : return gfc_finish_block (&block);
6263 : : }
6264 : :
6265 : 2102 : if (capture_expr2
6266 : 565 : && capture_expr2->expr_type == EXPR_FUNCTION
6267 : 21 : && capture_expr2->value.function.isym
6268 : 21 : && capture_expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
6269 : 21 : capture_expr2 = capture_expr2->value.function.actual->expr;
6270 : 565 : gcc_assert (!capture_expr2 || capture_expr2->expr_type == EXPR_VARIABLE);
6271 : :
6272 : 2102 : if (aop == OMP_ATOMIC_CAPTURE_OLD)
6273 : : {
6274 : 318 : gfc_conv_expr (&vse, capture_expr1);
6275 : 318 : gfc_add_block_to_block (&block, &vse.pre);
6276 : 318 : gfc_conv_expr (&lse, capture_expr2);
6277 : 318 : gfc_add_block_to_block (&block, &lse.pre);
6278 : 318 : gfc_init_se (&lse, NULL);
6279 : : }
6280 : :
6281 : 2102 : gfc_conv_expr (&lse, expr1);
6282 : 2102 : gfc_add_block_to_block (&block, &lse.pre);
6283 : 2102 : type = TREE_TYPE (lse.expr);
6284 : 2102 : lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
6285 : :
6286 : 2102 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6287 : : == GFC_OMP_ATOMIC_WRITE)
6288 : 1696 : || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
6289 : 1674 : || compare)
6290 : : {
6291 : 572 : gfc_conv_expr (&rse, expr2);
6292 : 572 : gfc_add_block_to_block (&block, &rse.pre);
6293 : : }
6294 : 1530 : else if (expr2->expr_type == EXPR_OP)
6295 : : {
6296 : 1184 : gfc_expr *e;
6297 : 1184 : switch (expr2->value.op.op)
6298 : : {
6299 : : case INTRINSIC_PLUS:
6300 : : op = PLUS_EXPR;
6301 : : break;
6302 : 91 : case INTRINSIC_TIMES:
6303 : 91 : op = MULT_EXPR;
6304 : 91 : break;
6305 : 113 : case INTRINSIC_MINUS:
6306 : 113 : op = MINUS_EXPR;
6307 : 113 : break;
6308 : 91 : case INTRINSIC_DIVIDE:
6309 : 91 : if (expr2->ts.type == BT_INTEGER)
6310 : : op = TRUNC_DIV_EXPR;
6311 : : else
6312 : 74 : op = RDIV_EXPR;
6313 : : break;
6314 : 43 : case INTRINSIC_AND:
6315 : 43 : op = TRUTH_ANDIF_EXPR;
6316 : 43 : break;
6317 : 49 : case INTRINSIC_OR:
6318 : 49 : op = TRUTH_ORIF_EXPR;
6319 : 49 : break;
6320 : 43 : case INTRINSIC_EQV:
6321 : 43 : op = EQ_EXPR;
6322 : 43 : break;
6323 : 43 : case INTRINSIC_NEQV:
6324 : 43 : op = NE_EXPR;
6325 : 43 : break;
6326 : 0 : default:
6327 : 0 : gcc_unreachable ();
6328 : : }
6329 : 1184 : e = expr2->value.op.op1;
6330 : 1184 : if (e->expr_type == EXPR_FUNCTION
6331 : 48 : && e->value.function.isym
6332 : 48 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6333 : 48 : e = e->value.function.actual->expr;
6334 : 1184 : if (e->expr_type == EXPR_VARIABLE
6335 : 925 : && e->symtree != NULL
6336 : 925 : && e->symtree->n.sym == var)
6337 : : {
6338 : 910 : expr2 = expr2->value.op.op2;
6339 : 910 : var_on_left = true;
6340 : : }
6341 : : else
6342 : : {
6343 : 274 : e = expr2->value.op.op2;
6344 : 274 : if (e->expr_type == EXPR_FUNCTION
6345 : 48 : && e->value.function.isym
6346 : 48 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6347 : 48 : e = e->value.function.actual->expr;
6348 : 274 : gcc_assert (e->expr_type == EXPR_VARIABLE
6349 : : && e->symtree != NULL
6350 : : && e->symtree->n.sym == var);
6351 : : expr2 = expr2->value.op.op1;
6352 : : var_on_left = false;
6353 : : }
6354 : 1184 : gfc_conv_expr (&rse, expr2);
6355 : 1184 : gfc_add_block_to_block (&block, &rse.pre);
6356 : : }
6357 : : else
6358 : : {
6359 : 346 : gcc_assert (expr2->expr_type == EXPR_FUNCTION);
6360 : 346 : switch (expr2->value.function.isym->id)
6361 : : {
6362 : : case GFC_ISYM_MIN:
6363 : : op = MIN_EXPR;
6364 : : break;
6365 : 114 : case GFC_ISYM_MAX:
6366 : 114 : op = MAX_EXPR;
6367 : 114 : break;
6368 : 47 : case GFC_ISYM_IAND:
6369 : 47 : op = BIT_AND_EXPR;
6370 : 47 : break;
6371 : 49 : case GFC_ISYM_IOR:
6372 : 49 : op = BIT_IOR_EXPR;
6373 : 49 : break;
6374 : 45 : case GFC_ISYM_IEOR:
6375 : 45 : op = BIT_XOR_EXPR;
6376 : 45 : break;
6377 : 0 : default:
6378 : 0 : gcc_unreachable ();
6379 : : }
6380 : 346 : e = expr2->value.function.actual->expr;
6381 : 346 : if (e->expr_type == EXPR_FUNCTION
6382 : 13 : && e->value.function.isym
6383 : 13 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6384 : 13 : e = e->value.function.actual->expr;
6385 : 346 : gcc_assert (e->expr_type == EXPR_VARIABLE
6386 : : && e->symtree != NULL
6387 : : && e->symtree->n.sym == var);
6388 : :
6389 : 346 : gfc_conv_expr (&rse, expr2->value.function.actual->next->expr);
6390 : 346 : gfc_add_block_to_block (&block, &rse.pre);
6391 : 346 : if (expr2->value.function.actual->next->next != NULL)
6392 : : {
6393 : 26 : tree accum = gfc_create_var (TREE_TYPE (rse.expr), NULL);
6394 : 26 : gfc_actual_arglist *arg;
6395 : :
6396 : 26 : gfc_add_modify (&block, accum, rse.expr);
6397 : 64 : for (arg = expr2->value.function.actual->next->next; arg;
6398 : 38 : arg = arg->next)
6399 : : {
6400 : 38 : gfc_init_block (&rse.pre);
6401 : 38 : gfc_conv_expr (&rse, arg->expr);
6402 : 38 : gfc_add_block_to_block (&block, &rse.pre);
6403 : 38 : x = fold_build2_loc (input_location, op, TREE_TYPE (accum),
6404 : : accum, rse.expr);
6405 : 38 : gfc_add_modify (&block, accum, x);
6406 : : }
6407 : :
6408 : 26 : rse.expr = accum;
6409 : : }
6410 : :
6411 : 346 : expr2 = expr2->value.function.actual->next->expr;
6412 : : }
6413 : :
6414 : 2102 : lhsaddr = save_expr (lhsaddr);
6415 : 2102 : if (TREE_CODE (lhsaddr) != SAVE_EXPR
6416 : 2102 : && (TREE_CODE (lhsaddr) != ADDR_EXPR
6417 : 1642 : || !VAR_P (TREE_OPERAND (lhsaddr, 0))))
6418 : : {
6419 : : /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
6420 : : it even after unsharing function body. */
6421 : 44 : tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
6422 : 44 : DECL_CONTEXT (var) = current_function_decl;
6423 : 44 : lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr,
6424 : : NULL_TREE, NULL_TREE);
6425 : : }
6426 : :
6427 : 2102 : if (compare)
6428 : : {
6429 : 144 : tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
6430 : 144 : DECL_CONTEXT (var) = current_function_decl;
6431 : 144 : lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr, NULL,
6432 : : NULL);
6433 : 144 : lse.expr = build_fold_indirect_ref_loc (input_location, lhsaddr);
6434 : 144 : compare = convert (TREE_TYPE (lse.expr), compare);
6435 : 144 : compare = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
6436 : : lse.expr, compare);
6437 : : }
6438 : :
6439 : 2102 : if (expr2->expr_type == EXPR_VARIABLE || compare)
6440 : 460 : rhs = rse.expr;
6441 : : else
6442 : 1642 : rhs = gfc_evaluate_now (rse.expr, &block);
6443 : :
6444 : 2102 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6445 : : == GFC_OMP_ATOMIC_WRITE)
6446 : 1696 : || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
6447 : 1674 : || compare)
6448 : : x = rhs;
6449 : : else
6450 : : {
6451 : 1530 : x = convert (TREE_TYPE (rhs),
6452 : : build_fold_indirect_ref_loc (input_location, lhsaddr));
6453 : 1530 : if (var_on_left)
6454 : 910 : x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), x, rhs);
6455 : : else
6456 : 620 : x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), rhs, x);
6457 : : }
6458 : :
6459 : 2102 : if (TREE_CODE (TREE_TYPE (rhs)) == COMPLEX_TYPE
6460 : 2102 : && TREE_CODE (type) != COMPLEX_TYPE)
6461 : 0 : x = fold_build1_loc (input_location, REALPART_EXPR,
6462 : 0 : TREE_TYPE (TREE_TYPE (rhs)), x);
6463 : :
6464 : 2102 : gfc_add_block_to_block (&block, &lse.pre);
6465 : 2102 : gfc_add_block_to_block (&block, &rse.pre);
6466 : :
6467 : 2102 : if (aop == OMP_ATOMIC_CAPTURE_NEW)
6468 : : {
6469 : 247 : gfc_conv_expr (&vse, capture_expr1);
6470 : 247 : gfc_add_block_to_block (&block, &vse.pre);
6471 : 247 : gfc_add_block_to_block (&block, &lse.pre);
6472 : : }
6473 : :
6474 : 2102 : if (compare && else_branch)
6475 : : {
6476 : 64 : tree var2 = create_tmp_var_raw (boolean_type_node);
6477 : 64 : DECL_CONTEXT (var2) = current_function_decl;
6478 : 64 : comp_tgt = build4 (TARGET_EXPR, boolean_type_node, var2,
6479 : : boolean_false_node, NULL, NULL);
6480 : 64 : compare = fold_build2_loc (input_location, MODIFY_EXPR, TREE_TYPE (var2),
6481 : : var2, compare);
6482 : 64 : TREE_OPERAND (compare, 0) = comp_tgt;
6483 : 64 : compare = omit_one_operand_loc (input_location, boolean_type_node,
6484 : : compare, comp_tgt);
6485 : : }
6486 : :
6487 : 2102 : if (compare)
6488 : 144 : x = build3_loc (input_location, COND_EXPR, type, compare,
6489 : : convert (type, x), lse.expr);
6490 : :
6491 : 2102 : if (aop == OMP_ATOMIC)
6492 : : {
6493 : 1537 : x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x));
6494 : 1537 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6495 : 1537 : OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
6496 : 1537 : gfc_add_expr_to_block (&block, x);
6497 : : }
6498 : : else
6499 : : {
6500 : 565 : x = build2 (aop, type, lhsaddr, convert (type, x));
6501 : 565 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6502 : 565 : OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
6503 : 565 : if (compare && else_branch)
6504 : : {
6505 : 64 : tree vtmp = create_tmp_var_raw (TREE_TYPE (x));
6506 : 64 : DECL_CONTEXT (vtmp) = current_function_decl;
6507 : 64 : x = fold_build2_loc (input_location, MODIFY_EXPR,
6508 : 64 : TREE_TYPE (vtmp), vtmp, x);
6509 : 64 : vtmp = build4 (TARGET_EXPR, TREE_TYPE (vtmp), vtmp,
6510 : 64 : build_zero_cst (TREE_TYPE (vtmp)), NULL, NULL);
6511 : 64 : TREE_OPERAND (x, 0) = vtmp;
6512 : 64 : tree x2 = convert (TREE_TYPE (vse.expr), vtmp);
6513 : 64 : x2 = fold_build2_loc (input_location, MODIFY_EXPR,
6514 : 64 : TREE_TYPE (vse.expr), vse.expr, x2);
6515 : 64 : x2 = build3_loc (input_location, COND_EXPR, void_type_node, comp_tgt,
6516 : : void_node, x2);
6517 : 64 : x = omit_one_operand_loc (input_location, TREE_TYPE (x2), x2, x);
6518 : 64 : gfc_add_expr_to_block (&block, x);
6519 : : }
6520 : : else
6521 : : {
6522 : 501 : x = convert (TREE_TYPE (vse.expr), x);
6523 : 501 : gfc_add_modify (&block, vse.expr, x);
6524 : : }
6525 : : }
6526 : :
6527 : 2102 : return gfc_finish_block (&block);
6528 : : }
6529 : :
6530 : : static tree
6531 : 603 : gfc_trans_omp_barrier (void)
6532 : : {
6533 : 603 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
6534 : 603 : return build_call_expr_loc (input_location, decl, 0);
6535 : : }
6536 : :
6537 : : static tree
6538 : 310 : gfc_trans_omp_cancel (gfc_code *code)
6539 : : {
6540 : 310 : int mask = 0;
6541 : 310 : tree ifc = boolean_true_node;
6542 : 310 : stmtblock_t block;
6543 : 310 : switch (code->ext.omp_clauses->cancel)
6544 : : {
6545 : : case OMP_CANCEL_PARALLEL: mask = 1; break;
6546 : : case OMP_CANCEL_DO: mask = 2; break;
6547 : : case OMP_CANCEL_SECTIONS: mask = 4; break;
6548 : : case OMP_CANCEL_TASKGROUP: mask = 8; break;
6549 : 0 : default: gcc_unreachable ();
6550 : : }
6551 : 310 : gfc_start_block (&block);
6552 : 310 : if (code->ext.omp_clauses->if_expr
6553 : 219 : || code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL])
6554 : : {
6555 : 99 : gfc_se se;
6556 : 99 : tree if_var;
6557 : :
6558 : 99 : gcc_assert ((code->ext.omp_clauses->if_expr == NULL)
6559 : : ^ (code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL] == NULL));
6560 : 99 : gfc_init_se (&se, NULL);
6561 : 99 : gfc_conv_expr (&se, code->ext.omp_clauses->if_expr != NULL
6562 : : ? code->ext.omp_clauses->if_expr
6563 : : : code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL]);
6564 : 99 : gfc_add_block_to_block (&block, &se.pre);
6565 : 99 : if_var = gfc_evaluate_now (se.expr, &block);
6566 : 99 : gfc_add_block_to_block (&block, &se.post);
6567 : 99 : tree type = TREE_TYPE (if_var);
6568 : 99 : ifc = fold_build2_loc (input_location, NE_EXPR,
6569 : : boolean_type_node, if_var,
6570 : : build_zero_cst (type));
6571 : : }
6572 : 310 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
6573 : 310 : tree c_bool_type = TREE_TYPE (TREE_TYPE (decl));
6574 : 310 : ifc = fold_convert (c_bool_type, ifc);
6575 : 310 : gfc_add_expr_to_block (&block,
6576 : : build_call_expr_loc (input_location, decl, 2,
6577 : : build_int_cst (integer_type_node,
6578 : 310 : mask), ifc));
6579 : 310 : return gfc_finish_block (&block);
6580 : : }
6581 : :
6582 : : static tree
6583 : 170 : gfc_trans_omp_cancellation_point (gfc_code *code)
6584 : : {
6585 : 170 : int mask = 0;
6586 : 170 : switch (code->ext.omp_clauses->cancel)
6587 : : {
6588 : : case OMP_CANCEL_PARALLEL: mask = 1; break;
6589 : : case OMP_CANCEL_DO: mask = 2; break;
6590 : : case OMP_CANCEL_SECTIONS: mask = 4; break;
6591 : : case OMP_CANCEL_TASKGROUP: mask = 8; break;
6592 : 0 : default: gcc_unreachable ();
6593 : : }
6594 : 170 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
6595 : 170 : return build_call_expr_loc (input_location, decl, 1,
6596 : 340 : build_int_cst (integer_type_node, mask));
6597 : : }
6598 : :
6599 : : static tree
6600 : 143 : gfc_trans_omp_critical (gfc_code *code)
6601 : : {
6602 : 143 : stmtblock_t block;
6603 : 143 : tree stmt, name = NULL_TREE;
6604 : 143 : if (code->ext.omp_clauses->critical_name != NULL)
6605 : 36 : name = get_identifier (code->ext.omp_clauses->critical_name);
6606 : 143 : gfc_start_block (&block);
6607 : 143 : stmt = make_node (OMP_CRITICAL);
6608 : 143 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
6609 : 143 : TREE_TYPE (stmt) = void_type_node;
6610 : 143 : OMP_CRITICAL_BODY (stmt) = gfc_trans_code (code->block->next);
6611 : 143 : OMP_CRITICAL_NAME (stmt) = name;
6612 : 143 : OMP_CRITICAL_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
6613 : : code->ext.omp_clauses,
6614 : : code->loc);
6615 : 143 : gfc_add_expr_to_block (&block, stmt);
6616 : 143 : return gfc_finish_block (&block);
6617 : : }
6618 : :
6619 : : typedef struct dovar_init_d {
6620 : : gfc_symbol *sym;
6621 : : tree var;
6622 : : tree init;
6623 : : bool non_unit_iter;
6624 : : } dovar_init;
6625 : :
6626 : : static bool
6627 : 2884 : gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n,
6628 : : gfc_code *code, gfc_expr *expr, vec<dovar_init> *inits,
6629 : : int simple, gfc_expr *curr_loop_var)
6630 : : {
6631 : 2884 : int i;
6632 : 4771 : for (i = 0; i < loop_n; i++)
6633 : : {
6634 : 2441 : gcc_assert (code->ext.iterator->var->expr_type == EXPR_VARIABLE);
6635 : 2441 : if (gfc_find_sym_in_expr (code->ext.iterator->var->symtree->n.sym, expr))
6636 : : break;
6637 : 1887 : code = code->block->next;
6638 : : }
6639 : 2884 : if (i >= loop_n)
6640 : : return false;
6641 : :
6642 : : /* Canonical format: TREE_VEC with [var, multiplier, offset]. */
6643 : 554 : gfc_symbol *var = code->ext.iterator->var->symtree->n.sym;
6644 : :
6645 : 554 : tree tree_var = NULL_TREE;
6646 : 554 : tree a1 = integer_one_node;
6647 : 554 : tree a2 = integer_zero_node;
6648 : :
6649 : 554 : if (!simple)
6650 : : {
6651 : : /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
6652 : 6 : sorry_at (gfc_get_location (&curr_loop_var->where),
6653 : : "non-rectangular loop nest with non-constant step for %qs",
6654 : 3 : curr_loop_var->symtree->n.sym->name);
6655 : 3 : return false;
6656 : : }
6657 : :
6658 : : dovar_init *di;
6659 : : unsigned ix;
6660 : 551 : FOR_EACH_VEC_ELT (*inits, ix, di)
6661 : 18 : if (di->sym == var)
6662 : : {
6663 : 18 : if (!di->non_unit_iter)
6664 : : {
6665 : 16 : tree_var = di->init;
6666 : 16 : gcc_assert (DECL_P (tree_var));
6667 : : break;
6668 : : }
6669 : : else
6670 : : {
6671 : : /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
6672 : 2 : sorry_at (gfc_get_location (&code->loc),
6673 : : "non-rectangular loop nest with non-constant step "
6674 : : "for %qs", var->name);
6675 : 2 : inform (gfc_get_location (&expr->where), "Used here");
6676 : 2 : return false;
6677 : : }
6678 : : }
6679 : 533 : if (tree_var == NULL_TREE)
6680 : 533 : tree_var = var->backend_decl;
6681 : :
6682 : 549 : if (expr->expr_type == EXPR_VARIABLE)
6683 : 54 : gcc_assert (expr->symtree->n.sym == var);
6684 : 495 : else if (expr->expr_type != EXPR_OP
6685 : 495 : || (expr->value.op.op != INTRINSIC_TIMES
6686 : 479 : && expr->value.op.op != INTRINSIC_PLUS
6687 : 359 : && expr->value.op.op != INTRINSIC_MINUS))
6688 : 0 : gcc_unreachable ();
6689 : : else
6690 : : {
6691 : 495 : gfc_se se;
6692 : 495 : gfc_expr *et = NULL, *eo = NULL, *e = expr;
6693 : 495 : if (expr->value.op.op != INTRINSIC_TIMES)
6694 : : {
6695 : 479 : if (gfc_find_sym_in_expr (var, expr->value.op.op1))
6696 : : {
6697 : 431 : e = expr->value.op.op1;
6698 : 431 : eo = expr->value.op.op2;
6699 : : }
6700 : : else
6701 : : {
6702 : 48 : eo = expr->value.op.op1;
6703 : 48 : e = expr->value.op.op2;
6704 : : }
6705 : : }
6706 : 495 : if (e->value.op.op == INTRINSIC_TIMES)
6707 : : {
6708 : 91 : if (e->value.op.op1->expr_type == EXPR_VARIABLE
6709 : 91 : && e->value.op.op1->symtree->n.sym == var)
6710 : 51 : et = e->value.op.op2;
6711 : : else
6712 : : {
6713 : 40 : et = e->value.op.op1;
6714 : 40 : gcc_assert (e->value.op.op2->expr_type == EXPR_VARIABLE
6715 : : && e->value.op.op2->symtree->n.sym == var);
6716 : : }
6717 : : }
6718 : : else
6719 : 404 : gcc_assert (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym == var);
6720 : 91 : if (et != NULL)
6721 : : {
6722 : 91 : gfc_init_se (&se, NULL);
6723 : 91 : gfc_conv_expr_val (&se, et);
6724 : 91 : gfc_add_block_to_block (pblock, &se.pre);
6725 : 91 : a1 = se.expr;
6726 : : }
6727 : 495 : if (eo != NULL)
6728 : : {
6729 : 479 : gfc_init_se (&se, NULL);
6730 : 479 : gfc_conv_expr_val (&se, eo);
6731 : 479 : gfc_add_block_to_block (pblock, &se.pre);
6732 : 479 : a2 = se.expr;
6733 : 479 : if (expr->value.op.op == INTRINSIC_MINUS && expr->value.op.op2 == eo)
6734 : : /* outer-var - a2. */
6735 : 335 : a2 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a2), a2);
6736 : 144 : else if (expr->value.op.op == INTRINSIC_MINUS)
6737 : : /* a2 - outer-var. */
6738 : 24 : a1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a1), a1);
6739 : : }
6740 : 495 : a1 = DECL_P (a1) ? a1 : gfc_evaluate_now (a1, pblock);
6741 : 495 : a2 = DECL_P (a2) ? a2 : gfc_evaluate_now (a2, pblock);
6742 : : }
6743 : :
6744 : 549 : gfc_init_se (sep, NULL);
6745 : 549 : sep->expr = make_tree_vec (3);
6746 : 549 : TREE_VEC_ELT (sep->expr, 0) = tree_var;
6747 : 549 : TREE_VEC_ELT (sep->expr, 1) = fold_convert (TREE_TYPE (tree_var), a1);
6748 : 549 : TREE_VEC_ELT (sep->expr, 2) = fold_convert (TREE_TYPE (tree_var), a2);
6749 : :
6750 : 549 : return true;
6751 : : }
6752 : :
6753 : : int
6754 : 708 : gfc_expr_list_len (gfc_expr_list *list)
6755 : : {
6756 : 708 : unsigned len = 0;
6757 : 2092 : for (; list; list = list->next)
6758 : 1384 : len++;
6759 : :
6760 : 708 : return len;
6761 : : }
6762 : :
6763 : : static tree
6764 : 9512 : gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock,
6765 : : gfc_omp_clauses *do_clauses, tree par_clauses)
6766 : : {
6767 : 9512 : gfc_se se;
6768 : 9512 : tree dovar, stmt, from, to, step, type, init, cond, incr, orig_decls;
6769 : 9512 : tree local_dovar = NULL_TREE, cycle_label, tmp, omp_clauses;
6770 : 9512 : stmtblock_t block;
6771 : 9512 : stmtblock_t body;
6772 : 9512 : gfc_omp_clauses *clauses = code->ext.omp_clauses;
6773 : 9512 : int i, collapse = clauses->collapse;
6774 : 9512 : vec<dovar_init> inits = vNULL;
6775 : 9512 : dovar_init *di;
6776 : 9512 : unsigned ix;
6777 : 9512 : vec<tree, va_heap, vl_embed> *saved_doacross_steps = doacross_steps;
6778 : 19024 : gfc_expr_list *oacc_tile
6779 : 9512 : = do_clauses ? do_clauses->tile_list : clauses->tile_list;
6780 : 9512 : gfc_expr_list *sizes
6781 : : = do_clauses ? do_clauses->sizes_list : clauses->sizes_list;
6782 : 9512 : gfc_code *orig_code = code;
6783 : :
6784 : : /* Both collapsed and tiled loops are lowered the same way. In
6785 : : OpenACC, those clauses are not compatible, so prioritize the tile
6786 : : clause, if present. */
6787 : 9512 : if (oacc_tile)
6788 : 60 : collapse = gfc_expr_list_len (oacc_tile);
6789 : 9452 : else if (sizes)
6790 : 120 : collapse = gfc_expr_list_len (sizes);
6791 : :
6792 : 9512 : doacross_steps = NULL;
6793 : 9512 : if (clauses->orderedc)
6794 : 132 : collapse = clauses->orderedc;
6795 : 9512 : if (collapse <= 0)
6796 : : collapse = 1;
6797 : :
6798 : 9512 : code = code->block->next;
6799 : :
6800 : 9512 : init = make_tree_vec (collapse);
6801 : 9512 : cond = make_tree_vec (collapse);
6802 : 9512 : incr = make_tree_vec (collapse);
6803 : 9512 : orig_decls = clauses->ordered ? make_tree_vec (collapse) : NULL_TREE;
6804 : :
6805 : 9512 : if (pblock == NULL)
6806 : : {
6807 : 6028 : gfc_start_block (&block);
6808 : 6028 : pblock = █
6809 : : }
6810 : :
6811 : : /* simd schedule modifier is only useful for composite do simd and other
6812 : : constructs including that, where gfc_trans_omp_do is only called
6813 : : on the simd construct and DO's clauses are translated elsewhere. */
6814 : 9512 : do_clauses->sched_simd = false;
6815 : :
6816 : 9512 : omp_clauses = gfc_trans_omp_clauses (pblock, do_clauses, code->loc);
6817 : :
6818 : 21509 : for (i = 0; i < collapse; i++)
6819 : : {
6820 : 11997 : int simple = 0;
6821 : 11997 : int dovar_found = 0;
6822 : 11997 : tree dovar_decl;
6823 : :
6824 : 11997 : if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
6825 : : {
6826 : 320 : TREE_VEC_ELT (init, i) = NULL_TREE;
6827 : 320 : TREE_VEC_ELT (cond, i) = NULL_TREE;
6828 : 320 : TREE_VEC_ELT (incr, i) = NULL_TREE;
6829 : 320 : TREE_VEC_ELT (incr, i) = NULL_TREE;
6830 : 320 : if (orig_decls)
6831 : 2 : TREE_VEC_ELT (orig_decls, i) = NULL_TREE;
6832 : 320 : continue;
6833 : : }
6834 : 11677 : gcc_assert (code->op == EXEC_DO);
6835 : 11677 : if (clauses)
6836 : : {
6837 : 11677 : gfc_omp_namelist *n = NULL;
6838 : 11677 : if (op == EXEC_OMP_SIMD && collapse == 1)
6839 : 936 : for (n = clauses->lists[OMP_LIST_LINEAR];
6840 : 1236 : n != NULL; n = n->next)
6841 : 443 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6842 : : {
6843 : : dovar_found = 3;
6844 : : break;
6845 : : }
6846 : 11677 : if (n == NULL && op != EXEC_OMP_DISTRIBUTE)
6847 : 11440 : for (n = clauses->lists[OMP_LIST_LASTPRIVATE];
6848 : 13499 : n != NULL; n = n->next)
6849 : 3436 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6850 : : {
6851 : : dovar_found = 2;
6852 : : break;
6853 : : }
6854 : 11677 : if (n == NULL)
6855 : 11410 : for (n = clauses->lists[OMP_LIST_PRIVATE]; n != NULL; n = n->next)
6856 : 6977 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6857 : : {
6858 : : dovar_found = 1;
6859 : : break;
6860 : : }
6861 : : }
6862 : :
6863 : : /* Evaluate all the expressions in the iterator. */
6864 : 11677 : gfc_init_se (&se, NULL);
6865 : 11677 : gfc_conv_expr_lhs (&se, code->ext.iterator->var);
6866 : 11677 : gfc_add_block_to_block (pblock, &se.pre);
6867 : 11677 : local_dovar = dovar_decl = dovar = se.expr;
6868 : 11677 : type = TREE_TYPE (dovar);
6869 : 11677 : gcc_assert (TREE_CODE (type) == INTEGER_TYPE);
6870 : :
6871 : 11677 : gfc_init_se (&se, NULL);
6872 : 11677 : gfc_conv_expr_val (&se, code->ext.iterator->step);
6873 : 11677 : gfc_add_block_to_block (pblock, &se.pre);
6874 : 11677 : step = gfc_evaluate_now (se.expr, pblock);
6875 : :
6876 : 11677 : if (TREE_CODE (step) == INTEGER_CST)
6877 : 11086 : simple = tree_int_cst_sgn (step);
6878 : :
6879 : 11677 : gfc_init_se (&se, NULL);
6880 : 11677 : if (!clauses->non_rectangular
6881 : 13119 : || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
6882 : : code->ext.iterator->start, &inits, simple,
6883 : 1442 : code->ext.iterator->var))
6884 : : {
6885 : 11361 : gfc_conv_expr_val (&se, code->ext.iterator->start);
6886 : 11361 : gfc_add_block_to_block (pblock, &se.pre);
6887 : 11361 : if (!DECL_P (se.expr))
6888 : 10963 : se.expr = gfc_evaluate_now (se.expr, pblock);
6889 : : }
6890 : 11677 : from = se.expr;
6891 : :
6892 : 11677 : gfc_init_se (&se, NULL);
6893 : 11677 : if (!clauses->non_rectangular
6894 : 13119 : || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
6895 : : code->ext.iterator->end, &inits, simple,
6896 : 1442 : code->ext.iterator->var))
6897 : : {
6898 : 11444 : gfc_conv_expr_val (&se, code->ext.iterator->end);
6899 : 11444 : gfc_add_block_to_block (pblock, &se.pre);
6900 : 11444 : if (!DECL_P (se.expr))
6901 : 10211 : se.expr = gfc_evaluate_now (se.expr, pblock);
6902 : : }
6903 : 11677 : to = se.expr;
6904 : :
6905 : 11677 : if (!DECL_P (dovar))
6906 : 38 : dovar_decl
6907 : 38 : = gfc_trans_omp_variable (code->ext.iterator->var->symtree->n.sym,
6908 : : false);
6909 : 11677 : if (simple && !DECL_P (dovar))
6910 : : {
6911 : 38 : const char *name = code->ext.iterator->var->symtree->n.sym->name;
6912 : 38 : local_dovar = gfc_create_var (type, name);
6913 : 38 : dovar_init e = {code->ext.iterator->var->symtree->n.sym,
6914 : 38 : dovar, local_dovar, false};
6915 : 38 : inits.safe_push (e);
6916 : : }
6917 : : /* Loop body. */
6918 : 11677 : if (simple)
6919 : : {
6920 : 11086 : TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar, from);
6921 : : /* The condition should not be folded. */
6922 : 11638 : TREE_VEC_ELT (cond, i) = build2_loc (input_location, simple > 0
6923 : : ? LE_EXPR : GE_EXPR,
6924 : : logical_type_node, local_dovar,
6925 : : to);
6926 : 11086 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
6927 : : type, local_dovar, step);
6928 : 11086 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
6929 : : MODIFY_EXPR,
6930 : : type, local_dovar,
6931 : 11086 : TREE_VEC_ELT (incr, i));
6932 : 11086 : if (orig_decls && !clauses->orderedc)
6933 : : orig_decls = NULL;
6934 : 380 : else if (orig_decls)
6935 : 380 : TREE_VEC_ELT (orig_decls, i) = dovar_decl;
6936 : : }
6937 : : else
6938 : : {
6939 : : /* STEP is not 1 or -1. Use:
6940 : : for (count = 0; count < (to + step - from) / step; count++)
6941 : : {
6942 : : dovar = from + count * step;
6943 : : body;
6944 : : cycle_label:;
6945 : : } */
6946 : 591 : tmp = fold_build2_loc (input_location, MINUS_EXPR, type, step, from);
6947 : 591 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type, to, tmp);
6948 : 591 : tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR, type, tmp,
6949 : : step);
6950 : 591 : tmp = gfc_evaluate_now (tmp, pblock);
6951 : 591 : local_dovar = gfc_create_var (type, "count");
6952 : 591 : TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar,
6953 : : build_int_cst (type, 0));
6954 : : /* The condition should not be folded. */
6955 : 591 : TREE_VEC_ELT (cond, i) = build2_loc (input_location, LT_EXPR,
6956 : : logical_type_node,
6957 : : local_dovar, tmp);
6958 : 591 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
6959 : : type, local_dovar,
6960 : : build_int_cst (type, 1));
6961 : 591 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
6962 : : MODIFY_EXPR, type,
6963 : : local_dovar,
6964 : 591 : TREE_VEC_ELT (incr, i));
6965 : :
6966 : : /* Initialize DOVAR. */
6967 : 591 : tmp = fold_build2_loc (input_location, MULT_EXPR, type, local_dovar,
6968 : : step);
6969 : 591 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type, from, tmp);
6970 : 591 : dovar_init e = {code->ext.iterator->var->symtree->n.sym,
6971 : 591 : dovar, tmp, true};
6972 : 591 : inits.safe_push (e);
6973 : 591 : if (clauses->orderedc)
6974 : : {
6975 : 192 : if (doacross_steps == NULL)
6976 : 47 : vec_safe_grow_cleared (doacross_steps, clauses->orderedc, true);
6977 : 192 : (*doacross_steps)[i] = step;
6978 : : }
6979 : 591 : if (orig_decls)
6980 : 198 : TREE_VEC_ELT (orig_decls, i) = dovar_decl;
6981 : : }
6982 : :
6983 : 11677 : if (dovar_found == 3
6984 : 11677 : && op == EXEC_OMP_SIMD
6985 : 143 : && collapse == 1
6986 : 143 : && local_dovar != dovar)
6987 : : {
6988 : 120 : for (tmp = omp_clauses; tmp; tmp = OMP_CLAUSE_CHAIN (tmp))
6989 : 120 : if (OMP_CLAUSE_CODE (tmp) == OMP_CLAUSE_LINEAR
6990 : 120 : && OMP_CLAUSE_DECL (tmp) == dovar)
6991 : : {
6992 : 30 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
6993 : 30 : break;
6994 : : }
6995 : : }
6996 : 11677 : if (!dovar_found && op == EXEC_OMP_SIMD)
6997 : : {
6998 : 1352 : if (collapse == 1)
6999 : : {
7000 : 783 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
7001 : 783 : OMP_CLAUSE_LINEAR_STEP (tmp) = step;
7002 : 783 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
7003 : 783 : OMP_CLAUSE_DECL (tmp) = dovar_decl;
7004 : 783 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
7005 : 783 : if (local_dovar != dovar)
7006 : : dovar_found = 3;
7007 : : }
7008 : : }
7009 : 10325 : else if (!dovar_found && local_dovar != dovar)
7010 : : {
7011 : 260 : tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
7012 : 260 : OMP_CLAUSE_DECL (tmp) = dovar_decl;
7013 : 260 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
7014 : : }
7015 : 11647 : if (dovar_found > 1)
7016 : : {
7017 : 1550 : tree c = NULL;
7018 : :
7019 : 1550 : tmp = NULL;
7020 : 1550 : if (local_dovar != dovar)
7021 : : {
7022 : : /* If dovar is lastprivate, but different counter is used,
7023 : : dovar += step needs to be added to
7024 : : OMP_CLAUSE_LASTPRIVATE_STMT, otherwise the copied dovar
7025 : : will have the value on entry of the last loop, rather
7026 : : than value after iterator increment. */
7027 : 243 : if (clauses->orderedc)
7028 : : {
7029 : 60 : if (clauses->collapse <= 1 || i >= clauses->collapse)
7030 : : tmp = local_dovar;
7031 : : else
7032 : 36 : tmp = fold_build2_loc (input_location, PLUS_EXPR,
7033 : : type, local_dovar,
7034 : : build_one_cst (type));
7035 : 60 : tmp = fold_build2_loc (input_location, MULT_EXPR, type,
7036 : : tmp, step);
7037 : 60 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
7038 : : from, tmp);
7039 : : }
7040 : : else
7041 : 183 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
7042 : : dovar, step);
7043 : 243 : tmp = fold_build2_loc (input_location, MODIFY_EXPR, type,
7044 : : dovar, tmp);
7045 : 934 : for (c = omp_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7046 : 613 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7047 : 613 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7048 : : {
7049 : 105 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = tmp;
7050 : 105 : break;
7051 : : }
7052 : 508 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7053 : 508 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7054 : : {
7055 : 60 : OMP_CLAUSE_LINEAR_STMT (c) = tmp;
7056 : 60 : break;
7057 : : }
7058 : : }
7059 : 1550 : if (c == NULL && op == EXEC_OMP_DO && par_clauses != NULL)
7060 : : {
7061 : 892 : for (c = par_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7062 : 892 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7063 : 892 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7064 : : {
7065 : 406 : tree l = build_omp_clause (input_location,
7066 : : OMP_CLAUSE_LASTPRIVATE);
7067 : 406 : if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
7068 : 4 : OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (l) = 1;
7069 : 406 : OMP_CLAUSE_DECL (l) = dovar_decl;
7070 : 406 : OMP_CLAUSE_CHAIN (l) = omp_clauses;
7071 : 406 : OMP_CLAUSE_LASTPRIVATE_STMT (l) = tmp;
7072 : 406 : omp_clauses = l;
7073 : 406 : OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_SHARED);
7074 : 406 : break;
7075 : : }
7076 : : }
7077 : 1550 : gcc_assert (local_dovar == dovar || c != NULL);
7078 : : }
7079 : 11677 : if (local_dovar != dovar)
7080 : : {
7081 : 629 : if (op != EXEC_OMP_SIMD || dovar_found == 1)
7082 : 550 : tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
7083 : 79 : else if (collapse == 1)
7084 : : {
7085 : 60 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
7086 : 60 : OMP_CLAUSE_LINEAR_STEP (tmp) = build_int_cst (type, 1);
7087 : 60 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
7088 : 60 : OMP_CLAUSE_LINEAR_NO_COPYOUT (tmp) = 1;
7089 : : }
7090 : : else
7091 : 19 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LASTPRIVATE);
7092 : 629 : OMP_CLAUSE_DECL (tmp) = local_dovar;
7093 : 629 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
7094 : : }
7095 : :
7096 : 11677 : if (i + 1 < collapse)
7097 : 2457 : code = code->block->next;
7098 : : }
7099 : :
7100 : 9512 : if (pblock != &block)
7101 : : {
7102 : 3484 : pushlevel ();
7103 : 3484 : gfc_start_block (&block);
7104 : : }
7105 : :
7106 : 9512 : gfc_start_block (&body);
7107 : :
7108 : 19653 : FOR_EACH_VEC_ELT (inits, ix, di)
7109 : 629 : gfc_add_modify (&body, di->var, di->init);
7110 : 9512 : inits.release ();
7111 : :
7112 : : /* Cycle statement is implemented with a goto. Exit statement must not be
7113 : : present for this loop. */
7114 : 9512 : cycle_label = gfc_build_label_decl (NULL_TREE);
7115 : :
7116 : : /* Put these labels where they can be found later. */
7117 : :
7118 : 9512 : code->cycle_label = cycle_label;
7119 : 9512 : code->exit_label = NULL_TREE;
7120 : :
7121 : : /* Main loop body. */
7122 : 9512 : if (clauses->lists[OMP_LIST_REDUCTION_INSCAN])
7123 : : {
7124 : 16 : gfc_code *code1, *scan, *code2, *tmpcode;
7125 : 16 : code1 = tmpcode = code->block->next;
7126 : 16 : if (tmpcode && tmpcode->op != EXEC_OMP_SCAN)
7127 : 18 : while (tmpcode && tmpcode->next && tmpcode->next->op != EXEC_OMP_SCAN)
7128 : : tmpcode = tmpcode->next;
7129 : 16 : scan = tmpcode->op == EXEC_OMP_SCAN ? tmpcode : tmpcode->next;
7130 : 16 : if (code1 != scan)
7131 : 16 : tmpcode->next = NULL;
7132 : 16 : code2 = scan->next;
7133 : 16 : gcc_assert (scan->op == EXEC_OMP_SCAN);
7134 : 16 : location_t loc = gfc_get_location (&scan->loc);
7135 : :
7136 : 16 : tmp = code1 != scan ? gfc_trans_code (code1) : build_empty_stmt (loc);
7137 : 16 : tmp = build2 (OMP_SCAN, void_type_node, tmp, NULL_TREE);
7138 : 16 : SET_EXPR_LOCATION (tmp, loc);
7139 : 16 : gfc_add_expr_to_block (&body, tmp);
7140 : 16 : input_location = loc;
7141 : 16 : tree c = gfc_trans_omp_clauses (&body, scan->ext.omp_clauses, scan->loc);
7142 : 16 : tmp = code2 ? gfc_trans_code (code2) : build_empty_stmt (loc);
7143 : 16 : tmp = build2 (OMP_SCAN, void_type_node, tmp, c);
7144 : 16 : SET_EXPR_LOCATION (tmp, loc);
7145 : 16 : if (code1 != scan)
7146 : 16 : tmpcode->next = scan;
7147 : : }
7148 : 9496 : else if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
7149 : 292 : tmp = gfc_trans_omp_code (code, true);
7150 : : else
7151 : 9204 : tmp = gfc_trans_omp_code (code->block->next, true);
7152 : 9512 : gfc_add_expr_to_block (&body, tmp);
7153 : :
7154 : : /* Label for cycle statements (if needed). */
7155 : 9512 : if (TREE_USED (cycle_label))
7156 : : {
7157 : 9512 : tmp = build1_v (LABEL_EXPR, cycle_label);
7158 : 9512 : gfc_add_expr_to_block (&body, tmp);
7159 : : }
7160 : :
7161 : : /* End of loop body. */
7162 : 9512 : switch (op)
7163 : : {
7164 : 1453 : case EXEC_OMP_SIMD: stmt = make_node (OMP_SIMD); break;
7165 : 2404 : case EXEC_OMP_DO: stmt = make_node (OMP_FOR); break;
7166 : 80 : case EXEC_OMP_DISTRIBUTE: stmt = make_node (OMP_DISTRIBUTE); break;
7167 : 112 : case EXEC_OMP_LOOP: stmt = make_node (OMP_LOOP); break;
7168 : 94 : case EXEC_OMP_TASKLOOP: stmt = make_node (OMP_TASKLOOP); break;
7169 : 4927 : case EXEC_OACC_LOOP: stmt = make_node (OACC_LOOP); break;
7170 : 120 : case EXEC_OMP_TILE: stmt = make_node (OMP_TILE); break;
7171 : 322 : case EXEC_OMP_UNROLL: stmt = make_node (OMP_UNROLL); break;
7172 : 0 : default: gcc_unreachable ();
7173 : : }
7174 : :
7175 : 9512 : SET_EXPR_LOCATION (stmt, gfc_get_location (&orig_code->loc));
7176 : 9512 : TREE_TYPE (stmt) = void_type_node;
7177 : 9512 : OMP_FOR_BODY (stmt) = gfc_finish_block (&body);
7178 : 9512 : OMP_FOR_CLAUSES (stmt) = omp_clauses;
7179 : 9512 : OMP_FOR_INIT (stmt) = init;
7180 : 9512 : OMP_FOR_COND (stmt) = cond;
7181 : 9512 : OMP_FOR_INCR (stmt) = incr;
7182 : 9512 : if (orig_decls)
7183 : 138 : OMP_FOR_ORIG_DECLS (stmt) = orig_decls;
7184 : 9512 : OMP_FOR_NON_RECTANGULAR (stmt) = clauses->non_rectangular;
7185 : 9512 : gfc_add_expr_to_block (&block, stmt);
7186 : :
7187 : 9512 : vec_free (doacross_steps);
7188 : 9512 : doacross_steps = saved_doacross_steps;
7189 : :
7190 : 9512 : return gfc_finish_block (&block);
7191 : : }
7192 : :
7193 : : /* Translate combined OpenACC 'parallel loop', 'kernels loop', 'serial loop'
7194 : : construct. */
7195 : :
7196 : : static tree
7197 : 1552 : gfc_trans_oacc_combined_directive (gfc_code *code)
7198 : : {
7199 : 1552 : stmtblock_t block, *pblock = NULL;
7200 : 1552 : gfc_omp_clauses construct_clauses, loop_clauses;
7201 : 1552 : tree stmt, oacc_clauses = NULL_TREE;
7202 : 1552 : enum tree_code construct_code;
7203 : 1552 : location_t loc = input_location;
7204 : :
7205 : 1552 : switch (code->op)
7206 : : {
7207 : : case EXEC_OACC_PARALLEL_LOOP:
7208 : : construct_code = OACC_PARALLEL;
7209 : : break;
7210 : : case EXEC_OACC_KERNELS_LOOP:
7211 : : construct_code = OACC_KERNELS;
7212 : : break;
7213 : : case EXEC_OACC_SERIAL_LOOP:
7214 : : construct_code = OACC_SERIAL;
7215 : : break;
7216 : 0 : default:
7217 : 0 : gcc_unreachable ();
7218 : : }
7219 : :
7220 : 1552 : gfc_start_block (&block);
7221 : :
7222 : 1552 : memset (&loop_clauses, 0, sizeof (loop_clauses));
7223 : 1552 : if (code->ext.omp_clauses != NULL)
7224 : : {
7225 : 1552 : memcpy (&construct_clauses, code->ext.omp_clauses,
7226 : : sizeof (construct_clauses));
7227 : 1552 : loop_clauses.collapse = construct_clauses.collapse;
7228 : 1552 : loop_clauses.gang = construct_clauses.gang;
7229 : 1552 : loop_clauses.gang_static = construct_clauses.gang_static;
7230 : 1552 : loop_clauses.gang_num_expr = construct_clauses.gang_num_expr;
7231 : 1552 : loop_clauses.gang_static_expr = construct_clauses.gang_static_expr;
7232 : 1552 : loop_clauses.vector = construct_clauses.vector;
7233 : 1552 : loop_clauses.vector_expr = construct_clauses.vector_expr;
7234 : 1552 : loop_clauses.worker = construct_clauses.worker;
7235 : 1552 : loop_clauses.worker_expr = construct_clauses.worker_expr;
7236 : 1552 : loop_clauses.seq = construct_clauses.seq;
7237 : 1552 : loop_clauses.par_auto = construct_clauses.par_auto;
7238 : 1552 : loop_clauses.independent = construct_clauses.independent;
7239 : 1552 : loop_clauses.tile_list = construct_clauses.tile_list;
7240 : 1552 : loop_clauses.lists[OMP_LIST_PRIVATE]
7241 : 1552 : = construct_clauses.lists[OMP_LIST_PRIVATE];
7242 : 1552 : loop_clauses.lists[OMP_LIST_REDUCTION]
7243 : 1552 : = construct_clauses.lists[OMP_LIST_REDUCTION];
7244 : 1552 : construct_clauses.gang = false;
7245 : 1552 : construct_clauses.gang_static = false;
7246 : 1552 : construct_clauses.gang_num_expr = NULL;
7247 : 1552 : construct_clauses.gang_static_expr = NULL;
7248 : 1552 : construct_clauses.vector = false;
7249 : 1552 : construct_clauses.vector_expr = NULL;
7250 : 1552 : construct_clauses.worker = false;
7251 : 1552 : construct_clauses.worker_expr = NULL;
7252 : 1552 : construct_clauses.seq = false;
7253 : 1552 : construct_clauses.par_auto = false;
7254 : 1552 : construct_clauses.independent = false;
7255 : 1552 : construct_clauses.independent = false;
7256 : 1552 : construct_clauses.tile_list = NULL;
7257 : 1552 : construct_clauses.lists[OMP_LIST_PRIVATE] = NULL;
7258 : 1552 : if (construct_code == OACC_KERNELS)
7259 : 87 : construct_clauses.lists[OMP_LIST_REDUCTION] = NULL;
7260 : 1552 : oacc_clauses = gfc_trans_omp_clauses (&block, &construct_clauses,
7261 : : code->loc, false, true);
7262 : : }
7263 : 1552 : if (!loop_clauses.seq)
7264 : : pblock = █
7265 : : else
7266 : 54 : pushlevel ();
7267 : 1552 : stmt = gfc_trans_omp_do (code, EXEC_OACC_LOOP, pblock, &loop_clauses, NULL);
7268 : 1552 : protected_set_expr_location (stmt, loc);
7269 : 1552 : if (TREE_CODE (stmt) != BIND_EXPR)
7270 : 1552 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
7271 : : else
7272 : 0 : poplevel (0, 0);
7273 : 1552 : stmt = build2_loc (loc, construct_code, void_type_node, stmt, oacc_clauses);
7274 : 1552 : gfc_add_expr_to_block (&block, stmt);
7275 : 1552 : return gfc_finish_block (&block);
7276 : : }
7277 : :
7278 : : static tree
7279 : 108 : gfc_trans_omp_depobj (gfc_code *code)
7280 : : {
7281 : 108 : stmtblock_t block;
7282 : 108 : gfc_se se;
7283 : 108 : gfc_init_se (&se, NULL);
7284 : 108 : gfc_init_block (&block);
7285 : 108 : gfc_conv_expr (&se, code->ext.omp_clauses->depobj);
7286 : 108 : gcc_assert (se.pre.head == NULL && se.post.head == NULL);
7287 : 108 : tree depobj = se.expr;
7288 : 108 : location_t loc = EXPR_LOCATION (depobj);
7289 : 108 : if (!POINTER_TYPE_P (TREE_TYPE (depobj)))
7290 : 108 : depobj = gfc_build_addr_expr (NULL, depobj);
7291 : 108 : depobj = fold_convert (build_pointer_type_for_mode (ptr_type_node,
7292 : : TYPE_MODE (ptr_type_node),
7293 : : true), depobj);
7294 : 108 : gfc_omp_namelist *n = code->ext.omp_clauses->lists[OMP_LIST_DEPEND];
7295 : 108 : if (n)
7296 : : {
7297 : 83 : tree var;
7298 : 83 : if (!n->sym) /* omp_all_memory. */
7299 : 3 : var = null_pointer_node;
7300 : 80 : else if (n->expr && n->expr->ref->u.ar.type != AR_FULL)
7301 : : {
7302 : 18 : gfc_init_se (&se, NULL);
7303 : 18 : if (n->expr->ref->u.ar.type == AR_ELEMENT)
7304 : : {
7305 : 18 : gfc_conv_expr_reference (&se, n->expr);
7306 : 18 : var = se.expr;
7307 : : }
7308 : : else
7309 : : {
7310 : 0 : gfc_conv_expr_descriptor (&se, n->expr);
7311 : 0 : var = gfc_conv_array_data (se.expr);
7312 : : }
7313 : 18 : gfc_add_block_to_block (&block, &se.pre);
7314 : 18 : gfc_add_block_to_block (&block, &se.post);
7315 : 18 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
7316 : : }
7317 : : else
7318 : : {
7319 : 62 : var = gfc_get_symbol_decl (n->sym);
7320 : 99 : if (POINTER_TYPE_P (TREE_TYPE (var))
7321 : 72 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (var))))
7322 : 8 : var = build_fold_indirect_ref (var);
7323 : 62 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (var)))
7324 : : {
7325 : 12 : var = gfc_conv_descriptor_data_get (var);
7326 : 12 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
7327 : : }
7328 : 50 : else if ((n->sym->attr.allocatable || n->sym->attr.pointer)
7329 : 13 : && n->sym->attr.dummy)
7330 : 8 : var = build_fold_indirect_ref (var);
7331 : 67 : else if (!POINTER_TYPE_P (TREE_TYPE (var))
7332 : 44 : || (n->sym->ts.f90_type == BT_VOID
7333 : 12 : && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (var)))
7334 : 8 : && !GFC_ARRAY_TYPE_P (TREE_TYPE (TREE_TYPE (var)))))
7335 : : {
7336 : 29 : TREE_ADDRESSABLE (var) = 1;
7337 : 29 : var = gfc_build_addr_expr (NULL, var);
7338 : : }
7339 : : }
7340 : 83 : depobj = save_expr (depobj);
7341 : 83 : tree r = build_fold_indirect_ref_loc (loc, depobj);
7342 : 83 : gfc_add_expr_to_block (&block,
7343 : : build2 (MODIFY_EXPR, void_type_node, r, var));
7344 : : }
7345 : :
7346 : : /* Only one may be set. */
7347 : 108 : gcc_assert (((int)(n != NULL) + (int)(code->ext.omp_clauses->destroy)
7348 : : + (int)(code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET))
7349 : : == 1);
7350 : 108 : int k = -1; /* omp_clauses->destroy */
7351 : 108 : if (!code->ext.omp_clauses->destroy)
7352 : 92 : switch (code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET
7353 : 92 : ? code->ext.omp_clauses->depobj_update : n->u.depend_doacross_op)
7354 : : {
7355 : : case OMP_DEPEND_IN: k = GOMP_DEPEND_IN; break;
7356 : : case OMP_DEPEND_OUT: k = GOMP_DEPEND_OUT; break;
7357 : : case OMP_DEPEND_INOUT: k = GOMP_DEPEND_INOUT; break;
7358 : : case OMP_DEPEND_INOUTSET: k = GOMP_DEPEND_INOUTSET; break;
7359 : : case OMP_DEPEND_MUTEXINOUTSET: k = GOMP_DEPEND_MUTEXINOUTSET; break;
7360 : 0 : default: gcc_unreachable ();
7361 : : }
7362 : 108 : tree t = build_int_cst (ptr_type_node, k);
7363 : 108 : depobj = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (depobj), depobj,
7364 : 108 : TYPE_SIZE_UNIT (ptr_type_node));
7365 : 108 : depobj = build_fold_indirect_ref_loc (loc, depobj);
7366 : 108 : gfc_add_expr_to_block (&block, build2 (MODIFY_EXPR, void_type_node, depobj, t));
7367 : :
7368 : 108 : return gfc_finish_block (&block);
7369 : : }
7370 : :
7371 : : /* Callback for walk_tree to find an OMP dispatch call and wrap it into an
7372 : : * IFN_GOMP_DISPATCH. */
7373 : :
7374 : : static tree
7375 : 2066 : replace_omp_dispatch_call (tree *tp, int *, void *decls_p)
7376 : : {
7377 : 2066 : tree t = *tp;
7378 : 2066 : tree decls = (tree) decls_p;
7379 : 2066 : tree orig_fn_decl = TREE_PURPOSE (decls);
7380 : 2066 : tree dup_fn_decl = TREE_VALUE (decls);
7381 : 2066 : if (TREE_CODE (t) == CALL_EXPR)
7382 : : {
7383 : 141 : if (CALL_EXPR_FN (t) == dup_fn_decl)
7384 : 1 : CALL_EXPR_FN (t) = orig_fn_decl;
7385 : 140 : else if (TREE_CODE (CALL_EXPR_FN (t)) == ADDR_EXPR
7386 : 140 : && TREE_OPERAND (CALL_EXPR_FN (t), 0) == dup_fn_decl)
7387 : 127 : TREE_OPERAND (CALL_EXPR_FN (t), 0) = dup_fn_decl;
7388 : : else
7389 : : return NULL_TREE;
7390 : 128 : *tp = build_call_expr_internal_loc (input_location, IFN_GOMP_DISPATCH,
7391 : 128 : TREE_TYPE (t), 1, t);
7392 : 128 : return *tp;
7393 : : }
7394 : :
7395 : : return NULL_TREE;
7396 : : }
7397 : :
7398 : : static tree
7399 : 128 : gfc_trans_omp_dispatch (gfc_code *code)
7400 : : {
7401 : 128 : stmtblock_t block;
7402 : 128 : gfc_code *next = code->block->next;
7403 : : // assume ill-formed "function dispatch structured
7404 : : // block" have already been rejected by resolve_omp_dispatch
7405 : 128 : gcc_assert (next->op == EXEC_CALL || next->op == EXEC_ASSIGN);
7406 : :
7407 : : // Make duplicate decl for dispatch function call to make it easy to spot
7408 : : // after translation
7409 : 128 : gfc_symbol *orig_fn_sym;
7410 : 128 : gfc_expr *call_expr = next->op == EXEC_CALL ? next->expr1 : next->expr2;
7411 : 128 : if (call_expr != NULL) // function
7412 : : {
7413 : 71 : if (call_expr->value.function.isym != NULL) // dig into convert intrinsics
7414 : 4 : call_expr = call_expr->value.function.actual->expr;
7415 : 71 : gcc_assert (call_expr->expr_type == EXPR_FUNCTION);
7416 : 71 : orig_fn_sym = call_expr->value.function.esym
7417 : 71 : ? call_expr->value.function.esym
7418 : 0 : : call_expr->symtree->n.sym;
7419 : : }
7420 : : else // subroutine
7421 : : {
7422 : 57 : orig_fn_sym = next->resolved_sym;
7423 : : }
7424 : 128 : if (!orig_fn_sym->backend_decl)
7425 : 25 : gfc_get_symbol_decl (orig_fn_sym);
7426 : 128 : gfc_symbol dup_fn_sym = *orig_fn_sym;
7427 : 128 : dup_fn_sym.backend_decl = copy_node (orig_fn_sym->backend_decl);
7428 : 128 : if (call_expr != NULL)
7429 : 71 : call_expr->value.function.esym = &dup_fn_sym;
7430 : : else
7431 : 57 : next->resolved_sym = &dup_fn_sym;
7432 : :
7433 : 128 : tree body = gfc_trans_code (next);
7434 : :
7435 : : // Walk the tree to find the duplicate decl, wrap IFN call and replace
7436 : : // dup decl with original
7437 : 128 : tree fn_decls
7438 : 128 : = build_tree_list (orig_fn_sym->backend_decl, dup_fn_sym.backend_decl);
7439 : 128 : tree dispatch_call
7440 : 128 : = walk_tree (&body, replace_omp_dispatch_call, fn_decls, NULL);
7441 : 128 : gcc_assert (dispatch_call != NULL_TREE);
7442 : :
7443 : 128 : gfc_start_block (&block);
7444 : 128 : tree omp_clauses
7445 : 128 : = gfc_trans_omp_clauses (&block, code->ext.omp_clauses, code->loc);
7446 : :
7447 : : // Extract depend clauses and create taskwait
7448 : 128 : tree depend_clauses = NULL_TREE;
7449 : 128 : tree *depend_clauses_ptr = &depend_clauses;
7450 : 333 : for (tree c = omp_clauses; c; c = OMP_CLAUSE_CHAIN (c))
7451 : : {
7452 : 205 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
7453 : : {
7454 : 8 : *depend_clauses_ptr = c;
7455 : 8 : depend_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
7456 : : }
7457 : : }
7458 : 128 : if (depend_clauses != NULL_TREE)
7459 : : {
7460 : 4 : tree stmt = make_node (OMP_TASK);
7461 : 4 : TREE_TYPE (stmt) = void_node;
7462 : 4 : OMP_TASK_CLAUSES (stmt) = depend_clauses;
7463 : 4 : OMP_TASK_BODY (stmt) = NULL_TREE;
7464 : 4 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7465 : 4 : gfc_add_expr_to_block (&block, stmt);
7466 : : }
7467 : :
7468 : 128 : tree stmt = make_node (OMP_DISPATCH);
7469 : 128 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7470 : 128 : TREE_TYPE (stmt) = void_type_node;
7471 : 128 : OMP_DISPATCH_BODY (stmt) = body;
7472 : 128 : OMP_DISPATCH_CLAUSES (stmt) = omp_clauses;
7473 : :
7474 : 128 : gfc_add_expr_to_block (&block, stmt);
7475 : 128 : return gfc_finish_block (&block);
7476 : : }
7477 : :
7478 : : static tree
7479 : 29 : gfc_trans_omp_error (gfc_code *code)
7480 : : {
7481 : 29 : stmtblock_t block;
7482 : 29 : gfc_se se;
7483 : 29 : tree len, message;
7484 : 29 : bool fatal = code->ext.omp_clauses->severity == OMP_SEVERITY_FATAL;
7485 : 42 : tree fndecl = builtin_decl_explicit (fatal ? BUILT_IN_GOMP_ERROR
7486 : : : BUILT_IN_GOMP_WARNING);
7487 : 29 : gfc_start_block (&block);
7488 : 29 : gfc_init_se (&se, NULL );
7489 : 29 : if (!code->ext.omp_clauses->message)
7490 : : {
7491 : 3 : message = null_pointer_node;
7492 : 3 : len = build_int_cst (size_type_node, 0);
7493 : : }
7494 : : else
7495 : : {
7496 : 26 : gfc_conv_expr (&se, code->ext.omp_clauses->message);
7497 : 26 : message = se.expr;
7498 : 26 : if (!POINTER_TYPE_P (TREE_TYPE (message)))
7499 : : /* To ensure an ARRAY_TYPE is not passed as such. */
7500 : 17 : message = gfc_build_addr_expr (NULL, message);
7501 : 26 : len = se.string_length;
7502 : : }
7503 : 29 : gfc_add_block_to_block (&block, &se.pre);
7504 : 29 : gfc_add_expr_to_block (&block, build_call_expr_loc (input_location, fndecl,
7505 : : 2, message, len));
7506 : 29 : gfc_add_block_to_block (&block, &se.post);
7507 : 29 : return gfc_finish_block (&block);
7508 : : }
7509 : :
7510 : : static tree
7511 : 70 : gfc_trans_omp_flush (gfc_code *code)
7512 : : {
7513 : 70 : tree call;
7514 : 70 : if (!code->ext.omp_clauses
7515 : 4 : || code->ext.omp_clauses->memorder == OMP_MEMORDER_UNSET
7516 : 4 : || code->ext.omp_clauses->memorder == OMP_MEMORDER_SEQ_CST)
7517 : : {
7518 : 67 : call = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
7519 : 67 : call = build_call_expr_loc (input_location, call, 0);
7520 : : }
7521 : : else
7522 : : {
7523 : 3 : enum memmodel mo = MEMMODEL_LAST;
7524 : 3 : switch (code->ext.omp_clauses->memorder)
7525 : : {
7526 : : case OMP_MEMORDER_ACQ_REL: mo = MEMMODEL_ACQ_REL; break;
7527 : : case OMP_MEMORDER_RELEASE: mo = MEMMODEL_RELEASE; break;
7528 : : case OMP_MEMORDER_ACQUIRE: mo = MEMMODEL_ACQUIRE; break;
7529 : 0 : default: gcc_unreachable (); break;
7530 : : }
7531 : 3 : call = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
7532 : 3 : call = build_call_expr_loc (input_location, call, 1,
7533 : 3 : build_int_cst (integer_type_node, mo));
7534 : : }
7535 : 70 : return call;
7536 : : }
7537 : :
7538 : : static tree
7539 : 115 : gfc_trans_omp_master (gfc_code *code)
7540 : : {
7541 : 115 : tree stmt = gfc_trans_code (code->block->next);
7542 : 115 : if (IS_EMPTY_STMT (stmt))
7543 : : return stmt;
7544 : 109 : return build1_v (OMP_MASTER, stmt);
7545 : : }
7546 : :
7547 : : static tree
7548 : 49 : gfc_trans_omp_masked (gfc_code *code, gfc_omp_clauses *clauses)
7549 : : {
7550 : 49 : stmtblock_t block;
7551 : 49 : tree body = gfc_trans_code (code->block->next);
7552 : 49 : if (IS_EMPTY_STMT (body))
7553 : : return body;
7554 : 40 : if (!clauses)
7555 : 33 : clauses = code->ext.omp_clauses;
7556 : 40 : gfc_start_block (&block);
7557 : 40 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
7558 : 40 : tree stmt = make_node (OMP_MASKED);
7559 : 40 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7560 : 40 : TREE_TYPE (stmt) = void_type_node;
7561 : 40 : OMP_MASKED_BODY (stmt) = body;
7562 : 40 : OMP_MASKED_CLAUSES (stmt) = omp_clauses;
7563 : 40 : gfc_add_expr_to_block (&block, stmt);
7564 : 40 : return gfc_finish_block (&block);
7565 : : }
7566 : :
7567 : :
7568 : : static tree
7569 : 519 : gfc_trans_omp_ordered (gfc_code *code)
7570 : : {
7571 : 519 : if (!flag_openmp)
7572 : : {
7573 : 5 : if (!code->ext.omp_clauses->simd)
7574 : 3 : return gfc_trans_code (code->block ? code->block->next : NULL);
7575 : 2 : code->ext.omp_clauses->threads = 0;
7576 : : }
7577 : 516 : tree omp_clauses = gfc_trans_omp_clauses (NULL, code->ext.omp_clauses,
7578 : : code->loc);
7579 : 516 : return build2_loc (input_location, OMP_ORDERED, void_type_node,
7580 : 516 : code->block ? gfc_trans_code (code->block->next)
7581 : 516 : : NULL_TREE, omp_clauses);
7582 : : }
7583 : :
7584 : : static tree
7585 : 1858 : gfc_trans_omp_parallel (gfc_code *code)
7586 : : {
7587 : 1858 : stmtblock_t block;
7588 : 1858 : tree stmt, omp_clauses;
7589 : :
7590 : 1858 : gfc_start_block (&block);
7591 : 1858 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
7592 : : code->loc);
7593 : 1858 : pushlevel ();
7594 : 1858 : stmt = gfc_trans_omp_code (code->block->next, true);
7595 : 1858 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
7596 : 1858 : stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
7597 : : omp_clauses);
7598 : 1858 : gfc_add_expr_to_block (&block, stmt);
7599 : 1858 : return gfc_finish_block (&block);
7600 : : }
7601 : :
7602 : : enum
7603 : : {
7604 : : GFC_OMP_SPLIT_SIMD,
7605 : : GFC_OMP_SPLIT_DO,
7606 : : GFC_OMP_SPLIT_PARALLEL,
7607 : : GFC_OMP_SPLIT_DISTRIBUTE,
7608 : : GFC_OMP_SPLIT_TEAMS,
7609 : : GFC_OMP_SPLIT_TARGET,
7610 : : GFC_OMP_SPLIT_TASKLOOP,
7611 : : GFC_OMP_SPLIT_MASKED,
7612 : : GFC_OMP_SPLIT_NUM
7613 : : };
7614 : :
7615 : : enum
7616 : : {
7617 : : GFC_OMP_MASK_SIMD = (1 << GFC_OMP_SPLIT_SIMD),
7618 : : GFC_OMP_MASK_DO = (1 << GFC_OMP_SPLIT_DO),
7619 : : GFC_OMP_MASK_PARALLEL = (1 << GFC_OMP_SPLIT_PARALLEL),
7620 : : GFC_OMP_MASK_DISTRIBUTE = (1 << GFC_OMP_SPLIT_DISTRIBUTE),
7621 : : GFC_OMP_MASK_TEAMS = (1 << GFC_OMP_SPLIT_TEAMS),
7622 : : GFC_OMP_MASK_TARGET = (1 << GFC_OMP_SPLIT_TARGET),
7623 : : GFC_OMP_MASK_TASKLOOP = (1 << GFC_OMP_SPLIT_TASKLOOP),
7624 : : GFC_OMP_MASK_MASKED = (1 << GFC_OMP_SPLIT_MASKED)
7625 : : };
7626 : :
7627 : : /* If a var is in lastprivate/firstprivate/reduction but not in a
7628 : : data mapping/sharing clause, add it to 'map(tofrom:' if is_target
7629 : : and to 'shared' otherwise. */
7630 : : static void
7631 : 2514 : gfc_add_clause_implicitly (gfc_omp_clauses *clauses_out,
7632 : : gfc_omp_clauses *clauses_in,
7633 : : bool is_target, bool is_parallel_do)
7634 : : {
7635 : 2514 : int clauselist_to_add = is_target ? OMP_LIST_MAP : OMP_LIST_SHARED;
7636 : 2514 : gfc_omp_namelist *tail = NULL;
7637 : 15084 : for (int i = 0; i < 5; ++i)
7638 : : {
7639 : 12570 : gfc_omp_namelist *n;
7640 : 12570 : switch (i)
7641 : : {
7642 : 2514 : case 0: n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE]; break;
7643 : 2514 : case 1: n = clauses_in->lists[OMP_LIST_LASTPRIVATE]; break;
7644 : 2514 : case 2: n = clauses_in->lists[OMP_LIST_REDUCTION]; break;
7645 : 2514 : case 3: n = clauses_in->lists[OMP_LIST_REDUCTION_INSCAN]; break;
7646 : 2514 : case 4: n = clauses_in->lists[OMP_LIST_REDUCTION_TASK]; break;
7647 : : default: gcc_unreachable ();
7648 : : }
7649 : 15906 : for (; n != NULL; n = n->next)
7650 : : {
7651 : : gfc_omp_namelist *n2, **n_firstp = NULL, **n_lastp = NULL;
7652 : 20657 : for (int j = 0; j < 6; ++j)
7653 : : {
7654 : 18188 : gfc_omp_namelist **n2ref = NULL, *prev2 = NULL;
7655 : 18188 : switch (j)
7656 : : {
7657 : 3336 : case 0:
7658 : 3336 : n2ref = &clauses_out->lists[clauselist_to_add];
7659 : 3336 : break;
7660 : 3300 : case 1:
7661 : 3300 : n2ref = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
7662 : 3300 : break;
7663 : 3300 : case 2:
7664 : 3300 : if (is_target)
7665 : 255 : n2ref = &clauses_in->lists[OMP_LIST_LASTPRIVATE];
7666 : : else
7667 : 3045 : n2ref = &clauses_out->lists[OMP_LIST_LASTPRIVATE];
7668 : : break;
7669 : 3300 : case 3: n2ref = &clauses_out->lists[OMP_LIST_REDUCTION]; break;
7670 : 2476 : case 4:
7671 : 2476 : n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_INSCAN];
7672 : 2476 : break;
7673 : 2476 : case 5:
7674 : 2476 : n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_TASK];
7675 : 2476 : break;
7676 : : default: gcc_unreachable ();
7677 : : }
7678 : 28462 : for (n2 = *n2ref; n2 != NULL; prev2 = n2, n2 = n2->next)
7679 : 13535 : if (n2->sym == n->sym)
7680 : : break;
7681 : 18188 : if (n2)
7682 : : {
7683 : 3261 : if (j == 0 /* clauselist_to_add */)
7684 : : break; /* Already present. */
7685 : 3225 : if (j == 1 /* OMP_LIST_FIRSTPRIVATE */)
7686 : : {
7687 : 1128 : n_firstp = prev2 ? &prev2->next : n2ref;
7688 : 1128 : continue;
7689 : : }
7690 : 2097 : if (j == 2 /* OMP_LIST_LASTPRIVATE */)
7691 : : {
7692 : 1266 : n_lastp = prev2 ? &prev2->next : n2ref;
7693 : 1266 : continue;
7694 : : }
7695 : : break;
7696 : : }
7697 : : }
7698 : 3336 : if (n_firstp && n_lastp)
7699 : : {
7700 : : /* For parallel do, GCC puts firstprivate/lastprivate
7701 : : on the parallel. */
7702 : 283 : if (is_parallel_do)
7703 : 280 : continue;
7704 : 3 : *n_firstp = (*n_firstp)->next;
7705 : 3 : if (!is_target)
7706 : 0 : *n_lastp = (*n_lastp)->next;
7707 : : }
7708 : 3053 : else if (is_target && n_lastp)
7709 : : ;
7710 : 2998 : else if (n2 || n_firstp || n_lastp)
7711 : 2640 : continue;
7712 : 416 : if (clauses_out->lists[clauselist_to_add]
7713 : 305 : && (clauses_out->lists[clauselist_to_add]
7714 : 305 : == clauses_in->lists[clauselist_to_add]))
7715 : : {
7716 : : gfc_omp_namelist *p = NULL;
7717 : 421 : for (n2 = clauses_in->lists[clauselist_to_add]; n2; n2 = n2->next)
7718 : : {
7719 : 273 : if (p)
7720 : : {
7721 : 125 : p->next = gfc_get_omp_namelist ();
7722 : 125 : p = p->next;
7723 : : }
7724 : : else
7725 : : {
7726 : 148 : p = gfc_get_omp_namelist ();
7727 : 148 : clauses_out->lists[clauselist_to_add] = p;
7728 : : }
7729 : 273 : *p = *n2;
7730 : : }
7731 : : }
7732 : 416 : if (!tail)
7733 : : {
7734 : 287 : tail = clauses_out->lists[clauselist_to_add];
7735 : 412 : for (; tail && tail->next; tail = tail->next)
7736 : : ;
7737 : : }
7738 : 416 : n2 = gfc_get_omp_namelist ();
7739 : 416 : n2->where = n->where;
7740 : 416 : n2->sym = n->sym;
7741 : 416 : if (is_target)
7742 : 119 : n2->u.map.op = OMP_MAP_TOFROM;
7743 : 416 : if (tail)
7744 : : {
7745 : 305 : tail->next = n2;
7746 : 305 : tail = n2;
7747 : : }
7748 : : else
7749 : 111 : clauses_out->lists[clauselist_to_add] = n2;
7750 : : }
7751 : : }
7752 : 2514 : }
7753 : :
7754 : : /* Kind of opposite to above, add firstprivate to CLAUSES_OUT if it is mapped
7755 : : in CLAUSES_IN's FIRSTPRIVATE list but not its MAP list. */
7756 : :
7757 : : static void
7758 : 336 : gfc_add_firstprivate_if_unmapped (gfc_omp_clauses *clauses_out,
7759 : : gfc_omp_clauses *clauses_in)
7760 : : {
7761 : 336 : gfc_omp_namelist *n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE];
7762 : 336 : gfc_omp_namelist **tail = NULL;
7763 : :
7764 : 486 : for (; n != NULL; n = n->next)
7765 : : {
7766 : 150 : gfc_omp_namelist *n2 = clauses_out->lists[OMP_LIST_MAP];
7767 : 192 : for (; n2 != NULL; n2 = n2->next)
7768 : 53 : if (n->sym == n2->sym)
7769 : : break;
7770 : 150 : if (n2 == NULL)
7771 : : {
7772 : 139 : gfc_omp_namelist *dup = gfc_get_omp_namelist ();
7773 : 139 : *dup = *n;
7774 : 139 : dup->next = NULL;
7775 : 139 : if (!tail)
7776 : : {
7777 : 76 : tail = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
7778 : 76 : while (*tail && (*tail)->next)
7779 : 0 : tail = &(*tail)->next;
7780 : : }
7781 : 139 : *tail = dup;
7782 : 139 : tail = &(*tail)->next;
7783 : : }
7784 : : }
7785 : 336 : }
7786 : :
7787 : : static void
7788 : 4055 : gfc_free_split_omp_clauses (gfc_code *code, gfc_omp_clauses *clausesa)
7789 : : {
7790 : 36495 : for (int i = 0; i < GFC_OMP_SPLIT_NUM; ++i)
7791 : 1265160 : for (int j = 0; j < OMP_LIST_NUM; ++j)
7792 : 1232720 : if (clausesa[i].lists[j] && clausesa[i].lists[j] != code->ext.omp_clauses->lists[j])
7793 : 1397 : for (gfc_omp_namelist *n = clausesa[i].lists[j]; n;)
7794 : : {
7795 : 956 : gfc_omp_namelist *p = n;
7796 : 956 : n = n->next;
7797 : 956 : free (p);
7798 : : }
7799 : 4055 : }
7800 : :
7801 : : static void
7802 : 4055 : gfc_split_omp_clauses (gfc_code *code,
7803 : : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM])
7804 : : {
7805 : 4055 : int mask = 0, innermost = 0;
7806 : 4055 : bool is_loop = false;
7807 : 4055 : memset (clausesa, 0, GFC_OMP_SPLIT_NUM * sizeof (gfc_omp_clauses));
7808 : 4055 : switch (code->op)
7809 : : {
7810 : : case EXEC_OMP_DISTRIBUTE:
7811 : : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7812 : : break;
7813 : 38 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
7814 : 38 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7815 : 38 : innermost = GFC_OMP_SPLIT_DO;
7816 : 38 : break;
7817 : 28 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
7818 : 28 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL
7819 : : | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7820 : 28 : innermost = GFC_OMP_SPLIT_SIMD;
7821 : 28 : break;
7822 : 47 : case EXEC_OMP_DISTRIBUTE_SIMD:
7823 : 47 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7824 : 47 : innermost = GFC_OMP_SPLIT_SIMD;
7825 : 47 : break;
7826 : 0 : case EXEC_OMP_DO:
7827 : 0 : case EXEC_OMP_LOOP:
7828 : 0 : innermost = GFC_OMP_SPLIT_DO;
7829 : 0 : break;
7830 : 126 : case EXEC_OMP_DO_SIMD:
7831 : 126 : mask = GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7832 : 126 : innermost = GFC_OMP_SPLIT_SIMD;
7833 : 126 : break;
7834 : 0 : case EXEC_OMP_PARALLEL:
7835 : 0 : innermost = GFC_OMP_SPLIT_PARALLEL;
7836 : 0 : break;
7837 : 1102 : case EXEC_OMP_PARALLEL_DO:
7838 : 1102 : case EXEC_OMP_PARALLEL_LOOP:
7839 : 1102 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7840 : 1102 : innermost = GFC_OMP_SPLIT_DO;
7841 : 1102 : break;
7842 : 285 : case EXEC_OMP_PARALLEL_DO_SIMD:
7843 : 285 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7844 : 285 : innermost = GFC_OMP_SPLIT_SIMD;
7845 : 285 : break;
7846 : 11 : case EXEC_OMP_PARALLEL_MASKED:
7847 : 11 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED;
7848 : 11 : innermost = GFC_OMP_SPLIT_MASKED;
7849 : 11 : break;
7850 : 14 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
7851 : 14 : mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
7852 : : | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
7853 : 14 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7854 : 14 : break;
7855 : 20 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
7856 : 20 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7857 : 20 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7858 : 20 : break;
7859 : 24 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
7860 : 24 : mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
7861 : : | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
7862 : 24 : innermost = GFC_OMP_SPLIT_SIMD;
7863 : 24 : break;
7864 : 28 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
7865 : 28 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7866 : 28 : innermost = GFC_OMP_SPLIT_SIMD;
7867 : 28 : break;
7868 : 0 : case EXEC_OMP_SIMD:
7869 : 0 : innermost = GFC_OMP_SPLIT_SIMD;
7870 : 0 : break;
7871 : 1651 : case EXEC_OMP_TARGET:
7872 : 1651 : innermost = GFC_OMP_SPLIT_TARGET;
7873 : 1651 : break;
7874 : 20 : case EXEC_OMP_TARGET_PARALLEL:
7875 : 20 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL;
7876 : 20 : innermost = GFC_OMP_SPLIT_PARALLEL;
7877 : 20 : break;
7878 : 79 : case EXEC_OMP_TARGET_PARALLEL_DO:
7879 : 79 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
7880 : 79 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7881 : 79 : innermost = GFC_OMP_SPLIT_DO;
7882 : 79 : break;
7883 : 15 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
7884 : 15 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO
7885 : : | GFC_OMP_MASK_SIMD;
7886 : 15 : innermost = GFC_OMP_SPLIT_SIMD;
7887 : 15 : break;
7888 : 26 : case EXEC_OMP_TARGET_SIMD:
7889 : 26 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_SIMD;
7890 : 26 : innermost = GFC_OMP_SPLIT_SIMD;
7891 : 26 : break;
7892 : 69 : case EXEC_OMP_TARGET_TEAMS:
7893 : 69 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS;
7894 : 69 : innermost = GFC_OMP_SPLIT_TEAMS;
7895 : 69 : break;
7896 : 14 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
7897 : 14 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
7898 : : | GFC_OMP_MASK_DISTRIBUTE;
7899 : 14 : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7900 : 14 : break;
7901 : 56 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
7902 : 56 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7903 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7904 : 56 : innermost = GFC_OMP_SPLIT_DO;
7905 : 56 : break;
7906 : 29 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
7907 : 29 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7908 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7909 : 29 : innermost = GFC_OMP_SPLIT_SIMD;
7910 : 29 : break;
7911 : 16 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
7912 : 16 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
7913 : : | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7914 : 16 : innermost = GFC_OMP_SPLIT_SIMD;
7915 : 16 : break;
7916 : 12 : case EXEC_OMP_TARGET_TEAMS_LOOP:
7917 : 12 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
7918 : 12 : innermost = GFC_OMP_SPLIT_DO;
7919 : 12 : break;
7920 : 8 : case EXEC_OMP_MASKED_TASKLOOP:
7921 : 8 : mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP;
7922 : 8 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7923 : 8 : break;
7924 : 0 : case EXEC_OMP_MASTER_TASKLOOP:
7925 : 0 : case EXEC_OMP_TASKLOOP:
7926 : 0 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7927 : 0 : break;
7928 : 22 : case EXEC_OMP_MASKED_TASKLOOP_SIMD:
7929 : 22 : mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7930 : 22 : innermost = GFC_OMP_SPLIT_SIMD;
7931 : 22 : break;
7932 : 46 : case EXEC_OMP_MASTER_TASKLOOP_SIMD:
7933 : 46 : case EXEC_OMP_TASKLOOP_SIMD:
7934 : 46 : mask = GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7935 : 46 : innermost = GFC_OMP_SPLIT_SIMD;
7936 : 46 : break;
7937 : 124 : case EXEC_OMP_TEAMS:
7938 : 124 : innermost = GFC_OMP_SPLIT_TEAMS;
7939 : 124 : break;
7940 : 14 : case EXEC_OMP_TEAMS_DISTRIBUTE:
7941 : 14 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE;
7942 : 14 : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7943 : 14 : break;
7944 : 32 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
7945 : 32 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7946 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7947 : 32 : innermost = GFC_OMP_SPLIT_DO;
7948 : 32 : break;
7949 : 56 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
7950 : 56 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7951 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7952 : 56 : innermost = GFC_OMP_SPLIT_SIMD;
7953 : 56 : break;
7954 : 37 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
7955 : 37 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7956 : 37 : innermost = GFC_OMP_SPLIT_SIMD;
7957 : 37 : break;
7958 : : case EXEC_OMP_TEAMS_LOOP:
7959 : : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
7960 : : innermost = GFC_OMP_SPLIT_DO;
7961 : : break;
7962 : 0 : default:
7963 : 0 : gcc_unreachable ();
7964 : : }
7965 : 4049 : if (mask == 0)
7966 : : {
7967 : 1775 : clausesa[innermost] = *code->ext.omp_clauses;
7968 : 1775 : return;
7969 : : }
7970 : : /* Loops are similar to DO but still a bit different. */
7971 : 2280 : switch (code->op)
7972 : : {
7973 : 53 : case EXEC_OMP_LOOP:
7974 : 53 : case EXEC_OMP_PARALLEL_LOOP:
7975 : 53 : case EXEC_OMP_TEAMS_LOOP:
7976 : 53 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
7977 : 53 : case EXEC_OMP_TARGET_TEAMS_LOOP:
7978 : 53 : is_loop = true;
7979 : 2280 : default:
7980 : 2280 : break;
7981 : : }
7982 : 2280 : if (code->ext.omp_clauses != NULL)
7983 : : {
7984 : 2280 : if (mask & GFC_OMP_MASK_TARGET)
7985 : : {
7986 : : /* First the clauses that are unique to some constructs. */
7987 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_MAP]
7988 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_MAP];
7989 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IS_DEVICE_PTR]
7990 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_IS_DEVICE_PTR];
7991 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_HAS_DEVICE_ADDR]
7992 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_HAS_DEVICE_ADDR];
7993 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].device
7994 : 336 : = code->ext.omp_clauses->device;
7995 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].thread_limit
7996 : 336 : = code->ext.omp_clauses->thread_limit;
7997 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_USES_ALLOCATORS]
7998 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_USES_ALLOCATORS];
7999 : 2352 : for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
8000 : 2016 : clausesa[GFC_OMP_SPLIT_TARGET].defaultmap[i]
8001 : 2016 : = code->ext.omp_clauses->defaultmap[i];
8002 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].if_exprs[OMP_IF_TARGET]
8003 : 336 : = code->ext.omp_clauses->if_exprs[OMP_IF_TARGET];
8004 : : /* And this is copied to all. */
8005 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].if_expr
8006 : 336 : = code->ext.omp_clauses->if_expr;
8007 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].nowait
8008 : 336 : = code->ext.omp_clauses->nowait;
8009 : : }
8010 : 2280 : if (mask & GFC_OMP_MASK_TEAMS)
8011 : : {
8012 : : /* First the clauses that are unique to some constructs. */
8013 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower
8014 : 341 : = code->ext.omp_clauses->num_teams_lower;
8015 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
8016 : 341 : = code->ext.omp_clauses->num_teams_upper;
8017 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit
8018 : 341 : = code->ext.omp_clauses->thread_limit;
8019 : : /* Shared and default clauses are allowed on parallel, teams
8020 : : and taskloop. */
8021 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_SHARED]
8022 : 341 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8023 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].default_sharing
8024 : 341 : = code->ext.omp_clauses->default_sharing;
8025 : : }
8026 : 2280 : if (mask & GFC_OMP_MASK_DISTRIBUTE)
8027 : : {
8028 : : /* First the clauses that are unique to some constructs. */
8029 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_sched_kind
8030 : 367 : = code->ext.omp_clauses->dist_sched_kind;
8031 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_chunk_size
8032 : 367 : = code->ext.omp_clauses->dist_chunk_size;
8033 : : /* Duplicate collapse. */
8034 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].collapse
8035 : 367 : = code->ext.omp_clauses->collapse;
8036 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_concurrent
8037 : 367 : = code->ext.omp_clauses->order_concurrent;
8038 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_unconstrained
8039 : 367 : = code->ext.omp_clauses->order_unconstrained;
8040 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_reproducible
8041 : 367 : = code->ext.omp_clauses->order_reproducible;
8042 : : }
8043 : 2280 : if (mask & GFC_OMP_MASK_PARALLEL)
8044 : : {
8045 : : /* First the clauses that are unique to some constructs. */
8046 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_COPYIN]
8047 : 1837 : = code->ext.omp_clauses->lists[OMP_LIST_COPYIN];
8048 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].num_threads
8049 : 1837 : = code->ext.omp_clauses->num_threads;
8050 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].proc_bind
8051 : 1837 : = code->ext.omp_clauses->proc_bind;
8052 : : /* Shared and default clauses are allowed on parallel, teams
8053 : : and taskloop. */
8054 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_SHARED]
8055 : 1837 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8056 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].default_sharing
8057 : 1837 : = code->ext.omp_clauses->default_sharing;
8058 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].if_exprs[OMP_IF_PARALLEL]
8059 : 1837 : = code->ext.omp_clauses->if_exprs[OMP_IF_PARALLEL];
8060 : : /* And this is copied to all. */
8061 : 1837 : clausesa[GFC_OMP_SPLIT_PARALLEL].if_expr
8062 : 1837 : = code->ext.omp_clauses->if_expr;
8063 : : }
8064 : 2280 : if (mask & GFC_OMP_MASK_MASKED)
8065 : 79 : clausesa[GFC_OMP_SPLIT_MASKED].filter = code->ext.omp_clauses->filter;
8066 : 2280 : if ((mask & GFC_OMP_MASK_DO) && !is_loop)
8067 : : {
8068 : : /* First the clauses that are unique to some constructs. */
8069 : 1811 : clausesa[GFC_OMP_SPLIT_DO].ordered
8070 : 1811 : = code->ext.omp_clauses->ordered;
8071 : 1811 : clausesa[GFC_OMP_SPLIT_DO].orderedc
8072 : 1811 : = code->ext.omp_clauses->orderedc;
8073 : 1811 : clausesa[GFC_OMP_SPLIT_DO].sched_kind
8074 : 1811 : = code->ext.omp_clauses->sched_kind;
8075 : 1811 : if (innermost == GFC_OMP_SPLIT_SIMD)
8076 : 539 : clausesa[GFC_OMP_SPLIT_DO].sched_simd
8077 : 539 : = code->ext.omp_clauses->sched_simd;
8078 : 1811 : clausesa[GFC_OMP_SPLIT_DO].sched_monotonic
8079 : 1811 : = code->ext.omp_clauses->sched_monotonic;
8080 : 1811 : clausesa[GFC_OMP_SPLIT_DO].sched_nonmonotonic
8081 : 1811 : = code->ext.omp_clauses->sched_nonmonotonic;
8082 : 1811 : clausesa[GFC_OMP_SPLIT_DO].chunk_size
8083 : 1811 : = code->ext.omp_clauses->chunk_size;
8084 : 1811 : clausesa[GFC_OMP_SPLIT_DO].nowait
8085 : 1811 : = code->ext.omp_clauses->nowait;
8086 : : }
8087 : 1864 : if (mask & GFC_OMP_MASK_DO)
8088 : : {
8089 : 1864 : clausesa[GFC_OMP_SPLIT_DO].bind
8090 : 1864 : = code->ext.omp_clauses->bind;
8091 : : /* Duplicate collapse. */
8092 : 1864 : clausesa[GFC_OMP_SPLIT_DO].collapse
8093 : 1864 : = code->ext.omp_clauses->collapse;
8094 : 1864 : clausesa[GFC_OMP_SPLIT_DO].order_concurrent
8095 : 1864 : = code->ext.omp_clauses->order_concurrent;
8096 : 1864 : clausesa[GFC_OMP_SPLIT_DO].order_unconstrained
8097 : 1864 : = code->ext.omp_clauses->order_unconstrained;
8098 : 1864 : clausesa[GFC_OMP_SPLIT_DO].order_reproducible
8099 : 1864 : = code->ext.omp_clauses->order_reproducible;
8100 : : }
8101 : 2280 : if (mask & GFC_OMP_MASK_SIMD)
8102 : : {
8103 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].safelen_expr
8104 : 819 : = code->ext.omp_clauses->safelen_expr;
8105 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].simdlen_expr
8106 : 819 : = code->ext.omp_clauses->simdlen_expr;
8107 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_ALIGNED]
8108 : 819 : = code->ext.omp_clauses->lists[OMP_LIST_ALIGNED];
8109 : : /* Duplicate collapse. */
8110 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].collapse
8111 : 819 : = code->ext.omp_clauses->collapse;
8112 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].if_exprs[OMP_IF_SIMD]
8113 : 819 : = code->ext.omp_clauses->if_exprs[OMP_IF_SIMD];
8114 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_concurrent
8115 : 819 : = code->ext.omp_clauses->order_concurrent;
8116 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_unconstrained
8117 : 819 : = code->ext.omp_clauses->order_unconstrained;
8118 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_reproducible
8119 : 819 : = code->ext.omp_clauses->order_reproducible;
8120 : : /* And this is copied to all. */
8121 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].if_expr
8122 : 819 : = code->ext.omp_clauses->if_expr;
8123 : : }
8124 : 2280 : if (mask & GFC_OMP_MASK_TASKLOOP)
8125 : : {
8126 : : /* First the clauses that are unique to some constructs. */
8127 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].nogroup
8128 : 162 : = code->ext.omp_clauses->nogroup;
8129 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize
8130 : 162 : = code->ext.omp_clauses->grainsize;
8131 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize_strict
8132 : 162 : = code->ext.omp_clauses->grainsize_strict;
8133 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks
8134 : 162 : = code->ext.omp_clauses->num_tasks;
8135 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks_strict
8136 : 162 : = code->ext.omp_clauses->num_tasks_strict;
8137 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].priority
8138 : 162 : = code->ext.omp_clauses->priority;
8139 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].final_expr
8140 : 162 : = code->ext.omp_clauses->final_expr;
8141 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].untied
8142 : 162 : = code->ext.omp_clauses->untied;
8143 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].mergeable
8144 : 162 : = code->ext.omp_clauses->mergeable;
8145 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].if_exprs[OMP_IF_TASKLOOP]
8146 : 162 : = code->ext.omp_clauses->if_exprs[OMP_IF_TASKLOOP];
8147 : : /* And this is copied to all. */
8148 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].if_expr
8149 : 162 : = code->ext.omp_clauses->if_expr;
8150 : : /* Shared and default clauses are allowed on parallel, teams
8151 : : and taskloop. */
8152 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_SHARED]
8153 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8154 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].default_sharing
8155 : 162 : = code->ext.omp_clauses->default_sharing;
8156 : : /* Duplicate collapse. */
8157 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].collapse
8158 : 162 : = code->ext.omp_clauses->collapse;
8159 : : }
8160 : : /* Private clause is supported on all constructs but master/masked,
8161 : : it is enough to put it on the innermost one except for master/masked. For
8162 : : !$ omp parallel do put it on parallel though,
8163 : : as that's what we did for OpenMP 3.1. */
8164 : 2280 : clausesa[((innermost == GFC_OMP_SPLIT_DO && !is_loop)
8165 : : || code->op == EXEC_OMP_PARALLEL_MASTER
8166 : 1008 : || code->op == EXEC_OMP_PARALLEL_MASKED)
8167 : 997 : ? (int) GFC_OMP_SPLIT_PARALLEL
8168 : 3277 : : innermost].lists[OMP_LIST_PRIVATE]
8169 : 2280 : = code->ext.omp_clauses->lists[OMP_LIST_PRIVATE];
8170 : : /* Firstprivate clause is supported on all constructs but
8171 : : simd and masked/master. Put it on the outermost of those and duplicate
8172 : : on parallel and teams. */
8173 : 2280 : if (mask & GFC_OMP_MASK_TARGET)
8174 : 336 : gfc_add_firstprivate_if_unmapped (&clausesa[GFC_OMP_SPLIT_TARGET],
8175 : : code->ext.omp_clauses);
8176 : 2280 : if (mask & GFC_OMP_MASK_TEAMS)
8177 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_FIRSTPRIVATE]
8178 : 341 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8179 : 1939 : else if (mask & GFC_OMP_MASK_DISTRIBUTE)
8180 : 113 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_FIRSTPRIVATE]
8181 : 113 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8182 : 2280 : if (mask & GFC_OMP_MASK_TASKLOOP)
8183 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_FIRSTPRIVATE]
8184 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8185 : 2280 : if ((mask & GFC_OMP_MASK_PARALLEL)
8186 : 1837 : && !(mask & GFC_OMP_MASK_TASKLOOP))
8187 : 1751 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_FIRSTPRIVATE]
8188 : 1751 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8189 : 529 : else if ((mask & GFC_OMP_MASK_DO) && !is_loop)
8190 : 126 : clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_FIRSTPRIVATE]
8191 : 126 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8192 : : /* Lastprivate is allowed on distribute, do, simd, taskloop and loop.
8193 : : In parallel do{, simd} we actually want to put it on
8194 : : parallel rather than do. */
8195 : 2280 : if (mask & GFC_OMP_MASK_DISTRIBUTE)
8196 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_LASTPRIVATE]
8197 : 367 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8198 : 2280 : if (mask & GFC_OMP_MASK_TASKLOOP)
8199 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_LASTPRIVATE]
8200 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8201 : 2280 : if ((mask & GFC_OMP_MASK_PARALLEL) && !is_loop
8202 : 1802 : && !(mask & GFC_OMP_MASK_TASKLOOP))
8203 : 1716 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_LASTPRIVATE]
8204 : 1716 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8205 : 564 : else if (mask & GFC_OMP_MASK_DO)
8206 : 179 : clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_LASTPRIVATE]
8207 : 179 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8208 : 2280 : if (mask & GFC_OMP_MASK_SIMD)
8209 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_LASTPRIVATE]
8210 : 819 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8211 : : /* Reduction is allowed on simd, do, parallel, teams, taskloop, and loop.
8212 : : Duplicate it on all of them, but
8213 : : - omit on do if parallel is present;
8214 : : - omit on task and parallel if loop is present;
8215 : : additionally, inscan applies to do/simd only. */
8216 : 9120 : for (int i = OMP_LIST_REDUCTION; i <= OMP_LIST_REDUCTION_TASK; i++)
8217 : : {
8218 : 6840 : if (mask & GFC_OMP_MASK_TASKLOOP
8219 : 486 : && i != OMP_LIST_REDUCTION_INSCAN)
8220 : 324 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[i]
8221 : 324 : = code->ext.omp_clauses->lists[i];
8222 : 6840 : if (mask & GFC_OMP_MASK_TEAMS
8223 : 1023 : && i != OMP_LIST_REDUCTION_INSCAN
8224 : 1023 : && !is_loop)
8225 : 646 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[i]
8226 : 646 : = code->ext.omp_clauses->lists[i];
8227 : 6840 : if (mask & GFC_OMP_MASK_PARALLEL
8228 : 5511 : && i != OMP_LIST_REDUCTION_INSCAN
8229 : 3674 : && !(mask & GFC_OMP_MASK_TASKLOOP)
8230 : 3502 : && !is_loop)
8231 : 3432 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[i]
8232 : 3432 : = code->ext.omp_clauses->lists[i];
8233 : 3408 : else if (mask & GFC_OMP_MASK_DO)
8234 : 2222 : clausesa[GFC_OMP_SPLIT_DO].lists[i]
8235 : 2222 : = code->ext.omp_clauses->lists[i];
8236 : 6840 : if (mask & GFC_OMP_MASK_SIMD)
8237 : 2457 : clausesa[GFC_OMP_SPLIT_SIMD].lists[i]
8238 : 2457 : = code->ext.omp_clauses->lists[i];
8239 : : }
8240 : 2280 : if (mask & GFC_OMP_MASK_TARGET)
8241 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IN_REDUCTION]
8242 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
8243 : 2280 : if (mask & GFC_OMP_MASK_TASKLOOP)
8244 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_IN_REDUCTION]
8245 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
8246 : : /* Linear clause is supported on do and simd,
8247 : : put it on the innermost one. */
8248 : 2280 : clausesa[innermost].lists[OMP_LIST_LINEAR]
8249 : 2280 : = code->ext.omp_clauses->lists[OMP_LIST_LINEAR];
8250 : : }
8251 : : /* Propagate firstprivate/lastprivate/reduction vars to
8252 : : shared (parallel, teams) and map-tofrom (target). */
8253 : 2280 : if (mask & GFC_OMP_MASK_TARGET)
8254 : 336 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TARGET],
8255 : : code->ext.omp_clauses, true, false);
8256 : 2280 : if ((mask & GFC_OMP_MASK_PARALLEL) && innermost != GFC_OMP_MASK_PARALLEL)
8257 : 1837 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_PARALLEL],
8258 : : code->ext.omp_clauses, false,
8259 : 1837 : mask & GFC_OMP_MASK_DO);
8260 : 2280 : if (mask & GFC_OMP_MASK_TEAMS && innermost != GFC_OMP_MASK_TEAMS)
8261 : 341 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TEAMS],
8262 : : code->ext.omp_clauses, false, false);
8263 : 2280 : if (((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
8264 : : == (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
8265 : 1720 : && !is_loop)
8266 : 1685 : clausesa[GFC_OMP_SPLIT_DO].nowait = true;
8267 : :
8268 : : /* Distribute allocate clause to do, parallel, distribute, teams, target
8269 : : and taskloop. The code below iterates over variables in the
8270 : : allocate list and checks if that available is also in any
8271 : : privatization clause on those construct. If yes, then we add it
8272 : : to the list of 'allocate'ed variables for that construct. If a
8273 : : variable is found in none of them then we issue an error. */
8274 : :
8275 : 2280 : if (code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE])
8276 : : {
8277 : : gfc_omp_namelist *alloc_nl, *priv_nl;
8278 : : gfc_omp_namelist *tails[GFC_OMP_SPLIT_NUM];
8279 : 104 : for (alloc_nl = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
8280 : 181 : alloc_nl; alloc_nl = alloc_nl->next)
8281 : : {
8282 : : bool found = false;
8283 : 728 : for (int i = GFC_OMP_SPLIT_DO; i <= GFC_OMP_SPLIT_TASKLOOP; i++)
8284 : : {
8285 : : gfc_omp_namelist *p;
8286 : : int list;
8287 : 24336 : for (list = 0; list < OMP_LIST_NUM; list++)
8288 : : {
8289 : 23712 : switch (list)
8290 : : {
8291 : 5616 : case OMP_LIST_PRIVATE:
8292 : 5616 : case OMP_LIST_FIRSTPRIVATE:
8293 : 5616 : case OMP_LIST_LASTPRIVATE:
8294 : 5616 : case OMP_LIST_REDUCTION:
8295 : 5616 : case OMP_LIST_REDUCTION_INSCAN:
8296 : 5616 : case OMP_LIST_REDUCTION_TASK:
8297 : 5616 : case OMP_LIST_IN_REDUCTION:
8298 : 5616 : case OMP_LIST_TASK_REDUCTION:
8299 : 5616 : case OMP_LIST_LINEAR:
8300 : 6092 : for (priv_nl = clausesa[i].lists[list]; priv_nl;
8301 : 476 : priv_nl = priv_nl->next)
8302 : 476 : if (alloc_nl->sym == priv_nl->sym)
8303 : : {
8304 : 131 : found = true;
8305 : 131 : p = gfc_get_omp_namelist ();
8306 : 131 : p->sym = alloc_nl->sym;
8307 : 131 : p->expr = alloc_nl->expr;
8308 : 131 : p->u.align = alloc_nl->u.align;
8309 : 131 : p->u2.allocator = alloc_nl->u2.allocator;
8310 : 131 : p->where = alloc_nl->where;
8311 : 131 : if (clausesa[i].lists[OMP_LIST_ALLOCATE] == NULL)
8312 : : {
8313 : 109 : clausesa[i].lists[OMP_LIST_ALLOCATE] = p;
8314 : 109 : tails[i] = p;
8315 : : }
8316 : : else
8317 : : {
8318 : 22 : tails[i]->next = p;
8319 : 22 : tails[i] = tails[i]->next;
8320 : : }
8321 : : }
8322 : : break;
8323 : : default:
8324 : : break;
8325 : : }
8326 : : }
8327 : : }
8328 : 104 : if (!found)
8329 : 1 : gfc_error ("%qs specified in %<allocate%> clause at %L but not "
8330 : : "in an explicit privatization clause",
8331 : 1 : alloc_nl->sym->name, &alloc_nl->where);
8332 : : }
8333 : : }
8334 : : }
8335 : :
8336 : : static tree
8337 : 539 : gfc_trans_omp_do_simd (gfc_code *code, stmtblock_t *pblock,
8338 : : gfc_omp_clauses *clausesa, tree omp_clauses)
8339 : : {
8340 : 539 : stmtblock_t block;
8341 : 539 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8342 : 539 : tree stmt, body, omp_do_clauses = NULL_TREE;
8343 : 539 : bool free_clausesa = false;
8344 : :
8345 : 539 : if (pblock == NULL)
8346 : 411 : gfc_start_block (&block);
8347 : : else
8348 : 128 : gfc_init_block (&block);
8349 : :
8350 : 539 : if (clausesa == NULL)
8351 : : {
8352 : 126 : clausesa = clausesa_buf;
8353 : 126 : gfc_split_omp_clauses (code, clausesa);
8354 : 126 : free_clausesa = true;
8355 : : }
8356 : 539 : if (flag_openmp)
8357 : 534 : omp_do_clauses
8358 : 534 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DO], code->loc);
8359 : 667 : body = gfc_trans_omp_do (code, EXEC_OMP_SIMD, pblock ? pblock : &block,
8360 : : &clausesa[GFC_OMP_SPLIT_SIMD], omp_clauses);
8361 : 539 : if (pblock == NULL)
8362 : : {
8363 : 411 : if (TREE_CODE (body) != BIND_EXPR)
8364 : 411 : body = build3_v (BIND_EXPR, NULL, body, poplevel (1, 0));
8365 : : else
8366 : 0 : poplevel (0, 0);
8367 : : }
8368 : 128 : else if (TREE_CODE (body) != BIND_EXPR)
8369 : 128 : body = build3_v (BIND_EXPR, NULL, body, NULL_TREE);
8370 : 539 : if (flag_openmp)
8371 : : {
8372 : 534 : stmt = make_node (OMP_FOR);
8373 : 534 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8374 : 534 : TREE_TYPE (stmt) = void_type_node;
8375 : 534 : OMP_FOR_BODY (stmt) = body;
8376 : 534 : OMP_FOR_CLAUSES (stmt) = omp_do_clauses;
8377 : : }
8378 : : else
8379 : : stmt = body;
8380 : 539 : gfc_add_expr_to_block (&block, stmt);
8381 : 539 : if (free_clausesa)
8382 : 126 : gfc_free_split_omp_clauses (code, clausesa);
8383 : 539 : return gfc_finish_block (&block);
8384 : : }
8385 : :
8386 : : static tree
8387 : 1307 : gfc_trans_omp_parallel_do (gfc_code *code, bool is_loop, stmtblock_t *pblock,
8388 : : gfc_omp_clauses *clausesa)
8389 : : {
8390 : 1307 : stmtblock_t block, *new_pblock = pblock;
8391 : 1307 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8392 : 1307 : tree stmt, omp_clauses = NULL_TREE;
8393 : 1307 : bool free_clausesa = false;
8394 : :
8395 : 1307 : if (pblock == NULL)
8396 : 1102 : gfc_start_block (&block);
8397 : : else
8398 : 205 : gfc_init_block (&block);
8399 : :
8400 : 1307 : if (clausesa == NULL)
8401 : : {
8402 : 1102 : clausesa = clausesa_buf;
8403 : 1102 : gfc_split_omp_clauses (code, clausesa);
8404 : 1102 : free_clausesa = true;
8405 : : }
8406 : 1307 : omp_clauses
8407 : 1307 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8408 : : code->loc);
8409 : 1307 : if (pblock == NULL)
8410 : : {
8411 : 1102 : if (!clausesa[GFC_OMP_SPLIT_DO].ordered
8412 : 1093 : && clausesa[GFC_OMP_SPLIT_DO].sched_kind != OMP_SCHED_STATIC)
8413 : : new_pblock = █
8414 : : else
8415 : 65 : pushlevel ();
8416 : : }
8417 : 2579 : stmt = gfc_trans_omp_do (code, is_loop ? EXEC_OMP_LOOP : EXEC_OMP_DO,
8418 : : new_pblock, &clausesa[GFC_OMP_SPLIT_DO],
8419 : : omp_clauses);
8420 : 1307 : if (pblock == NULL)
8421 : : {
8422 : 1102 : if (TREE_CODE (stmt) != BIND_EXPR)
8423 : 1086 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8424 : : else
8425 : 16 : poplevel (0, 0);
8426 : : }
8427 : 205 : else if (TREE_CODE (stmt) != BIND_EXPR)
8428 : 205 : stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
8429 : 1307 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8430 : : void_type_node, stmt, omp_clauses);
8431 : 1307 : OMP_PARALLEL_COMBINED (stmt) = 1;
8432 : 1307 : gfc_add_expr_to_block (&block, stmt);
8433 : 1307 : if (free_clausesa)
8434 : 1102 : gfc_free_split_omp_clauses (code, clausesa);
8435 : 1307 : return gfc_finish_block (&block);
8436 : : }
8437 : :
8438 : : static tree
8439 : 413 : gfc_trans_omp_parallel_do_simd (gfc_code *code, stmtblock_t *pblock,
8440 : : gfc_omp_clauses *clausesa)
8441 : : {
8442 : 413 : stmtblock_t block;
8443 : 413 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8444 : 413 : tree stmt, omp_clauses = NULL_TREE;
8445 : 413 : bool free_clausesa = false;
8446 : :
8447 : 413 : if (pblock == NULL)
8448 : 285 : gfc_start_block (&block);
8449 : : else
8450 : 128 : gfc_init_block (&block);
8451 : :
8452 : 413 : if (clausesa == NULL)
8453 : : {
8454 : 285 : clausesa = clausesa_buf;
8455 : 285 : gfc_split_omp_clauses (code, clausesa);
8456 : 285 : free_clausesa = true;
8457 : : }
8458 : 413 : if (flag_openmp)
8459 : 410 : omp_clauses
8460 : 410 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8461 : : code->loc);
8462 : 413 : if (pblock == NULL)
8463 : 285 : pushlevel ();
8464 : 413 : stmt = gfc_trans_omp_do_simd (code, pblock, clausesa, omp_clauses);
8465 : 413 : if (pblock == NULL)
8466 : : {
8467 : 285 : if (TREE_CODE (stmt) != BIND_EXPR)
8468 : 214 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8469 : : else
8470 : 71 : poplevel (0, 0);
8471 : : }
8472 : 128 : else if (TREE_CODE (stmt) != BIND_EXPR)
8473 : 128 : stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
8474 : 413 : if (flag_openmp)
8475 : : {
8476 : 410 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8477 : : void_type_node, stmt, omp_clauses);
8478 : 410 : OMP_PARALLEL_COMBINED (stmt) = 1;
8479 : : }
8480 : 413 : gfc_add_expr_to_block (&block, stmt);
8481 : 413 : if (free_clausesa)
8482 : 285 : gfc_free_split_omp_clauses (code, clausesa);
8483 : 413 : return gfc_finish_block (&block);
8484 : : }
8485 : :
8486 : : static tree
8487 : 54 : gfc_trans_omp_parallel_sections (gfc_code *code)
8488 : : {
8489 : 54 : stmtblock_t block;
8490 : 54 : gfc_omp_clauses section_clauses;
8491 : 54 : tree stmt, omp_clauses;
8492 : :
8493 : 54 : memset (§ion_clauses, 0, sizeof (section_clauses));
8494 : 54 : section_clauses.nowait = true;
8495 : :
8496 : 54 : gfc_start_block (&block);
8497 : 54 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8498 : : code->loc);
8499 : 54 : pushlevel ();
8500 : 54 : stmt = gfc_trans_omp_sections (code, §ion_clauses);
8501 : 54 : if (TREE_CODE (stmt) != BIND_EXPR)
8502 : 54 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8503 : : else
8504 : 0 : poplevel (0, 0);
8505 : 54 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8506 : : void_type_node, stmt, omp_clauses);
8507 : 54 : OMP_PARALLEL_COMBINED (stmt) = 1;
8508 : 54 : gfc_add_expr_to_block (&block, stmt);
8509 : 54 : return gfc_finish_block (&block);
8510 : : }
8511 : :
8512 : : static tree
8513 : 50 : gfc_trans_omp_parallel_workshare (gfc_code *code)
8514 : : {
8515 : 50 : stmtblock_t block;
8516 : 50 : gfc_omp_clauses workshare_clauses;
8517 : 50 : tree stmt, omp_clauses;
8518 : :
8519 : 50 : memset (&workshare_clauses, 0, sizeof (workshare_clauses));
8520 : 50 : workshare_clauses.nowait = true;
8521 : :
8522 : 50 : gfc_start_block (&block);
8523 : 50 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8524 : : code->loc);
8525 : 50 : pushlevel ();
8526 : 50 : stmt = gfc_trans_omp_workshare (code, &workshare_clauses);
8527 : 50 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8528 : 50 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8529 : : void_type_node, stmt, omp_clauses);
8530 : 50 : OMP_PARALLEL_COMBINED (stmt) = 1;
8531 : 50 : gfc_add_expr_to_block (&block, stmt);
8532 : 50 : return gfc_finish_block (&block);
8533 : : }
8534 : :
8535 : : static tree
8536 : 53 : gfc_trans_omp_scope (gfc_code *code)
8537 : : {
8538 : 53 : stmtblock_t block;
8539 : 53 : tree body = gfc_trans_code (code->block->next);
8540 : 53 : if (IS_EMPTY_STMT (body))
8541 : : return body;
8542 : 51 : gfc_start_block (&block);
8543 : 51 : tree omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8544 : : code->loc);
8545 : 51 : tree stmt = make_node (OMP_SCOPE);
8546 : 51 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8547 : 51 : TREE_TYPE (stmt) = void_type_node;
8548 : 51 : OMP_SCOPE_BODY (stmt) = body;
8549 : 51 : OMP_SCOPE_CLAUSES (stmt) = omp_clauses;
8550 : 51 : gfc_add_expr_to_block (&block, stmt);
8551 : 51 : return gfc_finish_block (&block);
8552 : : }
8553 : :
8554 : : static tree
8555 : 129 : gfc_trans_omp_sections (gfc_code *code, gfc_omp_clauses *clauses)
8556 : : {
8557 : 129 : stmtblock_t block, body;
8558 : 129 : tree omp_clauses, stmt;
8559 : 129 : bool has_lastprivate = clauses->lists[OMP_LIST_LASTPRIVATE] != NULL;
8560 : 129 : location_t loc = gfc_get_location (&code->loc);
8561 : :
8562 : 129 : gfc_start_block (&block);
8563 : :
8564 : 129 : omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
8565 : :
8566 : 129 : gfc_init_block (&body);
8567 : 499 : for (code = code->block; code; code = code->block)
8568 : : {
8569 : : /* Last section is special because of lastprivate, so even if it
8570 : : is empty, chain it in. */
8571 : 370 : stmt = gfc_trans_omp_code (code->next,
8572 : 370 : has_lastprivate && code->block == NULL);
8573 : 370 : if (! IS_EMPTY_STMT (stmt))
8574 : : {
8575 : 280 : stmt = build1_v (OMP_SECTION, stmt);
8576 : 280 : gfc_add_expr_to_block (&body, stmt);
8577 : : }
8578 : : }
8579 : 129 : stmt = gfc_finish_block (&body);
8580 : :
8581 : 129 : stmt = build2_loc (loc, OMP_SECTIONS, void_type_node, stmt, omp_clauses);
8582 : 129 : gfc_add_expr_to_block (&block, stmt);
8583 : :
8584 : 129 : return gfc_finish_block (&block);
8585 : : }
8586 : :
8587 : : static tree
8588 : 555 : gfc_trans_omp_single (gfc_code *code, gfc_omp_clauses *clauses)
8589 : : {
8590 : 555 : stmtblock_t block;
8591 : 555 : gfc_start_block (&block);
8592 : 555 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
8593 : 555 : tree stmt = gfc_trans_omp_code (code->block->next, true);
8594 : 555 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_SINGLE, void_type_node,
8595 : : stmt, omp_clauses);
8596 : 555 : gfc_add_expr_to_block (&block, stmt);
8597 : 555 : return gfc_finish_block (&block);
8598 : : }
8599 : :
8600 : : static tree
8601 : 1121 : gfc_trans_omp_task (gfc_code *code)
8602 : : {
8603 : 1121 : stmtblock_t block;
8604 : 1121 : tree stmt, omp_clauses;
8605 : :
8606 : 1121 : gfc_start_block (&block);
8607 : 1121 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8608 : : code->loc);
8609 : 1121 : pushlevel ();
8610 : 1121 : stmt = gfc_trans_omp_code (code->block->next, true);
8611 : 1121 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8612 : 1121 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TASK, void_type_node,
8613 : : stmt, omp_clauses);
8614 : 1121 : gfc_add_expr_to_block (&block, stmt);
8615 : 1121 : return gfc_finish_block (&block);
8616 : : }
8617 : :
8618 : : static tree
8619 : 181 : gfc_trans_omp_taskgroup (gfc_code *code)
8620 : : {
8621 : 181 : stmtblock_t block;
8622 : 181 : gfc_start_block (&block);
8623 : 181 : tree body = gfc_trans_code (code->block->next);
8624 : 181 : tree stmt = make_node (OMP_TASKGROUP);
8625 : 181 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8626 : 181 : TREE_TYPE (stmt) = void_type_node;
8627 : 181 : OMP_TASKGROUP_BODY (stmt) = body;
8628 : 181 : OMP_TASKGROUP_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
8629 : : code->ext.omp_clauses,
8630 : : code->loc);
8631 : 181 : gfc_add_expr_to_block (&block, stmt);
8632 : 181 : return gfc_finish_block (&block);
8633 : : }
8634 : :
8635 : : static tree
8636 : 145 : gfc_trans_omp_taskwait (gfc_code *code)
8637 : : {
8638 : 145 : if (!code->ext.omp_clauses)
8639 : : {
8640 : 132 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
8641 : 132 : return build_call_expr_loc (input_location, decl, 0);
8642 : : }
8643 : 13 : stmtblock_t block;
8644 : 13 : gfc_start_block (&block);
8645 : 13 : tree stmt = make_node (OMP_TASK);
8646 : 13 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8647 : 13 : TREE_TYPE (stmt) = void_type_node;
8648 : 13 : OMP_TASK_BODY (stmt) = NULL_TREE;
8649 : 13 : OMP_TASK_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
8650 : : code->ext.omp_clauses,
8651 : : code->loc);
8652 : 13 : gfc_add_expr_to_block (&block, stmt);
8653 : 13 : return gfc_finish_block (&block);
8654 : : }
8655 : :
8656 : : static tree
8657 : 8 : gfc_trans_omp_taskyield (void)
8658 : : {
8659 : 8 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
8660 : 8 : return build_call_expr_loc (input_location, decl, 0);
8661 : : }
8662 : :
8663 : : static tree
8664 : 339 : gfc_trans_omp_distribute (gfc_code *code, gfc_omp_clauses *clausesa)
8665 : : {
8666 : 339 : stmtblock_t block;
8667 : 339 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8668 : 339 : tree stmt, omp_clauses = NULL_TREE;
8669 : 339 : bool free_clausesa = false;
8670 : :
8671 : 339 : gfc_start_block (&block);
8672 : 339 : if (clausesa == NULL)
8673 : : {
8674 : 113 : clausesa = clausesa_buf;
8675 : 113 : gfc_split_omp_clauses (code, clausesa);
8676 : 113 : free_clausesa = true;
8677 : : }
8678 : 339 : if (flag_openmp)
8679 : 339 : omp_clauses
8680 : 339 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
8681 : : code->loc);
8682 : 339 : switch (code->op)
8683 : : {
8684 : 0 : case EXEC_OMP_DISTRIBUTE:
8685 : 0 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
8686 : 0 : case EXEC_OMP_TEAMS_DISTRIBUTE:
8687 : : /* This is handled in gfc_trans_omp_do. */
8688 : 0 : gcc_unreachable ();
8689 : 126 : break;
8690 : 126 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
8691 : 126 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
8692 : 126 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
8693 : 126 : stmt = gfc_trans_omp_parallel_do (code, false, &block, clausesa);
8694 : 126 : if (TREE_CODE (stmt) != BIND_EXPR)
8695 : 126 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8696 : : else
8697 : 0 : poplevel (0, 0);
8698 : : break;
8699 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
8700 : 113 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
8701 : 113 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
8702 : 113 : stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
8703 : 113 : if (TREE_CODE (stmt) != BIND_EXPR)
8704 : 113 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8705 : : else
8706 : 0 : poplevel (0, 0);
8707 : : break;
8708 : 100 : case EXEC_OMP_DISTRIBUTE_SIMD:
8709 : 100 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
8710 : 100 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
8711 : 100 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8712 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8713 : 100 : if (TREE_CODE (stmt) != BIND_EXPR)
8714 : 100 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8715 : : else
8716 : 0 : poplevel (0, 0);
8717 : : break;
8718 : 0 : default:
8719 : 0 : gcc_unreachable ();
8720 : : }
8721 : 339 : if (flag_openmp)
8722 : : {
8723 : 339 : tree distribute = make_node (OMP_DISTRIBUTE);
8724 : 339 : SET_EXPR_LOCATION (distribute, gfc_get_location (&code->loc));
8725 : 339 : TREE_TYPE (distribute) = void_type_node;
8726 : 339 : OMP_FOR_BODY (distribute) = stmt;
8727 : 339 : OMP_FOR_CLAUSES (distribute) = omp_clauses;
8728 : 339 : stmt = distribute;
8729 : : }
8730 : 339 : gfc_add_expr_to_block (&block, stmt);
8731 : 339 : if (free_clausesa)
8732 : 113 : gfc_free_split_omp_clauses (code, clausesa);
8733 : 339 : return gfc_finish_block (&block);
8734 : : }
8735 : :
8736 : : static tree
8737 : 465 : gfc_trans_omp_teams (gfc_code *code, gfc_omp_clauses *clausesa,
8738 : : tree omp_clauses)
8739 : : {
8740 : 465 : stmtblock_t block;
8741 : 465 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8742 : 465 : tree stmt;
8743 : 465 : bool combined = true, free_clausesa = false;
8744 : :
8745 : 465 : gfc_start_block (&block);
8746 : 465 : if (clausesa == NULL)
8747 : : {
8748 : 269 : clausesa = clausesa_buf;
8749 : 269 : gfc_split_omp_clauses (code, clausesa);
8750 : 269 : free_clausesa = true;
8751 : : }
8752 : 465 : if (flag_openmp)
8753 : : {
8754 : 465 : omp_clauses
8755 : 465 : = chainon (omp_clauses,
8756 : : gfc_trans_omp_clauses (&block,
8757 : : &clausesa[GFC_OMP_SPLIT_TEAMS],
8758 : : code->loc));
8759 : 465 : pushlevel ();
8760 : : }
8761 : 465 : switch (code->op)
8762 : : {
8763 : 193 : case EXEC_OMP_TARGET_TEAMS:
8764 : 193 : case EXEC_OMP_TEAMS:
8765 : 193 : stmt = gfc_trans_omp_code (code->block->next, true);
8766 : 193 : combined = false;
8767 : 193 : break;
8768 : 28 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
8769 : 28 : case EXEC_OMP_TEAMS_DISTRIBUTE:
8770 : 28 : stmt = gfc_trans_omp_do (code, EXEC_OMP_DISTRIBUTE, NULL,
8771 : : &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
8772 : : NULL);
8773 : 28 : break;
8774 : 18 : case EXEC_OMP_TARGET_TEAMS_LOOP:
8775 : 18 : case EXEC_OMP_TEAMS_LOOP:
8776 : 18 : stmt = gfc_trans_omp_do (code, EXEC_OMP_LOOP, NULL,
8777 : : &clausesa[GFC_OMP_SPLIT_DO],
8778 : : NULL);
8779 : 18 : break;
8780 : 226 : default:
8781 : 226 : stmt = gfc_trans_omp_distribute (code, clausesa);
8782 : 226 : break;
8783 : : }
8784 : 465 : if (flag_openmp)
8785 : : {
8786 : 465 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8787 : 465 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TEAMS,
8788 : : void_type_node, stmt, omp_clauses);
8789 : 465 : if (combined)
8790 : 272 : OMP_TEAMS_COMBINED (stmt) = 1;
8791 : : }
8792 : 465 : gfc_add_expr_to_block (&block, stmt);
8793 : 465 : if (free_clausesa)
8794 : 269 : gfc_free_split_omp_clauses (code, clausesa);
8795 : 465 : return gfc_finish_block (&block);
8796 : : }
8797 : :
8798 : : static tree
8799 : 1987 : gfc_trans_omp_target (gfc_code *code)
8800 : : {
8801 : 1987 : stmtblock_t block;
8802 : 1987 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8803 : 1987 : tree stmt, omp_clauses = NULL_TREE;
8804 : :
8805 : 1987 : gfc_start_block (&block);
8806 : 1987 : gfc_split_omp_clauses (code, clausesa);
8807 : 1987 : if (flag_openmp)
8808 : 1987 : omp_clauses
8809 : 1987 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TARGET],
8810 : : code->loc);
8811 : 1987 : switch (code->op)
8812 : : {
8813 : 1651 : case EXEC_OMP_TARGET:
8814 : 1651 : pushlevel ();
8815 : 1651 : stmt = gfc_trans_omp_code (code->block->next, true);
8816 : 1651 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8817 : 1651 : break;
8818 : 20 : case EXEC_OMP_TARGET_PARALLEL:
8819 : 20 : {
8820 : 20 : stmtblock_t iblock;
8821 : :
8822 : 20 : pushlevel ();
8823 : 20 : gfc_start_block (&iblock);
8824 : 20 : tree inner_clauses
8825 : 20 : = gfc_trans_omp_clauses (&iblock, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8826 : : code->loc);
8827 : 20 : stmt = gfc_trans_omp_code (code->block->next, true);
8828 : 20 : stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
8829 : : inner_clauses);
8830 : 20 : gfc_add_expr_to_block (&iblock, stmt);
8831 : 20 : stmt = gfc_finish_block (&iblock);
8832 : 20 : if (TREE_CODE (stmt) != BIND_EXPR)
8833 : 17 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8834 : : else
8835 : 3 : poplevel (0, 0);
8836 : : }
8837 : 20 : break;
8838 : 79 : case EXEC_OMP_TARGET_PARALLEL_DO:
8839 : 79 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
8840 : 79 : stmt = gfc_trans_omp_parallel_do (code,
8841 : : (code->op
8842 : : == EXEC_OMP_TARGET_PARALLEL_LOOP),
8843 : : &block, clausesa);
8844 : 79 : if (TREE_CODE (stmt) != BIND_EXPR)
8845 : 79 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8846 : : else
8847 : 0 : poplevel (0, 0);
8848 : : break;
8849 : 15 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
8850 : 15 : stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
8851 : 15 : if (TREE_CODE (stmt) != BIND_EXPR)
8852 : 15 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8853 : : else
8854 : 0 : poplevel (0, 0);
8855 : : break;
8856 : 26 : case EXEC_OMP_TARGET_SIMD:
8857 : 26 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8858 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8859 : 26 : if (TREE_CODE (stmt) != BIND_EXPR)
8860 : 26 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8861 : : else
8862 : 0 : poplevel (0, 0);
8863 : : break;
8864 : 196 : default:
8865 : 196 : if (flag_openmp
8866 : 196 : && (clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
8867 : 146 : || clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit))
8868 : : {
8869 : 51 : gfc_omp_clauses clausesb;
8870 : 51 : tree teams_clauses;
8871 : : /* For combined !$omp target teams, the num_teams and
8872 : : thread_limit clauses are evaluated before entering the
8873 : : target construct. */
8874 : 51 : memset (&clausesb, '\0', sizeof (clausesb));
8875 : 51 : clausesb.num_teams_lower
8876 : 51 : = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower;
8877 : 51 : clausesb.num_teams_upper
8878 : 51 : = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper;
8879 : 51 : clausesb.thread_limit = clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit;
8880 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower = NULL;
8881 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper = NULL;
8882 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit = NULL;
8883 : 51 : teams_clauses
8884 : 51 : = gfc_trans_omp_clauses (&block, &clausesb, code->loc);
8885 : 51 : pushlevel ();
8886 : 51 : stmt = gfc_trans_omp_teams (code, clausesa, teams_clauses);
8887 : 51 : }
8888 : : else
8889 : : {
8890 : 145 : pushlevel ();
8891 : 145 : stmt = gfc_trans_omp_teams (code, clausesa, NULL_TREE);
8892 : : }
8893 : 196 : if (TREE_CODE (stmt) != BIND_EXPR)
8894 : 195 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8895 : : else
8896 : 1 : poplevel (0, 0);
8897 : : break;
8898 : : }
8899 : 1987 : if (flag_openmp)
8900 : : {
8901 : 1987 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET,
8902 : : void_type_node, stmt, omp_clauses);
8903 : 1987 : if (code->op != EXEC_OMP_TARGET)
8904 : 336 : OMP_TARGET_COMBINED (stmt) = 1;
8905 : 1987 : cfun->has_omp_target = true;
8906 : : }
8907 : 1987 : gfc_add_expr_to_block (&block, stmt);
8908 : 1987 : gfc_free_split_omp_clauses (code, clausesa);
8909 : 1987 : return gfc_finish_block (&block);
8910 : : }
8911 : :
8912 : : static tree
8913 : 79 : gfc_trans_omp_taskloop (gfc_code *code, gfc_exec_op op)
8914 : : {
8915 : 79 : stmtblock_t block;
8916 : 79 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8917 : 79 : tree stmt, omp_clauses = NULL_TREE;
8918 : :
8919 : 79 : gfc_start_block (&block);
8920 : 79 : gfc_split_omp_clauses (code, clausesa);
8921 : 79 : if (flag_openmp)
8922 : 79 : omp_clauses
8923 : 79 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TASKLOOP],
8924 : : code->loc);
8925 : 79 : switch (op)
8926 : : {
8927 : 0 : case EXEC_OMP_TASKLOOP:
8928 : : /* This is handled in gfc_trans_omp_do. */
8929 : 0 : gcc_unreachable ();
8930 : 79 : break;
8931 : 79 : case EXEC_OMP_TASKLOOP_SIMD:
8932 : 79 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8933 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8934 : 79 : if (TREE_CODE (stmt) != BIND_EXPR)
8935 : 79 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8936 : : else
8937 : 0 : poplevel (0, 0);
8938 : 79 : break;
8939 : 0 : default:
8940 : 0 : gcc_unreachable ();
8941 : : }
8942 : 79 : if (flag_openmp)
8943 : : {
8944 : 79 : tree taskloop = make_node (OMP_TASKLOOP);
8945 : 79 : SET_EXPR_LOCATION (taskloop, gfc_get_location (&code->loc));
8946 : 79 : TREE_TYPE (taskloop) = void_type_node;
8947 : 79 : OMP_FOR_BODY (taskloop) = stmt;
8948 : 79 : OMP_FOR_CLAUSES (taskloop) = omp_clauses;
8949 : 79 : stmt = taskloop;
8950 : : }
8951 : 79 : gfc_add_expr_to_block (&block, stmt);
8952 : 79 : gfc_free_split_omp_clauses (code, clausesa);
8953 : 79 : return gfc_finish_block (&block);
8954 : : }
8955 : :
8956 : : static tree
8957 : 84 : gfc_trans_omp_master_masked_taskloop (gfc_code *code, gfc_exec_op op)
8958 : : {
8959 : 84 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8960 : 84 : stmtblock_t block;
8961 : 84 : tree stmt;
8962 : :
8963 : 84 : if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
8964 : 55 : && code->op != EXEC_OMP_MASTER_TASKLOOP)
8965 : 44 : gfc_split_omp_clauses (code, clausesa);
8966 : :
8967 : 84 : pushlevel ();
8968 : 84 : if (op == EXEC_OMP_MASKED_TASKLOOP_SIMD
8969 : 84 : || op == EXEC_OMP_MASTER_TASKLOOP_SIMD)
8970 : 48 : stmt = gfc_trans_omp_taskloop (code, EXEC_OMP_TASKLOOP_SIMD);
8971 : : else
8972 : : {
8973 : 36 : gcc_assert (op == EXEC_OMP_MASKED_TASKLOOP
8974 : : || op == EXEC_OMP_MASTER_TASKLOOP);
8975 : 36 : stmt = gfc_trans_omp_do (code, EXEC_OMP_TASKLOOP, NULL,
8976 : 36 : code->op != EXEC_OMP_MASTER_TASKLOOP
8977 : : ? &clausesa[GFC_OMP_SPLIT_TASKLOOP]
8978 : : : code->ext.omp_clauses, NULL);
8979 : : }
8980 : 84 : if (TREE_CODE (stmt) != BIND_EXPR)
8981 : 55 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8982 : : else
8983 : 29 : poplevel (0, 0);
8984 : 84 : gfc_start_block (&block);
8985 : 84 : if (op == EXEC_OMP_MASKED_TASKLOOP || op == EXEC_OMP_MASKED_TASKLOOP_SIMD)
8986 : : {
8987 : 34 : tree clauses = gfc_trans_omp_clauses (&block,
8988 : : &clausesa[GFC_OMP_SPLIT_MASKED],
8989 : : code->loc);
8990 : 34 : tree msk = make_node (OMP_MASKED);
8991 : 34 : SET_EXPR_LOCATION (msk, gfc_get_location (&code->loc));
8992 : 34 : TREE_TYPE (msk) = void_type_node;
8993 : 34 : OMP_MASKED_BODY (msk) = stmt;
8994 : 34 : OMP_MASKED_CLAUSES (msk) = clauses;
8995 : 34 : OMP_MASKED_COMBINED (msk) = 1;
8996 : 34 : gfc_add_expr_to_block (&block, msk);
8997 : : }
8998 : : else
8999 : : {
9000 : 50 : gcc_assert (op == EXEC_OMP_MASTER_TASKLOOP
9001 : : || op == EXEC_OMP_MASTER_TASKLOOP_SIMD);
9002 : 50 : stmt = build1_v (OMP_MASTER, stmt);
9003 : 50 : gfc_add_expr_to_block (&block, stmt);
9004 : : }
9005 : 84 : if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
9006 : 55 : && code->op != EXEC_OMP_MASTER_TASKLOOP)
9007 : 44 : gfc_free_split_omp_clauses (code, clausesa);
9008 : 84 : return gfc_finish_block (&block);
9009 : : }
9010 : :
9011 : : static tree
9012 : 61 : gfc_trans_omp_parallel_master_masked (gfc_code *code)
9013 : : {
9014 : 61 : stmtblock_t block;
9015 : 61 : tree stmt, omp_clauses;
9016 : 61 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
9017 : 61 : bool parallel_combined = false;
9018 : :
9019 : 61 : if (code->op != EXEC_OMP_PARALLEL_MASTER)
9020 : 50 : gfc_split_omp_clauses (code, clausesa);
9021 : :
9022 : 61 : gfc_start_block (&block);
9023 : 61 : omp_clauses = gfc_trans_omp_clauses (&block,
9024 : 61 : code->op == EXEC_OMP_PARALLEL_MASTER
9025 : : ? code->ext.omp_clauses
9026 : : : &clausesa[GFC_OMP_SPLIT_PARALLEL],
9027 : : code->loc);
9028 : 61 : pushlevel ();
9029 : 61 : if (code->op == EXEC_OMP_PARALLEL_MASTER)
9030 : 11 : stmt = gfc_trans_omp_master (code);
9031 : 50 : else if (code->op == EXEC_OMP_PARALLEL_MASKED)
9032 : 11 : stmt = gfc_trans_omp_masked (code, &clausesa[GFC_OMP_SPLIT_MASKED]);
9033 : : else
9034 : : {
9035 : 39 : gfc_exec_op op;
9036 : 39 : switch (code->op)
9037 : : {
9038 : : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
9039 : : op = EXEC_OMP_MASKED_TASKLOOP;
9040 : : break;
9041 : 8 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
9042 : 8 : op = EXEC_OMP_MASKED_TASKLOOP_SIMD;
9043 : 8 : break;
9044 : 10 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
9045 : 10 : op = EXEC_OMP_MASTER_TASKLOOP;
9046 : 10 : break;
9047 : 14 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
9048 : 14 : op = EXEC_OMP_MASTER_TASKLOOP_SIMD;
9049 : 14 : break;
9050 : 0 : default:
9051 : 0 : gcc_unreachable ();
9052 : : }
9053 : 39 : stmt = gfc_trans_omp_master_masked_taskloop (code, op);
9054 : 39 : parallel_combined = true;
9055 : : }
9056 : 61 : if (TREE_CODE (stmt) != BIND_EXPR)
9057 : 48 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
9058 : : else
9059 : 13 : poplevel (0, 0);
9060 : 61 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
9061 : : void_type_node, stmt, omp_clauses);
9062 : : /* masked does have just filter clause, but during gimplification
9063 : : isn't represented by a gimplification omp context, so for
9064 : : !$omp parallel masked don't set OMP_PARALLEL_COMBINED,
9065 : : so that
9066 : : !$omp parallel masked
9067 : : !$omp taskloop simd lastprivate (x)
9068 : : isn't confused with
9069 : : !$omp parallel masked taskloop simd lastprivate (x) */
9070 : 61 : if (parallel_combined)
9071 : 39 : OMP_PARALLEL_COMBINED (stmt) = 1;
9072 : 61 : gfc_add_expr_to_block (&block, stmt);
9073 : 61 : if (code->op != EXEC_OMP_PARALLEL_MASTER)
9074 : 50 : gfc_free_split_omp_clauses (code, clausesa);
9075 : 61 : return gfc_finish_block (&block);
9076 : : }
9077 : :
9078 : : static tree
9079 : 1388 : gfc_trans_omp_target_data (gfc_code *code)
9080 : : {
9081 : 1388 : stmtblock_t block;
9082 : 1388 : tree stmt, omp_clauses;
9083 : :
9084 : 1388 : gfc_start_block (&block);
9085 : 1388 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9086 : : code->loc);
9087 : 1388 : stmt = gfc_trans_omp_code (code->block->next, true);
9088 : 1388 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET_DATA,
9089 : : void_type_node, stmt, omp_clauses);
9090 : 1388 : gfc_add_expr_to_block (&block, stmt);
9091 : 1388 : return gfc_finish_block (&block);
9092 : : }
9093 : :
9094 : : static tree
9095 : 325 : gfc_trans_omp_target_enter_data (gfc_code *code)
9096 : : {
9097 : 325 : stmtblock_t block;
9098 : 325 : tree stmt, omp_clauses;
9099 : :
9100 : 325 : gfc_start_block (&block);
9101 : 325 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9102 : : code->loc);
9103 : 325 : stmt = build1_loc (input_location, OMP_TARGET_ENTER_DATA, void_type_node,
9104 : : omp_clauses);
9105 : 325 : gfc_add_expr_to_block (&block, stmt);
9106 : 325 : return gfc_finish_block (&block);
9107 : : }
9108 : :
9109 : : static tree
9110 : 263 : gfc_trans_omp_target_exit_data (gfc_code *code)
9111 : : {
9112 : 263 : stmtblock_t block;
9113 : 263 : tree stmt, omp_clauses;
9114 : :
9115 : 263 : gfc_start_block (&block);
9116 : 263 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9117 : : code->loc, false, false, code->op);
9118 : 263 : stmt = build1_loc (input_location, OMP_TARGET_EXIT_DATA, void_type_node,
9119 : : omp_clauses);
9120 : 263 : gfc_add_expr_to_block (&block, stmt);
9121 : 263 : return gfc_finish_block (&block);
9122 : : }
9123 : :
9124 : : static tree
9125 : 1697 : gfc_trans_omp_target_update (gfc_code *code)
9126 : : {
9127 : 1697 : stmtblock_t block;
9128 : 1697 : tree stmt, omp_clauses;
9129 : :
9130 : 1697 : gfc_start_block (&block);
9131 : 1697 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9132 : : code->loc);
9133 : 1697 : stmt = build1_loc (input_location, OMP_TARGET_UPDATE, void_type_node,
9134 : : omp_clauses);
9135 : 1697 : gfc_add_expr_to_block (&block, stmt);
9136 : 1697 : return gfc_finish_block (&block);
9137 : : }
9138 : :
9139 : : static tree
9140 : 8 : gfc_trans_openmp_interop (gfc_code *code, gfc_omp_clauses *clauses)
9141 : : {
9142 : 8 : stmtblock_t block;
9143 : 8 : gfc_start_block (&block);
9144 : 8 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
9145 : 8 : tree stmt = build1_loc (input_location, OMP_INTEROP, void_type_node,
9146 : : omp_clauses);
9147 : 8 : gfc_add_expr_to_block (&block, stmt);
9148 : 8 : return gfc_finish_block (&block);
9149 : : }
9150 : :
9151 : : static tree
9152 : 85 : gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
9153 : : {
9154 : 85 : tree res, tmp, stmt;
9155 : 85 : stmtblock_t block, *pblock = NULL;
9156 : 85 : stmtblock_t singleblock;
9157 : 85 : int saved_ompws_flags;
9158 : 85 : bool singleblock_in_progress = false;
9159 : : /* True if previous gfc_code in workshare construct is not workshared. */
9160 : 85 : bool prev_singleunit;
9161 : 85 : location_t loc = gfc_get_location (&code->loc);
9162 : :
9163 : 85 : code = code->block->next;
9164 : :
9165 : 85 : pushlevel ();
9166 : :
9167 : 85 : gfc_start_block (&block);
9168 : 85 : pblock = █
9169 : :
9170 : 85 : ompws_flags = OMPWS_WORKSHARE_FLAG;
9171 : 85 : prev_singleunit = false;
9172 : :
9173 : : /* Translate statements one by one to trees until we reach
9174 : : the end of the workshare construct. Adjacent gfc_codes that
9175 : : are a single unit of work are clustered and encapsulated in a
9176 : : single OMP_SINGLE construct. */
9177 : 282 : for (; code; code = code->next)
9178 : : {
9179 : 197 : if (code->here != 0)
9180 : : {
9181 : 0 : res = gfc_trans_label_here (code);
9182 : 0 : gfc_add_expr_to_block (pblock, res);
9183 : : }
9184 : :
9185 : : /* No dependence analysis, use for clauses with wait.
9186 : : If this is the last gfc_code, use default omp_clauses. */
9187 : 197 : if (code->next == NULL && clauses->nowait)
9188 : 60 : ompws_flags |= OMPWS_NOWAIT;
9189 : :
9190 : : /* By default, every gfc_code is a single unit of work. */
9191 : 197 : ompws_flags |= OMPWS_CURR_SINGLEUNIT;
9192 : 197 : ompws_flags &= ~(OMPWS_SCALARIZER_WS | OMPWS_SCALARIZER_BODY);
9193 : :
9194 : 197 : switch (code->op)
9195 : : {
9196 : : case EXEC_NOP:
9197 : : res = NULL_TREE;
9198 : : break;
9199 : :
9200 : 125 : case EXEC_ASSIGN:
9201 : 125 : res = gfc_trans_assign (code);
9202 : 125 : break;
9203 : :
9204 : 0 : case EXEC_POINTER_ASSIGN:
9205 : 0 : res = gfc_trans_pointer_assign (code);
9206 : 0 : break;
9207 : :
9208 : 0 : case EXEC_INIT_ASSIGN:
9209 : 0 : res = gfc_trans_init_assign (code);
9210 : 0 : break;
9211 : :
9212 : 24 : case EXEC_FORALL:
9213 : 24 : res = gfc_trans_forall (code);
9214 : 24 : break;
9215 : :
9216 : 19 : case EXEC_WHERE:
9217 : 19 : res = gfc_trans_where (code);
9218 : 19 : break;
9219 : :
9220 : 7 : case EXEC_OMP_ATOMIC:
9221 : 7 : res = gfc_trans_omp_directive (code);
9222 : 7 : break;
9223 : :
9224 : 17 : case EXEC_OMP_PARALLEL:
9225 : 17 : case EXEC_OMP_PARALLEL_DO:
9226 : 17 : case EXEC_OMP_PARALLEL_MASTER:
9227 : 17 : case EXEC_OMP_PARALLEL_SECTIONS:
9228 : 17 : case EXEC_OMP_PARALLEL_WORKSHARE:
9229 : 17 : case EXEC_OMP_CRITICAL:
9230 : 17 : saved_ompws_flags = ompws_flags;
9231 : 17 : ompws_flags = 0;
9232 : 17 : res = gfc_trans_omp_directive (code);
9233 : 17 : ompws_flags = saved_ompws_flags;
9234 : 17 : break;
9235 : :
9236 : 5 : case EXEC_BLOCK:
9237 : 5 : res = gfc_trans_block_construct (code);
9238 : 5 : break;
9239 : :
9240 : 0 : default:
9241 : 0 : gfc_internal_error ("gfc_trans_omp_workshare(): Bad statement code");
9242 : : }
9243 : :
9244 : 197 : input_location = gfc_get_location (&code->loc);
9245 : :
9246 : 197 : if (res != NULL_TREE && ! IS_EMPTY_STMT (res))
9247 : : {
9248 : 197 : if (prev_singleunit)
9249 : : {
9250 : 72 : if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
9251 : : /* Add current gfc_code to single block. */
9252 : 44 : gfc_add_expr_to_block (&singleblock, res);
9253 : : else
9254 : : {
9255 : : /* Finish single block and add it to pblock. */
9256 : 28 : tmp = gfc_finish_block (&singleblock);
9257 : 28 : tmp = build2_loc (loc, OMP_SINGLE,
9258 : : void_type_node, tmp, NULL_TREE);
9259 : 28 : gfc_add_expr_to_block (pblock, tmp);
9260 : : /* Add current gfc_code to pblock. */
9261 : 28 : gfc_add_expr_to_block (pblock, res);
9262 : 28 : singleblock_in_progress = false;
9263 : : }
9264 : : }
9265 : : else
9266 : : {
9267 : 125 : if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
9268 : : {
9269 : : /* Start single block. */
9270 : 73 : gfc_init_block (&singleblock);
9271 : 73 : gfc_add_expr_to_block (&singleblock, res);
9272 : 73 : singleblock_in_progress = true;
9273 : 73 : loc = gfc_get_location (&code->loc);
9274 : : }
9275 : : else
9276 : : /* Add the new statement to the block. */
9277 : 52 : gfc_add_expr_to_block (pblock, res);
9278 : : }
9279 : 197 : prev_singleunit = (ompws_flags & OMPWS_CURR_SINGLEUNIT) != 0;
9280 : : }
9281 : : }
9282 : :
9283 : : /* Finish remaining SINGLE block, if we were in the middle of one. */
9284 : 85 : if (singleblock_in_progress)
9285 : : {
9286 : : /* Finish single block and add it to pblock. */
9287 : 45 : tmp = gfc_finish_block (&singleblock);
9288 : 45 : tmp = build2_loc (loc, OMP_SINGLE, void_type_node, tmp,
9289 : 45 : clauses->nowait
9290 : 27 : ? build_omp_clause (input_location, OMP_CLAUSE_NOWAIT)
9291 : : : NULL_TREE);
9292 : 45 : gfc_add_expr_to_block (pblock, tmp);
9293 : : }
9294 : :
9295 : 85 : stmt = gfc_finish_block (pblock);
9296 : 85 : if (TREE_CODE (stmt) != BIND_EXPR)
9297 : : {
9298 : 65 : if (!IS_EMPTY_STMT (stmt))
9299 : : {
9300 : 65 : tree bindblock = poplevel (1, 0);
9301 : 65 : stmt = build3_v (BIND_EXPR, NULL, stmt, bindblock);
9302 : : }
9303 : : else
9304 : 0 : poplevel (0, 0);
9305 : : }
9306 : : else
9307 : 20 : poplevel (0, 0);
9308 : :
9309 : 85 : if (IS_EMPTY_STMT (stmt) && !clauses->nowait)
9310 : 0 : stmt = gfc_trans_omp_barrier ();
9311 : :
9312 : 85 : ompws_flags = 0;
9313 : 85 : return stmt;
9314 : : }
9315 : :
9316 : : tree
9317 : 75 : gfc_trans_oacc_declare (gfc_code *code)
9318 : : {
9319 : 75 : stmtblock_t block;
9320 : 75 : tree stmt, oacc_clauses;
9321 : 75 : enum tree_code construct_code;
9322 : :
9323 : 75 : construct_code = OACC_DATA;
9324 : :
9325 : 75 : gfc_start_block (&block);
9326 : :
9327 : 75 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.oacc_declare->clauses,
9328 : : code->loc, false, true);
9329 : 75 : stmt = gfc_trans_omp_code (code->block->next, true);
9330 : 75 : stmt = build2_loc (input_location, construct_code, void_type_node, stmt,
9331 : : oacc_clauses);
9332 : 75 : gfc_add_expr_to_block (&block, stmt);
9333 : :
9334 : 75 : return gfc_finish_block (&block);
9335 : : }
9336 : :
9337 : : tree
9338 : 11955 : gfc_trans_oacc_directive (gfc_code *code)
9339 : : {
9340 : 11955 : switch (code->op)
9341 : : {
9342 : 1552 : case EXEC_OACC_PARALLEL_LOOP:
9343 : 1552 : case EXEC_OACC_KERNELS_LOOP:
9344 : 1552 : case EXEC_OACC_SERIAL_LOOP:
9345 : 1552 : return gfc_trans_oacc_combined_directive (code);
9346 : 4168 : case EXEC_OACC_PARALLEL:
9347 : 4168 : case EXEC_OACC_KERNELS:
9348 : 4168 : case EXEC_OACC_SERIAL:
9349 : 4168 : case EXEC_OACC_DATA:
9350 : 4168 : case EXEC_OACC_HOST_DATA:
9351 : 4168 : return gfc_trans_oacc_construct (code);
9352 : 3375 : case EXEC_OACC_LOOP:
9353 : 3375 : return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
9354 : 3375 : NULL);
9355 : 2075 : case EXEC_OACC_UPDATE:
9356 : 2075 : case EXEC_OACC_CACHE:
9357 : 2075 : case EXEC_OACC_ENTER_DATA:
9358 : 2075 : case EXEC_OACC_EXIT_DATA:
9359 : 2075 : return gfc_trans_oacc_executable_directive (code);
9360 : 167 : case EXEC_OACC_WAIT:
9361 : 167 : return gfc_trans_oacc_wait_directive (code);
9362 : 543 : case EXEC_OACC_ATOMIC:
9363 : 543 : return gfc_trans_omp_atomic (code);
9364 : 75 : case EXEC_OACC_DECLARE:
9365 : 75 : return gfc_trans_oacc_declare (code);
9366 : 0 : default:
9367 : 0 : gcc_unreachable ();
9368 : : }
9369 : : }
9370 : :
9371 : : tree
9372 : 18682 : gfc_trans_omp_directive (gfc_code *code)
9373 : : {
9374 : 18682 : switch (code->op)
9375 : : {
9376 : 34 : case EXEC_OMP_ALLOCATE:
9377 : 34 : case EXEC_OMP_ALLOCATORS:
9378 : 34 : return gfc_trans_omp_allocators (code);
9379 : 10 : case EXEC_OMP_ASSUME:
9380 : 10 : return gfc_trans_omp_assume (code);
9381 : 2053 : case EXEC_OMP_ATOMIC:
9382 : 2053 : return gfc_trans_omp_atomic (code);
9383 : 603 : case EXEC_OMP_BARRIER:
9384 : 603 : return gfc_trans_omp_barrier ();
9385 : 310 : case EXEC_OMP_CANCEL:
9386 : 310 : return gfc_trans_omp_cancel (code);
9387 : 170 : case EXEC_OMP_CANCELLATION_POINT:
9388 : 170 : return gfc_trans_omp_cancellation_point (code);
9389 : 143 : case EXEC_OMP_CRITICAL:
9390 : 143 : return gfc_trans_omp_critical (code);
9391 : 108 : case EXEC_OMP_DEPOBJ:
9392 : 108 : return gfc_trans_omp_depobj (code);
9393 : 2452 : case EXEC_OMP_DISTRIBUTE:
9394 : 2452 : case EXEC_OMP_DO:
9395 : 2452 : case EXEC_OMP_LOOP:
9396 : 2452 : case EXEC_OMP_SIMD:
9397 : 2452 : case EXEC_OMP_TASKLOOP:
9398 : 2452 : case EXEC_OMP_TILE:
9399 : 2452 : case EXEC_OMP_UNROLL:
9400 : 2452 : return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
9401 : 2452 : NULL);
9402 : 128 : case EXEC_OMP_DISPATCH:
9403 : 128 : return gfc_trans_omp_dispatch (code);
9404 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
9405 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
9406 : 113 : case EXEC_OMP_DISTRIBUTE_SIMD:
9407 : 113 : return gfc_trans_omp_distribute (code, NULL);
9408 : 126 : case EXEC_OMP_DO_SIMD:
9409 : 126 : return gfc_trans_omp_do_simd (code, NULL, NULL, NULL_TREE);
9410 : 29 : case EXEC_OMP_ERROR:
9411 : 29 : return gfc_trans_omp_error (code);
9412 : 70 : case EXEC_OMP_FLUSH:
9413 : 70 : return gfc_trans_omp_flush (code);
9414 : 38 : case EXEC_OMP_MASKED:
9415 : 38 : return gfc_trans_omp_masked (code, NULL);
9416 : 104 : case EXEC_OMP_MASTER:
9417 : 104 : return gfc_trans_omp_master (code);
9418 : 45 : case EXEC_OMP_MASKED_TASKLOOP:
9419 : 45 : case EXEC_OMP_MASKED_TASKLOOP_SIMD:
9420 : 45 : case EXEC_OMP_MASTER_TASKLOOP:
9421 : 45 : case EXEC_OMP_MASTER_TASKLOOP_SIMD:
9422 : 45 : return gfc_trans_omp_master_masked_taskloop (code, code->op);
9423 : 76 : case EXEC_OMP_METADIRECTIVE:
9424 : 76 : return gfc_trans_omp_metadirective (code);
9425 : 519 : case EXEC_OMP_ORDERED:
9426 : 519 : return gfc_trans_omp_ordered (code);
9427 : 1858 : case EXEC_OMP_PARALLEL:
9428 : 1858 : return gfc_trans_omp_parallel (code);
9429 : 1078 : case EXEC_OMP_PARALLEL_DO:
9430 : 1078 : return gfc_trans_omp_parallel_do (code, false, NULL, NULL);
9431 : 24 : case EXEC_OMP_PARALLEL_LOOP:
9432 : 24 : return gfc_trans_omp_parallel_do (code, true, NULL, NULL);
9433 : 285 : case EXEC_OMP_PARALLEL_DO_SIMD:
9434 : 285 : return gfc_trans_omp_parallel_do_simd (code, NULL, NULL);
9435 : 61 : case EXEC_OMP_PARALLEL_MASKED:
9436 : 61 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
9437 : 61 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
9438 : 61 : case EXEC_OMP_PARALLEL_MASTER:
9439 : 61 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
9440 : 61 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
9441 : 61 : return gfc_trans_omp_parallel_master_masked (code);
9442 : 54 : case EXEC_OMP_PARALLEL_SECTIONS:
9443 : 54 : return gfc_trans_omp_parallel_sections (code);
9444 : 50 : case EXEC_OMP_PARALLEL_WORKSHARE:
9445 : 50 : return gfc_trans_omp_parallel_workshare (code);
9446 : 53 : case EXEC_OMP_SCOPE:
9447 : 53 : return gfc_trans_omp_scope (code);
9448 : 75 : case EXEC_OMP_SECTIONS:
9449 : 75 : return gfc_trans_omp_sections (code, code->ext.omp_clauses);
9450 : 555 : case EXEC_OMP_SINGLE:
9451 : 555 : return gfc_trans_omp_single (code, code->ext.omp_clauses);
9452 : 1987 : case EXEC_OMP_TARGET:
9453 : 1987 : case EXEC_OMP_TARGET_PARALLEL:
9454 : 1987 : case EXEC_OMP_TARGET_PARALLEL_DO:
9455 : 1987 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
9456 : 1987 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
9457 : 1987 : case EXEC_OMP_TARGET_SIMD:
9458 : 1987 : case EXEC_OMP_TARGET_TEAMS:
9459 : 1987 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
9460 : 1987 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
9461 : 1987 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
9462 : 1987 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
9463 : 1987 : case EXEC_OMP_TARGET_TEAMS_LOOP:
9464 : 1987 : return gfc_trans_omp_target (code);
9465 : 1388 : case EXEC_OMP_TARGET_DATA:
9466 : 1388 : return gfc_trans_omp_target_data (code);
9467 : 325 : case EXEC_OMP_TARGET_ENTER_DATA:
9468 : 325 : return gfc_trans_omp_target_enter_data (code);
9469 : 263 : case EXEC_OMP_TARGET_EXIT_DATA:
9470 : 263 : return gfc_trans_omp_target_exit_data (code);
9471 : 1697 : case EXEC_OMP_TARGET_UPDATE:
9472 : 1697 : return gfc_trans_omp_target_update (code);
9473 : 1121 : case EXEC_OMP_TASK:
9474 : 1121 : return gfc_trans_omp_task (code);
9475 : 181 : case EXEC_OMP_TASKGROUP:
9476 : 181 : return gfc_trans_omp_taskgroup (code);
9477 : 31 : case EXEC_OMP_TASKLOOP_SIMD:
9478 : 31 : return gfc_trans_omp_taskloop (code, code->op);
9479 : 145 : case EXEC_OMP_TASKWAIT:
9480 : 145 : return gfc_trans_omp_taskwait (code);
9481 : 8 : case EXEC_OMP_TASKYIELD:
9482 : 8 : return gfc_trans_omp_taskyield ();
9483 : 269 : case EXEC_OMP_TEAMS:
9484 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE:
9485 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
9486 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
9487 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
9488 : 269 : case EXEC_OMP_TEAMS_LOOP:
9489 : 269 : return gfc_trans_omp_teams (code, NULL, NULL_TREE);
9490 : 35 : case EXEC_OMP_WORKSHARE:
9491 : 35 : return gfc_trans_omp_workshare (code, code->ext.omp_clauses);
9492 : 8 : case EXEC_OMP_INTEROP:
9493 : 8 : return gfc_trans_openmp_interop (code, code->ext.omp_clauses);
9494 : 0 : default:
9495 : 0 : gcc_unreachable ();
9496 : : }
9497 : : }
9498 : :
9499 : : void
9500 : 109 : gfc_trans_omp_declare_simd (gfc_namespace *ns)
9501 : : {
9502 : 109 : if (ns->entries)
9503 : : return;
9504 : :
9505 : 109 : gfc_omp_declare_simd *ods;
9506 : 262 : for (ods = ns->omp_declare_simd; ods; ods = ods->next)
9507 : : {
9508 : 153 : tree c = gfc_trans_omp_clauses (NULL, ods->clauses, ods->where, true);
9509 : 153 : tree fndecl = ns->proc_name->backend_decl;
9510 : 153 : if (c != NULL_TREE)
9511 : 103 : c = tree_cons (NULL_TREE, c, NULL_TREE);
9512 : 153 : c = build_tree_list (get_identifier ("omp declare simd"), c);
9513 : 153 : TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
9514 : 153 : DECL_ATTRIBUTES (fndecl) = c;
9515 : : }
9516 : : }
9517 : :
9518 : : /* Translate the context selector list GFC_SELECTORS, using WHERE as the
9519 : : locus for error messages. */
9520 : :
9521 : : static tree
9522 : 486 : gfc_trans_omp_set_selector (gfc_omp_set_selector *gfc_selectors, locus where)
9523 : : {
9524 : 486 : tree set_selectors = NULL_TREE;
9525 : 486 : gfc_omp_set_selector *oss;
9526 : :
9527 : 962 : for (oss = gfc_selectors; oss; oss = oss->next)
9528 : : {
9529 : 476 : tree selectors = NULL_TREE;
9530 : 476 : gfc_omp_selector *os;
9531 : 476 : enum omp_tss_code set = oss->code;
9532 : 476 : gcc_assert (set != OMP_TRAIT_SET_INVALID);
9533 : :
9534 : 1077 : for (os = oss->trait_selectors; os; os = os->next)
9535 : : {
9536 : 601 : tree scoreval = NULL_TREE;
9537 : 601 : tree properties = NULL_TREE;
9538 : 601 : gfc_omp_trait_property *otp;
9539 : 601 : enum omp_ts_code sel = os->code;
9540 : :
9541 : : /* Per the spec, "Implementations can ignore specified
9542 : : selectors that are not those described in this section";
9543 : : however, we must record such selectors because they
9544 : : cause match failures. */
9545 : 601 : if (sel == OMP_TRAIT_INVALID)
9546 : : {
9547 : 1 : selectors = make_trait_selector (sel, NULL_TREE, NULL_TREE,
9548 : : selectors);
9549 : 1 : continue;
9550 : : }
9551 : :
9552 : 959 : for (otp = os->properties; otp; otp = otp->next)
9553 : : {
9554 : 359 : switch (otp->property_kind)
9555 : : {
9556 : 72 : case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
9557 : 72 : case OMP_TRAIT_PROPERTY_BOOL_EXPR:
9558 : 72 : {
9559 : 72 : tree expr = NULL_TREE;
9560 : 72 : gfc_se se;
9561 : 72 : gfc_init_se (&se, NULL);
9562 : 72 : gfc_conv_expr (&se, otp->expr);
9563 : 72 : expr = se.expr;
9564 : 72 : properties = make_trait_property (NULL_TREE, expr,
9565 : : properties);
9566 : : }
9567 : 72 : break;
9568 : 23 : case OMP_TRAIT_PROPERTY_ID:
9569 : 23 : properties
9570 : 23 : = make_trait_property (get_identifier (otp->name),
9571 : : NULL_TREE, properties);
9572 : 23 : break;
9573 : 250 : case OMP_TRAIT_PROPERTY_NAME_LIST:
9574 : 250 : {
9575 : 250 : tree prop = OMP_TP_NAMELIST_NODE;
9576 : 250 : tree value = NULL_TREE;
9577 : 250 : if (otp->is_name)
9578 : 165 : value = get_identifier (otp->name);
9579 : : else
9580 : 85 : value = gfc_conv_constant_to_tree (otp->expr);
9581 : :
9582 : 250 : properties = make_trait_property (prop, value,
9583 : : properties);
9584 : : }
9585 : 250 : break;
9586 : 14 : case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
9587 : 14 : properties = gfc_trans_omp_clauses (NULL, otp->clauses,
9588 : : where, true);
9589 : 14 : break;
9590 : 0 : default:
9591 : 0 : gcc_unreachable ();
9592 : : }
9593 : : }
9594 : :
9595 : 600 : if (os->score)
9596 : : {
9597 : 51 : gfc_se se;
9598 : 51 : gfc_init_se (&se, NULL);
9599 : 51 : gfc_conv_expr (&se, os->score);
9600 : 51 : scoreval = se.expr;
9601 : : }
9602 : :
9603 : 600 : selectors = make_trait_selector (sel, scoreval,
9604 : : properties, selectors);
9605 : : }
9606 : 476 : set_selectors = make_trait_set_selector (set, selectors, set_selectors);
9607 : : }
9608 : 486 : return set_selectors;
9609 : : }
9610 : :
9611 : : /* If 'ns' points to a formal namespace in an interface, ns->parent == NULL;
9612 : : hence, parent_ns is used instead. */
9613 : :
9614 : : void
9615 : 10017 : gfc_trans_omp_declare_variant (gfc_namespace *ns, gfc_namespace *parent_ns)
9616 : : {
9617 : 10017 : tree base_fn_decl = ns->proc_name->backend_decl;
9618 : 10017 : gfc_namespace *search_ns = ns;
9619 : 10017 : gfc_omp_declare_variant *next;
9620 : :
9621 : 10017 : for (gfc_omp_declare_variant *odv = search_ns->omp_declare_variant;
9622 : 27173 : search_ns; odv = next)
9623 : : {
9624 : : /* Look in the parent namespace if there are no more directives in the
9625 : : current namespace. */
9626 : 17156 : if (!odv)
9627 : : {
9628 : 16774 : if (!search_ns->parent && search_ns == ns)
9629 : : search_ns = parent_ns;
9630 : : else
9631 : 11713 : search_ns = search_ns->parent;
9632 : 16774 : if (search_ns)
9633 : 6757 : next = search_ns->omp_declare_variant;
9634 : 16774 : continue;
9635 : : }
9636 : :
9637 : 382 : next = odv->next;
9638 : :
9639 : 382 : if (odv->error_p)
9640 : 17 : continue;
9641 : :
9642 : : /* Check directive the first time it is encountered. */
9643 : 365 : bool error_found = true;
9644 : :
9645 : 365 : if (odv->checked_p)
9646 : 43 : error_found = false;
9647 : 365 : if (odv->base_proc_symtree == NULL)
9648 : : {
9649 : 328 : if (!search_ns->proc_name->attr.function
9650 : 209 : && !search_ns->proc_name->attr.subroutine)
9651 : 1 : gfc_error ("The base name for %<declare variant%> must be "
9652 : : "specified at %L", &odv->where);
9653 : : else
9654 : : error_found = false;
9655 : : }
9656 : : else
9657 : : {
9658 : 37 : if (!search_ns->contained
9659 : 21 : && !odv->base_proc_symtree->n.sym->attr.use_assoc
9660 : 5 : && strcmp (odv->base_proc_symtree->name,
9661 : 5 : ns->proc_name->name))
9662 : 1 : gfc_error ("The base name at %L does not match the name of the "
9663 : : "current procedure", &odv->where);
9664 : 36 : else if (odv->base_proc_symtree->n.sym->attr.entry)
9665 : 1 : gfc_error ("The base name at %L must not be an entry name",
9666 : : &odv->where);
9667 : 35 : else if (odv->base_proc_symtree->n.sym->attr.generic)
9668 : 1 : gfc_error ("The base name at %L must not be a generic name",
9669 : : &odv->where);
9670 : 34 : else if (odv->base_proc_symtree->n.sym->attr.proc_pointer)
9671 : 1 : gfc_error ("The base name at %L must not be a procedure pointer",
9672 : : &odv->where);
9673 : 33 : else if (odv->base_proc_symtree->n.sym->attr.implicit_type)
9674 : 1 : gfc_error ("The base procedure at %L must have an explicit "
9675 : : "interface", &odv->where);
9676 : : else
9677 : : error_found = false;
9678 : : }
9679 : :
9680 : 365 : odv->checked_p = true;
9681 : 365 : if (error_found)
9682 : : {
9683 : 6 : odv->error_p = true;
9684 : 6 : continue;
9685 : : }
9686 : :
9687 : : /* Ignore directives that do not apply to the current procedure. */
9688 : 359 : if ((odv->base_proc_symtree == NULL && search_ns != ns)
9689 : 333 : || (odv->base_proc_symtree != NULL
9690 : 32 : && !ns->proc_name->attr.use_assoc
9691 : 19 : && strcmp (odv->base_proc_symtree->name, ns->proc_name->name))
9692 : 320 : || (odv->base_proc_symtree != NULL
9693 : 19 : && ns->proc_name->attr.use_assoc
9694 : 13 : && strcmp (odv->base_proc_symtree->n.sym->name,
9695 : : ns->proc_name->name)))
9696 : 44 : continue;
9697 : :
9698 : 315 : tree set_selectors = gfc_trans_omp_set_selector (odv->set_selectors,
9699 : : odv->where);
9700 : 315 : const char *variant_proc_name = odv->variant_proc_symtree->name;
9701 : 315 : gfc_symbol *variant_proc_sym = odv->variant_proc_symtree->n.sym;
9702 : 315 : if (variant_proc_sym == NULL || variant_proc_sym->attr.implicit_type)
9703 : : {
9704 : 38 : gfc_symtree *proc_st;
9705 : 38 : gfc_find_sym_tree (variant_proc_name, gfc_current_ns, 1, &proc_st);
9706 : 38 : variant_proc_sym = proc_st->n.sym;
9707 : : }
9708 : 38 : if (variant_proc_sym == NULL)
9709 : : {
9710 : 0 : gfc_error ("Cannot find symbol %qs", variant_proc_name);
9711 : 0 : continue;
9712 : : }
9713 : 315 : set_selectors = omp_check_context_selector
9714 : 315 : (gfc_get_location (&odv->where), set_selectors,
9715 : : OMP_CTX_DECLARE_VARIANT);
9716 : 315 : if (set_selectors != error_mark_node)
9717 : : {
9718 : 295 : if (!variant_proc_sym->attr.implicit_type
9719 : 295 : && !variant_proc_sym->attr.subroutine
9720 : 89 : && !variant_proc_sym->attr.function)
9721 : : {
9722 : 0 : gfc_error ("variant %qs at %L is not a function or subroutine",
9723 : : variant_proc_name, &odv->where);
9724 : 0 : variant_proc_sym = NULL;
9725 : : }
9726 : 295 : else if (omp_get_context_selector (set_selectors,
9727 : : OMP_TRAIT_SET_CONSTRUCT,
9728 : : OMP_TRAIT_CONSTRUCT_SIMD)
9729 : : == NULL_TREE)
9730 : : {
9731 : 281 : char err[256];
9732 : 281 : gfc_formal_arglist *last_arg = NULL, *extra_arg = NULL;
9733 : 281 : int nappend_args = 0;
9734 : 281 : if (odv->append_args_list)
9735 : : {
9736 : 26 : gfc_formal_arglist *arg;
9737 : 26 : int nargs = 0;
9738 : 26 : for (arg = gfc_sym_get_dummy_args (ns->proc_name);
9739 : 56 : arg; arg = arg->next)
9740 : 30 : nargs++;
9741 : :
9742 : 26 : last_arg = gfc_sym_get_dummy_args (variant_proc_sym);
9743 : 33 : for (int i = 1 ; i < nargs && last_arg; i++)
9744 : 7 : last_arg = last_arg->next;
9745 : 26 : if (nargs == 0)
9746 : : {
9747 : 3 : extra_arg = last_arg;
9748 : 3 : last_arg = NULL;
9749 : 3 : variant_proc_sym->formal = NULL;
9750 : : }
9751 : 23 : else if (last_arg)
9752 : : {
9753 : 23 : extra_arg = last_arg->next;
9754 : 23 : last_arg->next = NULL;
9755 : : }
9756 : 76 : for (gfc_omp_namelist *n = odv->append_args_list; n != NULL;
9757 : 50 : n = n->next)
9758 : 50 : nappend_args++;
9759 : : }
9760 : 281 : if (!gfc_compare_interfaces (ns->proc_name, variant_proc_sym,
9761 : : variant_proc_sym->name, 0, 1,
9762 : : err, sizeof (err), NULL, NULL))
9763 : : {
9764 : 2 : gfc_error ("variant %qs and base %qs at %L have "
9765 : : "incompatible types: %s",
9766 : 2 : variant_proc_name, ns->proc_name->name,
9767 : : &odv->where, err);
9768 : 2 : if (nappend_args)
9769 : 0 : inform (gfc_get_location (&odv->append_args_list->where),
9770 : : "%<append_args%> clause implies that %qs has %d "
9771 : : "dummy arguments of integer type with "
9772 : : "%<omp_interop_kind%> kind", variant_proc_name,
9773 : : nappend_args);
9774 : : variant_proc_sym = NULL;
9775 : : }
9776 : 281 : if (last_arg)
9777 : 23 : last_arg->next = extra_arg;
9778 : 258 : else if (extra_arg)
9779 : 3 : variant_proc_sym->formal = extra_arg;
9780 : 26 : locus *loc = (odv->append_args_list
9781 : 281 : ? &odv->append_args_list->where : &odv->where);
9782 : 281 : int nextra_arg = 0;
9783 : 334 : for (; extra_arg; extra_arg = extra_arg->next)
9784 : : {
9785 : 53 : nextra_arg++;
9786 : 53 : if (!variant_proc_sym)
9787 : 8 : continue;
9788 : 45 : if (extra_arg->sym->ts.type != BT_INTEGER
9789 : 43 : || extra_arg->sym->ts.kind != gfc_index_integer_kind
9790 : 42 : || extra_arg->sym->attr.dimension
9791 : 40 : || extra_arg->sym->attr.codimension
9792 : 39 : || extra_arg->sym->attr.pointer
9793 : 38 : || extra_arg->sym->attr.allocatable
9794 : 37 : || extra_arg->sym->attr.proc_pointer)
9795 : : {
9796 : 8 : gfc_error ("%qs at %L must be a nonpointer, "
9797 : : "nonallocatable scalar integer dummy argument "
9798 : : "of %<omp_interop_kind%> kind as it utilized "
9799 : : "with the %<append_args%> clause at %L",
9800 : : extra_arg->sym->name,
9801 : : &extra_arg->sym->declared_at, loc);
9802 : 8 : variant_proc_sym = NULL;
9803 : : }
9804 : 45 : if (extra_arg->sym->attr.optional)
9805 : : {
9806 : 2 : gfc_error ("%qs at %L with OPTIONAL attribute "
9807 : : "not support when utilized with the "
9808 : : "%<append_args%> clause at %L",
9809 : : extra_arg->sym->name,
9810 : : &extra_arg->sym->declared_at, loc);
9811 : 2 : variant_proc_sym = NULL;
9812 : : }
9813 : : }
9814 : 281 : if (variant_proc_sym && nappend_args != nextra_arg)
9815 : : {
9816 : 1 : gfc_error ("%qs at %L has %d but requires %d "
9817 : : "%<omp_interop_kind%> kind dummy arguments as it "
9818 : : "is utilized with the %<append_args%> clause at "
9819 : : "%L", variant_proc_sym->name,
9820 : : &variant_proc_sym->declared_at, nextra_arg,
9821 : : nappend_args, loc);
9822 : 1 : variant_proc_sym = NULL;
9823 : : }
9824 : : }
9825 : 249 : if ((odv->adjust_args_list != NULL || odv->append_args_list != NULL)
9826 : 320 : && omp_get_context_selector (set_selectors,
9827 : : OMP_TRAIT_SET_CONSTRUCT,
9828 : : OMP_TRAIT_CONSTRUCT_DISPATCH)
9829 : : == NULL_TREE)
9830 : : {
9831 : 6 : gfc_error ("the %qs clause can only be specified if "
9832 : : "the %<dispatch%> selector of the construct "
9833 : : "selector set appears in the %<match%> clause at %L",
9834 : 3 : odv->adjust_args_list ? "adjust_args" : "append_args",
9835 : : &odv->where);
9836 : 3 : variant_proc_sym = NULL;
9837 : : }
9838 : 295 : if (variant_proc_sym != NULL)
9839 : : {
9840 : 280 : gfc_set_sym_referenced (variant_proc_sym);
9841 : 280 : tree construct
9842 : 280 : = omp_get_context_selector_list (set_selectors,
9843 : : OMP_TRAIT_SET_CONSTRUCT);
9844 : 280 : omp_mark_declare_variant (gfc_get_location (&odv->where),
9845 : : gfc_get_symbol_decl (variant_proc_sym),
9846 : : construct);
9847 : 280 : if (omp_context_selector_matches (set_selectors,
9848 : : NULL_TREE, false))
9849 : : {
9850 : 201 : tree need_device_ptr_list = NULL_TREE;
9851 : 201 : tree need_device_addr_list = NULL_TREE;
9852 : 201 : tree append_args_tree = NULL_TREE;
9853 : 201 : tree id = get_identifier ("omp declare variant base");
9854 : 201 : tree variant = gfc_get_symbol_decl (variant_proc_sym);
9855 : 201 : DECL_ATTRIBUTES (base_fn_decl)
9856 : 201 : = tree_cons (id, build_tree_list (variant, set_selectors),
9857 : 201 : DECL_ATTRIBUTES (base_fn_decl));
9858 : 201 : int arg_idx_offset = 0;
9859 : 201 : if (gfc_return_by_reference (ns->proc_name))
9860 : : {
9861 : 2 : arg_idx_offset++;
9862 : 2 : if (ns->proc_name->ts.type == BT_CHARACTER)
9863 : 2 : arg_idx_offset++;
9864 : : }
9865 : 201 : int nargs = 0;
9866 : 201 : for (gfc_formal_arglist *arg
9867 : 201 : = gfc_sym_get_dummy_args (ns->proc_name);
9868 : 442 : arg; arg = arg->next)
9869 : 241 : nargs++;
9870 : 201 : if (odv->append_args_list)
9871 : : {
9872 : 14 : int append_arg_no = arg_idx_offset + nargs;
9873 : 14 : tree last_arg = NULL_TREE;
9874 : 14 : for (gfc_omp_namelist *n = odv->append_args_list;
9875 : 43 : n != NULL; n = n->next)
9876 : : {
9877 : 29 : tree pref = NULL_TREE;
9878 : 29 : if (n->u.init.len)
9879 : : {
9880 : 22 : pref = build_string (n->u.init.len,
9881 : 11 : n->u2.init_interop);
9882 : 11 : TREE_TYPE (pref) = build_array_type_nelts (
9883 : : unsigned_char_type_node,
9884 : 11 : n->u.init.len);
9885 : : }
9886 : : /* Save location, (target + target sync) and
9887 : : prefer_type list in a tree list. */
9888 : 29 : tree t = build_tree_list (n->u.init.target
9889 : : ? boolean_true_node
9890 : : : boolean_false_node,
9891 : 29 : n->u.init.targetsync
9892 : : ? boolean_true_node
9893 : : : boolean_false_node);
9894 : 29 : t = build1_loc (gfc_get_location (&n->where),
9895 : : NOP_EXPR, void_type_node, t);
9896 : 29 : t = build_tree_list (t, pref);
9897 : 29 : if (append_args_tree)
9898 : : {
9899 : 15 : TREE_CHAIN (last_arg) = t;
9900 : 15 : last_arg = t;
9901 : : }
9902 : : else
9903 : : append_args_tree = last_arg = t;
9904 : : }
9905 : : /* Store as 'purpose' = arg number to be used for inserting
9906 : : and 'value' = list of interop items. */
9907 : 14 : append_args_tree = build_tree_list (
9908 : : build_int_cst (integer_type_node,
9909 : 14 : append_arg_no),
9910 : : append_args_tree);
9911 : : }
9912 : 201 : vec<gfc_symbol *> adjust_args_list = vNULL;
9913 : 201 : for (gfc_omp_namelist *arg_list = odv->adjust_args_list;
9914 : 311 : arg_list != NULL; arg_list = arg_list->next)
9915 : : {
9916 : 110 : int from, to;
9917 : 110 : if (arg_list->expr == NULL || arg_list->sym)
9918 : 204 : from = ((arg_list->u.adj_args.omp_num_args_minus
9919 : 94 : || arg_list->u.adj_args.omp_num_args_plus)
9920 : 94 : ? nargs : 1);
9921 : : else
9922 : : {
9923 : 16 : if (arg_list->u.adj_args.omp_num_args_plus)
9924 : 0 : mpz_add_ui (arg_list->expr->value.integer,
9925 : 0 : arg_list->expr->value.integer, nargs);
9926 : 16 : if (arg_list->u.adj_args.omp_num_args_minus)
9927 : 2 : mpz_ui_sub (arg_list->expr->value.integer, nargs,
9928 : 2 : arg_list->expr->value.integer);
9929 : 16 : if (mpz_sgn (arg_list->expr->value.integer) <= 0)
9930 : : {
9931 : 1 : gfc_warning (OPT_Wopenmp,
9932 : : "Expected positive argument index "
9933 : : "at %L", &arg_list->where);
9934 : 1 : from = 1;
9935 : : }
9936 : : else
9937 : 15 : from
9938 : 15 : = (mpz_fits_sint_p (arg_list->expr->value.integer)
9939 : 15 : ? mpz_get_si (arg_list->expr->value.integer)
9940 : : : INT_MAX);
9941 : 16 : if (from > nargs)
9942 : 1 : gfc_warning (OPT_Wopenmp,
9943 : : "Argument index at %L exceeds number "
9944 : : "of arguments %d", &arg_list->where,
9945 : : nargs);
9946 : : }
9947 : 110 : locus loc = arg_list->where;
9948 : 110 : if (!arg_list->u.adj_args.range_start)
9949 : : to = from;
9950 : : else
9951 : : {
9952 : 6 : loc = gfc_get_location_range (&arg_list->where, 0,
9953 : : &arg_list->where, 0,
9954 : 6 : &arg_list->next->where);
9955 : 6 : if (arg_list->next->expr == NULL)
9956 : : to = nargs;
9957 : : else
9958 : : {
9959 : 4 : if (arg_list->next->u.adj_args.omp_num_args_plus)
9960 : 0 : mpz_add_ui (arg_list->next->expr->value.integer,
9961 : 0 : arg_list->next->expr->value.integer,
9962 : : nargs);
9963 : 4 : if (arg_list->next->u.adj_args.omp_num_args_minus)
9964 : 2 : mpz_ui_sub (arg_list->next->expr->value.integer,
9965 : : nargs,
9966 : 2 : arg_list->next->expr->value.integer);
9967 : 4 : if (mpz_sgn (arg_list->next->expr->value.integer)
9968 : : <= 0)
9969 : : {
9970 : 0 : gfc_warning (OPT_Wopenmp,
9971 : : "Expected positive argument "
9972 : : "index at %L", &loc);
9973 : 0 : to = 0;
9974 : : }
9975 : : else
9976 : 4 : to = mpz_get_si (
9977 : 4 : arg_list->next->expr->value.integer);
9978 : : }
9979 : 6 : if (from > to && to != 0)
9980 : 1 : gfc_warning (OPT_Wopenmp,
9981 : : "Upper argument index smaller than "
9982 : : "lower one at %L", &loc);
9983 : 6 : if (to > nargs)
9984 : : to = nargs;
9985 : 6 : arg_list = arg_list->next;
9986 : : }
9987 : 110 : if (from > nargs)
9988 : 1 : continue;
9989 : : /* Change to zero based index. */
9990 : 109 : from--; to--;
9991 : 109 : gfc_formal_arglist *arg = ns->proc_name->formal;
9992 : 109 : if (!arg_list->sym && to >= from)
9993 : 35 : for (int idx = 0; idx < from; idx++)
9994 : 18 : arg = arg->next;
9995 : 223 : for (int idx = from; idx <= to; idx++)
9996 : : {
9997 : 114 : if (idx > from)
9998 : 6 : arg = arg->next;
9999 : 114 : if (arg_list->sym)
10000 : : {
10001 : 91 : for (arg = ns->proc_name->formal, idx = 0;
10002 : 201 : arg != NULL; arg = arg->next, idx++)
10003 : 200 : if (arg->sym == arg_list->sym)
10004 : : break;
10005 : 91 : if (!arg || !arg_list->sym->attr.dummy)
10006 : : {
10007 : 1 : gfc_error ("List item %qs at %L, declared at "
10008 : : "%L, is not a dummy argument",
10009 : : arg_list->sym->name, &loc,
10010 : : &arg_list->sym->declared_at);
10011 : 1 : continue;
10012 : : }
10013 : : }
10014 : 113 : if (arg_list->u.adj_args.need_ptr
10015 : 82 : && (arg->sym->ts.f90_type != BT_VOID
10016 : 80 : || !arg->sym->ts.u.derived->ts.is_iso_c
10017 : 80 : || (arg->sym->ts.u.derived->intmod_sym_id
10018 : : != ISOCBINDING_PTR)
10019 : 79 : || arg->sym->attr.dimension))
10020 : : {
10021 : 6 : gfc_error ("Argument %qs at %L to list item in "
10022 : : "%<need_device_ptr%> at %L must be a "
10023 : : "scalar of TYPE(C_PTR)",
10024 : : arg->sym->name,
10025 : : &arg->sym->declared_at, &loc);
10026 : 6 : if (!arg->sym->attr.value)
10027 : 6 : inform (gfc_get_location (&loc),
10028 : : "Consider using %<need_device_addr%> "
10029 : : "instead");
10030 : 6 : continue;
10031 : : }
10032 : 107 : if (arg_list->u.adj_args.need_addr
10033 : 11 : && arg->sym->attr.value)
10034 : : {
10035 : 1 : gfc_error ("Argument %qs at %L to list item in "
10036 : : "%<need_device_addr%> at %L must not "
10037 : : "have the VALUE attribute",
10038 : : arg->sym->name,
10039 : : &arg->sym->declared_at, &loc);
10040 : 1 : continue;
10041 : : }
10042 : 106 : if (adjust_args_list.contains (arg->sym))
10043 : : {
10044 : 7 : gfc_error ("%qs at %L is specified more than "
10045 : 7 : "once", arg->sym->name, &loc);
10046 : 7 : continue;
10047 : : }
10048 : 99 : adjust_args_list.safe_push (arg->sym);
10049 : :
10050 : 99 : if (arg_list->u.adj_args.need_addr)
10051 : : {
10052 : : /* TODO: Has to to support OPTIONAL and array
10053 : : descriptors; should check for CLASS, coarrays?
10054 : : Reject "abc" and 123 as actual arguments (in
10055 : : gimplify.cc or in the FE? Reject noncontiguous
10056 : : actuals? Cf. also PR C++/118859.
10057 : : Also check array-valued type(c_ptr). */
10058 : 7 : static bool warned = false;
10059 : 7 : if (!warned)
10060 : 1 : sorry_at (gfc_get_location (&loc),
10061 : : "%<need_device_addr%> not yet "
10062 : : "supported");
10063 : 7 : warned = true;
10064 : 7 : continue;
10065 : 7 : }
10066 : 92 : if (arg_list->u.adj_args.need_ptr
10067 : : || arg_list->u.adj_args.need_addr)
10068 : : {
10069 : : // Store 0-based argument index,
10070 : : // as in gimplify_call_expr
10071 : 74 : tree t
10072 : 74 : = build_tree_list (
10073 : : NULL_TREE,
10074 : : build_int_cst (integer_type_node,
10075 : 74 : idx + arg_idx_offset));
10076 : 74 : if (arg_list->u.adj_args.need_ptr)
10077 : 74 : need_device_ptr_list
10078 : 74 : = chainon (need_device_ptr_list, t);
10079 : : else
10080 : 0 : need_device_addr_list
10081 : 0 : = chainon (need_device_addr_list, t);
10082 : : }
10083 : : }
10084 : : }
10085 : 201 : tree t = NULL_TREE;
10086 : 201 : if (need_device_ptr_list
10087 : 201 : || need_device_addr_list
10088 : 165 : || append_args_tree)
10089 : : {
10090 : 50 : t = build_tree_list (need_device_ptr_list,
10091 : : need_device_addr_list),
10092 : 50 : TREE_CHAIN (t) = append_args_tree;
10093 : 50 : DECL_ATTRIBUTES (variant) = tree_cons (
10094 : : get_identifier ("omp declare variant variant args"), t,
10095 : 50 : DECL_ATTRIBUTES (variant));
10096 : : }
10097 : : }
10098 : : }
10099 : : }
10100 : : }
10101 : 10017 : }
10102 : :
10103 : : /* Add ptr for tracking as being allocated by GOMP_alloc. */
10104 : :
10105 : : tree
10106 : 29 : gfc_omp_call_add_alloc (tree ptr)
10107 : : {
10108 : 29 : static tree fn = NULL_TREE;
10109 : 29 : if (fn == NULL_TREE)
10110 : : {
10111 : 6 : fn = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10112 : 6 : tree att = build_tree_list (NULL_TREE, build_string (4, ". R "));
10113 : 6 : att = tree_cons (get_identifier ("fn spec"), att, TYPE_ATTRIBUTES (fn));
10114 : 6 : fn = build_type_attribute_variant (fn, att);
10115 : 6 : fn = build_fn_decl ("GOMP_add_alloc", fn);
10116 : : }
10117 : 29 : return build_call_expr_loc (input_location, fn, 1, ptr);
10118 : : }
10119 : :
10120 : : /* Generated function returns true when it was tracked via GOMP_add_alloc and
10121 : : removes it from the tracking. As called just before GOMP_free or omp_realloc
10122 : : the pointer is or might become invalid, thus, it is always removed. */
10123 : :
10124 : : tree
10125 : 47 : gfc_omp_call_is_alloc (tree ptr)
10126 : : {
10127 : 47 : static tree fn = NULL_TREE;
10128 : 47 : if (fn == NULL_TREE)
10129 : : {
10130 : 6 : fn = build_function_type_list (boolean_type_node, ptr_type_node,
10131 : : NULL_TREE);
10132 : 6 : tree att = build_tree_list (NULL_TREE, build_string (4, ". R "));
10133 : 6 : att = tree_cons (get_identifier ("fn spec"), att, TYPE_ATTRIBUTES (fn));
10134 : 6 : fn = build_type_attribute_variant (fn, att);
10135 : 6 : fn = build_fn_decl ("GOMP_is_alloc", fn);
10136 : : }
10137 : 47 : return build_call_expr_loc (input_location, fn, 1, ptr);
10138 : : }
10139 : :
10140 : : tree
10141 : 76 : gfc_trans_omp_metadirective (gfc_code *code)
10142 : : {
10143 : 76 : gfc_omp_variant *variant = code->ext.omp_variants;
10144 : :
10145 : 76 : tree metadirective_tree = make_node (OMP_METADIRECTIVE);
10146 : 76 : SET_EXPR_LOCATION (metadirective_tree, gfc_get_location (&code->loc));
10147 : 76 : TREE_TYPE (metadirective_tree) = void_type_node;
10148 : 76 : OMP_METADIRECTIVE_VARIANTS (metadirective_tree) = NULL_TREE;
10149 : :
10150 : 76 : tree tree_body = NULL_TREE;
10151 : :
10152 : 247 : while (variant)
10153 : : {
10154 : 171 : tree ctx = gfc_trans_omp_set_selector (variant->selectors,
10155 : : variant->where);
10156 : 171 : ctx = omp_check_context_selector (gfc_get_location (&variant->where),
10157 : : ctx, OMP_CTX_METADIRECTIVE);
10158 : 171 : if (ctx == error_mark_node)
10159 : : return error_mark_node;
10160 : :
10161 : : /* If the selector doesn't match, drop the whole variant. */
10162 : 171 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
10163 : : {
10164 : 23 : variant = variant->next;
10165 : 23 : continue;
10166 : : }
10167 : :
10168 : 148 : gfc_code *next_code = variant->code->next;
10169 : 148 : if (next_code && tree_body == NULL_TREE)
10170 : 17 : tree_body = gfc_trans_code (next_code);
10171 : :
10172 : 148 : if (next_code)
10173 : 19 : variant->code->next = NULL;
10174 : 148 : tree directive = gfc_trans_code (variant->code);
10175 : 148 : if (next_code)
10176 : 19 : variant->code->next = next_code;
10177 : :
10178 : 19 : tree body = next_code ? tree_body : NULL_TREE;
10179 : 148 : tree omp_variant = make_omp_metadirective_variant (ctx, directive, body);
10180 : 296 : OMP_METADIRECTIVE_VARIANTS (metadirective_tree)
10181 : 148 : = chainon (OMP_METADIRECTIVE_VARIANTS (metadirective_tree),
10182 : : omp_variant);
10183 : 148 : variant = variant->next;
10184 : : }
10185 : :
10186 : : /* TODO: Resolve the metadirective here if possible. */
10187 : :
10188 : : return metadirective_tree;
10189 : : }
|