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 : 5941 : gfc_omp_is_allocatable_or_ptr (const_tree decl)
66 : : {
67 : 5941 : return (DECL_P (decl)
68 : 5941 : && (GFC_DECL_GET_SCALAR_POINTER (decl)
69 : 4210 : || 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 : 45979 : gfc_omp_is_optional_argument (const_tree decl)
81 : : {
82 : : /* Note: VAR_DECL can occur with BIND(C) and array descriptors. */
83 : 30192 : return ((TREE_CODE (decl) == PARM_DECL || VAR_P (decl))
84 : 45979 : && DECL_LANG_SPECIFIC (decl)
85 : 20757 : && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
86 : 20573 : && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
87 : 20338 : && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != FUNCTION_TYPE
88 : 66292 : && 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 : 21789 : gfc_omp_check_optional_argument (tree decl, bool for_present_check)
101 : : {
102 : 21789 : if (!for_present_check)
103 : 2168 : return gfc_omp_is_optional_argument (decl) ? decl : NULL_TREE;
104 : :
105 : 19621 : if (!DECL_LANG_SPECIFIC (decl))
106 : : return NULL_TREE;
107 : :
108 : 5235 : tree orig_decl = decl;
109 : :
110 : : /* For assumed-shape arrays, a local decl with arg->data is used. */
111 : 5235 : if (TREE_CODE (decl) != PARM_DECL
112 : 5235 : && (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
113 : 1843 : || GFC_ARRAY_TYPE_P (TREE_TYPE (decl))))
114 : 726 : decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
115 : :
116 : : /* Note: With BIND(C), array descriptors are converted to a VAR_DECL. */
117 : 5235 : if (decl == NULL_TREE
118 : 5116 : || (TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != VAR_DECL)
119 : 5116 : || !DECL_LANG_SPECIFIC (decl)
120 : 9947 : || !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 : 18605 : gfc_omp_array_data (tree decl, bool type_only)
159 : : {
160 : 18605 : tree type = TREE_TYPE (decl);
161 : :
162 : 18605 : if (POINTER_TYPE_P (type))
163 : 10154 : type = TREE_TYPE (type);
164 : :
165 : 18605 : 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 : 456234 : gfc_omp_privatize_by_reference (const_tree decl)
226 : : {
227 : 456234 : tree type = TREE_TYPE (decl);
228 : :
229 : 456234 : if (TREE_CODE (type) == REFERENCE_TYPE
230 : 456234 : && (!DECL_ARTIFICIAL (decl) || TREE_CODE (decl) == PARM_DECL))
231 : : return true;
232 : :
233 : 432966 : if (TREE_CODE (type) == POINTER_TYPE
234 : 432966 : && gfc_omp_is_optional_argument (decl))
235 : : return true;
236 : :
237 : 423880 : if (TREE_CODE (type) == POINTER_TYPE)
238 : : {
239 : 32604 : 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 : 32604 : if (GFC_DECL_GET_SCALAR_POINTER (decl)
247 : 31098 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
248 : 28755 : || GFC_DECL_CRAY_POINTEE (decl)
249 : 28749 : || GFC_DECL_ASSOCIATE_VAR_P (decl)
250 : 38111 : || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
251 : : return false;
252 : :
253 : 20856 : if (!DECL_ARTIFICIAL (decl)
254 : 20856 : && 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 : 13483 : if (DECL_LANG_SPECIFIC (decl)
260 : 13483 : && 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 : 8420 : 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 : 8420 : 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 : 8375 : if (DECL_ARTIFICIAL (decl)
287 : 1579 : && ! GFC_DECL_RESULT (decl)
288 : 9930 : && ! (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 : 3843 : gfc_omp_predetermined_mapping (tree decl)
345 : : {
346 : 3843 : if (DECL_ARTIFICIAL (decl)
347 : 870 : && ! GFC_DECL_RESULT (decl)
348 : 4707 : && ! (DECL_LANG_SPECIFIC (decl)
349 : 68 : && 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 : 3022 : if (TREE_CODE (decl) == PARM_DECL
357 : 1809 : && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
358 : 3399 : && 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 : 1213 : if (VAR_P (decl) && TREE_READONLY (decl)
363 : 3015 : && (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 : 119903 : gfc_has_alloc_comps (tree type, tree decl, bool ptr_ok,
391 : : bool shallow_alloc_only=false)
392 : : {
393 : 119903 : tree field, ftype;
394 : :
395 : 119903 : 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 : 119720 : if (!ptr_ok
405 : 97949 : && GFC_DESCRIPTOR_TYPE_P (type)
406 : 122866 : && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
407 : 2886 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
408 : : return false;
409 : :
410 : 119457 : if (GFC_DESCRIPTOR_TYPE_P (type) || GFC_ARRAY_TYPE_P (type))
411 : 11822 : type = gfc_get_element_type (type);
412 : :
413 : 119457 : if (TREE_CODE (type) != RECORD_TYPE)
414 : : return false;
415 : :
416 : 9239 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
417 : : {
418 : 8258 : ftype = TREE_TYPE (field);
419 : 8258 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field))
420 : : return true;
421 : 7690 : if (GFC_DESCRIPTOR_TYPE_P (ftype)
422 : 7690 : && GFC_TYPE_ARRAY_AKIND (ftype) == GFC_ARRAY_ALLOCATABLE)
423 : : return true;
424 : 5693 : if (!shallow_alloc_only
425 : 5693 : && 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 : 63533 : gfc_is_polymorphic_nonptr (tree type)
473 : : {
474 : 63533 : if (POINTER_TYPE_P (type))
475 : 3630 : type = TREE_TYPE (type);
476 : 63533 : 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 : 77 : gfc_is_unlimited_polymorphic_nonptr (tree type)
484 : : {
485 : 77 : if (POINTER_TYPE_P (type))
486 : 0 : type = TREE_TYPE (type);
487 : 77 : if (!GFC_CLASS_TYPE_P (type))
488 : : return false;
489 : :
490 : 77 : tree field = TYPE_FIELDS (type); /* _data */
491 : 77 : gcc_assert (field);
492 : 77 : field = DECL_CHAIN (field); /* _vptr */
493 : 77 : gcc_assert (field);
494 : 77 : field = DECL_CHAIN (field);
495 : 77 : 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 : 3843 : gfc_omp_allocatable_p (tree decl)
505 : : {
506 : 3843 : if (!DECL_P (decl))
507 : : return false;
508 : :
509 : 3843 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
510 : : return true;
511 : :
512 : 3623 : tree type = TREE_TYPE (decl);
513 : 3623 : if (gfc_omp_privatize_by_reference (decl))
514 : 1796 : type = TREE_TYPE (type);
515 : :
516 : 3623 : if (GFC_DESCRIPTOR_TYPE_P (type)
517 : 3623 : && 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 : 14436 : gfc_omp_private_outer_ref (tree decl)
528 : : {
529 : 14436 : tree type = TREE_TYPE (decl);
530 : :
531 : 14436 : if (gfc_omp_privatize_by_reference (decl))
532 : 617 : type = TREE_TYPE (type);
533 : :
534 : 14436 : if (GFC_DESCRIPTOR_TYPE_P (type)
535 : 14436 : && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
536 : : return true;
537 : :
538 : 14310 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))
539 : : return true;
540 : :
541 : 14224 : 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 : 20345 : gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer)
778 : : {
779 : 20345 : tree type = TREE_TYPE (decl), size, ptr, cond, then_b, else_b;
780 : 20345 : stmtblock_t block, cond_block;
781 : :
782 : 20345 : 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 : 20318 : case OMP_CLAUSE_PRIVATE:
790 : 20318 : case OMP_CLAUSE_LASTPRIVATE:
791 : 20318 : case OMP_CLAUSE_LINEAR:
792 : 20318 : case OMP_CLAUSE_REDUCTION:
793 : 20318 : case OMP_CLAUSE_IN_REDUCTION:
794 : 20318 : case OMP_CLAUSE_TASK_REDUCTION:
795 : 20318 : break;
796 : 0 : default:
797 : 0 : gcc_unreachable ();
798 : : }
799 : :
800 : 20318 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
801 : 263 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
802 : 20337 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
803 : 85 : || !POINTER_TYPE_P (type)))
804 : : {
805 : 19989 : 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 : 9195 : gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
905 : : {
906 : 9195 : tree type = TREE_TYPE (dest), ptr, size, call;
907 : 9195 : tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
908 : 9195 : tree cond, then_b, else_b;
909 : 9195 : stmtblock_t block, cond_block;
910 : :
911 : 9195 : 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 : 9195 : if (DECL_P (OMP_CLAUSE_DECL (clause))
916 : 9195 : && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
917 : 27 : return build2 (MODIFY_EXPR, TREE_TYPE (dest), dest, src);
918 : :
919 : 9168 : if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
920 : 6136 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
921 : 9349 : && 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 : 9168 : 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 : 24 : 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 : 9128 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
995 : 138 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
996 : 9152 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
997 : 77 : || !POINTER_TYPE_P (type)))
998 : : {
999 : 8939 : 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 : 8919 : 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 : 32010 : gfc_omp_clause_dtor (tree clause, tree decl)
1428 : : {
1429 : 32010 : tree type = TREE_TYPE (decl), tem;
1430 : 32010 : tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
1431 : :
1432 : : /* Only pointer was privatized; cf. gfc_omp_clause_copy_ctor. */
1433 : 32010 : if (DECL_P (OMP_CLAUSE_DECL (clause))
1434 : 32010 : && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause)))
1435 : : return NULL_TREE;
1436 : :
1437 : 31983 : if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
1438 : 11863 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
1439 : 32336 : && 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 : 31983 : 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 : 31946 : if ((! GFC_DESCRIPTOR_TYPE_P (type)
1488 : 433 : || GFC_TYPE_ARRAY_AKIND (type) != GFC_ARRAY_ALLOCATABLE)
1489 : 31997 : && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
1490 : 186 : || !POINTER_TYPE_P (type)))
1491 : : {
1492 : 31380 : 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 : 28522 : gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc)
1587 : : {
1588 : 28522 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
1589 : : return;
1590 : :
1591 : 6894 : tree decl = OMP_CLAUSE_DECL (c);
1592 : 6894 : 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 : 6894 : 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 : 7263 : && 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 : 6893 : tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
1609 : 6893 : tree present = gfc_omp_check_optional_argument (decl, true);
1610 : 6893 : tree orig_decl = NULL_TREE;
1611 : 6893 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
1612 : : {
1613 : 1285 : if (!gfc_omp_privatize_by_reference (decl)
1614 : 155 : && !GFC_DECL_GET_SCALAR_POINTER (decl)
1615 : 91 : && !GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
1616 : 3 : && !GFC_DECL_CRAY_POINTEE (decl)
1617 : 1288 : && !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
1618 : : return;
1619 : 1282 : orig_decl = decl;
1620 : :
1621 : 1282 : c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1622 : 1282 : OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
1623 : 1282 : OMP_CLAUSE_DECL (c4) = decl;
1624 : 1282 : OMP_CLAUSE_SIZE (c4) = size_int (0);
1625 : 1282 : decl = build_fold_indirect_ref (decl);
1626 : 1282 : if (present
1627 : 1282 : && (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 : 1215 : OMP_CLAUSE_DECL (c) = decl;
1648 : 1215 : OMP_CLAUSE_SIZE (c) = NULL_TREE;
1649 : : }
1650 : 1282 : if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
1651 : 1282 : && (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 : 6890 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
1663 : : {
1664 : 1729 : stmtblock_t block;
1665 : 1729 : gfc_start_block (&block);
1666 : 1729 : tree type = TREE_TYPE (decl);
1667 : 1729 : 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 : 1729 : bool always_modifier = false;
1674 : :
1675 : 1729 : if (!openacc
1676 : 1729 : && !(TYPE_QUALS (TREE_TYPE (ptr)) & TYPE_QUAL_RESTRICT))
1677 : : always_modifier = true;
1678 : :
1679 : 1729 : if (present)
1680 : 56 : ptr = gfc_build_cond_assign_expr (&block, present, ptr,
1681 : : null_pointer_node);
1682 : 1729 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
1683 : 1729 : ptr = build_fold_indirect_ref (ptr);
1684 : 1729 : OMP_CLAUSE_DECL (c) = ptr;
1685 : 1729 : c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
1686 : 1729 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_TO_PSET);
1687 : 1729 : 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 : 1673 : OMP_CLAUSE_DECL (c2) = decl;
1696 : 1729 : OMP_CLAUSE_SIZE (c2) = TYPE_SIZE_UNIT (type);
1697 : 1729 : c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
1698 : 3247 : OMP_CLAUSE_SET_MAP_KIND (c3, always_modifier ? GOMP_MAP_ALWAYS_POINTER
1699 : : : GOMP_MAP_POINTER);
1700 : 1729 : 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 : 1673 : OMP_CLAUSE_DECL (c3) = gfc_conv_descriptor_data_get (decl);
1711 : 1729 : OMP_CLAUSE_SIZE (c3) = size_int (0);
1712 : 1729 : tree size = create_tmp_var (gfc_array_index_type);
1713 : 1729 : tree elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
1714 : 1729 : elemsz = fold_convert (gfc_array_index_type, elemsz);
1715 : :
1716 : 1729 : if (orig_decl == NULL_TREE)
1717 : 1495 : orig_decl = decl;
1718 : 1729 : if (!openacc
1719 : 1729 : && 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 : 1729 : enum gfc_array_kind akind = GFC_TYPE_ARRAY_AKIND (type);
1727 : 1729 : if (akind == GFC_ARRAY_ALLOCATABLE
1728 : : || akind == GFC_ARRAY_POINTER
1729 : 1729 : || akind == GFC_ARRAY_POINTER_CONT
1730 : 1729 : || akind == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
1731 : : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER
1732 : 1 : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT)
1733 : : {
1734 : 1728 : stmtblock_t cond_block;
1735 : 1728 : tree tem, then_b, else_b, zero, cond;
1736 : :
1737 : 1728 : int rank = ((akind == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
1738 : : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER
1739 : 1728 : || akind == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT)
1740 : 1728 : ? -1 : GFC_TYPE_ARRAY_RANK (type));
1741 : 1728 : gfc_init_block (&cond_block);
1742 : 1728 : tem = gfc_full_array_size (&cond_block, unshare_expr (decl), rank);
1743 : 1728 : gfc_add_modify (&cond_block, size, tem);
1744 : 1728 : gfc_add_modify (&cond_block, size,
1745 : : fold_build2 (MULT_EXPR, gfc_array_index_type,
1746 : : size, elemsz));
1747 : 1728 : then_b = gfc_finish_block (&cond_block);
1748 : 1728 : gfc_init_block (&cond_block);
1749 : 1728 : zero = build_int_cst (gfc_array_index_type, 0);
1750 : 1728 : gfc_add_modify (&cond_block, size, zero);
1751 : 1728 : else_b = gfc_finish_block (&cond_block);
1752 : 1728 : tem = gfc_conv_descriptor_data_get (unshare_expr (decl));
1753 : 1728 : tem = fold_convert (pvoid_type_node, tem);
1754 : 1728 : cond = fold_build2_loc (loc, NE_EXPR,
1755 : : boolean_type_node, tem, null_pointer_node);
1756 : 1728 : if (present)
1757 : : {
1758 : 55 : cond = fold_build2_loc (loc, TRUTH_ANDIF_EXPR,
1759 : : boolean_type_node, present, cond);
1760 : : }
1761 : 1728 : gfc_add_expr_to_block (&block, build3_loc (loc, COND_EXPR,
1762 : : void_type_node, cond,
1763 : : then_b, else_b));
1764 : 1728 : }
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 : 1 : 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 : 1729 : OMP_CLAUSE_SIZE (c) = size;
1798 : 1729 : tree stmt = gfc_finish_block (&block);
1799 : 1729 : gimplify_and_add (stmt, pre_p);
1800 : : }
1801 : : else
1802 : : {
1803 : 5161 : if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
1804 : 1191 : OMP_CLAUSE_SIZE (c)
1805 : 3363 : = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
1806 : 981 : : TYPE_SIZE_UNIT (TREE_TYPE (decl));
1807 : :
1808 : 5161 : tree type = TREE_TYPE (decl);
1809 : 5161 : if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE (type)))
1810 : 0 : type = TREE_TYPE (type);
1811 : 5161 : if (!openacc
1812 : 5161 : && orig_decl != NULL_TREE
1813 : 5161 : && 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 : 19 : tree size = create_tmp_var (TREE_TYPE (OMP_CLAUSE_SIZE (c)));
1818 : 19 : gfc_allocate_lang_decl (size);
1819 : 19 : GFC_DECL_SAVED_DESCRIPTOR (size) = orig_decl;
1820 : 19 : gimplify_assign (size, OMP_CLAUSE_SIZE (c), pre_p);
1821 : 19 : OMP_CLAUSE_SIZE (c) = size;
1822 : : }
1823 : : }
1824 : 6890 : tree last = c;
1825 : 6890 : 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 : 6890 : if (c2)
1829 : : {
1830 : 1796 : OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (last);
1831 : 1796 : OMP_CLAUSE_CHAIN (last) = c2;
1832 : 1796 : last = c2;
1833 : : }
1834 : 6890 : if (c3)
1835 : : {
1836 : 1796 : OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (last);
1837 : 1796 : OMP_CLAUSE_CHAIN (last) = c3;
1838 : 1796 : last = c3;
1839 : : }
1840 : 6890 : if (c4)
1841 : : {
1842 : 1282 : OMP_CLAUSE_CHAIN (c4) = OMP_CLAUSE_CHAIN (last);
1843 : 1282 : 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 : 362 : 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 : 362 : tree one = build_int_cst (size_type_node, 1);
1858 : :
1859 : 362 : STRIP_NOPS (data);
1860 : 362 : if (!POINTER_TYPE_P (TREE_TYPE (data)))
1861 : : {
1862 : 205 : gcc_assert (TREE_CODE (data) == INDIRECT_REF);
1863 : 205 : data = TREE_OPERAND (data, 0);
1864 : : }
1865 : :
1866 : : /* data_array[offset_data] = data; */
1867 : 362 : tree tmp = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (data_array)),
1868 : : unshare_expr (data_array), offset_data,
1869 : : NULL_TREE, NULL_TREE);
1870 : 362 : gimplify_assign (tmp, data, seq);
1871 : :
1872 : : /* offset_data++ */
1873 : 362 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset_data, one);
1874 : 362 : gimplify_assign (offset_data, tmp, seq);
1875 : :
1876 : : /* data_array[offset_data] = &data; */
1877 : 362 : tmp = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (data_array)),
1878 : : unshare_expr (data_array),
1879 : : offset_data, NULL_TREE, NULL_TREE);
1880 : 362 : gimplify_assign (tmp, build_fold_addr_expr (data), seq);
1881 : :
1882 : : /* offset_data++ */
1883 : 362 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset_data, one);
1884 : 362 : gimplify_assign (offset_data, tmp, seq);
1885 : :
1886 : : /* sizes_array[offset] = size */
1887 : 362 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1888 : 362 : TYPE_SIZE_UNIT (size_type_node), offset);
1889 : 362 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (sizes_array),
1890 : : sizes_array, tmp);
1891 : 362 : gimple_seq seq2 = NULL;
1892 : 362 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1893 : 362 : gimple_seq_add_seq (seq, seq2);
1894 : 362 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1895 : 362 : gimplify_assign (tmp, size, seq);
1896 : :
1897 : : /* FIXME: tkind |= talign << talign_shift; */
1898 : : /* kinds_array[offset] = tkind. */
1899 : 362 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1900 : 362 : TYPE_SIZE_UNIT (short_unsigned_type_node), offset);
1901 : 362 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (kinds_array),
1902 : : kinds_array, tmp);
1903 : 362 : seq2 = NULL;
1904 : 362 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1905 : 362 : gimple_seq_add_seq (seq, seq2);
1906 : 362 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1907 : 362 : gimplify_assign (tmp, build_int_cst (short_unsigned_type_node, tkind), seq);
1908 : :
1909 : : /* offset++ */
1910 : 362 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset, one);
1911 : 362 : gimplify_assign (offset, tmp, seq);
1912 : :
1913 : : /* sizes_array[offset] = bias (= 0). */
1914 : 362 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1915 : 362 : TYPE_SIZE_UNIT (size_type_node), offset);
1916 : 362 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (sizes_array),
1917 : : sizes_array, tmp);
1918 : 362 : seq2 = NULL;
1919 : 362 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1920 : 362 : gimple_seq_add_seq (seq, seq2);
1921 : 362 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1922 : 362 : gimplify_assign (tmp, build_zero_cst (size_type_node), seq);
1923 : :
1924 : 362 : gcc_assert (gimple_code (ctx) == GIMPLE_OMP_TARGET);
1925 : 362 : tkind = (gimple_omp_target_kind (ctx) == GF_OMP_TARGET_KIND_EXIT_DATA
1926 : 362 : ? GOMP_MAP_DETACH : GOMP_MAP_ATTACH);
1927 : :
1928 : : /* kinds_array[offset] = tkind. */
1929 : 362 : tmp = build2_loc (loc, MULT_EXPR, size_type_node,
1930 : 362 : TYPE_SIZE_UNIT (short_unsigned_type_node), offset);
1931 : 362 : tmp = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (kinds_array),
1932 : : kinds_array, tmp);
1933 : 362 : seq2 = NULL;
1934 : 362 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
1935 : 362 : gimple_seq_add_seq (seq, seq2);
1936 : 362 : tmp = build_fold_indirect_ref_loc (loc, tmp);
1937 : 362 : gimplify_assign (tmp, build_int_cst (short_unsigned_type_node, tkind), seq);
1938 : :
1939 : : /* offset++ */
1940 : 362 : tmp = build2_loc (loc, PLUS_EXPR, size_type_node, offset, one);
1941 : 362 : gimplify_assign (offset, tmp, seq);
1942 : 362 : }
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 : 642 : 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 : 642 : tree type = TREE_TYPE (decl);
1959 : 642 : if (TREE_CODE (type) != RECORD_TYPE)
1960 : : return;
1961 : 1688 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1962 : : {
1963 : 1050 : type = TREE_TYPE (field);
1964 : 1050 : if (gfc_is_polymorphic_nonptr (type)
1965 : 848 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (field)
1966 : 1620 : || (GFC_DESCRIPTOR_TYPE_P (type)
1967 : 204 : && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE))
1968 : : {
1969 : 684 : tree tmp = fold_build3_loc (loc, COMPONENT_REF, TREE_TYPE (field),
1970 : : decl, field, NULL_TREE);
1971 : 684 : 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 : 366 : else if (GFC_DECL_GET_SCALAR_POINTER (field)
1977 : 366 : || GFC_DESCRIPTOR_TYPE_P (type))
1978 : 0 : continue;
1979 : 366 : else if (gfc_has_alloc_comps (TREE_TYPE (field), field, false))
1980 : : {
1981 : 80 : tree tmp = fold_build3_loc (loc, COMPONENT_REF, TREE_TYPE (field),
1982 : : decl, field, NULL_TREE);
1983 : 80 : if (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1984 : 40 : 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 : 40 : 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 : 460 : 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 : 460 : tree tmp;
2003 : :
2004 : : /* var = begin. */
2005 : 460 : gimplify_assign (var, begin, seq1);
2006 : :
2007 : : /* Loop: for (var = begin; var <cond> end; var += step). */
2008 : 460 : tree label_loop = create_artificial_label (loc);
2009 : 460 : tree label_cond = create_artificial_label (loc);
2010 : :
2011 : 460 : gimplify_and_add (fold_build1_loc (loc, GOTO_EXPR, void_type_node,
2012 : : label_cond), seq1);
2013 : 460 : 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 : 460 : tmp = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (var), var, step);
2019 : 460 : gimplify_assign (var, tmp, seq2);
2020 : 460 : gimple_seq_add_stmt (seq2, gimple_build_label (label_cond));
2021 : 460 : tmp = fold_build2_loc (loc, cond, boolean_type_node, var, end);
2022 : 460 : tmp = build3_v (COND_EXPR, tmp, build1_v (GOTO_EXPR, label_loop),
2023 : : build_empty_stmt (loc));
2024 : 460 : gimplify_and_add (tmp, seq2);
2025 : 460 : }
2026 : :
2027 : : /* Return size variable with the size of an array. */
2028 : : static tree
2029 : 254 : gfc_omp_get_array_size (location_t loc, tree desc, gimple_seq *seq)
2030 : : {
2031 : 254 : tree tmp;
2032 : 254 : gimple_seq seq1 = NULL, seq2 = NULL;
2033 : 254 : tree size = build_decl (loc, VAR_DECL, create_tmp_var_name ("size"),
2034 : : size_type_node);
2035 : 254 : tree extent = build_decl (loc, VAR_DECL, create_tmp_var_name ("extent"),
2036 : : gfc_array_index_type);
2037 : 254 : tree idx = build_decl (loc, VAR_DECL, create_tmp_var_name ("idx"),
2038 : : signed_char_type_node);
2039 : :
2040 : 254 : tree begin = build_zero_cst (signed_char_type_node);
2041 : 254 : tree end;
2042 : 254 : if (GFC_TYPE_ARRAY_AKIND (TREE_TYPE (desc)) == GFC_ARRAY_ASSUMED_SHAPE_CONT
2043 : 254 : || GFC_TYPE_ARRAY_AKIND (TREE_TYPE (desc)) == GFC_ARRAY_ASSUMED_SHAPE)
2044 : 8 : end = gfc_conv_descriptor_rank (desc);
2045 : : else
2046 : 246 : end = build_int_cst (signed_char_type_node,
2047 : 246 : GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc)));
2048 : 254 : 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 : 254 : gimplify_assign (size, build_int_cst (size_type_node, 1), seq);
2056 : :
2057 : 254 : gfc_omp_gen_simple_loop (idx, begin, end, LT_EXPR, step, loc, &seq1, &seq2);
2058 : 254 : gimple_seq_add_seq (seq, seq1);
2059 : :
2060 : 254 : 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 : 254 : tmp = fold_build2_loc (loc, PLUS_EXPR, gfc_array_index_type,
2064 : : tmp, gfc_index_one_node);
2065 : 254 : gimplify_assign (extent, tmp, seq);
2066 : 254 : tmp = fold_build2_loc (loc, LT_EXPR, boolean_type_node,
2067 : : extent, gfc_index_zero_node);
2068 : 254 : 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 : 254 : gimplify_and_add (tmp, seq);
2074 : : /* size *= extent. */
2075 : 254 : gimplify_assign (size, fold_build2_loc (loc, MULT_EXPR, size_type_node, size,
2076 : : fold_convert (size_type_node,
2077 : : extent)), seq);
2078 : 254 : gimple_seq_add_seq (seq, seq2);
2079 : 254 : 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 : 206 : gfc_omp_elmental_loop (location_t loc, tree decl, tree size, tree elem_len,
2087 : : gimple_seq *seq1, gimple_seq *seq2)
2088 : : {
2089 : 206 : tree idx = build_decl (loc, VAR_DECL, create_tmp_var_name ("idx"),
2090 : : size_type_node);
2091 : 206 : tree begin = build_zero_cst (size_type_node);
2092 : 206 : tree end = size;
2093 : 206 : tree step = build_int_cst (size_type_node, 1);
2094 : 206 : tree ptr;
2095 : :
2096 : 206 : gfc_omp_gen_simple_loop (idx, begin, end, LT_EXPR, step, loc, seq1, seq2);
2097 : :
2098 : 206 : tree type = TREE_TYPE (decl);
2099 : 206 : if (POINTER_TYPE_P (type))
2100 : : {
2101 : 162 : type = TREE_TYPE (type);
2102 : 162 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2103 : 162 : decl = fold_convert (build_pointer_type (TREE_TYPE (type)), decl);
2104 : : }
2105 : : else
2106 : : {
2107 : 44 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
2108 : 44 : decl = build_fold_addr_expr_loc (loc, decl);
2109 : : }
2110 : 206 : decl = fold_convert (build_pointer_type (TREE_TYPE (type)), decl);
2111 : 206 : tree tmp = build2_loc (loc, MULT_EXPR, size_type_node, idx,
2112 : : fold_convert (size_type_node, elem_len));
2113 : 206 : ptr = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (decl), decl, tmp);
2114 : 206 : gimple_seq seq3 = NULL;
2115 : 206 : ptr = force_gimple_operand (ptr, &seq3, true, NULL_TREE);
2116 : 206 : gimple_seq_add_seq (seq1, seq3);
2117 : :
2118 : 206 : 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 : 1004 : 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 : 1004 : tree tmp;
2138 : 1004 : tree type = TREE_TYPE (decl);
2139 : 1004 : if (POINTER_TYPE_P (type))
2140 : 416 : type = TREE_TYPE (type);
2141 : 1004 : tree end_label = NULL_TREE;
2142 : 1004 : tree size = NULL_TREE, elem_len = NULL_TREE;
2143 : :
2144 : 1004 : bool poly = gfc_is_polymorphic_nonptr (type);
2145 : 1004 : if (poly && is_cnt && !*poly_warned)
2146 : : {
2147 : 41 : 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 : 39 : warning_at (loc, OPT_Wopenmp,
2154 : : "Mapping of polymorphic list item %qD is "
2155 : : "unspecified behavior", decl);
2156 : 41 : *poly_warned = true;
2157 : : }
2158 : 1004 : if (do_alloc_check)
2159 : : {
2160 : 862 : tree then_label = create_artificial_label (loc);
2161 : 862 : end_label = create_artificial_label (loc);
2162 : 862 : tmp = decl;
2163 : 862 : if (TREE_CODE (TREE_TYPE (tmp)) == REFERENCE_TYPE
2164 : 862 : || (POINTER_TYPE_P (TREE_TYPE (tmp))
2165 : 396 : && (POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (tmp)))
2166 : 396 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (tmp))))))
2167 : 8 : tmp = build_fold_indirect_ref_loc (loc, tmp);
2168 : 862 : if (poly)
2169 : 242 : tmp = gfc_class_data_get (tmp);
2170 : 862 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
2171 : 338 : tmp = gfc_conv_descriptor_data_get (tmp);
2172 : 862 : gimple_seq seq2 = NULL;
2173 : 862 : tmp = force_gimple_operand (tmp, &seq2, true, NULL_TREE);
2174 : 862 : gimple_seq_add_seq (seq, seq2);
2175 : :
2176 : 862 : gimple_seq_add_stmt (seq,
2177 : 862 : gimple_build_cond (NE_EXPR, tmp, null_pointer_node,
2178 : : then_label, end_label));
2179 : 862 : gimple_seq_add_stmt (seq, gimple_build_label (then_label));
2180 : : }
2181 : 1004 : tree class_decl = decl;
2182 : 1004 : if (poly)
2183 : : {
2184 : 242 : decl = gfc_class_data_get (decl);
2185 : 242 : type = TREE_TYPE (decl);
2186 : : }
2187 : 1004 : if (POINTER_TYPE_P (TREE_TYPE (decl)))
2188 : : {
2189 : 548 : decl = build_fold_indirect_ref (decl);
2190 : 548 : type = TREE_TYPE (decl);
2191 : : }
2192 : :
2193 : 1004 : if (is_cnt && do_copy)
2194 : : {
2195 : 362 : tree tmp = fold_build2_loc (loc, PLUS_EXPR, size_type_node,
2196 : 362 : num, build_int_cst (size_type_node, 1));
2197 : 362 : gimplify_assign (num, tmp, seq);
2198 : : }
2199 : 642 : else if (do_copy)
2200 : : {
2201 : : /* copy data pointer */
2202 : 362 : tree bytesize;
2203 : 362 : 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 : 157 : elem_len = (poly ? gfc_class_vtab_size_get (class_decl)
2208 : 102 : : gfc_conv_descriptor_elem_len (decl));
2209 : 314 : tmp = (POINTER_TYPE_P (TREE_TYPE (decl))
2210 : 157 : ? build_fold_indirect_ref (decl) : decl);
2211 : 157 : size = gfc_omp_get_array_size (loc, tmp, seq);
2212 : 157 : 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 : 157 : tmp = gfc_conv_descriptor_data_get (decl);
2216 : : }
2217 : 205 : else if (poly)
2218 : : {
2219 : 66 : tmp = decl;
2220 : 66 : bytesize = fold_convert (size_type_node,
2221 : : gfc_class_vtab_size_get (class_decl));
2222 : : }
2223 : : else
2224 : : {
2225 : 139 : tmp = decl;
2226 : 139 : bytesize = TYPE_SIZE_UNIT (TREE_TYPE (decl));
2227 : : }
2228 : 362 : unsigned HOST_WIDE_INT tkind2 = tkind;
2229 : 362 : if (!is_cnt
2230 : 362 : && (tkind == GOMP_MAP_ALLOC
2231 : 334 : || (tkind == GOMP_MAP_FROM
2232 : 58 : && (gimple_omp_target_kind (ctx)
2233 : : != GF_OMP_TARGET_KIND_EXIT_DATA)))
2234 : 406 : && 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 : 362 : 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 : 1004 : tmp = decl;
2243 : 1004 : 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 : 1004 : if (poly || gfc_has_alloc_comps (type, tmp, true))
2247 : : {
2248 : 602 : gimple_seq seq2 = NULL;
2249 : 602 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
2250 : : {
2251 : 162 : if (elem_len == NULL_TREE)
2252 : : {
2253 : 97 : elem_len = gfc_conv_descriptor_elem_len (decl);
2254 : 97 : size = fold_convert (size_type_node,
2255 : : gfc_omp_get_array_size (loc, decl, seq));
2256 : : }
2257 : 162 : decl = gfc_conv_descriptor_data_get (decl);
2258 : 162 : decl = gfc_omp_elmental_loop (loc, decl, size, elem_len, seq, &seq2);
2259 : 162 : decl = build_fold_indirect_ref_loc (loc, decl);
2260 : : }
2261 : 440 : else if (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2262 : : {
2263 : 44 : 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 : 44 : elem_len = TYPE_SIZE_UNIT (TREE_TYPE (type));
2268 : 44 : size = fold_convert (size_type_node, GFC_TYPE_ARRAY_SIZE (type));
2269 : 44 : decl = gfc_omp_elmental_loop (loc, decl, size, elem_len, seq, &seq2);
2270 : 44 : decl = build_fold_indirect_ref_loc (loc, decl);
2271 : : }
2272 : 396 : else if (POINTER_TYPE_P (TREE_TYPE (decl)))
2273 : 0 : decl = build_fold_indirect_ref (decl);
2274 : :
2275 : 602 : 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 : 602 : gimple_seq_add_seq (seq, seq2);
2280 : : }
2281 : 1004 : if (end_label)
2282 : 862 : gimple_seq_add_stmt (seq, gimple_build_label (end_label));
2283 : 1004 : }
2284 : :
2285 : :
2286 : : /* Which map types to check/handle for deep mapping. */
2287 : : static bool
2288 : 36496 : gfc_omp_deep_map_kind_p (tree clause)
2289 : : {
2290 : 36496 : switch (OMP_CLAUSE_CODE (clause))
2291 : : {
2292 : 32940 : case OMP_CLAUSE_MAP:
2293 : 32940 : 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 : 32940 : 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 : 87736 : gfc_omp_deep_mapping_int_p (const gimple *ctx, tree clause)
2362 : : {
2363 : 87736 : if (is_gimple_omp_oacc (ctx) || !gfc_omp_deep_map_kind_p (clause))
2364 : : return NULL_TREE;
2365 : 20048 : tree decl = OMP_CLAUSE_DECL (clause);
2366 : 20048 : if (OMP_CLAUSE_SIZE (clause) != NULL_TREE
2367 : 20038 : && DECL_P (OMP_CLAUSE_SIZE (clause))
2368 : 6493 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_SIZE (clause))
2369 : 20347 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (clause)))
2370 : : /* Saved decl. */
2371 : 299 : decl = GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (clause));
2372 : 19749 : else if (TREE_CODE (decl) == MEM_REF || TREE_CODE (decl) == INDIRECT_REF)
2373 : : /* The following can happen for, e.g., class(t) :: var(..) */
2374 : 11386 : decl = TREE_OPERAND (decl, 0);
2375 : 20048 : 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 : 20048 : if (DECL_P (decl)
2379 : 12380 : && DECL_LANG_SPECIFIC (decl)
2380 : 22165 : && 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 : 20048 : tree tmp = OMP_CLAUSE_CHAIN (clause);
2385 : 20048 : if (tmp != NULL_TREE
2386 : 14894 : && OMP_CLAUSE_CODE (tmp) == OMP_CLAUSE_CODE (clause)
2387 : 13371 : && OMP_CLAUSE_SIZE (tmp) != NULL_TREE
2388 : 13371 : && DECL_P (OMP_CLAUSE_SIZE (tmp))
2389 : 1368 : && DECL_LANG_SPECIFIC (OMP_CLAUSE_SIZE (tmp))
2390 : 20120 : && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_SIZE (tmp)) == decl)
2391 : : return NULL_TREE;
2392 : 20048 : if (DECL_P (decl)
2393 : 12380 : && DECL_LANG_SPECIFIC (decl)
2394 : 22132 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
2395 : 29 : decl = GFC_DECL_SAVED_DESCRIPTOR (decl);
2396 : 20048 : tree type = TREE_TYPE (decl);
2397 : 20048 : if (POINTER_TYPE_P (type))
2398 : 12304 : type = TREE_TYPE (type);
2399 : 20048 : if (POINTER_TYPE_P (type))
2400 : 140 : type = TREE_TYPE (type);
2401 : 20048 : tmp = decl;
2402 : 21641 : while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
2403 : 2142 : tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2404 : 20048 : if (!gfc_is_polymorphic_nonptr (type)
2405 : 20048 : && !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 : 42448 : gfc_omp_deep_mapping_p (const gimple *ctx, tree clause)
2414 : : {
2415 : 42448 : tree decl = gfc_omp_deep_mapping_int_p (ctx, clause);
2416 : 42448 : if (decl == NULL_TREE)
2417 : 42367 : return false;
2418 : : return true;
2419 : : }
2420 : :
2421 : : /* Handle gfc_omp_deep_mapping{,_cnt} */
2422 : : static tree
2423 : 45264 : 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 : 45264 : tree num = NULL_TREE;
2429 : 45264 : location_t loc = OMP_CLAUSE_LOCATION (clause);
2430 : 45264 : tree decl = gfc_omp_deep_mapping_int_p (ctx, clause);
2431 : 45264 : bool poly_warned = false;
2432 : 45264 : 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 : 292 : if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
2437 : 292 : && (OMP_CLAUSE_MAP_KIND (clause) == GOMP_MAP_ALLOC
2438 : 248 : || 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 : 280 : tree type = TREE_TYPE (decl);
2451 : 280 : if (POINTER_TYPE_P (type))
2452 : 138 : type = TREE_TYPE (type);
2453 : 280 : if (POINTER_TYPE_P (type))
2454 : 8 : type = TREE_TYPE (type);
2455 : 280 : bool poly = gfc_is_polymorphic_nonptr (type);
2456 : :
2457 : 280 : if (is_cnt)
2458 : : {
2459 : 140 : num = build_decl (loc, VAR_DECL,
2460 : : create_tmp_var_name ("n_deepmap"), size_type_node);
2461 : 140 : tree tmp = fold_build2_loc (loc, MODIFY_EXPR, size_type_node, num,
2462 : 140 : build_int_cst (size_type_node, 0));
2463 : 140 : gimple_add_tmp_var (num);
2464 : 140 : gimplify_and_add (tmp, seq);
2465 : : }
2466 : : else
2467 : 140 : gcc_assert (short_unsigned_type_node == TREE_TYPE (TREE_TYPE (kinds)));
2468 : :
2469 : 280 : bool do_copy = poly;
2470 : 280 : bool do_alloc_check = false;
2471 : 280 : tree token = NULL_TREE;
2472 : 280 : tree tmp = decl;
2473 : 280 : if (poly)
2474 : : {
2475 : 40 : tmp = TYPE_FIELDS (type);
2476 : 40 : type = TREE_TYPE (tmp);
2477 : : }
2478 : : else
2479 : 276 : while (TREE_CODE (tmp) == COMPONENT_REF || TREE_CODE (tmp) == ARRAY_REF)
2480 : 40 : tmp = TREE_OPERAND (tmp, TREE_CODE (tmp) == COMPONENT_REF ? 1 : 0);
2481 : : /* If the clause argument is nonallocatable, skip is-allocate check. */
2482 : 280 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (tmp)
2483 : 152 : || GFC_DECL_GET_SCALAR_POINTER (tmp)
2484 : 292 : || (GFC_DESCRIPTOR_TYPE_P (type)
2485 : 42 : && (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE
2486 : 24 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
2487 : 8 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT)))
2488 : : do_alloc_check = true;
2489 : :
2490 : 280 : if (!is_cnt
2491 : 140 : && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
2492 : 136 : && (tkind == GOMP_MAP_ALLOC
2493 : 124 : || (tkind == GOMP_MAP_FROM
2494 : 20 : && (gimple_omp_target_kind (ctx)
2495 : : != GF_OMP_TARGET_KIND_EXIT_DATA)))
2496 : 316 : && (poly || gfc_omp_replace_alloc_by_to_mapping (type, tmp, true)))
2497 : 24 : OMP_CLAUSE_SET_MAP_KIND (clause, tkind == GOMP_MAP_ALLOC ? GOMP_MAP_TO
2498 : : : GOMP_MAP_TOFROM);
2499 : :
2500 : : /* TODO: For map(a(:)), we know it is present & allocated. */
2501 : :
2502 : 280 : tree present = (DECL_P (decl) ? gfc_omp_check_optional_argument (decl, true)
2503 : 280 : : NULL_TREE);
2504 : 438 : if (POINTER_TYPE_P (TREE_TYPE (decl))
2505 : 296 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
2506 : 8 : decl = build_fold_indirect_ref (decl);
2507 : 280 : if (present)
2508 : : {
2509 : 16 : tree then_label = create_artificial_label (loc);
2510 : 16 : tree end_label = create_artificial_label (loc);
2511 : 16 : gimple_seq seq2 = NULL;
2512 : 16 : tmp = force_gimple_operand (present, &seq2, true, NULL_TREE);
2513 : 16 : gimple_seq_add_seq (seq, seq2);
2514 : 16 : gimple_seq_add_stmt (seq,
2515 : 16 : gimple_build_cond_from_tree (present,
2516 : : then_label, end_label));
2517 : 16 : gimple_seq_add_stmt (seq, gimple_build_label (then_label));
2518 : 16 : gfc_omp_deep_mapping_item (is_cnt, do_copy, do_alloc_check, loc, decl,
2519 : : &token, tkind, data, sizes, kinds,
2520 : : offset_data, offset, num, seq, ctx,
2521 : : &poly_warned);
2522 : 16 : gimple_seq_add_stmt (seq, gimple_build_label (end_label));
2523 : : }
2524 : : else
2525 : 264 : gfc_omp_deep_mapping_item (is_cnt, do_copy, do_alloc_check, loc, decl,
2526 : : &token, tkind, data, sizes, kinds, offset_data,
2527 : : offset, num, seq, ctx, &poly_warned);
2528 : : /* Multiply by 2 as there are two mappings: data + pointer assign. */
2529 : 280 : if (is_cnt)
2530 : 140 : gimplify_assign (num,
2531 : : fold_build2_loc (loc, MULT_EXPR,
2532 : : size_type_node, num,
2533 : 140 : build_int_cst (size_type_node, 2)), seq);
2534 : : return num;
2535 : : }
2536 : :
2537 : : /* Return tree with a variable which contains the count of deep-mappyings
2538 : : (value depends, e.g., on allocation status) */
2539 : : tree
2540 : 44958 : gfc_omp_deep_mapping_cnt (const gimple *ctx, tree clause, gimple_seq *seq)
2541 : : {
2542 : 44958 : return gfc_omp_deep_mapping_do (true, ctx, clause, 0, NULL_TREE, NULL_TREE,
2543 : 44958 : NULL_TREE, NULL_TREE, NULL_TREE, seq);
2544 : : }
2545 : :
2546 : : /* Does the actual deep mapping. */
2547 : : void
2548 : 306 : gfc_omp_deep_mapping (const gimple *ctx, tree clause,
2549 : : unsigned HOST_WIDE_INT tkind, tree data,
2550 : : tree sizes, tree kinds, tree offset_data, tree offset,
2551 : : gimple_seq *seq)
2552 : : {
2553 : 306 : (void) gfc_omp_deep_mapping_do (false, ctx, clause, tkind, data, sizes, kinds,
2554 : : offset_data, offset, seq);
2555 : 306 : }
2556 : :
2557 : : /* Return true if DECL is a scalar variable (for the purpose of
2558 : : implicit firstprivatization/mapping). Only if 'ptr_alloc_ok.'
2559 : : is true, allocatables and pointers are permitted. */
2560 : :
2561 : : bool
2562 : 3608 : gfc_omp_scalar_p (tree decl, bool ptr_alloc_ok)
2563 : : {
2564 : 3608 : tree type = TREE_TYPE (decl);
2565 : 3608 : if (TREE_CODE (type) == REFERENCE_TYPE)
2566 : 1347 : type = TREE_TYPE (type);
2567 : 3608 : if (TREE_CODE (type) == POINTER_TYPE)
2568 : : {
2569 : 587 : if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
2570 : 587 : || GFC_DECL_GET_SCALAR_POINTER (decl))
2571 : : {
2572 : 150 : if (!ptr_alloc_ok)
2573 : : return false;
2574 : 0 : type = TREE_TYPE (type);
2575 : : }
2576 : 437 : if (GFC_ARRAY_TYPE_P (type)
2577 : 437 : || GFC_CLASS_TYPE_P (type))
2578 : : return false;
2579 : : }
2580 : 3060 : if ((TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == INTEGER_TYPE)
2581 : 5485 : && TYPE_STRING_FLAG (type))
2582 : : return false;
2583 : 3136 : if (INTEGRAL_TYPE_P (type)
2584 : 3136 : || SCALAR_FLOAT_TYPE_P (type)
2585 : 3136 : || COMPLEX_FLOAT_TYPE_P (type))
2586 : 2612 : return true;
2587 : : return false;
2588 : : }
2589 : :
2590 : :
2591 : : /* Return true if DECL is a scalar with target attribute but does not have the
2592 : : allocatable (or pointer) attribute (for the purpose of implicit mapping). */
2593 : :
2594 : : bool
2595 : 3501 : gfc_omp_scalar_target_p (tree decl)
2596 : : {
2597 : 3501 : return (DECL_P (decl) && GFC_DECL_GET_SCALAR_TARGET (decl)
2598 : 3601 : && gfc_omp_scalar_p (decl, false));
2599 : : }
2600 : :
2601 : :
2602 : : /* Return true if DECL's DECL_VALUE_EXPR (if any) should be
2603 : : disregarded in OpenMP construct, because it is going to be
2604 : : remapped during OpenMP lowering. SHARED is true if DECL
2605 : : is going to be shared, false if it is going to be privatized. */
2606 : :
2607 : : bool
2608 : 1594928 : gfc_omp_disregard_value_expr (tree decl, bool shared)
2609 : : {
2610 : 1594928 : if (GFC_DECL_COMMON_OR_EQUIV (decl)
2611 : 1594928 : && DECL_HAS_VALUE_EXPR_P (decl))
2612 : : {
2613 : 3050 : tree value = DECL_VALUE_EXPR (decl);
2614 : :
2615 : 3050 : if (TREE_CODE (value) == COMPONENT_REF
2616 : 3050 : && VAR_P (TREE_OPERAND (value, 0))
2617 : 6100 : && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
2618 : : {
2619 : : /* If variable in COMMON or EQUIVALENCE is privatized, return
2620 : : true, as just that variable is supposed to be privatized,
2621 : : not the whole COMMON or whole EQUIVALENCE.
2622 : : For shared variables in COMMON or EQUIVALENCE, let them be
2623 : : gimplified to DECL_VALUE_EXPR, so that for multiple shared vars
2624 : : from the same COMMON or EQUIVALENCE just one sharing of the
2625 : : whole COMMON or EQUIVALENCE is enough. */
2626 : 3050 : return ! shared;
2627 : : }
2628 : : }
2629 : :
2630 : 1591878 : if (GFC_DECL_RESULT (decl) && DECL_HAS_VALUE_EXPR_P (decl))
2631 : 374 : return ! shared;
2632 : :
2633 : : return false;
2634 : : }
2635 : :
2636 : : /* Return true if DECL that is shared iff SHARED is true should
2637 : : be put into OMP_CLAUSE_PRIVATE with OMP_CLAUSE_PRIVATE_DEBUG
2638 : : flag set. */
2639 : :
2640 : : bool
2641 : 38276 : gfc_omp_private_debug_clause (tree decl, bool shared)
2642 : : {
2643 : 38276 : if (GFC_DECL_CRAY_POINTEE (decl))
2644 : : return true;
2645 : :
2646 : 38240 : if (GFC_DECL_COMMON_OR_EQUIV (decl)
2647 : 38240 : && DECL_HAS_VALUE_EXPR_P (decl))
2648 : : {
2649 : 326 : tree value = DECL_VALUE_EXPR (decl);
2650 : :
2651 : 326 : if (TREE_CODE (value) == COMPONENT_REF
2652 : 326 : && VAR_P (TREE_OPERAND (value, 0))
2653 : 652 : && GFC_DECL_COMMON_OR_EQUIV (TREE_OPERAND (value, 0)))
2654 : : return shared;
2655 : : }
2656 : :
2657 : : return false;
2658 : : }
2659 : :
2660 : : /* Register language specific type size variables as potentially OpenMP
2661 : : firstprivate variables. */
2662 : :
2663 : : void
2664 : 21650 : gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *ctx, tree type)
2665 : : {
2666 : 21650 : if (GFC_ARRAY_TYPE_P (type) || GFC_DESCRIPTOR_TYPE_P (type))
2667 : : {
2668 : 3965 : int r;
2669 : :
2670 : 3965 : gcc_assert (TYPE_LANG_SPECIFIC (type) != NULL);
2671 : 9128 : for (r = 0; r < GFC_TYPE_ARRAY_RANK (type); r++)
2672 : : {
2673 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_LBOUND (type, r));
2674 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_UBOUND (type, r));
2675 : 5163 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_STRIDE (type, r));
2676 : : }
2677 : 3965 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_SIZE (type));
2678 : 3965 : omp_firstprivatize_variable (ctx, GFC_TYPE_ARRAY_OFFSET (type));
2679 : : }
2680 : 21650 : }
2681 : :
2682 : :
2683 : : static inline tree
2684 : 73450 : gfc_trans_add_clause (tree node, tree tail)
2685 : : {
2686 : 73450 : OMP_CLAUSE_CHAIN (node) = tail;
2687 : 73450 : return node;
2688 : : }
2689 : :
2690 : : static tree
2691 : 42594 : gfc_trans_omp_variable (gfc_symbol *sym, bool declare_simd)
2692 : : {
2693 : 42594 : if (declare_simd)
2694 : : {
2695 : 182 : int cnt = 0;
2696 : 182 : gfc_symbol *proc_sym;
2697 : 182 : gfc_formal_arglist *f;
2698 : :
2699 : 182 : gcc_assert (sym->attr.dummy);
2700 : 182 : proc_sym = sym->ns->proc_name;
2701 : 182 : if (proc_sym->attr.entry_master)
2702 : 0 : ++cnt;
2703 : 182 : if (gfc_return_by_reference (proc_sym))
2704 : : {
2705 : 0 : ++cnt;
2706 : 0 : if (proc_sym->ts.type == BT_CHARACTER)
2707 : 0 : ++cnt;
2708 : : }
2709 : 349 : for (f = gfc_sym_get_dummy_args (proc_sym); f; f = f->next)
2710 : 349 : if (f->sym == sym)
2711 : : break;
2712 : 167 : else if (f->sym)
2713 : 167 : ++cnt;
2714 : 182 : gcc_assert (f);
2715 : 182 : return build_int_cst (integer_type_node, cnt);
2716 : : }
2717 : :
2718 : 42412 : tree t = gfc_get_symbol_decl (sym);
2719 : 42412 : tree parent_decl;
2720 : 42412 : int parent_flag;
2721 : 42412 : bool return_value;
2722 : 42412 : bool alternate_entry;
2723 : 42412 : bool entry_master;
2724 : :
2725 : 42412 : return_value = sym->attr.function && sym->result == sym;
2726 : 164 : alternate_entry = sym->attr.function && sym->attr.entry
2727 : 42446 : && sym->result == sym;
2728 : 84824 : entry_master = sym->attr.result
2729 : 172 : && sym->ns->proc_name->attr.entry_master
2730 : 42424 : && !gfc_return_by_reference (sym->ns->proc_name);
2731 : 84824 : parent_decl = current_function_decl
2732 : 42412 : ? DECL_CONTEXT (current_function_decl) : NULL_TREE;
2733 : :
2734 : 42412 : if ((t == parent_decl && return_value)
2735 : 42405 : || (sym->ns && sym->ns->proc_name
2736 : 42405 : && sym->ns->proc_name->backend_decl == parent_decl
2737 : 2170 : && (alternate_entry || entry_master)))
2738 : : parent_flag = 1;
2739 : : else
2740 : 42403 : parent_flag = 0;
2741 : :
2742 : : /* Special case for assigning the return value of a function.
2743 : : Self recursive functions must have an explicit return value. */
2744 : 42412 : if (return_value && (t == current_function_decl || parent_flag))
2745 : 94 : t = gfc_get_fake_result_decl (sym, parent_flag);
2746 : :
2747 : : /* Similarly for alternate entry points. */
2748 : 42318 : else if (alternate_entry
2749 : 32 : && (sym->ns->proc_name->backend_decl == current_function_decl
2750 : 0 : || parent_flag))
2751 : : {
2752 : 32 : gfc_entry_list *el = NULL;
2753 : :
2754 : 51 : for (el = sym->ns->entries; el; el = el->next)
2755 : 51 : if (sym == el->sym)
2756 : : {
2757 : 32 : t = gfc_get_fake_result_decl (sym, parent_flag);
2758 : 32 : break;
2759 : : }
2760 : : }
2761 : :
2762 : 42286 : else if (entry_master
2763 : 12 : && (sym->ns->proc_name->backend_decl == current_function_decl
2764 : 0 : || parent_flag))
2765 : 12 : t = gfc_get_fake_result_decl (sym, parent_flag);
2766 : :
2767 : : return t;
2768 : : }
2769 : :
2770 : : static tree
2771 : 11627 : gfc_trans_omp_variable_list (enum omp_clause_code code,
2772 : : gfc_omp_namelist *namelist, tree list,
2773 : : bool declare_simd)
2774 : : {
2775 : 29999 : for (; namelist != NULL; namelist = namelist->next)
2776 : 18372 : if (namelist->sym->attr.referenced || declare_simd)
2777 : : {
2778 : 18372 : tree t = gfc_trans_omp_variable (namelist->sym, declare_simd);
2779 : 18372 : if (t != error_mark_node)
2780 : : {
2781 : 18372 : tree node;
2782 : 18372 : node = build_omp_clause (input_location, code);
2783 : 18372 : OMP_CLAUSE_DECL (node) = t;
2784 : 18372 : list = gfc_trans_add_clause (node, list);
2785 : :
2786 : 18372 : if (code == OMP_CLAUSE_LASTPRIVATE
2787 : 2864 : && namelist->u.lastprivate_conditional)
2788 : 88 : OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (node) = 1;
2789 : : }
2790 : : }
2791 : 11627 : return list;
2792 : : }
2793 : :
2794 : : struct omp_udr_find_orig_data
2795 : : {
2796 : : gfc_omp_udr *omp_udr;
2797 : : bool omp_orig_seen;
2798 : : };
2799 : :
2800 : : static int
2801 : 678 : omp_udr_find_orig (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
2802 : : void *data)
2803 : : {
2804 : 678 : struct omp_udr_find_orig_data *cd = (struct omp_udr_find_orig_data *) data;
2805 : 678 : if ((*e)->expr_type == EXPR_VARIABLE
2806 : 366 : && (*e)->symtree->n.sym == cd->omp_udr->omp_orig)
2807 : 72 : cd->omp_orig_seen = true;
2808 : :
2809 : 678 : return 0;
2810 : : }
2811 : :
2812 : : static void
2813 : 683 : gfc_trans_omp_array_reduction_or_udr (tree c, gfc_omp_namelist *n, locus where)
2814 : : {
2815 : 683 : gfc_symbol *sym = n->sym;
2816 : 683 : gfc_symtree *root1 = NULL, *root2 = NULL, *root3 = NULL, *root4 = NULL;
2817 : 683 : gfc_symtree *symtree1, *symtree2, *symtree3, *symtree4 = NULL;
2818 : 683 : gfc_symbol init_val_sym, outer_sym, intrinsic_sym;
2819 : 683 : gfc_symbol omp_var_copy[4];
2820 : 683 : gfc_expr *e1, *e2, *e3, *e4;
2821 : 683 : gfc_ref *ref;
2822 : 683 : tree decl, backend_decl, stmt, type, outer_decl;
2823 : 683 : locus old_loc = gfc_current_locus;
2824 : 683 : const char *iname;
2825 : 683 : bool t;
2826 : 683 : gfc_omp_udr *udr = n->u2.udr ? n->u2.udr->udr : NULL;
2827 : :
2828 : 683 : decl = OMP_CLAUSE_DECL (c);
2829 : 683 : gfc_current_locus = where;
2830 : 683 : type = TREE_TYPE (decl);
2831 : 683 : outer_decl = create_tmp_var_raw (type);
2832 : 683 : if (TREE_CODE (decl) == PARM_DECL
2833 : 31 : && TREE_CODE (type) == REFERENCE_TYPE
2834 : 12 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
2835 : 695 : && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (type)) == GFC_ARRAY_ALLOCATABLE)
2836 : : {
2837 : 12 : decl = build_fold_indirect_ref (decl);
2838 : 12 : type = TREE_TYPE (type);
2839 : : }
2840 : :
2841 : : /* Create a fake symbol for init value. */
2842 : 683 : memset (&init_val_sym, 0, sizeof (init_val_sym));
2843 : 683 : init_val_sym.ns = sym->ns;
2844 : 683 : init_val_sym.name = sym->name;
2845 : 683 : init_val_sym.ts = sym->ts;
2846 : 683 : init_val_sym.attr.referenced = 1;
2847 : 683 : init_val_sym.declared_at = where;
2848 : 683 : init_val_sym.attr.flavor = FL_VARIABLE;
2849 : 683 : if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
2850 : 283 : backend_decl = omp_reduction_init (c, gfc_sym_type (&init_val_sym));
2851 : 400 : else if (udr->initializer_ns)
2852 : : backend_decl = NULL;
2853 : : else
2854 : 130 : switch (sym->ts.type)
2855 : : {
2856 : 15 : case BT_LOGICAL:
2857 : 15 : case BT_INTEGER:
2858 : 15 : case BT_REAL:
2859 : 15 : case BT_COMPLEX:
2860 : 15 : backend_decl = build_zero_cst (gfc_sym_type (&init_val_sym));
2861 : 15 : break;
2862 : : default:
2863 : : backend_decl = NULL_TREE;
2864 : : break;
2865 : : }
2866 : 683 : init_val_sym.backend_decl = backend_decl;
2867 : :
2868 : : /* Create a fake symbol for the outer array reference. */
2869 : 683 : outer_sym = *sym;
2870 : 683 : if (sym->as)
2871 : 426 : outer_sym.as = gfc_copy_array_spec (sym->as);
2872 : 683 : outer_sym.attr.dummy = 0;
2873 : 683 : outer_sym.attr.result = 0;
2874 : 683 : outer_sym.attr.flavor = FL_VARIABLE;
2875 : 683 : outer_sym.backend_decl = outer_decl;
2876 : 683 : if (decl != OMP_CLAUSE_DECL (c))
2877 : 12 : outer_sym.backend_decl = build_fold_indirect_ref (outer_decl);
2878 : :
2879 : : /* Create fake symtrees for it. */
2880 : 683 : symtree1 = gfc_new_symtree (&root1, sym->name);
2881 : 683 : symtree1->n.sym = sym;
2882 : 683 : gcc_assert (symtree1 == root1);
2883 : :
2884 : 683 : symtree2 = gfc_new_symtree (&root2, sym->name);
2885 : 683 : symtree2->n.sym = &init_val_sym;
2886 : 683 : gcc_assert (symtree2 == root2);
2887 : :
2888 : 683 : symtree3 = gfc_new_symtree (&root3, sym->name);
2889 : 683 : symtree3->n.sym = &outer_sym;
2890 : 683 : gcc_assert (symtree3 == root3);
2891 : :
2892 : 683 : memset (omp_var_copy, 0, sizeof omp_var_copy);
2893 : 683 : if (udr)
2894 : : {
2895 : 400 : omp_var_copy[0] = *udr->omp_out;
2896 : 400 : omp_var_copy[1] = *udr->omp_in;
2897 : 400 : *udr->omp_out = outer_sym;
2898 : 400 : *udr->omp_in = *sym;
2899 : 400 : if (udr->initializer_ns)
2900 : : {
2901 : 270 : omp_var_copy[2] = *udr->omp_priv;
2902 : 270 : omp_var_copy[3] = *udr->omp_orig;
2903 : 270 : *udr->omp_priv = *sym;
2904 : 270 : *udr->omp_orig = outer_sym;
2905 : : }
2906 : : }
2907 : :
2908 : : /* Create expressions. */
2909 : 683 : e1 = gfc_get_expr ();
2910 : 683 : e1->expr_type = EXPR_VARIABLE;
2911 : 683 : e1->where = where;
2912 : 683 : e1->symtree = symtree1;
2913 : 683 : e1->ts = sym->ts;
2914 : 683 : if (sym->attr.dimension)
2915 : : {
2916 : 426 : e1->ref = ref = gfc_get_ref ();
2917 : 426 : ref->type = REF_ARRAY;
2918 : 426 : ref->u.ar.where = where;
2919 : 426 : ref->u.ar.as = sym->as;
2920 : 426 : ref->u.ar.type = AR_FULL;
2921 : 426 : ref->u.ar.dimen = 0;
2922 : : }
2923 : 683 : t = gfc_resolve_expr (e1);
2924 : 683 : gcc_assert (t);
2925 : :
2926 : 683 : e2 = NULL;
2927 : 683 : if (backend_decl != NULL_TREE)
2928 : : {
2929 : 298 : e2 = gfc_get_expr ();
2930 : 298 : e2->expr_type = EXPR_VARIABLE;
2931 : 298 : e2->where = where;
2932 : 298 : e2->symtree = symtree2;
2933 : 298 : e2->ts = sym->ts;
2934 : 298 : t = gfc_resolve_expr (e2);
2935 : 298 : gcc_assert (t);
2936 : : }
2937 : 385 : else if (udr->initializer_ns == NULL)
2938 : : {
2939 : 115 : gcc_assert (sym->ts.type == BT_DERIVED);
2940 : 115 : e2 = gfc_default_initializer (&sym->ts);
2941 : 115 : gcc_assert (e2);
2942 : 115 : t = gfc_resolve_expr (e2);
2943 : 115 : gcc_assert (t);
2944 : : }
2945 : 270 : else if (n->u2.udr->initializer->op == EXEC_ASSIGN)
2946 : : {
2947 : 204 : e2 = gfc_copy_expr (n->u2.udr->initializer->expr2);
2948 : 204 : t = gfc_resolve_expr (e2);
2949 : 204 : gcc_assert (t);
2950 : : }
2951 : 683 : if (udr && udr->initializer_ns)
2952 : : {
2953 : 270 : struct omp_udr_find_orig_data cd;
2954 : 270 : cd.omp_udr = udr;
2955 : 270 : cd.omp_orig_seen = false;
2956 : 270 : gfc_code_walker (&n->u2.udr->initializer,
2957 : : gfc_dummy_code_callback, omp_udr_find_orig, &cd);
2958 : 270 : if (cd.omp_orig_seen)
2959 : 72 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
2960 : : }
2961 : :
2962 : 683 : e3 = gfc_copy_expr (e1);
2963 : 683 : e3->symtree = symtree3;
2964 : 683 : t = gfc_resolve_expr (e3);
2965 : 683 : gcc_assert (t);
2966 : :
2967 : 683 : iname = NULL;
2968 : 683 : e4 = NULL;
2969 : 683 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
2970 : : {
2971 : 159 : case PLUS_EXPR:
2972 : 159 : case MINUS_EXPR:
2973 : 159 : e4 = gfc_add (e3, e1);
2974 : 159 : break;
2975 : 26 : case MULT_EXPR:
2976 : 26 : e4 = gfc_multiply (e3, e1);
2977 : 26 : break;
2978 : 6 : case TRUTH_ANDIF_EXPR:
2979 : 6 : e4 = gfc_and (e3, e1);
2980 : 6 : break;
2981 : 6 : case TRUTH_ORIF_EXPR:
2982 : 6 : e4 = gfc_or (e3, e1);
2983 : 6 : break;
2984 : 6 : case EQ_EXPR:
2985 : 6 : e4 = gfc_eqv (e3, e1);
2986 : 6 : break;
2987 : 6 : case NE_EXPR:
2988 : 6 : e4 = gfc_neqv (e3, e1);
2989 : 6 : break;
2990 : : case MIN_EXPR:
2991 : : iname = "min";
2992 : : break;
2993 : : case MAX_EXPR:
2994 : : iname = "max";
2995 : : break;
2996 : : case BIT_AND_EXPR:
2997 : : iname = "iand";
2998 : : break;
2999 : : case BIT_IOR_EXPR:
3000 : : iname = "ior";
3001 : : break;
3002 : : case BIT_XOR_EXPR:
3003 : : iname = "ieor";
3004 : : break;
3005 : 400 : case ERROR_MARK:
3006 : 400 : if (n->u2.udr->combiner->op == EXEC_ASSIGN)
3007 : : {
3008 : 334 : gfc_free_expr (e3);
3009 : 334 : e3 = gfc_copy_expr (n->u2.udr->combiner->expr1);
3010 : 334 : e4 = gfc_copy_expr (n->u2.udr->combiner->expr2);
3011 : 334 : t = gfc_resolve_expr (e3);
3012 : 334 : gcc_assert (t);
3013 : 334 : t = gfc_resolve_expr (e4);
3014 : 334 : gcc_assert (t);
3015 : : }
3016 : : break;
3017 : 0 : default:
3018 : 0 : gcc_unreachable ();
3019 : : }
3020 : 209 : if (iname != NULL)
3021 : : {
3022 : 74 : memset (&intrinsic_sym, 0, sizeof (intrinsic_sym));
3023 : 74 : intrinsic_sym.ns = sym->ns;
3024 : 74 : intrinsic_sym.name = iname;
3025 : 74 : intrinsic_sym.ts = sym->ts;
3026 : 74 : intrinsic_sym.attr.referenced = 1;
3027 : 74 : intrinsic_sym.attr.intrinsic = 1;
3028 : 74 : intrinsic_sym.attr.function = 1;
3029 : 74 : intrinsic_sym.attr.implicit_type = 1;
3030 : 74 : intrinsic_sym.result = &intrinsic_sym;
3031 : 74 : intrinsic_sym.declared_at = where;
3032 : :
3033 : 74 : symtree4 = gfc_new_symtree (&root4, iname);
3034 : 74 : symtree4->n.sym = &intrinsic_sym;
3035 : 74 : gcc_assert (symtree4 == root4);
3036 : :
3037 : 74 : e4 = gfc_get_expr ();
3038 : 74 : e4->expr_type = EXPR_FUNCTION;
3039 : 74 : e4->where = where;
3040 : 74 : e4->symtree = symtree4;
3041 : 74 : e4->value.function.actual = gfc_get_actual_arglist ();
3042 : 74 : e4->value.function.actual->expr = e3;
3043 : 74 : e4->value.function.actual->next = gfc_get_actual_arglist ();
3044 : 74 : e4->value.function.actual->next->expr = e1;
3045 : : }
3046 : 683 : if (OMP_CLAUSE_REDUCTION_CODE (c) != ERROR_MARK)
3047 : : {
3048 : : /* e1 and e3 have been stored as arguments of e4, avoid sharing. */
3049 : 283 : e1 = gfc_copy_expr (e1);
3050 : 283 : e3 = gfc_copy_expr (e3);
3051 : 283 : t = gfc_resolve_expr (e4);
3052 : 283 : gcc_assert (t);
3053 : : }
3054 : :
3055 : : /* Create the init statement list. */
3056 : 683 : pushlevel ();
3057 : 683 : if (e2)
3058 : 617 : stmt = gfc_trans_assignment (e1, e2, false, false);
3059 : : else
3060 : 66 : stmt = gfc_trans_call (n->u2.udr->initializer, false,
3061 : : NULL_TREE, NULL_TREE, false);
3062 : 683 : if (TREE_CODE (stmt) != BIND_EXPR)
3063 : 196 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
3064 : : else
3065 : 487 : poplevel (0, 0);
3066 : 683 : OMP_CLAUSE_REDUCTION_INIT (c) = stmt;
3067 : :
3068 : : /* Create the merge statement list. */
3069 : 683 : pushlevel ();
3070 : 683 : if (e4)
3071 : 617 : stmt = gfc_trans_assignment (e3, e4, false, true);
3072 : : else
3073 : 66 : stmt = gfc_trans_call (n->u2.udr->combiner, false,
3074 : : NULL_TREE, NULL_TREE, false);
3075 : 683 : if (TREE_CODE (stmt) != BIND_EXPR)
3076 : 233 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
3077 : : else
3078 : 450 : poplevel (0, 0);
3079 : 683 : OMP_CLAUSE_REDUCTION_MERGE (c) = stmt;
3080 : :
3081 : : /* And stick the placeholder VAR_DECL into the clause as well. */
3082 : 683 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = outer_decl;
3083 : :
3084 : 683 : gfc_current_locus = old_loc;
3085 : :
3086 : 683 : gfc_free_expr (e1);
3087 : 683 : if (e2)
3088 : 617 : gfc_free_expr (e2);
3089 : 683 : gfc_free_expr (e3);
3090 : 683 : if (e4)
3091 : 617 : gfc_free_expr (e4);
3092 : 683 : free (symtree1);
3093 : 683 : free (symtree2);
3094 : 683 : free (symtree3);
3095 : 683 : free (symtree4);
3096 : 683 : if (outer_sym.as)
3097 : 426 : gfc_free_array_spec (outer_sym.as);
3098 : :
3099 : 683 : if (udr)
3100 : : {
3101 : 400 : *udr->omp_out = omp_var_copy[0];
3102 : 400 : *udr->omp_in = omp_var_copy[1];
3103 : 400 : if (udr->initializer_ns)
3104 : : {
3105 : 270 : *udr->omp_priv = omp_var_copy[2];
3106 : 270 : *udr->omp_orig = omp_var_copy[3];
3107 : : }
3108 : : }
3109 : 683 : }
3110 : :
3111 : : static tree
3112 : 3840 : gfc_trans_omp_reduction_list (int kind, gfc_omp_namelist *namelist, tree list,
3113 : : locus where, bool mark_addressable)
3114 : : {
3115 : 3840 : omp_clause_code clause = OMP_CLAUSE_REDUCTION;
3116 : 3840 : switch (kind)
3117 : : {
3118 : : case OMP_LIST_REDUCTION:
3119 : : case OMP_LIST_REDUCTION_INSCAN:
3120 : : case OMP_LIST_REDUCTION_TASK:
3121 : : break;
3122 : : case OMP_LIST_IN_REDUCTION:
3123 : : clause = OMP_CLAUSE_IN_REDUCTION;
3124 : : break;
3125 : : case OMP_LIST_TASK_REDUCTION:
3126 : : clause = OMP_CLAUSE_TASK_REDUCTION;
3127 : : break;
3128 : 0 : default:
3129 : 0 : gcc_unreachable ();
3130 : : }
3131 : 8624 : for (; namelist != NULL; namelist = namelist->next)
3132 : 4784 : if (namelist->sym->attr.referenced)
3133 : : {
3134 : 4784 : tree t = gfc_trans_omp_variable (namelist->sym, false);
3135 : 4784 : if (t != error_mark_node)
3136 : : {
3137 : 4784 : tree node = build_omp_clause (gfc_get_location (&namelist->where),
3138 : : clause);
3139 : 4784 : OMP_CLAUSE_DECL (node) = t;
3140 : 4784 : if (mark_addressable)
3141 : 38 : TREE_ADDRESSABLE (t) = 1;
3142 : 4784 : if (kind == OMP_LIST_REDUCTION_INSCAN)
3143 : 20 : OMP_CLAUSE_REDUCTION_INSCAN (node) = 1;
3144 : 4784 : if (kind == OMP_LIST_REDUCTION_TASK)
3145 : 91 : OMP_CLAUSE_REDUCTION_TASK (node) = 1;
3146 : 4784 : switch (namelist->u.reduction_op)
3147 : : {
3148 : 2338 : case OMP_REDUCTION_PLUS:
3149 : 2338 : OMP_CLAUSE_REDUCTION_CODE (node) = PLUS_EXPR;
3150 : 2338 : break;
3151 : 197 : case OMP_REDUCTION_MINUS:
3152 : 197 : OMP_CLAUSE_REDUCTION_CODE (node) = MINUS_EXPR;
3153 : 197 : break;
3154 : 254 : case OMP_REDUCTION_TIMES:
3155 : 254 : OMP_CLAUSE_REDUCTION_CODE (node) = MULT_EXPR;
3156 : 254 : break;
3157 : 92 : case OMP_REDUCTION_AND:
3158 : 92 : OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ANDIF_EXPR;
3159 : 92 : break;
3160 : 785 : case OMP_REDUCTION_OR:
3161 : 785 : OMP_CLAUSE_REDUCTION_CODE (node) = TRUTH_ORIF_EXPR;
3162 : 785 : break;
3163 : 86 : case OMP_REDUCTION_EQV:
3164 : 86 : OMP_CLAUSE_REDUCTION_CODE (node) = EQ_EXPR;
3165 : 86 : break;
3166 : 86 : case OMP_REDUCTION_NEQV:
3167 : 86 : OMP_CLAUSE_REDUCTION_CODE (node) = NE_EXPR;
3168 : 86 : break;
3169 : 218 : case OMP_REDUCTION_MAX:
3170 : 218 : OMP_CLAUSE_REDUCTION_CODE (node) = MAX_EXPR;
3171 : 218 : break;
3172 : 201 : case OMP_REDUCTION_MIN:
3173 : 201 : OMP_CLAUSE_REDUCTION_CODE (node) = MIN_EXPR;
3174 : 201 : break;
3175 : 40 : case OMP_REDUCTION_IAND:
3176 : 40 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_AND_EXPR;
3177 : 40 : break;
3178 : 49 : case OMP_REDUCTION_IOR:
3179 : 49 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_IOR_EXPR;
3180 : 49 : break;
3181 : 38 : case OMP_REDUCTION_IEOR:
3182 : 38 : OMP_CLAUSE_REDUCTION_CODE (node) = BIT_XOR_EXPR;
3183 : 38 : break;
3184 : 400 : case OMP_REDUCTION_USER:
3185 : 400 : OMP_CLAUSE_REDUCTION_CODE (node) = ERROR_MARK;
3186 : 400 : break;
3187 : 0 : default:
3188 : 0 : gcc_unreachable ();
3189 : : }
3190 : 4784 : if (namelist->sym->attr.dimension
3191 : 4358 : || namelist->u.reduction_op == OMP_REDUCTION_USER
3192 : 4114 : || namelist->sym->attr.allocatable)
3193 : 683 : gfc_trans_omp_array_reduction_or_udr (node, namelist, where);
3194 : 4784 : list = gfc_trans_add_clause (node, list);
3195 : : }
3196 : : }
3197 : 3840 : return list;
3198 : : }
3199 : :
3200 : : static inline tree
3201 : 3374 : gfc_convert_expr_to_tree (stmtblock_t *block, gfc_expr *expr)
3202 : : {
3203 : 3374 : gfc_se se;
3204 : 3374 : tree result;
3205 : :
3206 : 3374 : gfc_init_se (&se, NULL );
3207 : 3374 : gfc_conv_expr (&se, expr);
3208 : 3374 : gfc_add_block_to_block (block, &se.pre);
3209 : 3374 : result = gfc_evaluate_now (se.expr, block);
3210 : 3374 : gfc_add_block_to_block (block, &se.post);
3211 : :
3212 : 3374 : return result;
3213 : : }
3214 : :
3215 : : static vec<tree, va_heap, vl_embed> *doacross_steps;
3216 : :
3217 : :
3218 : : /* Translate an array section or array element. */
3219 : :
3220 : : static void
3221 : 3980 : gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op,
3222 : : gfc_omp_namelist *n, tree decl, bool element,
3223 : : bool openmp, gomp_map_kind ptr_kind, tree &node,
3224 : : tree &node2, tree &node3, tree &node4)
3225 : : {
3226 : 3980 : gfc_se se;
3227 : 3980 : tree ptr, ptr2;
3228 : 3980 : tree elemsz = NULL_TREE;
3229 : :
3230 : 3980 : gfc_init_se (&se, NULL);
3231 : 3980 : if (element)
3232 : : {
3233 : 172 : gfc_conv_expr_reference (&se, n->expr);
3234 : 172 : gfc_add_block_to_block (block, &se.pre);
3235 : 172 : ptr = se.expr;
3236 : : }
3237 : : else
3238 : : {
3239 : 3808 : gfc_conv_expr_descriptor (&se, n->expr);
3240 : 3808 : ptr = gfc_conv_array_data (se.expr);
3241 : : }
3242 : 3980 : if (n->expr->ts.type == BT_CHARACTER && n->expr->ts.deferred)
3243 : : {
3244 : 0 : gcc_assert (se.string_length);
3245 : 0 : tree len = gfc_evaluate_now (se.string_length, block);
3246 : 0 : elemsz = gfc_get_char_type (n->expr->ts.kind);
3247 : 0 : elemsz = TYPE_SIZE_UNIT (elemsz);
3248 : 0 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
3249 : : fold_convert (size_type_node, len), elemsz);
3250 : : }
3251 : 3980 : if (element)
3252 : : {
3253 : 172 : if (!elemsz)
3254 : 172 : elemsz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
3255 : 172 : OMP_CLAUSE_SIZE (node) = elemsz;
3256 : : }
3257 : : else
3258 : : {
3259 : 3808 : tree type = TREE_TYPE (se.expr);
3260 : 3808 : gfc_add_block_to_block (block, &se.pre);
3261 : 3808 : OMP_CLAUSE_SIZE (node) = gfc_full_array_size (block, se.expr,
3262 : 3808 : GFC_TYPE_ARRAY_RANK (type));
3263 : 3808 : if (!elemsz)
3264 : 3808 : elemsz = TYPE_SIZE_UNIT (gfc_get_element_type (type));
3265 : 3808 : elemsz = fold_convert (gfc_array_index_type, elemsz);
3266 : 3808 : OMP_CLAUSE_SIZE (node) = fold_build2 (MULT_EXPR, gfc_array_index_type,
3267 : : OMP_CLAUSE_SIZE (node), elemsz);
3268 : 3808 : if (n->expr->ts.type == BT_DERIVED
3269 : 21 : && n->expr->ts.u.derived->attr.alloc_comp)
3270 : : {
3271 : : /* Save array descriptor for use in gfc_omp_deep_mapping{,_p,_cnt};
3272 : : force evaluate to ensure that it is not gimplified + is a decl. */
3273 : 15 : tree tmp = OMP_CLAUSE_SIZE (node);
3274 : 15 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
3275 : 15 : gfc_add_modify_loc (input_location, block, var, tmp);
3276 : 15 : OMP_CLAUSE_SIZE (node) = var;
3277 : 15 : gfc_allocate_lang_decl (var);
3278 : 15 : GFC_DECL_SAVED_DESCRIPTOR (var) = se.expr;
3279 : : }
3280 : : }
3281 : 3980 : gcc_assert (se.post.head == NULL_TREE);
3282 : 3980 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
3283 : 3980 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
3284 : 3980 : ptr = fold_convert (ptrdiff_type_node, ptr);
3285 : :
3286 : 7698 : if (POINTER_TYPE_P (TREE_TYPE (decl))
3287 : 340 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
3288 : 78 : && ptr_kind == GOMP_MAP_POINTER
3289 : 78 : && op != EXEC_OMP_TARGET_EXIT_DATA
3290 : 78 : && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_RELEASE
3291 : 4058 : && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_DELETE)
3292 : :
3293 : : {
3294 : 78 : node4 = build_omp_clause (input_location,
3295 : : OMP_CLAUSE_MAP);
3296 : 78 : OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
3297 : 78 : OMP_CLAUSE_DECL (node4) = decl;
3298 : 78 : OMP_CLAUSE_SIZE (node4) = size_int (0);
3299 : 78 : decl = build_fold_indirect_ref (decl);
3300 : : }
3301 : 3902 : else if (ptr_kind == GOMP_MAP_ALWAYS_POINTER
3302 : 0 : && n->expr->ts.type == BT_CHARACTER
3303 : 0 : && n->expr->ts.deferred)
3304 : : {
3305 : 0 : gomp_map_kind map_kind;
3306 : 0 : if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE)
3307 : 0 : map_kind = OMP_CLAUSE_MAP_KIND (node);
3308 : 0 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
3309 : 0 : || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE)
3310 : : map_kind = GOMP_MAP_RELEASE;
3311 : : else
3312 : : map_kind = GOMP_MAP_TO;
3313 : 0 : gcc_assert (se.string_length);
3314 : 0 : node4 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3315 : 0 : OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
3316 : 0 : OMP_CLAUSE_DECL (node4) = se.string_length;
3317 : 0 : OMP_CLAUSE_SIZE (node4) = TYPE_SIZE_UNIT (gfc_charlen_type_node);
3318 : : }
3319 : 3980 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
3320 : : {
3321 : 2707 : tree type = TREE_TYPE (decl);
3322 : 2707 : ptr2 = gfc_conv_descriptor_data_get (decl);
3323 : 2707 : node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3324 : 2707 : OMP_CLAUSE_DECL (node2) = decl;
3325 : 2707 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
3326 : 2707 : if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE
3327 : 2706 : || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE
3328 : 2497 : || op == EXEC_OMP_TARGET_EXIT_DATA
3329 : 5204 : || op == EXEC_OACC_EXIT_DATA)
3330 : : {
3331 : 391 : gomp_map_kind map_kind
3332 : 391 : = OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE ? GOMP_MAP_DELETE
3333 : 391 : : GOMP_MAP_RELEASE;
3334 : 391 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
3335 : 391 : OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
3336 : : }
3337 : : else
3338 : 2316 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET);
3339 : 2707 : node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP);
3340 : 2707 : OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
3341 : 2707 : OMP_CLAUSE_DECL (node3) = gfc_conv_descriptor_data_get (decl);
3342 : : /* This purposely does not include GOMP_MAP_ALWAYS_POINTER. The extra
3343 : : cast prevents gimplify.cc from recognising it as being part of the
3344 : : struct - and adding an 'alloc: for the 'desc.data' pointer, which
3345 : : would break as the 'desc' (the descriptor) is also mapped
3346 : : (see node4 above). */
3347 : 2707 : if (ptr_kind == GOMP_MAP_ATTACH_DETACH && !openmp)
3348 : 141 : STRIP_NOPS (OMP_CLAUSE_DECL (node3));
3349 : : }
3350 : : else
3351 : : {
3352 : 1273 : if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3353 : : {
3354 : 1011 : tree offset;
3355 : 1011 : ptr2 = build_fold_addr_expr (decl);
3356 : 1011 : offset = fold_build2 (MINUS_EXPR, ptrdiff_type_node, ptr,
3357 : : fold_convert (ptrdiff_type_node, ptr2));
3358 : 1011 : offset = build2 (TRUNC_DIV_EXPR, ptrdiff_type_node,
3359 : : offset, fold_convert (ptrdiff_type_node, elemsz));
3360 : 1011 : offset = build4_loc (input_location, ARRAY_REF,
3361 : 1011 : TREE_TYPE (TREE_TYPE (decl)),
3362 : : decl, offset, NULL_TREE, NULL_TREE);
3363 : 1011 : OMP_CLAUSE_DECL (node) = offset;
3364 : :
3365 : 1011 : if (ptr_kind == GOMP_MAP_ATTACH_DETACH && openmp)
3366 : 145 : return;
3367 : : }
3368 : : else
3369 : : {
3370 : 262 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
3371 : : ptr2 = decl;
3372 : : }
3373 : 1128 : node3 = build_omp_clause (input_location,
3374 : : OMP_CLAUSE_MAP);
3375 : 1128 : OMP_CLAUSE_SET_MAP_KIND (node3, ptr_kind);
3376 : 1128 : OMP_CLAUSE_DECL (node3) = decl;
3377 : : }
3378 : 3835 : ptr2 = fold_convert (ptrdiff_type_node, ptr2);
3379 : 3835 : OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, ptrdiff_type_node,
3380 : : ptr, ptr2);
3381 : : }
3382 : :
3383 : : static tree
3384 : 43 : handle_iterator (gfc_namespace *ns, stmtblock_t *iter_block, tree block)
3385 : : {
3386 : 43 : tree list = NULL_TREE;
3387 : 88 : for (gfc_symbol *sym = ns->omp_affinity_iterators; sym; sym = sym->tlink)
3388 : : {
3389 : 45 : gfc_constructor *c;
3390 : 45 : gfc_se se;
3391 : :
3392 : 45 : tree last = make_tree_vec (6);
3393 : 45 : tree iter_var = gfc_get_symbol_decl (sym);
3394 : 45 : tree type = TREE_TYPE (iter_var);
3395 : 45 : TREE_VEC_ELT (last, 0) = iter_var;
3396 : 45 : DECL_CHAIN (iter_var) = BLOCK_VARS (block);
3397 : 45 : BLOCK_VARS (block) = iter_var;
3398 : :
3399 : : /* begin */
3400 : 45 : c = gfc_constructor_first (sym->value->value.constructor);
3401 : 45 : gfc_init_se (&se, NULL);
3402 : 45 : gfc_conv_expr (&se, c->expr);
3403 : 45 : gfc_add_block_to_block (iter_block, &se.pre);
3404 : 45 : gfc_add_block_to_block (iter_block, &se.post);
3405 : 45 : TREE_VEC_ELT (last, 1) = fold_convert (type,
3406 : : gfc_evaluate_now (se.expr,
3407 : : iter_block));
3408 : : /* end */
3409 : 45 : c = gfc_constructor_next (c);
3410 : 45 : gfc_init_se (&se, NULL);
3411 : 45 : gfc_conv_expr (&se, c->expr);
3412 : 45 : gfc_add_block_to_block (iter_block, &se.pre);
3413 : 45 : gfc_add_block_to_block (iter_block, &se.post);
3414 : 45 : TREE_VEC_ELT (last, 2) = fold_convert (type,
3415 : : gfc_evaluate_now (se.expr,
3416 : : iter_block));
3417 : : /* step */
3418 : 45 : c = gfc_constructor_next (c);
3419 : 45 : tree step;
3420 : 45 : if (c)
3421 : : {
3422 : 5 : gfc_init_se (&se, NULL);
3423 : 5 : gfc_conv_expr (&se, c->expr);
3424 : 5 : gfc_add_block_to_block (iter_block, &se.pre);
3425 : 5 : gfc_add_block_to_block (iter_block, &se.post);
3426 : 5 : gfc_conv_expr (&se, c->expr);
3427 : 5 : step = fold_convert (type,
3428 : : gfc_evaluate_now (se.expr,
3429 : : iter_block));
3430 : : }
3431 : : else
3432 : 40 : step = build_int_cst (type, 1);
3433 : 45 : TREE_VEC_ELT (last, 3) = step;
3434 : : /* orig_step */
3435 : 45 : TREE_VEC_ELT (last, 4) = save_expr (step);
3436 : 45 : TREE_CHAIN (last) = list;
3437 : 45 : list = last;
3438 : : }
3439 : 43 : return list;
3440 : : }
3441 : :
3442 : : /* To alleviate quadratic behaviour in checking each entry of a
3443 : : gfc_omp_namelist against every other entry, we build a hashtable indexed by
3444 : : gfc_symbol pointer, which we can use in the usual case that a map
3445 : : expression has a symbol as its root term. Return a namelist based on the
3446 : : root symbol used by N, building a new table in SYM_ROOTED_NL using the
3447 : : gfc_omp_namelist N2 (all clauses) if we haven't done so already. */
3448 : :
3449 : : static gfc_omp_namelist *
3450 : 564 : get_symbol_rooted_namelist (hash_map<gfc_symbol *,
3451 : : gfc_omp_namelist *> *&sym_rooted_nl,
3452 : : gfc_omp_namelist *n,
3453 : : gfc_omp_namelist *n2, bool *sym_based)
3454 : : {
3455 : : /* Early-out if we have a NULL clause list (e.g. for OpenACC). */
3456 : 564 : if (!n2)
3457 : : return NULL;
3458 : :
3459 : 527 : gfc_symbol *use_sym = NULL;
3460 : :
3461 : : /* We're only interested in cases where we have an expression, e.g. a
3462 : : component access. */
3463 : 527 : if (n->expr && n->expr->expr_type == EXPR_VARIABLE && n->expr->symtree)
3464 : 527 : use_sym = n->expr->symtree->n.sym;
3465 : :
3466 : 527 : *sym_based = false;
3467 : :
3468 : 527 : if (!use_sym)
3469 : : return n2;
3470 : :
3471 : 527 : if (!sym_rooted_nl)
3472 : : {
3473 : 243 : sym_rooted_nl = new hash_map<gfc_symbol *, gfc_omp_namelist *> ();
3474 : :
3475 : 1194 : for (; n2 != NULL; n2 = n2->next)
3476 : : {
3477 : 951 : if (!n2->expr
3478 : 950 : || n2->expr->expr_type != EXPR_VARIABLE
3479 : 950 : || !n2->expr->symtree)
3480 : 1 : continue;
3481 : :
3482 : 950 : gfc_omp_namelist *nl_copy = gfc_get_omp_namelist ();
3483 : 950 : memcpy (nl_copy, n2, sizeof *nl_copy);
3484 : 950 : nl_copy->u2.duplicate_of = n2;
3485 : 950 : nl_copy->next = NULL;
3486 : :
3487 : 950 : gfc_symbol *idx_sym = n2->expr->symtree->n.sym;
3488 : :
3489 : 950 : bool existed;
3490 : 950 : gfc_omp_namelist *&entry
3491 : 950 : = sym_rooted_nl->get_or_insert (idx_sym, &existed);
3492 : 950 : if (existed)
3493 : 650 : nl_copy->next = entry;
3494 : 950 : entry = nl_copy;
3495 : : }
3496 : : }
3497 : :
3498 : 527 : gfc_omp_namelist **n2_sym = sym_rooted_nl->get (use_sym);
3499 : :
3500 : 527 : if (n2_sym)
3501 : : {
3502 : 527 : *sym_based = true;
3503 : 527 : return *n2_sym;
3504 : : }
3505 : :
3506 : : return NULL;
3507 : : }
3508 : :
3509 : : static tree
3510 : 31219 : gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
3511 : : locus where, bool declare_simd = false,
3512 : : bool openacc = false, gfc_exec_op op = EXEC_NOP)
3513 : : {
3514 : 31219 : tree omp_clauses = NULL_TREE, prev_clauses, chunk_size, c;
3515 : 31219 : tree iterator = NULL_TREE;
3516 : 31219 : tree tree_block = NULL_TREE;
3517 : 31219 : stmtblock_t iter_block;
3518 : 31219 : int list, ifc;
3519 : 31219 : enum omp_clause_code clause_code;
3520 : 31219 : gfc_omp_namelist *prev = NULL;
3521 : 31219 : gfc_se se;
3522 : :
3523 : 31219 : if (clauses == NULL)
3524 : : return NULL_TREE;
3525 : :
3526 : 31207 : hash_map<gfc_symbol *, gfc_omp_namelist *> *sym_rooted_nl = NULL;
3527 : :
3528 : 1217073 : for (list = 0; list < OMP_LIST_NUM; list++)
3529 : : {
3530 : 1185866 : gfc_omp_namelist *n = clauses->lists[list];
3531 : :
3532 : 1185866 : if (n == NULL)
3533 : 1158527 : continue;
3534 : 27339 : switch (list)
3535 : : {
3536 : 3840 : case OMP_LIST_REDUCTION:
3537 : 3840 : case OMP_LIST_REDUCTION_INSCAN:
3538 : 3840 : case OMP_LIST_REDUCTION_TASK:
3539 : 3840 : case OMP_LIST_IN_REDUCTION:
3540 : 3840 : case OMP_LIST_TASK_REDUCTION:
3541 : : /* An OpenACC async clause indicates the need to set reduction
3542 : : arguments addressable, to allow asynchronous copy-out. */
3543 : 3840 : omp_clauses = gfc_trans_omp_reduction_list (list, n, omp_clauses,
3544 : 3840 : where, clauses->async);
3545 : 3840 : break;
3546 : 6445 : case OMP_LIST_PRIVATE:
3547 : 6445 : clause_code = OMP_CLAUSE_PRIVATE;
3548 : 6445 : goto add_clause;
3549 : 1067 : case OMP_LIST_SHARED:
3550 : 1067 : clause_code = OMP_CLAUSE_SHARED;
3551 : 1067 : goto add_clause;
3552 : 1034 : case OMP_LIST_FIRSTPRIVATE:
3553 : 1034 : clause_code = OMP_CLAUSE_FIRSTPRIVATE;
3554 : 1034 : goto add_clause;
3555 : 1661 : case OMP_LIST_LASTPRIVATE:
3556 : 1661 : clause_code = OMP_CLAUSE_LASTPRIVATE;
3557 : 1661 : goto add_clause;
3558 : 96 : case OMP_LIST_COPYIN:
3559 : 96 : clause_code = OMP_CLAUSE_COPYIN;
3560 : 96 : goto add_clause;
3561 : 74 : case OMP_LIST_COPYPRIVATE:
3562 : 74 : clause_code = OMP_CLAUSE_COPYPRIVATE;
3563 : 74 : goto add_clause;
3564 : 61 : case OMP_LIST_UNIFORM:
3565 : 61 : clause_code = OMP_CLAUSE_UNIFORM;
3566 : 61 : goto add_clause;
3567 : 50 : case OMP_LIST_USE_DEVICE:
3568 : 50 : case OMP_LIST_USE_DEVICE_PTR:
3569 : 50 : clause_code = OMP_CLAUSE_USE_DEVICE_PTR;
3570 : 50 : goto add_clause;
3571 : 922 : case OMP_LIST_USE_DEVICE_ADDR:
3572 : 922 : clause_code = OMP_CLAUSE_USE_DEVICE_ADDR;
3573 : 922 : goto add_clause;
3574 : 40 : case OMP_LIST_IS_DEVICE_PTR:
3575 : 40 : clause_code = OMP_CLAUSE_IS_DEVICE_PTR;
3576 : 40 : goto add_clause;
3577 : 100 : case OMP_LIST_HAS_DEVICE_ADDR:
3578 : 100 : clause_code = OMP_CLAUSE_HAS_DEVICE_ADDR;
3579 : 100 : goto add_clause;
3580 : 2 : case OMP_LIST_NONTEMPORAL:
3581 : 2 : clause_code = OMP_CLAUSE_NONTEMPORAL;
3582 : 2 : goto add_clause;
3583 : 9 : case OMP_LIST_SCAN_IN:
3584 : 9 : clause_code = OMP_CLAUSE_INCLUSIVE;
3585 : 9 : goto add_clause;
3586 : 7 : case OMP_LIST_SCAN_EX:
3587 : 7 : clause_code = OMP_CLAUSE_EXCLUSIVE;
3588 : 7 : goto add_clause;
3589 : 4 : case OMP_LIST_USE:
3590 : 4 : clause_code = OMP_CLAUSE_USE;
3591 : 4 : goto add_clause;
3592 : 55 : case OMP_LIST_INTEROP:
3593 : 55 : clause_code = OMP_CLAUSE_INTEROP;
3594 : 55 : goto add_clause;
3595 : :
3596 : 11627 : add_clause:
3597 : 11627 : omp_clauses
3598 : 11627 : = gfc_trans_omp_variable_list (clause_code, n, omp_clauses,
3599 : : declare_simd);
3600 : 11627 : break;
3601 : :
3602 : : case OMP_LIST_DESTROY:
3603 : 12 : for (; n != NULL; n = n->next)
3604 : 9 : if (n->sym->attr.referenced)
3605 : : {
3606 : 9 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3607 : 9 : if (t != error_mark_node)
3608 : : {
3609 : 9 : tree node
3610 : 9 : = build_omp_clause (input_location, OMP_CLAUSE_DESTROY);
3611 : 9 : OMP_CLAUSE_DECL (node) = t;
3612 : 9 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (node)) = 1;
3613 : 9 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3614 : : }
3615 : : }
3616 : : break;
3617 : :
3618 : : case OMP_LIST_INIT:
3619 : : {
3620 : : tree pref_type = NULL_TREE;
3621 : : const char *last = NULL;
3622 : 32 : for (; n != NULL; n = n->next)
3623 : 26 : if (n->sym->attr.referenced)
3624 : : {
3625 : 26 : tree t = gfc_trans_omp_variable (n->sym, false);
3626 : 26 : if (t == error_mark_node)
3627 : 0 : continue;
3628 : 26 : tree node = build_omp_clause (input_location,
3629 : : OMP_CLAUSE_INIT);
3630 : 26 : OMP_CLAUSE_DECL (node) = t;
3631 : 26 : TREE_ADDRESSABLE (OMP_CLAUSE_DECL (node)) = 1;
3632 : 26 : if (n->u.init.target)
3633 : 19 : OMP_CLAUSE_INIT_TARGET (node) = 1;
3634 : 26 : if (n->u.init.targetsync)
3635 : 10 : OMP_CLAUSE_INIT_TARGETSYNC (node) = 1;
3636 : 26 : if (last != n->u2.init_interop)
3637 : : {
3638 : 6 : last = n->u2.init_interop;
3639 : 6 : if (n->u2.init_interop == NULL)
3640 : : pref_type = NULL_TREE;
3641 : : else
3642 : : {
3643 : 5 : pref_type = build_string (n->u.init.len,
3644 : : n->u2.init_interop);
3645 : 5 : TREE_TYPE (pref_type)
3646 : 10 : = build_array_type_nelts (unsigned_char_type_node,
3647 : 5 : n->u.init.len);
3648 : : }
3649 : : }
3650 : 26 : OMP_CLAUSE_INIT_PREFER_TYPE (node) = pref_type;
3651 : 26 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3652 : : }
3653 : : break;
3654 : : }
3655 : :
3656 : : case OMP_LIST_ALIGNED:
3657 : 256 : for (; n != NULL; n = n->next)
3658 : 149 : if (n->sym->attr.referenced || declare_simd)
3659 : : {
3660 : 149 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3661 : 149 : if (t != error_mark_node)
3662 : : {
3663 : 149 : tree node = build_omp_clause (input_location,
3664 : : OMP_CLAUSE_ALIGNED);
3665 : 149 : OMP_CLAUSE_DECL (node) = t;
3666 : 149 : if (n->expr)
3667 : : {
3668 : 148 : tree alignment_var;
3669 : :
3670 : 148 : if (declare_simd)
3671 : 5 : alignment_var = gfc_conv_constant_to_tree (n->expr);
3672 : : else
3673 : : {
3674 : 143 : gfc_init_se (&se, NULL);
3675 : 143 : gfc_conv_expr (&se, n->expr);
3676 : 143 : gfc_add_block_to_block (block, &se.pre);
3677 : 143 : alignment_var = gfc_evaluate_now (se.expr, block);
3678 : 143 : gfc_add_block_to_block (block, &se.post);
3679 : : }
3680 : 148 : OMP_CLAUSE_ALIGNED_ALIGNMENT (node) = alignment_var;
3681 : : }
3682 : 149 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3683 : : }
3684 : : }
3685 : : break;
3686 : : case OMP_LIST_ALLOCATE:
3687 : : {
3688 : : tree allocator_ = NULL_TREE;
3689 : : gfc_expr *alloc_expr = NULL;
3690 : 582 : for (; n != NULL; n = n->next)
3691 : 377 : if (n->sym->attr.referenced)
3692 : : {
3693 : 377 : tree t = gfc_trans_omp_variable (n->sym, false);
3694 : 377 : if (t != error_mark_node)
3695 : : {
3696 : 377 : tree node = build_omp_clause (input_location,
3697 : : OMP_CLAUSE_ALLOCATE);
3698 : 377 : OMP_CLAUSE_DECL (node) = t;
3699 : 377 : if (n->u2.allocator)
3700 : : {
3701 : 242 : if (alloc_expr != n->u2.allocator)
3702 : : {
3703 : 125 : gfc_init_se (&se, NULL);
3704 : 125 : gfc_conv_expr (&se, n->u2.allocator);
3705 : 125 : gfc_add_block_to_block (block, &se.pre);
3706 : 125 : allocator_ = gfc_evaluate_now (se.expr, block);
3707 : 125 : gfc_add_block_to_block (block, &se.post);
3708 : : }
3709 : 242 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (node) = allocator_;
3710 : : }
3711 : 377 : alloc_expr = n->u2.allocator;
3712 : 377 : if (n->u.align)
3713 : : {
3714 : 3 : tree align_;
3715 : 3 : gfc_init_se (&se, NULL);
3716 : 3 : gfc_conv_expr (&se, n->u.align);
3717 : 3 : gcc_assert (CONSTANT_CLASS_P (se.expr)
3718 : : && se.pre.head == NULL
3719 : : && se.post.head == NULL);
3720 : 3 : align_ = se.expr;
3721 : 3 : OMP_CLAUSE_ALLOCATE_ALIGN (node) = align_;
3722 : : }
3723 : 377 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3724 : : }
3725 : : }
3726 : : else
3727 : 0 : alloc_expr = n->u2.allocator;
3728 : : }
3729 : : break;
3730 : : case OMP_LIST_LINEAR:
3731 : : {
3732 : : gfc_expr *last_step_expr = NULL;
3733 : : tree last_step = NULL_TREE;
3734 : : bool last_step_parm = false;
3735 : :
3736 : 1288 : for (; n != NULL; n = n->next)
3737 : : {
3738 : 795 : if (n->expr)
3739 : : {
3740 : 776 : last_step_expr = n->expr;
3741 : 776 : last_step = NULL_TREE;
3742 : 776 : last_step_parm = false;
3743 : : }
3744 : 795 : if (n->sym->attr.referenced || declare_simd)
3745 : : {
3746 : 795 : tree t = gfc_trans_omp_variable (n->sym, declare_simd);
3747 : 795 : if (t != error_mark_node)
3748 : : {
3749 : 795 : tree node = build_omp_clause (input_location,
3750 : : OMP_CLAUSE_LINEAR);
3751 : 795 : OMP_CLAUSE_DECL (node) = t;
3752 : 795 : omp_clause_linear_kind kind;
3753 : 795 : switch (n->u.linear.op)
3754 : : {
3755 : : case OMP_LINEAR_DEFAULT:
3756 : : kind = OMP_CLAUSE_LINEAR_DEFAULT;
3757 : : break;
3758 : : case OMP_LINEAR_REF:
3759 : : kind = OMP_CLAUSE_LINEAR_REF;
3760 : : break;
3761 : : case OMP_LINEAR_VAL:
3762 : : kind = OMP_CLAUSE_LINEAR_VAL;
3763 : : break;
3764 : : case OMP_LINEAR_UVAL:
3765 : : kind = OMP_CLAUSE_LINEAR_UVAL;
3766 : : break;
3767 : 0 : default:
3768 : 0 : gcc_unreachable ();
3769 : : }
3770 : 795 : OMP_CLAUSE_LINEAR_KIND (node) = kind;
3771 : 795 : OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (node)
3772 : 795 : = n->u.linear.old_modifier;
3773 : 795 : if (last_step_expr && last_step == NULL_TREE)
3774 : : {
3775 : 776 : if (!declare_simd)
3776 : : {
3777 : 695 : gfc_init_se (&se, NULL);
3778 : 695 : gfc_conv_expr (&se, last_step_expr);
3779 : 695 : gfc_add_block_to_block (block, &se.pre);
3780 : 695 : last_step = gfc_evaluate_now (se.expr, block);
3781 : 695 : gfc_add_block_to_block (block, &se.post);
3782 : : }
3783 : 81 : else if (last_step_expr->expr_type == EXPR_VARIABLE)
3784 : : {
3785 : 2 : gfc_symbol *s = last_step_expr->symtree->n.sym;
3786 : 2 : last_step = gfc_trans_omp_variable (s, true);
3787 : 2 : last_step_parm = true;
3788 : : }
3789 : : else
3790 : 79 : last_step
3791 : 79 : = gfc_conv_constant_to_tree (last_step_expr);
3792 : : }
3793 : 795 : if (last_step_parm)
3794 : : {
3795 : 2 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (node) = 1;
3796 : 2 : OMP_CLAUSE_LINEAR_STEP (node) = last_step;
3797 : : }
3798 : : else
3799 : : {
3800 : 793 : if (kind == OMP_CLAUSE_LINEAR_REF)
3801 : : {
3802 : 34 : tree type;
3803 : 34 : if (n->sym->attr.flavor == FL_PROCEDURE)
3804 : : {
3805 : 0 : type = gfc_get_function_type (n->sym);
3806 : 0 : type = build_pointer_type (type);
3807 : : }
3808 : : else
3809 : 34 : type = gfc_sym_type (n->sym);
3810 : 34 : if (POINTER_TYPE_P (type))
3811 : 34 : type = TREE_TYPE (type);
3812 : : /* Otherwise to be determined what exactly
3813 : : should be done. */
3814 : 34 : tree t = fold_convert (sizetype, last_step);
3815 : 34 : t = size_binop (MULT_EXPR, t,
3816 : : TYPE_SIZE_UNIT (type));
3817 : 34 : OMP_CLAUSE_LINEAR_STEP (node) = t;
3818 : : }
3819 : : else
3820 : : {
3821 : 759 : tree type
3822 : 759 : = gfc_typenode_for_spec (&n->sym->ts);
3823 : 759 : OMP_CLAUSE_LINEAR_STEP (node)
3824 : 1518 : = fold_convert (type, last_step);
3825 : : }
3826 : : }
3827 : 795 : if (n->sym->attr.dimension || n->sym->attr.allocatable)
3828 : 222 : OMP_CLAUSE_LINEAR_ARRAY (node) = 1;
3829 : 795 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3830 : : }
3831 : : }
3832 : : }
3833 : : }
3834 : : break;
3835 : : case OMP_LIST_AFFINITY:
3836 : : case OMP_LIST_DEPEND:
3837 : : iterator = NULL_TREE;
3838 : : prev = NULL;
3839 : : prev_clauses = omp_clauses;
3840 : 1568 : for (; n != NULL; n = n->next)
3841 : : {
3842 : 850 : if (iterator && prev->u2.ns != n->u2.ns)
3843 : : {
3844 : 12 : BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
3845 : 12 : TREE_VEC_ELT (iterator, 5) = tree_block;
3846 : 26 : for (tree c = omp_clauses; c != prev_clauses;
3847 : 14 : c = OMP_CLAUSE_CHAIN (c))
3848 : 28 : OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
3849 : 14 : OMP_CLAUSE_DECL (c));
3850 : : prev_clauses = omp_clauses;
3851 : : iterator = NULL_TREE;
3852 : : }
3853 : 850 : if (n->u2.ns && (!prev || prev->u2.ns != n->u2.ns))
3854 : : {
3855 : 43 : gfc_init_block (&iter_block);
3856 : 43 : tree_block = make_node (BLOCK);
3857 : 43 : TREE_USED (tree_block) = 1;
3858 : 43 : BLOCK_VARS (tree_block) = NULL_TREE;
3859 : 43 : iterator = handle_iterator (n->u2.ns, block,
3860 : : tree_block);
3861 : : }
3862 : 850 : if (!iterator)
3863 : 798 : gfc_init_block (&iter_block);
3864 : 850 : prev = n;
3865 : 850 : if (list == OMP_LIST_DEPEND
3866 : 824 : && (n->u.depend_doacross_op == OMP_DOACROSS_SINK_FIRST
3867 : 824 : || n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST))
3868 : : {
3869 : 227 : tree vec = NULL_TREE;
3870 : 227 : unsigned int i;
3871 : 227 : bool is_depend
3872 : : = n->u.depend_doacross_op == OMP_DEPEND_SINK_FIRST;
3873 : 227 : for (i = 0; ; i++)
3874 : : {
3875 : 1218 : tree addend = integer_zero_node, t;
3876 : 1218 : bool neg = false;
3877 : 1218 : if (n->sym && n->expr)
3878 : : {
3879 : 558 : addend = gfc_conv_constant_to_tree (n->expr);
3880 : 558 : if (TREE_CODE (addend) == INTEGER_CST
3881 : 558 : && tree_int_cst_sgn (addend) == -1)
3882 : : {
3883 : 407 : neg = true;
3884 : 407 : addend = const_unop (NEGATE_EXPR,
3885 : 407 : TREE_TYPE (addend), addend);
3886 : : }
3887 : : }
3888 : :
3889 : 1218 : if (n->sym == NULL)
3890 : 0 : t = null_pointer_node; /* "omp_cur_iteration - 1". */
3891 : : else
3892 : 1218 : t = gfc_trans_omp_variable (n->sym, false);
3893 : 1218 : if (t != error_mark_node)
3894 : : {
3895 : 1218 : if (i < vec_safe_length (doacross_steps)
3896 : 426 : && !integer_zerop (addend)
3897 : 630 : && (*doacross_steps)[i])
3898 : : {
3899 : 204 : tree step = (*doacross_steps)[i];
3900 : 204 : addend = fold_convert (TREE_TYPE (step), addend);
3901 : 204 : addend = build2 (TRUNC_DIV_EXPR,
3902 : 204 : TREE_TYPE (step), addend, step);
3903 : : }
3904 : 1218 : vec = tree_cons (addend, t, vec);
3905 : 1218 : if (neg)
3906 : 407 : OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (vec) = 1;
3907 : : }
3908 : 1218 : if (n->next == NULL
3909 : 1057 : || n->next->u.depend_doacross_op != OMP_DOACROSS_SINK)
3910 : : break;
3911 : 991 : n = n->next;
3912 : 991 : }
3913 : 227 : if (vec == NULL_TREE)
3914 : 0 : continue;
3915 : :
3916 : 227 : tree node = build_omp_clause (input_location,
3917 : : OMP_CLAUSE_DOACROSS);
3918 : 227 : OMP_CLAUSE_DOACROSS_KIND (node) = OMP_CLAUSE_DOACROSS_SINK;
3919 : 227 : OMP_CLAUSE_DOACROSS_DEPEND (node) = is_depend;
3920 : 227 : OMP_CLAUSE_DECL (node) = nreverse (vec);
3921 : 227 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3922 : 227 : continue;
3923 : 227 : }
3924 : :
3925 : 623 : if (n->sym && !n->sym->attr.referenced)
3926 : 0 : continue;
3927 : :
3928 : 649 : tree node = build_omp_clause (input_location,
3929 : : list == OMP_LIST_DEPEND
3930 : : ? OMP_CLAUSE_DEPEND
3931 : : : OMP_CLAUSE_AFFINITY);
3932 : 623 : if (n->sym == NULL) /* omp_all_memory */
3933 : 9 : OMP_CLAUSE_DECL (node) = null_pointer_node;
3934 : 614 : else if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL)
3935 : : {
3936 : 404 : tree decl = gfc_trans_omp_variable (n->sym, false);
3937 : 404 : if (gfc_omp_privatize_by_reference (decl))
3938 : 62 : decl = build_fold_indirect_ref (decl);
3939 : 404 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
3940 : : {
3941 : 23 : decl = gfc_conv_descriptor_data_get (decl);
3942 : 23 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (decl)));
3943 : 23 : decl = build_fold_indirect_ref (decl);
3944 : : }
3945 : 381 : else if (n->sym->attr.allocatable || n->sym->attr.pointer)
3946 : 22 : decl = build_fold_indirect_ref (decl);
3947 : 359 : else if (DECL_P (decl))
3948 : 326 : TREE_ADDRESSABLE (decl) = 1;
3949 : 404 : OMP_CLAUSE_DECL (node) = decl;
3950 : 404 : }
3951 : : else
3952 : : {
3953 : 210 : tree ptr;
3954 : 210 : gfc_init_se (&se, NULL);
3955 : 210 : if (n->expr->ref->u.ar.type == AR_ELEMENT)
3956 : : {
3957 : 130 : gfc_conv_expr_reference (&se, n->expr);
3958 : 130 : ptr = se.expr;
3959 : : }
3960 : : else
3961 : : {
3962 : 80 : gfc_conv_expr_descriptor (&se, n->expr);
3963 : 80 : ptr = gfc_conv_array_data (se.expr);
3964 : : }
3965 : 210 : gfc_add_block_to_block (&iter_block, &se.pre);
3966 : 210 : gfc_add_block_to_block (&iter_block, &se.post);
3967 : 210 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
3968 : 210 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
3969 : : }
3970 : 623 : if (list == OMP_LIST_DEPEND)
3971 : 597 : switch (n->u.depend_doacross_op)
3972 : : {
3973 : 227 : case OMP_DEPEND_IN:
3974 : 227 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_IN;
3975 : 227 : break;
3976 : 256 : case OMP_DEPEND_OUT:
3977 : 256 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_OUT;
3978 : 256 : break;
3979 : 55 : case OMP_DEPEND_INOUT:
3980 : 55 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUT;
3981 : 55 : break;
3982 : 9 : case OMP_DEPEND_INOUTSET:
3983 : 9 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_INOUTSET;
3984 : 9 : break;
3985 : 15 : case OMP_DEPEND_MUTEXINOUTSET:
3986 : 15 : OMP_CLAUSE_DEPEND_KIND (node)
3987 : 15 : = OMP_CLAUSE_DEPEND_MUTEXINOUTSET;
3988 : 15 : break;
3989 : 35 : case OMP_DEPEND_DEPOBJ:
3990 : 35 : OMP_CLAUSE_DEPEND_KIND (node) = OMP_CLAUSE_DEPEND_DEPOBJ;
3991 : 35 : break;
3992 : 0 : default:
3993 : 0 : gcc_unreachable ();
3994 : : }
3995 : 623 : if (!iterator)
3996 : 571 : gfc_add_block_to_block (block, &iter_block);
3997 : 623 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
3998 : : }
3999 : 718 : if (iterator)
4000 : : {
4001 : 31 : BLOCK_SUBBLOCKS (tree_block) = gfc_finish_block (&iter_block);
4002 : 31 : TREE_VEC_ELT (iterator, 5) = tree_block;
4003 : 70 : for (tree c = omp_clauses; c != prev_clauses;
4004 : 39 : c = OMP_CLAUSE_CHAIN (c))
4005 : 78 : OMP_CLAUSE_DECL (c) = build_tree_list (iterator,
4006 : 39 : OMP_CLAUSE_DECL (c));
4007 : : }
4008 : : break;
4009 : : case OMP_LIST_MAP:
4010 : 23243 : for (; n != NULL; n = n->next)
4011 : : {
4012 : 14688 : if (!n->sym->attr.referenced)
4013 : 280 : continue;
4014 : :
4015 : 14688 : location_t map_loc = gfc_get_location (&n->where);
4016 : 14688 : bool always_modifier = false;
4017 : 14688 : tree node = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4018 : 14688 : tree node2 = NULL_TREE;
4019 : 14688 : tree node3 = NULL_TREE;
4020 : 14688 : tree node4 = NULL_TREE;
4021 : 14688 : tree node5 = NULL_TREE;
4022 : :
4023 : : /* OpenMP: automatically map pointer targets with the pointer;
4024 : : hence, always update the descriptor/pointer itself. */
4025 : 14688 : if (!openacc
4026 : 14688 : && ((n->expr == NULL && n->sym->attr.pointer)
4027 : 13918 : || (n->expr && gfc_expr_attr (n->expr).pointer)))
4028 : 1357 : always_modifier = true;
4029 : :
4030 : 14688 : if (n->u.map.readonly)
4031 : 22 : OMP_CLAUSE_MAP_READONLY (node) = 1;
4032 : :
4033 : 14688 : switch (n->u.map.op)
4034 : : {
4035 : 1015 : case OMP_MAP_ALLOC:
4036 : 1015 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALLOC);
4037 : 1015 : break;
4038 : 64 : case OMP_MAP_IF_PRESENT:
4039 : 64 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_IF_PRESENT);
4040 : 64 : break;
4041 : 62 : case OMP_MAP_ATTACH:
4042 : 62 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ATTACH);
4043 : 62 : break;
4044 : 4011 : case OMP_MAP_TO:
4045 : 4011 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TO);
4046 : 4011 : break;
4047 : 2808 : case OMP_MAP_FROM:
4048 : 2808 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FROM);
4049 : 2808 : break;
4050 : 4340 : case OMP_MAP_TOFROM:
4051 : 4340 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_TOFROM);
4052 : 4340 : break;
4053 : 32 : case OMP_MAP_ALWAYS_TO:
4054 : 32 : always_modifier = true;
4055 : 32 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TO);
4056 : 32 : break;
4057 : 14 : case OMP_MAP_ALWAYS_FROM:
4058 : 14 : always_modifier = true;
4059 : 14 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_FROM);
4060 : 14 : break;
4061 : 171 : case OMP_MAP_ALWAYS_TOFROM:
4062 : 171 : always_modifier = true;
4063 : 171 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_TOFROM);
4064 : 171 : break;
4065 : 6 : case OMP_MAP_PRESENT_ALLOC:
4066 : 6 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_ALLOC);
4067 : 6 : break;
4068 : 13 : case OMP_MAP_PRESENT_TO:
4069 : 13 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TO);
4070 : 13 : break;
4071 : 4 : case OMP_MAP_PRESENT_FROM:
4072 : 4 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_FROM);
4073 : 4 : break;
4074 : 2 : case OMP_MAP_PRESENT_TOFROM:
4075 : 2 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_PRESENT_TOFROM);
4076 : 2 : break;
4077 : 8 : case OMP_MAP_ALWAYS_PRESENT_TO:
4078 : 8 : always_modifier = true;
4079 : 8 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TO);
4080 : 8 : break;
4081 : 4 : case OMP_MAP_ALWAYS_PRESENT_FROM:
4082 : 4 : always_modifier = true;
4083 : 4 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_FROM);
4084 : 4 : break;
4085 : 2 : case OMP_MAP_ALWAYS_PRESENT_TOFROM:
4086 : 2 : always_modifier = true;
4087 : 2 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_ALWAYS_PRESENT_TOFROM);
4088 : 2 : break;
4089 : 382 : case OMP_MAP_RELEASE:
4090 : 382 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_RELEASE);
4091 : 382 : break;
4092 : 56 : case OMP_MAP_DELETE:
4093 : 56 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DELETE);
4094 : 56 : break;
4095 : 40 : case OMP_MAP_DETACH:
4096 : 40 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_DETACH);
4097 : 40 : break;
4098 : 63 : case OMP_MAP_FORCE_ALLOC:
4099 : 63 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_ALLOC);
4100 : 63 : break;
4101 : 465 : case OMP_MAP_FORCE_TO:
4102 : 465 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TO);
4103 : 465 : break;
4104 : 577 : case OMP_MAP_FORCE_FROM:
4105 : 577 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_FROM);
4106 : 577 : break;
4107 : 0 : case OMP_MAP_FORCE_TOFROM:
4108 : 0 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_TOFROM);
4109 : 0 : break;
4110 : 545 : case OMP_MAP_FORCE_PRESENT:
4111 : 545 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_PRESENT);
4112 : 545 : break;
4113 : 4 : case OMP_MAP_FORCE_DEVICEPTR:
4114 : 4 : OMP_CLAUSE_SET_MAP_KIND (node, GOMP_MAP_FORCE_DEVICEPTR);
4115 : 4 : break;
4116 : 0 : default:
4117 : 0 : gcc_unreachable ();
4118 : : }
4119 : :
4120 : 14688 : tree decl = gfc_trans_omp_variable (n->sym, false);
4121 : 14688 : if (DECL_P (decl))
4122 : 14688 : TREE_ADDRESSABLE (decl) = 1;
4123 : :
4124 : 14688 : gfc_ref *lastref = NULL;
4125 : :
4126 : 14688 : if (n->expr)
4127 : 12751 : for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
4128 : 7474 : if (ref->type == REF_COMPONENT || ref->type == REF_ARRAY)
4129 : 7474 : lastref = ref;
4130 : :
4131 : 5277 : bool allocatable = false, pointer = false;
4132 : :
4133 : 5277 : if (lastref && lastref->type == REF_COMPONENT)
4134 : : {
4135 : 439 : gfc_component *c = lastref->u.c.component;
4136 : :
4137 : 439 : if (c->ts.type == BT_CLASS)
4138 : : {
4139 : 24 : pointer = CLASS_DATA (c)->attr.class_pointer;
4140 : 24 : allocatable = CLASS_DATA (c)->attr.allocatable;
4141 : : }
4142 : : else
4143 : : {
4144 : 415 : pointer = c->attr.pointer;
4145 : 415 : allocatable = c->attr.allocatable;
4146 : : }
4147 : : }
4148 : :
4149 : 14688 : if (n->expr == NULL
4150 : 5277 : || (n->expr->ref->type == REF_ARRAY
4151 : 3549 : && n->expr->ref->u.ar.type == AR_FULL))
4152 : : {
4153 : 9411 : gomp_map_kind map_kind;
4154 : 9411 : tree type = TREE_TYPE (decl);
4155 : 9411 : if (n->sym->ts.type == BT_CHARACTER
4156 : 182 : && n->sym->ts.deferred
4157 : 68 : && n->sym->attr.omp_declare_target
4158 : 8 : && (always_modifier || n->sym->attr.pointer)
4159 : 8 : && op != EXEC_OMP_TARGET_EXIT_DATA
4160 : 4 : && n->u.map.op != OMP_MAP_DELETE
4161 : 4 : && n->u.map.op != OMP_MAP_RELEASE)
4162 : : {
4163 : 4 : gcc_assert (n->sym->ts.u.cl->backend_decl);
4164 : 4 : node5 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4165 : 4 : OMP_CLAUSE_SET_MAP_KIND (node5, GOMP_MAP_ALWAYS_TO);
4166 : 4 : OMP_CLAUSE_DECL (node5) = n->sym->ts.u.cl->backend_decl;
4167 : 4 : OMP_CLAUSE_SIZE (node5)
4168 : 8 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4169 : : }
4170 : :
4171 : 9411 : tree present = gfc_omp_check_optional_argument (decl, true);
4172 : 9411 : if (openacc && n->sym->ts.type == BT_CLASS)
4173 : : {
4174 : 60 : if (n->sym->attr.optional)
4175 : 0 : sorry_at (gfc_get_location (&n->where),
4176 : : "optional class parameter");
4177 : 60 : tree ptr = gfc_class_data_get (decl);
4178 : 60 : ptr = build_fold_indirect_ref (ptr);
4179 : 60 : OMP_CLAUSE_DECL (node) = ptr;
4180 : 60 : OMP_CLAUSE_SIZE (node) = gfc_class_vtab_size_get (decl);
4181 : 60 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4182 : 60 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
4183 : 60 : OMP_CLAUSE_DECL (node2) = gfc_class_data_get (decl);
4184 : 60 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4185 : 60 : goto finalize_map_clause;
4186 : : }
4187 : 9351 : else if (POINTER_TYPE_P (type)
4188 : 9351 : && (gfc_omp_privatize_by_reference (decl)
4189 : 466 : || GFC_DECL_GET_SCALAR_POINTER (decl)
4190 : 304 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
4191 : 78 : || GFC_DECL_CRAY_POINTEE (decl)
4192 : 78 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))
4193 : 78 : || (n->sym->ts.type == BT_DERIVED
4194 : 8 : && (n->sym->ts.u.derived->ts.f90_type
4195 : : != BT_VOID))))
4196 : : {
4197 : 3348 : tree orig_decl = decl;
4198 : :
4199 : : /* For nonallocatable, nonpointer arrays, a temporary
4200 : : variable is generated, but this one is only defined if
4201 : : the variable is present; hence, we now set it to NULL
4202 : : to avoid accessing undefined variables. We cannot use
4203 : : a temporary variable here as otherwise the replacement
4204 : : of the variables in omp-low.cc will not work. */
4205 : 3348 : if (present && GFC_ARRAY_TYPE_P (type))
4206 : : {
4207 : 284 : tree tmp = fold_build2_loc (input_location,
4208 : : MODIFY_EXPR,
4209 : : void_type_node, decl,
4210 : : null_pointer_node);
4211 : 284 : tree cond = fold_build1_loc (input_location,
4212 : : TRUTH_NOT_EXPR,
4213 : : boolean_type_node,
4214 : : present);
4215 : 284 : gfc_add_expr_to_block (block,
4216 : : build3_loc (input_location,
4217 : : COND_EXPR,
4218 : : void_type_node,
4219 : : cond, tmp,
4220 : : NULL_TREE));
4221 : : }
4222 : : /* For descriptor types, the unmapping happens below. */
4223 : 3348 : if (op != EXEC_OMP_TARGET_EXIT_DATA
4224 : 3348 : || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
4225 : : {
4226 : 3348 : enum gomp_map_kind gmk = GOMP_MAP_POINTER;
4227 : 3348 : if (op == EXEC_OMP_TARGET_EXIT_DATA
4228 : 43 : && n->u.map.op == OMP_MAP_DELETE)
4229 : : gmk = GOMP_MAP_DELETE;
4230 : 38 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4231 : 38 : gmk = GOMP_MAP_RELEASE;
4232 : 3348 : tree size;
4233 : 3348 : if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
4234 : 43 : size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
4235 : : else
4236 : 3305 : size = size_int (0);
4237 : 3348 : node4 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4238 : 3348 : OMP_CLAUSE_SET_MAP_KIND (node4, gmk);
4239 : 3348 : OMP_CLAUSE_DECL (node4) = decl;
4240 : 3348 : OMP_CLAUSE_SIZE (node4) = size;
4241 : : }
4242 : 3348 : decl = build_fold_indirect_ref (decl);
4243 : 3348 : if ((TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE
4244 : 2121 : || gfc_omp_is_optional_argument (orig_decl))
4245 : 4400 : && (GFC_DECL_GET_SCALAR_POINTER (orig_decl)
4246 : 2109 : || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl)))
4247 : : {
4248 : 408 : enum gomp_map_kind gmk;
4249 : 408 : if (op == EXEC_OMP_TARGET_EXIT_DATA
4250 : 8 : && n->u.map.op == OMP_MAP_DELETE)
4251 : : gmk = GOMP_MAP_DELETE;
4252 : 6 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4253 : : gmk = GOMP_MAP_RELEASE;
4254 : : else
4255 : : gmk = GOMP_MAP_POINTER;
4256 : 408 : tree size;
4257 : 408 : if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE)
4258 : 8 : size = TYPE_SIZE_UNIT (TREE_TYPE (decl));
4259 : : else
4260 : 400 : size = size_int (0);
4261 : 408 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4262 : 408 : OMP_CLAUSE_SET_MAP_KIND (node3, gmk);
4263 : 408 : OMP_CLAUSE_DECL (node3) = decl;
4264 : 408 : OMP_CLAUSE_SIZE (node3) = size;
4265 : 408 : decl = build_fold_indirect_ref (decl);
4266 : : }
4267 : : }
4268 : 9351 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
4269 : : {
4270 : 1365 : tree type = TREE_TYPE (decl);
4271 : 1365 : tree ptr = gfc_conv_descriptor_data_get (decl);
4272 : 1365 : if (present)
4273 : 309 : ptr = gfc_build_cond_assign_expr (block, present, ptr,
4274 : : null_pointer_node);
4275 : 1365 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
4276 : 1365 : ptr = build_fold_indirect_ref (ptr);
4277 : 1365 : OMP_CLAUSE_DECL (node) = ptr;
4278 : 1365 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4279 : 1365 : OMP_CLAUSE_DECL (node2) = decl;
4280 : 1365 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
4281 : 1365 : if (n->u.map.op == OMP_MAP_DELETE)
4282 : : map_kind = GOMP_MAP_DELETE;
4283 : 1338 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
4284 : 1283 : || n->u.map.op == OMP_MAP_RELEASE)
4285 : : map_kind = GOMP_MAP_RELEASE;
4286 : : else
4287 : 1365 : map_kind = GOMP_MAP_TO_PSET;
4288 : 1365 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
4289 : :
4290 : 1365 : if (op != EXEC_OMP_TARGET_EXIT_DATA
4291 : 1283 : && n->u.map.op != OMP_MAP_DELETE
4292 : 1283 : && n->u.map.op != OMP_MAP_RELEASE)
4293 : : {
4294 : 1241 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4295 : 1241 : if (present)
4296 : : {
4297 : 309 : ptr = gfc_conv_descriptor_data_get (decl);
4298 : 309 : ptr = gfc_build_addr_expr (NULL, ptr);
4299 : 309 : ptr = gfc_build_cond_assign_expr (
4300 : : block, present, ptr, null_pointer_node);
4301 : 309 : ptr = build_fold_indirect_ref (ptr);
4302 : 309 : OMP_CLAUSE_DECL (node3) = ptr;
4303 : : }
4304 : : else
4305 : 932 : OMP_CLAUSE_DECL (node3)
4306 : 1864 : = gfc_conv_descriptor_data_get (decl);
4307 : 1241 : OMP_CLAUSE_SIZE (node3) = size_int (0);
4308 : :
4309 : 1241 : if (n->u.map.op == OMP_MAP_ATTACH)
4310 : : {
4311 : : /* Standalone attach clauses used with arrays with
4312 : : descriptors must copy the descriptor to the
4313 : : target, else they won't have anything to
4314 : : perform the attachment onto (see OpenACC 2.6,
4315 : : "2.6.3. Data Structures with Pointers"). */
4316 : 7 : OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH);
4317 : : /* We don't want to map PTR at all in this case,
4318 : : so delete its node and shuffle the others
4319 : : down. */
4320 : 7 : node = node2;
4321 : 7 : node2 = node3;
4322 : 7 : node3 = NULL;
4323 : 7 : goto finalize_map_clause;
4324 : : }
4325 : 1234 : else if (n->u.map.op == OMP_MAP_DETACH)
4326 : : {
4327 : 2 : OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_DETACH);
4328 : : /* Similarly to above, we don't want to unmap PTR
4329 : : here. */
4330 : 2 : node = node2;
4331 : 2 : node2 = node3;
4332 : 2 : node3 = NULL;
4333 : 2 : goto finalize_map_clause;
4334 : : }
4335 : : else
4336 : 2002 : OMP_CLAUSE_SET_MAP_KIND (node3,
4337 : : always_modifier
4338 : : ? GOMP_MAP_ALWAYS_POINTER
4339 : : : GOMP_MAP_POINTER);
4340 : : }
4341 : :
4342 : : /* We have to check for n->sym->attr.dimension because
4343 : : of scalar coarrays. */
4344 : 1356 : if ((n->sym->attr.pointer || n->sym->attr.allocatable)
4345 : 1356 : && n->sym->attr.dimension)
4346 : : {
4347 : 1356 : stmtblock_t cond_block;
4348 : 1356 : tree size
4349 : 1356 : = gfc_create_var (gfc_array_index_type, NULL);
4350 : 1356 : tree tem, then_b, else_b, zero, cond;
4351 : :
4352 : 1356 : gfc_init_block (&cond_block);
4353 : 1356 : tem
4354 : 2712 : = gfc_full_array_size (&cond_block, decl,
4355 : 1356 : GFC_TYPE_ARRAY_RANK (type));
4356 : 1356 : tree elemsz;
4357 : 1356 : if (n->sym->ts.type == BT_CHARACTER
4358 : 40 : && n->sym->ts.deferred)
4359 : : {
4360 : 32 : tree len = n->sym->ts.u.cl->backend_decl;
4361 : 32 : len = fold_convert (size_type_node, len);
4362 : 32 : elemsz = gfc_get_char_type (n->sym->ts.kind);
4363 : 32 : elemsz = TYPE_SIZE_UNIT (elemsz);
4364 : 32 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
4365 : : len, elemsz);
4366 : 32 : }
4367 : : else
4368 : 1324 : elemsz
4369 : 1324 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4370 : 1356 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4371 : 1356 : tem = fold_build2 (MULT_EXPR, gfc_array_index_type,
4372 : : tem, elemsz);
4373 : 1356 : gfc_add_modify (&cond_block, size, tem);
4374 : 1356 : then_b = gfc_finish_block (&cond_block);
4375 : 1356 : gfc_init_block (&cond_block);
4376 : 1356 : zero = build_int_cst (gfc_array_index_type, 0);
4377 : 1356 : gfc_add_modify (&cond_block, size, zero);
4378 : 1356 : else_b = gfc_finish_block (&cond_block);
4379 : 1356 : tem = gfc_conv_descriptor_data_get (decl);
4380 : 1356 : tem = fold_convert (pvoid_type_node, tem);
4381 : 1356 : cond = fold_build2_loc (input_location, NE_EXPR,
4382 : : boolean_type_node,
4383 : : tem, null_pointer_node);
4384 : 1356 : if (present)
4385 : 309 : cond = fold_build2_loc (input_location,
4386 : : TRUTH_ANDIF_EXPR,
4387 : : boolean_type_node,
4388 : : present, cond);
4389 : 1356 : gfc_add_expr_to_block (block,
4390 : : build3_loc (input_location,
4391 : : COND_EXPR,
4392 : : void_type_node,
4393 : : cond, then_b,
4394 : : else_b));
4395 : 1356 : OMP_CLAUSE_SIZE (node) = size;
4396 : 1356 : }
4397 : 0 : else if (n->sym->attr.dimension)
4398 : : {
4399 : 0 : stmtblock_t cond_block;
4400 : 0 : gfc_init_block (&cond_block);
4401 : 0 : tree size = gfc_full_array_size (&cond_block, decl,
4402 : 0 : GFC_TYPE_ARRAY_RANK (type));
4403 : 0 : tree elemsz
4404 : 0 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4405 : 0 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4406 : 0 : size = fold_build2 (MULT_EXPR, gfc_array_index_type,
4407 : : size, elemsz);
4408 : 0 : size = gfc_evaluate_now (size, &cond_block);
4409 : 0 : if (present)
4410 : : {
4411 : 0 : tree var = gfc_create_var (gfc_array_index_type,
4412 : : NULL);
4413 : 0 : gfc_add_modify (&cond_block, var, size);
4414 : 0 : tree cond_body = gfc_finish_block (&cond_block);
4415 : 0 : tree cond = build3_loc (input_location, COND_EXPR,
4416 : : void_type_node, present,
4417 : : cond_body, NULL_TREE);
4418 : 0 : gfc_add_expr_to_block (block, cond);
4419 : 0 : OMP_CLAUSE_SIZE (node) = var;
4420 : : }
4421 : : else
4422 : : {
4423 : 0 : gfc_add_block_to_block (block, &cond_block);
4424 : 0 : OMP_CLAUSE_SIZE (node) = size;
4425 : : }
4426 : : }
4427 : : }
4428 : 7986 : else if (present
4429 : 845 : && INDIRECT_REF_P (decl)
4430 : 8729 : && INDIRECT_REF_P (TREE_OPERAND (decl, 0)))
4431 : : {
4432 : : /* A single indirectref is handled by the middle end. */
4433 : 228 : gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl)));
4434 : 228 : tree tmp = TREE_OPERAND (decl, 0);
4435 : 228 : tmp = gfc_build_cond_assign_expr (block, present, tmp,
4436 : : null_pointer_node);
4437 : 228 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (tmp);
4438 : : }
4439 : : else
4440 : 7758 : OMP_CLAUSE_DECL (node) = decl;
4441 : :
4442 : 9342 : if (!n->sym->attr.dimension
4443 : 5915 : && n->sym->ts.type == BT_CHARACTER
4444 : 126 : && n->sym->ts.deferred)
4445 : : {
4446 : 36 : if (!DECL_P (decl))
4447 : : {
4448 : 36 : gcc_assert (TREE_CODE (decl) == INDIRECT_REF);
4449 : 36 : decl = TREE_OPERAND (decl, 0);
4450 : : }
4451 : 36 : tree cond = fold_build2_loc (input_location, NE_EXPR,
4452 : : boolean_type_node,
4453 : : decl, null_pointer_node);
4454 : 36 : if (present)
4455 : 2 : cond = fold_build2_loc (input_location,
4456 : : TRUTH_ANDIF_EXPR,
4457 : : boolean_type_node,
4458 : : present, cond);
4459 : 36 : tree len = n->sym->ts.u.cl->backend_decl;
4460 : 36 : len = fold_convert (size_type_node, len);
4461 : 36 : tree size = gfc_get_char_type (n->sym->ts.kind);
4462 : 36 : size = TYPE_SIZE_UNIT (size);
4463 : 36 : size = fold_build2 (MULT_EXPR, size_type_node, len, size);
4464 : 36 : size = build3_loc (input_location,
4465 : : COND_EXPR,
4466 : : size_type_node,
4467 : : cond, size,
4468 : : size_zero_node);
4469 : 36 : size = gfc_evaluate_now (size, block);
4470 : 36 : OMP_CLAUSE_SIZE (node) = size;
4471 : : }
4472 : 9342 : if ((TREE_CODE (decl) != PARM_DECL
4473 : 186 : || DECL_ARTIFICIAL (OMP_CLAUSE_DECL (node)))
4474 : 9156 : && n->sym->ts.type == BT_DERIVED
4475 : 9843 : && n->sym->ts.u.derived->attr.alloc_comp)
4476 : : {
4477 : : /* Save array descriptor for use in
4478 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4479 : : to ensure that it is not gimplified + is a decl. */
4480 : 188 : tree tmp = OMP_CLAUSE_SIZE (node);
4481 : 188 : if (tmp == NULL_TREE)
4482 : 205 : tmp = DECL_P (decl) ? DECL_SIZE_UNIT (decl)
4483 : 46 : : TYPE_SIZE_UNIT (TREE_TYPE (decl));
4484 : 188 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4485 : 188 : gfc_add_modify_loc (input_location, block, var, tmp);
4486 : 188 : OMP_CLAUSE_SIZE (node) = var;
4487 : 188 : gfc_allocate_lang_decl (var);
4488 : 188 : if (TREE_CODE (decl) == INDIRECT_REF)
4489 : 48 : decl = TREE_OPERAND (decl, 0);
4490 : 188 : if (TREE_CODE (decl) == INDIRECT_REF)
4491 : 2 : decl = TREE_OPERAND (decl, 0);
4492 : 188 : if (DECL_LANG_SPECIFIC (decl)
4493 : 188 : && GFC_DECL_SAVED_DESCRIPTOR (decl))
4494 : 6 : GFC_DECL_SAVED_DESCRIPTOR (var)
4495 : 2 : = GFC_DECL_SAVED_DESCRIPTOR (decl);
4496 : : else
4497 : 186 : GFC_DECL_SAVED_DESCRIPTOR (var) = decl;
4498 : : }
4499 : : }
4500 : 5277 : else if (n->expr
4501 : 5277 : && n->expr->expr_type == EXPR_VARIABLE
4502 : 5277 : && n->expr->ref->type == REF_ARRAY
4503 : 3549 : && !n->expr->ref->next)
4504 : : {
4505 : : /* An array element or array section which is not part of a
4506 : : derived type, etc. */
4507 : 3294 : bool element = n->expr->ref->u.ar.type == AR_ELEMENT;
4508 : 3294 : tree type = TREE_TYPE (decl);
4509 : 3294 : gomp_map_kind k = GOMP_MAP_POINTER;
4510 : 3294 : if (!openacc
4511 : 443 : && !GFC_DESCRIPTOR_TYPE_P (type)
4512 : 3682 : && !(POINTER_TYPE_P (type)
4513 : 256 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type))))
4514 : : k = GOMP_MAP_FIRSTPRIVATE_POINTER;
4515 : 3294 : gfc_trans_omp_array_section (block, op, n, decl, element,
4516 : 3294 : !openacc, k, node, node2,
4517 : : node3, node4);
4518 : 3294 : }
4519 : 1983 : else if (n->expr
4520 : 1983 : && n->expr->expr_type == EXPR_VARIABLE
4521 : 1983 : && (n->expr->ref->type == REF_COMPONENT
4522 : : || n->expr->ref->type == REF_ARRAY)
4523 : 1983 : && lastref
4524 : 1983 : && lastref->type == REF_COMPONENT
4525 : 439 : && lastref->u.c.component->ts.type != BT_CLASS
4526 : 415 : && lastref->u.c.component->ts.type != BT_DERIVED
4527 : 323 : && !lastref->u.c.component->attr.dimension)
4528 : : {
4529 : : /* Derived type access with last component being a scalar. */
4530 : 323 : gfc_init_se (&se, NULL);
4531 : :
4532 : 323 : gfc_conv_expr (&se, n->expr);
4533 : 323 : gfc_add_block_to_block (block, &se.pre);
4534 : : /* For BT_CHARACTER a pointer is returned. */
4535 : 323 : OMP_CLAUSE_DECL (node)
4536 : 558 : = POINTER_TYPE_P (TREE_TYPE (se.expr))
4537 : 323 : ? build_fold_indirect_ref (se.expr) : se.expr;
4538 : 323 : gfc_add_block_to_block (block, &se.post);
4539 : 323 : if (pointer || allocatable)
4540 : : {
4541 : : /* If it's a bare attach/detach clause, we just want
4542 : : to perform a single attach/detach operation, of the
4543 : : pointer itself, not of the pointed-to object. */
4544 : 152 : if (openacc
4545 : 68 : && (n->u.map.op == OMP_MAP_ATTACH
4546 : 50 : || n->u.map.op == OMP_MAP_DETACH))
4547 : : {
4548 : 36 : OMP_CLAUSE_DECL (node)
4549 : 36 : = build_fold_addr_expr (OMP_CLAUSE_DECL (node));
4550 : 36 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4551 : 36 : goto finalize_map_clause;
4552 : : }
4553 : :
4554 : 116 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4555 : 116 : OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH);
4556 : 116 : OMP_CLAUSE_DECL (node2)
4557 : 168 : = POINTER_TYPE_P (TREE_TYPE (se.expr))
4558 : 116 : ? se.expr
4559 : 52 : : gfc_build_addr_expr (NULL, se.expr);
4560 : 116 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4561 : 116 : if (!openacc
4562 : 84 : && n->expr->ts.type == BT_CHARACTER
4563 : 48 : && n->expr->ts.deferred)
4564 : : {
4565 : 48 : gcc_assert (se.string_length);
4566 : 48 : tree tmp
4567 : 48 : = gfc_get_char_type (n->expr->ts.kind);
4568 : 48 : OMP_CLAUSE_SIZE (node)
4569 : 48 : = fold_build2 (MULT_EXPR, size_type_node,
4570 : : fold_convert (size_type_node,
4571 : : se.string_length),
4572 : : TYPE_SIZE_UNIT (tmp));
4573 : 48 : gomp_map_kind kind;
4574 : 48 : if (n->u.map.op == OMP_MAP_DELETE)
4575 : : kind = GOMP_MAP_DELETE;
4576 : 48 : else if (op == EXEC_OMP_TARGET_EXIT_DATA)
4577 : : kind = GOMP_MAP_RELEASE;
4578 : : else
4579 : 44 : kind = GOMP_MAP_TO;
4580 : 48 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4581 : 48 : OMP_CLAUSE_SET_MAP_KIND (node3, kind);
4582 : 48 : OMP_CLAUSE_DECL (node3) = se.string_length;
4583 : 48 : OMP_CLAUSE_SIZE (node3)
4584 : 96 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4585 : : }
4586 : 84 : if (!openacc
4587 : 84 : && n->expr->ts.type == BT_DERIVED
4588 : 0 : && n->expr->ts.u.derived->attr.alloc_comp)
4589 : : {
4590 : : /* Save array descriptor for use in
4591 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4592 : : to ensure that it is not gimplified + is a decl. */
4593 : 0 : tree tmp = OMP_CLAUSE_SIZE (node);
4594 : 0 : if (tmp == NULL_TREE)
4595 : 0 : tmp = (DECL_P (se.expr)
4596 : 0 : ? DECL_SIZE_UNIT (se.expr)
4597 : 0 : : TYPE_SIZE_UNIT (TREE_TYPE (se.expr)));
4598 : 0 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4599 : 0 : gfc_add_modify_loc (input_location, block, var, tmp);
4600 : 0 : OMP_CLAUSE_SIZE (node) = var;
4601 : 0 : gfc_allocate_lang_decl (var);
4602 : 0 : if (TREE_CODE (se.expr) == INDIRECT_REF)
4603 : 0 : se.expr = TREE_OPERAND (se.expr, 0);
4604 : 0 : if (DECL_LANG_SPECIFIC (se.expr)
4605 : 0 : && GFC_DECL_SAVED_DESCRIPTOR (se.expr))
4606 : 0 : GFC_DECL_SAVED_DESCRIPTOR (var)
4607 : 0 : = GFC_DECL_SAVED_DESCRIPTOR (se.expr);
4608 : : else
4609 : 0 : GFC_DECL_SAVED_DESCRIPTOR (var) = se.expr;
4610 : : }
4611 : : }
4612 : : }
4613 : 1660 : else if (n->expr
4614 : 1660 : && n->expr->expr_type == EXPR_VARIABLE
4615 : 1660 : && (n->expr->ref->type == REF_COMPONENT
4616 : : || n->expr->ref->type == REF_ARRAY))
4617 : : {
4618 : 1660 : gfc_init_se (&se, NULL);
4619 : 1660 : se.expr = gfc_maybe_dereference_var (n->sym, decl);
4620 : :
4621 : 5496 : for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
4622 : : {
4623 : 3836 : if (ref->type == REF_COMPONENT)
4624 : : {
4625 : 1917 : if (ref->u.c.sym->attr.extension)
4626 : 91 : conv_parent_component_references (&se, ref);
4627 : :
4628 : 1917 : gfc_conv_component_ref (&se, ref);
4629 : : }
4630 : 1919 : else if (ref->type == REF_ARRAY)
4631 : : {
4632 : 1919 : if (ref->u.ar.type == AR_ELEMENT && ref->next)
4633 : 375 : gfc_conv_array_ref (&se, &ref->u.ar, n->expr,
4634 : 375 : &n->expr->where);
4635 : : else
4636 : 1544 : gcc_assert (!ref->next);
4637 : : }
4638 : : else
4639 : 0 : sorry_at (gfc_get_location (&n->where),
4640 : : "unhandled expression type");
4641 : : }
4642 : :
4643 : 1660 : tree inner = se.expr;
4644 : :
4645 : : /* Last component is a derived type or class pointer. */
4646 : 1660 : if (lastref->type == REF_COMPONENT
4647 : 116 : && (lastref->u.c.component->ts.type == BT_DERIVED
4648 : 24 : || lastref->u.c.component->ts.type == BT_CLASS))
4649 : : {
4650 : 116 : if (pointer || allocatable)
4651 : : {
4652 : : /* If it's a bare attach/detach clause, we just want
4653 : : to perform a single attach/detach operation, of the
4654 : : pointer itself, not of the pointed-to object. */
4655 : 67 : if (openacc
4656 : 49 : && (n->u.map.op == OMP_MAP_ATTACH
4657 : 43 : || n->u.map.op == OMP_MAP_DETACH))
4658 : : {
4659 : 12 : OMP_CLAUSE_DECL (node)
4660 : 12 : = build_fold_addr_expr (inner);
4661 : 12 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4662 : 18 : goto finalize_map_clause;
4663 : : }
4664 : :
4665 : 55 : gfc_omp_namelist *n2
4666 : 18 : = openacc ? NULL : clauses->lists[OMP_LIST_MAP];
4667 : :
4668 : 55 : bool sym_based;
4669 : 55 : n2 = get_symbol_rooted_namelist (sym_rooted_nl, n,
4670 : : n2, &sym_based);
4671 : :
4672 : : /* If the last reference is a pointer to a derived
4673 : : type ("foo%dt_ptr"), check if any subcomponents
4674 : : of the same derived type member are being mapped
4675 : : elsewhere in the clause list ("foo%dt_ptr%x",
4676 : : etc.). If we have such subcomponent mappings,
4677 : : we only create an ALLOC node for the pointer
4678 : : itself, and inhibit mapping the whole derived
4679 : : type. */
4680 : :
4681 : 103 : for (; n2 != NULL; n2 = n2->next)
4682 : : {
4683 : 54 : if ((!sym_based && n == n2)
4684 : 54 : || (sym_based && n == n2->u2.duplicate_of)
4685 : 42 : || !n2->expr)
4686 : 12 : continue;
4687 : :
4688 : 42 : if (!gfc_omp_expr_prefix_same (n->expr,
4689 : : n2->expr))
4690 : 36 : continue;
4691 : :
4692 : 6 : gfc_ref *ref1 = n->expr->ref;
4693 : 6 : gfc_ref *ref2 = n2->expr->ref;
4694 : :
4695 : 6 : while (ref1->next && ref2->next)
4696 : : {
4697 : : ref1 = ref1->next;
4698 : : ref2 = ref2->next;
4699 : : }
4700 : :
4701 : 6 : if (ref2->next)
4702 : : {
4703 : 6 : inner = build_fold_addr_expr (inner);
4704 : 6 : OMP_CLAUSE_SET_MAP_KIND (node,
4705 : : GOMP_MAP_ALLOC);
4706 : 6 : OMP_CLAUSE_DECL (node) = inner;
4707 : 6 : OMP_CLAUSE_SIZE (node)
4708 : 6 : = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4709 : 6 : goto finalize_map_clause;
4710 : : }
4711 : : }
4712 : :
4713 : 49 : tree data, size;
4714 : :
4715 : 49 : if (lastref->u.c.component->ts.type == BT_CLASS)
4716 : : {
4717 : 24 : data = gfc_class_data_get (inner);
4718 : 24 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (data)));
4719 : 24 : data = build_fold_indirect_ref (data);
4720 : 24 : size = gfc_class_vtab_size_get (inner);
4721 : : }
4722 : : else /* BT_DERIVED. */
4723 : : {
4724 : 25 : data = inner;
4725 : 25 : size = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4726 : : }
4727 : :
4728 : 49 : OMP_CLAUSE_DECL (node) = data;
4729 : 49 : OMP_CLAUSE_SIZE (node) = size;
4730 : 49 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4731 : 49 : OMP_CLAUSE_SET_MAP_KIND (node2,
4732 : : GOMP_MAP_ATTACH_DETACH);
4733 : 49 : OMP_CLAUSE_DECL (node2) = build_fold_addr_expr (data);
4734 : 49 : OMP_CLAUSE_SIZE (node2) = size_int (0);
4735 : : }
4736 : : else
4737 : : {
4738 : 49 : OMP_CLAUSE_DECL (node) = inner;
4739 : 49 : OMP_CLAUSE_SIZE (node)
4740 : 98 : = TYPE_SIZE_UNIT (TREE_TYPE (inner));
4741 : : }
4742 : 98 : if (!openacc
4743 : 14 : && n->expr->ts.type == BT_DERIVED
4744 : 14 : && n->expr->ts.u.derived->attr.alloc_comp)
4745 : : {
4746 : : /* Save array descriptor for use in
4747 : : gfc_omp_deep_mapping{,_p,_cnt}; force evaluate
4748 : : to ensure that it is not gimplified + is a decl. */
4749 : 8 : tree tmp = OMP_CLAUSE_SIZE (node);
4750 : 8 : tree var = gfc_create_var (TREE_TYPE (tmp), NULL);
4751 : 8 : gfc_add_modify_loc (input_location, block, var, tmp);
4752 : 8 : OMP_CLAUSE_SIZE (node) = var;
4753 : 8 : gfc_allocate_lang_decl (var);
4754 : 8 : if (TREE_CODE (inner) == INDIRECT_REF)
4755 : 6 : inner = TREE_OPERAND (inner, 0);
4756 : 8 : GFC_DECL_SAVED_DESCRIPTOR (var) = inner;
4757 : : }
4758 : : }
4759 : 1544 : else if (lastref->type == REF_ARRAY
4760 : 1544 : && lastref->u.ar.type == AR_FULL)
4761 : : {
4762 : : /* Bare attach and detach clauses don't want any
4763 : : additional nodes. */
4764 : 858 : if ((n->u.map.op == OMP_MAP_ATTACH
4765 : 827 : || n->u.map.op == OMP_MAP_DETACH)
4766 : 872 : && (POINTER_TYPE_P (TREE_TYPE (inner))
4767 : 45 : || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner))))
4768 : : {
4769 : 45 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
4770 : : {
4771 : 45 : tree ptr = gfc_conv_descriptor_data_get (inner);
4772 : 45 : OMP_CLAUSE_DECL (node) = ptr;
4773 : : }
4774 : : else
4775 : 0 : OMP_CLAUSE_DECL (node) = inner;
4776 : 45 : OMP_CLAUSE_SIZE (node) = size_zero_node;
4777 : 45 : goto finalize_map_clause;
4778 : : }
4779 : :
4780 : 813 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (inner)))
4781 : : {
4782 : 649 : gomp_map_kind map_kind;
4783 : 649 : tree type = TREE_TYPE (inner);
4784 : 649 : tree ptr = gfc_conv_descriptor_data_get (inner);
4785 : 649 : ptr = build_fold_indirect_ref (ptr);
4786 : 649 : OMP_CLAUSE_DECL (node) = ptr;
4787 : 649 : int rank = GFC_TYPE_ARRAY_RANK (type);
4788 : 649 : OMP_CLAUSE_SIZE (node)
4789 : 649 : = gfc_full_array_size (block, inner, rank);
4790 : 649 : tree elemsz
4791 : 649 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
4792 : 649 : map_kind = OMP_CLAUSE_MAP_KIND (node);
4793 : 649 : if (GOMP_MAP_COPY_TO_P (map_kind)
4794 : 107 : || map_kind == GOMP_MAP_ALLOC)
4795 : 563 : map_kind = ((GOMP_MAP_ALWAYS_P (map_kind)
4796 : 1054 : || gfc_expr_attr (n->expr).pointer)
4797 : 563 : ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO);
4798 : 86 : else if (n->u.map.op == OMP_MAP_RELEASE
4799 : 82 : || n->u.map.op == OMP_MAP_DELETE)
4800 : : ;
4801 : 81 : else if (op == EXEC_OMP_TARGET_EXIT_DATA
4802 : 81 : || op == EXEC_OACC_EXIT_DATA)
4803 : : map_kind = GOMP_MAP_RELEASE;
4804 : : else
4805 : 29 : map_kind = GOMP_MAP_ALLOC;
4806 : 649 : if (!openacc
4807 : 509 : && n->expr->ts.type == BT_CHARACTER
4808 : 36 : && n->expr->ts.deferred)
4809 : : {
4810 : 36 : gcc_assert (se.string_length);
4811 : 36 : tree len = fold_convert (size_type_node,
4812 : : se.string_length);
4813 : 36 : elemsz = gfc_get_char_type (n->expr->ts.kind);
4814 : 36 : elemsz = TYPE_SIZE_UNIT (elemsz);
4815 : 36 : elemsz = fold_build2 (MULT_EXPR, size_type_node,
4816 : : len, elemsz);
4817 : 36 : node4 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4818 : 36 : OMP_CLAUSE_SET_MAP_KIND (node4, map_kind);
4819 : 36 : OMP_CLAUSE_DECL (node4) = se.string_length;
4820 : 36 : OMP_CLAUSE_SIZE (node4)
4821 : 72 : = TYPE_SIZE_UNIT (gfc_charlen_type_node);
4822 : : }
4823 : 649 : elemsz = fold_convert (gfc_array_index_type, elemsz);
4824 : 649 : OMP_CLAUSE_SIZE (node)
4825 : 649 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
4826 : : OMP_CLAUSE_SIZE (node), elemsz);
4827 : 649 : node2 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4828 : 649 : if (map_kind == GOMP_MAP_RELEASE
4829 : 649 : || map_kind == GOMP_MAP_DELETE)
4830 : : {
4831 : 57 : OMP_CLAUSE_SET_MAP_KIND (node2, map_kind);
4832 : 57 : OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1;
4833 : : }
4834 : : else
4835 : 592 : OMP_CLAUSE_SET_MAP_KIND (node2,
4836 : : GOMP_MAP_TO_PSET);
4837 : 649 : OMP_CLAUSE_DECL (node2) = inner;
4838 : 649 : OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type);
4839 : 649 : if (!openacc)
4840 : : {
4841 : 509 : if (n->expr->ts.type == BT_DERIVED
4842 : 12 : && n->expr->ts.u.derived->attr.alloc_comp)
4843 : : {
4844 : : /* Save array descriptor for use
4845 : : in gfc_omp_deep_mapping{,_p,_cnt}; force
4846 : : evaluate to ensure that it is
4847 : : not gimplified + is a decl. */
4848 : 6 : tree tmp = OMP_CLAUSE_SIZE (node);
4849 : 6 : tree var = gfc_create_var (TREE_TYPE (tmp),
4850 : : NULL);
4851 : 6 : gfc_add_modify_loc (map_loc, block,
4852 : : var, tmp);
4853 : 6 : OMP_CLAUSE_SIZE (node) = var;
4854 : 6 : gfc_allocate_lang_decl (var);
4855 : 6 : GFC_DECL_SAVED_DESCRIPTOR (var) = inner;
4856 : : }
4857 : :
4858 : 509 : gfc_omp_namelist *n2
4859 : : = clauses->lists[OMP_LIST_MAP];
4860 : :
4861 : : /* If we don't have a mapping of a smaller part
4862 : : of the array -- or we can't prove that we do
4863 : : statically -- set this flag. If there is a
4864 : : mapping of a smaller part of the array after
4865 : : all, this will turn into a no-op at
4866 : : runtime. */
4867 : 509 : OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (node) = 1;
4868 : :
4869 : 509 : bool sym_based;
4870 : 509 : n2 = get_symbol_rooted_namelist (sym_rooted_nl,
4871 : : n, n2,
4872 : : &sym_based);
4873 : :
4874 : 509 : bool drop_mapping = false;
4875 : :
4876 : 1643 : for (; n2 != NULL; n2 = n2->next)
4877 : : {
4878 : 1414 : if ((!sym_based && n == n2)
4879 : 1414 : || (sym_based && n == n2->u2.duplicate_of)
4880 : 1167 : || !n2->expr)
4881 : 247 : continue;
4882 : :
4883 : 1167 : if (!gfc_omp_expr_prefix_same (n->expr,
4884 : : n2->expr))
4885 : 887 : continue;
4886 : :
4887 : 280 : gfc_ref *ref1 = n->expr->ref;
4888 : 280 : gfc_ref *ref2 = n2->expr->ref;
4889 : :
4890 : : /* We know ref1 and ref2 overlap. We're
4891 : : interested in whether ref2 describes a
4892 : : smaller part of the array than ref1, which
4893 : : we already know refers to the full
4894 : : array. */
4895 : :
4896 : 620 : while (ref1->next && ref2->next)
4897 : : {
4898 : : ref1 = ref1->next;
4899 : : ref2 = ref2->next;
4900 : : }
4901 : :
4902 : 280 : if (ref2->next
4903 : 280 : || (ref2->type == REF_ARRAY
4904 : 280 : && (ref2->u.ar.type == AR_ELEMENT
4905 : 280 : || (ref2->u.ar.type
4906 : : == AR_SECTION))))
4907 : : {
4908 : : drop_mapping = true;
4909 : : break;
4910 : : }
4911 : : }
4912 : 509 : if (drop_mapping)
4913 : 280 : continue;
4914 : : }
4915 : 369 : node3 = build_omp_clause (map_loc, OMP_CLAUSE_MAP);
4916 : 369 : OMP_CLAUSE_SET_MAP_KIND (node3,
4917 : : GOMP_MAP_ATTACH_DETACH);
4918 : 369 : OMP_CLAUSE_DECL (node3)
4919 : 369 : = gfc_conv_descriptor_data_get (inner);
4920 : : /* Similar to gfc_trans_omp_array_section (details
4921 : : there), we add/keep the cast for OpenMP to prevent
4922 : : that an 'alloc:' gets added for node3 ('desc.data')
4923 : : as that is part of the whole descriptor (node3).
4924 : : TODO: Remove once the ME handles this properly. */
4925 : 369 : if (!openacc)
4926 : 229 : OMP_CLAUSE_DECL (node3)
4927 : 458 : = fold_convert (TREE_TYPE (TREE_OPERAND(ptr, 0)),
4928 : : OMP_CLAUSE_DECL (node3));
4929 : : else
4930 : 140 : STRIP_NOPS (OMP_CLAUSE_DECL (node3));
4931 : 369 : OMP_CLAUSE_SIZE (node3) = size_int (0);
4932 : : }
4933 : : else
4934 : 164 : OMP_CLAUSE_DECL (node) = inner;
4935 : : }
4936 : 686 : else if (lastref->type == REF_ARRAY)
4937 : : {
4938 : : /* An array element or section. */
4939 : 686 : bool element = lastref->u.ar.type == AR_ELEMENT;
4940 : 686 : gomp_map_kind kind = GOMP_MAP_ATTACH_DETACH;
4941 : 686 : gfc_trans_omp_array_section (block, op, n, inner, element,
4942 : 686 : !openacc, kind, node, node2,
4943 : : node3, node4);
4944 : : }
4945 : : else
4946 : 0 : gcc_unreachable ();
4947 : : }
4948 : : else
4949 : 0 : sorry_at (gfc_get_location (&n->where), "unhandled expression");
4950 : :
4951 : 14408 : finalize_map_clause:
4952 : :
4953 : 14408 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
4954 : 14408 : if (node2)
4955 : 4666 : omp_clauses = gfc_trans_add_clause (node2, omp_clauses);
4956 : 14408 : if (node3)
4957 : 5892 : omp_clauses = gfc_trans_add_clause (node3, omp_clauses);
4958 : 14408 : if (node4)
4959 : 3462 : omp_clauses = gfc_trans_add_clause (node4, omp_clauses);
4960 : 14408 : if (node5)
4961 : 4 : omp_clauses = gfc_trans_add_clause (node5, omp_clauses);
4962 : : }
4963 : : break;
4964 : : case OMP_LIST_TO:
4965 : : case OMP_LIST_FROM:
4966 : : case OMP_LIST_CACHE:
4967 : 3633 : for (; n != NULL; n = n->next)
4968 : : {
4969 : 1860 : if (!n->sym->attr.referenced)
4970 : 0 : continue;
4971 : :
4972 : 1860 : switch (list)
4973 : : {
4974 : : case OMP_LIST_TO:
4975 : : clause_code = OMP_CLAUSE_TO;
4976 : : break;
4977 : 1030 : case OMP_LIST_FROM:
4978 : 1030 : clause_code = OMP_CLAUSE_FROM;
4979 : 1030 : break;
4980 : 82 : case OMP_LIST_CACHE:
4981 : 82 : clause_code = OMP_CLAUSE__CACHE_;
4982 : 82 : break;
4983 : 0 : default:
4984 : 0 : gcc_unreachable ();
4985 : : }
4986 : 1860 : tree node = build_omp_clause (gfc_get_location (&n->where),
4987 : : clause_code);
4988 : 1860 : if (n->expr == NULL
4989 : 128 : || (n->expr->ref->type == REF_ARRAY
4990 : 116 : && n->expr->ref->u.ar.type == AR_FULL
4991 : 0 : && n->expr->ref->next == NULL))
4992 : : {
4993 : 1732 : tree decl = gfc_trans_omp_variable (n->sym, false);
4994 : 1732 : if (gfc_omp_privatize_by_reference (decl))
4995 : : {
4996 : 1047 : if (gfc_omp_is_allocatable_or_ptr (decl))
4997 : 240 : decl = build_fold_indirect_ref (decl);
4998 : 1047 : decl = build_fold_indirect_ref (decl);
4999 : : }
5000 : 685 : else if (DECL_P (decl))
5001 : 685 : TREE_ADDRESSABLE (decl) = 1;
5002 : 1732 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
5003 : : {
5004 : 597 : tree type = TREE_TYPE (decl);
5005 : 597 : tree ptr = gfc_conv_descriptor_data_get (decl);
5006 : 597 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
5007 : 597 : ptr = build_fold_indirect_ref (ptr);
5008 : 597 : OMP_CLAUSE_DECL (node) = ptr;
5009 : 597 : OMP_CLAUSE_SIZE (node)
5010 : 597 : = gfc_full_array_size (block, decl,
5011 : 597 : GFC_TYPE_ARRAY_RANK (type));
5012 : 597 : tree elemsz
5013 : 597 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
5014 : 597 : elemsz = fold_convert (gfc_array_index_type, elemsz);
5015 : 1194 : OMP_CLAUSE_SIZE (node)
5016 : 1194 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
5017 : : OMP_CLAUSE_SIZE (node), elemsz);
5018 : : }
5019 : : else
5020 : : {
5021 : 1135 : OMP_CLAUSE_DECL (node) = decl;
5022 : 1135 : if (gfc_omp_is_allocatable_or_ptr (decl))
5023 : 120 : OMP_CLAUSE_SIZE (node)
5024 : 240 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl)));
5025 : : }
5026 : : }
5027 : : else
5028 : : {
5029 : 128 : tree ptr;
5030 : 128 : gfc_init_se (&se, NULL);
5031 : 128 : if (n->expr->rank == 0)
5032 : : {
5033 : 5 : gfc_conv_expr_reference (&se, n->expr);
5034 : 5 : ptr = se.expr;
5035 : 5 : gfc_add_block_to_block (block, &se.pre);
5036 : 5 : OMP_CLAUSE_SIZE (node)
5037 : 10 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ptr)));
5038 : : }
5039 : : else
5040 : : {
5041 : 123 : gfc_conv_expr_descriptor (&se, n->expr);
5042 : 123 : ptr = gfc_conv_array_data (se.expr);
5043 : 123 : tree type = TREE_TYPE (se.expr);
5044 : 123 : gfc_add_block_to_block (block, &se.pre);
5045 : 123 : OMP_CLAUSE_SIZE (node)
5046 : 123 : = gfc_full_array_size (block, se.expr,
5047 : 123 : GFC_TYPE_ARRAY_RANK (type));
5048 : 123 : tree elemsz
5049 : 123 : = TYPE_SIZE_UNIT (gfc_get_element_type (type));
5050 : 123 : elemsz = fold_convert (gfc_array_index_type, elemsz);
5051 : 246 : OMP_CLAUSE_SIZE (node)
5052 : 246 : = fold_build2 (MULT_EXPR, gfc_array_index_type,
5053 : : OMP_CLAUSE_SIZE (node), elemsz);
5054 : : }
5055 : 128 : gfc_add_block_to_block (block, &se.post);
5056 : 128 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
5057 : 128 : OMP_CLAUSE_DECL (node) = build_fold_indirect_ref (ptr);
5058 : : }
5059 : 1860 : if (n->u.present_modifier)
5060 : 5 : OMP_CLAUSE_MOTION_PRESENT (node) = 1;
5061 : 1860 : if (list == OMP_LIST_CACHE && n->u.map.readonly)
5062 : 16 : OMP_CLAUSE__CACHE__READONLY (node) = 1;
5063 : 1860 : omp_clauses = gfc_trans_add_clause (node, omp_clauses);
5064 : : }
5065 : : break;
5066 : : case OMP_LIST_USES_ALLOCATORS:
5067 : : /* Ignore pre-defined allocators as no special treatment is needed. */
5068 : 30 : for (; n != NULL; n = n->next)
5069 : 28 : if (n->sym->attr.flavor == FL_VARIABLE)
5070 : : break;
5071 : 12 : if (n != NULL)
5072 : 10 : sorry_at (input_location, "%<uses_allocators%> clause with traits "
5073 : : "and memory spaces");
5074 : : break;
5075 : : default:
5076 : : break;
5077 : : }
5078 : : }
5079 : :
5080 : : /* Free hashmap if we built it. */
5081 : 31207 : if (sym_rooted_nl)
5082 : : {
5083 : 243 : typedef hash_map<gfc_symbol *, gfc_omp_namelist *>::iterator hti;
5084 : 843 : for (hti it = sym_rooted_nl->begin (); it != sym_rooted_nl->end (); ++it)
5085 : : {
5086 : 300 : gfc_omp_namelist *&nl = (*it).second;
5087 : 1250 : while (nl)
5088 : : {
5089 : 950 : gfc_omp_namelist *next = nl->next;
5090 : 950 : free (nl);
5091 : 950 : nl = next;
5092 : : }
5093 : : }
5094 : 243 : delete sym_rooted_nl;
5095 : : }
5096 : :
5097 : 31207 : if (clauses->if_expr)
5098 : : {
5099 : 1109 : tree if_var;
5100 : :
5101 : 1109 : gfc_init_se (&se, NULL);
5102 : 1109 : gfc_conv_expr (&se, clauses->if_expr);
5103 : 1109 : gfc_add_block_to_block (block, &se.pre);
5104 : 1109 : if_var = gfc_evaluate_now (se.expr, block);
5105 : 1109 : gfc_add_block_to_block (block, &se.post);
5106 : :
5107 : 1109 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
5108 : 1109 : OMP_CLAUSE_IF_MODIFIER (c) = ERROR_MARK;
5109 : 1109 : OMP_CLAUSE_IF_EXPR (c) = if_var;
5110 : 1109 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5111 : : }
5112 : :
5113 : 343277 : for (ifc = 0; ifc < OMP_IF_LAST; ifc++)
5114 : 312070 : if (clauses->if_exprs[ifc])
5115 : : {
5116 : 123 : tree if_var;
5117 : :
5118 : 123 : gfc_init_se (&se, NULL);
5119 : 123 : gfc_conv_expr (&se, clauses->if_exprs[ifc]);
5120 : 123 : gfc_add_block_to_block (block, &se.pre);
5121 : 123 : if_var = gfc_evaluate_now (se.expr, block);
5122 : 123 : gfc_add_block_to_block (block, &se.post);
5123 : :
5124 : 123 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
5125 : 123 : switch (ifc)
5126 : : {
5127 : 0 : case OMP_IF_CANCEL:
5128 : 0 : OMP_CLAUSE_IF_MODIFIER (c) = VOID_CST;
5129 : 0 : break;
5130 : 40 : case OMP_IF_PARALLEL:
5131 : 40 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL;
5132 : 40 : break;
5133 : 39 : case OMP_IF_SIMD:
5134 : 39 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_SIMD;
5135 : 39 : break;
5136 : 1 : case OMP_IF_TASK:
5137 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASK;
5138 : 1 : break;
5139 : 23 : case OMP_IF_TASKLOOP:
5140 : 23 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASKLOOP;
5141 : 23 : break;
5142 : 16 : case OMP_IF_TARGET:
5143 : 16 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET;
5144 : 16 : break;
5145 : 1 : case OMP_IF_TARGET_DATA:
5146 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_DATA;
5147 : 1 : break;
5148 : 1 : case OMP_IF_TARGET_UPDATE:
5149 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_UPDATE;
5150 : 1 : break;
5151 : 1 : case OMP_IF_TARGET_ENTER_DATA:
5152 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_ENTER_DATA;
5153 : 1 : break;
5154 : 1 : case OMP_IF_TARGET_EXIT_DATA:
5155 : 1 : OMP_CLAUSE_IF_MODIFIER (c) = OMP_TARGET_EXIT_DATA;
5156 : 1 : break;
5157 : : default:
5158 : : gcc_unreachable ();
5159 : : }
5160 : 123 : OMP_CLAUSE_IF_EXPR (c) = if_var;
5161 : 123 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5162 : : }
5163 : :
5164 : 31207 : if (clauses->self_expr)
5165 : : {
5166 : 159 : tree self_var;
5167 : :
5168 : 159 : gfc_init_se (&se, NULL);
5169 : 159 : gfc_conv_expr (&se, clauses->self_expr);
5170 : 159 : gfc_add_block_to_block (block, &se.pre);
5171 : 159 : self_var = gfc_evaluate_now (se.expr, block);
5172 : 159 : gfc_add_block_to_block (block, &se.post);
5173 : :
5174 : 159 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SELF);
5175 : 159 : OMP_CLAUSE_SELF_EXPR (c) = self_var;
5176 : 159 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5177 : : }
5178 : :
5179 : 31207 : if (clauses->final_expr)
5180 : : {
5181 : 64 : tree final_var;
5182 : :
5183 : 64 : gfc_init_se (&se, NULL);
5184 : 64 : gfc_conv_expr (&se, clauses->final_expr);
5185 : 64 : gfc_add_block_to_block (block, &se.pre);
5186 : 64 : final_var = gfc_evaluate_now (se.expr, block);
5187 : 64 : gfc_add_block_to_block (block, &se.post);
5188 : :
5189 : 64 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINAL);
5190 : 64 : OMP_CLAUSE_FINAL_EXPR (c) = final_var;
5191 : 64 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5192 : : }
5193 : :
5194 : 31207 : if (clauses->novariants)
5195 : : {
5196 : 8 : tree novariants_var;
5197 : :
5198 : 8 : gfc_init_se (&se, NULL);
5199 : 8 : gfc_conv_expr (&se, clauses->novariants);
5200 : 8 : gfc_add_block_to_block (block, &se.pre);
5201 : 8 : novariants_var = gfc_evaluate_now (se.expr, block);
5202 : 8 : gfc_add_block_to_block (block, &se.post);
5203 : :
5204 : 8 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOVARIANTS);
5205 : 8 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = novariants_var;
5206 : 8 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5207 : : }
5208 : :
5209 : 31207 : if (clauses->nocontext)
5210 : : {
5211 : 9 : tree nocontext_var;
5212 : :
5213 : 9 : gfc_init_se (&se, NULL);
5214 : 9 : gfc_conv_expr (&se, clauses->nocontext);
5215 : 9 : gfc_add_block_to_block (block, &se.pre);
5216 : 9 : nocontext_var = gfc_evaluate_now (se.expr, block);
5217 : 9 : gfc_add_block_to_block (block, &se.post);
5218 : :
5219 : 9 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOCONTEXT);
5220 : 9 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = nocontext_var;
5221 : 9 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5222 : : }
5223 : :
5224 : 31207 : if (clauses->num_threads)
5225 : : {
5226 : 943 : tree num_threads;
5227 : :
5228 : 943 : gfc_init_se (&se, NULL);
5229 : 943 : gfc_conv_expr (&se, clauses->num_threads);
5230 : 943 : gfc_add_block_to_block (block, &se.pre);
5231 : 943 : num_threads = gfc_evaluate_now (se.expr, block);
5232 : 943 : gfc_add_block_to_block (block, &se.post);
5233 : :
5234 : 943 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_THREADS);
5235 : 943 : OMP_CLAUSE_NUM_THREADS_EXPR (c) = num_threads;
5236 : 943 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5237 : : }
5238 : :
5239 : 31207 : chunk_size = NULL_TREE;
5240 : 31207 : if (clauses->chunk_size)
5241 : : {
5242 : 493 : gfc_init_se (&se, NULL);
5243 : 493 : gfc_conv_expr (&se, clauses->chunk_size);
5244 : 493 : gfc_add_block_to_block (block, &se.pre);
5245 : 493 : chunk_size = gfc_evaluate_now (se.expr, block);
5246 : 493 : gfc_add_block_to_block (block, &se.post);
5247 : : }
5248 : :
5249 : 31207 : if (clauses->sched_kind != OMP_SCHED_NONE)
5250 : : {
5251 : 782 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SCHEDULE);
5252 : 782 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
5253 : 782 : switch (clauses->sched_kind)
5254 : : {
5255 : 407 : case OMP_SCHED_STATIC:
5256 : 407 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
5257 : 407 : break;
5258 : 159 : case OMP_SCHED_DYNAMIC:
5259 : 159 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
5260 : 159 : break;
5261 : 125 : case OMP_SCHED_GUIDED:
5262 : 125 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
5263 : 125 : break;
5264 : 84 : case OMP_SCHED_RUNTIME:
5265 : 84 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
5266 : 84 : break;
5267 : 7 : case OMP_SCHED_AUTO:
5268 : 7 : OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
5269 : 7 : break;
5270 : 0 : default:
5271 : 0 : gcc_unreachable ();
5272 : : }
5273 : 782 : if (clauses->sched_monotonic)
5274 : 54 : OMP_CLAUSE_SCHEDULE_KIND (c)
5275 : 27 : = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
5276 : : | OMP_CLAUSE_SCHEDULE_MONOTONIC);
5277 : 755 : else if (clauses->sched_nonmonotonic)
5278 : 46 : OMP_CLAUSE_SCHEDULE_KIND (c)
5279 : 23 : = (omp_clause_schedule_kind) (OMP_CLAUSE_SCHEDULE_KIND (c)
5280 : : | OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
5281 : 782 : if (clauses->sched_simd)
5282 : 17 : OMP_CLAUSE_SCHEDULE_SIMD (c) = 1;
5283 : 782 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5284 : : }
5285 : :
5286 : 31207 : if (clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
5287 : : {
5288 : 1075 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULT);
5289 : 1075 : switch (clauses->default_sharing)
5290 : : {
5291 : 665 : case OMP_DEFAULT_NONE:
5292 : 665 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_NONE;
5293 : 665 : break;
5294 : 183 : case OMP_DEFAULT_SHARED:
5295 : 183 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_SHARED;
5296 : 183 : break;
5297 : 24 : case OMP_DEFAULT_PRIVATE:
5298 : 24 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRIVATE;
5299 : 24 : break;
5300 : 8 : case OMP_DEFAULT_FIRSTPRIVATE:
5301 : 8 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
5302 : 8 : break;
5303 : 195 : case OMP_DEFAULT_PRESENT:
5304 : 195 : OMP_CLAUSE_DEFAULT_KIND (c) = OMP_CLAUSE_DEFAULT_PRESENT;
5305 : 195 : break;
5306 : 0 : default:
5307 : 0 : gcc_unreachable ();
5308 : : }
5309 : 1075 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5310 : : }
5311 : :
5312 : 31207 : if (clauses->nowait)
5313 : : {
5314 : 2051 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOWAIT);
5315 : 2051 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5316 : : }
5317 : :
5318 : 31207 : if (clauses->full)
5319 : : {
5320 : 47 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FULL);
5321 : 47 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5322 : : }
5323 : :
5324 : 31207 : if (clauses->partial)
5325 : : {
5326 : 259 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARTIAL);
5327 : 259 : OMP_CLAUSE_PARTIAL_EXPR (c)
5328 : 518 : = (clauses->partial > 0
5329 : 259 : ? build_int_cst (integer_type_node, clauses->partial)
5330 : : : NULL_TREE);
5331 : 259 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5332 : : }
5333 : :
5334 : 31207 : if (clauses->sizes_list)
5335 : : {
5336 : : tree list = NULL_TREE;
5337 : 344 : for (gfc_expr_list *el = clauses->sizes_list; el; el = el->next)
5338 : 224 : list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
5339 : : list);
5340 : :
5341 : 120 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIZES);
5342 : 120 : OMP_CLAUSE_SIZES_LIST (c) = nreverse (list);
5343 : 120 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5344 : : }
5345 : :
5346 : 31207 : if (clauses->ordered)
5347 : : {
5348 : 313 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDERED);
5349 : 313 : OMP_CLAUSE_ORDERED_EXPR (c)
5350 : 313 : = clauses->orderedc ? build_int_cst (integer_type_node,
5351 : 132 : clauses->orderedc) : NULL_TREE;
5352 : 313 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5353 : : }
5354 : :
5355 : 31207 : if (clauses->order_concurrent)
5356 : : {
5357 : 303 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDER);
5358 : 303 : OMP_CLAUSE_ORDER_UNCONSTRAINED (c) = clauses->order_unconstrained;
5359 : 303 : OMP_CLAUSE_ORDER_REPRODUCIBLE (c) = clauses->order_reproducible;
5360 : 303 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5361 : : }
5362 : :
5363 : 31207 : if (clauses->untied)
5364 : : {
5365 : 141 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_UNTIED);
5366 : 141 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5367 : : }
5368 : :
5369 : 31207 : if (clauses->mergeable)
5370 : : {
5371 : 32 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_MERGEABLE);
5372 : 32 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5373 : : }
5374 : :
5375 : 31207 : if (clauses->collapse)
5376 : : {
5377 : 1640 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_COLLAPSE);
5378 : 1640 : OMP_CLAUSE_COLLAPSE_EXPR (c)
5379 : 1640 : = build_int_cst (integer_type_node, clauses->collapse);
5380 : 1640 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5381 : : }
5382 : :
5383 : 31207 : if (clauses->inbranch)
5384 : : {
5385 : 18 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INBRANCH);
5386 : 18 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5387 : : }
5388 : :
5389 : 31207 : if (clauses->notinbranch)
5390 : : {
5391 : 23 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOTINBRANCH);
5392 : 23 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5393 : : }
5394 : :
5395 : 31207 : switch (clauses->cancel)
5396 : : {
5397 : : case OMP_CANCEL_UNKNOWN:
5398 : : break;
5399 : 0 : case OMP_CANCEL_PARALLEL:
5400 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARALLEL);
5401 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5402 : 0 : break;
5403 : 0 : case OMP_CANCEL_SECTIONS:
5404 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SECTIONS);
5405 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5406 : 0 : break;
5407 : 0 : case OMP_CANCEL_DO:
5408 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FOR);
5409 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5410 : 0 : break;
5411 : 0 : case OMP_CANCEL_TASKGROUP:
5412 : 0 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TASKGROUP);
5413 : 0 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5414 : 0 : break;
5415 : : }
5416 : :
5417 : 31207 : if (clauses->proc_bind != OMP_PROC_BIND_UNKNOWN)
5418 : : {
5419 : 64 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PROC_BIND);
5420 : 64 : switch (clauses->proc_bind)
5421 : : {
5422 : 1 : case OMP_PROC_BIND_PRIMARY:
5423 : 1 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_PRIMARY;
5424 : 1 : break;
5425 : 9 : case OMP_PROC_BIND_MASTER:
5426 : 9 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_MASTER;
5427 : 9 : break;
5428 : 53 : case OMP_PROC_BIND_SPREAD:
5429 : 53 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_SPREAD;
5430 : 53 : break;
5431 : 1 : case OMP_PROC_BIND_CLOSE:
5432 : 1 : OMP_CLAUSE_PROC_BIND_KIND (c) = OMP_CLAUSE_PROC_BIND_CLOSE;
5433 : 1 : break;
5434 : 0 : default:
5435 : 0 : gcc_unreachable ();
5436 : : }
5437 : 64 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5438 : : }
5439 : :
5440 : 31207 : if (clauses->safelen_expr)
5441 : : {
5442 : 89 : tree safelen_var;
5443 : :
5444 : 89 : gfc_init_se (&se, NULL);
5445 : 89 : gfc_conv_expr (&se, clauses->safelen_expr);
5446 : 89 : gfc_add_block_to_block (block, &se.pre);
5447 : 89 : safelen_var = gfc_evaluate_now (se.expr, block);
5448 : 89 : gfc_add_block_to_block (block, &se.post);
5449 : :
5450 : 89 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SAFELEN);
5451 : 89 : OMP_CLAUSE_SAFELEN_EXPR (c) = safelen_var;
5452 : 89 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5453 : : }
5454 : :
5455 : 31207 : if (clauses->simdlen_expr)
5456 : : {
5457 : 110 : if (declare_simd)
5458 : : {
5459 : 65 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
5460 : 65 : OMP_CLAUSE_SIMDLEN_EXPR (c)
5461 : 65 : = gfc_conv_constant_to_tree (clauses->simdlen_expr);
5462 : 65 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5463 : : }
5464 : : else
5465 : : {
5466 : 45 : tree simdlen_var;
5467 : :
5468 : 45 : gfc_init_se (&se, NULL);
5469 : 45 : gfc_conv_expr (&se, clauses->simdlen_expr);
5470 : 45 : gfc_add_block_to_block (block, &se.pre);
5471 : 45 : simdlen_var = gfc_evaluate_now (se.expr, block);
5472 : 45 : gfc_add_block_to_block (block, &se.post);
5473 : :
5474 : 45 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMDLEN);
5475 : 45 : OMP_CLAUSE_SIMDLEN_EXPR (c) = simdlen_var;
5476 : 45 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5477 : : }
5478 : : }
5479 : :
5480 : 31207 : if (clauses->num_teams_upper)
5481 : : {
5482 : 111 : tree num_teams_lower = NULL_TREE, num_teams_upper;
5483 : :
5484 : 111 : gfc_init_se (&se, NULL);
5485 : 111 : gfc_conv_expr (&se, clauses->num_teams_upper);
5486 : 111 : gfc_add_block_to_block (block, &se.pre);
5487 : 111 : num_teams_upper = gfc_evaluate_now (se.expr, block);
5488 : 111 : gfc_add_block_to_block (block, &se.post);
5489 : :
5490 : 111 : if (clauses->num_teams_lower)
5491 : : {
5492 : 21 : gfc_init_se (&se, NULL);
5493 : 21 : gfc_conv_expr (&se, clauses->num_teams_lower);
5494 : 21 : gfc_add_block_to_block (block, &se.pre);
5495 : 21 : num_teams_lower = gfc_evaluate_now (se.expr, block);
5496 : 21 : gfc_add_block_to_block (block, &se.post);
5497 : : }
5498 : 111 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TEAMS);
5499 : 111 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = num_teams_lower;
5500 : 111 : OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c) = num_teams_upper;
5501 : 111 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5502 : : }
5503 : :
5504 : 31207 : if (clauses->device)
5505 : : {
5506 : 274 : tree device;
5507 : :
5508 : 274 : gfc_init_se (&se, NULL);
5509 : 274 : gfc_conv_expr (&se, clauses->device);
5510 : 274 : gfc_add_block_to_block (block, &se.pre);
5511 : 274 : device = gfc_evaluate_now (se.expr, block);
5512 : 274 : gfc_add_block_to_block (block, &se.post);
5513 : :
5514 : 274 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEVICE);
5515 : 274 : OMP_CLAUSE_DEVICE_ID (c) = device;
5516 : :
5517 : 274 : if (clauses->ancestor)
5518 : 39 : OMP_CLAUSE_DEVICE_ANCESTOR (c) = 1;
5519 : :
5520 : 274 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5521 : : }
5522 : :
5523 : 31207 : if (clauses->thread_limit)
5524 : : {
5525 : 105 : tree thread_limit;
5526 : :
5527 : 105 : gfc_init_se (&se, NULL);
5528 : 105 : gfc_conv_expr (&se, clauses->thread_limit);
5529 : 105 : gfc_add_block_to_block (block, &se.pre);
5530 : 105 : thread_limit = gfc_evaluate_now (se.expr, block);
5531 : 105 : gfc_add_block_to_block (block, &se.post);
5532 : :
5533 : 105 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREAD_LIMIT);
5534 : 105 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = thread_limit;
5535 : 105 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5536 : : }
5537 : :
5538 : 31207 : chunk_size = NULL_TREE;
5539 : 31207 : if (clauses->dist_chunk_size)
5540 : : {
5541 : 81 : gfc_init_se (&se, NULL);
5542 : 81 : gfc_conv_expr (&se, clauses->dist_chunk_size);
5543 : 81 : gfc_add_block_to_block (block, &se.pre);
5544 : 81 : chunk_size = gfc_evaluate_now (se.expr, block);
5545 : 81 : gfc_add_block_to_block (block, &se.post);
5546 : : }
5547 : :
5548 : 31207 : if (clauses->dist_sched_kind != OMP_SCHED_NONE)
5549 : : {
5550 : 94 : c = build_omp_clause (gfc_get_location (&where),
5551 : : OMP_CLAUSE_DIST_SCHEDULE);
5552 : 94 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = chunk_size;
5553 : 94 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5554 : : }
5555 : :
5556 : 31207 : if (clauses->grainsize)
5557 : : {
5558 : 33 : tree grainsize;
5559 : :
5560 : 33 : gfc_init_se (&se, NULL);
5561 : 33 : gfc_conv_expr (&se, clauses->grainsize);
5562 : 33 : gfc_add_block_to_block (block, &se.pre);
5563 : 33 : grainsize = gfc_evaluate_now (se.expr, block);
5564 : 33 : gfc_add_block_to_block (block, &se.post);
5565 : :
5566 : 33 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GRAINSIZE);
5567 : 33 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = grainsize;
5568 : 33 : if (clauses->grainsize_strict)
5569 : 1 : OMP_CLAUSE_GRAINSIZE_STRICT (c) = 1;
5570 : 33 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5571 : : }
5572 : :
5573 : 31207 : if (clauses->num_tasks)
5574 : : {
5575 : 25 : tree num_tasks;
5576 : :
5577 : 25 : gfc_init_se (&se, NULL);
5578 : 25 : gfc_conv_expr (&se, clauses->num_tasks);
5579 : 25 : gfc_add_block_to_block (block, &se.pre);
5580 : 25 : num_tasks = gfc_evaluate_now (se.expr, block);
5581 : 25 : gfc_add_block_to_block (block, &se.post);
5582 : :
5583 : 25 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_TASKS);
5584 : 25 : OMP_CLAUSE_NUM_TASKS_EXPR (c) = num_tasks;
5585 : 25 : if (clauses->num_tasks_strict)
5586 : 1 : OMP_CLAUSE_NUM_TASKS_STRICT (c) = 1;
5587 : 25 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5588 : : }
5589 : :
5590 : 31207 : if (clauses->priority)
5591 : : {
5592 : 34 : tree priority;
5593 : :
5594 : 34 : gfc_init_se (&se, NULL);
5595 : 34 : gfc_conv_expr (&se, clauses->priority);
5596 : 34 : gfc_add_block_to_block (block, &se.pre);
5597 : 34 : priority = gfc_evaluate_now (se.expr, block);
5598 : 34 : gfc_add_block_to_block (block, &se.post);
5599 : :
5600 : 34 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PRIORITY);
5601 : 34 : OMP_CLAUSE_PRIORITY_EXPR (c) = priority;
5602 : 34 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5603 : : }
5604 : :
5605 : 31207 : if (clauses->detach)
5606 : : {
5607 : 116 : tree detach;
5608 : :
5609 : 116 : gfc_init_se (&se, NULL);
5610 : 116 : gfc_conv_expr (&se, clauses->detach);
5611 : 116 : gfc_add_block_to_block (block, &se.pre);
5612 : 116 : detach = se.expr;
5613 : 116 : gfc_add_block_to_block (block, &se.post);
5614 : :
5615 : 116 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DETACH);
5616 : 116 : TREE_ADDRESSABLE (detach) = 1;
5617 : 116 : OMP_CLAUSE_DECL (c) = detach;
5618 : 116 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5619 : : }
5620 : :
5621 : 31207 : if (clauses->filter)
5622 : : {
5623 : 31 : tree filter;
5624 : :
5625 : 31 : gfc_init_se (&se, NULL);
5626 : 31 : gfc_conv_expr (&se, clauses->filter);
5627 : 31 : gfc_add_block_to_block (block, &se.pre);
5628 : 31 : filter = gfc_evaluate_now (se.expr, block);
5629 : 31 : gfc_add_block_to_block (block, &se.post);
5630 : :
5631 : 31 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FILTER);
5632 : 31 : OMP_CLAUSE_FILTER_EXPR (c) = filter;
5633 : 31 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5634 : : }
5635 : :
5636 : 31207 : if (clauses->hint)
5637 : : {
5638 : 8 : tree hint;
5639 : :
5640 : 8 : gfc_init_se (&se, NULL);
5641 : 8 : gfc_conv_expr (&se, clauses->hint);
5642 : 8 : gfc_add_block_to_block (block, &se.pre);
5643 : 8 : hint = gfc_evaluate_now (se.expr, block);
5644 : 8 : gfc_add_block_to_block (block, &se.post);
5645 : :
5646 : 8 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_HINT);
5647 : 8 : OMP_CLAUSE_HINT_EXPR (c) = hint;
5648 : 8 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5649 : : }
5650 : :
5651 : 31207 : if (clauses->simd)
5652 : : {
5653 : 22 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIMD);
5654 : 22 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5655 : : }
5656 : 31207 : if (clauses->threads)
5657 : : {
5658 : 11 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_THREADS);
5659 : 11 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5660 : : }
5661 : 31207 : if (clauses->nogroup)
5662 : : {
5663 : 13 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NOGROUP);
5664 : 13 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5665 : : }
5666 : :
5667 : 218449 : for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
5668 : : {
5669 : 187242 : if (clauses->defaultmap[i] == OMP_DEFAULTMAP_UNSET)
5670 : 187094 : continue;
5671 : 148 : enum omp_clause_defaultmap_kind behavior, category;
5672 : 148 : switch ((gfc_omp_defaultmap_category) i)
5673 : : {
5674 : : case OMP_DEFAULTMAP_CAT_UNCATEGORIZED:
5675 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
5676 : : break;
5677 : : case OMP_DEFAULTMAP_CAT_ALL:
5678 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALL;
5679 : : break;
5680 : : case OMP_DEFAULTMAP_CAT_SCALAR:
5681 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_SCALAR;
5682 : : break;
5683 : : case OMP_DEFAULTMAP_CAT_AGGREGATE:
5684 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_AGGREGATE;
5685 : : break;
5686 : : case OMP_DEFAULTMAP_CAT_ALLOCATABLE:
5687 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_ALLOCATABLE;
5688 : : break;
5689 : : case OMP_DEFAULTMAP_CAT_POINTER:
5690 : : category = OMP_CLAUSE_DEFAULTMAP_CATEGORY_POINTER;
5691 : : break;
5692 : : default: gcc_unreachable ();
5693 : : }
5694 : 148 : switch (clauses->defaultmap[i])
5695 : : {
5696 : : case OMP_DEFAULTMAP_ALLOC:
5697 : : behavior = OMP_CLAUSE_DEFAULTMAP_ALLOC;
5698 : : break;
5699 : : case OMP_DEFAULTMAP_TO: behavior = OMP_CLAUSE_DEFAULTMAP_TO; break;
5700 : : case OMP_DEFAULTMAP_FROM: behavior = OMP_CLAUSE_DEFAULTMAP_FROM; break;
5701 : : case OMP_DEFAULTMAP_TOFROM:
5702 : : behavior = OMP_CLAUSE_DEFAULTMAP_TOFROM;
5703 : : break;
5704 : : case OMP_DEFAULTMAP_FIRSTPRIVATE:
5705 : : behavior = OMP_CLAUSE_DEFAULTMAP_FIRSTPRIVATE;
5706 : : break;
5707 : : case OMP_DEFAULTMAP_PRESENT:
5708 : : behavior = OMP_CLAUSE_DEFAULTMAP_PRESENT;
5709 : : break;
5710 : : case OMP_DEFAULTMAP_NONE: behavior = OMP_CLAUSE_DEFAULTMAP_NONE; break;
5711 : : case OMP_DEFAULTMAP_DEFAULT:
5712 : : behavior = OMP_CLAUSE_DEFAULTMAP_DEFAULT;
5713 : : break;
5714 : 0 : default: gcc_unreachable ();
5715 : : }
5716 : 148 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DEFAULTMAP);
5717 : 148 : OMP_CLAUSE_DEFAULTMAP_SET_KIND (c, behavior, category);
5718 : 148 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5719 : : }
5720 : :
5721 : 31207 : if (clauses->doacross_source)
5722 : : {
5723 : 131 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_DOACROSS);
5724 : 131 : OMP_CLAUSE_DOACROSS_KIND (c) = OMP_CLAUSE_DOACROSS_SOURCE;
5725 : 131 : OMP_CLAUSE_DOACROSS_DEPEND (c) = clauses->depend_source;
5726 : 131 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5727 : : }
5728 : :
5729 : 31207 : if (clauses->async)
5730 : : {
5731 : 540 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ASYNC);
5732 : 540 : if (clauses->async_expr)
5733 : 540 : OMP_CLAUSE_ASYNC_EXPR (c)
5734 : 1080 : = gfc_convert_expr_to_tree (block, clauses->async_expr);
5735 : : else
5736 : 0 : OMP_CLAUSE_ASYNC_EXPR (c) = NULL;
5737 : 540 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5738 : : }
5739 : 31207 : if (clauses->seq)
5740 : : {
5741 : 140 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SEQ);
5742 : 140 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5743 : : }
5744 : 31207 : if (clauses->par_auto)
5745 : : {
5746 : 62 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_AUTO);
5747 : 62 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5748 : : }
5749 : 31207 : if (clauses->if_present)
5750 : : {
5751 : 23 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF_PRESENT);
5752 : 23 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5753 : : }
5754 : 31207 : if (clauses->finalize)
5755 : : {
5756 : 15 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FINALIZE);
5757 : 15 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5758 : : }
5759 : 31207 : if (clauses->independent)
5760 : : {
5761 : 239 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_INDEPENDENT);
5762 : 239 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5763 : : }
5764 : 31207 : if (clauses->wait_list)
5765 : : {
5766 : : gfc_expr_list *el;
5767 : :
5768 : 317 : for (el = clauses->wait_list; el; el = el->next)
5769 : : {
5770 : 172 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WAIT);
5771 : 172 : OMP_CLAUSE_DECL (c) = gfc_convert_expr_to_tree (block, el->expr);
5772 : 172 : OMP_CLAUSE_CHAIN (c) = omp_clauses;
5773 : 172 : omp_clauses = c;
5774 : : }
5775 : : }
5776 : 31207 : if (clauses->num_gangs_expr)
5777 : : {
5778 : 666 : tree num_gangs_var
5779 : 666 : = gfc_convert_expr_to_tree (block, clauses->num_gangs_expr);
5780 : 666 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_GANGS);
5781 : 666 : OMP_CLAUSE_NUM_GANGS_EXPR (c) = num_gangs_var;
5782 : 666 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5783 : : }
5784 : 31207 : if (clauses->num_workers_expr)
5785 : : {
5786 : 583 : tree num_workers_var
5787 : 583 : = gfc_convert_expr_to_tree (block, clauses->num_workers_expr);
5788 : 583 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_NUM_WORKERS);
5789 : 583 : OMP_CLAUSE_NUM_WORKERS_EXPR (c) = num_workers_var;
5790 : 583 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5791 : : }
5792 : 31207 : if (clauses->vector_length_expr)
5793 : : {
5794 : 553 : tree vector_length_var
5795 : 553 : = gfc_convert_expr_to_tree (block, clauses->vector_length_expr);
5796 : 553 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR_LENGTH);
5797 : 553 : OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = vector_length_var;
5798 : 553 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5799 : : }
5800 : 31207 : if (clauses->tile_list)
5801 : : {
5802 : : tree list = NULL_TREE;
5803 : 174 : for (gfc_expr_list *el = clauses->tile_list; el; el = el->next)
5804 : 114 : list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
5805 : : list);
5806 : :
5807 : 60 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TILE);
5808 : 60 : OMP_CLAUSE_TILE_LIST (c) = nreverse (list);
5809 : 60 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5810 : : }
5811 : 31207 : if (clauses->vector)
5812 : : {
5813 : 835 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_VECTOR);
5814 : 835 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5815 : :
5816 : 835 : if (clauses->vector_expr)
5817 : : {
5818 : 119 : tree vector_var
5819 : 119 : = gfc_convert_expr_to_tree (block, clauses->vector_expr);
5820 : 119 : OMP_CLAUSE_VECTOR_EXPR (c) = vector_var;
5821 : :
5822 : : /* TODO: We're not capturing location information for individual
5823 : : clauses. However, if we have an expression attached to the
5824 : : clause, that one provides better location information. */
5825 : 238 : OMP_CLAUSE_LOCATION (c)
5826 : 119 : = gfc_get_location (&clauses->vector_expr->where);
5827 : : }
5828 : : }
5829 : 31207 : if (clauses->worker)
5830 : : {
5831 : 730 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_WORKER);
5832 : 730 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5833 : :
5834 : 730 : if (clauses->worker_expr)
5835 : : {
5836 : 89 : tree worker_var
5837 : 89 : = gfc_convert_expr_to_tree (block, clauses->worker_expr);
5838 : 89 : OMP_CLAUSE_WORKER_EXPR (c) = worker_var;
5839 : :
5840 : : /* TODO: We're not capturing location information for individual
5841 : : clauses. However, if we have an expression attached to the
5842 : : clause, that one provides better location information. */
5843 : 178 : OMP_CLAUSE_LOCATION (c)
5844 : 89 : = gfc_get_location (&clauses->worker_expr->where);
5845 : : }
5846 : : }
5847 : 31207 : if (clauses->gang)
5848 : : {
5849 : 1010 : tree arg;
5850 : 1010 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_GANG);
5851 : 1010 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5852 : :
5853 : 1010 : if (clauses->gang_num_expr)
5854 : : {
5855 : 101 : arg = gfc_convert_expr_to_tree (block, clauses->gang_num_expr);
5856 : 101 : OMP_CLAUSE_GANG_EXPR (c) = arg;
5857 : :
5858 : : /* TODO: We're not capturing location information for individual
5859 : : clauses. However, if we have an expression attached to the
5860 : : clause, that one provides better location information. */
5861 : 202 : OMP_CLAUSE_LOCATION (c)
5862 : 101 : = gfc_get_location (&clauses->gang_num_expr->where);
5863 : : }
5864 : :
5865 : 1010 : if (clauses->gang_static)
5866 : : {
5867 : 208 : arg = clauses->gang_static_expr
5868 : 104 : ? gfc_convert_expr_to_tree (block, clauses->gang_static_expr)
5869 : : : integer_minus_one_node;
5870 : 104 : OMP_CLAUSE_GANG_STATIC_EXPR (c) = arg;
5871 : : }
5872 : : }
5873 : 31207 : if (clauses->bind != OMP_BIND_UNSET)
5874 : : {
5875 : 30 : c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_BIND);
5876 : 30 : omp_clauses = gfc_trans_add_clause (c, omp_clauses);
5877 : 30 : switch (clauses->bind)
5878 : : {
5879 : 10 : case OMP_BIND_TEAMS:
5880 : 10 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_TEAMS;
5881 : 10 : break;
5882 : 15 : case OMP_BIND_PARALLEL:
5883 : 15 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_PARALLEL;
5884 : 15 : break;
5885 : 5 : case OMP_BIND_THREAD:
5886 : 5 : OMP_CLAUSE_BIND_KIND (c) = OMP_CLAUSE_BIND_THREAD;
5887 : 5 : break;
5888 : 0 : default:
5889 : 0 : gcc_unreachable ();
5890 : : }
5891 : : }
5892 : : /* OpenACC 'nohost' clauses cannot appear here. */
5893 : 31207 : gcc_checking_assert (!clauses->nohost);
5894 : :
5895 : 31207 : return nreverse (omp_clauses);
5896 : : }
5897 : :
5898 : : /* Like gfc_trans_code, but force creation of a BIND_EXPR around it. */
5899 : :
5900 : : static tree
5901 : 20834 : gfc_trans_omp_code (gfc_code *code, bool force_empty)
5902 : : {
5903 : 20834 : tree stmt;
5904 : :
5905 : 20834 : pushlevel ();
5906 : 20834 : stmt = gfc_trans_code (code);
5907 : 20834 : if (TREE_CODE (stmt) != BIND_EXPR)
5908 : : {
5909 : 18588 : if (!IS_EMPTY_STMT (stmt) || force_empty)
5910 : : {
5911 : 18498 : tree block = poplevel (1, 0);
5912 : 18498 : stmt = build3_v (BIND_EXPR, NULL, stmt, block);
5913 : : }
5914 : : else
5915 : 90 : poplevel (0, 0);
5916 : : }
5917 : : else
5918 : 2246 : poplevel (0, 0);
5919 : 20834 : return stmt;
5920 : : }
5921 : :
5922 : : /* Translate OpenACC 'parallel', 'kernels', 'serial', 'data', 'host_data'
5923 : : construct. */
5924 : :
5925 : : static tree
5926 : 4164 : gfc_trans_oacc_construct (gfc_code *code)
5927 : : {
5928 : 4164 : stmtblock_t block;
5929 : 4164 : tree stmt, oacc_clauses;
5930 : 4164 : enum tree_code construct_code;
5931 : :
5932 : 4164 : switch (code->op)
5933 : : {
5934 : : case EXEC_OACC_PARALLEL:
5935 : : construct_code = OACC_PARALLEL;
5936 : : break;
5937 : : case EXEC_OACC_KERNELS:
5938 : : construct_code = OACC_KERNELS;
5939 : : break;
5940 : : case EXEC_OACC_SERIAL:
5941 : : construct_code = OACC_SERIAL;
5942 : : break;
5943 : : case EXEC_OACC_DATA:
5944 : : construct_code = OACC_DATA;
5945 : : break;
5946 : : case EXEC_OACC_HOST_DATA:
5947 : : construct_code = OACC_HOST_DATA;
5948 : : break;
5949 : 0 : default:
5950 : 0 : gcc_unreachable ();
5951 : : }
5952 : :
5953 : 4164 : gfc_start_block (&block);
5954 : 4164 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
5955 : : code->loc, false, true);
5956 : 4164 : pushlevel ();
5957 : 4164 : stmt = gfc_trans_omp_code (code->block->next, true);
5958 : 4164 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
5959 : 4164 : stmt = build2_loc (gfc_get_location (&code->loc), construct_code,
5960 : : void_type_node, stmt, oacc_clauses);
5961 : 4164 : gfc_add_expr_to_block (&block, stmt);
5962 : 4164 : return gfc_finish_block (&block);
5963 : : }
5964 : :
5965 : : /* update, enter_data, exit_data, cache. */
5966 : : static tree
5967 : 2075 : gfc_trans_oacc_executable_directive (gfc_code *code)
5968 : : {
5969 : 2075 : stmtblock_t block;
5970 : 2075 : tree stmt, oacc_clauses;
5971 : 2075 : enum tree_code construct_code;
5972 : :
5973 : 2075 : switch (code->op)
5974 : : {
5975 : : case EXEC_OACC_UPDATE:
5976 : : construct_code = OACC_UPDATE;
5977 : : break;
5978 : 767 : case EXEC_OACC_ENTER_DATA:
5979 : 767 : construct_code = OACC_ENTER_DATA;
5980 : 767 : break;
5981 : 545 : case EXEC_OACC_EXIT_DATA:
5982 : 545 : construct_code = OACC_EXIT_DATA;
5983 : 545 : break;
5984 : 74 : case EXEC_OACC_CACHE:
5985 : 74 : construct_code = OACC_CACHE;
5986 : 74 : break;
5987 : 0 : default:
5988 : 0 : gcc_unreachable ();
5989 : : }
5990 : :
5991 : 2075 : gfc_start_block (&block);
5992 : 2075 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
5993 : : code->loc, false, true, code->op);
5994 : 2075 : stmt = build1_loc (input_location, construct_code, void_type_node,
5995 : : oacc_clauses);
5996 : 2075 : gfc_add_expr_to_block (&block, stmt);
5997 : 2075 : return gfc_finish_block (&block);
5998 : : }
5999 : :
6000 : : static tree
6001 : 167 : gfc_trans_oacc_wait_directive (gfc_code *code)
6002 : : {
6003 : 167 : stmtblock_t block;
6004 : 167 : tree stmt, t;
6005 : 167 : vec<tree, va_gc> *args;
6006 : 167 : int nparms = 0;
6007 : 167 : gfc_expr_list *el;
6008 : 167 : gfc_omp_clauses *clauses = code->ext.omp_clauses;
6009 : 167 : location_t loc = input_location;
6010 : :
6011 : 291 : for (el = clauses->wait_list; el; el = el->next)
6012 : 124 : nparms++;
6013 : :
6014 : 167 : vec_alloc (args, nparms + 2);
6015 : 167 : stmt = builtin_decl_explicit (BUILT_IN_GOACC_WAIT);
6016 : :
6017 : 167 : gfc_start_block (&block);
6018 : :
6019 : 167 : if (clauses->async_expr)
6020 : 0 : t = gfc_convert_expr_to_tree (&block, clauses->async_expr);
6021 : : else
6022 : 167 : t = build_int_cst (integer_type_node, -2);
6023 : :
6024 : 167 : args->quick_push (t);
6025 : 167 : args->quick_push (build_int_cst (integer_type_node, nparms));
6026 : :
6027 : 291 : for (el = clauses->wait_list; el; el = el->next)
6028 : 124 : args->quick_push (gfc_convert_expr_to_tree (&block, el->expr));
6029 : :
6030 : 167 : stmt = build_call_expr_loc_vec (loc, stmt, args);
6031 : 167 : gfc_add_expr_to_block (&block, stmt);
6032 : :
6033 : 167 : vec_free (args);
6034 : :
6035 : 167 : return gfc_finish_block (&block);
6036 : : }
6037 : :
6038 : : static tree gfc_trans_omp_sections (gfc_code *, gfc_omp_clauses *);
6039 : : static tree gfc_trans_omp_workshare (gfc_code *, gfc_omp_clauses *);
6040 : :
6041 : : static tree
6042 : 31 : gfc_trans_omp_allocators (gfc_code *code)
6043 : : {
6044 : 31 : static bool warned = false;
6045 : 31 : gfc_omp_namelist *omp_allocate
6046 : 31 : = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
6047 : 31 : if (!flag_openmp_allocators && !warned)
6048 : : {
6049 : 2 : omp_allocate = NULL;
6050 : 2 : gfc_error ("%<!$OMP %s%> at %L requires %<-fopenmp-allocators%>",
6051 : 2 : code->op == EXEC_OMP_ALLOCATE ? "ALLOCATE" : "ALLOCATORS",
6052 : : &code->loc);
6053 : 2 : warning (0, "All files that might deallocate such a variable must be "
6054 : : "compiled with %<-fopenmp-allocators%>");
6055 : 2 : inform (UNKNOWN_LOCATION,
6056 : : "This includes explicit DEALLOCATE, reallocation on intrinsic "
6057 : : "assignment, INTENT(OUT) for allocatable dummy arguments, and "
6058 : : "reallocation of allocatable components allocated with an "
6059 : : "OpenMP allocator");
6060 : 2 : warned = true;
6061 : : }
6062 : 31 : return gfc_trans_allocate (code->block->next, omp_allocate);
6063 : : }
6064 : :
6065 : : static tree
6066 : 10 : gfc_trans_omp_assume (gfc_code *code)
6067 : : {
6068 : 10 : stmtblock_t block;
6069 : 10 : gfc_init_block (&block);
6070 : 10 : gfc_omp_assumptions *assume = code->ext.omp_clauses->assume;
6071 : 10 : if (assume)
6072 : 19 : for (gfc_expr_list *el = assume->holds; el; el = el->next)
6073 : : {
6074 : 9 : location_t loc = gfc_get_location (&el->expr->where);
6075 : 9 : gfc_se se;
6076 : 9 : gfc_init_se (&se, NULL);
6077 : 9 : gfc_conv_expr (&se, el->expr);
6078 : 9 : tree t;
6079 : 9 : if (se.pre.head == NULL_TREE && se.post.head == NULL_TREE)
6080 : 8 : t = se.expr;
6081 : : else
6082 : : {
6083 : 1 : tree var = create_tmp_var_raw (boolean_type_node);
6084 : 1 : DECL_CONTEXT (var) = current_function_decl;
6085 : 1 : stmtblock_t block2;
6086 : 1 : gfc_init_block (&block2);
6087 : 1 : gfc_add_block_to_block (&block2, &se.pre);
6088 : 1 : gfc_add_modify_loc (loc, &block2, var,
6089 : : fold_convert_loc (loc, boolean_type_node,
6090 : : se.expr));
6091 : 1 : gfc_add_block_to_block (&block2, &se.post);
6092 : 1 : t = gfc_finish_block (&block2);
6093 : 1 : t = build4 (TARGET_EXPR, boolean_type_node, var, t, NULL, NULL);
6094 : : }
6095 : 9 : t = build_call_expr_internal_loc (loc, IFN_ASSUME,
6096 : : void_type_node, 1, t);
6097 : 9 : gfc_add_expr_to_block (&block, t);
6098 : : }
6099 : 10 : gfc_add_expr_to_block (&block, gfc_trans_omp_code (code->block->next, true));
6100 : 10 : return gfc_finish_block (&block);
6101 : : }
6102 : :
6103 : : static tree
6104 : 2596 : gfc_trans_omp_atomic (gfc_code *code)
6105 : : {
6106 : 2596 : gfc_code *atomic_code = code->block;
6107 : 2596 : gfc_se lse;
6108 : 2596 : gfc_se rse;
6109 : 2596 : gfc_se vse;
6110 : 2596 : gfc_expr *expr1, *expr2, *e, *capture_expr1 = NULL, *capture_expr2 = NULL;
6111 : 2596 : gfc_symbol *var;
6112 : 2596 : stmtblock_t block;
6113 : 2596 : tree lhsaddr, type, rhs, x, compare = NULL_TREE, comp_tgt = NULL_TREE;
6114 : 2596 : enum tree_code op = ERROR_MARK;
6115 : 2596 : enum tree_code aop = OMP_ATOMIC;
6116 : 2596 : bool var_on_left = false, else_branch = false;
6117 : 2596 : enum omp_memory_order mo, fail_mo;
6118 : 2596 : switch (atomic_code->ext.omp_clauses->memorder)
6119 : : {
6120 : : case OMP_MEMORDER_UNSET: mo = OMP_MEMORY_ORDER_UNSPECIFIED; break;
6121 : : case OMP_MEMORDER_ACQ_REL: mo = OMP_MEMORY_ORDER_ACQ_REL; break;
6122 : : case OMP_MEMORDER_ACQUIRE: mo = OMP_MEMORY_ORDER_ACQUIRE; break;
6123 : : case OMP_MEMORDER_RELAXED: mo = OMP_MEMORY_ORDER_RELAXED; break;
6124 : : case OMP_MEMORDER_RELEASE: mo = OMP_MEMORY_ORDER_RELEASE; break;
6125 : : case OMP_MEMORDER_SEQ_CST: mo = OMP_MEMORY_ORDER_SEQ_CST; break;
6126 : 0 : default: gcc_unreachable ();
6127 : : }
6128 : 2596 : switch (atomic_code->ext.omp_clauses->fail)
6129 : : {
6130 : : case OMP_MEMORDER_UNSET: fail_mo = OMP_FAIL_MEMORY_ORDER_UNSPECIFIED; break;
6131 : 14 : case OMP_MEMORDER_ACQUIRE: fail_mo = OMP_FAIL_MEMORY_ORDER_ACQUIRE; break;
6132 : 26 : case OMP_MEMORDER_RELAXED: fail_mo = OMP_FAIL_MEMORY_ORDER_RELAXED; break;
6133 : 2 : case OMP_MEMORDER_SEQ_CST: fail_mo = OMP_FAIL_MEMORY_ORDER_SEQ_CST; break;
6134 : 0 : default: gcc_unreachable ();
6135 : : }
6136 : 2596 : mo = (omp_memory_order) (mo | fail_mo);
6137 : :
6138 : 2596 : code = code->block->next;
6139 : 2596 : if (atomic_code->ext.omp_clauses->compare)
6140 : : {
6141 : 144 : gfc_expr *comp_expr;
6142 : 144 : if (code->op == EXEC_IF)
6143 : : {
6144 : 125 : comp_expr = code->block->expr1;
6145 : 125 : gcc_assert (code->block->next->op == EXEC_ASSIGN);
6146 : 125 : expr1 = code->block->next->expr1;
6147 : 125 : expr2 = code->block->next->expr2;
6148 : 125 : if (code->block->block)
6149 : : {
6150 : 64 : gcc_assert (atomic_code->ext.omp_clauses->capture
6151 : : && code->block->block->next->op == EXEC_ASSIGN);
6152 : 64 : else_branch = true;
6153 : 64 : aop = OMP_ATOMIC_CAPTURE_OLD;
6154 : 64 : capture_expr1 = code->block->block->next->expr1;
6155 : 64 : capture_expr2 = code->block->block->next->expr2;
6156 : : }
6157 : 61 : else if (atomic_code->ext.omp_clauses->capture)
6158 : : {
6159 : 19 : gcc_assert (code->next->op == EXEC_ASSIGN);
6160 : 19 : aop = OMP_ATOMIC_CAPTURE_NEW;
6161 : 19 : capture_expr1 = code->next->expr1;
6162 : 19 : capture_expr2 = code->next->expr2;
6163 : : }
6164 : : }
6165 : : else
6166 : : {
6167 : 19 : gcc_assert (atomic_code->ext.omp_clauses->capture
6168 : : && code->op == EXEC_ASSIGN
6169 : : && code->next->op == EXEC_IF);
6170 : 19 : aop = OMP_ATOMIC_CAPTURE_OLD;
6171 : 19 : capture_expr1 = code->expr1;
6172 : 19 : capture_expr2 = code->expr2;
6173 : 19 : expr1 = code->next->block->next->expr1;
6174 : 19 : expr2 = code->next->block->next->expr2;
6175 : 19 : comp_expr = code->next->block->expr1;
6176 : : }
6177 : 144 : gfc_init_se (&lse, NULL);
6178 : 144 : gfc_conv_expr (&lse, comp_expr->value.op.op2);
6179 : 144 : gfc_add_block_to_block (&block, &lse.pre);
6180 : 144 : compare = lse.expr;
6181 : 144 : var = expr1->symtree->n.sym;
6182 : : }
6183 : : else
6184 : : {
6185 : 2452 : gcc_assert (code->op == EXEC_ASSIGN);
6186 : 2452 : expr1 = code->expr1;
6187 : 2452 : expr2 = code->expr2;
6188 : 2452 : if (atomic_code->ext.omp_clauses->capture
6189 : 463 : && (expr2->expr_type == EXPR_VARIABLE
6190 : 245 : || (expr2->expr_type == EXPR_FUNCTION
6191 : 113 : && expr2->value.function.isym
6192 : 113 : && expr2->value.function.isym->id == GFC_ISYM_CONVERSION
6193 : 41 : && (expr2->value.function.actual->expr->expr_type
6194 : : == EXPR_VARIABLE))))
6195 : : {
6196 : 235 : capture_expr1 = expr1;
6197 : 235 : capture_expr2 = expr2;
6198 : 235 : expr1 = code->next->expr1;
6199 : 235 : expr2 = code->next->expr2;
6200 : 235 : aop = OMP_ATOMIC_CAPTURE_OLD;
6201 : : }
6202 : 2217 : else if (atomic_code->ext.omp_clauses->capture)
6203 : : {
6204 : 228 : aop = OMP_ATOMIC_CAPTURE_NEW;
6205 : 228 : capture_expr1 = code->next->expr1;
6206 : 228 : capture_expr2 = code->next->expr2;
6207 : : }
6208 : 2452 : var = expr1->symtree->n.sym;
6209 : : }
6210 : :
6211 : 2596 : gfc_init_se (&lse, NULL);
6212 : 2596 : gfc_init_se (&rse, NULL);
6213 : 2596 : gfc_init_se (&vse, NULL);
6214 : 2596 : gfc_start_block (&block);
6215 : :
6216 : 2596 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6217 : : != GFC_OMP_ATOMIC_WRITE)
6218 : 2190 : && expr2->expr_type == EXPR_FUNCTION
6219 : 472 : && expr2->value.function.isym
6220 : 472 : && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
6221 : 139 : expr2 = expr2->value.function.actual->expr;
6222 : :
6223 : 2596 : if ((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6224 : : == GFC_OMP_ATOMIC_READ)
6225 : : {
6226 : 494 : gfc_conv_expr (&vse, expr1);
6227 : 494 : gfc_add_block_to_block (&block, &vse.pre);
6228 : :
6229 : 494 : gfc_conv_expr (&lse, expr2);
6230 : 494 : gfc_add_block_to_block (&block, &lse.pre);
6231 : 494 : type = TREE_TYPE (lse.expr);
6232 : 494 : lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
6233 : :
6234 : 494 : x = build1 (OMP_ATOMIC_READ, type, lhsaddr);
6235 : 494 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6236 : 494 : x = convert (TREE_TYPE (vse.expr), x);
6237 : 494 : gfc_add_modify (&block, vse.expr, x);
6238 : :
6239 : 494 : gfc_add_block_to_block (&block, &lse.pre);
6240 : 494 : gfc_add_block_to_block (&block, &rse.pre);
6241 : :
6242 : 494 : return gfc_finish_block (&block);
6243 : : }
6244 : :
6245 : 2102 : if (capture_expr2
6246 : 565 : && capture_expr2->expr_type == EXPR_FUNCTION
6247 : 21 : && capture_expr2->value.function.isym
6248 : 21 : && capture_expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
6249 : 21 : capture_expr2 = capture_expr2->value.function.actual->expr;
6250 : 565 : gcc_assert (!capture_expr2 || capture_expr2->expr_type == EXPR_VARIABLE);
6251 : :
6252 : 2102 : if (aop == OMP_ATOMIC_CAPTURE_OLD)
6253 : : {
6254 : 318 : gfc_conv_expr (&vse, capture_expr1);
6255 : 318 : gfc_add_block_to_block (&block, &vse.pre);
6256 : 318 : gfc_conv_expr (&lse, capture_expr2);
6257 : 318 : gfc_add_block_to_block (&block, &lse.pre);
6258 : 318 : gfc_init_se (&lse, NULL);
6259 : : }
6260 : :
6261 : 2102 : gfc_conv_expr (&lse, expr1);
6262 : 2102 : gfc_add_block_to_block (&block, &lse.pre);
6263 : 2102 : type = TREE_TYPE (lse.expr);
6264 : 2102 : lhsaddr = gfc_build_addr_expr (NULL, lse.expr);
6265 : :
6266 : 2102 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6267 : : == GFC_OMP_ATOMIC_WRITE)
6268 : 1696 : || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
6269 : 1674 : || compare)
6270 : : {
6271 : 572 : gfc_conv_expr (&rse, expr2);
6272 : 572 : gfc_add_block_to_block (&block, &rse.pre);
6273 : : }
6274 : 1530 : else if (expr2->expr_type == EXPR_OP)
6275 : : {
6276 : 1184 : gfc_expr *e;
6277 : 1184 : switch (expr2->value.op.op)
6278 : : {
6279 : : case INTRINSIC_PLUS:
6280 : : op = PLUS_EXPR;
6281 : : break;
6282 : 91 : case INTRINSIC_TIMES:
6283 : 91 : op = MULT_EXPR;
6284 : 91 : break;
6285 : 113 : case INTRINSIC_MINUS:
6286 : 113 : op = MINUS_EXPR;
6287 : 113 : break;
6288 : 91 : case INTRINSIC_DIVIDE:
6289 : 91 : if (expr2->ts.type == BT_INTEGER)
6290 : : op = TRUNC_DIV_EXPR;
6291 : : else
6292 : 74 : op = RDIV_EXPR;
6293 : : break;
6294 : 43 : case INTRINSIC_AND:
6295 : 43 : op = TRUTH_ANDIF_EXPR;
6296 : 43 : break;
6297 : 49 : case INTRINSIC_OR:
6298 : 49 : op = TRUTH_ORIF_EXPR;
6299 : 49 : break;
6300 : 43 : case INTRINSIC_EQV:
6301 : 43 : op = EQ_EXPR;
6302 : 43 : break;
6303 : 43 : case INTRINSIC_NEQV:
6304 : 43 : op = NE_EXPR;
6305 : 43 : break;
6306 : 0 : default:
6307 : 0 : gcc_unreachable ();
6308 : : }
6309 : 1184 : e = expr2->value.op.op1;
6310 : 1184 : if (e->expr_type == EXPR_FUNCTION
6311 : 48 : && e->value.function.isym
6312 : 48 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6313 : 48 : e = e->value.function.actual->expr;
6314 : 1184 : if (e->expr_type == EXPR_VARIABLE
6315 : 925 : && e->symtree != NULL
6316 : 925 : && e->symtree->n.sym == var)
6317 : : {
6318 : 910 : expr2 = expr2->value.op.op2;
6319 : 910 : var_on_left = true;
6320 : : }
6321 : : else
6322 : : {
6323 : 274 : e = expr2->value.op.op2;
6324 : 274 : if (e->expr_type == EXPR_FUNCTION
6325 : 48 : && e->value.function.isym
6326 : 48 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6327 : 48 : e = e->value.function.actual->expr;
6328 : 274 : gcc_assert (e->expr_type == EXPR_VARIABLE
6329 : : && e->symtree != NULL
6330 : : && e->symtree->n.sym == var);
6331 : : expr2 = expr2->value.op.op1;
6332 : : var_on_left = false;
6333 : : }
6334 : 1184 : gfc_conv_expr (&rse, expr2);
6335 : 1184 : gfc_add_block_to_block (&block, &rse.pre);
6336 : : }
6337 : : else
6338 : : {
6339 : 346 : gcc_assert (expr2->expr_type == EXPR_FUNCTION);
6340 : 346 : switch (expr2->value.function.isym->id)
6341 : : {
6342 : : case GFC_ISYM_MIN:
6343 : : op = MIN_EXPR;
6344 : : break;
6345 : 114 : case GFC_ISYM_MAX:
6346 : 114 : op = MAX_EXPR;
6347 : 114 : break;
6348 : 47 : case GFC_ISYM_IAND:
6349 : 47 : op = BIT_AND_EXPR;
6350 : 47 : break;
6351 : 49 : case GFC_ISYM_IOR:
6352 : 49 : op = BIT_IOR_EXPR;
6353 : 49 : break;
6354 : 45 : case GFC_ISYM_IEOR:
6355 : 45 : op = BIT_XOR_EXPR;
6356 : 45 : break;
6357 : 0 : default:
6358 : 0 : gcc_unreachable ();
6359 : : }
6360 : 346 : e = expr2->value.function.actual->expr;
6361 : 346 : if (e->expr_type == EXPR_FUNCTION
6362 : 13 : && e->value.function.isym
6363 : 13 : && e->value.function.isym->id == GFC_ISYM_CONVERSION)
6364 : 13 : e = e->value.function.actual->expr;
6365 : 346 : gcc_assert (e->expr_type == EXPR_VARIABLE
6366 : : && e->symtree != NULL
6367 : : && e->symtree->n.sym == var);
6368 : :
6369 : 346 : gfc_conv_expr (&rse, expr2->value.function.actual->next->expr);
6370 : 346 : gfc_add_block_to_block (&block, &rse.pre);
6371 : 346 : if (expr2->value.function.actual->next->next != NULL)
6372 : : {
6373 : 26 : tree accum = gfc_create_var (TREE_TYPE (rse.expr), NULL);
6374 : 26 : gfc_actual_arglist *arg;
6375 : :
6376 : 26 : gfc_add_modify (&block, accum, rse.expr);
6377 : 64 : for (arg = expr2->value.function.actual->next->next; arg;
6378 : 38 : arg = arg->next)
6379 : : {
6380 : 38 : gfc_init_block (&rse.pre);
6381 : 38 : gfc_conv_expr (&rse, arg->expr);
6382 : 38 : gfc_add_block_to_block (&block, &rse.pre);
6383 : 38 : x = fold_build2_loc (input_location, op, TREE_TYPE (accum),
6384 : : accum, rse.expr);
6385 : 38 : gfc_add_modify (&block, accum, x);
6386 : : }
6387 : :
6388 : 26 : rse.expr = accum;
6389 : : }
6390 : :
6391 : 346 : expr2 = expr2->value.function.actual->next->expr;
6392 : : }
6393 : :
6394 : 2102 : lhsaddr = save_expr (lhsaddr);
6395 : 2102 : if (TREE_CODE (lhsaddr) != SAVE_EXPR
6396 : 2102 : && (TREE_CODE (lhsaddr) != ADDR_EXPR
6397 : 1642 : || !VAR_P (TREE_OPERAND (lhsaddr, 0))))
6398 : : {
6399 : : /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
6400 : : it even after unsharing function body. */
6401 : 44 : tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
6402 : 44 : DECL_CONTEXT (var) = current_function_decl;
6403 : 44 : lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr,
6404 : : NULL_TREE, NULL_TREE);
6405 : : }
6406 : :
6407 : 2102 : if (compare)
6408 : : {
6409 : 144 : tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr));
6410 : 144 : DECL_CONTEXT (var) = current_function_decl;
6411 : 144 : lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr, NULL,
6412 : : NULL);
6413 : 144 : lse.expr = build_fold_indirect_ref_loc (input_location, lhsaddr);
6414 : 144 : compare = convert (TREE_TYPE (lse.expr), compare);
6415 : 144 : compare = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
6416 : : lse.expr, compare);
6417 : : }
6418 : :
6419 : 2102 : if (expr2->expr_type == EXPR_VARIABLE || compare)
6420 : 460 : rhs = rse.expr;
6421 : : else
6422 : 1642 : rhs = gfc_evaluate_now (rse.expr, &block);
6423 : :
6424 : 2102 : if (((atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_MASK)
6425 : : == GFC_OMP_ATOMIC_WRITE)
6426 : 1696 : || (atomic_code->ext.omp_clauses->atomic_op & GFC_OMP_ATOMIC_SWAP)
6427 : 1674 : || compare)
6428 : : x = rhs;
6429 : : else
6430 : : {
6431 : 1530 : x = convert (TREE_TYPE (rhs),
6432 : : build_fold_indirect_ref_loc (input_location, lhsaddr));
6433 : 1530 : if (var_on_left)
6434 : 910 : x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), x, rhs);
6435 : : else
6436 : 620 : x = fold_build2_loc (input_location, op, TREE_TYPE (rhs), rhs, x);
6437 : : }
6438 : :
6439 : 2102 : if (TREE_CODE (TREE_TYPE (rhs)) == COMPLEX_TYPE
6440 : 2102 : && TREE_CODE (type) != COMPLEX_TYPE)
6441 : 0 : x = fold_build1_loc (input_location, REALPART_EXPR,
6442 : 0 : TREE_TYPE (TREE_TYPE (rhs)), x);
6443 : :
6444 : 2102 : gfc_add_block_to_block (&block, &lse.pre);
6445 : 2102 : gfc_add_block_to_block (&block, &rse.pre);
6446 : :
6447 : 2102 : if (aop == OMP_ATOMIC_CAPTURE_NEW)
6448 : : {
6449 : 247 : gfc_conv_expr (&vse, capture_expr1);
6450 : 247 : gfc_add_block_to_block (&block, &vse.pre);
6451 : 247 : gfc_add_block_to_block (&block, &lse.pre);
6452 : : }
6453 : :
6454 : 2102 : if (compare && else_branch)
6455 : : {
6456 : 64 : tree var2 = create_tmp_var_raw (boolean_type_node);
6457 : 64 : DECL_CONTEXT (var2) = current_function_decl;
6458 : 64 : comp_tgt = build4 (TARGET_EXPR, boolean_type_node, var2,
6459 : : boolean_false_node, NULL, NULL);
6460 : 64 : compare = fold_build2_loc (input_location, MODIFY_EXPR, TREE_TYPE (var2),
6461 : : var2, compare);
6462 : 64 : TREE_OPERAND (compare, 0) = comp_tgt;
6463 : 64 : compare = omit_one_operand_loc (input_location, boolean_type_node,
6464 : : compare, comp_tgt);
6465 : : }
6466 : :
6467 : 2102 : if (compare)
6468 : 144 : x = build3_loc (input_location, COND_EXPR, type, compare,
6469 : : convert (type, x), lse.expr);
6470 : :
6471 : 2102 : if (aop == OMP_ATOMIC)
6472 : : {
6473 : 1537 : x = build2_v (OMP_ATOMIC, lhsaddr, convert (type, x));
6474 : 1537 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6475 : 1537 : OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
6476 : 1537 : gfc_add_expr_to_block (&block, x);
6477 : : }
6478 : : else
6479 : : {
6480 : 565 : x = build2 (aop, type, lhsaddr, convert (type, x));
6481 : 565 : OMP_ATOMIC_MEMORY_ORDER (x) = mo;
6482 : 565 : OMP_ATOMIC_WEAK (x) = atomic_code->ext.omp_clauses->weak;
6483 : 565 : if (compare && else_branch)
6484 : : {
6485 : 64 : tree vtmp = create_tmp_var_raw (TREE_TYPE (x));
6486 : 64 : DECL_CONTEXT (vtmp) = current_function_decl;
6487 : 64 : x = fold_build2_loc (input_location, MODIFY_EXPR,
6488 : 64 : TREE_TYPE (vtmp), vtmp, x);
6489 : 64 : vtmp = build4 (TARGET_EXPR, TREE_TYPE (vtmp), vtmp,
6490 : 64 : build_zero_cst (TREE_TYPE (vtmp)), NULL, NULL);
6491 : 64 : TREE_OPERAND (x, 0) = vtmp;
6492 : 64 : tree x2 = convert (TREE_TYPE (vse.expr), vtmp);
6493 : 64 : x2 = fold_build2_loc (input_location, MODIFY_EXPR,
6494 : 64 : TREE_TYPE (vse.expr), vse.expr, x2);
6495 : 64 : x2 = build3_loc (input_location, COND_EXPR, void_type_node, comp_tgt,
6496 : : void_node, x2);
6497 : 64 : x = omit_one_operand_loc (input_location, TREE_TYPE (x2), x2, x);
6498 : 64 : gfc_add_expr_to_block (&block, x);
6499 : : }
6500 : : else
6501 : : {
6502 : 501 : x = convert (TREE_TYPE (vse.expr), x);
6503 : 501 : gfc_add_modify (&block, vse.expr, x);
6504 : : }
6505 : : }
6506 : :
6507 : 2102 : return gfc_finish_block (&block);
6508 : : }
6509 : :
6510 : : static tree
6511 : 603 : gfc_trans_omp_barrier (void)
6512 : : {
6513 : 603 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
6514 : 603 : return build_call_expr_loc (input_location, decl, 0);
6515 : : }
6516 : :
6517 : : static tree
6518 : 310 : gfc_trans_omp_cancel (gfc_code *code)
6519 : : {
6520 : 310 : int mask = 0;
6521 : 310 : tree ifc = boolean_true_node;
6522 : 310 : stmtblock_t block;
6523 : 310 : switch (code->ext.omp_clauses->cancel)
6524 : : {
6525 : : case OMP_CANCEL_PARALLEL: mask = 1; break;
6526 : : case OMP_CANCEL_DO: mask = 2; break;
6527 : : case OMP_CANCEL_SECTIONS: mask = 4; break;
6528 : : case OMP_CANCEL_TASKGROUP: mask = 8; break;
6529 : 0 : default: gcc_unreachable ();
6530 : : }
6531 : 310 : gfc_start_block (&block);
6532 : 310 : if (code->ext.omp_clauses->if_expr
6533 : 219 : || code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL])
6534 : : {
6535 : 99 : gfc_se se;
6536 : 99 : tree if_var;
6537 : :
6538 : 99 : gcc_assert ((code->ext.omp_clauses->if_expr == NULL)
6539 : : ^ (code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL] == NULL));
6540 : 99 : gfc_init_se (&se, NULL);
6541 : 99 : gfc_conv_expr (&se, code->ext.omp_clauses->if_expr != NULL
6542 : : ? code->ext.omp_clauses->if_expr
6543 : : : code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL]);
6544 : 99 : gfc_add_block_to_block (&block, &se.pre);
6545 : 99 : if_var = gfc_evaluate_now (se.expr, &block);
6546 : 99 : gfc_add_block_to_block (&block, &se.post);
6547 : 99 : tree type = TREE_TYPE (if_var);
6548 : 99 : ifc = fold_build2_loc (input_location, NE_EXPR,
6549 : : boolean_type_node, if_var,
6550 : : build_zero_cst (type));
6551 : : }
6552 : 310 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
6553 : 310 : tree c_bool_type = TREE_TYPE (TREE_TYPE (decl));
6554 : 310 : ifc = fold_convert (c_bool_type, ifc);
6555 : 310 : gfc_add_expr_to_block (&block,
6556 : : build_call_expr_loc (input_location, decl, 2,
6557 : 310 : build_int_cst (integer_type_node,
6558 : : mask), ifc));
6559 : 310 : return gfc_finish_block (&block);
6560 : : }
6561 : :
6562 : : static tree
6563 : 170 : gfc_trans_omp_cancellation_point (gfc_code *code)
6564 : : {
6565 : 170 : int mask = 0;
6566 : 170 : switch (code->ext.omp_clauses->cancel)
6567 : : {
6568 : : case OMP_CANCEL_PARALLEL: mask = 1; break;
6569 : : case OMP_CANCEL_DO: mask = 2; break;
6570 : : case OMP_CANCEL_SECTIONS: mask = 4; break;
6571 : : case OMP_CANCEL_TASKGROUP: mask = 8; break;
6572 : 0 : default: gcc_unreachable ();
6573 : : }
6574 : 170 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
6575 : 170 : return build_call_expr_loc (input_location, decl, 1,
6576 : 340 : build_int_cst (integer_type_node, mask));
6577 : : }
6578 : :
6579 : : static tree
6580 : 143 : gfc_trans_omp_critical (gfc_code *code)
6581 : : {
6582 : 143 : stmtblock_t block;
6583 : 143 : tree stmt, name = NULL_TREE;
6584 : 143 : if (code->ext.omp_clauses->critical_name != NULL)
6585 : 36 : name = get_identifier (code->ext.omp_clauses->critical_name);
6586 : 143 : gfc_start_block (&block);
6587 : 143 : stmt = make_node (OMP_CRITICAL);
6588 : 143 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
6589 : 143 : TREE_TYPE (stmt) = void_type_node;
6590 : 143 : OMP_CRITICAL_BODY (stmt) = gfc_trans_code (code->block->next);
6591 : 143 : OMP_CRITICAL_NAME (stmt) = name;
6592 : 143 : OMP_CRITICAL_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
6593 : : code->ext.omp_clauses,
6594 : : code->loc);
6595 : 143 : gfc_add_expr_to_block (&block, stmt);
6596 : 143 : return gfc_finish_block (&block);
6597 : : }
6598 : :
6599 : : typedef struct dovar_init_d {
6600 : : gfc_symbol *sym;
6601 : : tree var;
6602 : : tree init;
6603 : : bool non_unit_iter;
6604 : : } dovar_init;
6605 : :
6606 : : static bool
6607 : 2884 : gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n,
6608 : : gfc_code *code, gfc_expr *expr, vec<dovar_init> *inits,
6609 : : int simple, gfc_expr *curr_loop_var)
6610 : : {
6611 : 2884 : int i;
6612 : 4771 : for (i = 0; i < loop_n; i++)
6613 : : {
6614 : 2441 : gcc_assert (code->ext.iterator->var->expr_type == EXPR_VARIABLE);
6615 : 2441 : if (gfc_find_sym_in_expr (code->ext.iterator->var->symtree->n.sym, expr))
6616 : : break;
6617 : 1887 : code = code->block->next;
6618 : : }
6619 : 2884 : if (i >= loop_n)
6620 : : return false;
6621 : :
6622 : : /* Canonical format: TREE_VEC with [var, multiplier, offset]. */
6623 : 554 : gfc_symbol *var = code->ext.iterator->var->symtree->n.sym;
6624 : :
6625 : 554 : tree tree_var = NULL_TREE;
6626 : 554 : tree a1 = integer_one_node;
6627 : 554 : tree a2 = integer_zero_node;
6628 : :
6629 : 554 : if (!simple)
6630 : : {
6631 : : /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
6632 : 6 : sorry_at (gfc_get_location (&curr_loop_var->where),
6633 : : "non-rectangular loop nest with non-constant step for %qs",
6634 : 3 : curr_loop_var->symtree->n.sym->name);
6635 : 3 : return false;
6636 : : }
6637 : :
6638 : : dovar_init *di;
6639 : : unsigned ix;
6640 : 551 : FOR_EACH_VEC_ELT (*inits, ix, di)
6641 : 18 : if (di->sym == var)
6642 : : {
6643 : 18 : if (!di->non_unit_iter)
6644 : : {
6645 : 16 : tree_var = di->init;
6646 : 16 : gcc_assert (DECL_P (tree_var));
6647 : : break;
6648 : : }
6649 : : else
6650 : : {
6651 : : /* FIXME: Handle non-const iter steps, cf. PR fortran/110735. */
6652 : 2 : sorry_at (gfc_get_location (&code->loc),
6653 : : "non-rectangular loop nest with non-constant step "
6654 : : "for %qs", var->name);
6655 : 2 : inform (gfc_get_location (&expr->where), "Used here");
6656 : 2 : return false;
6657 : : }
6658 : : }
6659 : 533 : if (tree_var == NULL_TREE)
6660 : 533 : tree_var = var->backend_decl;
6661 : :
6662 : 549 : if (expr->expr_type == EXPR_VARIABLE)
6663 : 54 : gcc_assert (expr->symtree->n.sym == var);
6664 : 495 : else if (expr->expr_type != EXPR_OP
6665 : 495 : || (expr->value.op.op != INTRINSIC_TIMES
6666 : 479 : && expr->value.op.op != INTRINSIC_PLUS
6667 : 359 : && expr->value.op.op != INTRINSIC_MINUS))
6668 : 0 : gcc_unreachable ();
6669 : : else
6670 : : {
6671 : 495 : gfc_se se;
6672 : 495 : gfc_expr *et = NULL, *eo = NULL, *e = expr;
6673 : 495 : if (expr->value.op.op != INTRINSIC_TIMES)
6674 : : {
6675 : 479 : if (gfc_find_sym_in_expr (var, expr->value.op.op1))
6676 : : {
6677 : 431 : e = expr->value.op.op1;
6678 : 431 : eo = expr->value.op.op2;
6679 : : }
6680 : : else
6681 : : {
6682 : 48 : eo = expr->value.op.op1;
6683 : 48 : e = expr->value.op.op2;
6684 : : }
6685 : : }
6686 : 495 : if (e->value.op.op == INTRINSIC_TIMES)
6687 : : {
6688 : 91 : if (e->value.op.op1->expr_type == EXPR_VARIABLE
6689 : 91 : && e->value.op.op1->symtree->n.sym == var)
6690 : 51 : et = e->value.op.op2;
6691 : : else
6692 : : {
6693 : 40 : et = e->value.op.op1;
6694 : 40 : gcc_assert (e->value.op.op2->expr_type == EXPR_VARIABLE
6695 : : && e->value.op.op2->symtree->n.sym == var);
6696 : : }
6697 : : }
6698 : : else
6699 : 404 : gcc_assert (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym == var);
6700 : 91 : if (et != NULL)
6701 : : {
6702 : 91 : gfc_init_se (&se, NULL);
6703 : 91 : gfc_conv_expr_val (&se, et);
6704 : 91 : gfc_add_block_to_block (pblock, &se.pre);
6705 : 91 : a1 = se.expr;
6706 : : }
6707 : 495 : if (eo != NULL)
6708 : : {
6709 : 479 : gfc_init_se (&se, NULL);
6710 : 479 : gfc_conv_expr_val (&se, eo);
6711 : 479 : gfc_add_block_to_block (pblock, &se.pre);
6712 : 479 : a2 = se.expr;
6713 : 479 : if (expr->value.op.op == INTRINSIC_MINUS && expr->value.op.op2 == eo)
6714 : : /* outer-var - a2. */
6715 : 335 : a2 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a2), a2);
6716 : 144 : else if (expr->value.op.op == INTRINSIC_MINUS)
6717 : : /* a2 - outer-var. */
6718 : 24 : a1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (a1), a1);
6719 : : }
6720 : 495 : a1 = DECL_P (a1) ? a1 : gfc_evaluate_now (a1, pblock);
6721 : 495 : a2 = DECL_P (a2) ? a2 : gfc_evaluate_now (a2, pblock);
6722 : : }
6723 : :
6724 : 549 : gfc_init_se (sep, NULL);
6725 : 549 : sep->expr = make_tree_vec (3);
6726 : 549 : TREE_VEC_ELT (sep->expr, 0) = tree_var;
6727 : 549 : TREE_VEC_ELT (sep->expr, 1) = fold_convert (TREE_TYPE (tree_var), a1);
6728 : 549 : TREE_VEC_ELT (sep->expr, 2) = fold_convert (TREE_TYPE (tree_var), a2);
6729 : :
6730 : 549 : return true;
6731 : : }
6732 : :
6733 : : int
6734 : 708 : gfc_expr_list_len (gfc_expr_list *list)
6735 : : {
6736 : 708 : unsigned len = 0;
6737 : 2092 : for (; list; list = list->next)
6738 : 1384 : len++;
6739 : :
6740 : 708 : return len;
6741 : : }
6742 : :
6743 : : static tree
6744 : 9510 : gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock,
6745 : : gfc_omp_clauses *do_clauses, tree par_clauses)
6746 : : {
6747 : 9510 : gfc_se se;
6748 : 9510 : tree dovar, stmt, from, to, step, type, init, cond, incr, orig_decls;
6749 : 9510 : tree local_dovar = NULL_TREE, cycle_label, tmp, omp_clauses;
6750 : 9510 : stmtblock_t block;
6751 : 9510 : stmtblock_t body;
6752 : 9510 : gfc_omp_clauses *clauses = code->ext.omp_clauses;
6753 : 9510 : int i, collapse = clauses->collapse;
6754 : 9510 : vec<dovar_init> inits = vNULL;
6755 : 9510 : dovar_init *di;
6756 : 9510 : unsigned ix;
6757 : 9510 : vec<tree, va_heap, vl_embed> *saved_doacross_steps = doacross_steps;
6758 : 19020 : gfc_expr_list *oacc_tile
6759 : 9510 : = do_clauses ? do_clauses->tile_list : clauses->tile_list;
6760 : 19020 : gfc_expr_list *sizes
6761 : 9510 : = do_clauses ? do_clauses->sizes_list : clauses->sizes_list;
6762 : 9510 : gfc_code *orig_code = code;
6763 : :
6764 : : /* Both collapsed and tiled loops are lowered the same way. In
6765 : : OpenACC, those clauses are not compatible, so prioritize the tile
6766 : : clause, if present. */
6767 : 9510 : if (oacc_tile)
6768 : 60 : collapse = gfc_expr_list_len (oacc_tile);
6769 : 9450 : else if (sizes)
6770 : 120 : collapse = gfc_expr_list_len (sizes);
6771 : :
6772 : 9510 : doacross_steps = NULL;
6773 : 9510 : if (clauses->orderedc)
6774 : 132 : collapse = clauses->orderedc;
6775 : 9510 : if (collapse <= 0)
6776 : : collapse = 1;
6777 : :
6778 : 9510 : code = code->block->next;
6779 : :
6780 : 9510 : init = make_tree_vec (collapse);
6781 : 9510 : cond = make_tree_vec (collapse);
6782 : 9510 : incr = make_tree_vec (collapse);
6783 : 9510 : orig_decls = clauses->ordered ? make_tree_vec (collapse) : NULL_TREE;
6784 : :
6785 : 9510 : if (pblock == NULL)
6786 : : {
6787 : 6027 : gfc_start_block (&block);
6788 : 6027 : pblock = █
6789 : : }
6790 : :
6791 : : /* simd schedule modifier is only useful for composite do simd and other
6792 : : constructs including that, where gfc_trans_omp_do is only called
6793 : : on the simd construct and DO's clauses are translated elsewhere. */
6794 : 9510 : do_clauses->sched_simd = false;
6795 : :
6796 : 9510 : omp_clauses = gfc_trans_omp_clauses (pblock, do_clauses, code->loc);
6797 : :
6798 : 21505 : for (i = 0; i < collapse; i++)
6799 : : {
6800 : 11995 : int simple = 0;
6801 : 11995 : int dovar_found = 0;
6802 : 11995 : tree dovar_decl;
6803 : :
6804 : 11995 : if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
6805 : : {
6806 : 320 : TREE_VEC_ELT (init, i) = NULL_TREE;
6807 : 320 : TREE_VEC_ELT (cond, i) = NULL_TREE;
6808 : 320 : TREE_VEC_ELT (incr, i) = NULL_TREE;
6809 : 320 : TREE_VEC_ELT (incr, i) = NULL_TREE;
6810 : 320 : if (orig_decls)
6811 : 2 : TREE_VEC_ELT (orig_decls, i) = NULL_TREE;
6812 : 320 : continue;
6813 : : }
6814 : 11675 : gcc_assert (code->op == EXEC_DO);
6815 : 11675 : if (clauses)
6816 : : {
6817 : 11675 : gfc_omp_namelist *n = NULL;
6818 : 11675 : if (op == EXEC_OMP_SIMD && collapse == 1)
6819 : 936 : for (n = clauses->lists[OMP_LIST_LINEAR];
6820 : 1236 : n != NULL; n = n->next)
6821 : 443 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6822 : : {
6823 : : dovar_found = 3;
6824 : : break;
6825 : : }
6826 : 11675 : if (n == NULL && op != EXEC_OMP_DISTRIBUTE)
6827 : 11438 : for (n = clauses->lists[OMP_LIST_LASTPRIVATE];
6828 : 13497 : n != NULL; n = n->next)
6829 : 3436 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6830 : : {
6831 : : dovar_found = 2;
6832 : : break;
6833 : : }
6834 : 11675 : if (n == NULL)
6835 : 11408 : for (n = clauses->lists[OMP_LIST_PRIVATE]; n != NULL; n = n->next)
6836 : 6976 : if (code->ext.iterator->var->symtree->n.sym == n->sym)
6837 : : {
6838 : : dovar_found = 1;
6839 : : break;
6840 : : }
6841 : : }
6842 : :
6843 : : /* Evaluate all the expressions in the iterator. */
6844 : 11675 : gfc_init_se (&se, NULL);
6845 : 11675 : gfc_conv_expr_lhs (&se, code->ext.iterator->var);
6846 : 11675 : gfc_add_block_to_block (pblock, &se.pre);
6847 : 11675 : local_dovar = dovar_decl = dovar = se.expr;
6848 : 11675 : type = TREE_TYPE (dovar);
6849 : 11675 : gcc_assert (TREE_CODE (type) == INTEGER_TYPE);
6850 : :
6851 : 11675 : gfc_init_se (&se, NULL);
6852 : 11675 : gfc_conv_expr_val (&se, code->ext.iterator->step);
6853 : 11675 : gfc_add_block_to_block (pblock, &se.pre);
6854 : 11675 : step = gfc_evaluate_now (se.expr, pblock);
6855 : :
6856 : 11675 : if (TREE_CODE (step) == INTEGER_CST)
6857 : 11084 : simple = tree_int_cst_sgn (step);
6858 : :
6859 : 11675 : gfc_init_se (&se, NULL);
6860 : 11675 : if (!clauses->non_rectangular
6861 : 13117 : || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
6862 : : code->ext.iterator->start, &inits, simple,
6863 : 1442 : code->ext.iterator->var))
6864 : : {
6865 : 11359 : gfc_conv_expr_val (&se, code->ext.iterator->start);
6866 : 11359 : gfc_add_block_to_block (pblock, &se.pre);
6867 : 11359 : if (!DECL_P (se.expr))
6868 : 10961 : se.expr = gfc_evaluate_now (se.expr, pblock);
6869 : : }
6870 : 11675 : from = se.expr;
6871 : :
6872 : 11675 : gfc_init_se (&se, NULL);
6873 : 11675 : if (!clauses->non_rectangular
6874 : 13117 : || !gfc_nonrect_loop_expr (pblock, &se, i, orig_code->block->next,
6875 : : code->ext.iterator->end, &inits, simple,
6876 : 1442 : code->ext.iterator->var))
6877 : : {
6878 : 11442 : gfc_conv_expr_val (&se, code->ext.iterator->end);
6879 : 11442 : gfc_add_block_to_block (pblock, &se.pre);
6880 : 11442 : if (!DECL_P (se.expr))
6881 : 10209 : se.expr = gfc_evaluate_now (se.expr, pblock);
6882 : : }
6883 : 11675 : to = se.expr;
6884 : :
6885 : 11675 : if (!DECL_P (dovar))
6886 : 38 : dovar_decl
6887 : 38 : = gfc_trans_omp_variable (code->ext.iterator->var->symtree->n.sym,
6888 : : false);
6889 : 11675 : if (simple && !DECL_P (dovar))
6890 : : {
6891 : 38 : const char *name = code->ext.iterator->var->symtree->n.sym->name;
6892 : 38 : local_dovar = gfc_create_var (type, name);
6893 : 38 : dovar_init e = {code->ext.iterator->var->symtree->n.sym,
6894 : 38 : dovar, local_dovar, false};
6895 : 38 : inits.safe_push (e);
6896 : : }
6897 : : /* Loop body. */
6898 : 11675 : if (simple)
6899 : : {
6900 : 11084 : TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar, from);
6901 : : /* The condition should not be folded. */
6902 : 11636 : TREE_VEC_ELT (cond, i) = build2_loc (input_location, simple > 0
6903 : : ? LE_EXPR : GE_EXPR,
6904 : : logical_type_node, local_dovar,
6905 : : to);
6906 : 11084 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
6907 : : type, local_dovar, step);
6908 : 11084 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
6909 : : MODIFY_EXPR,
6910 : : type, local_dovar,
6911 : 11084 : TREE_VEC_ELT (incr, i));
6912 : 11084 : if (orig_decls && !clauses->orderedc)
6913 : : orig_decls = NULL;
6914 : 380 : else if (orig_decls)
6915 : 380 : TREE_VEC_ELT (orig_decls, i) = dovar_decl;
6916 : : }
6917 : : else
6918 : : {
6919 : : /* STEP is not 1 or -1. Use:
6920 : : for (count = 0; count < (to + step - from) / step; count++)
6921 : : {
6922 : : dovar = from + count * step;
6923 : : body;
6924 : : cycle_label:;
6925 : : } */
6926 : 591 : tmp = fold_build2_loc (input_location, MINUS_EXPR, type, step, from);
6927 : 591 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type, to, tmp);
6928 : 591 : tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR, type, tmp,
6929 : : step);
6930 : 591 : tmp = gfc_evaluate_now (tmp, pblock);
6931 : 591 : local_dovar = gfc_create_var (type, "count");
6932 : 591 : TREE_VEC_ELT (init, i) = build2_v (MODIFY_EXPR, local_dovar,
6933 : : build_int_cst (type, 0));
6934 : : /* The condition should not be folded. */
6935 : 591 : TREE_VEC_ELT (cond, i) = build2_loc (input_location, LT_EXPR,
6936 : : logical_type_node,
6937 : : local_dovar, tmp);
6938 : 591 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location, PLUS_EXPR,
6939 : : type, local_dovar,
6940 : 591 : build_int_cst (type, 1));
6941 : 591 : TREE_VEC_ELT (incr, i) = fold_build2_loc (input_location,
6942 : : MODIFY_EXPR, type,
6943 : : local_dovar,
6944 : 591 : TREE_VEC_ELT (incr, i));
6945 : :
6946 : : /* Initialize DOVAR. */
6947 : 591 : tmp = fold_build2_loc (input_location, MULT_EXPR, type, local_dovar,
6948 : : step);
6949 : 591 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type, from, tmp);
6950 : 591 : dovar_init e = {code->ext.iterator->var->symtree->n.sym,
6951 : 591 : dovar, tmp, true};
6952 : 591 : inits.safe_push (e);
6953 : 591 : if (clauses->orderedc)
6954 : : {
6955 : 192 : if (doacross_steps == NULL)
6956 : 47 : vec_safe_grow_cleared (doacross_steps, clauses->orderedc, true);
6957 : 192 : (*doacross_steps)[i] = step;
6958 : : }
6959 : 591 : if (orig_decls)
6960 : 198 : TREE_VEC_ELT (orig_decls, i) = dovar_decl;
6961 : : }
6962 : :
6963 : 11675 : if (dovar_found == 3
6964 : 11675 : && op == EXEC_OMP_SIMD
6965 : 143 : && collapse == 1
6966 : 143 : && local_dovar != dovar)
6967 : : {
6968 : 120 : for (tmp = omp_clauses; tmp; tmp = OMP_CLAUSE_CHAIN (tmp))
6969 : 120 : if (OMP_CLAUSE_CODE (tmp) == OMP_CLAUSE_LINEAR
6970 : 120 : && OMP_CLAUSE_DECL (tmp) == dovar)
6971 : : {
6972 : 30 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
6973 : 30 : break;
6974 : : }
6975 : : }
6976 : 11675 : if (!dovar_found && op == EXEC_OMP_SIMD)
6977 : : {
6978 : 1352 : if (collapse == 1)
6979 : : {
6980 : 783 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
6981 : 783 : OMP_CLAUSE_LINEAR_STEP (tmp) = step;
6982 : 783 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
6983 : 783 : OMP_CLAUSE_DECL (tmp) = dovar_decl;
6984 : 783 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
6985 : 783 : if (local_dovar != dovar)
6986 : : dovar_found = 3;
6987 : : }
6988 : : }
6989 : 10323 : else if (!dovar_found && local_dovar != dovar)
6990 : : {
6991 : 260 : tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
6992 : 260 : OMP_CLAUSE_DECL (tmp) = dovar_decl;
6993 : 260 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
6994 : : }
6995 : 11645 : if (dovar_found > 1)
6996 : : {
6997 : 1550 : tree c = NULL;
6998 : :
6999 : 1550 : tmp = NULL;
7000 : 1550 : if (local_dovar != dovar)
7001 : : {
7002 : : /* If dovar is lastprivate, but different counter is used,
7003 : : dovar += step needs to be added to
7004 : : OMP_CLAUSE_LASTPRIVATE_STMT, otherwise the copied dovar
7005 : : will have the value on entry of the last loop, rather
7006 : : than value after iterator increment. */
7007 : 243 : if (clauses->orderedc)
7008 : : {
7009 : 60 : if (clauses->collapse <= 1 || i >= clauses->collapse)
7010 : : tmp = local_dovar;
7011 : : else
7012 : 36 : tmp = fold_build2_loc (input_location, PLUS_EXPR,
7013 : : type, local_dovar,
7014 : : build_one_cst (type));
7015 : 60 : tmp = fold_build2_loc (input_location, MULT_EXPR, type,
7016 : : tmp, step);
7017 : 60 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
7018 : : from, tmp);
7019 : : }
7020 : : else
7021 : 183 : tmp = fold_build2_loc (input_location, PLUS_EXPR, type,
7022 : : dovar, step);
7023 : 243 : tmp = fold_build2_loc (input_location, MODIFY_EXPR, type,
7024 : : dovar, tmp);
7025 : 934 : for (c = omp_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7026 : 613 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7027 : 613 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7028 : : {
7029 : 105 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = tmp;
7030 : 105 : break;
7031 : : }
7032 : 508 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7033 : 508 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7034 : : {
7035 : 60 : OMP_CLAUSE_LINEAR_STMT (c) = tmp;
7036 : 60 : break;
7037 : : }
7038 : : }
7039 : 1550 : if (c == NULL && op == EXEC_OMP_DO && par_clauses != NULL)
7040 : : {
7041 : 892 : for (c = par_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7042 : 892 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7043 : 892 : && OMP_CLAUSE_DECL (c) == dovar_decl)
7044 : : {
7045 : 406 : tree l = build_omp_clause (input_location,
7046 : : OMP_CLAUSE_LASTPRIVATE);
7047 : 406 : if (OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
7048 : 4 : OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (l) = 1;
7049 : 406 : OMP_CLAUSE_DECL (l) = dovar_decl;
7050 : 406 : OMP_CLAUSE_CHAIN (l) = omp_clauses;
7051 : 406 : OMP_CLAUSE_LASTPRIVATE_STMT (l) = tmp;
7052 : 406 : omp_clauses = l;
7053 : 406 : OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_SHARED);
7054 : 406 : break;
7055 : : }
7056 : : }
7057 : 1550 : gcc_assert (local_dovar == dovar || c != NULL);
7058 : : }
7059 : 11675 : if (local_dovar != dovar)
7060 : : {
7061 : 629 : if (op != EXEC_OMP_SIMD || dovar_found == 1)
7062 : 550 : tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
7063 : 79 : else if (collapse == 1)
7064 : : {
7065 : 60 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LINEAR);
7066 : 60 : OMP_CLAUSE_LINEAR_STEP (tmp) = build_int_cst (type, 1);
7067 : 60 : OMP_CLAUSE_LINEAR_NO_COPYIN (tmp) = 1;
7068 : 60 : OMP_CLAUSE_LINEAR_NO_COPYOUT (tmp) = 1;
7069 : : }
7070 : : else
7071 : 19 : tmp = build_omp_clause (input_location, OMP_CLAUSE_LASTPRIVATE);
7072 : 629 : OMP_CLAUSE_DECL (tmp) = local_dovar;
7073 : 629 : omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
7074 : : }
7075 : :
7076 : 11675 : if (i + 1 < collapse)
7077 : 2457 : code = code->block->next;
7078 : : }
7079 : :
7080 : 9510 : if (pblock != &block)
7081 : : {
7082 : 3483 : pushlevel ();
7083 : 3483 : gfc_start_block (&block);
7084 : : }
7085 : :
7086 : 9510 : gfc_start_block (&body);
7087 : :
7088 : 19649 : FOR_EACH_VEC_ELT (inits, ix, di)
7089 : 629 : gfc_add_modify (&body, di->var, di->init);
7090 : 9510 : inits.release ();
7091 : :
7092 : : /* Cycle statement is implemented with a goto. Exit statement must not be
7093 : : present for this loop. */
7094 : 9510 : cycle_label = gfc_build_label_decl (NULL_TREE);
7095 : :
7096 : : /* Put these labels where they can be found later. */
7097 : :
7098 : 9510 : code->cycle_label = cycle_label;
7099 : 9510 : code->exit_label = NULL_TREE;
7100 : :
7101 : : /* Main loop body. */
7102 : 9510 : if (clauses->lists[OMP_LIST_REDUCTION_INSCAN])
7103 : : {
7104 : 16 : gfc_code *code1, *scan, *code2, *tmpcode;
7105 : 16 : code1 = tmpcode = code->block->next;
7106 : 16 : if (tmpcode && tmpcode->op != EXEC_OMP_SCAN)
7107 : 18 : while (tmpcode && tmpcode->next && tmpcode->next->op != EXEC_OMP_SCAN)
7108 : : tmpcode = tmpcode->next;
7109 : 16 : scan = tmpcode->op == EXEC_OMP_SCAN ? tmpcode : tmpcode->next;
7110 : 16 : if (code1 != scan)
7111 : 16 : tmpcode->next = NULL;
7112 : 16 : code2 = scan->next;
7113 : 16 : gcc_assert (scan->op == EXEC_OMP_SCAN);
7114 : 16 : location_t loc = gfc_get_location (&scan->loc);
7115 : :
7116 : 16 : tmp = code1 != scan ? gfc_trans_code (code1) : build_empty_stmt (loc);
7117 : 16 : tmp = build2 (OMP_SCAN, void_type_node, tmp, NULL_TREE);
7118 : 16 : SET_EXPR_LOCATION (tmp, loc);
7119 : 16 : gfc_add_expr_to_block (&body, tmp);
7120 : 16 : input_location = loc;
7121 : 16 : tree c = gfc_trans_omp_clauses (&body, scan->ext.omp_clauses, scan->loc);
7122 : 16 : tmp = code2 ? gfc_trans_code (code2) : build_empty_stmt (loc);
7123 : 16 : tmp = build2 (OMP_SCAN, void_type_node, tmp, c);
7124 : 16 : SET_EXPR_LOCATION (tmp, loc);
7125 : 16 : if (code1 != scan)
7126 : 16 : tmpcode->next = scan;
7127 : : }
7128 : 9494 : else if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
7129 : 292 : tmp = gfc_trans_omp_code (code, true);
7130 : : else
7131 : 9202 : tmp = gfc_trans_omp_code (code->block->next, true);
7132 : 9510 : gfc_add_expr_to_block (&body, tmp);
7133 : :
7134 : : /* Label for cycle statements (if needed). */
7135 : 9510 : if (TREE_USED (cycle_label))
7136 : : {
7137 : 9510 : tmp = build1_v (LABEL_EXPR, cycle_label);
7138 : 9510 : gfc_add_expr_to_block (&body, tmp);
7139 : : }
7140 : :
7141 : : /* End of loop body. */
7142 : 9510 : switch (op)
7143 : : {
7144 : 1453 : case EXEC_OMP_SIMD: stmt = make_node (OMP_SIMD); break;
7145 : 2403 : case EXEC_OMP_DO: stmt = make_node (OMP_FOR); break;
7146 : 80 : case EXEC_OMP_DISTRIBUTE: stmt = make_node (OMP_DISTRIBUTE); break;
7147 : 112 : case EXEC_OMP_LOOP: stmt = make_node (OMP_LOOP); break;
7148 : 94 : case EXEC_OMP_TASKLOOP: stmt = make_node (OMP_TASKLOOP); break;
7149 : 4926 : case EXEC_OACC_LOOP: stmt = make_node (OACC_LOOP); break;
7150 : 120 : case EXEC_OMP_TILE: stmt = make_node (OMP_TILE); break;
7151 : 322 : case EXEC_OMP_UNROLL: stmt = make_node (OMP_UNROLL); break;
7152 : 0 : default: gcc_unreachable ();
7153 : : }
7154 : :
7155 : 9510 : SET_EXPR_LOCATION (stmt, gfc_get_location (&orig_code->loc));
7156 : 9510 : TREE_TYPE (stmt) = void_type_node;
7157 : 9510 : OMP_FOR_BODY (stmt) = gfc_finish_block (&body);
7158 : 9510 : OMP_FOR_CLAUSES (stmt) = omp_clauses;
7159 : 9510 : OMP_FOR_INIT (stmt) = init;
7160 : 9510 : OMP_FOR_COND (stmt) = cond;
7161 : 9510 : OMP_FOR_INCR (stmt) = incr;
7162 : 9510 : if (orig_decls)
7163 : 138 : OMP_FOR_ORIG_DECLS (stmt) = orig_decls;
7164 : 9510 : OMP_FOR_NON_RECTANGULAR (stmt) = clauses->non_rectangular;
7165 : 9510 : gfc_add_expr_to_block (&block, stmt);
7166 : :
7167 : 9510 : vec_free (doacross_steps);
7168 : 9510 : doacross_steps = saved_doacross_steps;
7169 : :
7170 : 9510 : return gfc_finish_block (&block);
7171 : : }
7172 : :
7173 : : /* Translate combined OpenACC 'parallel loop', 'kernels loop', 'serial loop'
7174 : : construct. */
7175 : :
7176 : : static tree
7177 : 1552 : gfc_trans_oacc_combined_directive (gfc_code *code)
7178 : : {
7179 : 1552 : stmtblock_t block, *pblock = NULL;
7180 : 1552 : gfc_omp_clauses construct_clauses, loop_clauses;
7181 : 1552 : tree stmt, oacc_clauses = NULL_TREE;
7182 : 1552 : enum tree_code construct_code;
7183 : 1552 : location_t loc = input_location;
7184 : :
7185 : 1552 : switch (code->op)
7186 : : {
7187 : : case EXEC_OACC_PARALLEL_LOOP:
7188 : : construct_code = OACC_PARALLEL;
7189 : : break;
7190 : : case EXEC_OACC_KERNELS_LOOP:
7191 : : construct_code = OACC_KERNELS;
7192 : : break;
7193 : : case EXEC_OACC_SERIAL_LOOP:
7194 : : construct_code = OACC_SERIAL;
7195 : : break;
7196 : 0 : default:
7197 : 0 : gcc_unreachable ();
7198 : : }
7199 : :
7200 : 1552 : gfc_start_block (&block);
7201 : :
7202 : 1552 : memset (&loop_clauses, 0, sizeof (loop_clauses));
7203 : 1552 : if (code->ext.omp_clauses != NULL)
7204 : : {
7205 : 1552 : memcpy (&construct_clauses, code->ext.omp_clauses,
7206 : : sizeof (construct_clauses));
7207 : 1552 : loop_clauses.collapse = construct_clauses.collapse;
7208 : 1552 : loop_clauses.gang = construct_clauses.gang;
7209 : 1552 : loop_clauses.gang_static = construct_clauses.gang_static;
7210 : 1552 : loop_clauses.gang_num_expr = construct_clauses.gang_num_expr;
7211 : 1552 : loop_clauses.gang_static_expr = construct_clauses.gang_static_expr;
7212 : 1552 : loop_clauses.vector = construct_clauses.vector;
7213 : 1552 : loop_clauses.vector_expr = construct_clauses.vector_expr;
7214 : 1552 : loop_clauses.worker = construct_clauses.worker;
7215 : 1552 : loop_clauses.worker_expr = construct_clauses.worker_expr;
7216 : 1552 : loop_clauses.seq = construct_clauses.seq;
7217 : 1552 : loop_clauses.par_auto = construct_clauses.par_auto;
7218 : 1552 : loop_clauses.independent = construct_clauses.independent;
7219 : 1552 : loop_clauses.tile_list = construct_clauses.tile_list;
7220 : 1552 : loop_clauses.lists[OMP_LIST_PRIVATE]
7221 : 1552 : = construct_clauses.lists[OMP_LIST_PRIVATE];
7222 : 1552 : loop_clauses.lists[OMP_LIST_REDUCTION]
7223 : 1552 : = construct_clauses.lists[OMP_LIST_REDUCTION];
7224 : 1552 : construct_clauses.gang = false;
7225 : 1552 : construct_clauses.gang_static = false;
7226 : 1552 : construct_clauses.gang_num_expr = NULL;
7227 : 1552 : construct_clauses.gang_static_expr = NULL;
7228 : 1552 : construct_clauses.vector = false;
7229 : 1552 : construct_clauses.vector_expr = NULL;
7230 : 1552 : construct_clauses.worker = false;
7231 : 1552 : construct_clauses.worker_expr = NULL;
7232 : 1552 : construct_clauses.seq = false;
7233 : 1552 : construct_clauses.par_auto = false;
7234 : 1552 : construct_clauses.independent = false;
7235 : 1552 : construct_clauses.independent = false;
7236 : 1552 : construct_clauses.tile_list = NULL;
7237 : 1552 : construct_clauses.lists[OMP_LIST_PRIVATE] = NULL;
7238 : 1552 : if (construct_code == OACC_KERNELS)
7239 : 87 : construct_clauses.lists[OMP_LIST_REDUCTION] = NULL;
7240 : 1552 : oacc_clauses = gfc_trans_omp_clauses (&block, &construct_clauses,
7241 : : code->loc, false, true);
7242 : : }
7243 : 1552 : if (!loop_clauses.seq)
7244 : : pblock = █
7245 : : else
7246 : 54 : pushlevel ();
7247 : 1552 : stmt = gfc_trans_omp_do (code, EXEC_OACC_LOOP, pblock, &loop_clauses, NULL);
7248 : 1552 : protected_set_expr_location (stmt, loc);
7249 : 1552 : if (TREE_CODE (stmt) != BIND_EXPR)
7250 : 1552 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
7251 : : else
7252 : 0 : poplevel (0, 0);
7253 : 1552 : stmt = build2_loc (loc, construct_code, void_type_node, stmt, oacc_clauses);
7254 : 1552 : gfc_add_expr_to_block (&block, stmt);
7255 : 1552 : return gfc_finish_block (&block);
7256 : : }
7257 : :
7258 : : static tree
7259 : 106 : gfc_trans_omp_depobj (gfc_code *code)
7260 : : {
7261 : 106 : stmtblock_t block;
7262 : 106 : gfc_se se;
7263 : 106 : gfc_init_se (&se, NULL);
7264 : 106 : gfc_init_block (&block);
7265 : 106 : gfc_conv_expr (&se, code->ext.omp_clauses->depobj);
7266 : 106 : gcc_assert (se.pre.head == NULL && se.post.head == NULL);
7267 : 106 : tree depobj = se.expr;
7268 : 106 : location_t loc = EXPR_LOCATION (depobj);
7269 : 106 : if (!POINTER_TYPE_P (TREE_TYPE (depobj)))
7270 : 106 : depobj = gfc_build_addr_expr (NULL, depobj);
7271 : 106 : depobj = fold_convert (build_pointer_type_for_mode (ptr_type_node,
7272 : : TYPE_MODE (ptr_type_node),
7273 : : true), depobj);
7274 : 106 : gfc_omp_namelist *n = code->ext.omp_clauses->lists[OMP_LIST_DEPEND];
7275 : 106 : if (n)
7276 : : {
7277 : 82 : tree var;
7278 : 82 : if (!n->sym) /* omp_all_memory. */
7279 : 3 : var = null_pointer_node;
7280 : 79 : else if (n->expr && n->expr->ref->u.ar.type != AR_FULL)
7281 : : {
7282 : 18 : gfc_init_se (&se, NULL);
7283 : 18 : if (n->expr->ref->u.ar.type == AR_ELEMENT)
7284 : : {
7285 : 18 : gfc_conv_expr_reference (&se, n->expr);
7286 : 18 : var = se.expr;
7287 : : }
7288 : : else
7289 : : {
7290 : 0 : gfc_conv_expr_descriptor (&se, n->expr);
7291 : 0 : var = gfc_conv_array_data (se.expr);
7292 : : }
7293 : 18 : gfc_add_block_to_block (&block, &se.pre);
7294 : 18 : gfc_add_block_to_block (&block, &se.post);
7295 : 18 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
7296 : : }
7297 : : else
7298 : : {
7299 : 61 : var = gfc_get_symbol_decl (n->sym);
7300 : 98 : if (POINTER_TYPE_P (TREE_TYPE (var))
7301 : 71 : && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (var))))
7302 : 8 : var = build_fold_indirect_ref (var);
7303 : 61 : if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (var)))
7304 : : {
7305 : 12 : var = gfc_conv_descriptor_data_get (var);
7306 : 12 : gcc_assert (POINTER_TYPE_P (TREE_TYPE (var)));
7307 : : }
7308 : 49 : else if ((n->sym->attr.allocatable || n->sym->attr.pointer)
7309 : 13 : && n->sym->attr.dummy)
7310 : 8 : var = build_fold_indirect_ref (var);
7311 : 66 : else if (!POINTER_TYPE_P (TREE_TYPE (var))
7312 : 43 : || (n->sym->ts.f90_type == BT_VOID
7313 : 11 : && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (var)))
7314 : 7 : && !GFC_ARRAY_TYPE_P (TREE_TYPE (TREE_TYPE (var)))))
7315 : : {
7316 : 28 : TREE_ADDRESSABLE (var) = 1;
7317 : 28 : var = gfc_build_addr_expr (NULL, var);
7318 : : }
7319 : : }
7320 : 82 : depobj = save_expr (depobj);
7321 : 82 : tree r = build_fold_indirect_ref_loc (loc, depobj);
7322 : 82 : gfc_add_expr_to_block (&block,
7323 : : build2 (MODIFY_EXPR, void_type_node, r, var));
7324 : : }
7325 : :
7326 : : /* Only one may be set. */
7327 : 106 : gcc_assert (((int)(n != NULL) + (int)(code->ext.omp_clauses->destroy)
7328 : : + (int)(code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET))
7329 : : == 1);
7330 : 106 : int k = -1; /* omp_clauses->destroy */
7331 : 106 : if (!code->ext.omp_clauses->destroy)
7332 : 91 : switch (code->ext.omp_clauses->depobj_update != OMP_DEPEND_UNSET
7333 : 91 : ? code->ext.omp_clauses->depobj_update : n->u.depend_doacross_op)
7334 : : {
7335 : : case OMP_DEPEND_IN: k = GOMP_DEPEND_IN; break;
7336 : : case OMP_DEPEND_OUT: k = GOMP_DEPEND_OUT; break;
7337 : : case OMP_DEPEND_INOUT: k = GOMP_DEPEND_INOUT; break;
7338 : : case OMP_DEPEND_INOUTSET: k = GOMP_DEPEND_INOUTSET; break;
7339 : : case OMP_DEPEND_MUTEXINOUTSET: k = GOMP_DEPEND_MUTEXINOUTSET; break;
7340 : 0 : default: gcc_unreachable ();
7341 : : }
7342 : 106 : tree t = build_int_cst (ptr_type_node, k);
7343 : 106 : depobj = build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (depobj), depobj,
7344 : 106 : TYPE_SIZE_UNIT (ptr_type_node));
7345 : 106 : depobj = build_fold_indirect_ref_loc (loc, depobj);
7346 : 106 : gfc_add_expr_to_block (&block, build2 (MODIFY_EXPR, void_type_node, depobj, t));
7347 : :
7348 : 106 : return gfc_finish_block (&block);
7349 : : }
7350 : :
7351 : : /* Callback for walk_tree to find an OMP dispatch call and wrap it into an
7352 : : * IFN_GOMP_DISPATCH. */
7353 : :
7354 : : static tree
7355 : 2066 : replace_omp_dispatch_call (tree *tp, int *, void *decls_p)
7356 : : {
7357 : 2066 : tree t = *tp;
7358 : 2066 : tree decls = (tree) decls_p;
7359 : 2066 : tree orig_fn_decl = TREE_PURPOSE (decls);
7360 : 2066 : tree dup_fn_decl = TREE_VALUE (decls);
7361 : 2066 : if (TREE_CODE (t) == CALL_EXPR)
7362 : : {
7363 : 141 : if (CALL_EXPR_FN (t) == dup_fn_decl)
7364 : 1 : CALL_EXPR_FN (t) = orig_fn_decl;
7365 : 140 : else if (TREE_CODE (CALL_EXPR_FN (t)) == ADDR_EXPR
7366 : 140 : && TREE_OPERAND (CALL_EXPR_FN (t), 0) == dup_fn_decl)
7367 : 127 : TREE_OPERAND (CALL_EXPR_FN (t), 0) = dup_fn_decl;
7368 : : else
7369 : : return NULL_TREE;
7370 : 128 : *tp = build_call_expr_internal_loc (input_location, IFN_GOMP_DISPATCH,
7371 : 128 : TREE_TYPE (t), 1, t);
7372 : 128 : return *tp;
7373 : : }
7374 : :
7375 : : return NULL_TREE;
7376 : : }
7377 : :
7378 : : static tree
7379 : 128 : gfc_trans_omp_dispatch (gfc_code *code)
7380 : : {
7381 : 128 : stmtblock_t block;
7382 : 128 : gfc_code *next = code->block->next;
7383 : : // assume ill-formed "function dispatch structured
7384 : : // block" have already been rejected by resolve_omp_dispatch
7385 : 128 : gcc_assert (next->op == EXEC_CALL || next->op == EXEC_ASSIGN);
7386 : :
7387 : : // Make duplicate decl for dispatch function call to make it easy to spot
7388 : : // after translation
7389 : 128 : gfc_symbol *orig_fn_sym;
7390 : 128 : gfc_expr *call_expr = next->op == EXEC_CALL ? next->expr1 : next->expr2;
7391 : 128 : if (call_expr != NULL) // function
7392 : : {
7393 : 71 : if (call_expr->value.function.isym != NULL) // dig into convert intrinsics
7394 : 4 : call_expr = call_expr->value.function.actual->expr;
7395 : 71 : gcc_assert (call_expr->expr_type == EXPR_FUNCTION);
7396 : 71 : orig_fn_sym = call_expr->value.function.esym
7397 : 71 : ? call_expr->value.function.esym
7398 : 0 : : call_expr->symtree->n.sym;
7399 : : }
7400 : : else // subroutine
7401 : : {
7402 : 57 : orig_fn_sym = next->resolved_sym;
7403 : : }
7404 : 128 : if (!orig_fn_sym->backend_decl)
7405 : 25 : gfc_get_symbol_decl (orig_fn_sym);
7406 : 128 : gfc_symbol dup_fn_sym = *orig_fn_sym;
7407 : 128 : dup_fn_sym.backend_decl = copy_node (orig_fn_sym->backend_decl);
7408 : 128 : if (call_expr != NULL)
7409 : 71 : call_expr->value.function.esym = &dup_fn_sym;
7410 : : else
7411 : 57 : next->resolved_sym = &dup_fn_sym;
7412 : :
7413 : 128 : tree body = gfc_trans_code (next);
7414 : :
7415 : : // Walk the tree to find the duplicate decl, wrap IFN call and replace
7416 : : // dup decl with original
7417 : 128 : tree fn_decls
7418 : 128 : = build_tree_list (orig_fn_sym->backend_decl, dup_fn_sym.backend_decl);
7419 : 128 : tree dispatch_call
7420 : 128 : = walk_tree (&body, replace_omp_dispatch_call, fn_decls, NULL);
7421 : 128 : gcc_assert (dispatch_call != NULL_TREE);
7422 : :
7423 : 128 : gfc_start_block (&block);
7424 : 128 : tree omp_clauses
7425 : 128 : = gfc_trans_omp_clauses (&block, code->ext.omp_clauses, code->loc);
7426 : :
7427 : : // Extract depend clauses and create taskwait
7428 : 128 : tree depend_clauses = NULL_TREE;
7429 : 128 : tree *depend_clauses_ptr = &depend_clauses;
7430 : 333 : for (tree c = omp_clauses; c; c = OMP_CLAUSE_CHAIN (c))
7431 : : {
7432 : 205 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
7433 : : {
7434 : 8 : *depend_clauses_ptr = c;
7435 : 8 : depend_clauses_ptr = &OMP_CLAUSE_CHAIN (c);
7436 : : }
7437 : : }
7438 : 128 : if (depend_clauses != NULL_TREE)
7439 : : {
7440 : 4 : tree stmt = make_node (OMP_TASK);
7441 : 4 : TREE_TYPE (stmt) = void_node;
7442 : 4 : OMP_TASK_CLAUSES (stmt) = depend_clauses;
7443 : 4 : OMP_TASK_BODY (stmt) = NULL_TREE;
7444 : 4 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7445 : 4 : gfc_add_expr_to_block (&block, stmt);
7446 : : }
7447 : :
7448 : 128 : tree stmt = make_node (OMP_DISPATCH);
7449 : 128 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7450 : 128 : TREE_TYPE (stmt) = void_type_node;
7451 : 128 : OMP_DISPATCH_BODY (stmt) = body;
7452 : 128 : OMP_DISPATCH_CLAUSES (stmt) = omp_clauses;
7453 : :
7454 : 128 : gfc_add_expr_to_block (&block, stmt);
7455 : 128 : return gfc_finish_block (&block);
7456 : : }
7457 : :
7458 : : static tree
7459 : 29 : gfc_trans_omp_error (gfc_code *code)
7460 : : {
7461 : 29 : stmtblock_t block;
7462 : 29 : gfc_se se;
7463 : 29 : tree len, message;
7464 : 29 : bool fatal = code->ext.omp_clauses->severity == OMP_SEVERITY_FATAL;
7465 : 42 : tree fndecl = builtin_decl_explicit (fatal ? BUILT_IN_GOMP_ERROR
7466 : : : BUILT_IN_GOMP_WARNING);
7467 : 29 : gfc_start_block (&block);
7468 : 29 : gfc_init_se (&se, NULL );
7469 : 29 : if (!code->ext.omp_clauses->message)
7470 : : {
7471 : 3 : message = null_pointer_node;
7472 : 3 : len = build_int_cst (size_type_node, 0);
7473 : : }
7474 : : else
7475 : : {
7476 : 26 : gfc_conv_expr (&se, code->ext.omp_clauses->message);
7477 : 26 : message = se.expr;
7478 : 26 : if (!POINTER_TYPE_P (TREE_TYPE (message)))
7479 : : /* To ensure an ARRAY_TYPE is not passed as such. */
7480 : 17 : message = gfc_build_addr_expr (NULL, message);
7481 : 26 : len = se.string_length;
7482 : : }
7483 : 29 : gfc_add_block_to_block (&block, &se.pre);
7484 : 29 : gfc_add_expr_to_block (&block, build_call_expr_loc (input_location, fndecl,
7485 : : 2, message, len));
7486 : 29 : gfc_add_block_to_block (&block, &se.post);
7487 : 29 : return gfc_finish_block (&block);
7488 : : }
7489 : :
7490 : : static tree
7491 : 70 : gfc_trans_omp_flush (gfc_code *code)
7492 : : {
7493 : 70 : tree call;
7494 : 70 : if (!code->ext.omp_clauses
7495 : 4 : || code->ext.omp_clauses->memorder == OMP_MEMORDER_UNSET
7496 : 4 : || code->ext.omp_clauses->memorder == OMP_MEMORDER_SEQ_CST)
7497 : : {
7498 : 67 : call = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
7499 : 67 : call = build_call_expr_loc (input_location, call, 0);
7500 : : }
7501 : : else
7502 : : {
7503 : 3 : enum memmodel mo = MEMMODEL_LAST;
7504 : 3 : switch (code->ext.omp_clauses->memorder)
7505 : : {
7506 : : case OMP_MEMORDER_ACQ_REL: mo = MEMMODEL_ACQ_REL; break;
7507 : : case OMP_MEMORDER_RELEASE: mo = MEMMODEL_RELEASE; break;
7508 : : case OMP_MEMORDER_ACQUIRE: mo = MEMMODEL_ACQUIRE; break;
7509 : 0 : default: gcc_unreachable (); break;
7510 : : }
7511 : 3 : call = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
7512 : 3 : call = build_call_expr_loc (input_location, call, 1,
7513 : 3 : build_int_cst (integer_type_node, mo));
7514 : : }
7515 : 70 : return call;
7516 : : }
7517 : :
7518 : : static tree
7519 : 115 : gfc_trans_omp_master (gfc_code *code)
7520 : : {
7521 : 115 : tree stmt = gfc_trans_code (code->block->next);
7522 : 115 : if (IS_EMPTY_STMT (stmt))
7523 : : return stmt;
7524 : 109 : return build1_v (OMP_MASTER, stmt);
7525 : : }
7526 : :
7527 : : static tree
7528 : 49 : gfc_trans_omp_masked (gfc_code *code, gfc_omp_clauses *clauses)
7529 : : {
7530 : 49 : stmtblock_t block;
7531 : 49 : tree body = gfc_trans_code (code->block->next);
7532 : 49 : if (IS_EMPTY_STMT (body))
7533 : : return body;
7534 : 40 : if (!clauses)
7535 : 33 : clauses = code->ext.omp_clauses;
7536 : 40 : gfc_start_block (&block);
7537 : 40 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
7538 : 40 : tree stmt = make_node (OMP_MASKED);
7539 : 40 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
7540 : 40 : TREE_TYPE (stmt) = void_type_node;
7541 : 40 : OMP_MASKED_BODY (stmt) = body;
7542 : 40 : OMP_MASKED_CLAUSES (stmt) = omp_clauses;
7543 : 40 : gfc_add_expr_to_block (&block, stmt);
7544 : 40 : return gfc_finish_block (&block);
7545 : : }
7546 : :
7547 : :
7548 : : static tree
7549 : 519 : gfc_trans_omp_ordered (gfc_code *code)
7550 : : {
7551 : 519 : if (!flag_openmp)
7552 : : {
7553 : 5 : if (!code->ext.omp_clauses->simd)
7554 : 3 : return gfc_trans_code (code->block ? code->block->next : NULL);
7555 : 2 : code->ext.omp_clauses->threads = 0;
7556 : : }
7557 : 516 : tree omp_clauses = gfc_trans_omp_clauses (NULL, code->ext.omp_clauses,
7558 : : code->loc);
7559 : 516 : return build2_loc (input_location, OMP_ORDERED, void_type_node,
7560 : 516 : code->block ? gfc_trans_code (code->block->next)
7561 : 516 : : NULL_TREE, omp_clauses);
7562 : : }
7563 : :
7564 : : static tree
7565 : 1858 : gfc_trans_omp_parallel (gfc_code *code)
7566 : : {
7567 : 1858 : stmtblock_t block;
7568 : 1858 : tree stmt, omp_clauses;
7569 : :
7570 : 1858 : gfc_start_block (&block);
7571 : 1858 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
7572 : : code->loc);
7573 : 1858 : pushlevel ();
7574 : 1858 : stmt = gfc_trans_omp_code (code->block->next, true);
7575 : 1858 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
7576 : 1858 : stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
7577 : : omp_clauses);
7578 : 1858 : gfc_add_expr_to_block (&block, stmt);
7579 : 1858 : return gfc_finish_block (&block);
7580 : : }
7581 : :
7582 : : enum
7583 : : {
7584 : : GFC_OMP_SPLIT_SIMD,
7585 : : GFC_OMP_SPLIT_DO,
7586 : : GFC_OMP_SPLIT_PARALLEL,
7587 : : GFC_OMP_SPLIT_DISTRIBUTE,
7588 : : GFC_OMP_SPLIT_TEAMS,
7589 : : GFC_OMP_SPLIT_TARGET,
7590 : : GFC_OMP_SPLIT_TASKLOOP,
7591 : : GFC_OMP_SPLIT_MASKED,
7592 : : GFC_OMP_SPLIT_NUM
7593 : : };
7594 : :
7595 : : enum
7596 : : {
7597 : : GFC_OMP_MASK_SIMD = (1 << GFC_OMP_SPLIT_SIMD),
7598 : : GFC_OMP_MASK_DO = (1 << GFC_OMP_SPLIT_DO),
7599 : : GFC_OMP_MASK_PARALLEL = (1 << GFC_OMP_SPLIT_PARALLEL),
7600 : : GFC_OMP_MASK_DISTRIBUTE = (1 << GFC_OMP_SPLIT_DISTRIBUTE),
7601 : : GFC_OMP_MASK_TEAMS = (1 << GFC_OMP_SPLIT_TEAMS),
7602 : : GFC_OMP_MASK_TARGET = (1 << GFC_OMP_SPLIT_TARGET),
7603 : : GFC_OMP_MASK_TASKLOOP = (1 << GFC_OMP_SPLIT_TASKLOOP),
7604 : : GFC_OMP_MASK_MASKED = (1 << GFC_OMP_SPLIT_MASKED)
7605 : : };
7606 : :
7607 : : /* If a var is in lastprivate/firstprivate/reduction but not in a
7608 : : data mapping/sharing clause, add it to 'map(tofrom:' if is_target
7609 : : and to 'shared' otherwise. */
7610 : : static void
7611 : 2513 : gfc_add_clause_implicitly (gfc_omp_clauses *clauses_out,
7612 : : gfc_omp_clauses *clauses_in,
7613 : : bool is_target, bool is_parallel_do)
7614 : : {
7615 : 2513 : int clauselist_to_add = is_target ? OMP_LIST_MAP : OMP_LIST_SHARED;
7616 : 2513 : gfc_omp_namelist *tail = NULL;
7617 : 15078 : for (int i = 0; i < 5; ++i)
7618 : : {
7619 : 12565 : gfc_omp_namelist *n;
7620 : 12565 : switch (i)
7621 : : {
7622 : 2513 : case 0: n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE]; break;
7623 : 2513 : case 1: n = clauses_in->lists[OMP_LIST_LASTPRIVATE]; break;
7624 : 2513 : case 2: n = clauses_in->lists[OMP_LIST_REDUCTION]; break;
7625 : 2513 : case 3: n = clauses_in->lists[OMP_LIST_REDUCTION_INSCAN]; break;
7626 : 2513 : case 4: n = clauses_in->lists[OMP_LIST_REDUCTION_TASK]; break;
7627 : : default: gcc_unreachable ();
7628 : : }
7629 : 15901 : for (; n != NULL; n = n->next)
7630 : : {
7631 : : gfc_omp_namelist *n2, **n_firstp = NULL, **n_lastp = NULL;
7632 : 20657 : for (int j = 0; j < 6; ++j)
7633 : : {
7634 : 18188 : gfc_omp_namelist **n2ref = NULL, *prev2 = NULL;
7635 : 18188 : switch (j)
7636 : : {
7637 : 3336 : case 0:
7638 : 3336 : n2ref = &clauses_out->lists[clauselist_to_add];
7639 : 3336 : break;
7640 : 3300 : case 1:
7641 : 3300 : n2ref = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
7642 : 3300 : break;
7643 : 3300 : case 2:
7644 : 3300 : if (is_target)
7645 : 255 : n2ref = &clauses_in->lists[OMP_LIST_LASTPRIVATE];
7646 : : else
7647 : 3045 : n2ref = &clauses_out->lists[OMP_LIST_LASTPRIVATE];
7648 : : break;
7649 : 3300 : case 3: n2ref = &clauses_out->lists[OMP_LIST_REDUCTION]; break;
7650 : 2476 : case 4:
7651 : 2476 : n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_INSCAN];
7652 : 2476 : break;
7653 : 2476 : case 5:
7654 : 2476 : n2ref = &clauses_out->lists[OMP_LIST_REDUCTION_TASK];
7655 : 2476 : break;
7656 : : default: gcc_unreachable ();
7657 : : }
7658 : 28462 : for (n2 = *n2ref; n2 != NULL; prev2 = n2, n2 = n2->next)
7659 : 13535 : if (n2->sym == n->sym)
7660 : : break;
7661 : 18188 : if (n2)
7662 : : {
7663 : 3261 : if (j == 0 /* clauselist_to_add */)
7664 : : break; /* Already present. */
7665 : 3225 : if (j == 1 /* OMP_LIST_FIRSTPRIVATE */)
7666 : : {
7667 : 1128 : n_firstp = prev2 ? &prev2->next : n2ref;
7668 : 1128 : continue;
7669 : : }
7670 : 2097 : if (j == 2 /* OMP_LIST_LASTPRIVATE */)
7671 : : {
7672 : 1266 : n_lastp = prev2 ? &prev2->next : n2ref;
7673 : 1266 : continue;
7674 : : }
7675 : : break;
7676 : : }
7677 : : }
7678 : 3336 : if (n_firstp && n_lastp)
7679 : : {
7680 : : /* For parallel do, GCC puts firstprivate/lastprivate
7681 : : on the parallel. */
7682 : 283 : if (is_parallel_do)
7683 : 280 : continue;
7684 : 3 : *n_firstp = (*n_firstp)->next;
7685 : 3 : if (!is_target)
7686 : 0 : *n_lastp = (*n_lastp)->next;
7687 : : }
7688 : 3053 : else if (is_target && n_lastp)
7689 : : ;
7690 : 2998 : else if (n2 || n_firstp || n_lastp)
7691 : 2640 : continue;
7692 : 416 : if (clauses_out->lists[clauselist_to_add]
7693 : 305 : && (clauses_out->lists[clauselist_to_add]
7694 : 305 : == clauses_in->lists[clauselist_to_add]))
7695 : : {
7696 : : gfc_omp_namelist *p = NULL;
7697 : 421 : for (n2 = clauses_in->lists[clauselist_to_add]; n2; n2 = n2->next)
7698 : : {
7699 : 273 : if (p)
7700 : : {
7701 : 125 : p->next = gfc_get_omp_namelist ();
7702 : 125 : p = p->next;
7703 : : }
7704 : : else
7705 : : {
7706 : 148 : p = gfc_get_omp_namelist ();
7707 : 148 : clauses_out->lists[clauselist_to_add] = p;
7708 : : }
7709 : 273 : *p = *n2;
7710 : : }
7711 : : }
7712 : 416 : if (!tail)
7713 : : {
7714 : 287 : tail = clauses_out->lists[clauselist_to_add];
7715 : 412 : for (; tail && tail->next; tail = tail->next)
7716 : : ;
7717 : : }
7718 : 416 : n2 = gfc_get_omp_namelist ();
7719 : 416 : n2->where = n->where;
7720 : 416 : n2->sym = n->sym;
7721 : 416 : if (is_target)
7722 : 119 : n2->u.map.op = OMP_MAP_TOFROM;
7723 : 416 : if (tail)
7724 : : {
7725 : 305 : tail->next = n2;
7726 : 305 : tail = n2;
7727 : : }
7728 : : else
7729 : 111 : clauses_out->lists[clauselist_to_add] = n2;
7730 : : }
7731 : : }
7732 : 2513 : }
7733 : :
7734 : : /* Kind of opposite to above, add firstprivate to CLAUSES_OUT if it is mapped
7735 : : in CLAUSES_IN's FIRSTPRIVATE list but not its MAP list. */
7736 : :
7737 : : static void
7738 : 336 : gfc_add_firstprivate_if_unmapped (gfc_omp_clauses *clauses_out,
7739 : : gfc_omp_clauses *clauses_in)
7740 : : {
7741 : 336 : gfc_omp_namelist *n = clauses_in->lists[OMP_LIST_FIRSTPRIVATE];
7742 : 336 : gfc_omp_namelist **tail = NULL;
7743 : :
7744 : 486 : for (; n != NULL; n = n->next)
7745 : : {
7746 : 150 : gfc_omp_namelist *n2 = clauses_out->lists[OMP_LIST_MAP];
7747 : 192 : for (; n2 != NULL; n2 = n2->next)
7748 : 53 : if (n->sym == n2->sym)
7749 : : break;
7750 : 150 : if (n2 == NULL)
7751 : : {
7752 : 139 : gfc_omp_namelist *dup = gfc_get_omp_namelist ();
7753 : 139 : *dup = *n;
7754 : 139 : dup->next = NULL;
7755 : 139 : if (!tail)
7756 : : {
7757 : 76 : tail = &clauses_out->lists[OMP_LIST_FIRSTPRIVATE];
7758 : 76 : while (*tail && (*tail)->next)
7759 : 0 : tail = &(*tail)->next;
7760 : : }
7761 : 139 : *tail = dup;
7762 : 139 : tail = &(*tail)->next;
7763 : : }
7764 : : }
7765 : 336 : }
7766 : :
7767 : : static void
7768 : 3990 : gfc_free_split_omp_clauses (gfc_code *code, gfc_omp_clauses *clausesa)
7769 : : {
7770 : 35910 : for (int i = 0; i < GFC_OMP_SPLIT_NUM; ++i)
7771 : 1244880 : for (int j = 0; j < OMP_LIST_NUM; ++j)
7772 : 1212960 : if (clausesa[i].lists[j] && clausesa[i].lists[j] != code->ext.omp_clauses->lists[j])
7773 : 1397 : for (gfc_omp_namelist *n = clausesa[i].lists[j]; n;)
7774 : : {
7775 : 956 : gfc_omp_namelist *p = n;
7776 : 956 : n = n->next;
7777 : 956 : free (p);
7778 : : }
7779 : 3990 : }
7780 : :
7781 : : static void
7782 : 3990 : gfc_split_omp_clauses (gfc_code *code,
7783 : : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM])
7784 : : {
7785 : 3990 : int mask = 0, innermost = 0;
7786 : 3990 : bool is_loop = false;
7787 : 3990 : memset (clausesa, 0, GFC_OMP_SPLIT_NUM * sizeof (gfc_omp_clauses));
7788 : 3990 : switch (code->op)
7789 : : {
7790 : : case EXEC_OMP_DISTRIBUTE:
7791 : : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7792 : : break;
7793 : 38 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
7794 : 38 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7795 : 38 : innermost = GFC_OMP_SPLIT_DO;
7796 : 38 : break;
7797 : 28 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
7798 : 28 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_PARALLEL
7799 : : | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7800 : 28 : innermost = GFC_OMP_SPLIT_SIMD;
7801 : 28 : break;
7802 : 47 : case EXEC_OMP_DISTRIBUTE_SIMD:
7803 : 47 : mask = GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7804 : 47 : innermost = GFC_OMP_SPLIT_SIMD;
7805 : 47 : break;
7806 : 0 : case EXEC_OMP_DO:
7807 : 0 : case EXEC_OMP_LOOP:
7808 : 0 : innermost = GFC_OMP_SPLIT_DO;
7809 : 0 : break;
7810 : 126 : case EXEC_OMP_DO_SIMD:
7811 : 126 : mask = GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7812 : 126 : innermost = GFC_OMP_SPLIT_SIMD;
7813 : 126 : break;
7814 : 0 : case EXEC_OMP_PARALLEL:
7815 : 0 : innermost = GFC_OMP_SPLIT_PARALLEL;
7816 : 0 : break;
7817 : 1101 : case EXEC_OMP_PARALLEL_DO:
7818 : 1101 : case EXEC_OMP_PARALLEL_LOOP:
7819 : 1101 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7820 : 1101 : innermost = GFC_OMP_SPLIT_DO;
7821 : 1101 : break;
7822 : 285 : case EXEC_OMP_PARALLEL_DO_SIMD:
7823 : 285 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7824 : 285 : innermost = GFC_OMP_SPLIT_SIMD;
7825 : 285 : break;
7826 : 11 : case EXEC_OMP_PARALLEL_MASKED:
7827 : 11 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED;
7828 : 11 : innermost = GFC_OMP_SPLIT_MASKED;
7829 : 11 : break;
7830 : 14 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
7831 : 14 : mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
7832 : : | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
7833 : 14 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7834 : 14 : break;
7835 : 20 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
7836 : 20 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7837 : 20 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7838 : 20 : break;
7839 : 24 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
7840 : 24 : mask = (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_MASKED
7841 : : | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD);
7842 : 24 : innermost = GFC_OMP_SPLIT_SIMD;
7843 : 24 : break;
7844 : 28 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
7845 : 28 : mask = GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7846 : 28 : innermost = GFC_OMP_SPLIT_SIMD;
7847 : 28 : break;
7848 : 0 : case EXEC_OMP_SIMD:
7849 : 0 : innermost = GFC_OMP_SPLIT_SIMD;
7850 : 0 : break;
7851 : 1587 : case EXEC_OMP_TARGET:
7852 : 1587 : innermost = GFC_OMP_SPLIT_TARGET;
7853 : 1587 : break;
7854 : 20 : case EXEC_OMP_TARGET_PARALLEL:
7855 : 20 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL;
7856 : 20 : innermost = GFC_OMP_SPLIT_PARALLEL;
7857 : 20 : break;
7858 : 79 : case EXEC_OMP_TARGET_PARALLEL_DO:
7859 : 79 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
7860 : 79 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7861 : 79 : innermost = GFC_OMP_SPLIT_DO;
7862 : 79 : break;
7863 : 15 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
7864 : 15 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO
7865 : : | GFC_OMP_MASK_SIMD;
7866 : 15 : innermost = GFC_OMP_SPLIT_SIMD;
7867 : 15 : break;
7868 : 26 : case EXEC_OMP_TARGET_SIMD:
7869 : 26 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_SIMD;
7870 : 26 : innermost = GFC_OMP_SPLIT_SIMD;
7871 : 26 : break;
7872 : 69 : case EXEC_OMP_TARGET_TEAMS:
7873 : 69 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS;
7874 : 69 : innermost = GFC_OMP_SPLIT_TEAMS;
7875 : 69 : break;
7876 : 14 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
7877 : 14 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
7878 : : | GFC_OMP_MASK_DISTRIBUTE;
7879 : 14 : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7880 : 14 : break;
7881 : 56 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
7882 : 56 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7883 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7884 : 56 : innermost = GFC_OMP_SPLIT_DO;
7885 : 56 : break;
7886 : 29 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
7887 : 29 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7888 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7889 : 29 : innermost = GFC_OMP_SPLIT_SIMD;
7890 : 29 : break;
7891 : 16 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
7892 : 16 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS
7893 : : | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7894 : 16 : innermost = GFC_OMP_SPLIT_SIMD;
7895 : 16 : break;
7896 : 12 : case EXEC_OMP_TARGET_TEAMS_LOOP:
7897 : 12 : mask = GFC_OMP_MASK_TARGET | GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
7898 : 12 : innermost = GFC_OMP_SPLIT_DO;
7899 : 12 : break;
7900 : 8 : case EXEC_OMP_MASKED_TASKLOOP:
7901 : 8 : mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP;
7902 : 8 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7903 : 8 : break;
7904 : 0 : case EXEC_OMP_MASTER_TASKLOOP:
7905 : 0 : case EXEC_OMP_TASKLOOP:
7906 : 0 : innermost = GFC_OMP_SPLIT_TASKLOOP;
7907 : 0 : break;
7908 : 22 : case EXEC_OMP_MASKED_TASKLOOP_SIMD:
7909 : 22 : mask = GFC_OMP_MASK_MASKED | GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7910 : 22 : innermost = GFC_OMP_SPLIT_SIMD;
7911 : 22 : break;
7912 : 46 : case EXEC_OMP_MASTER_TASKLOOP_SIMD:
7913 : 46 : case EXEC_OMP_TASKLOOP_SIMD:
7914 : 46 : mask = GFC_OMP_MASK_TASKLOOP | GFC_OMP_MASK_SIMD;
7915 : 46 : innermost = GFC_OMP_SPLIT_SIMD;
7916 : 46 : break;
7917 : 124 : case EXEC_OMP_TEAMS:
7918 : 124 : innermost = GFC_OMP_SPLIT_TEAMS;
7919 : 124 : break;
7920 : 14 : case EXEC_OMP_TEAMS_DISTRIBUTE:
7921 : 14 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE;
7922 : 14 : innermost = GFC_OMP_SPLIT_DISTRIBUTE;
7923 : 14 : break;
7924 : 32 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
7925 : 32 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7926 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO;
7927 : 32 : innermost = GFC_OMP_SPLIT_DO;
7928 : 32 : break;
7929 : 56 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
7930 : 56 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE
7931 : : | GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO | GFC_OMP_MASK_SIMD;
7932 : 56 : innermost = GFC_OMP_SPLIT_SIMD;
7933 : 56 : break;
7934 : 37 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
7935 : 37 : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DISTRIBUTE | GFC_OMP_MASK_SIMD;
7936 : 37 : innermost = GFC_OMP_SPLIT_SIMD;
7937 : 37 : break;
7938 : : case EXEC_OMP_TEAMS_LOOP:
7939 : : mask = GFC_OMP_MASK_TEAMS | GFC_OMP_MASK_DO;
7940 : : innermost = GFC_OMP_SPLIT_DO;
7941 : : break;
7942 : 0 : default:
7943 : 0 : gcc_unreachable ();
7944 : : }
7945 : 3984 : if (mask == 0)
7946 : : {
7947 : 1711 : clausesa[innermost] = *code->ext.omp_clauses;
7948 : 1711 : return;
7949 : : }
7950 : : /* Loops are similar to DO but still a bit different. */
7951 : 2279 : switch (code->op)
7952 : : {
7953 : 53 : case EXEC_OMP_LOOP:
7954 : 53 : case EXEC_OMP_PARALLEL_LOOP:
7955 : 53 : case EXEC_OMP_TEAMS_LOOP:
7956 : 53 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
7957 : 53 : case EXEC_OMP_TARGET_TEAMS_LOOP:
7958 : 53 : is_loop = true;
7959 : 2279 : default:
7960 : 2279 : break;
7961 : : }
7962 : 2279 : if (code->ext.omp_clauses != NULL)
7963 : : {
7964 : 2279 : if (mask & GFC_OMP_MASK_TARGET)
7965 : : {
7966 : : /* First the clauses that are unique to some constructs. */
7967 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_MAP]
7968 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_MAP];
7969 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IS_DEVICE_PTR]
7970 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_IS_DEVICE_PTR];
7971 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_HAS_DEVICE_ADDR]
7972 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_HAS_DEVICE_ADDR];
7973 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].device
7974 : 336 : = code->ext.omp_clauses->device;
7975 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].thread_limit
7976 : 336 : = code->ext.omp_clauses->thread_limit;
7977 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_USES_ALLOCATORS]
7978 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_USES_ALLOCATORS];
7979 : 2352 : for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++)
7980 : 2016 : clausesa[GFC_OMP_SPLIT_TARGET].defaultmap[i]
7981 : 2016 : = code->ext.omp_clauses->defaultmap[i];
7982 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].if_exprs[OMP_IF_TARGET]
7983 : 336 : = code->ext.omp_clauses->if_exprs[OMP_IF_TARGET];
7984 : : /* And this is copied to all. */
7985 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].if_expr
7986 : 336 : = code->ext.omp_clauses->if_expr;
7987 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].nowait
7988 : 336 : = code->ext.omp_clauses->nowait;
7989 : : }
7990 : 2279 : if (mask & GFC_OMP_MASK_TEAMS)
7991 : : {
7992 : : /* First the clauses that are unique to some constructs. */
7993 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower
7994 : 341 : = code->ext.omp_clauses->num_teams_lower;
7995 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
7996 : 341 : = code->ext.omp_clauses->num_teams_upper;
7997 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit
7998 : 341 : = code->ext.omp_clauses->thread_limit;
7999 : : /* Shared and default clauses are allowed on parallel, teams
8000 : : and taskloop. */
8001 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_SHARED]
8002 : 341 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8003 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].default_sharing
8004 : 341 : = code->ext.omp_clauses->default_sharing;
8005 : : }
8006 : 2279 : if (mask & GFC_OMP_MASK_DISTRIBUTE)
8007 : : {
8008 : : /* First the clauses that are unique to some constructs. */
8009 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_sched_kind
8010 : 367 : = code->ext.omp_clauses->dist_sched_kind;
8011 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].dist_chunk_size
8012 : 367 : = code->ext.omp_clauses->dist_chunk_size;
8013 : : /* Duplicate collapse. */
8014 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].collapse
8015 : 367 : = code->ext.omp_clauses->collapse;
8016 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_concurrent
8017 : 367 : = code->ext.omp_clauses->order_concurrent;
8018 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_unconstrained
8019 : 367 : = code->ext.omp_clauses->order_unconstrained;
8020 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].order_reproducible
8021 : 367 : = code->ext.omp_clauses->order_reproducible;
8022 : : }
8023 : 2279 : if (mask & GFC_OMP_MASK_PARALLEL)
8024 : : {
8025 : : /* First the clauses that are unique to some constructs. */
8026 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_COPYIN]
8027 : 1836 : = code->ext.omp_clauses->lists[OMP_LIST_COPYIN];
8028 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].num_threads
8029 : 1836 : = code->ext.omp_clauses->num_threads;
8030 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].proc_bind
8031 : 1836 : = code->ext.omp_clauses->proc_bind;
8032 : : /* Shared and default clauses are allowed on parallel, teams
8033 : : and taskloop. */
8034 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_SHARED]
8035 : 1836 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8036 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].default_sharing
8037 : 1836 : = code->ext.omp_clauses->default_sharing;
8038 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].if_exprs[OMP_IF_PARALLEL]
8039 : 1836 : = code->ext.omp_clauses->if_exprs[OMP_IF_PARALLEL];
8040 : : /* And this is copied to all. */
8041 : 1836 : clausesa[GFC_OMP_SPLIT_PARALLEL].if_expr
8042 : 1836 : = code->ext.omp_clauses->if_expr;
8043 : : }
8044 : 2279 : if (mask & GFC_OMP_MASK_MASKED)
8045 : 79 : clausesa[GFC_OMP_SPLIT_MASKED].filter = code->ext.omp_clauses->filter;
8046 : 2279 : if ((mask & GFC_OMP_MASK_DO) && !is_loop)
8047 : : {
8048 : : /* First the clauses that are unique to some constructs. */
8049 : 1810 : clausesa[GFC_OMP_SPLIT_DO].ordered
8050 : 1810 : = code->ext.omp_clauses->ordered;
8051 : 1810 : clausesa[GFC_OMP_SPLIT_DO].orderedc
8052 : 1810 : = code->ext.omp_clauses->orderedc;
8053 : 1810 : clausesa[GFC_OMP_SPLIT_DO].sched_kind
8054 : 1810 : = code->ext.omp_clauses->sched_kind;
8055 : 1810 : if (innermost == GFC_OMP_SPLIT_SIMD)
8056 : 539 : clausesa[GFC_OMP_SPLIT_DO].sched_simd
8057 : 539 : = code->ext.omp_clauses->sched_simd;
8058 : 1810 : clausesa[GFC_OMP_SPLIT_DO].sched_monotonic
8059 : 1810 : = code->ext.omp_clauses->sched_monotonic;
8060 : 1810 : clausesa[GFC_OMP_SPLIT_DO].sched_nonmonotonic
8061 : 1810 : = code->ext.omp_clauses->sched_nonmonotonic;
8062 : 1810 : clausesa[GFC_OMP_SPLIT_DO].chunk_size
8063 : 1810 : = code->ext.omp_clauses->chunk_size;
8064 : 1810 : clausesa[GFC_OMP_SPLIT_DO].nowait
8065 : 1810 : = code->ext.omp_clauses->nowait;
8066 : : }
8067 : 1863 : if (mask & GFC_OMP_MASK_DO)
8068 : : {
8069 : 1863 : clausesa[GFC_OMP_SPLIT_DO].bind
8070 : 1863 : = code->ext.omp_clauses->bind;
8071 : : /* Duplicate collapse. */
8072 : 1863 : clausesa[GFC_OMP_SPLIT_DO].collapse
8073 : 1863 : = code->ext.omp_clauses->collapse;
8074 : 1863 : clausesa[GFC_OMP_SPLIT_DO].order_concurrent
8075 : 1863 : = code->ext.omp_clauses->order_concurrent;
8076 : 1863 : clausesa[GFC_OMP_SPLIT_DO].order_unconstrained
8077 : 1863 : = code->ext.omp_clauses->order_unconstrained;
8078 : 1863 : clausesa[GFC_OMP_SPLIT_DO].order_reproducible
8079 : 1863 : = code->ext.omp_clauses->order_reproducible;
8080 : : }
8081 : 2279 : if (mask & GFC_OMP_MASK_SIMD)
8082 : : {
8083 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].safelen_expr
8084 : 819 : = code->ext.omp_clauses->safelen_expr;
8085 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].simdlen_expr
8086 : 819 : = code->ext.omp_clauses->simdlen_expr;
8087 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_ALIGNED]
8088 : 819 : = code->ext.omp_clauses->lists[OMP_LIST_ALIGNED];
8089 : : /* Duplicate collapse. */
8090 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].collapse
8091 : 819 : = code->ext.omp_clauses->collapse;
8092 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].if_exprs[OMP_IF_SIMD]
8093 : 819 : = code->ext.omp_clauses->if_exprs[OMP_IF_SIMD];
8094 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_concurrent
8095 : 819 : = code->ext.omp_clauses->order_concurrent;
8096 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_unconstrained
8097 : 819 : = code->ext.omp_clauses->order_unconstrained;
8098 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].order_reproducible
8099 : 819 : = code->ext.omp_clauses->order_reproducible;
8100 : : /* And this is copied to all. */
8101 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].if_expr
8102 : 819 : = code->ext.omp_clauses->if_expr;
8103 : : }
8104 : 2279 : if (mask & GFC_OMP_MASK_TASKLOOP)
8105 : : {
8106 : : /* First the clauses that are unique to some constructs. */
8107 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].nogroup
8108 : 162 : = code->ext.omp_clauses->nogroup;
8109 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize
8110 : 162 : = code->ext.omp_clauses->grainsize;
8111 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].grainsize_strict
8112 : 162 : = code->ext.omp_clauses->grainsize_strict;
8113 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks
8114 : 162 : = code->ext.omp_clauses->num_tasks;
8115 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].num_tasks_strict
8116 : 162 : = code->ext.omp_clauses->num_tasks_strict;
8117 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].priority
8118 : 162 : = code->ext.omp_clauses->priority;
8119 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].final_expr
8120 : 162 : = code->ext.omp_clauses->final_expr;
8121 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].untied
8122 : 162 : = code->ext.omp_clauses->untied;
8123 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].mergeable
8124 : 162 : = code->ext.omp_clauses->mergeable;
8125 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].if_exprs[OMP_IF_TASKLOOP]
8126 : 162 : = code->ext.omp_clauses->if_exprs[OMP_IF_TASKLOOP];
8127 : : /* And this is copied to all. */
8128 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].if_expr
8129 : 162 : = code->ext.omp_clauses->if_expr;
8130 : : /* Shared and default clauses are allowed on parallel, teams
8131 : : and taskloop. */
8132 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_SHARED]
8133 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_SHARED];
8134 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].default_sharing
8135 : 162 : = code->ext.omp_clauses->default_sharing;
8136 : : /* Duplicate collapse. */
8137 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].collapse
8138 : 162 : = code->ext.omp_clauses->collapse;
8139 : : }
8140 : : /* Private clause is supported on all constructs but master/masked,
8141 : : it is enough to put it on the innermost one except for master/masked. For
8142 : : !$ omp parallel do put it on parallel though,
8143 : : as that's what we did for OpenMP 3.1. */
8144 : 2279 : clausesa[((innermost == GFC_OMP_SPLIT_DO && !is_loop)
8145 : : || code->op == EXEC_OMP_PARALLEL_MASTER
8146 : 1008 : || code->op == EXEC_OMP_PARALLEL_MASKED)
8147 : 997 : ? (int) GFC_OMP_SPLIT_PARALLEL
8148 : 3276 : : innermost].lists[OMP_LIST_PRIVATE]
8149 : 2279 : = code->ext.omp_clauses->lists[OMP_LIST_PRIVATE];
8150 : : /* Firstprivate clause is supported on all constructs but
8151 : : simd and masked/master. Put it on the outermost of those and duplicate
8152 : : on parallel and teams. */
8153 : 2279 : if (mask & GFC_OMP_MASK_TARGET)
8154 : 336 : gfc_add_firstprivate_if_unmapped (&clausesa[GFC_OMP_SPLIT_TARGET],
8155 : : code->ext.omp_clauses);
8156 : 2279 : if (mask & GFC_OMP_MASK_TEAMS)
8157 : 341 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[OMP_LIST_FIRSTPRIVATE]
8158 : 341 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8159 : 1938 : else if (mask & GFC_OMP_MASK_DISTRIBUTE)
8160 : 113 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_FIRSTPRIVATE]
8161 : 113 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8162 : 2279 : if (mask & GFC_OMP_MASK_TASKLOOP)
8163 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_FIRSTPRIVATE]
8164 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8165 : 2279 : if ((mask & GFC_OMP_MASK_PARALLEL)
8166 : : && !(mask & GFC_OMP_MASK_TASKLOOP))
8167 : 1750 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_FIRSTPRIVATE]
8168 : 1750 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8169 : 529 : else if ((mask & GFC_OMP_MASK_DO) && !is_loop)
8170 : 126 : clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_FIRSTPRIVATE]
8171 : 126 : = code->ext.omp_clauses->lists[OMP_LIST_FIRSTPRIVATE];
8172 : : /* Lastprivate is allowed on distribute, do, simd, taskloop and loop.
8173 : : In parallel do{, simd} we actually want to put it on
8174 : : parallel rather than do. */
8175 : 2279 : if (mask & GFC_OMP_MASK_DISTRIBUTE)
8176 : 367 : clausesa[GFC_OMP_SPLIT_DISTRIBUTE].lists[OMP_LIST_LASTPRIVATE]
8177 : 367 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8178 : 2279 : if (mask & GFC_OMP_MASK_TASKLOOP)
8179 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_LASTPRIVATE]
8180 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8181 : 2279 : if ((mask & GFC_OMP_MASK_PARALLEL) && !is_loop
8182 : 1801 : && !(mask & GFC_OMP_MASK_TASKLOOP))
8183 : 1715 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[OMP_LIST_LASTPRIVATE]
8184 : 1715 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8185 : 564 : else if (mask & GFC_OMP_MASK_DO)
8186 : 179 : clausesa[GFC_OMP_SPLIT_DO].lists[OMP_LIST_LASTPRIVATE]
8187 : 179 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8188 : 2279 : if (mask & GFC_OMP_MASK_SIMD)
8189 : 819 : clausesa[GFC_OMP_SPLIT_SIMD].lists[OMP_LIST_LASTPRIVATE]
8190 : 819 : = code->ext.omp_clauses->lists[OMP_LIST_LASTPRIVATE];
8191 : : /* Reduction is allowed on simd, do, parallel, teams, taskloop, and loop.
8192 : : Duplicate it on all of them, but
8193 : : - omit on do if parallel is present;
8194 : : - omit on task and parallel if loop is present;
8195 : : additionally, inscan applies to do/simd only. */
8196 : 9116 : for (int i = OMP_LIST_REDUCTION; i <= OMP_LIST_REDUCTION_TASK; i++)
8197 : : {
8198 : 6837 : if (mask & GFC_OMP_MASK_TASKLOOP
8199 : 486 : && i != OMP_LIST_REDUCTION_INSCAN)
8200 : 324 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[i]
8201 : 324 : = code->ext.omp_clauses->lists[i];
8202 : 6837 : if (mask & GFC_OMP_MASK_TEAMS
8203 : 1023 : && i != OMP_LIST_REDUCTION_INSCAN
8204 : 1023 : && !is_loop)
8205 : 646 : clausesa[GFC_OMP_SPLIT_TEAMS].lists[i]
8206 : 646 : = code->ext.omp_clauses->lists[i];
8207 : 6837 : if (mask & GFC_OMP_MASK_PARALLEL
8208 : 5508 : && i != OMP_LIST_REDUCTION_INSCAN
8209 : 3672 : && !(mask & GFC_OMP_MASK_TASKLOOP)
8210 : 3500 : && !is_loop)
8211 : 3430 : clausesa[GFC_OMP_SPLIT_PARALLEL].lists[i]
8212 : 3430 : = code->ext.omp_clauses->lists[i];
8213 : 3407 : else if (mask & GFC_OMP_MASK_DO)
8214 : 2221 : clausesa[GFC_OMP_SPLIT_DO].lists[i]
8215 : 2221 : = code->ext.omp_clauses->lists[i];
8216 : 6837 : if (mask & GFC_OMP_MASK_SIMD)
8217 : 2457 : clausesa[GFC_OMP_SPLIT_SIMD].lists[i]
8218 : 2457 : = code->ext.omp_clauses->lists[i];
8219 : : }
8220 : 2279 : if (mask & GFC_OMP_MASK_TARGET)
8221 : 336 : clausesa[GFC_OMP_SPLIT_TARGET].lists[OMP_LIST_IN_REDUCTION]
8222 : 336 : = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
8223 : 2279 : if (mask & GFC_OMP_MASK_TASKLOOP)
8224 : 162 : clausesa[GFC_OMP_SPLIT_TASKLOOP].lists[OMP_LIST_IN_REDUCTION]
8225 : 162 : = code->ext.omp_clauses->lists[OMP_LIST_IN_REDUCTION];
8226 : : /* Linear clause is supported on do and simd,
8227 : : put it on the innermost one. */
8228 : 2279 : clausesa[innermost].lists[OMP_LIST_LINEAR]
8229 : 2279 : = code->ext.omp_clauses->lists[OMP_LIST_LINEAR];
8230 : : }
8231 : : /* Propagate firstprivate/lastprivate/reduction vars to
8232 : : shared (parallel, teams) and map-tofrom (target). */
8233 : 2279 : if (mask & GFC_OMP_MASK_TARGET)
8234 : 336 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TARGET],
8235 : : code->ext.omp_clauses, true, false);
8236 : 2279 : if ((mask & GFC_OMP_MASK_PARALLEL) && innermost != GFC_OMP_MASK_PARALLEL)
8237 : 1836 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_PARALLEL],
8238 : : code->ext.omp_clauses, false,
8239 : 1836 : mask & GFC_OMP_MASK_DO);
8240 : 2279 : if (mask & GFC_OMP_MASK_TEAMS && innermost != GFC_OMP_MASK_TEAMS)
8241 : 341 : gfc_add_clause_implicitly (&clausesa[GFC_OMP_SPLIT_TEAMS],
8242 : : code->ext.omp_clauses, false, false);
8243 : 2279 : if (((mask & (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
8244 : : == (GFC_OMP_MASK_PARALLEL | GFC_OMP_MASK_DO))
8245 : 1719 : && !is_loop)
8246 : 1684 : clausesa[GFC_OMP_SPLIT_DO].nowait = true;
8247 : :
8248 : : /* Distribute allocate clause to do, parallel, distribute, teams, target
8249 : : and taskloop. The code below iterates over variables in the
8250 : : allocate list and checks if that available is also in any
8251 : : privatization clause on those construct. If yes, then we add it
8252 : : to the list of 'allocate'ed variables for that construct. If a
8253 : : variable is found in none of them then we issue an error. */
8254 : :
8255 : 2279 : if (code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE])
8256 : : {
8257 : : gfc_omp_namelist *alloc_nl, *priv_nl;
8258 : : gfc_omp_namelist *tails[GFC_OMP_SPLIT_NUM];
8259 : 104 : for (alloc_nl = code->ext.omp_clauses->lists[OMP_LIST_ALLOCATE];
8260 : 181 : alloc_nl; alloc_nl = alloc_nl->next)
8261 : : {
8262 : : bool found = false;
8263 : 728 : for (int i = GFC_OMP_SPLIT_DO; i <= GFC_OMP_SPLIT_TASKLOOP; i++)
8264 : : {
8265 : : gfc_omp_namelist *p;
8266 : : int list;
8267 : 24336 : for (list = 0; list < OMP_LIST_NUM; list++)
8268 : : {
8269 : 23712 : switch (list)
8270 : : {
8271 : 5616 : case OMP_LIST_PRIVATE:
8272 : 5616 : case OMP_LIST_FIRSTPRIVATE:
8273 : 5616 : case OMP_LIST_LASTPRIVATE:
8274 : 5616 : case OMP_LIST_REDUCTION:
8275 : 5616 : case OMP_LIST_REDUCTION_INSCAN:
8276 : 5616 : case OMP_LIST_REDUCTION_TASK:
8277 : 5616 : case OMP_LIST_IN_REDUCTION:
8278 : 5616 : case OMP_LIST_TASK_REDUCTION:
8279 : 5616 : case OMP_LIST_LINEAR:
8280 : 6092 : for (priv_nl = clausesa[i].lists[list]; priv_nl;
8281 : 476 : priv_nl = priv_nl->next)
8282 : 476 : if (alloc_nl->sym == priv_nl->sym)
8283 : : {
8284 : 131 : found = true;
8285 : 131 : p = gfc_get_omp_namelist ();
8286 : 131 : p->sym = alloc_nl->sym;
8287 : 131 : p->expr = alloc_nl->expr;
8288 : 131 : p->u.align = alloc_nl->u.align;
8289 : 131 : p->u2.allocator = alloc_nl->u2.allocator;
8290 : 131 : p->where = alloc_nl->where;
8291 : 131 : if (clausesa[i].lists[OMP_LIST_ALLOCATE] == NULL)
8292 : : {
8293 : 109 : clausesa[i].lists[OMP_LIST_ALLOCATE] = p;
8294 : 109 : tails[i] = p;
8295 : : }
8296 : : else
8297 : : {
8298 : 22 : tails[i]->next = p;
8299 : 22 : tails[i] = tails[i]->next;
8300 : : }
8301 : : }
8302 : : break;
8303 : : default:
8304 : : break;
8305 : : }
8306 : : }
8307 : : }
8308 : 104 : if (!found)
8309 : 1 : gfc_error ("%qs specified in %<allocate%> clause at %L but not "
8310 : : "in an explicit privatization clause",
8311 : 1 : alloc_nl->sym->name, &alloc_nl->where);
8312 : : }
8313 : : }
8314 : : }
8315 : :
8316 : : static tree
8317 : 539 : gfc_trans_omp_do_simd (gfc_code *code, stmtblock_t *pblock,
8318 : : gfc_omp_clauses *clausesa, tree omp_clauses)
8319 : : {
8320 : 539 : stmtblock_t block;
8321 : 539 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8322 : 539 : tree stmt, body, omp_do_clauses = NULL_TREE;
8323 : 539 : bool free_clausesa = false;
8324 : :
8325 : 539 : if (pblock == NULL)
8326 : 411 : gfc_start_block (&block);
8327 : : else
8328 : 128 : gfc_init_block (&block);
8329 : :
8330 : 539 : if (clausesa == NULL)
8331 : : {
8332 : 126 : clausesa = clausesa_buf;
8333 : 126 : gfc_split_omp_clauses (code, clausesa);
8334 : 126 : free_clausesa = true;
8335 : : }
8336 : 539 : if (flag_openmp)
8337 : 534 : omp_do_clauses
8338 : 534 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DO], code->loc);
8339 : 667 : body = gfc_trans_omp_do (code, EXEC_OMP_SIMD, pblock ? pblock : &block,
8340 : : &clausesa[GFC_OMP_SPLIT_SIMD], omp_clauses);
8341 : 539 : if (pblock == NULL)
8342 : : {
8343 : 411 : if (TREE_CODE (body) != BIND_EXPR)
8344 : 411 : body = build3_v (BIND_EXPR, NULL, body, poplevel (1, 0));
8345 : : else
8346 : 0 : poplevel (0, 0);
8347 : : }
8348 : 128 : else if (TREE_CODE (body) != BIND_EXPR)
8349 : 128 : body = build3_v (BIND_EXPR, NULL, body, NULL_TREE);
8350 : 539 : if (flag_openmp)
8351 : : {
8352 : 534 : stmt = make_node (OMP_FOR);
8353 : 534 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8354 : 534 : TREE_TYPE (stmt) = void_type_node;
8355 : 534 : OMP_FOR_BODY (stmt) = body;
8356 : 534 : OMP_FOR_CLAUSES (stmt) = omp_do_clauses;
8357 : : }
8358 : : else
8359 : : stmt = body;
8360 : 539 : gfc_add_expr_to_block (&block, stmt);
8361 : 539 : if (free_clausesa)
8362 : 126 : gfc_free_split_omp_clauses (code, clausesa);
8363 : 539 : return gfc_finish_block (&block);
8364 : : }
8365 : :
8366 : : static tree
8367 : 1306 : gfc_trans_omp_parallel_do (gfc_code *code, bool is_loop, stmtblock_t *pblock,
8368 : : gfc_omp_clauses *clausesa)
8369 : : {
8370 : 1306 : stmtblock_t block, *new_pblock = pblock;
8371 : 1306 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8372 : 1306 : tree stmt, omp_clauses = NULL_TREE;
8373 : 1306 : bool free_clausesa = false;
8374 : :
8375 : 1306 : if (pblock == NULL)
8376 : 1101 : gfc_start_block (&block);
8377 : : else
8378 : 205 : gfc_init_block (&block);
8379 : :
8380 : 1306 : if (clausesa == NULL)
8381 : : {
8382 : 1101 : clausesa = clausesa_buf;
8383 : 1101 : gfc_split_omp_clauses (code, clausesa);
8384 : 1101 : free_clausesa = true;
8385 : : }
8386 : 1306 : omp_clauses
8387 : 1306 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8388 : : code->loc);
8389 : 1306 : if (pblock == NULL)
8390 : : {
8391 : 1101 : if (!clausesa[GFC_OMP_SPLIT_DO].ordered
8392 : 1092 : && clausesa[GFC_OMP_SPLIT_DO].sched_kind != OMP_SCHED_STATIC)
8393 : : new_pblock = █
8394 : : else
8395 : 65 : pushlevel ();
8396 : : }
8397 : 2577 : stmt = gfc_trans_omp_do (code, is_loop ? EXEC_OMP_LOOP : EXEC_OMP_DO,
8398 : : new_pblock, &clausesa[GFC_OMP_SPLIT_DO],
8399 : : omp_clauses);
8400 : 1306 : if (pblock == NULL)
8401 : : {
8402 : 1101 : if (TREE_CODE (stmt) != BIND_EXPR)
8403 : 1085 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8404 : : else
8405 : 16 : poplevel (0, 0);
8406 : : }
8407 : 205 : else if (TREE_CODE (stmt) != BIND_EXPR)
8408 : 205 : stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
8409 : 1306 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8410 : : void_type_node, stmt, omp_clauses);
8411 : 1306 : OMP_PARALLEL_COMBINED (stmt) = 1;
8412 : 1306 : gfc_add_expr_to_block (&block, stmt);
8413 : 1306 : if (free_clausesa)
8414 : 1101 : gfc_free_split_omp_clauses (code, clausesa);
8415 : 1306 : return gfc_finish_block (&block);
8416 : : }
8417 : :
8418 : : static tree
8419 : 413 : gfc_trans_omp_parallel_do_simd (gfc_code *code, stmtblock_t *pblock,
8420 : : gfc_omp_clauses *clausesa)
8421 : : {
8422 : 413 : stmtblock_t block;
8423 : 413 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8424 : 413 : tree stmt, omp_clauses = NULL_TREE;
8425 : 413 : bool free_clausesa = false;
8426 : :
8427 : 413 : if (pblock == NULL)
8428 : 285 : gfc_start_block (&block);
8429 : : else
8430 : 128 : gfc_init_block (&block);
8431 : :
8432 : 413 : if (clausesa == NULL)
8433 : : {
8434 : 285 : clausesa = clausesa_buf;
8435 : 285 : gfc_split_omp_clauses (code, clausesa);
8436 : 285 : free_clausesa = true;
8437 : : }
8438 : 413 : if (flag_openmp)
8439 : 410 : omp_clauses
8440 : 410 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8441 : : code->loc);
8442 : 413 : if (pblock == NULL)
8443 : 285 : pushlevel ();
8444 : 413 : stmt = gfc_trans_omp_do_simd (code, pblock, clausesa, omp_clauses);
8445 : 413 : if (pblock == NULL)
8446 : : {
8447 : 285 : if (TREE_CODE (stmt) != BIND_EXPR)
8448 : 214 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8449 : : else
8450 : 71 : poplevel (0, 0);
8451 : : }
8452 : 128 : else if (TREE_CODE (stmt) != BIND_EXPR)
8453 : 128 : stmt = build3_v (BIND_EXPR, NULL, stmt, NULL_TREE);
8454 : 413 : if (flag_openmp)
8455 : : {
8456 : 410 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8457 : : void_type_node, stmt, omp_clauses);
8458 : 410 : OMP_PARALLEL_COMBINED (stmt) = 1;
8459 : : }
8460 : 413 : gfc_add_expr_to_block (&block, stmt);
8461 : 413 : if (free_clausesa)
8462 : 285 : gfc_free_split_omp_clauses (code, clausesa);
8463 : 413 : return gfc_finish_block (&block);
8464 : : }
8465 : :
8466 : : static tree
8467 : 54 : gfc_trans_omp_parallel_sections (gfc_code *code)
8468 : : {
8469 : 54 : stmtblock_t block;
8470 : 54 : gfc_omp_clauses section_clauses;
8471 : 54 : tree stmt, omp_clauses;
8472 : :
8473 : 54 : memset (§ion_clauses, 0, sizeof (section_clauses));
8474 : 54 : section_clauses.nowait = true;
8475 : :
8476 : 54 : gfc_start_block (&block);
8477 : 54 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8478 : : code->loc);
8479 : 54 : pushlevel ();
8480 : 54 : stmt = gfc_trans_omp_sections (code, §ion_clauses);
8481 : 54 : if (TREE_CODE (stmt) != BIND_EXPR)
8482 : 54 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8483 : : else
8484 : 0 : poplevel (0, 0);
8485 : 54 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8486 : : void_type_node, stmt, omp_clauses);
8487 : 54 : OMP_PARALLEL_COMBINED (stmt) = 1;
8488 : 54 : gfc_add_expr_to_block (&block, stmt);
8489 : 54 : return gfc_finish_block (&block);
8490 : : }
8491 : :
8492 : : static tree
8493 : 50 : gfc_trans_omp_parallel_workshare (gfc_code *code)
8494 : : {
8495 : 50 : stmtblock_t block;
8496 : 50 : gfc_omp_clauses workshare_clauses;
8497 : 50 : tree stmt, omp_clauses;
8498 : :
8499 : 50 : memset (&workshare_clauses, 0, sizeof (workshare_clauses));
8500 : 50 : workshare_clauses.nowait = true;
8501 : :
8502 : 50 : gfc_start_block (&block);
8503 : 50 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8504 : : code->loc);
8505 : 50 : pushlevel ();
8506 : 50 : stmt = gfc_trans_omp_workshare (code, &workshare_clauses);
8507 : 50 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8508 : 50 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
8509 : : void_type_node, stmt, omp_clauses);
8510 : 50 : OMP_PARALLEL_COMBINED (stmt) = 1;
8511 : 50 : gfc_add_expr_to_block (&block, stmt);
8512 : 50 : return gfc_finish_block (&block);
8513 : : }
8514 : :
8515 : : static tree
8516 : 53 : gfc_trans_omp_scope (gfc_code *code)
8517 : : {
8518 : 53 : stmtblock_t block;
8519 : 53 : tree body = gfc_trans_code (code->block->next);
8520 : 53 : if (IS_EMPTY_STMT (body))
8521 : : return body;
8522 : 51 : gfc_start_block (&block);
8523 : 51 : tree omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8524 : : code->loc);
8525 : 51 : tree stmt = make_node (OMP_SCOPE);
8526 : 51 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8527 : 51 : TREE_TYPE (stmt) = void_type_node;
8528 : 51 : OMP_SCOPE_BODY (stmt) = body;
8529 : 51 : OMP_SCOPE_CLAUSES (stmt) = omp_clauses;
8530 : 51 : gfc_add_expr_to_block (&block, stmt);
8531 : 51 : return gfc_finish_block (&block);
8532 : : }
8533 : :
8534 : : static tree
8535 : 129 : gfc_trans_omp_sections (gfc_code *code, gfc_omp_clauses *clauses)
8536 : : {
8537 : 129 : stmtblock_t block, body;
8538 : 129 : tree omp_clauses, stmt;
8539 : 129 : bool has_lastprivate = clauses->lists[OMP_LIST_LASTPRIVATE] != NULL;
8540 : 129 : location_t loc = gfc_get_location (&code->loc);
8541 : :
8542 : 129 : gfc_start_block (&block);
8543 : :
8544 : 129 : omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
8545 : :
8546 : 129 : gfc_init_block (&body);
8547 : 499 : for (code = code->block; code; code = code->block)
8548 : : {
8549 : : /* Last section is special because of lastprivate, so even if it
8550 : : is empty, chain it in. */
8551 : 370 : stmt = gfc_trans_omp_code (code->next,
8552 : 370 : has_lastprivate && code->block == NULL);
8553 : 370 : if (! IS_EMPTY_STMT (stmt))
8554 : : {
8555 : 280 : stmt = build1_v (OMP_SECTION, stmt);
8556 : 280 : gfc_add_expr_to_block (&body, stmt);
8557 : : }
8558 : : }
8559 : 129 : stmt = gfc_finish_block (&body);
8560 : :
8561 : 129 : stmt = build2_loc (loc, OMP_SECTIONS, void_type_node, stmt, omp_clauses);
8562 : 129 : gfc_add_expr_to_block (&block, stmt);
8563 : :
8564 : 129 : return gfc_finish_block (&block);
8565 : : }
8566 : :
8567 : : static tree
8568 : 555 : gfc_trans_omp_single (gfc_code *code, gfc_omp_clauses *clauses)
8569 : : {
8570 : 555 : stmtblock_t block;
8571 : 555 : gfc_start_block (&block);
8572 : 555 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
8573 : 555 : tree stmt = gfc_trans_omp_code (code->block->next, true);
8574 : 555 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_SINGLE, void_type_node,
8575 : : stmt, omp_clauses);
8576 : 555 : gfc_add_expr_to_block (&block, stmt);
8577 : 555 : return gfc_finish_block (&block);
8578 : : }
8579 : :
8580 : : static tree
8581 : 1121 : gfc_trans_omp_task (gfc_code *code)
8582 : : {
8583 : 1121 : stmtblock_t block;
8584 : 1121 : tree stmt, omp_clauses;
8585 : :
8586 : 1121 : gfc_start_block (&block);
8587 : 1121 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
8588 : : code->loc);
8589 : 1121 : pushlevel ();
8590 : 1121 : stmt = gfc_trans_omp_code (code->block->next, true);
8591 : 1121 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8592 : 1121 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TASK, void_type_node,
8593 : : stmt, omp_clauses);
8594 : 1121 : gfc_add_expr_to_block (&block, stmt);
8595 : 1121 : return gfc_finish_block (&block);
8596 : : }
8597 : :
8598 : : static tree
8599 : 181 : gfc_trans_omp_taskgroup (gfc_code *code)
8600 : : {
8601 : 181 : stmtblock_t block;
8602 : 181 : gfc_start_block (&block);
8603 : 181 : tree body = gfc_trans_code (code->block->next);
8604 : 181 : tree stmt = make_node (OMP_TASKGROUP);
8605 : 181 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8606 : 181 : TREE_TYPE (stmt) = void_type_node;
8607 : 181 : OMP_TASKGROUP_BODY (stmt) = body;
8608 : 181 : OMP_TASKGROUP_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
8609 : : code->ext.omp_clauses,
8610 : : code->loc);
8611 : 181 : gfc_add_expr_to_block (&block, stmt);
8612 : 181 : return gfc_finish_block (&block);
8613 : : }
8614 : :
8615 : : static tree
8616 : 143 : gfc_trans_omp_taskwait (gfc_code *code)
8617 : : {
8618 : 143 : if (!code->ext.omp_clauses)
8619 : : {
8620 : 131 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
8621 : 131 : return build_call_expr_loc (input_location, decl, 0);
8622 : : }
8623 : 12 : stmtblock_t block;
8624 : 12 : gfc_start_block (&block);
8625 : 12 : tree stmt = make_node (OMP_TASK);
8626 : 12 : SET_EXPR_LOCATION (stmt, gfc_get_location (&code->loc));
8627 : 12 : TREE_TYPE (stmt) = void_type_node;
8628 : 12 : OMP_TASK_BODY (stmt) = NULL_TREE;
8629 : 12 : OMP_TASK_CLAUSES (stmt) = gfc_trans_omp_clauses (&block,
8630 : : code->ext.omp_clauses,
8631 : : code->loc);
8632 : 12 : gfc_add_expr_to_block (&block, stmt);
8633 : 12 : return gfc_finish_block (&block);
8634 : : }
8635 : :
8636 : : static tree
8637 : 8 : gfc_trans_omp_taskyield (void)
8638 : : {
8639 : 8 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
8640 : 8 : return build_call_expr_loc (input_location, decl, 0);
8641 : : }
8642 : :
8643 : : static tree
8644 : 339 : gfc_trans_omp_distribute (gfc_code *code, gfc_omp_clauses *clausesa)
8645 : : {
8646 : 339 : stmtblock_t block;
8647 : 339 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8648 : 339 : tree stmt, omp_clauses = NULL_TREE;
8649 : 339 : bool free_clausesa = false;
8650 : :
8651 : 339 : gfc_start_block (&block);
8652 : 339 : if (clausesa == NULL)
8653 : : {
8654 : 113 : clausesa = clausesa_buf;
8655 : 113 : gfc_split_omp_clauses (code, clausesa);
8656 : 113 : free_clausesa = true;
8657 : : }
8658 : 339 : if (flag_openmp)
8659 : 339 : omp_clauses
8660 : 339 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
8661 : : code->loc);
8662 : 339 : switch (code->op)
8663 : : {
8664 : 0 : case EXEC_OMP_DISTRIBUTE:
8665 : 0 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
8666 : 0 : case EXEC_OMP_TEAMS_DISTRIBUTE:
8667 : : /* This is handled in gfc_trans_omp_do. */
8668 : 0 : gcc_unreachable ();
8669 : 126 : break;
8670 : 126 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
8671 : 126 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
8672 : 126 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
8673 : 126 : stmt = gfc_trans_omp_parallel_do (code, false, &block, clausesa);
8674 : 126 : if (TREE_CODE (stmt) != BIND_EXPR)
8675 : 126 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8676 : : else
8677 : 0 : poplevel (0, 0);
8678 : : break;
8679 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
8680 : 113 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
8681 : 113 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
8682 : 113 : stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
8683 : 113 : if (TREE_CODE (stmt) != BIND_EXPR)
8684 : 113 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8685 : : else
8686 : 0 : poplevel (0, 0);
8687 : : break;
8688 : 100 : case EXEC_OMP_DISTRIBUTE_SIMD:
8689 : 100 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
8690 : 100 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
8691 : 100 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8692 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8693 : 100 : if (TREE_CODE (stmt) != BIND_EXPR)
8694 : 100 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8695 : : else
8696 : 0 : poplevel (0, 0);
8697 : : break;
8698 : 0 : default:
8699 : 0 : gcc_unreachable ();
8700 : : }
8701 : 339 : if (flag_openmp)
8702 : : {
8703 : 339 : tree distribute = make_node (OMP_DISTRIBUTE);
8704 : 339 : SET_EXPR_LOCATION (distribute, gfc_get_location (&code->loc));
8705 : 339 : TREE_TYPE (distribute) = void_type_node;
8706 : 339 : OMP_FOR_BODY (distribute) = stmt;
8707 : 339 : OMP_FOR_CLAUSES (distribute) = omp_clauses;
8708 : 339 : stmt = distribute;
8709 : : }
8710 : 339 : gfc_add_expr_to_block (&block, stmt);
8711 : 339 : if (free_clausesa)
8712 : 113 : gfc_free_split_omp_clauses (code, clausesa);
8713 : 339 : return gfc_finish_block (&block);
8714 : : }
8715 : :
8716 : : static tree
8717 : 465 : gfc_trans_omp_teams (gfc_code *code, gfc_omp_clauses *clausesa,
8718 : : tree omp_clauses)
8719 : : {
8720 : 465 : stmtblock_t block;
8721 : 465 : gfc_omp_clauses clausesa_buf[GFC_OMP_SPLIT_NUM];
8722 : 465 : tree stmt;
8723 : 465 : bool combined = true, free_clausesa = false;
8724 : :
8725 : 465 : gfc_start_block (&block);
8726 : 465 : if (clausesa == NULL)
8727 : : {
8728 : 269 : clausesa = clausesa_buf;
8729 : 269 : gfc_split_omp_clauses (code, clausesa);
8730 : 269 : free_clausesa = true;
8731 : : }
8732 : 465 : if (flag_openmp)
8733 : : {
8734 : 465 : omp_clauses
8735 : 465 : = chainon (omp_clauses,
8736 : : gfc_trans_omp_clauses (&block,
8737 : : &clausesa[GFC_OMP_SPLIT_TEAMS],
8738 : : code->loc));
8739 : 465 : pushlevel ();
8740 : : }
8741 : 465 : switch (code->op)
8742 : : {
8743 : 193 : case EXEC_OMP_TARGET_TEAMS:
8744 : 193 : case EXEC_OMP_TEAMS:
8745 : 193 : stmt = gfc_trans_omp_code (code->block->next, true);
8746 : 193 : combined = false;
8747 : 193 : break;
8748 : 28 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
8749 : 28 : case EXEC_OMP_TEAMS_DISTRIBUTE:
8750 : 28 : stmt = gfc_trans_omp_do (code, EXEC_OMP_DISTRIBUTE, NULL,
8751 : : &clausesa[GFC_OMP_SPLIT_DISTRIBUTE],
8752 : : NULL);
8753 : 28 : break;
8754 : 18 : case EXEC_OMP_TARGET_TEAMS_LOOP:
8755 : 18 : case EXEC_OMP_TEAMS_LOOP:
8756 : 18 : stmt = gfc_trans_omp_do (code, EXEC_OMP_LOOP, NULL,
8757 : : &clausesa[GFC_OMP_SPLIT_DO],
8758 : : NULL);
8759 : 18 : break;
8760 : 226 : default:
8761 : 226 : stmt = gfc_trans_omp_distribute (code, clausesa);
8762 : 226 : break;
8763 : : }
8764 : 465 : if (flag_openmp)
8765 : : {
8766 : 465 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8767 : 465 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TEAMS,
8768 : : void_type_node, stmt, omp_clauses);
8769 : 465 : if (combined)
8770 : 272 : OMP_TEAMS_COMBINED (stmt) = 1;
8771 : : }
8772 : 465 : gfc_add_expr_to_block (&block, stmt);
8773 : 465 : if (free_clausesa)
8774 : 269 : gfc_free_split_omp_clauses (code, clausesa);
8775 : 465 : return gfc_finish_block (&block);
8776 : : }
8777 : :
8778 : : static tree
8779 : 1923 : gfc_trans_omp_target (gfc_code *code)
8780 : : {
8781 : 1923 : stmtblock_t block;
8782 : 1923 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8783 : 1923 : tree stmt, omp_clauses = NULL_TREE;
8784 : :
8785 : 1923 : gfc_start_block (&block);
8786 : 1923 : gfc_split_omp_clauses (code, clausesa);
8787 : 1923 : if (flag_openmp)
8788 : 1923 : omp_clauses
8789 : 1923 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TARGET],
8790 : : code->loc);
8791 : 1923 : switch (code->op)
8792 : : {
8793 : 1587 : case EXEC_OMP_TARGET:
8794 : 1587 : pushlevel ();
8795 : 1587 : stmt = gfc_trans_omp_code (code->block->next, true);
8796 : 1587 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8797 : 1587 : break;
8798 : 20 : case EXEC_OMP_TARGET_PARALLEL:
8799 : 20 : {
8800 : 20 : stmtblock_t iblock;
8801 : :
8802 : 20 : pushlevel ();
8803 : 20 : gfc_start_block (&iblock);
8804 : 20 : tree inner_clauses
8805 : 20 : = gfc_trans_omp_clauses (&iblock, &clausesa[GFC_OMP_SPLIT_PARALLEL],
8806 : : code->loc);
8807 : 20 : stmt = gfc_trans_omp_code (code->block->next, true);
8808 : 20 : stmt = build2_loc (input_location, OMP_PARALLEL, void_type_node, stmt,
8809 : : inner_clauses);
8810 : 20 : gfc_add_expr_to_block (&iblock, stmt);
8811 : 20 : stmt = gfc_finish_block (&iblock);
8812 : 20 : if (TREE_CODE (stmt) != BIND_EXPR)
8813 : 17 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8814 : : else
8815 : 3 : poplevel (0, 0);
8816 : : }
8817 : 20 : break;
8818 : 79 : case EXEC_OMP_TARGET_PARALLEL_DO:
8819 : 79 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
8820 : 79 : stmt = gfc_trans_omp_parallel_do (code,
8821 : : (code->op
8822 : : == EXEC_OMP_TARGET_PARALLEL_LOOP),
8823 : : &block, clausesa);
8824 : 79 : if (TREE_CODE (stmt) != BIND_EXPR)
8825 : 79 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8826 : : else
8827 : 0 : poplevel (0, 0);
8828 : : break;
8829 : 15 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
8830 : 15 : stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
8831 : 15 : if (TREE_CODE (stmt) != BIND_EXPR)
8832 : 15 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8833 : : else
8834 : 0 : poplevel (0, 0);
8835 : : break;
8836 : 26 : case EXEC_OMP_TARGET_SIMD:
8837 : 26 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8838 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8839 : 26 : if (TREE_CODE (stmt) != BIND_EXPR)
8840 : 26 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8841 : : else
8842 : 0 : poplevel (0, 0);
8843 : : break;
8844 : 196 : default:
8845 : 196 : if (flag_openmp
8846 : 196 : && (clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper
8847 : 146 : || clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit))
8848 : : {
8849 : 51 : gfc_omp_clauses clausesb;
8850 : 51 : tree teams_clauses;
8851 : : /* For combined !$omp target teams, the num_teams and
8852 : : thread_limit clauses are evaluated before entering the
8853 : : target construct. */
8854 : 51 : memset (&clausesb, '\0', sizeof (clausesb));
8855 : 51 : clausesb.num_teams_lower
8856 : 51 : = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower;
8857 : 51 : clausesb.num_teams_upper
8858 : 51 : = clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper;
8859 : 51 : clausesb.thread_limit = clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit;
8860 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_lower = NULL;
8861 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].num_teams_upper = NULL;
8862 : 51 : clausesa[GFC_OMP_SPLIT_TEAMS].thread_limit = NULL;
8863 : 51 : teams_clauses
8864 : 51 : = gfc_trans_omp_clauses (&block, &clausesb, code->loc);
8865 : 51 : pushlevel ();
8866 : 51 : stmt = gfc_trans_omp_teams (code, clausesa, teams_clauses);
8867 : 51 : }
8868 : : else
8869 : : {
8870 : 145 : pushlevel ();
8871 : 145 : stmt = gfc_trans_omp_teams (code, clausesa, NULL_TREE);
8872 : : }
8873 : 196 : if (TREE_CODE (stmt) != BIND_EXPR)
8874 : 195 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8875 : : else
8876 : 1 : poplevel (0, 0);
8877 : : break;
8878 : : }
8879 : 1923 : if (flag_openmp)
8880 : : {
8881 : 1923 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET,
8882 : : void_type_node, stmt, omp_clauses);
8883 : 1923 : if (code->op != EXEC_OMP_TARGET)
8884 : 336 : OMP_TARGET_COMBINED (stmt) = 1;
8885 : 1923 : cfun->has_omp_target = true;
8886 : : }
8887 : 1923 : gfc_add_expr_to_block (&block, stmt);
8888 : 1923 : gfc_free_split_omp_clauses (code, clausesa);
8889 : 1923 : return gfc_finish_block (&block);
8890 : : }
8891 : :
8892 : : static tree
8893 : 79 : gfc_trans_omp_taskloop (gfc_code *code, gfc_exec_op op)
8894 : : {
8895 : 79 : stmtblock_t block;
8896 : 79 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8897 : 79 : tree stmt, omp_clauses = NULL_TREE;
8898 : :
8899 : 79 : gfc_start_block (&block);
8900 : 79 : gfc_split_omp_clauses (code, clausesa);
8901 : 79 : if (flag_openmp)
8902 : 79 : omp_clauses
8903 : 79 : = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_TASKLOOP],
8904 : : code->loc);
8905 : 79 : switch (op)
8906 : : {
8907 : 0 : case EXEC_OMP_TASKLOOP:
8908 : : /* This is handled in gfc_trans_omp_do. */
8909 : 0 : gcc_unreachable ();
8910 : 79 : break;
8911 : 79 : case EXEC_OMP_TASKLOOP_SIMD:
8912 : 79 : stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
8913 : : &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
8914 : 79 : if (TREE_CODE (stmt) != BIND_EXPR)
8915 : 79 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8916 : : else
8917 : 0 : poplevel (0, 0);
8918 : 79 : break;
8919 : 0 : default:
8920 : 0 : gcc_unreachable ();
8921 : : }
8922 : 79 : if (flag_openmp)
8923 : : {
8924 : 79 : tree taskloop = make_node (OMP_TASKLOOP);
8925 : 79 : SET_EXPR_LOCATION (taskloop, gfc_get_location (&code->loc));
8926 : 79 : TREE_TYPE (taskloop) = void_type_node;
8927 : 79 : OMP_FOR_BODY (taskloop) = stmt;
8928 : 79 : OMP_FOR_CLAUSES (taskloop) = omp_clauses;
8929 : 79 : stmt = taskloop;
8930 : : }
8931 : 79 : gfc_add_expr_to_block (&block, stmt);
8932 : 79 : gfc_free_split_omp_clauses (code, clausesa);
8933 : 79 : return gfc_finish_block (&block);
8934 : : }
8935 : :
8936 : : static tree
8937 : 84 : gfc_trans_omp_master_masked_taskloop (gfc_code *code, gfc_exec_op op)
8938 : : {
8939 : 84 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8940 : 84 : stmtblock_t block;
8941 : 84 : tree stmt;
8942 : :
8943 : 84 : if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
8944 : 55 : && code->op != EXEC_OMP_MASTER_TASKLOOP)
8945 : 44 : gfc_split_omp_clauses (code, clausesa);
8946 : :
8947 : 84 : pushlevel ();
8948 : 84 : if (op == EXEC_OMP_MASKED_TASKLOOP_SIMD
8949 : 84 : || op == EXEC_OMP_MASTER_TASKLOOP_SIMD)
8950 : 48 : stmt = gfc_trans_omp_taskloop (code, EXEC_OMP_TASKLOOP_SIMD);
8951 : : else
8952 : : {
8953 : 36 : gcc_assert (op == EXEC_OMP_MASKED_TASKLOOP
8954 : : || op == EXEC_OMP_MASTER_TASKLOOP);
8955 : 36 : stmt = gfc_trans_omp_do (code, EXEC_OMP_TASKLOOP, NULL,
8956 : 36 : code->op != EXEC_OMP_MASTER_TASKLOOP
8957 : : ? &clausesa[GFC_OMP_SPLIT_TASKLOOP]
8958 : : : code->ext.omp_clauses, NULL);
8959 : : }
8960 : 84 : if (TREE_CODE (stmt) != BIND_EXPR)
8961 : 55 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
8962 : : else
8963 : 29 : poplevel (0, 0);
8964 : 84 : gfc_start_block (&block);
8965 : 84 : if (op == EXEC_OMP_MASKED_TASKLOOP || op == EXEC_OMP_MASKED_TASKLOOP_SIMD)
8966 : : {
8967 : 34 : tree clauses = gfc_trans_omp_clauses (&block,
8968 : : &clausesa[GFC_OMP_SPLIT_MASKED],
8969 : : code->loc);
8970 : 34 : tree msk = make_node (OMP_MASKED);
8971 : 34 : SET_EXPR_LOCATION (msk, gfc_get_location (&code->loc));
8972 : 34 : TREE_TYPE (msk) = void_type_node;
8973 : 34 : OMP_MASKED_BODY (msk) = stmt;
8974 : 34 : OMP_MASKED_CLAUSES (msk) = clauses;
8975 : 34 : OMP_MASKED_COMBINED (msk) = 1;
8976 : 34 : gfc_add_expr_to_block (&block, msk);
8977 : : }
8978 : : else
8979 : : {
8980 : 50 : gcc_assert (op == EXEC_OMP_MASTER_TASKLOOP
8981 : : || op == EXEC_OMP_MASTER_TASKLOOP_SIMD);
8982 : 50 : stmt = build1_v (OMP_MASTER, stmt);
8983 : 50 : gfc_add_expr_to_block (&block, stmt);
8984 : : }
8985 : 84 : if (op != EXEC_OMP_MASTER_TASKLOOP_SIMD
8986 : 55 : && code->op != EXEC_OMP_MASTER_TASKLOOP)
8987 : 44 : gfc_free_split_omp_clauses (code, clausesa);
8988 : 84 : return gfc_finish_block (&block);
8989 : : }
8990 : :
8991 : : static tree
8992 : 61 : gfc_trans_omp_parallel_master_masked (gfc_code *code)
8993 : : {
8994 : 61 : stmtblock_t block;
8995 : 61 : tree stmt, omp_clauses;
8996 : 61 : gfc_omp_clauses clausesa[GFC_OMP_SPLIT_NUM];
8997 : 61 : bool parallel_combined = false;
8998 : :
8999 : 61 : if (code->op != EXEC_OMP_PARALLEL_MASTER)
9000 : 50 : gfc_split_omp_clauses (code, clausesa);
9001 : :
9002 : 61 : gfc_start_block (&block);
9003 : 61 : omp_clauses = gfc_trans_omp_clauses (&block,
9004 : 61 : code->op == EXEC_OMP_PARALLEL_MASTER
9005 : : ? code->ext.omp_clauses
9006 : : : &clausesa[GFC_OMP_SPLIT_PARALLEL],
9007 : : code->loc);
9008 : 61 : pushlevel ();
9009 : 61 : if (code->op == EXEC_OMP_PARALLEL_MASTER)
9010 : 11 : stmt = gfc_trans_omp_master (code);
9011 : 50 : else if (code->op == EXEC_OMP_PARALLEL_MASKED)
9012 : 11 : stmt = gfc_trans_omp_masked (code, &clausesa[GFC_OMP_SPLIT_MASKED]);
9013 : : else
9014 : : {
9015 : 39 : gfc_exec_op op;
9016 : 39 : switch (code->op)
9017 : : {
9018 : : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
9019 : : op = EXEC_OMP_MASKED_TASKLOOP;
9020 : : break;
9021 : 8 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
9022 : 8 : op = EXEC_OMP_MASKED_TASKLOOP_SIMD;
9023 : 8 : break;
9024 : 10 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
9025 : 10 : op = EXEC_OMP_MASTER_TASKLOOP;
9026 : 10 : break;
9027 : 14 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
9028 : 14 : op = EXEC_OMP_MASTER_TASKLOOP_SIMD;
9029 : 14 : break;
9030 : 0 : default:
9031 : 0 : gcc_unreachable ();
9032 : : }
9033 : 39 : stmt = gfc_trans_omp_master_masked_taskloop (code, op);
9034 : 39 : parallel_combined = true;
9035 : : }
9036 : 61 : if (TREE_CODE (stmt) != BIND_EXPR)
9037 : 48 : stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
9038 : : else
9039 : 13 : poplevel (0, 0);
9040 : 61 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_PARALLEL,
9041 : : void_type_node, stmt, omp_clauses);
9042 : : /* masked does have just filter clause, but during gimplification
9043 : : isn't represented by a gimplification omp context, so for
9044 : : !$omp parallel masked don't set OMP_PARALLEL_COMBINED,
9045 : : so that
9046 : : !$omp parallel masked
9047 : : !$omp taskloop simd lastprivate (x)
9048 : : isn't confused with
9049 : : !$omp parallel masked taskloop simd lastprivate (x) */
9050 : 61 : if (parallel_combined)
9051 : 39 : OMP_PARALLEL_COMBINED (stmt) = 1;
9052 : 61 : gfc_add_expr_to_block (&block, stmt);
9053 : 61 : if (code->op != EXEC_OMP_PARALLEL_MASTER)
9054 : 50 : gfc_free_split_omp_clauses (code, clausesa);
9055 : 61 : return gfc_finish_block (&block);
9056 : : }
9057 : :
9058 : : static tree
9059 : 1388 : gfc_trans_omp_target_data (gfc_code *code)
9060 : : {
9061 : 1388 : stmtblock_t block;
9062 : 1388 : tree stmt, omp_clauses;
9063 : :
9064 : 1388 : gfc_start_block (&block);
9065 : 1388 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9066 : : code->loc);
9067 : 1388 : stmt = gfc_trans_omp_code (code->block->next, true);
9068 : 1388 : stmt = build2_loc (gfc_get_location (&code->loc), OMP_TARGET_DATA,
9069 : : void_type_node, stmt, omp_clauses);
9070 : 1388 : gfc_add_expr_to_block (&block, stmt);
9071 : 1388 : return gfc_finish_block (&block);
9072 : : }
9073 : :
9074 : : static tree
9075 : 285 : gfc_trans_omp_target_enter_data (gfc_code *code)
9076 : : {
9077 : 285 : stmtblock_t block;
9078 : 285 : tree stmt, omp_clauses;
9079 : :
9080 : 285 : gfc_start_block (&block);
9081 : 285 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9082 : : code->loc);
9083 : 285 : stmt = build1_loc (input_location, OMP_TARGET_ENTER_DATA, void_type_node,
9084 : : omp_clauses);
9085 : 285 : gfc_add_expr_to_block (&block, stmt);
9086 : 285 : return gfc_finish_block (&block);
9087 : : }
9088 : :
9089 : : static tree
9090 : 223 : gfc_trans_omp_target_exit_data (gfc_code *code)
9091 : : {
9092 : 223 : stmtblock_t block;
9093 : 223 : tree stmt, omp_clauses;
9094 : :
9095 : 223 : gfc_start_block (&block);
9096 : 223 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9097 : : code->loc, false, false, code->op);
9098 : 223 : stmt = build1_loc (input_location, OMP_TARGET_EXIT_DATA, void_type_node,
9099 : : omp_clauses);
9100 : 223 : gfc_add_expr_to_block (&block, stmt);
9101 : 223 : return gfc_finish_block (&block);
9102 : : }
9103 : :
9104 : : static tree
9105 : 1697 : gfc_trans_omp_target_update (gfc_code *code)
9106 : : {
9107 : 1697 : stmtblock_t block;
9108 : 1697 : tree stmt, omp_clauses;
9109 : :
9110 : 1697 : gfc_start_block (&block);
9111 : 1697 : omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses,
9112 : : code->loc);
9113 : 1697 : stmt = build1_loc (input_location, OMP_TARGET_UPDATE, void_type_node,
9114 : : omp_clauses);
9115 : 1697 : gfc_add_expr_to_block (&block, stmt);
9116 : 1697 : return gfc_finish_block (&block);
9117 : : }
9118 : :
9119 : : static tree
9120 : 8 : gfc_trans_openmp_interop (gfc_code *code, gfc_omp_clauses *clauses)
9121 : : {
9122 : 8 : stmtblock_t block;
9123 : 8 : gfc_start_block (&block);
9124 : 8 : tree omp_clauses = gfc_trans_omp_clauses (&block, clauses, code->loc);
9125 : 8 : tree stmt = build1_loc (input_location, OMP_INTEROP, void_type_node,
9126 : : omp_clauses);
9127 : 8 : gfc_add_expr_to_block (&block, stmt);
9128 : 8 : return gfc_finish_block (&block);
9129 : : }
9130 : :
9131 : : static tree
9132 : 85 : gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
9133 : : {
9134 : 85 : tree res, tmp, stmt;
9135 : 85 : stmtblock_t block, *pblock = NULL;
9136 : 85 : stmtblock_t singleblock;
9137 : 85 : int saved_ompws_flags;
9138 : 85 : bool singleblock_in_progress = false;
9139 : : /* True if previous gfc_code in workshare construct is not workshared. */
9140 : 85 : bool prev_singleunit;
9141 : 85 : location_t loc = gfc_get_location (&code->loc);
9142 : :
9143 : 85 : code = code->block->next;
9144 : :
9145 : 85 : pushlevel ();
9146 : :
9147 : 85 : gfc_start_block (&block);
9148 : 85 : pblock = █
9149 : :
9150 : 85 : ompws_flags = OMPWS_WORKSHARE_FLAG;
9151 : 85 : prev_singleunit = false;
9152 : :
9153 : : /* Translate statements one by one to trees until we reach
9154 : : the end of the workshare construct. Adjacent gfc_codes that
9155 : : are a single unit of work are clustered and encapsulated in a
9156 : : single OMP_SINGLE construct. */
9157 : 282 : for (; code; code = code->next)
9158 : : {
9159 : 197 : if (code->here != 0)
9160 : : {
9161 : 0 : res = gfc_trans_label_here (code);
9162 : 0 : gfc_add_expr_to_block (pblock, res);
9163 : : }
9164 : :
9165 : : /* No dependence analysis, use for clauses with wait.
9166 : : If this is the last gfc_code, use default omp_clauses. */
9167 : 197 : if (code->next == NULL && clauses->nowait)
9168 : 60 : ompws_flags |= OMPWS_NOWAIT;
9169 : :
9170 : : /* By default, every gfc_code is a single unit of work. */
9171 : 197 : ompws_flags |= OMPWS_CURR_SINGLEUNIT;
9172 : 197 : ompws_flags &= ~(OMPWS_SCALARIZER_WS | OMPWS_SCALARIZER_BODY);
9173 : :
9174 : 197 : switch (code->op)
9175 : : {
9176 : : case EXEC_NOP:
9177 : : res = NULL_TREE;
9178 : : break;
9179 : :
9180 : 125 : case EXEC_ASSIGN:
9181 : 125 : res = gfc_trans_assign (code);
9182 : 125 : break;
9183 : :
9184 : 0 : case EXEC_POINTER_ASSIGN:
9185 : 0 : res = gfc_trans_pointer_assign (code);
9186 : 0 : break;
9187 : :
9188 : 0 : case EXEC_INIT_ASSIGN:
9189 : 0 : res = gfc_trans_init_assign (code);
9190 : 0 : break;
9191 : :
9192 : 24 : case EXEC_FORALL:
9193 : 24 : res = gfc_trans_forall (code);
9194 : 24 : break;
9195 : :
9196 : 19 : case EXEC_WHERE:
9197 : 19 : res = gfc_trans_where (code);
9198 : 19 : break;
9199 : :
9200 : 7 : case EXEC_OMP_ATOMIC:
9201 : 7 : res = gfc_trans_omp_directive (code);
9202 : 7 : break;
9203 : :
9204 : 17 : case EXEC_OMP_PARALLEL:
9205 : 17 : case EXEC_OMP_PARALLEL_DO:
9206 : 17 : case EXEC_OMP_PARALLEL_MASTER:
9207 : 17 : case EXEC_OMP_PARALLEL_SECTIONS:
9208 : 17 : case EXEC_OMP_PARALLEL_WORKSHARE:
9209 : 17 : case EXEC_OMP_CRITICAL:
9210 : 17 : saved_ompws_flags = ompws_flags;
9211 : 17 : ompws_flags = 0;
9212 : 17 : res = gfc_trans_omp_directive (code);
9213 : 17 : ompws_flags = saved_ompws_flags;
9214 : 17 : break;
9215 : :
9216 : 5 : case EXEC_BLOCK:
9217 : 5 : res = gfc_trans_block_construct (code);
9218 : 5 : break;
9219 : :
9220 : 0 : default:
9221 : 0 : gfc_internal_error ("gfc_trans_omp_workshare(): Bad statement code");
9222 : : }
9223 : :
9224 : 197 : input_location = gfc_get_location (&code->loc);
9225 : :
9226 : 197 : if (res != NULL_TREE && ! IS_EMPTY_STMT (res))
9227 : : {
9228 : 197 : if (prev_singleunit)
9229 : : {
9230 : 72 : if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
9231 : : /* Add current gfc_code to single block. */
9232 : 44 : gfc_add_expr_to_block (&singleblock, res);
9233 : : else
9234 : : {
9235 : : /* Finish single block and add it to pblock. */
9236 : 28 : tmp = gfc_finish_block (&singleblock);
9237 : 28 : tmp = build2_loc (loc, OMP_SINGLE,
9238 : : void_type_node, tmp, NULL_TREE);
9239 : 28 : gfc_add_expr_to_block (pblock, tmp);
9240 : : /* Add current gfc_code to pblock. */
9241 : 28 : gfc_add_expr_to_block (pblock, res);
9242 : 28 : singleblock_in_progress = false;
9243 : : }
9244 : : }
9245 : : else
9246 : : {
9247 : 125 : if (ompws_flags & OMPWS_CURR_SINGLEUNIT)
9248 : : {
9249 : : /* Start single block. */
9250 : 73 : gfc_init_block (&singleblock);
9251 : 73 : gfc_add_expr_to_block (&singleblock, res);
9252 : 73 : singleblock_in_progress = true;
9253 : 73 : loc = gfc_get_location (&code->loc);
9254 : : }
9255 : : else
9256 : : /* Add the new statement to the block. */
9257 : 52 : gfc_add_expr_to_block (pblock, res);
9258 : : }
9259 : 197 : prev_singleunit = (ompws_flags & OMPWS_CURR_SINGLEUNIT) != 0;
9260 : : }
9261 : : }
9262 : :
9263 : : /* Finish remaining SINGLE block, if we were in the middle of one. */
9264 : 85 : if (singleblock_in_progress)
9265 : : {
9266 : : /* Finish single block and add it to pblock. */
9267 : 45 : tmp = gfc_finish_block (&singleblock);
9268 : 45 : tmp = build2_loc (loc, OMP_SINGLE, void_type_node, tmp,
9269 : 45 : clauses->nowait
9270 : 27 : ? build_omp_clause (input_location, OMP_CLAUSE_NOWAIT)
9271 : : : NULL_TREE);
9272 : 45 : gfc_add_expr_to_block (pblock, tmp);
9273 : : }
9274 : :
9275 : 85 : stmt = gfc_finish_block (pblock);
9276 : 85 : if (TREE_CODE (stmt) != BIND_EXPR)
9277 : : {
9278 : 65 : if (!IS_EMPTY_STMT (stmt))
9279 : : {
9280 : 65 : tree bindblock = poplevel (1, 0);
9281 : 65 : stmt = build3_v (BIND_EXPR, NULL, stmt, bindblock);
9282 : : }
9283 : : else
9284 : 0 : poplevel (0, 0);
9285 : : }
9286 : : else
9287 : 20 : poplevel (0, 0);
9288 : :
9289 : 85 : if (IS_EMPTY_STMT (stmt) && !clauses->nowait)
9290 : 0 : stmt = gfc_trans_omp_barrier ();
9291 : :
9292 : 85 : ompws_flags = 0;
9293 : 85 : return stmt;
9294 : : }
9295 : :
9296 : : tree
9297 : 74 : gfc_trans_oacc_declare (gfc_code *code)
9298 : : {
9299 : 74 : stmtblock_t block;
9300 : 74 : tree stmt, oacc_clauses;
9301 : 74 : enum tree_code construct_code;
9302 : :
9303 : 74 : construct_code = OACC_DATA;
9304 : :
9305 : 74 : gfc_start_block (&block);
9306 : :
9307 : 74 : oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.oacc_declare->clauses,
9308 : : code->loc, false, true);
9309 : 74 : stmt = gfc_trans_omp_code (code->block->next, true);
9310 : 74 : stmt = build2_loc (input_location, construct_code, void_type_node, stmt,
9311 : : oacc_clauses);
9312 : 74 : gfc_add_expr_to_block (&block, stmt);
9313 : :
9314 : 74 : return gfc_finish_block (&block);
9315 : : }
9316 : :
9317 : : tree
9318 : 11949 : gfc_trans_oacc_directive (gfc_code *code)
9319 : : {
9320 : 11949 : switch (code->op)
9321 : : {
9322 : 1552 : case EXEC_OACC_PARALLEL_LOOP:
9323 : 1552 : case EXEC_OACC_KERNELS_LOOP:
9324 : 1552 : case EXEC_OACC_SERIAL_LOOP:
9325 : 1552 : return gfc_trans_oacc_combined_directive (code);
9326 : 4164 : case EXEC_OACC_PARALLEL:
9327 : 4164 : case EXEC_OACC_KERNELS:
9328 : 4164 : case EXEC_OACC_SERIAL:
9329 : 4164 : case EXEC_OACC_DATA:
9330 : 4164 : case EXEC_OACC_HOST_DATA:
9331 : 4164 : return gfc_trans_oacc_construct (code);
9332 : 3374 : case EXEC_OACC_LOOP:
9333 : 3374 : return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
9334 : 3374 : NULL);
9335 : 2075 : case EXEC_OACC_UPDATE:
9336 : 2075 : case EXEC_OACC_CACHE:
9337 : 2075 : case EXEC_OACC_ENTER_DATA:
9338 : 2075 : case EXEC_OACC_EXIT_DATA:
9339 : 2075 : return gfc_trans_oacc_executable_directive (code);
9340 : 167 : case EXEC_OACC_WAIT:
9341 : 167 : return gfc_trans_oacc_wait_directive (code);
9342 : 543 : case EXEC_OACC_ATOMIC:
9343 : 543 : return gfc_trans_omp_atomic (code);
9344 : 74 : case EXEC_OACC_DECLARE:
9345 : 74 : return gfc_trans_oacc_declare (code);
9346 : 0 : default:
9347 : 0 : gcc_unreachable ();
9348 : : }
9349 : : }
9350 : :
9351 : : tree
9352 : 18530 : gfc_trans_omp_directive (gfc_code *code)
9353 : : {
9354 : 18530 : switch (code->op)
9355 : : {
9356 : 31 : case EXEC_OMP_ALLOCATE:
9357 : 31 : case EXEC_OMP_ALLOCATORS:
9358 : 31 : return gfc_trans_omp_allocators (code);
9359 : 10 : case EXEC_OMP_ASSUME:
9360 : 10 : return gfc_trans_omp_assume (code);
9361 : 2053 : case EXEC_OMP_ATOMIC:
9362 : 2053 : return gfc_trans_omp_atomic (code);
9363 : 603 : case EXEC_OMP_BARRIER:
9364 : 603 : return gfc_trans_omp_barrier ();
9365 : 310 : case EXEC_OMP_CANCEL:
9366 : 310 : return gfc_trans_omp_cancel (code);
9367 : 170 : case EXEC_OMP_CANCELLATION_POINT:
9368 : 170 : return gfc_trans_omp_cancellation_point (code);
9369 : 143 : case EXEC_OMP_CRITICAL:
9370 : 143 : return gfc_trans_omp_critical (code);
9371 : 106 : case EXEC_OMP_DEPOBJ:
9372 : 106 : return gfc_trans_omp_depobj (code);
9373 : 2452 : case EXEC_OMP_DISTRIBUTE:
9374 : 2452 : case EXEC_OMP_DO:
9375 : 2452 : case EXEC_OMP_LOOP:
9376 : 2452 : case EXEC_OMP_SIMD:
9377 : 2452 : case EXEC_OMP_TASKLOOP:
9378 : 2452 : case EXEC_OMP_TILE:
9379 : 2452 : case EXEC_OMP_UNROLL:
9380 : 2452 : return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
9381 : 2452 : NULL);
9382 : 128 : case EXEC_OMP_DISPATCH:
9383 : 128 : return gfc_trans_omp_dispatch (code);
9384 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
9385 : 113 : case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
9386 : 113 : case EXEC_OMP_DISTRIBUTE_SIMD:
9387 : 113 : return gfc_trans_omp_distribute (code, NULL);
9388 : 126 : case EXEC_OMP_DO_SIMD:
9389 : 126 : return gfc_trans_omp_do_simd (code, NULL, NULL, NULL_TREE);
9390 : 29 : case EXEC_OMP_ERROR:
9391 : 29 : return gfc_trans_omp_error (code);
9392 : 70 : case EXEC_OMP_FLUSH:
9393 : 70 : return gfc_trans_omp_flush (code);
9394 : 38 : case EXEC_OMP_MASKED:
9395 : 38 : return gfc_trans_omp_masked (code, NULL);
9396 : 104 : case EXEC_OMP_MASTER:
9397 : 104 : return gfc_trans_omp_master (code);
9398 : 45 : case EXEC_OMP_MASKED_TASKLOOP:
9399 : 45 : case EXEC_OMP_MASKED_TASKLOOP_SIMD:
9400 : 45 : case EXEC_OMP_MASTER_TASKLOOP:
9401 : 45 : case EXEC_OMP_MASTER_TASKLOOP_SIMD:
9402 : 45 : return gfc_trans_omp_master_masked_taskloop (code, code->op);
9403 : 76 : case EXEC_OMP_METADIRECTIVE:
9404 : 76 : return gfc_trans_omp_metadirective (code);
9405 : 519 : case EXEC_OMP_ORDERED:
9406 : 519 : return gfc_trans_omp_ordered (code);
9407 : 1858 : case EXEC_OMP_PARALLEL:
9408 : 1858 : return gfc_trans_omp_parallel (code);
9409 : 1077 : case EXEC_OMP_PARALLEL_DO:
9410 : 1077 : return gfc_trans_omp_parallel_do (code, false, NULL, NULL);
9411 : 24 : case EXEC_OMP_PARALLEL_LOOP:
9412 : 24 : return gfc_trans_omp_parallel_do (code, true, NULL, NULL);
9413 : 285 : case EXEC_OMP_PARALLEL_DO_SIMD:
9414 : 285 : return gfc_trans_omp_parallel_do_simd (code, NULL, NULL);
9415 : 61 : case EXEC_OMP_PARALLEL_MASKED:
9416 : 61 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP:
9417 : 61 : case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
9418 : 61 : case EXEC_OMP_PARALLEL_MASTER:
9419 : 61 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
9420 : 61 : case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
9421 : 61 : return gfc_trans_omp_parallel_master_masked (code);
9422 : 54 : case EXEC_OMP_PARALLEL_SECTIONS:
9423 : 54 : return gfc_trans_omp_parallel_sections (code);
9424 : 50 : case EXEC_OMP_PARALLEL_WORKSHARE:
9425 : 50 : return gfc_trans_omp_parallel_workshare (code);
9426 : 53 : case EXEC_OMP_SCOPE:
9427 : 53 : return gfc_trans_omp_scope (code);
9428 : 75 : case EXEC_OMP_SECTIONS:
9429 : 75 : return gfc_trans_omp_sections (code, code->ext.omp_clauses);
9430 : 555 : case EXEC_OMP_SINGLE:
9431 : 555 : return gfc_trans_omp_single (code, code->ext.omp_clauses);
9432 : 1923 : case EXEC_OMP_TARGET:
9433 : 1923 : case EXEC_OMP_TARGET_PARALLEL:
9434 : 1923 : case EXEC_OMP_TARGET_PARALLEL_DO:
9435 : 1923 : case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
9436 : 1923 : case EXEC_OMP_TARGET_PARALLEL_LOOP:
9437 : 1923 : case EXEC_OMP_TARGET_SIMD:
9438 : 1923 : case EXEC_OMP_TARGET_TEAMS:
9439 : 1923 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
9440 : 1923 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
9441 : 1923 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
9442 : 1923 : case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
9443 : 1923 : case EXEC_OMP_TARGET_TEAMS_LOOP:
9444 : 1923 : return gfc_trans_omp_target (code);
9445 : 1388 : case EXEC_OMP_TARGET_DATA:
9446 : 1388 : return gfc_trans_omp_target_data (code);
9447 : 285 : case EXEC_OMP_TARGET_ENTER_DATA:
9448 : 285 : return gfc_trans_omp_target_enter_data (code);
9449 : 223 : case EXEC_OMP_TARGET_EXIT_DATA:
9450 : 223 : return gfc_trans_omp_target_exit_data (code);
9451 : 1697 : case EXEC_OMP_TARGET_UPDATE:
9452 : 1697 : return gfc_trans_omp_target_update (code);
9453 : 1121 : case EXEC_OMP_TASK:
9454 : 1121 : return gfc_trans_omp_task (code);
9455 : 181 : case EXEC_OMP_TASKGROUP:
9456 : 181 : return gfc_trans_omp_taskgroup (code);
9457 : 31 : case EXEC_OMP_TASKLOOP_SIMD:
9458 : 31 : return gfc_trans_omp_taskloop (code, code->op);
9459 : 143 : case EXEC_OMP_TASKWAIT:
9460 : 143 : return gfc_trans_omp_taskwait (code);
9461 : 8 : case EXEC_OMP_TASKYIELD:
9462 : 8 : return gfc_trans_omp_taskyield ();
9463 : 269 : case EXEC_OMP_TEAMS:
9464 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE:
9465 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
9466 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
9467 : 269 : case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
9468 : 269 : case EXEC_OMP_TEAMS_LOOP:
9469 : 269 : return gfc_trans_omp_teams (code, NULL, NULL_TREE);
9470 : 35 : case EXEC_OMP_WORKSHARE:
9471 : 35 : return gfc_trans_omp_workshare (code, code->ext.omp_clauses);
9472 : 8 : case EXEC_OMP_INTEROP:
9473 : 8 : return gfc_trans_openmp_interop (code, code->ext.omp_clauses);
9474 : 0 : default:
9475 : 0 : gcc_unreachable ();
9476 : : }
9477 : : }
9478 : :
9479 : : void
9480 : 109 : gfc_trans_omp_declare_simd (gfc_namespace *ns)
9481 : : {
9482 : 109 : if (ns->entries)
9483 : : return;
9484 : :
9485 : 109 : gfc_omp_declare_simd *ods;
9486 : 262 : for (ods = ns->omp_declare_simd; ods; ods = ods->next)
9487 : : {
9488 : 153 : tree c = gfc_trans_omp_clauses (NULL, ods->clauses, ods->where, true);
9489 : 153 : tree fndecl = ns->proc_name->backend_decl;
9490 : 153 : if (c != NULL_TREE)
9491 : 103 : c = tree_cons (NULL_TREE, c, NULL_TREE);
9492 : 153 : c = build_tree_list (get_identifier ("omp declare simd"), c);
9493 : 153 : TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
9494 : 153 : DECL_ATTRIBUTES (fndecl) = c;
9495 : : }
9496 : : }
9497 : :
9498 : : /* Translate the context selector list GFC_SELECTORS, using WHERE as the
9499 : : locus for error messages. */
9500 : :
9501 : : static tree
9502 : 486 : gfc_trans_omp_set_selector (gfc_omp_set_selector *gfc_selectors, locus where)
9503 : : {
9504 : 486 : tree set_selectors = NULL_TREE;
9505 : 486 : gfc_omp_set_selector *oss;
9506 : :
9507 : 962 : for (oss = gfc_selectors; oss; oss = oss->next)
9508 : : {
9509 : 476 : tree selectors = NULL_TREE;
9510 : 476 : gfc_omp_selector *os;
9511 : 476 : enum omp_tss_code set = oss->code;
9512 : 476 : gcc_assert (set != OMP_TRAIT_SET_INVALID);
9513 : :
9514 : 1077 : for (os = oss->trait_selectors; os; os = os->next)
9515 : : {
9516 : 601 : tree scoreval = NULL_TREE;
9517 : 601 : tree properties = NULL_TREE;
9518 : 601 : gfc_omp_trait_property *otp;
9519 : 601 : enum omp_ts_code sel = os->code;
9520 : :
9521 : : /* Per the spec, "Implementations can ignore specified
9522 : : selectors that are not those described in this section";
9523 : : however, we must record such selectors because they
9524 : : cause match failures. */
9525 : 601 : if (sel == OMP_TRAIT_INVALID)
9526 : : {
9527 : 1 : selectors = make_trait_selector (sel, NULL_TREE, NULL_TREE,
9528 : : selectors);
9529 : 1 : continue;
9530 : : }
9531 : :
9532 : 959 : for (otp = os->properties; otp; otp = otp->next)
9533 : : {
9534 : 359 : switch (otp->property_kind)
9535 : : {
9536 : 72 : case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
9537 : 72 : case OMP_TRAIT_PROPERTY_BOOL_EXPR:
9538 : 72 : {
9539 : 72 : tree expr = NULL_TREE;
9540 : 72 : gfc_se se;
9541 : 72 : gfc_init_se (&se, NULL);
9542 : 72 : gfc_conv_expr (&se, otp->expr);
9543 : 72 : expr = se.expr;
9544 : 72 : properties = make_trait_property (NULL_TREE, expr,
9545 : : properties);
9546 : : }
9547 : 72 : break;
9548 : 23 : case OMP_TRAIT_PROPERTY_ID:
9549 : 23 : properties
9550 : 23 : = make_trait_property (get_identifier (otp->name),
9551 : : NULL_TREE, properties);
9552 : 23 : break;
9553 : 250 : case OMP_TRAIT_PROPERTY_NAME_LIST:
9554 : 250 : {
9555 : 250 : tree prop = OMP_TP_NAMELIST_NODE;
9556 : 250 : tree value = NULL_TREE;
9557 : 250 : if (otp->is_name)
9558 : 165 : value = get_identifier (otp->name);
9559 : : else
9560 : 85 : value = gfc_conv_constant_to_tree (otp->expr);
9561 : :
9562 : 250 : properties = make_trait_property (prop, value,
9563 : : properties);
9564 : : }
9565 : 250 : break;
9566 : 14 : case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
9567 : 14 : properties = gfc_trans_omp_clauses (NULL, otp->clauses,
9568 : : where, true);
9569 : 14 : break;
9570 : 0 : default:
9571 : 0 : gcc_unreachable ();
9572 : : }
9573 : : }
9574 : :
9575 : 600 : if (os->score)
9576 : : {
9577 : 51 : gfc_se se;
9578 : 51 : gfc_init_se (&se, NULL);
9579 : 51 : gfc_conv_expr (&se, os->score);
9580 : 51 : scoreval = se.expr;
9581 : : }
9582 : :
9583 : 600 : selectors = make_trait_selector (sel, scoreval,
9584 : : properties, selectors);
9585 : : }
9586 : 476 : set_selectors = make_trait_set_selector (set, selectors, set_selectors);
9587 : : }
9588 : 486 : return set_selectors;
9589 : : }
9590 : :
9591 : : /* If 'ns' points to a formal namespace in an interface, ns->parent == NULL;
9592 : : hence, parent_ns is used instead. */
9593 : :
9594 : : void
9595 : 9985 : gfc_trans_omp_declare_variant (gfc_namespace *ns, gfc_namespace *parent_ns)
9596 : : {
9597 : 9985 : tree base_fn_decl = ns->proc_name->backend_decl;
9598 : 9985 : gfc_namespace *search_ns = ns;
9599 : 9985 : gfc_omp_declare_variant *next;
9600 : :
9601 : 9985 : for (gfc_omp_declare_variant *odv = search_ns->omp_declare_variant;
9602 : 27086 : search_ns; odv = next)
9603 : : {
9604 : : /* Look in the parent namespace if there are no more directives in the
9605 : : current namespace. */
9606 : 17101 : if (!odv)
9607 : : {
9608 : 16719 : if (!search_ns->parent && search_ns == ns)
9609 : : search_ns = parent_ns;
9610 : : else
9611 : 11680 : search_ns = search_ns->parent;
9612 : 16719 : if (search_ns)
9613 : 6734 : next = search_ns->omp_declare_variant;
9614 : 16719 : continue;
9615 : : }
9616 : :
9617 : 382 : next = odv->next;
9618 : :
9619 : 382 : if (odv->error_p)
9620 : 17 : continue;
9621 : :
9622 : : /* Check directive the first time it is encountered. */
9623 : 365 : bool error_found = true;
9624 : :
9625 : 365 : if (odv->checked_p)
9626 : 43 : error_found = false;
9627 : 365 : if (odv->base_proc_symtree == NULL)
9628 : : {
9629 : 328 : if (!search_ns->proc_name->attr.function
9630 : 328 : && !search_ns->proc_name->attr.subroutine)
9631 : 1 : gfc_error ("The base name for %<declare variant%> must be "
9632 : : "specified at %L", &odv->where);
9633 : : else
9634 : : error_found = false;
9635 : : }
9636 : : else
9637 : : {
9638 : 37 : if (!search_ns->contained
9639 : 21 : && !odv->base_proc_symtree->n.sym->attr.use_assoc
9640 : 5 : && strcmp (odv->base_proc_symtree->name,
9641 : 5 : ns->proc_name->name))
9642 : 1 : gfc_error ("The base name at %L does not match the name of the "
9643 : : "current procedure", &odv->where);
9644 : 36 : else if (odv->base_proc_symtree->n.sym->attr.entry)
9645 : 1 : gfc_error ("The base name at %L must not be an entry name",
9646 : : &odv->where);
9647 : 35 : else if (odv->base_proc_symtree->n.sym->attr.generic)
9648 : 1 : gfc_error ("The base name at %L must not be a generic name",
9649 : : &odv->where);
9650 : 34 : else if (odv->base_proc_symtree->n.sym->attr.proc_pointer)
9651 : 1 : gfc_error ("The base name at %L must not be a procedure pointer",
9652 : : &odv->where);
9653 : 33 : else if (odv->base_proc_symtree->n.sym->attr.implicit_type)
9654 : 1 : gfc_error ("The base procedure at %L must have an explicit "
9655 : : "interface", &odv->where);
9656 : : else
9657 : : error_found = false;
9658 : : }
9659 : :
9660 : 365 : odv->checked_p = true;
9661 : 365 : if (error_found)
9662 : : {
9663 : 6 : odv->error_p = true;
9664 : 6 : continue;
9665 : : }
9666 : :
9667 : : /* Ignore directives that do not apply to the current procedure. */
9668 : 359 : if ((odv->base_proc_symtree == NULL && search_ns != ns)
9669 : 333 : || (odv->base_proc_symtree != NULL
9670 : 32 : && !ns->proc_name->attr.use_assoc
9671 : 19 : && strcmp (odv->base_proc_symtree->name, ns->proc_name->name))
9672 : 320 : || (odv->base_proc_symtree != NULL
9673 : 19 : && ns->proc_name->attr.use_assoc
9674 : 13 : && strcmp (odv->base_proc_symtree->n.sym->name,
9675 : : ns->proc_name->name)))
9676 : 44 : continue;
9677 : :
9678 : 315 : tree set_selectors = gfc_trans_omp_set_selector (odv->set_selectors,
9679 : : odv->where);
9680 : 315 : const char *variant_proc_name = odv->variant_proc_symtree->name;
9681 : 315 : gfc_symbol *variant_proc_sym = odv->variant_proc_symtree->n.sym;
9682 : 315 : if (variant_proc_sym == NULL || variant_proc_sym->attr.implicit_type)
9683 : : {
9684 : 38 : gfc_symtree *proc_st;
9685 : 38 : gfc_find_sym_tree (variant_proc_name, gfc_current_ns, 1, &proc_st);
9686 : 38 : variant_proc_sym = proc_st->n.sym;
9687 : : }
9688 : 38 : if (variant_proc_sym == NULL)
9689 : : {
9690 : 0 : gfc_error ("Cannot find symbol %qs", variant_proc_name);
9691 : 0 : continue;
9692 : : }
9693 : 315 : set_selectors = omp_check_context_selector
9694 : 315 : (gfc_get_location (&odv->where), set_selectors,
9695 : : OMP_CTX_DECLARE_VARIANT);
9696 : 315 : if (set_selectors != error_mark_node)
9697 : : {
9698 : 295 : if (!variant_proc_sym->attr.implicit_type
9699 : : && !variant_proc_sym->attr.subroutine
9700 : 295 : && !variant_proc_sym->attr.function)
9701 : : {
9702 : 0 : gfc_error ("variant %qs at %L is not a function or subroutine",
9703 : : variant_proc_name, &odv->where);
9704 : 0 : variant_proc_sym = NULL;
9705 : : }
9706 : 295 : else if (omp_get_context_selector (set_selectors,
9707 : : OMP_TRAIT_SET_CONSTRUCT,
9708 : : OMP_TRAIT_CONSTRUCT_SIMD)
9709 : : == NULL_TREE)
9710 : : {
9711 : 281 : char err[256];
9712 : 281 : gfc_formal_arglist *last_arg = NULL, *extra_arg = NULL;
9713 : 281 : int nappend_args = 0;
9714 : 281 : if (odv->append_args_list)
9715 : : {
9716 : 26 : gfc_formal_arglist *arg;
9717 : 26 : int nargs = 0;
9718 : 26 : for (arg = gfc_sym_get_dummy_args (ns->proc_name);
9719 : 56 : arg; arg = arg->next)
9720 : 30 : nargs++;
9721 : :
9722 : 26 : last_arg = gfc_sym_get_dummy_args (variant_proc_sym);
9723 : 33 : for (int i = 1 ; i < nargs && last_arg; i++)
9724 : 7 : last_arg = last_arg->next;
9725 : 26 : if (nargs == 0)
9726 : : {
9727 : 3 : extra_arg = last_arg;
9728 : 3 : last_arg = NULL;
9729 : 3 : variant_proc_sym->formal = NULL;
9730 : : }
9731 : 23 : else if (last_arg)
9732 : : {
9733 : 23 : extra_arg = last_arg->next;
9734 : 23 : last_arg->next = NULL;
9735 : : }
9736 : 76 : for (gfc_omp_namelist *n = odv->append_args_list; n != NULL;
9737 : 50 : n = n->next)
9738 : 50 : nappend_args++;
9739 : : }
9740 : 281 : if (!gfc_compare_interfaces (ns->proc_name, variant_proc_sym,
9741 : : variant_proc_sym->name, 0, 1,
9742 : : err, sizeof (err), NULL, NULL))
9743 : : {
9744 : 2 : gfc_error ("variant %qs and base %qs at %L have "
9745 : : "incompatible types: %s",
9746 : 2 : variant_proc_name, ns->proc_name->name,
9747 : : &odv->where, err);
9748 : 2 : if (nappend_args)
9749 : 0 : inform (gfc_get_location (&odv->append_args_list->where),
9750 : : "%<append_args%> clause implies that %qs has %d "
9751 : : "dummy arguments of integer type with "
9752 : : "%<omp_interop_kind%> kind", variant_proc_name,
9753 : : nappend_args);
9754 : : variant_proc_sym = NULL;
9755 : : }
9756 : 281 : if (last_arg)
9757 : 23 : last_arg->next = extra_arg;
9758 : 258 : else if (extra_arg)
9759 : 3 : variant_proc_sym->formal = extra_arg;
9760 : 562 : locus *loc = (odv->append_args_list
9761 : 281 : ? &odv->append_args_list->where : &odv->where);
9762 : 281 : int nextra_arg = 0;
9763 : 334 : for (; extra_arg; extra_arg = extra_arg->next)
9764 : : {
9765 : 53 : nextra_arg++;
9766 : 53 : if (!variant_proc_sym)
9767 : 8 : continue;
9768 : 45 : if (extra_arg->sym->ts.type != BT_INTEGER
9769 : 43 : || extra_arg->sym->ts.kind != gfc_index_integer_kind
9770 : : || extra_arg->sym->attr.dimension
9771 : : || extra_arg->sym->attr.codimension
9772 : : || extra_arg->sym->attr.pointer
9773 : : || extra_arg->sym->attr.allocatable
9774 : 42 : || extra_arg->sym->attr.proc_pointer)
9775 : : {
9776 : 8 : gfc_error ("%qs at %L must be a nonpointer, "
9777 : : "nonallocatable scalar integer dummy argument "
9778 : : "of %<omp_interop_kind%> kind as it utilized "
9779 : : "with the %<append_args%> clause at %L",
9780 : : extra_arg->sym->name,
9781 : : &extra_arg->sym->declared_at, loc);
9782 : 8 : variant_proc_sym = NULL;
9783 : : }
9784 : 45 : if (extra_arg->sym->attr.optional)
9785 : : {
9786 : 2 : gfc_error ("%qs at %L with OPTIONAL attribute "
9787 : : "not support when utilized with the "
9788 : : "%<append_args%> clause at %L",
9789 : : extra_arg->sym->name,
9790 : : &extra_arg->sym->declared_at, loc);
9791 : 2 : variant_proc_sym = NULL;
9792 : : }
9793 : : }
9794 : 281 : if (variant_proc_sym && nappend_args != nextra_arg)
9795 : : {
9796 : 1 : gfc_error ("%qs at %L has %d but requires %d "
9797 : : "%<omp_interop_kind%> kind dummy arguments as it "
9798 : : "is utilized with the %<append_args%> clause at "
9799 : : "%L", variant_proc_sym->name,
9800 : : &variant_proc_sym->declared_at, nextra_arg,
9801 : : nappend_args, loc);
9802 : 1 : variant_proc_sym = NULL;
9803 : : }
9804 : : }
9805 : 249 : if ((odv->adjust_args_list != NULL || odv->append_args_list != NULL)
9806 : 320 : && omp_get_context_selector (set_selectors,
9807 : : OMP_TRAIT_SET_CONSTRUCT,
9808 : : OMP_TRAIT_CONSTRUCT_DISPATCH)
9809 : : == NULL_TREE)
9810 : : {
9811 : 6 : gfc_error ("the %qs clause can only be specified if "
9812 : : "the %<dispatch%> selector of the construct "
9813 : : "selector set appears in the %<match%> clause at %L",
9814 : 3 : odv->adjust_args_list ? "adjust_args" : "append_args",
9815 : : &odv->where);
9816 : 3 : variant_proc_sym = NULL;
9817 : : }
9818 : 295 : if (variant_proc_sym != NULL)
9819 : : {
9820 : 280 : gfc_set_sym_referenced (variant_proc_sym);
9821 : 280 : tree construct
9822 : 280 : = omp_get_context_selector_list (set_selectors,
9823 : : OMP_TRAIT_SET_CONSTRUCT);
9824 : 280 : omp_mark_declare_variant (gfc_get_location (&odv->where),
9825 : : gfc_get_symbol_decl (variant_proc_sym),
9826 : : construct);
9827 : 280 : if (omp_context_selector_matches (set_selectors,
9828 : : NULL_TREE, false))
9829 : : {
9830 : 201 : tree need_device_ptr_list = NULL_TREE;
9831 : 201 : tree need_device_addr_list = NULL_TREE;
9832 : 201 : tree append_args_tree = NULL_TREE;
9833 : 201 : tree id = get_identifier ("omp declare variant base");
9834 : 201 : tree variant = gfc_get_symbol_decl (variant_proc_sym);
9835 : 201 : DECL_ATTRIBUTES (base_fn_decl)
9836 : 201 : = tree_cons (id, build_tree_list (variant, set_selectors),
9837 : 201 : DECL_ATTRIBUTES (base_fn_decl));
9838 : 201 : int arg_idx_offset = 0;
9839 : 201 : if (gfc_return_by_reference (ns->proc_name))
9840 : : {
9841 : 2 : arg_idx_offset++;
9842 : 2 : if (ns->proc_name->ts.type == BT_CHARACTER)
9843 : 2 : arg_idx_offset++;
9844 : : }
9845 : 201 : int nargs = 0;
9846 : 201 : for (gfc_formal_arglist *arg
9847 : 201 : = gfc_sym_get_dummy_args (ns->proc_name);
9848 : 442 : arg; arg = arg->next)
9849 : 241 : nargs++;
9850 : 201 : if (odv->append_args_list)
9851 : : {
9852 : 14 : int append_arg_no = arg_idx_offset + nargs;
9853 : 14 : tree last_arg = NULL_TREE;
9854 : 14 : for (gfc_omp_namelist *n = odv->append_args_list;
9855 : 43 : n != NULL; n = n->next)
9856 : : {
9857 : 29 : tree pref = NULL_TREE;
9858 : 29 : if (n->u.init.len)
9859 : : {
9860 : 22 : pref = build_string (n->u.init.len,
9861 : 11 : n->u2.init_interop);
9862 : 11 : TREE_TYPE (pref) = build_array_type_nelts (
9863 : : unsigned_char_type_node,
9864 : 11 : n->u.init.len);
9865 : : }
9866 : : /* Save location, (target + target sync) and
9867 : : prefer_type list in a tree list. */
9868 : 29 : tree t = build_tree_list (n->u.init.target
9869 : : ? boolean_true_node
9870 : : : boolean_false_node,
9871 : 29 : n->u.init.targetsync
9872 : : ? boolean_true_node
9873 : : : boolean_false_node);
9874 : 29 : t = build1_loc (gfc_get_location (&n->where),
9875 : : NOP_EXPR, void_type_node, t);
9876 : 29 : t = build_tree_list (t, pref);
9877 : 29 : if (append_args_tree)
9878 : : {
9879 : 15 : TREE_CHAIN (last_arg) = t;
9880 : 15 : last_arg = t;
9881 : : }
9882 : : else
9883 : : append_args_tree = last_arg = t;
9884 : : }
9885 : : /* Store as 'purpose' = arg number to be used for inserting
9886 : : and 'value' = list of interop items. */
9887 : 14 : append_args_tree = build_tree_list (
9888 : 14 : build_int_cst (integer_type_node,
9889 : : append_arg_no),
9890 : : append_args_tree);
9891 : : }
9892 : 201 : vec<gfc_symbol *> adjust_args_list = vNULL;
9893 : 201 : for (gfc_omp_namelist *arg_list = odv->adjust_args_list;
9894 : 311 : arg_list != NULL; arg_list = arg_list->next)
9895 : : {
9896 : 110 : int from, to;
9897 : 110 : if (arg_list->expr == NULL || arg_list->sym)
9898 : 94 : from = ((arg_list->u.adj_args.omp_num_args_minus
9899 : 94 : || arg_list->u.adj_args.omp_num_args_plus)
9900 : 94 : ? nargs : 1);
9901 : : else
9902 : : {
9903 : 16 : if (arg_list->u.adj_args.omp_num_args_plus)
9904 : 0 : mpz_add_ui (arg_list->expr->value.integer,
9905 : 0 : arg_list->expr->value.integer, nargs);
9906 : 16 : if (arg_list->u.adj_args.omp_num_args_minus)
9907 : 2 : mpz_ui_sub (arg_list->expr->value.integer, nargs,
9908 : 2 : arg_list->expr->value.integer);
9909 : 16 : if (mpz_sgn (arg_list->expr->value.integer) <= 0)
9910 : : {
9911 : 1 : gfc_warning (OPT_Wopenmp,
9912 : : "Expected positive argument index "
9913 : : "at %L", &arg_list->where);
9914 : 1 : from = 1;
9915 : : }
9916 : : else
9917 : 15 : from
9918 : 15 : = (mpz_fits_sint_p (arg_list->expr->value.integer)
9919 : 15 : ? mpz_get_si (arg_list->expr->value.integer)
9920 : : : INT_MAX);
9921 : 16 : if (from > nargs)
9922 : 1 : gfc_warning (OPT_Wopenmp,
9923 : : "Argument index at %L exceeds number "
9924 : : "of arguments %d", &arg_list->where,
9925 : : nargs);
9926 : : }
9927 : 110 : locus loc = arg_list->where;
9928 : 110 : if (!arg_list->u.adj_args.range_start)
9929 : : to = from;
9930 : : else
9931 : : {
9932 : 6 : loc = gfc_get_location_range (&arg_list->where, 0,
9933 : : &arg_list->where, 0,
9934 : 6 : &arg_list->next->where);
9935 : 6 : if (arg_list->next->expr == NULL)
9936 : : to = nargs;
9937 : : else
9938 : : {
9939 : 4 : if (arg_list->next->u.adj_args.omp_num_args_plus)
9940 : 0 : mpz_add_ui (arg_list->next->expr->value.integer,
9941 : 0 : arg_list->next->expr->value.integer,
9942 : : nargs);
9943 : 4 : if (arg_list->next->u.adj_args.omp_num_args_minus)
9944 : 2 : mpz_ui_sub (arg_list->next->expr->value.integer,
9945 : : nargs,
9946 : 2 : arg_list->next->expr->value.integer);
9947 : 4 : if (mpz_sgn (arg_list->next->expr->value.integer)
9948 : : <= 0)
9949 : : {
9950 : 0 : gfc_warning (OPT_Wopenmp,
9951 : : "Expected positive argument "
9952 : : "index at %L", &loc);
9953 : 0 : to = 0;
9954 : : }
9955 : : else
9956 : 4 : to = mpz_get_si (
9957 : 4 : arg_list->next->expr->value.integer);
9958 : : }
9959 : 6 : if (from > to && to != 0)
9960 : 1 : gfc_warning (OPT_Wopenmp,
9961 : : "Upper argument index smaller than "
9962 : : "lower one at %L", &loc);
9963 : 6 : if (to > nargs)
9964 : : to = nargs;
9965 : 6 : arg_list = arg_list->next;
9966 : : }
9967 : 110 : if (from > nargs)
9968 : 1 : continue;
9969 : : /* Change to zero based index. */
9970 : 109 : from--; to--;
9971 : 109 : gfc_formal_arglist *arg = ns->proc_name->formal;
9972 : 109 : if (!arg_list->sym && to >= from)
9973 : 35 : for (int idx = 0; idx < from; idx++)
9974 : 18 : arg = arg->next;
9975 : 223 : for (int idx = from; idx <= to; idx++)
9976 : : {
9977 : 114 : if (idx > from)
9978 : 6 : arg = arg->next;
9979 : 114 : if (arg_list->sym)
9980 : : {
9981 : 91 : for (arg = ns->proc_name->formal, idx = 0;
9982 : 201 : arg != NULL; arg = arg->next, idx++)
9983 : 200 : if (arg->sym == arg_list->sym)
9984 : : break;
9985 : 91 : if (!arg || !arg_list->sym->attr.dummy)
9986 : : {
9987 : 1 : gfc_error ("List item %qs at %L, declared at "
9988 : : "%L, is not a dummy argument",
9989 : : arg_list->sym->name, &loc,
9990 : : &arg_list->sym->declared_at);
9991 : 1 : continue;
9992 : : }
9993 : : }
9994 : 113 : if (arg_list->u.adj_args.need_ptr
9995 : 82 : && (arg->sym->ts.f90_type != BT_VOID
9996 : 80 : || !arg->sym->ts.u.derived->ts.is_iso_c
9997 : 80 : || (arg->sym->ts.u.derived->intmod_sym_id
9998 : : != ISOCBINDING_PTR)
9999 : 79 : || arg->sym->attr.dimension))
10000 : : {
10001 : 6 : gfc_error ("Argument %qs at %L to list item in "
10002 : : "%<need_device_ptr%> at %L must be a "
10003 : : "scalar of TYPE(C_PTR)",
10004 : : arg->sym->name,
10005 : : &arg->sym->declared_at, &loc);
10006 : 6 : if (!arg->sym->attr.value)
10007 : 6 : inform (gfc_get_location (&loc),
10008 : : "Consider using %<need_device_addr%> "
10009 : : "instead");
10010 : 6 : continue;
10011 : : }
10012 : 107 : if (arg_list->u.adj_args.need_addr
10013 : 11 : && arg->sym->attr.value)
10014 : : {
10015 : 1 : gfc_error ("Argument %qs at %L to list item in "
10016 : : "%<need_device_addr%> at %L must not "
10017 : : "have the VALUE attribute",
10018 : : arg->sym->name,
10019 : : &arg->sym->declared_at, &loc);
10020 : 1 : continue;
10021 : : }
10022 : 106 : if (adjust_args_list.contains (arg->sym))
10023 : : {
10024 : 7 : gfc_error ("%qs at %L is specified more than "
10025 : 7 : "once", arg->sym->name, &loc);
10026 : 7 : continue;
10027 : : }
10028 : 99 : adjust_args_list.safe_push (arg->sym);
10029 : :
10030 : 99 : if (arg_list->u.adj_args.need_addr)
10031 : : {
10032 : : /* TODO: Has to to support OPTIONAL and array
10033 : : descriptors; should check for CLASS, coarrays?
10034 : : Reject "abc" and 123 as actual arguments (in
10035 : : gimplify.cc or in the FE? Reject noncontiguous
10036 : : actuals? Cf. also PR C++/118859.
10037 : : Also check array-valued type(c_ptr). */
10038 : 7 : static bool warned = false;
10039 : 7 : if (!warned)
10040 : 1 : sorry_at (gfc_get_location (&loc),
10041 : : "%<need_device_addr%> not yet "
10042 : : "supported");
10043 : 7 : warned = true;
10044 : 7 : continue;
10045 : 7 : }
10046 : 92 : if (arg_list->u.adj_args.need_ptr
10047 : : || arg_list->u.adj_args.need_addr)
10048 : : {
10049 : : // Store 0-based argument index,
10050 : : // as in gimplify_call_expr
10051 : 74 : tree t
10052 : 74 : = build_tree_list (
10053 : : NULL_TREE,
10054 : 74 : build_int_cst (integer_type_node,
10055 : 74 : idx + arg_idx_offset));
10056 : 74 : if (arg_list->u.adj_args.need_ptr)
10057 : 74 : need_device_ptr_list
10058 : 74 : = chainon (need_device_ptr_list, t);
10059 : : else
10060 : 0 : need_device_addr_list
10061 : 0 : = chainon (need_device_addr_list, t);
10062 : : }
10063 : : }
10064 : : }
10065 : 201 : tree t = NULL_TREE;
10066 : 201 : if (need_device_ptr_list
10067 : 201 : || need_device_addr_list
10068 : 165 : || append_args_tree)
10069 : : {
10070 : 50 : t = build_tree_list (need_device_ptr_list,
10071 : : need_device_addr_list),
10072 : 50 : TREE_CHAIN (t) = append_args_tree;
10073 : 50 : DECL_ATTRIBUTES (variant) = tree_cons (
10074 : : get_identifier ("omp declare variant variant args"), t,
10075 : 50 : DECL_ATTRIBUTES (variant));
10076 : : }
10077 : : }
10078 : : }
10079 : : }
10080 : : }
10081 : 9985 : }
10082 : :
10083 : : /* Add ptr for tracking as being allocated by GOMP_alloc. */
10084 : :
10085 : : tree
10086 : 29 : gfc_omp_call_add_alloc (tree ptr)
10087 : : {
10088 : 29 : static tree fn = NULL_TREE;
10089 : 29 : if (fn == NULL_TREE)
10090 : : {
10091 : 6 : fn = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10092 : 6 : tree att = build_tree_list (NULL_TREE, build_string (4, ". R "));
10093 : 6 : att = tree_cons (get_identifier ("fn spec"), att, TYPE_ATTRIBUTES (fn));
10094 : 6 : fn = build_type_attribute_variant (fn, att);
10095 : 6 : fn = build_fn_decl ("GOMP_add_alloc", fn);
10096 : : }
10097 : 29 : return build_call_expr_loc (input_location, fn, 1, ptr);
10098 : : }
10099 : :
10100 : : /* Generated function returns true when it was tracked via GOMP_add_alloc and
10101 : : removes it from the tracking. As called just before GOMP_free or omp_realloc
10102 : : the pointer is or might become invalid, thus, it is always removed. */
10103 : :
10104 : : tree
10105 : 47 : gfc_omp_call_is_alloc (tree ptr)
10106 : : {
10107 : 47 : static tree fn = NULL_TREE;
10108 : 47 : if (fn == NULL_TREE)
10109 : : {
10110 : 6 : fn = build_function_type_list (boolean_type_node, ptr_type_node,
10111 : : 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_is_alloc", fn);
10116 : : }
10117 : 47 : return build_call_expr_loc (input_location, fn, 1, ptr);
10118 : : }
10119 : :
10120 : : tree
10121 : 76 : gfc_trans_omp_metadirective (gfc_code *code)
10122 : : {
10123 : 76 : gfc_omp_variant *variant = code->ext.omp_variants;
10124 : :
10125 : 76 : tree metadirective_tree = make_node (OMP_METADIRECTIVE);
10126 : 76 : SET_EXPR_LOCATION (metadirective_tree, gfc_get_location (&code->loc));
10127 : 76 : TREE_TYPE (metadirective_tree) = void_type_node;
10128 : 76 : OMP_METADIRECTIVE_VARIANTS (metadirective_tree) = NULL_TREE;
10129 : :
10130 : 76 : tree tree_body = NULL_TREE;
10131 : :
10132 : 247 : while (variant)
10133 : : {
10134 : 171 : tree ctx = gfc_trans_omp_set_selector (variant->selectors,
10135 : : variant->where);
10136 : 171 : ctx = omp_check_context_selector (gfc_get_location (&variant->where),
10137 : : ctx, OMP_CTX_METADIRECTIVE);
10138 : 171 : if (ctx == error_mark_node)
10139 : : return error_mark_node;
10140 : :
10141 : : /* If the selector doesn't match, drop the whole variant. */
10142 : 171 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
10143 : : {
10144 : 23 : variant = variant->next;
10145 : 23 : continue;
10146 : : }
10147 : :
10148 : 148 : gfc_code *next_code = variant->code->next;
10149 : 148 : if (next_code && tree_body == NULL_TREE)
10150 : 17 : tree_body = gfc_trans_code (next_code);
10151 : :
10152 : 148 : if (next_code)
10153 : 19 : variant->code->next = NULL;
10154 : 148 : tree directive = gfc_trans_code (variant->code);
10155 : 148 : if (next_code)
10156 : 19 : variant->code->next = next_code;
10157 : :
10158 : 19 : tree body = next_code ? tree_body : NULL_TREE;
10159 : 148 : tree omp_variant = make_omp_metadirective_variant (ctx, directive, body);
10160 : 296 : OMP_METADIRECTIVE_VARIANTS (metadirective_tree)
10161 : 148 : = chainon (OMP_METADIRECTIVE_VARIANTS (metadirective_tree),
10162 : : omp_variant);
10163 : 148 : variant = variant->next;
10164 : : }
10165 : :
10166 : : /* TODO: Resolve the metadirective here if possible. */
10167 : :
10168 : : return metadirective_tree;
10169 : : }
|