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