Branch data Line data Source code
1 : : /* Lowering pass for OMP directives. Converts OMP directives into explicit
2 : : calls to the runtime library (libgomp), data marshalling to implement data
3 : : sharing and copying clauses, offloading to accelerators, and more.
4 : :
5 : : Contributed by Diego Novillo <dnovillo@redhat.com>
6 : :
7 : : Copyright (C) 2005-2026 Free Software Foundation, Inc.
8 : :
9 : : This file is part of GCC.
10 : :
11 : : GCC is free software; you can redistribute it and/or modify it under
12 : : the terms of the GNU General Public License as published by the Free
13 : : Software Foundation; either version 3, or (at your option) any later
14 : : version.
15 : :
16 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 : : for more details.
20 : :
21 : : You should have received a copy of the GNU General Public License
22 : : along with GCC; see the file COPYING3. If not see
23 : : <http://www.gnu.org/licenses/>. */
24 : :
25 : : #include "config.h"
26 : : #include "system.h"
27 : : #include "coretypes.h"
28 : : #include "backend.h"
29 : : #include "target.h"
30 : : #include "tree.h"
31 : : #include "gimple.h"
32 : : #include "tree-pass.h"
33 : : #include "ssa.h"
34 : : #include "cgraph.h"
35 : : #include "pretty-print.h"
36 : : #include "diagnostic-core.h"
37 : : #include "fold-const.h"
38 : : #include "stor-layout.h"
39 : : #include "internal-fn.h"
40 : : #include "gimple-iterator.h"
41 : : #include "gimple-fold.h"
42 : : #include "gimplify.h"
43 : : #include "gimplify-me.h"
44 : : #include "gimple-walk.h"
45 : : #include "tree-iterator.h"
46 : : #include "tree-inline.h"
47 : : #include "langhooks.h"
48 : : #include "tree-dfa.h"
49 : : #include "tree-ssa.h"
50 : : #include "splay-tree.h"
51 : : #include "omp-general.h"
52 : : #include "omp-low.h"
53 : : #include "gimple-low.h"
54 : : #include "alloc-pool.h"
55 : : #include "symbol-summary.h"
56 : : #include "tree-nested.h"
57 : : #include "context.h"
58 : : #include "gomp-constants.h"
59 : : #include "gimple-pretty-print.h"
60 : : #include "stringpool.h"
61 : : #include "attribs.h"
62 : : #include "omp-offload.h"
63 : :
64 : : /* Lowering of OMP parallel and workshare constructs proceeds in two
65 : : phases. The first phase scans the function looking for OMP statements
66 : : and then for variables that must be replaced to satisfy data sharing
67 : : clauses. The second phase expands code for the constructs, as well as
68 : : re-gimplifying things when variables have been replaced with complex
69 : : expressions.
70 : :
71 : : Final code generation is done by pass_expand_omp. The flowgraph is
72 : : scanned for regions which are then moved to a new
73 : : function, to be invoked by the thread library, or offloaded. */
74 : :
75 : : /* Context structure. Used to store information about each parallel
76 : : directive in the code. */
77 : :
78 : : struct omp_context
79 : : {
80 : : /* This field must be at the beginning, as we do "inheritance": Some
81 : : callback functions for tree-inline.cc (e.g., omp_copy_decl)
82 : : receive a copy_body_data pointer that is up-casted to an
83 : : omp_context pointer. */
84 : : copy_body_data cb;
85 : :
86 : : /* The tree of contexts corresponding to the encountered constructs. */
87 : : struct omp_context *outer;
88 : : gimple *stmt;
89 : :
90 : : /* Map variables to fields in a structure that allows communication
91 : : between sending and receiving threads. */
92 : : splay_tree field_map;
93 : : tree record_type;
94 : : tree sender_decl;
95 : : tree receiver_decl;
96 : :
97 : : /* These are used just by task contexts, if task firstprivate fn is
98 : : needed. srecord_type is used to communicate from the thread
99 : : that encountered the task construct to task firstprivate fn,
100 : : record_type is allocated by GOMP_task, initialized by task firstprivate
101 : : fn and passed to the task body fn. */
102 : : splay_tree sfield_map;
103 : : tree srecord_type;
104 : :
105 : : /* A chain of variables to add to the top-level block surrounding the
106 : : construct. In the case of a parallel, this is in the child function. */
107 : : tree block_vars;
108 : :
109 : : /* Label to which GOMP_cancel{,llation_point} and explicit and implicit
110 : : barriers should jump to during omplower pass. */
111 : : tree cancel_label;
112 : :
113 : : /* The sibling GIMPLE_OMP_FOR simd with _simt_ clause or NULL
114 : : otherwise. */
115 : : gimple *simt_stmt;
116 : :
117 : : /* For task reductions registered in this context, a vector containing
118 : : the length of the private copies block (if constant, otherwise NULL)
119 : : and then offsets (if constant, otherwise NULL) for each entry. */
120 : : vec<tree> task_reductions;
121 : :
122 : : /* A hash map from the reduction clauses to the registered array
123 : : elts. */
124 : : hash_map<tree, unsigned> *task_reduction_map;
125 : :
126 : : /* And a hash map from the lastprivate(conditional:) variables to their
127 : : corresponding tracking loop iteration variables. */
128 : : hash_map<tree, tree> *lastprivate_conditional_map;
129 : :
130 : : /* And a hash map from the allocate variables to their corresponding
131 : : allocators. */
132 : : hash_map<tree, tree> *allocate_map;
133 : :
134 : : /* A tree_list of the reduction clauses in this context. This is
135 : : only used for checking the consistency of OpenACC reduction
136 : : clauses in scan_omp_for and is not guaranteed to contain a valid
137 : : value outside of this function. */
138 : : tree local_reduction_clauses;
139 : :
140 : : /* A tree_list of the reduction clauses in outer contexts. This is
141 : : only used for checking the consistency of OpenACC reduction
142 : : clauses in scan_omp_for and is not guaranteed to contain a valid
143 : : value outside of this function. */
144 : : tree outer_reduction_clauses;
145 : :
146 : : /* Nesting depth of this context. Used to beautify error messages re
147 : : invalid gotos. The outermost ctx is depth 1, with depth 0 being
148 : : reserved for the main body of the function. */
149 : : int depth;
150 : :
151 : : /* True if this parallel directive is nested within another. */
152 : : bool is_nested;
153 : :
154 : : /* True if this construct can be cancelled. */
155 : : bool cancellable;
156 : :
157 : : /* True if lower_omp_1 should look up lastprivate conditional in parent
158 : : context. */
159 : : bool combined_into_simd_safelen1;
160 : :
161 : : /* True if there is nested scan context with inclusive clause. */
162 : : bool scan_inclusive;
163 : :
164 : : /* True if there is nested scan context with exclusive clause. */
165 : : bool scan_exclusive;
166 : :
167 : : /* True in the second simd loop of for simd with inscan reductions. */
168 : : bool for_simd_scan_phase;
169 : :
170 : : /* True if there is order(concurrent) clause on the construct. */
171 : : bool order_concurrent;
172 : :
173 : : /* True if there is bind clause on the construct (i.e. a loop construct). */
174 : : bool loop_p;
175 : :
176 : : /* Only used for omp target contexts. True if a teams construct is
177 : : strictly nested in it. */
178 : : bool teams_nested_p;
179 : :
180 : : /* Only used for omp target contexts. True if an OpenMP construct other
181 : : than teams is strictly nested in it. */
182 : : bool nonteams_nested_p;
183 : :
184 : : /* Candidates for adjusting OpenACC privatization level. */
185 : : vec<tree> oacc_privatization_candidates;
186 : : };
187 : :
188 : : static splay_tree all_contexts;
189 : : static int taskreg_nesting_level;
190 : : static int target_nesting_level;
191 : : static bitmap make_addressable_vars;
192 : : static bitmap global_nonaddressable_vars;
193 : : static vec<omp_context *> taskreg_contexts;
194 : : static vec<gomp_task *> task_cpyfns;
195 : :
196 : : static void scan_omp (gimple_seq *, omp_context *);
197 : : static tree scan_omp_1_op (tree *, int *, void *);
198 : : static bool omp_maybe_offloaded_ctx (omp_context *ctx);
199 : :
200 : : #define WALK_SUBSTMTS \
201 : : case GIMPLE_BIND: \
202 : : case GIMPLE_TRY: \
203 : : case GIMPLE_CATCH: \
204 : : case GIMPLE_EH_FILTER: \
205 : : case GIMPLE_ASSUME: \
206 : : case GIMPLE_TRANSACTION: \
207 : : /* The sub-statements for these should be walked. */ \
208 : : *handled_ops_p = false; \
209 : : break;
210 : :
211 : : /* Return whether CTX represents an OpenACC 'parallel' or 'serial' construct.
212 : : (This doesn't include OpenACC 'kernels' decomposed parts.) */
213 : :
214 : : static bool
215 : 17772 : is_oacc_parallel_or_serial (omp_context *ctx)
216 : : {
217 : 17772 : enum gimple_code outer_type = gimple_code (ctx->stmt);
218 : 17772 : return ((outer_type == GIMPLE_OMP_TARGET)
219 : 17772 : && ((gimple_omp_target_kind (ctx->stmt)
220 : : == GF_OMP_TARGET_KIND_OACC_PARALLEL)
221 : 3344 : || (gimple_omp_target_kind (ctx->stmt)
222 : 17772 : == GF_OMP_TARGET_KIND_OACC_SERIAL)));
223 : : }
224 : :
225 : : /* Return whether CTX represents an OpenACC 'kernels' construct.
226 : : (This doesn't include OpenACC 'kernels' decomposed parts.) */
227 : :
228 : : static bool
229 : 49894 : is_oacc_kernels (omp_context *ctx)
230 : : {
231 : 49894 : enum gimple_code outer_type = gimple_code (ctx->stmt);
232 : 49894 : return ((outer_type == GIMPLE_OMP_TARGET)
233 : 49894 : && (gimple_omp_target_kind (ctx->stmt)
234 : 49894 : == GF_OMP_TARGET_KIND_OACC_KERNELS));
235 : : }
236 : :
237 : : /* Return whether CTX represents an OpenACC 'kernels' decomposed part. */
238 : :
239 : : static bool
240 : 21645 : is_oacc_kernels_decomposed_part (omp_context *ctx)
241 : : {
242 : 21645 : enum gimple_code outer_type = gimple_code (ctx->stmt);
243 : 21645 : return ((outer_type == GIMPLE_OMP_TARGET)
244 : 21645 : && ((gimple_omp_target_kind (ctx->stmt)
245 : : == GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED)
246 : 14552 : || (gimple_omp_target_kind (ctx->stmt)
247 : : == GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE)
248 : 14552 : || (gimple_omp_target_kind (ctx->stmt)
249 : 21645 : == GF_OMP_TARGET_KIND_OACC_DATA_KERNELS)));
250 : : }
251 : :
252 : : /* Return true if STMT corresponds to an OpenMP target region. */
253 : : static bool
254 : 42754 : is_omp_target (gimple *stmt)
255 : : {
256 : 42754 : if (gimple_code (stmt) == GIMPLE_OMP_TARGET)
257 : : {
258 : 6424 : int kind = gimple_omp_target_kind (stmt);
259 : 6424 : return (kind == GF_OMP_TARGET_KIND_REGION
260 : 6424 : || kind == GF_OMP_TARGET_KIND_DATA
261 : 6424 : || kind == GF_OMP_TARGET_KIND_ENTER_DATA
262 : 10985 : || kind == GF_OMP_TARGET_KIND_EXIT_DATA);
263 : : }
264 : : return false;
265 : : }
266 : :
267 : : /* If DECL is the artificial dummy VAR_DECL created for non-static
268 : : data member privatization, return the underlying "this" parameter,
269 : : otherwise return NULL. */
270 : :
271 : : tree
272 : 508797 : omp_member_access_dummy_var (tree decl)
273 : : {
274 : 508797 : if (!VAR_P (decl)
275 : 320326 : || !DECL_ARTIFICIAL (decl)
276 : 156869 : || !DECL_IGNORED_P (decl)
277 : 151617 : || !DECL_HAS_VALUE_EXPR_P (decl)
278 : 521351 : || !lang_hooks.decls.omp_disregard_value_expr (decl, false))
279 : 506537 : return NULL_TREE;
280 : :
281 : 2260 : tree v = DECL_VALUE_EXPR (decl);
282 : 2260 : if (TREE_CODE (v) != COMPONENT_REF)
283 : : return NULL_TREE;
284 : :
285 : 16164 : while (1)
286 : 9197 : switch (TREE_CODE (v))
287 : : {
288 : 6967 : case COMPONENT_REF:
289 : 6967 : case MEM_REF:
290 : 6967 : case INDIRECT_REF:
291 : 6967 : CASE_CONVERT:
292 : 6967 : case POINTER_PLUS_EXPR:
293 : 6967 : v = TREE_OPERAND (v, 0);
294 : 6967 : continue;
295 : 2211 : case PARM_DECL:
296 : 2211 : if (DECL_CONTEXT (v) == current_function_decl
297 : 2211 : && DECL_ARTIFICIAL (v)
298 : 4422 : && TREE_CODE (TREE_TYPE (v)) == POINTER_TYPE)
299 : : return v;
300 : : return NULL_TREE;
301 : : default:
302 : : return NULL_TREE;
303 : : }
304 : : }
305 : :
306 : : /* Helper for unshare_and_remap, called through walk_tree. */
307 : :
308 : : static tree
309 : 1579 : unshare_and_remap_1 (tree *tp, int *walk_subtrees, void *data)
310 : : {
311 : 1579 : tree *pair = (tree *) data;
312 : 1579 : if (*tp == pair[0])
313 : : {
314 : 233 : *tp = unshare_expr (pair[1]);
315 : 233 : *walk_subtrees = 0;
316 : : }
317 : 1346 : else if (IS_TYPE_OR_DECL_P (*tp))
318 : 244 : *walk_subtrees = 0;
319 : 1579 : return NULL_TREE;
320 : : }
321 : :
322 : : /* Return unshare_expr (X) with all occurrences of FROM
323 : : replaced with TO. */
324 : :
325 : : static tree
326 : 150 : unshare_and_remap (tree x, tree from, tree to)
327 : : {
328 : 150 : tree pair[2] = { from, to };
329 : 150 : x = unshare_expr (x);
330 : 150 : walk_tree (&x, unshare_and_remap_1, pair, NULL);
331 : 150 : return x;
332 : : }
333 : :
334 : : /* Convenience function for calling scan_omp_1_op on tree operands. */
335 : :
336 : : static inline tree
337 : 338742 : scan_omp_op (tree *tp, omp_context *ctx)
338 : : {
339 : 338742 : struct walk_stmt_info wi;
340 : :
341 : 338742 : memset (&wi, 0, sizeof (wi));
342 : 338742 : wi.info = ctx;
343 : 338742 : wi.want_locations = true;
344 : :
345 : 338742 : return walk_tree (tp, scan_omp_1_op, &wi, NULL);
346 : : }
347 : :
348 : : static void lower_omp (gimple_seq *, omp_context *);
349 : : static tree lookup_decl_in_outer_ctx (tree, omp_context *);
350 : : static tree maybe_lookup_decl_in_outer_ctx (tree, omp_context *);
351 : :
352 : : /* Return true if CTX is for an omp parallel. */
353 : :
354 : : static inline bool
355 : 775123 : is_parallel_ctx (omp_context *ctx)
356 : : {
357 : 61098 : return gimple_code (ctx->stmt) == GIMPLE_OMP_PARALLEL;
358 : : }
359 : :
360 : :
361 : : /* Return true if CTX is for an omp task. */
362 : :
363 : : static inline bool
364 : 235627 : is_task_ctx (omp_context *ctx)
365 : : {
366 : 38735 : return gimple_code (ctx->stmt) == GIMPLE_OMP_TASK;
367 : : }
368 : :
369 : :
370 : : /* Return true if CTX is for an omp taskloop. */
371 : :
372 : : static inline bool
373 : 8182 : is_taskloop_ctx (omp_context *ctx)
374 : : {
375 : 8182 : return gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
376 : 8182 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_TASKLOOP;
377 : : }
378 : :
379 : :
380 : : /* Return true if CTX is for a host omp teams. */
381 : :
382 : : static inline bool
383 : 520406 : is_host_teams_ctx (omp_context *ctx)
384 : : {
385 : 520406 : return gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
386 : 520406 : && gimple_omp_teams_host (as_a <gomp_teams *> (ctx->stmt));
387 : : }
388 : :
389 : : /* Return true if CTX is for an omp parallel or omp task or host omp teams
390 : : (the last one is strictly not a task region in OpenMP speak, but we
391 : : need to treat it similarly). */
392 : :
393 : : static inline bool
394 : 662610 : is_taskreg_ctx (omp_context *ctx)
395 : : {
396 : 662610 : return is_parallel_ctx (ctx) || is_task_ctx (ctx) || is_host_teams_ctx (ctx);
397 : : }
398 : :
399 : : /* Return true if EXPR is variable sized. */
400 : :
401 : : static inline bool
402 : 877346 : is_variable_sized (const_tree expr)
403 : : {
404 : 877346 : return !TREE_CONSTANT (TYPE_SIZE_UNIT (TREE_TYPE (expr)));
405 : : }
406 : :
407 : : /* Lookup variables. The "maybe" form
408 : : allows for the variable form to not have been entered, otherwise we
409 : : assert that the variable must have been entered. */
410 : :
411 : : static inline tree
412 : 701189 : lookup_decl (tree var, omp_context *ctx)
413 : : {
414 : 1402279 : tree *n = ctx->cb.decl_map->get (var);
415 : 701189 : return *n;
416 : : }
417 : :
418 : : static inline tree
419 : 718844 : maybe_lookup_decl (const_tree var, omp_context *ctx)
420 : : {
421 : 718844 : tree *n = ctx->cb.decl_map->get (const_cast<tree> (var));
422 : 718844 : return n ? *n : NULL_TREE;
423 : : }
424 : :
425 : : static inline tree
426 : 125977 : lookup_field (tree var, omp_context *ctx)
427 : : {
428 : 125977 : splay_tree_node n;
429 : 251954 : n = splay_tree_lookup (ctx->field_map, (splay_tree_key) var);
430 : 125977 : return (tree) n->value;
431 : : }
432 : :
433 : : static inline tree
434 : 165872 : lookup_sfield (splay_tree_key key, omp_context *ctx)
435 : : {
436 : 165872 : splay_tree_node n;
437 : 165872 : n = splay_tree_lookup (ctx->sfield_map
438 : : ? ctx->sfield_map : ctx->field_map, key);
439 : 165872 : return (tree) n->value;
440 : : }
441 : :
442 : : static inline tree
443 : 967 : lookup_sfield (tree var, omp_context *ctx)
444 : : {
445 : 967 : return lookup_sfield ((splay_tree_key) var, ctx);
446 : : }
447 : :
448 : : static inline tree
449 : 218572 : maybe_lookup_field (splay_tree_key key, omp_context *ctx)
450 : : {
451 : 218572 : splay_tree_node n;
452 : 218572 : n = splay_tree_lookup (ctx->field_map, key);
453 : 218572 : return n ? (tree) n->value : NULL_TREE;
454 : : }
455 : :
456 : : static inline tree
457 : 218572 : maybe_lookup_field (tree var, omp_context *ctx)
458 : : {
459 : 2860 : return maybe_lookup_field ((splay_tree_key) var, ctx);
460 : : }
461 : :
462 : : /* Return true if DECL should be copied by pointer. SHARED_CTX is
463 : : the parallel context if DECL is to be shared. */
464 : :
465 : : static bool
466 : 232172 : use_pointer_for_field (tree decl, omp_context *shared_ctx)
467 : : {
468 : 452820 : if (AGGREGATE_TYPE_P (TREE_TYPE (decl))
469 : 215553 : || TYPE_ATOMIC (TREE_TYPE (decl))
470 : 447725 : || POLY_INT_CST_P (DECL_SIZE (decl)))
471 : : return true;
472 : :
473 : : /* We can only use copy-in/copy-out semantics for shared variables
474 : : when we know the value is not accessible from an outer scope. */
475 : 215523 : if (shared_ctx)
476 : : {
477 : 29394 : gcc_assert (!is_gimple_omp_oacc (shared_ctx->stmt));
478 : :
479 : : /* ??? Trivially accessible from anywhere. But why would we even
480 : : be passing an address in this case? Should we simply assert
481 : : this to be false, or should we have a cleanup pass that removes
482 : : these from the list of mappings? */
483 : 29394 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, shared_ctx)))
484 : : return true;
485 : :
486 : : /* For variables with DECL_HAS_VALUE_EXPR_P set, we cannot tell
487 : : without analyzing the expression whether or not its location
488 : : is accessible to anyone else. In the case of nested parallel
489 : : regions it certainly may be. */
490 : 29394 : if (TREE_CODE (decl) != RESULT_DECL && DECL_HAS_VALUE_EXPR_P (decl))
491 : : return true;
492 : :
493 : : /* Do not use copy-in/copy-out for variables that have their
494 : : address taken. */
495 : 28480 : if (is_global_var (decl))
496 : : {
497 : : /* For file scope vars, track whether we've seen them as
498 : : non-addressable initially and in that case, keep the same
499 : : answer for the duration of the pass, even when they are made
500 : : addressable later on e.g. through reduction expansion. Global
501 : : variables which weren't addressable before the pass will not
502 : : have their privatized copies address taken. See PR91216. */
503 : 1232 : if (!TREE_ADDRESSABLE (decl))
504 : : {
505 : 479 : if (!global_nonaddressable_vars)
506 : 74 : global_nonaddressable_vars = BITMAP_ALLOC (NULL);
507 : 479 : bitmap_set_bit (global_nonaddressable_vars, DECL_UID (decl));
508 : : }
509 : 753 : else if (!global_nonaddressable_vars
510 : 986 : || !bitmap_bit_p (global_nonaddressable_vars,
511 : 233 : DECL_UID (decl)))
512 : 731 : return true;
513 : : }
514 : 27248 : else if (TREE_ADDRESSABLE (decl))
515 : : return true;
516 : :
517 : : /* lower_send_shared_vars only uses copy-in, but not copy-out
518 : : for these. */
519 : 18344 : if (TREE_READONLY (decl)
520 : 18344 : || ((TREE_CODE (decl) == RESULT_DECL
521 : 11761 : || TREE_CODE (decl) == PARM_DECL)
522 : 673 : && DECL_BY_REFERENCE (decl)))
523 : : return false;
524 : :
525 : : /* Disallow copy-in/out in nested parallel if
526 : : decl is shared in outer parallel, otherwise
527 : : each thread could store the shared variable
528 : : in its own copy-in location, making the
529 : : variable no longer really shared. */
530 : 11529 : if (shared_ctx->is_nested)
531 : : {
532 : 2470 : omp_context *up;
533 : :
534 : 5975 : for (up = shared_ctx->outer; up; up = up->outer)
535 : 5702 : if ((is_taskreg_ctx (up)
536 : 3643 : || (gimple_code (up->stmt) == GIMPLE_OMP_TARGET
537 : 411 : && is_gimple_omp_offloaded (up->stmt)))
538 : 6113 : && maybe_lookup_decl (decl, up))
539 : : break;
540 : :
541 : 2470 : if (up)
542 : : {
543 : 2197 : tree c;
544 : :
545 : 2197 : if (gimple_code (up->stmt) == GIMPLE_OMP_TARGET)
546 : : {
547 : 309 : for (c = gimple_omp_target_clauses (up->stmt);
548 : 2031 : c; c = OMP_CLAUSE_CHAIN (c))
549 : 1932 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
550 : 1932 : && OMP_CLAUSE_DECL (c) == decl)
551 : : break;
552 : : }
553 : : else
554 : 1888 : for (c = gimple_omp_taskreg_clauses (up->stmt);
555 : 6909 : c; c = OMP_CLAUSE_CHAIN (c))
556 : 6454 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
557 : 6454 : && OMP_CLAUSE_DECL (c) == decl)
558 : : break;
559 : :
560 : 2197 : if (c)
561 : 1643 : goto maybe_mark_addressable_and_ret;
562 : : }
563 : : }
564 : :
565 : : /* For tasks avoid using copy-in/out. As tasks can be
566 : : deferred or executed in different thread, when GOMP_task
567 : : returns, the task hasn't necessarily terminated. */
568 : 9886 : if (is_task_ctx (shared_ctx))
569 : : {
570 : 2193 : tree outer;
571 : 550 : maybe_mark_addressable_and_ret:
572 : 2193 : outer = maybe_lookup_decl_in_outer_ctx (decl, shared_ctx);
573 : 2193 : if (is_gimple_reg (outer) && !omp_member_access_dummy_var (outer))
574 : : {
575 : : /* Taking address of OUTER in lower_send_shared_vars
576 : : might need regimplification of everything that uses the
577 : : variable. */
578 : 982 : if (!make_addressable_vars)
579 : 489 : make_addressable_vars = BITMAP_ALLOC (NULL);
580 : 982 : bitmap_set_bit (make_addressable_vars, DECL_UID (outer));
581 : 982 : TREE_ADDRESSABLE (outer) = 1;
582 : : }
583 : 2193 : return true;
584 : : }
585 : : }
586 : :
587 : : return false;
588 : : }
589 : :
590 : : /* Construct a new automatic decl similar to VAR. */
591 : :
592 : : static tree
593 : 228217 : omp_copy_decl_2 (tree var, tree name, tree type, omp_context *ctx)
594 : : {
595 : 228217 : tree copy = copy_var_decl (var, name, type);
596 : :
597 : 228217 : DECL_CONTEXT (copy) = current_function_decl;
598 : :
599 : 228217 : if (ctx)
600 : : {
601 : 227936 : DECL_CHAIN (copy) = ctx->block_vars;
602 : 227936 : ctx->block_vars = copy;
603 : : }
604 : : else
605 : 281 : record_vars (copy);
606 : :
607 : : /* If VAR is listed in make_addressable_vars, it wasn't
608 : : originally addressable, but was only later made so.
609 : : We don't need to take address of privatizations
610 : : from that var. */
611 : 228217 : if (TREE_ADDRESSABLE (var)
612 : 228217 : && ((make_addressable_vars
613 : 3467 : && bitmap_bit_p (make_addressable_vars, DECL_UID (var)))
614 : 38949 : || (global_nonaddressable_vars
615 : 515 : && bitmap_bit_p (global_nonaddressable_vars, DECL_UID (var)))))
616 : 2077 : TREE_ADDRESSABLE (copy) = 0;
617 : :
618 : 228217 : return copy;
619 : : }
620 : :
621 : : static tree
622 : 228217 : omp_copy_decl_1 (tree var, omp_context *ctx)
623 : : {
624 : 228217 : return omp_copy_decl_2 (var, DECL_NAME (var), TREE_TYPE (var), ctx);
625 : : }
626 : :
627 : : /* Build tree nodes to access the field for VAR on the receiver side. */
628 : :
629 : : static tree
630 : 121522 : build_receiver_ref (tree var, bool by_ref, omp_context *ctx)
631 : : {
632 : 121522 : tree x, field = lookup_field (var, ctx);
633 : :
634 : : /* If the receiver record type was remapped in the child function,
635 : : remap the field into the new record type. */
636 : 121522 : x = maybe_lookup_field (field, ctx);
637 : 121522 : if (x != NULL)
638 : 10955 : field = x;
639 : :
640 : 121522 : x = build_simple_mem_ref (ctx->receiver_decl);
641 : 121522 : TREE_THIS_NOTRAP (x) = 1;
642 : 121522 : x = omp_build_component_ref (x, field);
643 : 121522 : if (by_ref)
644 : : {
645 : 35384 : x = build_simple_mem_ref (x);
646 : 35384 : TREE_THIS_NOTRAP (x) = 1;
647 : : }
648 : :
649 : 121522 : return x;
650 : : }
651 : :
652 : : /* Build tree nodes to access VAR in the scope outer to CTX. In the case
653 : : of a parallel, this is a component reference; for workshare constructs
654 : : this is some variable. */
655 : :
656 : : static tree
657 : 114302 : build_outer_var_ref (tree var, omp_context *ctx,
658 : : enum omp_clause_code code = OMP_CLAUSE_ERROR)
659 : : {
660 : 114302 : tree x;
661 : 114302 : omp_context *outer = ctx->outer;
662 : 114691 : for (; outer; outer = outer->outer)
663 : : {
664 : 82459 : if (gimple_code (outer->stmt) == GIMPLE_OMP_TASKGROUP)
665 : 373 : continue;
666 : 82102 : if (gimple_code (outer->stmt) == GIMPLE_OMP_SCOPE
667 : 82086 : && !maybe_lookup_decl (var, outer))
668 : 16 : continue;
669 : : break;
670 : : }
671 : :
672 : 114302 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx)))
673 : : x = var;
674 : 106207 : else if (is_variable_sized (var))
675 : : {
676 : 47 : x = TREE_OPERAND (DECL_VALUE_EXPR (var), 0);
677 : 47 : x = build_outer_var_ref (x, ctx, code);
678 : 47 : x = build_simple_mem_ref (x);
679 : : }
680 : 106160 : else if (is_taskreg_ctx (ctx))
681 : : {
682 : 63624 : bool by_ref = use_pointer_for_field (var, NULL);
683 : 63624 : x = build_receiver_ref (var, by_ref, ctx);
684 : : }
685 : 42536 : else if ((gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
686 : 41199 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD)
687 : 14074 : || ctx->loop_p
688 : 13301 : || code == OMP_CLAUSE_ALLOCATE
689 : 55585 : || (code == OMP_CLAUSE_PRIVATE
690 : 39 : && (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
691 : : || gimple_code (ctx->stmt) == GIMPLE_OMP_SECTIONS
692 : : || gimple_code (ctx->stmt) == GIMPLE_OMP_SINGLE)))
693 : : {
694 : : /* #pragma omp simd isn't a worksharing construct, and can reference
695 : : even private vars in its linear etc. clauses.
696 : : Similarly for OMP_CLAUSE_PRIVATE with outer ref, that can refer
697 : : to private vars in all worksharing constructs. */
698 : 29506 : x = NULL_TREE;
699 : 29506 : if (outer && is_taskreg_ctx (outer))
700 : 1002 : x = lookup_decl (var, outer);
701 : 28504 : else if (outer)
702 : 22314 : x = maybe_lookup_decl_in_outer_ctx (var, ctx);
703 : 23316 : if (x == NULL_TREE)
704 : : x = var;
705 : : }
706 : 13030 : else if (code == OMP_CLAUSE_LASTPRIVATE && is_taskloop_ctx (ctx))
707 : : {
708 : 689 : gcc_assert (outer);
709 : 689 : splay_tree_node n
710 : 1378 : = splay_tree_lookup (outer->field_map,
711 : 689 : (splay_tree_key) &DECL_UID (var));
712 : 689 : if (n == NULL)
713 : : {
714 : 610 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, outer)))
715 : : x = var;
716 : : else
717 : 384 : x = lookup_decl (var, outer);
718 : : }
719 : : else
720 : : {
721 : 79 : tree field = (tree) n->value;
722 : : /* If the receiver record type was remapped in the child function,
723 : : remap the field into the new record type. */
724 : 79 : x = maybe_lookup_field (field, outer);
725 : 79 : if (x != NULL)
726 : 0 : field = x;
727 : :
728 : 79 : x = build_simple_mem_ref (outer->receiver_decl);
729 : 79 : x = omp_build_component_ref (x, field);
730 : 79 : if (use_pointer_for_field (var, outer))
731 : 59 : x = build_simple_mem_ref (x);
732 : : }
733 : : }
734 : 12341 : else if (outer)
735 : 12149 : x = lookup_decl (var, outer);
736 : 192 : else if (omp_privatize_by_reference (var))
737 : : /* This can happen with orphaned constructs. If var is reference, it is
738 : : possible it is shared and as such valid. */
739 : : x = var;
740 : 94 : else if (omp_member_access_dummy_var (var))
741 : : x = var;
742 : : else
743 : 0 : gcc_unreachable ();
744 : :
745 : 114302 : if (x == var)
746 : : {
747 : 16277 : tree t = omp_member_access_dummy_var (var);
748 : 16277 : if (t)
749 : : {
750 : 220 : x = DECL_VALUE_EXPR (var);
751 : 220 : tree o = maybe_lookup_decl_in_outer_ctx (t, ctx);
752 : 220 : if (o != t)
753 : 54 : x = unshare_and_remap (x, t, o);
754 : : else
755 : 166 : x = unshare_expr (x);
756 : : }
757 : : }
758 : :
759 : 114302 : if (omp_privatize_by_reference (var))
760 : 3080 : x = build_simple_mem_ref (x);
761 : :
762 : 114302 : return x;
763 : : }
764 : :
765 : : /* Build tree nodes to access the field for VAR on the sender side. */
766 : :
767 : : static tree
768 : 164826 : build_sender_ref (splay_tree_key key, omp_context *ctx)
769 : : {
770 : 164826 : tree field = lookup_sfield (key, ctx);
771 : 164826 : tree tmp = ctx->sender_decl;
772 : 164826 : if (POINTER_TYPE_P (TREE_TYPE (tmp)))
773 : 431 : tmp = build_fold_indirect_ref (tmp);
774 : 164826 : return omp_build_component_ref (tmp, field);
775 : : }
776 : :
777 : : static tree
778 : 160682 : build_sender_ref (tree var, omp_context *ctx)
779 : : {
780 : 0 : return build_sender_ref ((splay_tree_key) var, ctx);
781 : : }
782 : :
783 : : /* Add a new field for VAR inside the structure CTX->SENDER_DECL. If
784 : : BASE_POINTERS_RESTRICT, declare the field with restrict. */
785 : :
786 : : static void
787 : 129663 : install_var_field (tree var, bool by_ref, int mask, omp_context *ctx)
788 : : {
789 : 129663 : tree field, type, sfield = NULL_TREE;
790 : 129663 : splay_tree_key key = (splay_tree_key) var;
791 : :
792 : 129663 : if ((mask & 16) != 0)
793 : : {
794 : 619 : key = (splay_tree_key) &DECL_NAME (var);
795 : 619 : gcc_checking_assert (key != (splay_tree_key) var);
796 : : }
797 : 129663 : if ((mask & 8) != 0)
798 : : {
799 : 1614 : key = (splay_tree_key) &DECL_UID (var);
800 : 1614 : gcc_checking_assert (key != (splay_tree_key) var);
801 : : }
802 : 129663 : gcc_assert ((mask & 1) == 0
803 : : || !splay_tree_lookup (ctx->field_map, key));
804 : 129663 : gcc_assert ((mask & 2) == 0 || !ctx->sfield_map
805 : : || !splay_tree_lookup (ctx->sfield_map, key));
806 : 129663 : gcc_assert ((mask & 3) == 3
807 : : || !is_gimple_omp_oacc (ctx->stmt));
808 : :
809 : 129663 : type = TREE_TYPE (var);
810 : 129663 : if ((mask & 16) != 0)
811 : 619 : type = lang_hooks.decls.omp_array_data (var, true);
812 : :
813 : : /* Prevent redeclaring the var in the split-off function with a restrict
814 : : pointer type. Note that we only clear type itself, restrict qualifiers in
815 : : the pointed-to type will be ignored by points-to analysis. */
816 : 129663 : if (POINTER_TYPE_P (type)
817 : 129663 : && TYPE_RESTRICT (type))
818 : 6907 : type = build_qualified_type (type, TYPE_QUALS (type) & ~TYPE_QUAL_RESTRICT);
819 : :
820 : 129663 : if (mask & 4)
821 : : {
822 : 425 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
823 : 425 : type = build_pointer_type (build_pointer_type (type));
824 : : }
825 : 129238 : else if (by_ref)
826 : 62670 : type = build_pointer_type (type);
827 : 66568 : else if ((mask & (32 | 3)) == 1
828 : 66568 : && omp_privatize_by_reference (var))
829 : 162 : type = TREE_TYPE (type);
830 : :
831 : 129663 : field = build_decl (DECL_SOURCE_LOCATION (var),
832 : 129663 : FIELD_DECL, DECL_NAME (var), type);
833 : :
834 : : /* Remember what variable this field was created for. This does have a
835 : : side effect of making dwarf2out ignore this member, so for helpful
836 : : debugging we clear it later in delete_omp_context. */
837 : 129663 : DECL_ABSTRACT_ORIGIN (field) = var;
838 : 129663 : if ((mask & 16) == 0 && type == TREE_TYPE (var))
839 : : {
840 : 62117 : SET_DECL_ALIGN (field, DECL_ALIGN (var));
841 : 62117 : DECL_USER_ALIGN (field) = DECL_USER_ALIGN (var);
842 : 62117 : TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (var);
843 : : }
844 : : else
845 : 67546 : SET_DECL_ALIGN (field, TYPE_ALIGN (type));
846 : :
847 : 129663 : if ((mask & 3) == 3)
848 : : {
849 : 128611 : insert_field_into_struct (ctx->record_type, field);
850 : 128611 : if (ctx->srecord_type)
851 : : {
852 : 678 : sfield = build_decl (DECL_SOURCE_LOCATION (var),
853 : 678 : FIELD_DECL, DECL_NAME (var), type);
854 : 678 : DECL_ABSTRACT_ORIGIN (sfield) = var;
855 : 678 : SET_DECL_ALIGN (sfield, DECL_ALIGN (field));
856 : 678 : DECL_USER_ALIGN (sfield) = DECL_USER_ALIGN (field);
857 : 678 : TREE_THIS_VOLATILE (sfield) = TREE_THIS_VOLATILE (field);
858 : 678 : insert_field_into_struct (ctx->srecord_type, sfield);
859 : : }
860 : : }
861 : : else
862 : : {
863 : 1052 : if (ctx->srecord_type == NULL_TREE)
864 : : {
865 : 544 : tree t;
866 : :
867 : 544 : ctx->srecord_type = lang_hooks.types.make_type (RECORD_TYPE);
868 : 544 : ctx->sfield_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
869 : 2027 : for (t = TYPE_FIELDS (ctx->record_type); t ; t = TREE_CHAIN (t))
870 : : {
871 : 1483 : sfield = build_decl (DECL_SOURCE_LOCATION (t),
872 : 1483 : FIELD_DECL, DECL_NAME (t), TREE_TYPE (t));
873 : 1483 : DECL_ABSTRACT_ORIGIN (sfield) = DECL_ABSTRACT_ORIGIN (t);
874 : 1483 : insert_field_into_struct (ctx->srecord_type, sfield);
875 : 2966 : splay_tree_insert (ctx->sfield_map,
876 : 1483 : (splay_tree_key) DECL_ABSTRACT_ORIGIN (t),
877 : : (splay_tree_value) sfield);
878 : : }
879 : : }
880 : 1052 : sfield = field;
881 : 1052 : insert_field_into_struct ((mask & 1) ? ctx->record_type
882 : : : ctx->srecord_type, field);
883 : : }
884 : :
885 : 129663 : if (mask & 1)
886 : 129276 : splay_tree_insert (ctx->field_map, key, (splay_tree_value) field);
887 : 129663 : if ((mask & 2) && ctx->sfield_map)
888 : 1065 : splay_tree_insert (ctx->sfield_map, key, (splay_tree_value) sfield);
889 : 129663 : }
890 : :
891 : : static tree
892 : 227786 : install_var_local (tree var, omp_context *ctx)
893 : : {
894 : 227786 : tree new_var = omp_copy_decl_1 (var, ctx);
895 : 227786 : insert_decl_map (&ctx->cb, var, new_var);
896 : 227786 : return new_var;
897 : : }
898 : :
899 : : /* Adjust the replacement for DECL in CTX for the new context. This means
900 : : copying the DECL_VALUE_EXPR, and fixing up the type. */
901 : :
902 : : static void
903 : 203065 : fixup_remapped_decl (tree decl, omp_context *ctx, bool private_debug)
904 : : {
905 : 203065 : tree new_decl, size;
906 : :
907 : 203065 : new_decl = lookup_decl (decl, ctx);
908 : :
909 : 203065 : TREE_TYPE (new_decl) = remap_type (TREE_TYPE (decl), &ctx->cb);
910 : :
911 : 405001 : if ((!TREE_CONSTANT (DECL_SIZE (new_decl)) || private_debug)
912 : 203254 : && DECL_HAS_VALUE_EXPR_P (decl))
913 : : {
914 : 1318 : tree ve = DECL_VALUE_EXPR (decl);
915 : 1318 : walk_tree (&ve, copy_tree_body_r, &ctx->cb, NULL);
916 : 1318 : SET_DECL_VALUE_EXPR (new_decl, ve);
917 : 1318 : DECL_HAS_VALUE_EXPR_P (new_decl) = 1;
918 : : }
919 : :
920 : 203065 : if (!TREE_CONSTANT (DECL_SIZE (new_decl)))
921 : : {
922 : 1129 : size = remap_decl (DECL_SIZE (decl), &ctx->cb);
923 : 1129 : if (size == error_mark_node)
924 : 316 : size = TYPE_SIZE (TREE_TYPE (new_decl));
925 : 1129 : DECL_SIZE (new_decl) = size;
926 : :
927 : 1129 : size = remap_decl (DECL_SIZE_UNIT (decl), &ctx->cb);
928 : 1129 : if (size == error_mark_node)
929 : 303 : size = TYPE_SIZE_UNIT (TREE_TYPE (new_decl));
930 : 1129 : DECL_SIZE_UNIT (new_decl) = size;
931 : : }
932 : 203065 : }
933 : :
934 : : /* The callback for remap_decl. Search all containing contexts for a
935 : : mapping of the variable; this avoids having to duplicate the splay
936 : : tree ahead of time. We know a mapping doesn't already exist in the
937 : : given context. Create new mappings to implement default semantics. */
938 : :
939 : : static tree
940 : 460146 : omp_copy_decl (tree var, copy_body_data *cb)
941 : : {
942 : 460146 : omp_context *ctx = (omp_context *) cb;
943 : 460146 : tree new_var;
944 : :
945 : 460146 : if (TREE_CODE (var) == LABEL_DECL)
946 : : {
947 : 185401 : if (FORCED_LABEL (var) || DECL_NONLOCAL (var))
948 : : return var;
949 : 185395 : new_var = create_artificial_label (DECL_SOURCE_LOCATION (var));
950 : 185395 : DECL_CONTEXT (new_var) = current_function_decl;
951 : 185395 : insert_decl_map (&ctx->cb, var, new_var);
952 : 185395 : return new_var;
953 : : }
954 : :
955 : 356641 : while (!is_taskreg_ctx (ctx))
956 : : {
957 : 337459 : ctx = ctx->outer;
958 : 337459 : if (ctx == NULL)
959 : : return var;
960 : 279507 : new_var = maybe_lookup_decl (var, ctx);
961 : 279507 : if (new_var)
962 : : return new_var;
963 : : }
964 : :
965 : 19182 : if (is_global_var (var) || decl_function_context (var) != ctx->cb.src_fn)
966 : 13349 : return var;
967 : :
968 : 5833 : return error_mark_node;
969 : : }
970 : :
971 : : /* Create a new context, with OUTER_CTX being the surrounding context. */
972 : :
973 : : static omp_context *
974 : 136614 : new_omp_context (gimple *stmt, omp_context *outer_ctx)
975 : : {
976 : 136614 : omp_context *ctx = XCNEW (omp_context);
977 : :
978 : 136614 : splay_tree_insert (all_contexts, (splay_tree_key) stmt,
979 : : (splay_tree_value) ctx);
980 : 136614 : ctx->stmt = stmt;
981 : :
982 : 136614 : if (outer_ctx)
983 : : {
984 : 74414 : ctx->outer = outer_ctx;
985 : 74414 : ctx->cb = outer_ctx->cb;
986 : 74414 : ctx->cb.block = NULL;
987 : 74414 : ctx->depth = outer_ctx->depth + 1;
988 : : }
989 : : else
990 : : {
991 : 62200 : ctx->cb.src_fn = current_function_decl;
992 : 62200 : ctx->cb.dst_fn = current_function_decl;
993 : 62200 : ctx->cb.src_node = cgraph_node::get (current_function_decl);
994 : 62200 : gcc_checking_assert (ctx->cb.src_node);
995 : 62200 : ctx->cb.dst_node = ctx->cb.src_node;
996 : 62200 : ctx->cb.src_cfun = cfun;
997 : 62200 : ctx->cb.copy_decl = omp_copy_decl;
998 : 62200 : ctx->cb.eh_lp_nr = 0;
999 : 62200 : ctx->cb.transform_call_graph_edges = CB_CGE_MOVE;
1000 : 62200 : ctx->cb.adjust_array_error_bounds = true;
1001 : 62200 : ctx->cb.dont_remap_vla_if_no_change = true;
1002 : 62200 : ctx->depth = 1;
1003 : : }
1004 : :
1005 : 136614 : ctx->cb.decl_map = new hash_map<tree, tree>;
1006 : :
1007 : 136614 : return ctx;
1008 : : }
1009 : :
1010 : : static gimple_seq maybe_catch_exception (gimple_seq);
1011 : :
1012 : : /* Finalize task copyfn. */
1013 : :
1014 : : static void
1015 : 504 : finalize_task_copyfn (gomp_task *task_stmt)
1016 : : {
1017 : 504 : struct function *child_cfun;
1018 : 504 : tree child_fn;
1019 : 504 : gimple_seq seq = NULL, new_seq;
1020 : 504 : gbind *bind;
1021 : :
1022 : 504 : child_fn = gimple_omp_task_copy_fn (task_stmt);
1023 : 504 : if (child_fn == NULL_TREE)
1024 : 0 : return;
1025 : :
1026 : 504 : child_cfun = DECL_STRUCT_FUNCTION (child_fn);
1027 : 504 : DECL_STRUCT_FUNCTION (child_fn)->curr_properties = cfun->curr_properties;
1028 : :
1029 : 504 : push_cfun (child_cfun);
1030 : 504 : bind = gimplify_body (child_fn, false);
1031 : 504 : gimple_seq_add_stmt (&seq, bind);
1032 : 504 : new_seq = maybe_catch_exception (seq);
1033 : 504 : if (new_seq != seq)
1034 : : {
1035 : 332 : bind = gimple_build_bind (NULL, new_seq, NULL);
1036 : 332 : seq = NULL;
1037 : 332 : gimple_seq_add_stmt (&seq, bind);
1038 : : }
1039 : 504 : gimple_set_body (child_fn, seq);
1040 : 504 : pop_cfun ();
1041 : :
1042 : : /* Inform the callgraph about the new function. */
1043 : 504 : cgraph_node *node = cgraph_node::get_create (child_fn);
1044 : 504 : node->parallelized_function = 1;
1045 : 504 : cgraph_node::add_new_function (child_fn, false);
1046 : : }
1047 : :
1048 : : /* Destroy a omp_context data structures. Called through the splay tree
1049 : : value delete callback. */
1050 : :
1051 : : static void
1052 : 136608 : delete_omp_context (splay_tree_value value)
1053 : : {
1054 : 136608 : omp_context *ctx = (omp_context *) value;
1055 : :
1056 : 273216 : delete ctx->cb.decl_map;
1057 : :
1058 : 136608 : if (ctx->field_map)
1059 : 68132 : splay_tree_delete (ctx->field_map);
1060 : 136608 : if (ctx->sfield_map)
1061 : 544 : splay_tree_delete (ctx->sfield_map);
1062 : :
1063 : : /* We hijacked DECL_ABSTRACT_ORIGIN earlier. We need to clear it before
1064 : : it produces corrupt debug information. */
1065 : 136608 : if (ctx->record_type)
1066 : : {
1067 : 52385 : tree t;
1068 : 217844 : for (t = TYPE_FIELDS (ctx->record_type); t ; t = DECL_CHAIN (t))
1069 : 165459 : DECL_ABSTRACT_ORIGIN (t) = NULL;
1070 : : }
1071 : 136608 : if (ctx->srecord_type)
1072 : : {
1073 : 544 : tree t;
1074 : 3092 : for (t = TYPE_FIELDS (ctx->srecord_type); t ; t = DECL_CHAIN (t))
1075 : 2548 : DECL_ABSTRACT_ORIGIN (t) = NULL;
1076 : : }
1077 : :
1078 : 136608 : if (ctx->task_reduction_map)
1079 : : {
1080 : 1164 : ctx->task_reductions.release ();
1081 : 2328 : delete ctx->task_reduction_map;
1082 : : }
1083 : :
1084 : 136881 : delete ctx->lastprivate_conditional_map;
1085 : 137913 : delete ctx->allocate_map;
1086 : :
1087 : 136608 : XDELETE (ctx);
1088 : 136608 : }
1089 : :
1090 : : /* Fix up RECEIVER_DECL with a type that has been remapped to the child
1091 : : context. */
1092 : :
1093 : : static void
1094 : 36116 : fixup_child_record_type (omp_context *ctx)
1095 : : {
1096 : 36116 : tree f, type = ctx->record_type;
1097 : :
1098 : 36116 : if (!ctx->receiver_decl)
1099 : : return;
1100 : : /* ??? It isn't sufficient to just call remap_type here, because
1101 : : variably_modified_type_p doesn't work the way we expect for
1102 : : record types. Testing each field for whether it needs remapping
1103 : : and creating a new record by hand works, however. */
1104 : 159427 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
1105 : 124535 : if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
1106 : : break;
1107 : 36116 : if (f)
1108 : : {
1109 : 1224 : tree name, new_fields = NULL;
1110 : :
1111 : 1224 : type = lang_hooks.types.make_type (RECORD_TYPE);
1112 : 1224 : name = DECL_NAME (TYPE_NAME (ctx->record_type));
1113 : 1224 : name = build_decl (DECL_SOURCE_LOCATION (ctx->receiver_decl),
1114 : : TYPE_DECL, name, type);
1115 : 1224 : TYPE_NAME (type) = name;
1116 : :
1117 : 13138 : for (f = TYPE_FIELDS (ctx->record_type); f ; f = DECL_CHAIN (f))
1118 : : {
1119 : 11914 : tree new_f = copy_node (f);
1120 : 11914 : DECL_CONTEXT (new_f) = type;
1121 : 11914 : TREE_TYPE (new_f) = remap_type (TREE_TYPE (f), &ctx->cb);
1122 : 11914 : DECL_CHAIN (new_f) = new_fields;
1123 : 11914 : walk_tree (&DECL_SIZE (new_f), copy_tree_body_r, &ctx->cb, NULL);
1124 : 11914 : walk_tree (&DECL_SIZE_UNIT (new_f), copy_tree_body_r,
1125 : : &ctx->cb, NULL);
1126 : 11914 : walk_tree (&DECL_FIELD_OFFSET (new_f), copy_tree_body_r,
1127 : : &ctx->cb, NULL);
1128 : 11914 : new_fields = new_f;
1129 : :
1130 : : /* Arrange to be able to look up the receiver field
1131 : : given the sender field. */
1132 : 11914 : splay_tree_insert (ctx->field_map, (splay_tree_key) f,
1133 : : (splay_tree_value) new_f);
1134 : : }
1135 : 1224 : TYPE_FIELDS (type) = nreverse (new_fields);
1136 : 1224 : layout_type (type);
1137 : : }
1138 : :
1139 : : /* In a target region we never modify any of the pointers in *.omp_data_i,
1140 : : so attempt to help the optimizers. */
1141 : 36116 : if (is_gimple_omp_offloaded (ctx->stmt))
1142 : 16989 : type = build_qualified_type (type, TYPE_QUAL_CONST);
1143 : :
1144 : 36116 : TREE_TYPE (ctx->receiver_decl)
1145 : 108348 : = build_qualified_type (flexible_array_type_p (type)
1146 : 89 : ? build_pointer_type (type)
1147 : 36027 : : build_reference_type (type), TYPE_QUAL_RESTRICT);
1148 : : }
1149 : :
1150 : : /* Instantiate decls as necessary in CTX to satisfy the data sharing
1151 : : specified by CLAUSES. */
1152 : :
1153 : : static void
1154 : 128777 : scan_sharing_clauses (tree clauses, omp_context *ctx)
1155 : : {
1156 : 128777 : tree c, decl;
1157 : 128777 : bool scan_array_reductions = false;
1158 : 128777 : bool flex_array_ptr = false;
1159 : :
1160 : 543999 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
1161 : 415222 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
1162 : 415222 : && (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
1163 : : /* omp_default_mem_alloc is 1 */
1164 : 1184 : || !integer_onep (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
1165 : 568 : || OMP_CLAUSE_ALLOCATE_ALIGN (c) != NULL_TREE))
1166 : : {
1167 : : /* The allocate clauses that appear on a target construct or on
1168 : : constructs in a target region must specify an allocator expression
1169 : : unless a requires directive with the dynamic_allocators clause
1170 : : is present in the same compilation unit. */
1171 : 1748 : if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
1172 : 1092 : && ((omp_requires_mask & OMP_REQUIRES_DYNAMIC_ALLOCATORS) == 0)
1173 : 2828 : && omp_maybe_offloaded_ctx (ctx))
1174 : 10 : error_at (OMP_CLAUSE_LOCATION (c), "%<allocate%> clause must"
1175 : : " specify an allocator here");
1176 : 1748 : if (ctx->allocate_map == NULL)
1177 : 1305 : ctx->allocate_map = new hash_map<tree, tree>;
1178 : 1748 : tree val = integer_zero_node;
1179 : 1748 : if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
1180 : 656 : val = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
1181 : 1748 : if (OMP_CLAUSE_ALLOCATE_ALIGN (c))
1182 : 199 : val = build_tree_list (val, OMP_CLAUSE_ALLOCATE_ALIGN (c));
1183 : 1748 : ctx->allocate_map->put (OMP_CLAUSE_DECL (c), val);
1184 : : }
1185 : :
1186 : 543999 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
1187 : : {
1188 : 415222 : bool by_ref;
1189 : :
1190 : 415222 : switch (OMP_CLAUSE_CODE (c))
1191 : : {
1192 : 73124 : case OMP_CLAUSE_PRIVATE:
1193 : 73124 : decl = OMP_CLAUSE_DECL (c);
1194 : 73124 : if (OMP_CLAUSE_PRIVATE_OUTER_REF (c))
1195 : 163 : goto do_private;
1196 : 72961 : else if (!is_variable_sized (decl))
1197 : 72600 : install_var_local (decl, ctx);
1198 : : break;
1199 : :
1200 : 46738 : case OMP_CLAUSE_SHARED:
1201 : 46738 : decl = OMP_CLAUSE_DECL (c);
1202 : 46738 : if (ctx->allocate_map && ctx->allocate_map->get (decl))
1203 : 37 : ctx->allocate_map->remove (decl);
1204 : : /* Ignore shared directives in teams construct inside of
1205 : : target construct. */
1206 : 46738 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
1207 : 46738 : && !is_host_teams_ctx (ctx))
1208 : : {
1209 : : /* Global variables don't need to be copied,
1210 : : the receiver side will use them directly. */
1211 : 11856 : tree odecl = maybe_lookup_decl_in_outer_ctx (decl, ctx);
1212 : 11856 : if (is_global_var (odecl))
1213 : : break;
1214 : 8127 : insert_decl_map (&ctx->cb, decl, odecl);
1215 : 8127 : break;
1216 : : }
1217 : 34882 : gcc_assert (is_taskreg_ctx (ctx));
1218 : 34882 : gcc_assert (!COMPLETE_TYPE_P (TREE_TYPE (decl))
1219 : : || !is_variable_sized (decl));
1220 : : /* Global variables don't need to be copied,
1221 : : the receiver side will use them directly. */
1222 : 34882 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
1223 : : break;
1224 : 28833 : if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
1225 : : {
1226 : 86 : use_pointer_for_field (decl, ctx);
1227 : 86 : break;
1228 : : }
1229 : 28747 : by_ref = use_pointer_for_field (decl, NULL);
1230 : 55029 : if ((! TREE_READONLY (decl) && !OMP_CLAUSE_SHARED_READONLY (c))
1231 : 19251 : || TREE_ADDRESSABLE (decl)
1232 : 18894 : || by_ref
1233 : 47641 : || omp_privatize_by_reference (decl))
1234 : : {
1235 : 11964 : by_ref = use_pointer_for_field (decl, ctx);
1236 : 11964 : install_var_field (decl, by_ref, 3, ctx);
1237 : 11964 : install_var_local (decl, ctx);
1238 : 11964 : break;
1239 : : }
1240 : : /* We don't need to copy const scalar vars back. */
1241 : 16783 : OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_FIRSTPRIVATE);
1242 : 16783 : goto do_private;
1243 : :
1244 : 14499 : case OMP_CLAUSE_REDUCTION:
1245 : : /* Collect 'reduction' clauses on OpenACC compute construct. */
1246 : 14499 : if (is_gimple_omp_oacc (ctx->stmt)
1247 : 14499 : && is_gimple_omp_offloaded (ctx->stmt))
1248 : : {
1249 : : /* No 'reduction' clauses on OpenACC 'kernels'. */
1250 : 790 : gcc_checking_assert (!is_oacc_kernels (ctx));
1251 : : /* Likewise, on OpenACC 'kernels' decomposed parts. */
1252 : 790 : gcc_checking_assert (!is_oacc_kernels_decomposed_part (ctx));
1253 : :
1254 : 790 : ctx->local_reduction_clauses
1255 : 790 : = tree_cons (NULL, c, ctx->local_reduction_clauses);
1256 : : }
1257 : : /* FALLTHRU */
1258 : :
1259 : 16573 : case OMP_CLAUSE_IN_REDUCTION:
1260 : 16573 : decl = OMP_CLAUSE_DECL (c);
1261 : 16573 : if (ctx->allocate_map
1262 : 16573 : && ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
1263 : 389 : && (OMP_CLAUSE_REDUCTION_INSCAN (c)
1264 : 389 : || OMP_CLAUSE_REDUCTION_TASK (c)))
1265 : 397 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
1266 : 389 : || is_task_ctx (ctx)))
1267 : : {
1268 : : /* For now. */
1269 : 17 : if (ctx->allocate_map->get (decl))
1270 : 17 : ctx->allocate_map->remove (decl);
1271 : : }
1272 : 16573 : if (TREE_CODE (decl) == MEM_REF)
1273 : : {
1274 : 2366 : tree t = TREE_OPERAND (decl, 0);
1275 : 2366 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
1276 : 436 : t = TREE_OPERAND (t, 0);
1277 : 2366 : if (INDIRECT_REF_P (t)
1278 : 2272 : || TREE_CODE (t) == ADDR_EXPR)
1279 : 1378 : t = TREE_OPERAND (t, 0);
1280 : 2366 : if (is_omp_target (ctx->stmt))
1281 : : {
1282 : 96 : if (is_variable_sized (t))
1283 : : {
1284 : 32 : gcc_assert (DECL_HAS_VALUE_EXPR_P (t));
1285 : 32 : t = DECL_VALUE_EXPR (t);
1286 : 32 : gcc_assert (INDIRECT_REF_P (t));
1287 : 32 : t = TREE_OPERAND (t, 0);
1288 : 32 : gcc_assert (DECL_P (t));
1289 : : }
1290 : 96 : tree at = t;
1291 : 96 : if (ctx->outer)
1292 : 96 : scan_omp_op (&at, ctx->outer);
1293 : 96 : tree nt = omp_copy_decl_1 (at, ctx->outer);
1294 : 192 : splay_tree_insert (ctx->field_map,
1295 : 96 : (splay_tree_key) &DECL_CONTEXT (t),
1296 : : (splay_tree_value) nt);
1297 : 96 : if (at != t)
1298 : 96 : splay_tree_insert (ctx->field_map,
1299 : 48 : (splay_tree_key) &DECL_CONTEXT (at),
1300 : : (splay_tree_value) nt);
1301 : 96 : break;
1302 : : }
1303 : 2270 : install_var_local (t, ctx);
1304 : 2270 : if (is_taskreg_ctx (ctx)
1305 : 1822 : && (!is_global_var (maybe_lookup_decl_in_outer_ctx (t, ctx))
1306 : 387 : || (is_task_ctx (ctx)
1307 : 310 : && (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
1308 : 234 : || (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE
1309 : 0 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
1310 : : == POINTER_TYPE)))))
1311 : 1511 : && !is_variable_sized (t)
1312 : 3722 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
1313 : 617 : || (!OMP_CLAUSE_REDUCTION_TASK (c)
1314 : 578 : && !is_task_ctx (ctx))))
1315 : : {
1316 : 1335 : by_ref = use_pointer_for_field (t, NULL);
1317 : 1335 : if (is_task_ctx (ctx)
1318 : 835 : && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE
1319 : 1495 : && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == POINTER_TYPE)
1320 : : {
1321 : 32 : install_var_field (t, false, 1, ctx);
1322 : 32 : install_var_field (t, by_ref, 2, ctx);
1323 : : }
1324 : : else
1325 : 1303 : install_var_field (t, by_ref, 3, ctx);
1326 : : }
1327 : : break;
1328 : : }
1329 : 14207 : if (is_omp_target (ctx->stmt))
1330 : : {
1331 : 335 : tree at = decl;
1332 : 335 : if (ctx->outer)
1333 : 54 : scan_omp_op (&at, ctx->outer);
1334 : 335 : tree nt = omp_copy_decl_1 (at, ctx->outer);
1335 : 670 : splay_tree_insert (ctx->field_map,
1336 : 335 : (splay_tree_key) &DECL_CONTEXT (decl),
1337 : : (splay_tree_value) nt);
1338 : 335 : if (at != decl)
1339 : 24 : splay_tree_insert (ctx->field_map,
1340 : 12 : (splay_tree_key) &DECL_CONTEXT (at),
1341 : : (splay_tree_value) nt);
1342 : 335 : break;
1343 : : }
1344 : 13872 : if (is_task_ctx (ctx)
1345 : 26674 : || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
1346 : 12802 : && OMP_CLAUSE_REDUCTION_TASK (c)
1347 : 372 : && is_parallel_ctx (ctx)))
1348 : : {
1349 : : /* Global variables don't need to be copied,
1350 : : the receiver side will use them directly. */
1351 : 1149 : if (!is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
1352 : : {
1353 : 461 : by_ref = use_pointer_for_field (decl, ctx);
1354 : 461 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
1355 : 304 : install_var_field (decl, by_ref, 3, ctx);
1356 : : }
1357 : 1149 : install_var_local (decl, ctx);
1358 : 1149 : break;
1359 : : }
1360 : 12723 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
1361 : 12723 : && OMP_CLAUSE_REDUCTION_TASK (c))
1362 : : {
1363 : 293 : install_var_local (decl, ctx);
1364 : 293 : break;
1365 : : }
1366 : 12430 : goto do_private;
1367 : :
1368 : 22736 : case OMP_CLAUSE_LASTPRIVATE:
1369 : : /* Let the corresponding firstprivate clause create
1370 : : the variable. */
1371 : 22736 : if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
1372 : : break;
1373 : : /* FALLTHRU */
1374 : :
1375 : 58849 : case OMP_CLAUSE_FIRSTPRIVATE:
1376 : 58849 : case OMP_CLAUSE_LINEAR:
1377 : 58849 : decl = OMP_CLAUSE_DECL (c);
1378 : 88597 : do_private:
1379 : 88597 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
1380 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR
1381 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
1382 : 45237 : && is_gimple_omp_offloaded (ctx->stmt))
1383 : : {
1384 : 15807 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
1385 : 15807 : || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
1386 : 225 : && lang_hooks.decls.omp_array_data (decl, true)))
1387 : : {
1388 : 15448 : by_ref = !omp_privatize_by_reference (decl);
1389 : 15448 : install_var_field (decl, by_ref, 3, ctx);
1390 : : }
1391 : 359 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
1392 : : {
1393 : 212 : if (INDIRECT_REF_P (decl))
1394 : 0 : decl = TREE_OPERAND (decl, 0);
1395 : 212 : install_var_field (decl, true, 3, ctx);
1396 : : }
1397 : 147 : else if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1398 : 8 : install_var_field (decl, true, 3, ctx);
1399 : : else
1400 : 139 : install_var_field (decl, false, 3, ctx);
1401 : : }
1402 : 88597 : if (is_variable_sized (decl))
1403 : : {
1404 : 58 : if (is_task_ctx (ctx))
1405 : : {
1406 : 14 : if (ctx->allocate_map
1407 : 14 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
1408 : : {
1409 : : /* For now. */
1410 : 0 : if (ctx->allocate_map->get (decl))
1411 : 0 : ctx->allocate_map->remove (decl);
1412 : : }
1413 : 14 : install_var_field (decl, false, 1, ctx);
1414 : : }
1415 : : break;
1416 : : }
1417 : 88539 : else if (is_taskreg_ctx (ctx))
1418 : : {
1419 : 38252 : bool global
1420 : 38252 : = is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx));
1421 : 38252 : by_ref = use_pointer_for_field (decl, NULL);
1422 : :
1423 : 38252 : if (is_task_ctx (ctx)
1424 : 38252 : && (global || by_ref || omp_privatize_by_reference (decl)))
1425 : : {
1426 : 619 : if (ctx->allocate_map
1427 : 619 : && ctx->allocate_map->get (decl))
1428 : 59 : install_var_field (decl, by_ref, 32 | 1, ctx);
1429 : : else
1430 : 560 : install_var_field (decl, false, 1, ctx);
1431 : 619 : if (!global)
1432 : 355 : install_var_field (decl, by_ref, 2, ctx);
1433 : : }
1434 : 37633 : else if (!global)
1435 : 36370 : install_var_field (decl, by_ref, 3, ctx);
1436 : : }
1437 : 88539 : install_var_local (decl, ctx);
1438 : : /* For descr arrays on target: firstprivatize data + attach ptr. */
1439 : 88539 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
1440 : 44820 : && is_gimple_omp_offloaded (ctx->stmt)
1441 : 15431 : && !is_gimple_omp_oacc (ctx->stmt)
1442 : 99722 : && lang_hooks.decls.omp_array_data (decl, true))
1443 : : {
1444 : 18 : install_var_field (decl, false, 16 | 3, ctx);
1445 : 18 : install_var_field (decl, true, 8 | 3, ctx);
1446 : : }
1447 : : break;
1448 : :
1449 : 2118 : case OMP_CLAUSE_USE_DEVICE_PTR:
1450 : 2118 : case OMP_CLAUSE_USE_DEVICE_ADDR:
1451 : 2118 : decl = OMP_CLAUSE_DECL (c);
1452 : :
1453 : : /* Fortran array descriptors. */
1454 : 2118 : if (lang_hooks.decls.omp_array_data (decl, true))
1455 : 601 : install_var_field (decl, false, 19, ctx);
1456 : 1517 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR
1457 : 1312 : && !omp_privatize_by_reference (decl)
1458 : 513 : && !omp_is_allocatable_or_ptr (decl))
1459 : 2454 : || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1460 : 407 : install_var_field (decl, true, 11, ctx);
1461 : : else
1462 : 1110 : install_var_field (decl, false, 11, ctx);
1463 : 2118 : if (DECL_SIZE (decl)
1464 : 2118 : && !poly_int_tree_p (DECL_SIZE (decl)))
1465 : : {
1466 : 6 : tree decl2 = DECL_VALUE_EXPR (decl);
1467 : 6 : gcc_assert (INDIRECT_REF_P (decl2));
1468 : 6 : decl2 = TREE_OPERAND (decl2, 0);
1469 : 6 : gcc_assert (DECL_P (decl2));
1470 : 6 : install_var_local (decl2, ctx);
1471 : : }
1472 : 2118 : install_var_local (decl, ctx);
1473 : 2118 : break;
1474 : :
1475 : 225 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
1476 : 225 : decl = OMP_CLAUSE_DECL (c);
1477 : 225 : while (INDIRECT_REF_P (decl)
1478 : 242 : || TREE_CODE (decl) == ARRAY_REF)
1479 : 17 : decl = TREE_OPERAND (decl, 0);
1480 : 225 : goto do_private;
1481 : :
1482 : 147 : case OMP_CLAUSE_IS_DEVICE_PTR:
1483 : 147 : decl = OMP_CLAUSE_DECL (c);
1484 : 147 : goto do_private;
1485 : :
1486 : 20104 : case OMP_CLAUSE__LOOPTEMP_:
1487 : 20104 : case OMP_CLAUSE__REDUCTEMP_:
1488 : 20104 : gcc_assert (is_taskreg_ctx (ctx));
1489 : 20104 : decl = OMP_CLAUSE_DECL (c);
1490 : 20104 : install_var_field (decl, false, 3, ctx);
1491 : 20104 : install_var_local (decl, ctx);
1492 : 20104 : break;
1493 : :
1494 : 892 : case OMP_CLAUSE_COPYPRIVATE:
1495 : 892 : case OMP_CLAUSE_COPYIN:
1496 : 892 : decl = OMP_CLAUSE_DECL (c);
1497 : 892 : by_ref = use_pointer_for_field (decl, NULL);
1498 : 892 : install_var_field (decl, by_ref, 3, ctx);
1499 : 892 : break;
1500 : :
1501 : 54052 : case OMP_CLAUSE_FINAL:
1502 : 54052 : case OMP_CLAUSE_IF:
1503 : 54052 : case OMP_CLAUSE_SELF:
1504 : 54052 : case OMP_CLAUSE_NUM_THREADS:
1505 : 54052 : case OMP_CLAUSE_NUM_TEAMS:
1506 : 54052 : case OMP_CLAUSE_THREAD_LIMIT:
1507 : 54052 : case OMP_CLAUSE_DEVICE:
1508 : 54052 : case OMP_CLAUSE_SCHEDULE:
1509 : 54052 : case OMP_CLAUSE_DIST_SCHEDULE:
1510 : 54052 : case OMP_CLAUSE_DEPEND:
1511 : 54052 : case OMP_CLAUSE_PRIORITY:
1512 : 54052 : case OMP_CLAUSE_GRAINSIZE:
1513 : 54052 : case OMP_CLAUSE_NUM_TASKS:
1514 : 54052 : case OMP_CLAUSE_NUM_GANGS:
1515 : 54052 : case OMP_CLAUSE_NUM_WORKERS:
1516 : 54052 : case OMP_CLAUSE_VECTOR_LENGTH:
1517 : 54052 : case OMP_CLAUSE_DETACH:
1518 : 54052 : case OMP_CLAUSE_FILTER:
1519 : 54052 : if (ctx->outer)
1520 : 17560 : scan_omp_op (&OMP_CLAUSE_OPERAND (c, 0), ctx->outer);
1521 : : break;
1522 : :
1523 : 85247 : case OMP_CLAUSE_TO:
1524 : 85247 : case OMP_CLAUSE_FROM:
1525 : 85247 : case OMP_CLAUSE_MAP:
1526 : 85247 : if (ctx->outer)
1527 : 15343 : scan_omp_op (&OMP_CLAUSE_SIZE (c), ctx->outer);
1528 : 85247 : decl = OMP_CLAUSE_DECL (c);
1529 : : /* If requested, make 'decl' addressable. */
1530 : 85247 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1531 : 85247 : && OMP_CLAUSE_MAP_DECL_MAKE_ADDRESSABLE (c))
1532 : : {
1533 : 433 : gcc_checking_assert (DECL_P (decl));
1534 : :
1535 : 433 : bool decl_addressable = TREE_ADDRESSABLE (decl);
1536 : 433 : if (!decl_addressable)
1537 : : {
1538 : 219 : if (!make_addressable_vars)
1539 : 131 : make_addressable_vars = BITMAP_ALLOC (NULL);
1540 : 219 : bitmap_set_bit (make_addressable_vars, DECL_UID (decl));
1541 : 219 : TREE_ADDRESSABLE (decl) = 1;
1542 : : }
1543 : :
1544 : 433 : if (dump_enabled_p ())
1545 : : {
1546 : 421 : location_t loc = OMP_CLAUSE_LOCATION (c);
1547 : 421 : const dump_user_location_t d_u_loc
1548 : 421 : = dump_user_location_t::from_location_t (loc);
1549 : : /* PR100695 "Format decoder, quoting in 'dump_printf' etc." */
1550 : : #if __GNUC__ >= 10
1551 : 421 : # pragma GCC diagnostic push
1552 : 421 : # pragma GCC diagnostic ignored "-Wformat"
1553 : : #endif
1554 : 421 : if (!decl_addressable)
1555 : 207 : dump_printf_loc (MSG_NOTE, d_u_loc,
1556 : : "variable %<%T%>"
1557 : : " made addressable\n",
1558 : : decl);
1559 : : else
1560 : 214 : dump_printf_loc (MSG_NOTE, d_u_loc,
1561 : : "variable %<%T%>"
1562 : : " already made addressable\n",
1563 : : decl);
1564 : : #if __GNUC__ >= 10
1565 : 421 : # pragma GCC diagnostic pop
1566 : : #endif
1567 : : }
1568 : :
1569 : : /* Done. */
1570 : 433 : OMP_CLAUSE_MAP_DECL_MAKE_ADDRESSABLE (c) = 0;
1571 : : }
1572 : : /* Global variables with "omp declare target" attribute
1573 : : don't need to be copied, the receiver side will use them
1574 : : directly. However, global variables with "omp declare target link"
1575 : : attribute need to be copied. Or when ALWAYS modifier is used. */
1576 : 85247 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1577 : 77590 : && DECL_P (decl)
1578 : 43280 : && ((OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
1579 : 39525 : && (OMP_CLAUSE_MAP_KIND (c)
1580 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
1581 : 39100 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
1582 : 38874 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)
1583 : 4466 : || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1584 : 39981 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_TO
1585 : 39870 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_FROM
1586 : 39851 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_TOFROM
1587 : 39363 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_PRESENT_TO
1588 : 39337 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_PRESENT_FROM
1589 : 39315 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_PRESENT_TOFROM
1590 : 39301 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_TO_PSET
1591 : 35351 : && is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx))
1592 : 7424 : && varpool_node::get_create (decl)->offloadable
1593 : 90501 : && !lookup_attribute ("omp declare target link",
1594 : 5254 : DECL_ATTRIBUTES (decl)))
1595 : : break;
1596 : 80017 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1597 : 80017 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER)
1598 : : {
1599 : : /* Ignore GOMP_MAP_POINTER kind for arrays in regions that are
1600 : : not offloaded; there is nothing to map for those. */
1601 : 10438 : if (!is_gimple_omp_offloaded (ctx->stmt)
1602 : 4972 : && !POINTER_TYPE_P (TREE_TYPE (decl))
1603 : 10702 : && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c))
1604 : : break;
1605 : : }
1606 : 79753 : if (!flex_array_ptr)
1607 : 79518 : flex_array_ptr = lang_hooks.decls.omp_deep_mapping_p (ctx->stmt, c);
1608 : 79753 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1609 : 72096 : && DECL_P (decl)
1610 : 37786 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
1611 : 37560 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
1612 : 80039 : && is_omp_target (ctx->stmt))
1613 : : {
1614 : : /* If this is an offloaded region, an attach operation should
1615 : : only exist when the pointer variable is mapped in a prior
1616 : : clause. An exception is if we have a reference (to pointer):
1617 : : in that case we should have mapped "*decl" in a previous
1618 : : mapping instead of "decl". Skip the assertion in that case.
1619 : : If we had an error, we may not have attempted to sort clauses
1620 : : properly, so avoid the test. */
1621 : 252 : if (TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
1622 : 220 : && is_gimple_omp_offloaded (ctx->stmt)
1623 : 322 : && !seen_error ())
1624 : 62 : gcc_assert
1625 : : (maybe_lookup_decl (decl, ctx)
1626 : : || (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx))
1627 : : && lookup_attribute ("omp declare target",
1628 : : DECL_ATTRIBUTES (decl))));
1629 : :
1630 : : /* By itself, attach/detach is generated as part of pointer
1631 : : variable mapping and should not create new variables in the
1632 : : offloaded region, however sender refs for it must be created
1633 : : for its address to be passed to the runtime. */
1634 : 252 : tree field
1635 : 252 : = build_decl (OMP_CLAUSE_LOCATION (c),
1636 : : FIELD_DECL, NULL_TREE, ptr_type_node);
1637 : 252 : SET_DECL_ALIGN (field, TYPE_ALIGN (ptr_type_node));
1638 : 252 : insert_field_into_struct (ctx->record_type, field);
1639 : : /* To not clash with a map of the pointer variable itself,
1640 : : attach/detach maps have their field looked up by the *clause*
1641 : : tree expression, not the decl. */
1642 : 252 : gcc_assert (!splay_tree_lookup (ctx->field_map,
1643 : : (splay_tree_key) c));
1644 : 252 : splay_tree_insert (ctx->field_map, (splay_tree_key) c,
1645 : : (splay_tree_value) field);
1646 : 252 : break;
1647 : : }
1648 : 79501 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1649 : 79501 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
1650 : 68091 : || (OMP_CLAUSE_MAP_KIND (c)
1651 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE)))
1652 : : {
1653 : 4178 : if (TREE_CODE (decl) == COMPONENT_REF
1654 : 4178 : || (INDIRECT_REF_P (decl)
1655 : 0 : && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
1656 : 0 : && (((TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
1657 : : == REFERENCE_TYPE)
1658 : 0 : || (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl, 0)))
1659 : : == POINTER_TYPE)))))
1660 : : break;
1661 : 4178 : if (DECL_SIZE (decl)
1662 : 4178 : && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1663 : : {
1664 : 710 : tree decl2 = DECL_VALUE_EXPR (decl);
1665 : 710 : gcc_assert (INDIRECT_REF_P (decl2));
1666 : 710 : decl2 = TREE_OPERAND (decl2, 0);
1667 : 710 : gcc_assert (DECL_P (decl2));
1668 : 710 : install_var_local (decl2, ctx);
1669 : : }
1670 : 4178 : install_var_local (decl, ctx);
1671 : 4178 : break;
1672 : : }
1673 : 75323 : if (DECL_P (decl))
1674 : : {
1675 : 39516 : if (DECL_SIZE (decl)
1676 : 39516 : && !poly_int_tree_p (DECL_SIZE (decl)))
1677 : : {
1678 : 0 : tree decl2 = DECL_VALUE_EXPR (decl);
1679 : 0 : gcc_assert (INDIRECT_REF_P (decl2));
1680 : 0 : decl2 = TREE_OPERAND (decl2, 0);
1681 : 0 : gcc_assert (DECL_P (decl2));
1682 : 0 : install_var_field (decl2, true, 3, ctx);
1683 : 0 : install_var_local (decl2, ctx);
1684 : 0 : install_var_local (decl, ctx);
1685 : : }
1686 : : else
1687 : : {
1688 : 39516 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
1689 : 33356 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
1690 : 5189 : && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c)
1691 : 44705 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1692 : 425 : install_var_field (decl, true, 7, ctx);
1693 : : else
1694 : 39091 : install_var_field (decl, true, 3, ctx);
1695 : 39516 : if (is_gimple_omp_offloaded (ctx->stmt)
1696 : 39516 : && !(is_gimple_omp_oacc (ctx->stmt)
1697 : 13841 : && OMP_CLAUSE_MAP_IN_REDUCTION (c)))
1698 : 23097 : install_var_local (decl, ctx);
1699 : : }
1700 : : }
1701 : : else
1702 : : {
1703 : 35807 : tree base = get_base_address (decl);
1704 : 35807 : tree nc = OMP_CLAUSE_CHAIN (c);
1705 : 35807 : if (DECL_P (base)
1706 : 8425 : && nc != NULL_TREE
1707 : 6064 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
1708 : 4984 : && OMP_CLAUSE_DECL (nc) == base
1709 : 1148 : && OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_POINTER
1710 : 36475 : && integer_zerop (OMP_CLAUSE_SIZE (nc)))
1711 : : {
1712 : 0 : OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c) = 1;
1713 : 0 : OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (nc) = 1;
1714 : : }
1715 : : else
1716 : : {
1717 : 35807 : if (ctx->outer)
1718 : : {
1719 : 7117 : scan_omp_op (&OMP_CLAUSE_DECL (c), ctx->outer);
1720 : 7117 : decl = OMP_CLAUSE_DECL (c);
1721 : : }
1722 : 35807 : gcc_assert (!splay_tree_lookup (ctx->field_map,
1723 : : (splay_tree_key) decl));
1724 : 35807 : tree field
1725 : 35807 : = build_decl (OMP_CLAUSE_LOCATION (c),
1726 : : FIELD_DECL, NULL_TREE, ptr_type_node);
1727 : 35807 : SET_DECL_ALIGN (field, TYPE_ALIGN (ptr_type_node));
1728 : 35807 : insert_field_into_struct (ctx->record_type, field);
1729 : 35807 : splay_tree_insert (ctx->field_map, (splay_tree_key) decl,
1730 : : (splay_tree_value) field);
1731 : : }
1732 : : }
1733 : : break;
1734 : :
1735 : 3973 : case OMP_CLAUSE_ORDER:
1736 : 3973 : ctx->order_concurrent = true;
1737 : 3973 : break;
1738 : :
1739 : 1907 : case OMP_CLAUSE_BIND:
1740 : 1907 : ctx->loop_p = true;
1741 : 1907 : break;
1742 : :
1743 : : case OMP_CLAUSE_NOWAIT:
1744 : : case OMP_CLAUSE_ORDERED:
1745 : : case OMP_CLAUSE_COLLAPSE:
1746 : : case OMP_CLAUSE_UNTIED:
1747 : : case OMP_CLAUSE_MERGEABLE:
1748 : : case OMP_CLAUSE_PROC_BIND:
1749 : : case OMP_CLAUSE_SAFELEN:
1750 : : case OMP_CLAUSE_SIMDLEN:
1751 : : case OMP_CLAUSE_THREADS:
1752 : : case OMP_CLAUSE_SIMD:
1753 : : case OMP_CLAUSE_NOGROUP:
1754 : : case OMP_CLAUSE_DEFAULTMAP:
1755 : : case OMP_CLAUSE_ASYNC:
1756 : : case OMP_CLAUSE_WAIT:
1757 : : case OMP_CLAUSE_GANG:
1758 : : case OMP_CLAUSE_WORKER:
1759 : : case OMP_CLAUSE_VECTOR:
1760 : : case OMP_CLAUSE_INDEPENDENT:
1761 : : case OMP_CLAUSE_AUTO:
1762 : : case OMP_CLAUSE_SEQ:
1763 : : case OMP_CLAUSE_TILE:
1764 : : case OMP_CLAUSE__SIMT_:
1765 : : case OMP_CLAUSE_DEFAULT:
1766 : : case OMP_CLAUSE_NONTEMPORAL:
1767 : : case OMP_CLAUSE_IF_PRESENT:
1768 : : case OMP_CLAUSE_FINALIZE:
1769 : : case OMP_CLAUSE_TASK_REDUCTION:
1770 : : case OMP_CLAUSE_ALLOCATE:
1771 : : case OMP_CLAUSE_DEVICE_TYPE:
1772 : : break;
1773 : :
1774 : 162 : case OMP_CLAUSE_ALIGNED:
1775 : 162 : decl = OMP_CLAUSE_DECL (c);
1776 : 162 : if (is_global_var (decl)
1777 : 162 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1778 : 86 : install_var_local (decl, ctx);
1779 : : break;
1780 : :
1781 : 361 : case OMP_CLAUSE__CONDTEMP_:
1782 : 361 : decl = OMP_CLAUSE_DECL (c);
1783 : 361 : if (is_parallel_ctx (ctx))
1784 : : {
1785 : 118 : install_var_field (decl, false, 3, ctx);
1786 : 118 : install_var_local (decl, ctx);
1787 : : }
1788 : 243 : else if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
1789 : 243 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD
1790 : 368 : && !OMP_CLAUSE__CONDTEMP__ITER (c))
1791 : 125 : install_var_local (decl, ctx);
1792 : : break;
1793 : :
1794 : : case OMP_CLAUSE_INIT:
1795 : : case OMP_CLAUSE_USE:
1796 : : case OMP_CLAUSE_DESTROY:
1797 : : break;
1798 : :
1799 : 0 : case OMP_CLAUSE__CACHE_:
1800 : 0 : case OMP_CLAUSE_NOHOST:
1801 : 0 : default:
1802 : 0 : gcc_unreachable ();
1803 : : }
1804 : : }
1805 : :
1806 : 543999 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
1807 : : {
1808 : 415222 : switch (OMP_CLAUSE_CODE (c))
1809 : : {
1810 : 22736 : case OMP_CLAUSE_LASTPRIVATE:
1811 : : /* Let the corresponding firstprivate clause create
1812 : : the variable. */
1813 : 22736 : if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))
1814 : 7245 : scan_array_reductions = true;
1815 : 22736 : if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
1816 : : break;
1817 : : /* FALLTHRU */
1818 : :
1819 : 149128 : case OMP_CLAUSE_FIRSTPRIVATE:
1820 : 149128 : case OMP_CLAUSE_PRIVATE:
1821 : 149128 : case OMP_CLAUSE_LINEAR:
1822 : 149128 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
1823 : 149128 : case OMP_CLAUSE_IS_DEVICE_PTR:
1824 : 149128 : decl = OMP_CLAUSE_DECL (c);
1825 : 149128 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
1826 : : {
1827 : 242 : while (INDIRECT_REF_P (decl)
1828 : 242 : || TREE_CODE (decl) == ARRAY_REF)
1829 : 17 : decl = TREE_OPERAND (decl, 0);
1830 : : }
1831 : :
1832 : 149128 : if (is_variable_sized (decl))
1833 : : {
1834 : 419 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
1835 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR
1836 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
1837 : 51 : && is_gimple_omp_offloaded (ctx->stmt))
1838 : : {
1839 : 10 : tree decl2 = DECL_VALUE_EXPR (decl);
1840 : 10 : gcc_assert (INDIRECT_REF_P (decl2));
1841 : 10 : decl2 = TREE_OPERAND (decl2, 0);
1842 : 10 : gcc_assert (DECL_P (decl2));
1843 : 10 : install_var_local (decl2, ctx);
1844 : 10 : fixup_remapped_decl (decl2, ctx, false);
1845 : : }
1846 : 419 : install_var_local (decl, ctx);
1847 : : }
1848 : 298256 : fixup_remapped_decl (decl, ctx,
1849 : 149128 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
1850 : 149128 : && OMP_CLAUSE_PRIVATE_DEBUG (c));
1851 : 149128 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
1852 : 149128 : && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c))
1853 : : scan_array_reductions = true;
1854 : : break;
1855 : :
1856 : 16573 : case OMP_CLAUSE_REDUCTION:
1857 : 16573 : case OMP_CLAUSE_IN_REDUCTION:
1858 : 16573 : decl = OMP_CLAUSE_DECL (c);
1859 : 16573 : if (TREE_CODE (decl) != MEM_REF && !is_omp_target (ctx->stmt))
1860 : : {
1861 : 13872 : if (is_variable_sized (decl))
1862 : 0 : install_var_local (decl, ctx);
1863 : 13872 : fixup_remapped_decl (decl, ctx, false);
1864 : : }
1865 : 16573 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
1866 : 2835 : scan_array_reductions = true;
1867 : : break;
1868 : :
1869 : 530 : case OMP_CLAUSE_TASK_REDUCTION:
1870 : 530 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
1871 : 2835 : scan_array_reductions = true;
1872 : : break;
1873 : :
1874 : 29955 : case OMP_CLAUSE_SHARED:
1875 : : /* Ignore shared directives in teams construct inside of
1876 : : target construct. */
1877 : 29955 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
1878 : 29955 : && !is_host_teams_ctx (ctx))
1879 : : break;
1880 : 18099 : decl = OMP_CLAUSE_DECL (c);
1881 : 18099 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
1882 : : break;
1883 : 12050 : if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
1884 : : {
1885 : 86 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl,
1886 : : ctx->outer)))
1887 : : break;
1888 : 79 : bool by_ref = use_pointer_for_field (decl, ctx);
1889 : 79 : install_var_field (decl, by_ref, 11, ctx);
1890 : 79 : break;
1891 : : }
1892 : 11964 : fixup_remapped_decl (decl, ctx, false);
1893 : 11964 : break;
1894 : :
1895 : 77590 : case OMP_CLAUSE_MAP:
1896 : 77590 : if (!is_gimple_omp_offloaded (ctx->stmt))
1897 : : break;
1898 : 52680 : decl = OMP_CLAUSE_DECL (c);
1899 : 52680 : if (DECL_P (decl)
1900 : 33087 : && ((OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
1901 : 29500 : && (OMP_CLAUSE_MAP_KIND (c)
1902 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE))
1903 : 4012 : || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1904 : 30242 : && is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx))
1905 : 60012 : && varpool_node::get_create (decl)->offloadable)
1906 : : break;
1907 : 46998 : if ((OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
1908 : 44834 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
1909 : 2164 : && is_omp_target (ctx->stmt)
1910 : 48953 : && !is_gimple_omp_offloaded (ctx->stmt))
1911 : : break;
1912 : 46998 : if (DECL_P (decl))
1913 : : {
1914 : 27405 : if ((OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
1915 : 24363 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
1916 : 6627 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
1917 : 28994 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
1918 : : {
1919 : 24 : tree new_decl = lookup_decl (decl, ctx);
1920 : 24 : TREE_TYPE (new_decl)
1921 : 48 : = remap_type (TREE_TYPE (decl), &ctx->cb);
1922 : : }
1923 : 27381 : else if (DECL_SIZE (decl)
1924 : 27381 : && !poly_int_tree_p (DECL_SIZE (decl)))
1925 : : {
1926 : 710 : tree decl2 = DECL_VALUE_EXPR (decl);
1927 : 710 : gcc_assert (INDIRECT_REF_P (decl2));
1928 : 710 : decl2 = TREE_OPERAND (decl2, 0);
1929 : 710 : gcc_assert (DECL_P (decl2));
1930 : 710 : fixup_remapped_decl (decl2, ctx, false);
1931 : 710 : fixup_remapped_decl (decl, ctx, true);
1932 : : }
1933 : : else
1934 : 26671 : fixup_remapped_decl (decl, ctx, false);
1935 : : }
1936 : : break;
1937 : :
1938 : : case OMP_CLAUSE_COPYPRIVATE:
1939 : : case OMP_CLAUSE_COPYIN:
1940 : : case OMP_CLAUSE_DEFAULT:
1941 : : case OMP_CLAUSE_IF:
1942 : : case OMP_CLAUSE_SELF:
1943 : : case OMP_CLAUSE_NUM_THREADS:
1944 : : case OMP_CLAUSE_NUM_TEAMS:
1945 : : case OMP_CLAUSE_THREAD_LIMIT:
1946 : : case OMP_CLAUSE_DEVICE:
1947 : : case OMP_CLAUSE_SCHEDULE:
1948 : : case OMP_CLAUSE_DIST_SCHEDULE:
1949 : : case OMP_CLAUSE_NOWAIT:
1950 : : case OMP_CLAUSE_ORDERED:
1951 : : case OMP_CLAUSE_COLLAPSE:
1952 : : case OMP_CLAUSE_UNTIED:
1953 : : case OMP_CLAUSE_FINAL:
1954 : : case OMP_CLAUSE_MERGEABLE:
1955 : : case OMP_CLAUSE_PROC_BIND:
1956 : : case OMP_CLAUSE_SAFELEN:
1957 : : case OMP_CLAUSE_SIMDLEN:
1958 : : case OMP_CLAUSE_ALIGNED:
1959 : : case OMP_CLAUSE_DEPEND:
1960 : : case OMP_CLAUSE_DETACH:
1961 : : case OMP_CLAUSE_ALLOCATE:
1962 : : case OMP_CLAUSE__LOOPTEMP_:
1963 : : case OMP_CLAUSE__REDUCTEMP_:
1964 : : case OMP_CLAUSE_TO:
1965 : : case OMP_CLAUSE_FROM:
1966 : : case OMP_CLAUSE_PRIORITY:
1967 : : case OMP_CLAUSE_GRAINSIZE:
1968 : : case OMP_CLAUSE_NUM_TASKS:
1969 : : case OMP_CLAUSE_THREADS:
1970 : : case OMP_CLAUSE_SIMD:
1971 : : case OMP_CLAUSE_NOGROUP:
1972 : : case OMP_CLAUSE_DEFAULTMAP:
1973 : : case OMP_CLAUSE_ORDER:
1974 : : case OMP_CLAUSE_BIND:
1975 : : case OMP_CLAUSE_USE_DEVICE_PTR:
1976 : : case OMP_CLAUSE_USE_DEVICE_ADDR:
1977 : : case OMP_CLAUSE_NONTEMPORAL:
1978 : : case OMP_CLAUSE_ASYNC:
1979 : : case OMP_CLAUSE_WAIT:
1980 : : case OMP_CLAUSE_NUM_GANGS:
1981 : : case OMP_CLAUSE_NUM_WORKERS:
1982 : : case OMP_CLAUSE_VECTOR_LENGTH:
1983 : : case OMP_CLAUSE_GANG:
1984 : : case OMP_CLAUSE_WORKER:
1985 : : case OMP_CLAUSE_VECTOR:
1986 : : case OMP_CLAUSE_INDEPENDENT:
1987 : : case OMP_CLAUSE_AUTO:
1988 : : case OMP_CLAUSE_SEQ:
1989 : : case OMP_CLAUSE_TILE:
1990 : : case OMP_CLAUSE__SIMT_:
1991 : : case OMP_CLAUSE_IF_PRESENT:
1992 : : case OMP_CLAUSE_FINALIZE:
1993 : : case OMP_CLAUSE_FILTER:
1994 : : case OMP_CLAUSE__CONDTEMP_:
1995 : : case OMP_CLAUSE_INIT:
1996 : : case OMP_CLAUSE_USE:
1997 : : case OMP_CLAUSE_DESTROY:
1998 : : case OMP_CLAUSE_DEVICE_TYPE:
1999 : : break;
2000 : :
2001 : 0 : case OMP_CLAUSE__CACHE_:
2002 : 0 : case OMP_CLAUSE_NOHOST:
2003 : 0 : default:
2004 : 0 : gcc_unreachable ();
2005 : : }
2006 : : }
2007 : :
2008 : 128777 : gcc_checking_assert (!scan_array_reductions
2009 : : || !is_gimple_omp_oacc (ctx->stmt));
2010 : : if (scan_array_reductions)
2011 : : {
2012 : 34615 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
2013 : 29430 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
2014 : 27051 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
2015 : 26427 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
2016 : 30134 : && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
2017 : : {
2018 : 2181 : omp_context *rctx = ctx;
2019 : 2181 : if (is_omp_target (ctx->stmt))
2020 : 60 : rctx = ctx->outer;
2021 : 2181 : scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c), rctx);
2022 : 2181 : scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), rctx);
2023 : : }
2024 : 27249 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
2025 : 27249 : && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))
2026 : 7245 : scan_omp (&OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c), ctx);
2027 : 20004 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
2028 : 20004 : && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c))
2029 : 654 : scan_omp (&OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c), ctx);
2030 : : }
2031 : 128777 : if (flex_array_ptr)
2032 : : {
2033 : 136 : tree field = build_range_type (size_type_node,
2034 : : build_int_cstu (size_type_node, 0),
2035 : : NULL_TREE);
2036 : 136 : field = build_array_type (ptr_type_node, field);
2037 : 136 : field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, field);
2038 : 136 : SET_DECL_ALIGN (field, TYPE_ALIGN (ptr_type_node));
2039 : 136 : DECL_CONTEXT (field) = ctx->record_type;
2040 : 136 : DECL_CHAIN (field) = TYPE_FIELDS (ctx->record_type);
2041 : 136 : TYPE_FIELDS (ctx->record_type) = field;
2042 : : }
2043 : 128777 : }
2044 : :
2045 : : /* Create a new name for omp child function. Returns an identifier. */
2046 : :
2047 : : static tree
2048 : 50775 : create_omp_child_function_name (bool task_copy)
2049 : : {
2050 : 101006 : return clone_function_name_numbered (current_function_decl,
2051 : 50775 : task_copy ? "_omp_cpyfn" : "_omp_fn");
2052 : : }
2053 : :
2054 : : /* Return true if CTX may belong to offloaded code: either if current function
2055 : : is offloaded, or any enclosing context corresponds to a target region. */
2056 : :
2057 : : static bool
2058 : 120785 : omp_maybe_offloaded_ctx (omp_context *ctx)
2059 : : {
2060 : 120785 : if (cgraph_node::get (current_function_decl)->offloadable)
2061 : : return true;
2062 : 201166 : for (; ctx; ctx = ctx->outer)
2063 : 119569 : if (is_gimple_omp_offloaded (ctx->stmt))
2064 : : return true;
2065 : : return false;
2066 : : }
2067 : :
2068 : : /* Build a decl for the omp child function. It'll not contain a body
2069 : : yet, just the bare decl. */
2070 : :
2071 : : static void
2072 : 50775 : create_omp_child_function (omp_context *ctx, bool task_copy)
2073 : : {
2074 : 50775 : tree decl, type, name, t;
2075 : :
2076 : 50775 : name = create_omp_child_function_name (task_copy);
2077 : 50775 : if (task_copy)
2078 : 544 : type = build_function_type_list (void_type_node, ptr_type_node,
2079 : : ptr_type_node, NULL_TREE);
2080 : : else
2081 : 50231 : type = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
2082 : :
2083 : 50775 : decl = build_decl (gimple_location (ctx->stmt), FUNCTION_DECL, name, type);
2084 : :
2085 : 50775 : gcc_checking_assert (!is_gimple_omp_oacc (ctx->stmt)
2086 : : || !task_copy);
2087 : 39393 : if (!task_copy)
2088 : 50231 : ctx->cb.dst_fn = decl;
2089 : : else
2090 : 544 : gimple_omp_task_set_copy_fn (ctx->stmt, decl);
2091 : :
2092 : 50775 : TREE_STATIC (decl) = 1;
2093 : 50775 : TREE_USED (decl) = 1;
2094 : 50775 : DECL_ARTIFICIAL (decl) = 1;
2095 : 50775 : DECL_IGNORED_P (decl) = 0;
2096 : 50775 : TREE_PUBLIC (decl) = 0;
2097 : 50775 : DECL_UNINLINABLE (decl) = 1;
2098 : 50775 : DECL_EXTERNAL (decl) = 0;
2099 : 50775 : DECL_CONTEXT (decl) = NULL_TREE;
2100 : 50775 : DECL_INITIAL (decl) = make_node (BLOCK);
2101 : 50775 : BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl;
2102 : 50775 : DECL_ATTRIBUTES (decl) = DECL_ATTRIBUTES (current_function_decl);
2103 : : /* Remove omp declare simd attribute from the new attributes. */
2104 : 50775 : if (tree a = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (decl)))
2105 : : {
2106 : 9 : while (tree a2 = lookup_attribute ("omp declare simd", TREE_CHAIN (a)))
2107 : : a = a2;
2108 : 9 : a = TREE_CHAIN (a);
2109 : 22 : for (tree *p = &DECL_ATTRIBUTES (decl); *p != a;)
2110 : 13 : if (is_attribute_p ("omp declare simd", get_attribute_name (*p)))
2111 : 9 : *p = TREE_CHAIN (*p);
2112 : : else
2113 : : {
2114 : 4 : tree chain = TREE_CHAIN (*p);
2115 : 4 : *p = copy_node (*p);
2116 : 4 : p = &TREE_CHAIN (*p);
2117 : 4 : *p = chain;
2118 : : }
2119 : : }
2120 : 101550 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
2121 : 50775 : = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (current_function_decl);
2122 : 101550 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
2123 : 50775 : = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl);
2124 : 101550 : DECL_FUNCTION_VERSIONED (decl)
2125 : 50775 : = DECL_FUNCTION_VERSIONED (current_function_decl);
2126 : :
2127 : 50775 : if (omp_maybe_offloaded_ctx (ctx))
2128 : : {
2129 : 30459 : cgraph_node::get_create (decl)->offloadable = 1;
2130 : 30459 : if (ENABLE_OFFLOADING)
2131 : : g->have_offload = true;
2132 : : }
2133 : :
2134 : 50775 : if (cgraph_node::get_create (decl)->offloadable)
2135 : : {
2136 : 30459 : const char *target_attr = (is_gimple_omp_offloaded (ctx->stmt)
2137 : 30459 : ? "omp target entrypoint"
2138 : 6194 : : "omp declare target");
2139 : 30459 : if (lookup_attribute ("omp declare target",
2140 : 30459 : DECL_ATTRIBUTES (current_function_decl)))
2141 : : {
2142 : 3028 : if (is_gimple_omp_offloaded (ctx->stmt))
2143 : 1620 : DECL_ATTRIBUTES (decl)
2144 : 1620 : = remove_attribute ("omp declare target",
2145 : 1620 : copy_list (DECL_ATTRIBUTES (decl)));
2146 : : else
2147 : : target_attr = NULL;
2148 : : }
2149 : 1620 : if (target_attr
2150 : 29051 : && is_gimple_omp_offloaded (ctx->stmt)
2151 : 24265 : && lookup_attribute ("noclone", DECL_ATTRIBUTES (decl)) == NULL_TREE)
2152 : 18759 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("noclone"),
2153 : 18759 : NULL_TREE, DECL_ATTRIBUTES (decl));
2154 : 30459 : if (target_attr)
2155 : 29051 : DECL_ATTRIBUTES (decl)
2156 : 58102 : = tree_cons (get_identifier (target_attr),
2157 : 29051 : NULL_TREE, DECL_ATTRIBUTES (decl));
2158 : : }
2159 : :
2160 : 50775 : t = build_decl (DECL_SOURCE_LOCATION (decl),
2161 : : RESULT_DECL, NULL_TREE, void_type_node);
2162 : 50775 : DECL_ARTIFICIAL (t) = 1;
2163 : 50775 : DECL_IGNORED_P (t) = 1;
2164 : 50775 : DECL_CONTEXT (t) = decl;
2165 : 50775 : DECL_RESULT (decl) = t;
2166 : :
2167 : 50775 : tree data_name = get_identifier (".omp_data_i");
2168 : 50775 : t = build_decl (DECL_SOURCE_LOCATION (decl), PARM_DECL, data_name,
2169 : : ptr_type_node);
2170 : 50775 : DECL_ARTIFICIAL (t) = 1;
2171 : 50775 : DECL_NAMELESS (t) = 1;
2172 : 50775 : DECL_ARG_TYPE (t) = ptr_type_node;
2173 : 50775 : DECL_CONTEXT (t) = current_function_decl;
2174 : 50775 : TREE_USED (t) = 1;
2175 : 50775 : TREE_READONLY (t) = 1;
2176 : 50775 : DECL_ARGUMENTS (decl) = t;
2177 : 50775 : if (!task_copy)
2178 : 50231 : ctx->receiver_decl = t;
2179 : : else
2180 : : {
2181 : 544 : t = build_decl (DECL_SOURCE_LOCATION (decl),
2182 : : PARM_DECL, get_identifier (".omp_data_o"),
2183 : : ptr_type_node);
2184 : 544 : DECL_ARTIFICIAL (t) = 1;
2185 : 544 : DECL_NAMELESS (t) = 1;
2186 : 544 : DECL_ARG_TYPE (t) = ptr_type_node;
2187 : 544 : DECL_CONTEXT (t) = current_function_decl;
2188 : 544 : TREE_USED (t) = 1;
2189 : 544 : TREE_ADDRESSABLE (t) = 1;
2190 : 544 : DECL_CHAIN (t) = DECL_ARGUMENTS (decl);
2191 : 544 : DECL_ARGUMENTS (decl) = t;
2192 : : }
2193 : :
2194 : : /* Allocate memory for the function structure. The call to
2195 : : allocate_struct_function clobbers CFUN, so we need to restore
2196 : : it afterward. */
2197 : 50775 : push_struct_function (decl);
2198 : 50775 : cfun->function_end_locus = gimple_location (ctx->stmt);
2199 : 50775 : init_tree_ssa (cfun);
2200 : 50775 : pop_cfun ();
2201 : 50775 : }
2202 : :
2203 : : /* Callback for walk_gimple_seq. Check if combined parallel
2204 : : contains gimple_omp_for_combined_into_p OMP_FOR. */
2205 : :
2206 : : tree
2207 : 35306 : omp_find_combined_for (gimple_stmt_iterator *gsi_p,
2208 : : bool *handled_ops_p,
2209 : : struct walk_stmt_info *wi)
2210 : : {
2211 : 35306 : gimple *stmt = gsi_stmt (*gsi_p);
2212 : :
2213 : 35306 : *handled_ops_p = true;
2214 : 35306 : switch (gimple_code (stmt))
2215 : : {
2216 : 19633 : WALK_SUBSTMTS;
2217 : :
2218 : 13499 : case GIMPLE_OMP_FOR:
2219 : 13499 : if (gimple_omp_for_combined_into_p (stmt)
2220 : 13499 : && gimple_omp_for_kind (stmt)
2221 : 7957 : == *(const enum gf_mask *) (wi->info))
2222 : : {
2223 : 7957 : wi->info = stmt;
2224 : 7957 : return integer_zero_node;
2225 : : }
2226 : : break;
2227 : : default:
2228 : : break;
2229 : : }
2230 : : return NULL;
2231 : : }
2232 : :
2233 : : /* Add _LOOPTEMP_/_REDUCTEMP_ clauses on OpenMP parallel or task. */
2234 : :
2235 : : static void
2236 : 14084 : add_taskreg_looptemp_clauses (enum gf_mask msk, gimple *stmt,
2237 : : omp_context *outer_ctx)
2238 : : {
2239 : 14084 : struct walk_stmt_info wi;
2240 : :
2241 : 14084 : memset (&wi, 0, sizeof (wi));
2242 : 14084 : wi.val_only = true;
2243 : 14084 : wi.info = (void *) &msk;
2244 : 14084 : walk_gimple_seq (gimple_omp_body (stmt), omp_find_combined_for, NULL, &wi);
2245 : 14084 : if (wi.info != (void *) &msk)
2246 : : {
2247 : 7957 : gomp_for *for_stmt = as_a <gomp_for *> ((gimple *) wi.info);
2248 : 7957 : struct omp_for_data fd;
2249 : 7957 : omp_extract_for_data (for_stmt, &fd, NULL);
2250 : : /* We need two temporaries with fd.loop.v type (istart/iend)
2251 : : and then (fd.collapse - 1) temporaries with the same
2252 : : type for count2 ... countN-1 vars if not constant. */
2253 : 7957 : size_t count = 2, i;
2254 : 7957 : tree type = fd.iter_type;
2255 : 7957 : if (fd.collapse > 1
2256 : 2645 : && TREE_CODE (fd.loop.n2) != INTEGER_CST)
2257 : : {
2258 : 1466 : count += fd.collapse - 1;
2259 : : /* If there are lastprivate clauses on the inner
2260 : : GIMPLE_OMP_FOR, add one more temporaries for the total number
2261 : : of iterations (product of count1 ... countN-1). */
2262 : 1466 : if (omp_find_clause (gimple_omp_for_clauses (for_stmt),
2263 : : OMP_CLAUSE_LASTPRIVATE)
2264 : 1466 : || (msk == GF_OMP_FOR_KIND_FOR
2265 : 1335 : && omp_find_clause (gimple_omp_parallel_clauses (stmt),
2266 : : OMP_CLAUSE_LASTPRIVATE)))
2267 : : {
2268 : 726 : tree temp = create_tmp_var (type);
2269 : 726 : tree c = build_omp_clause (UNKNOWN_LOCATION,
2270 : : OMP_CLAUSE__LOOPTEMP_);
2271 : 726 : insert_decl_map (&outer_ctx->cb, temp, temp);
2272 : 726 : OMP_CLAUSE_DECL (c) = temp;
2273 : 726 : OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2274 : 726 : gimple_omp_taskreg_set_clauses (stmt, c);
2275 : : }
2276 : 1466 : if (fd.non_rect
2277 : 24 : && fd.last_nonrect == fd.first_nonrect + 1)
2278 : 12 : if (tree v = gimple_omp_for_index (for_stmt, fd.last_nonrect))
2279 : 12 : if (!TYPE_UNSIGNED (TREE_TYPE (v)))
2280 : : {
2281 : 12 : v = gimple_omp_for_index (for_stmt, fd.first_nonrect);
2282 : 12 : tree type2 = TREE_TYPE (v);
2283 : 12 : count++;
2284 : 48 : for (i = 0; i < 3; i++)
2285 : : {
2286 : 36 : tree temp = create_tmp_var (type2);
2287 : 36 : tree c = build_omp_clause (UNKNOWN_LOCATION,
2288 : : OMP_CLAUSE__LOOPTEMP_);
2289 : 36 : insert_decl_map (&outer_ctx->cb, temp, temp);
2290 : 36 : OMP_CLAUSE_DECL (c) = temp;
2291 : 36 : OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2292 : 36 : gimple_omp_taskreg_set_clauses (stmt, c);
2293 : : }
2294 : : }
2295 : : }
2296 : 26716 : for (i = 0; i < count; i++)
2297 : : {
2298 : 18759 : tree temp = create_tmp_var (type);
2299 : 18759 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__LOOPTEMP_);
2300 : 18759 : insert_decl_map (&outer_ctx->cb, temp, temp);
2301 : 18759 : OMP_CLAUSE_DECL (c) = temp;
2302 : 18759 : OMP_CLAUSE_CHAIN (c) = gimple_omp_taskreg_clauses (stmt);
2303 : 18759 : gimple_omp_taskreg_set_clauses (stmt, c);
2304 : : }
2305 : : }
2306 : 14084 : if (msk == GF_OMP_FOR_KIND_TASKLOOP
2307 : 15651 : && omp_find_clause (gimple_omp_task_clauses (stmt),
2308 : : OMP_CLAUSE_REDUCTION))
2309 : : {
2310 : 517 : tree type = build_pointer_type (pointer_sized_int_node);
2311 : 517 : tree temp = create_tmp_var (type);
2312 : 517 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
2313 : 517 : insert_decl_map (&outer_ctx->cb, temp, temp);
2314 : 517 : OMP_CLAUSE_DECL (c) = temp;
2315 : 517 : OMP_CLAUSE_CHAIN (c) = gimple_omp_task_clauses (stmt);
2316 : 517 : gimple_omp_task_set_clauses (stmt, c);
2317 : : }
2318 : 14084 : }
2319 : :
2320 : : /* Scan an OpenMP parallel directive. */
2321 : :
2322 : : static void
2323 : 18134 : scan_omp_parallel (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
2324 : : {
2325 : 18134 : omp_context *ctx;
2326 : 18134 : tree name;
2327 : 18134 : gomp_parallel *stmt = as_a <gomp_parallel *> (gsi_stmt (*gsi));
2328 : :
2329 : : /* Ignore parallel directives with empty bodies, unless there
2330 : : are copyin clauses. */
2331 : 18134 : if (optimize > 0
2332 : 12457 : && empty_body_p (gimple_omp_body (stmt))
2333 : 18179 : && omp_find_clause (gimple_omp_parallel_clauses (stmt),
2334 : : OMP_CLAUSE_COPYIN) == NULL)
2335 : : {
2336 : 39 : gsi_replace (gsi, gimple_build_nop (), false);
2337 : 39 : return;
2338 : : }
2339 : :
2340 : 18095 : if (gimple_omp_parallel_combined_p (stmt))
2341 : 12517 : add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_FOR, stmt, outer_ctx);
2342 : 18095 : for (tree c = omp_find_clause (gimple_omp_parallel_clauses (stmt),
2343 : : OMP_CLAUSE_REDUCTION);
2344 : 20923 : c; c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_REDUCTION))
2345 : 3906 : if (OMP_CLAUSE_REDUCTION_TASK (c))
2346 : : {
2347 : 66 : tree type = build_pointer_type (pointer_sized_int_node);
2348 : 66 : tree temp = create_tmp_var (type);
2349 : 66 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
2350 : 66 : if (outer_ctx)
2351 : 17 : insert_decl_map (&outer_ctx->cb, temp, temp);
2352 : 66 : OMP_CLAUSE_DECL (c) = temp;
2353 : 66 : OMP_CLAUSE_CHAIN (c) = gimple_omp_parallel_clauses (stmt);
2354 : 66 : gimple_omp_parallel_set_clauses (stmt, c);
2355 : 66 : break;
2356 : : }
2357 : 3840 : else if (OMP_CLAUSE_CHAIN (c) == NULL_TREE)
2358 : : break;
2359 : :
2360 : 18095 : ctx = new_omp_context (stmt, outer_ctx);
2361 : 18095 : taskreg_contexts.safe_push (ctx);
2362 : 18095 : if (taskreg_nesting_level > 1)
2363 : 6187 : ctx->is_nested = true;
2364 : 18095 : ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
2365 : 18095 : ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
2366 : 18095 : name = create_tmp_var_name (".omp_data_s");
2367 : 18095 : name = build_decl (gimple_location (stmt),
2368 : : TYPE_DECL, name, ctx->record_type);
2369 : 18095 : DECL_ARTIFICIAL (name) = 1;
2370 : 18095 : DECL_NAMELESS (name) = 1;
2371 : 18095 : TYPE_NAME (ctx->record_type) = name;
2372 : 18095 : TYPE_ARTIFICIAL (ctx->record_type) = 1;
2373 : 18095 : create_omp_child_function (ctx, false);
2374 : 18095 : gimple_omp_parallel_set_child_fn (stmt, ctx->cb.dst_fn);
2375 : :
2376 : 18095 : scan_sharing_clauses (gimple_omp_parallel_clauses (stmt), ctx);
2377 : 18095 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
2378 : :
2379 : 18095 : if (TYPE_FIELDS (ctx->record_type) == NULL)
2380 : 3559 : ctx->record_type = ctx->receiver_decl = NULL;
2381 : : }
2382 : :
2383 : : /* Scan an OpenMP task directive. */
2384 : :
2385 : : static void
2386 : 5365 : scan_omp_task (gimple_stmt_iterator *gsi, omp_context *outer_ctx)
2387 : : {
2388 : 5365 : omp_context *ctx;
2389 : 5365 : tree name, t;
2390 : 5365 : gomp_task *stmt = as_a <gomp_task *> (gsi_stmt (*gsi));
2391 : :
2392 : : /* Ignore task directives with empty bodies, unless they have depend
2393 : : clause. */
2394 : 5365 : if (optimize > 0
2395 : 2577 : && gimple_omp_body (stmt)
2396 : 2535 : && empty_body_p (gimple_omp_body (stmt))
2397 : 5417 : && !omp_find_clause (gimple_omp_task_clauses (stmt), OMP_CLAUSE_DEPEND))
2398 : : {
2399 : 19 : gsi_replace (gsi, gimple_build_nop (), false);
2400 : 128 : return;
2401 : : }
2402 : :
2403 : 5346 : if (gimple_omp_task_taskloop_p (stmt))
2404 : 1567 : add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_TASKLOOP, stmt, outer_ctx);
2405 : :
2406 : 5346 : ctx = new_omp_context (stmt, outer_ctx);
2407 : :
2408 : 5346 : if (gimple_omp_task_taskwait_p (stmt))
2409 : : {
2410 : 90 : scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx);
2411 : 90 : return;
2412 : : }
2413 : :
2414 : 5256 : taskreg_contexts.safe_push (ctx);
2415 : 5256 : if (taskreg_nesting_level > 1)
2416 : 2322 : ctx->is_nested = true;
2417 : 5256 : ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
2418 : 5256 : ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
2419 : 5256 : name = create_tmp_var_name (".omp_data_s");
2420 : 5256 : name = build_decl (gimple_location (stmt),
2421 : : TYPE_DECL, name, ctx->record_type);
2422 : 5256 : DECL_ARTIFICIAL (name) = 1;
2423 : 5256 : DECL_NAMELESS (name) = 1;
2424 : 5256 : TYPE_NAME (ctx->record_type) = name;
2425 : 5256 : TYPE_ARTIFICIAL (ctx->record_type) = 1;
2426 : 5256 : create_omp_child_function (ctx, false);
2427 : 5256 : gimple_omp_task_set_child_fn (stmt, ctx->cb.dst_fn);
2428 : :
2429 : 5256 : scan_sharing_clauses (gimple_omp_task_clauses (stmt), ctx);
2430 : :
2431 : 5256 : if (ctx->srecord_type)
2432 : : {
2433 : 544 : name = create_tmp_var_name (".omp_data_a");
2434 : 544 : name = build_decl (gimple_location (stmt),
2435 : : TYPE_DECL, name, ctx->srecord_type);
2436 : 544 : DECL_ARTIFICIAL (name) = 1;
2437 : 544 : DECL_NAMELESS (name) = 1;
2438 : 544 : TYPE_NAME (ctx->srecord_type) = name;
2439 : 544 : TYPE_ARTIFICIAL (ctx->srecord_type) = 1;
2440 : 544 : create_omp_child_function (ctx, true);
2441 : : }
2442 : :
2443 : 5256 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
2444 : :
2445 : 5256 : if (TYPE_FIELDS (ctx->record_type) == NULL)
2446 : : {
2447 : 1834 : ctx->record_type = ctx->receiver_decl = NULL;
2448 : 1834 : t = build_int_cst (long_integer_type_node, 0);
2449 : 1834 : gimple_omp_task_set_arg_size (stmt, t);
2450 : 1834 : t = build_int_cst (long_integer_type_node, 1);
2451 : 1834 : gimple_omp_task_set_arg_align (stmt, t);
2452 : : }
2453 : : }
2454 : :
2455 : : /* Helper function for finish_taskreg_scan, called through walk_tree.
2456 : : If maybe_lookup_decl_in_outer_context returns non-NULL for some
2457 : : tree, replace it in the expression. */
2458 : :
2459 : : static tree
2460 : 276 : finish_taskreg_remap (tree *tp, int *walk_subtrees, void *data)
2461 : : {
2462 : 276 : if (VAR_P (*tp))
2463 : : {
2464 : 96 : omp_context *ctx = (omp_context *) data;
2465 : 96 : tree t = maybe_lookup_decl_in_outer_ctx (*tp, ctx);
2466 : 96 : if (t != *tp)
2467 : : {
2468 : 9 : if (DECL_HAS_VALUE_EXPR_P (t))
2469 : 0 : t = unshare_expr (DECL_VALUE_EXPR (t));
2470 : 9 : *tp = t;
2471 : : }
2472 : 96 : *walk_subtrees = 0;
2473 : : }
2474 : 180 : else if (IS_TYPE_OR_DECL_P (*tp))
2475 : 0 : *walk_subtrees = 0;
2476 : 276 : return NULL_TREE;
2477 : : }
2478 : :
2479 : : /* If any decls have been made addressable during scan_omp,
2480 : : adjust their fields if needed, and layout record types
2481 : : of parallel/task constructs. */
2482 : :
2483 : : static void
2484 : 25966 : finish_taskreg_scan (omp_context *ctx)
2485 : : {
2486 : 25966 : if (ctx->record_type == NULL_TREE)
2487 : : return;
2488 : :
2489 : : /* If any make_addressable_vars were needed, verify all
2490 : : OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK,TEAMS}
2491 : : statements if use_pointer_for_field hasn't changed
2492 : : because of that. If it did, update field types now. */
2493 : 19127 : if (make_addressable_vars)
2494 : : {
2495 : 2209 : tree c;
2496 : :
2497 : 12338 : for (c = gimple_omp_taskreg_clauses (ctx->stmt);
2498 : 12338 : c; c = OMP_CLAUSE_CHAIN (c))
2499 : 10129 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
2500 : 10129 : && !OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
2501 : : {
2502 : 2617 : tree decl = OMP_CLAUSE_DECL (c);
2503 : :
2504 : : /* Global variables don't need to be copied,
2505 : : the receiver side will use them directly. */
2506 : 2617 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl, ctx)))
2507 : 281 : continue;
2508 : 2336 : if (!bitmap_bit_p (make_addressable_vars, DECL_UID (decl))
2509 : 2336 : || !use_pointer_for_field (decl, ctx))
2510 : 1787 : continue;
2511 : 549 : tree field = lookup_field (decl, ctx);
2512 : 549 : if (TREE_CODE (TREE_TYPE (field)) == POINTER_TYPE
2513 : 549 : && TREE_TYPE (TREE_TYPE (field)) == TREE_TYPE (decl))
2514 : 495 : continue;
2515 : 54 : TREE_TYPE (field) = build_pointer_type (TREE_TYPE (decl));
2516 : 54 : TREE_THIS_VOLATILE (field) = 0;
2517 : 54 : DECL_USER_ALIGN (field) = 0;
2518 : 54 : SET_DECL_ALIGN (field, TYPE_ALIGN (TREE_TYPE (field)));
2519 : 54 : if (TYPE_ALIGN (ctx->record_type) < DECL_ALIGN (field))
2520 : 16 : SET_TYPE_ALIGN (ctx->record_type, DECL_ALIGN (field));
2521 : 54 : if (ctx->srecord_type)
2522 : : {
2523 : 0 : tree sfield = lookup_sfield (decl, ctx);
2524 : 0 : TREE_TYPE (sfield) = TREE_TYPE (field);
2525 : 0 : TREE_THIS_VOLATILE (sfield) = 0;
2526 : 0 : DECL_USER_ALIGN (sfield) = 0;
2527 : 0 : SET_DECL_ALIGN (sfield, DECL_ALIGN (field));
2528 : 0 : if (TYPE_ALIGN (ctx->srecord_type) < DECL_ALIGN (sfield))
2529 : 0 : SET_TYPE_ALIGN (ctx->srecord_type, DECL_ALIGN (sfield));
2530 : : }
2531 : : }
2532 : : }
2533 : :
2534 : 19127 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_PARALLEL)
2535 : : {
2536 : 14536 : tree clauses = gimple_omp_parallel_clauses (ctx->stmt);
2537 : 14536 : tree c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
2538 : 14536 : if (c)
2539 : : {
2540 : : /* Move the _reductemp_ clause first. GOMP_parallel_reductions
2541 : : expects to find it at the start of data. */
2542 : 66 : tree f = lookup_field (OMP_CLAUSE_DECL (c), ctx);
2543 : 66 : tree *p = &TYPE_FIELDS (ctx->record_type);
2544 : 152 : while (*p)
2545 : 152 : if (*p == f)
2546 : : {
2547 : 66 : *p = DECL_CHAIN (*p);
2548 : 66 : break;
2549 : : }
2550 : : else
2551 : 86 : p = &DECL_CHAIN (*p);
2552 : 66 : DECL_CHAIN (f) = TYPE_FIELDS (ctx->record_type);
2553 : 66 : TYPE_FIELDS (ctx->record_type) = f;
2554 : : }
2555 : 14536 : layout_type (ctx->record_type);
2556 : 14536 : fixup_child_record_type (ctx);
2557 : : }
2558 : 4591 : else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
2559 : : {
2560 : 1169 : layout_type (ctx->record_type);
2561 : 1169 : fixup_child_record_type (ctx);
2562 : : }
2563 : : else
2564 : : {
2565 : 3422 : location_t loc = gimple_location (ctx->stmt);
2566 : 3422 : tree *p, vla_fields = NULL_TREE, *q = &vla_fields;
2567 : 3422 : tree detach_clause
2568 : 3422 : = omp_find_clause (gimple_omp_task_clauses (ctx->stmt),
2569 : : OMP_CLAUSE_DETACH);
2570 : : /* Move VLA fields to the end. */
2571 : 3422 : p = &TYPE_FIELDS (ctx->record_type);
2572 : 15319 : while (*p)
2573 : 11897 : if (!TYPE_SIZE_UNIT (TREE_TYPE (*p))
2574 : 11897 : || ! TREE_CONSTANT (TYPE_SIZE_UNIT (TREE_TYPE (*p))))
2575 : : {
2576 : 96 : *q = *p;
2577 : 96 : *p = TREE_CHAIN (*p);
2578 : 96 : TREE_CHAIN (*q) = NULL_TREE;
2579 : 96 : q = &TREE_CHAIN (*q);
2580 : : }
2581 : : else
2582 : 11801 : p = &DECL_CHAIN (*p);
2583 : 3422 : *p = vla_fields;
2584 : 3422 : if (gimple_omp_task_taskloop_p (ctx->stmt))
2585 : : {
2586 : : /* Move fields corresponding to first and second _looptemp_
2587 : : clause first. There are filled by GOMP_taskloop
2588 : : and thus need to be in specific positions. */
2589 : 1567 : tree clauses = gimple_omp_task_clauses (ctx->stmt);
2590 : 1567 : tree c1 = omp_find_clause (clauses, OMP_CLAUSE__LOOPTEMP_);
2591 : 1567 : tree c2 = omp_find_clause (OMP_CLAUSE_CHAIN (c1),
2592 : : OMP_CLAUSE__LOOPTEMP_);
2593 : 1567 : tree c3 = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
2594 : 1567 : tree f1 = lookup_field (OMP_CLAUSE_DECL (c1), ctx);
2595 : 1567 : tree f2 = lookup_field (OMP_CLAUSE_DECL (c2), ctx);
2596 : 2084 : tree f3 = c3 ? lookup_field (OMP_CLAUSE_DECL (c3), ctx) : NULL_TREE;
2597 : 1567 : p = &TYPE_FIELDS (ctx->record_type);
2598 : 8871 : while (*p)
2599 : 7304 : if (*p == f1 || *p == f2 || *p == f3)
2600 : 3651 : *p = DECL_CHAIN (*p);
2601 : : else
2602 : 3653 : p = &DECL_CHAIN (*p);
2603 : 1567 : DECL_CHAIN (f1) = f2;
2604 : 1567 : if (c3)
2605 : : {
2606 : 517 : DECL_CHAIN (f2) = f3;
2607 : 517 : DECL_CHAIN (f3) = TYPE_FIELDS (ctx->record_type);
2608 : : }
2609 : : else
2610 : 1050 : DECL_CHAIN (f2) = TYPE_FIELDS (ctx->record_type);
2611 : 1567 : TYPE_FIELDS (ctx->record_type) = f1;
2612 : 1567 : if (ctx->srecord_type)
2613 : : {
2614 : 389 : f1 = lookup_sfield (OMP_CLAUSE_DECL (c1), ctx);
2615 : 389 : f2 = lookup_sfield (OMP_CLAUSE_DECL (c2), ctx);
2616 : 389 : if (c3)
2617 : 186 : f3 = lookup_sfield (OMP_CLAUSE_DECL (c3), ctx);
2618 : 389 : p = &TYPE_FIELDS (ctx->srecord_type);
2619 : 2097 : while (*p)
2620 : 1708 : if (*p == f1 || *p == f2 || *p == f3)
2621 : 964 : *p = DECL_CHAIN (*p);
2622 : : else
2623 : 744 : p = &DECL_CHAIN (*p);
2624 : 389 : DECL_CHAIN (f1) = f2;
2625 : 389 : DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type);
2626 : 389 : if (c3)
2627 : : {
2628 : 186 : DECL_CHAIN (f2) = f3;
2629 : 186 : DECL_CHAIN (f3) = TYPE_FIELDS (ctx->srecord_type);
2630 : : }
2631 : : else
2632 : 203 : DECL_CHAIN (f2) = TYPE_FIELDS (ctx->srecord_type);
2633 : 389 : TYPE_FIELDS (ctx->srecord_type) = f1;
2634 : : }
2635 : : }
2636 : 3422 : if (detach_clause)
2637 : : {
2638 : 189 : tree c, field;
2639 : :
2640 : : /* Look for a firstprivate clause with the detach event handle. */
2641 : 540 : for (c = gimple_omp_taskreg_clauses (ctx->stmt);
2642 : 540 : c; c = OMP_CLAUSE_CHAIN (c))
2643 : : {
2644 : 540 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
2645 : 347 : continue;
2646 : 193 : if (maybe_lookup_decl_in_outer_ctx (OMP_CLAUSE_DECL (c), ctx)
2647 : 193 : == OMP_CLAUSE_DECL (detach_clause))
2648 : : break;
2649 : : }
2650 : :
2651 : 189 : gcc_assert (c);
2652 : 189 : field = lookup_field (OMP_CLAUSE_DECL (c), ctx);
2653 : :
2654 : : /* Move field corresponding to the detach clause first.
2655 : : This is filled by GOMP_task and needs to be in a
2656 : : specific position. */
2657 : 189 : p = &TYPE_FIELDS (ctx->record_type);
2658 : 518 : while (*p)
2659 : 329 : if (*p == field)
2660 : 189 : *p = DECL_CHAIN (*p);
2661 : : else
2662 : 140 : p = &DECL_CHAIN (*p);
2663 : 189 : DECL_CHAIN (field) = TYPE_FIELDS (ctx->record_type);
2664 : 189 : TYPE_FIELDS (ctx->record_type) = field;
2665 : 189 : if (ctx->srecord_type)
2666 : : {
2667 : 3 : field = lookup_sfield (OMP_CLAUSE_DECL (c), ctx);
2668 : 3 : p = &TYPE_FIELDS (ctx->srecord_type);
2669 : 9 : while (*p)
2670 : 6 : if (*p == field)
2671 : 3 : *p = DECL_CHAIN (*p);
2672 : : else
2673 : 3 : p = &DECL_CHAIN (*p);
2674 : 3 : DECL_CHAIN (field) = TYPE_FIELDS (ctx->srecord_type);
2675 : 3 : TYPE_FIELDS (ctx->srecord_type) = field;
2676 : : }
2677 : : }
2678 : 3422 : layout_type (ctx->record_type);
2679 : 3422 : fixup_child_record_type (ctx);
2680 : 3422 : if (ctx->srecord_type)
2681 : 544 : layout_type (ctx->srecord_type);
2682 : 3422 : tree t = fold_convert_loc (loc, long_integer_type_node,
2683 : 3422 : TYPE_SIZE_UNIT (ctx->record_type));
2684 : 3422 : if (TREE_CODE (t) != INTEGER_CST)
2685 : : {
2686 : 21 : t = unshare_expr (t);
2687 : 21 : walk_tree (&t, finish_taskreg_remap, ctx, NULL);
2688 : : }
2689 : 3422 : gimple_omp_task_set_arg_size (ctx->stmt, t);
2690 : 3422 : t = build_int_cst (long_integer_type_node,
2691 : 3422 : TYPE_ALIGN_UNIT (ctx->record_type));
2692 : 3422 : gimple_omp_task_set_arg_align (ctx->stmt, t);
2693 : : }
2694 : : }
2695 : :
2696 : : /* Find the enclosing offload context. */
2697 : :
2698 : : static omp_context *
2699 : 9665 : enclosing_target_ctx (omp_context *ctx)
2700 : : {
2701 : 43357 : for (; ctx; ctx = ctx->outer)
2702 : 41743 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TARGET)
2703 : : break;
2704 : :
2705 : 22109 : return ctx;
2706 : : }
2707 : :
2708 : : /* Return whether CTX's parent compute construct is an OpenACC 'kernels'
2709 : : construct.
2710 : : (This doesn't include OpenACC 'kernels' decomposed parts.) */
2711 : :
2712 : : static bool
2713 : 11323 : ctx_in_oacc_kernels_region (omp_context *ctx)
2714 : : {
2715 : 39133 : for (;ctx != NULL; ctx = ctx->outer)
2716 : : {
2717 : 29468 : gimple *stmt = ctx->stmt;
2718 : 29468 : if (gimple_code (stmt) == GIMPLE_OMP_TARGET
2719 : 29468 : && gimple_omp_target_kind (stmt) == GF_OMP_TARGET_KIND_OACC_KERNELS)
2720 : : return true;
2721 : : }
2722 : :
2723 : : return false;
2724 : : }
2725 : :
2726 : : /* Check the parallelism clauses inside a OpenACC 'kernels' region.
2727 : : (This doesn't include OpenACC 'kernels' decomposed parts.)
2728 : : Until kernels handling moves to use the same loop indirection
2729 : : scheme as parallel, we need to do this checking early. */
2730 : :
2731 : : static unsigned
2732 : 7146 : check_oacc_kernel_gwv (gomp_for *stmt, omp_context *ctx)
2733 : : {
2734 : 7146 : bool checking = true;
2735 : 7146 : unsigned outer_mask = 0;
2736 : 7146 : unsigned this_mask = 0;
2737 : 7146 : bool has_seq = false, has_auto = false;
2738 : :
2739 : 7146 : if (ctx->outer)
2740 : 4816 : outer_mask = check_oacc_kernel_gwv (NULL, ctx->outer);
2741 : 7146 : if (!stmt)
2742 : : {
2743 : 4816 : checking = false;
2744 : 4816 : if (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR)
2745 : : return outer_mask;
2746 : 1730 : stmt = as_a <gomp_for *> (ctx->stmt);
2747 : : }
2748 : :
2749 : 11323 : for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
2750 : : {
2751 : 7263 : switch (OMP_CLAUSE_CODE (c))
2752 : : {
2753 : 644 : case OMP_CLAUSE_GANG:
2754 : 644 : this_mask |= GOMP_DIM_MASK (GOMP_DIM_GANG);
2755 : 644 : break;
2756 : 439 : case OMP_CLAUSE_WORKER:
2757 : 439 : this_mask |= GOMP_DIM_MASK (GOMP_DIM_WORKER);
2758 : 439 : break;
2759 : 342 : case OMP_CLAUSE_VECTOR:
2760 : 342 : this_mask |= GOMP_DIM_MASK (GOMP_DIM_VECTOR);
2761 : 342 : break;
2762 : 63 : case OMP_CLAUSE_SEQ:
2763 : 63 : has_seq = true;
2764 : 63 : break;
2765 : 94 : case OMP_CLAUSE_AUTO:
2766 : 94 : has_auto = true;
2767 : 94 : break;
2768 : : default:
2769 : : break;
2770 : : }
2771 : : }
2772 : :
2773 : 4060 : if (checking)
2774 : : {
2775 : 2330 : if (has_seq && (this_mask || has_auto))
2776 : 36 : error_at (gimple_location (stmt), "%<seq%> overrides other"
2777 : : " OpenACC loop specifiers");
2778 : 2294 : else if (has_auto && this_mask)
2779 : 30 : error_at (gimple_location (stmt), "%<auto%> conflicts with other"
2780 : : " OpenACC loop specifiers");
2781 : :
2782 : 2330 : if (this_mask & outer_mask)
2783 : 15 : error_at (gimple_location (stmt), "inner loop uses same"
2784 : : " OpenACC parallelism as containing loop");
2785 : : }
2786 : :
2787 : 4060 : return outer_mask | this_mask;
2788 : : }
2789 : :
2790 : : /* Scan a GIMPLE_OMP_FOR. */
2791 : :
2792 : : static omp_context *
2793 : 52612 : scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
2794 : : {
2795 : 52612 : omp_context *ctx;
2796 : 52612 : size_t i;
2797 : 52612 : tree clauses = gimple_omp_for_clauses (stmt);
2798 : :
2799 : 52612 : ctx = new_omp_context (stmt, outer_ctx);
2800 : :
2801 : 52612 : if (is_gimple_omp_oacc (stmt))
2802 : : {
2803 : 12444 : omp_context *tgt = enclosing_target_ctx (outer_ctx);
2804 : :
2805 : 12444 : if (!(tgt && is_oacc_kernels (tgt)))
2806 : 32251 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
2807 : : {
2808 : 22137 : tree c_op0;
2809 : 22137 : switch (OMP_CLAUSE_CODE (c))
2810 : : {
2811 : 1952 : case OMP_CLAUSE_GANG:
2812 : 1952 : c_op0 = OMP_CLAUSE_GANG_EXPR (c);
2813 : 1952 : break;
2814 : :
2815 : 1426 : case OMP_CLAUSE_WORKER:
2816 : 1426 : c_op0 = OMP_CLAUSE_WORKER_EXPR (c);
2817 : 1426 : break;
2818 : :
2819 : 1627 : case OMP_CLAUSE_VECTOR:
2820 : 1627 : c_op0 = OMP_CLAUSE_VECTOR_EXPR (c);
2821 : 1627 : break;
2822 : :
2823 : 17132 : default:
2824 : 17132 : continue;
2825 : : }
2826 : :
2827 : 5005 : if (c_op0)
2828 : : {
2829 : : /* By construction, this is impossible for OpenACC 'kernels'
2830 : : decomposed parts. */
2831 : 210 : gcc_assert (!(tgt && is_oacc_kernels_decomposed_part (tgt)));
2832 : :
2833 : 210 : error_at (OMP_CLAUSE_LOCATION (c),
2834 : : "argument not permitted on %qs clause",
2835 : 210 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
2836 : 210 : if (tgt)
2837 : 180 : inform (gimple_location (tgt->stmt),
2838 : : "enclosing parent compute construct");
2839 : 30 : else if (oacc_get_fn_attrib (current_function_decl))
2840 : 30 : inform (DECL_SOURCE_LOCATION (current_function_decl),
2841 : : "enclosing routine");
2842 : : else
2843 : 0 : gcc_unreachable ();
2844 : : }
2845 : : }
2846 : :
2847 : 12444 : if (tgt && is_oacc_kernels (tgt))
2848 : 2330 : check_oacc_kernel_gwv (stmt, ctx);
2849 : :
2850 : : /* Collect all variables named in reductions on this loop. Ensure
2851 : : that, if this loop has a reduction on some variable v, and there is
2852 : : a reduction on v somewhere in an outer context, then there is a
2853 : : reduction on v on all intervening loops as well. */
2854 : 12444 : tree local_reduction_clauses = NULL;
2855 : 39367 : for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
2856 : : {
2857 : 26923 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
2858 : 4712 : local_reduction_clauses
2859 : 4712 : = tree_cons (NULL, c, local_reduction_clauses);
2860 : : }
2861 : 12444 : if (ctx->outer_reduction_clauses == NULL && ctx->outer != NULL)
2862 : 11918 : ctx->outer_reduction_clauses
2863 : 11918 : = chainon (unshare_expr (ctx->outer->local_reduction_clauses),
2864 : : ctx->outer->outer_reduction_clauses);
2865 : 12444 : tree outer_reduction_clauses = ctx->outer_reduction_clauses;
2866 : 12444 : tree local_iter = local_reduction_clauses;
2867 : 17156 : for (; local_iter; local_iter = TREE_CHAIN (local_iter))
2868 : : {
2869 : 4712 : tree local_clause = TREE_VALUE (local_iter);
2870 : 4712 : tree local_var = OMP_CLAUSE_DECL (local_clause);
2871 : 4712 : tree_code local_op = OMP_CLAUSE_REDUCTION_CODE (local_clause);
2872 : 4712 : bool have_outer_reduction = false;
2873 : 4712 : tree ctx_iter = outer_reduction_clauses;
2874 : 5826 : for (; ctx_iter; ctx_iter = TREE_CHAIN (ctx_iter))
2875 : : {
2876 : 3325 : tree outer_clause = TREE_VALUE (ctx_iter);
2877 : 3325 : tree outer_var = OMP_CLAUSE_DECL (outer_clause);
2878 : 3325 : tree_code outer_op = OMP_CLAUSE_REDUCTION_CODE (outer_clause);
2879 : 3325 : if (outer_var == local_var && outer_op != local_op)
2880 : : {
2881 : 535 : if (warning_at (OMP_CLAUSE_LOCATION (local_clause),
2882 : 535 : OPT_Wopenmp, "conflicting reduction "
2883 : : "operations for %qE",
2884 : : local_var))
2885 : 535 : inform (OMP_CLAUSE_LOCATION (outer_clause),
2886 : : "location of the previous reduction for %qE",
2887 : : outer_var);
2888 : : }
2889 : 3325 : if (outer_var == local_var)
2890 : : {
2891 : : have_outer_reduction = true;
2892 : : break;
2893 : : }
2894 : : }
2895 : 4712 : if (have_outer_reduction)
2896 : : {
2897 : : /* There is a reduction on outer_var both on this loop and on
2898 : : some enclosing loop. Walk up the context tree until such a
2899 : : loop with a reduction on outer_var is found, and complain
2900 : : about all intervening loops that do not have such a
2901 : : reduction. */
2902 : 2211 : struct omp_context *curr_loop = ctx->outer;
2903 : 2211 : bool found = false;
2904 : 2826 : while (curr_loop != NULL)
2905 : : {
2906 : 2826 : tree curr_iter = curr_loop->local_reduction_clauses;
2907 : 3460 : for (; curr_iter; curr_iter = TREE_CHAIN (curr_iter))
2908 : : {
2909 : 2845 : tree curr_clause = TREE_VALUE (curr_iter);
2910 : 2845 : tree curr_var = OMP_CLAUSE_DECL (curr_clause);
2911 : 2845 : if (curr_var == local_var)
2912 : : {
2913 : : found = true;
2914 : : break;
2915 : : }
2916 : : }
2917 : 2826 : if (!found)
2918 : 615 : warning_at (gimple_location (curr_loop->stmt), OPT_Wopenmp,
2919 : : "nested loop in reduction needs "
2920 : : "reduction clause for %qE",
2921 : : local_var);
2922 : : else
2923 : : break;
2924 : 615 : curr_loop = curr_loop->outer;
2925 : : }
2926 : : }
2927 : : }
2928 : 12444 : ctx->local_reduction_clauses = local_reduction_clauses;
2929 : 12444 : ctx->outer_reduction_clauses
2930 : 12444 : = chainon (unshare_expr (ctx->local_reduction_clauses),
2931 : : ctx->outer_reduction_clauses);
2932 : :
2933 : 12444 : if (tgt && is_oacc_kernels (tgt))
2934 : : {
2935 : : /* Strip out reductions, as they are not handled yet. */
2936 : : tree *prev_ptr = &clauses;
2937 : :
2938 : 7116 : while (tree probe = *prev_ptr)
2939 : : {
2940 : 4786 : tree *next_ptr = &OMP_CLAUSE_CHAIN (probe);
2941 : :
2942 : 4786 : if (OMP_CLAUSE_CODE (probe) == OMP_CLAUSE_REDUCTION)
2943 : 718 : *prev_ptr = *next_ptr;
2944 : : else
2945 : : prev_ptr = next_ptr;
2946 : : }
2947 : :
2948 : 2330 : gimple_omp_for_set_clauses (stmt, clauses);
2949 : : }
2950 : : }
2951 : :
2952 : 52612 : scan_sharing_clauses (clauses, ctx);
2953 : :
2954 : 52612 : scan_omp (gimple_omp_for_pre_body_ptr (stmt), ctx);
2955 : 179867 : for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2956 : : {
2957 : 74643 : scan_omp_op (gimple_omp_for_index_ptr (stmt, i), ctx);
2958 : 74643 : scan_omp_op (gimple_omp_for_initial_ptr (stmt, i), ctx);
2959 : 74643 : scan_omp_op (gimple_omp_for_final_ptr (stmt, i), ctx);
2960 : 74643 : scan_omp_op (gimple_omp_for_incr_ptr (stmt, i), ctx);
2961 : : }
2962 : 52612 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
2963 : 52612 : return ctx;
2964 : : }
2965 : :
2966 : : /* Duplicate #pragma omp simd, one for SIMT, another one for SIMD. */
2967 : :
2968 : : static void
2969 : 0 : scan_omp_simd (gimple_stmt_iterator *gsi, gomp_for *stmt,
2970 : : omp_context *outer_ctx)
2971 : : {
2972 : 0 : gbind *bind = gimple_build_bind (NULL, NULL, NULL);
2973 : 0 : gsi_replace (gsi, bind, false);
2974 : 0 : gimple_seq seq = NULL;
2975 : 0 : gimple *g = gimple_build_call_internal (IFN_GOMP_USE_SIMT, 0);
2976 : 0 : tree cond = create_tmp_var_raw (integer_type_node);
2977 : 0 : DECL_CONTEXT (cond) = current_function_decl;
2978 : 0 : DECL_SEEN_IN_BIND_EXPR_P (cond) = 1;
2979 : 0 : gimple_bind_set_vars (bind, cond);
2980 : 0 : gimple_call_set_lhs (g, cond);
2981 : 0 : gimple_seq_add_stmt (&seq, g);
2982 : 0 : tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
2983 : 0 : tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
2984 : 0 : tree lab3 = create_artificial_label (UNKNOWN_LOCATION);
2985 : 0 : g = gimple_build_cond (NE_EXPR, cond, integer_zero_node, lab1, lab2);
2986 : 0 : gimple_seq_add_stmt (&seq, g);
2987 : 0 : g = gimple_build_label (lab1);
2988 : 0 : gimple_seq_add_stmt (&seq, g);
2989 : 0 : gimple_seq new_seq = copy_gimple_seq_and_replace_locals (stmt);
2990 : 0 : gomp_for *new_stmt = as_a <gomp_for *> (new_seq);
2991 : 0 : tree clause = build_omp_clause (gimple_location (stmt), OMP_CLAUSE__SIMT_);
2992 : 0 : OMP_CLAUSE_CHAIN (clause) = gimple_omp_for_clauses (new_stmt);
2993 : 0 : gimple_omp_for_set_clauses (new_stmt, clause);
2994 : 0 : gimple_seq_add_stmt (&seq, new_stmt);
2995 : 0 : g = gimple_build_goto (lab3);
2996 : 0 : gimple_seq_add_stmt (&seq, g);
2997 : 0 : g = gimple_build_label (lab2);
2998 : 0 : gimple_seq_add_stmt (&seq, g);
2999 : 0 : gimple_seq_add_stmt (&seq, stmt);
3000 : 0 : g = gimple_build_label (lab3);
3001 : 0 : gimple_seq_add_stmt (&seq, g);
3002 : 0 : gimple_bind_set_body (bind, seq);
3003 : 0 : update_stmt (bind);
3004 : 0 : scan_omp_for (new_stmt, outer_ctx);
3005 : 0 : scan_omp_for (stmt, outer_ctx)->simt_stmt = new_stmt;
3006 : 0 : }
3007 : :
3008 : : static tree omp_find_scan (gimple_stmt_iterator *, bool *,
3009 : : struct walk_stmt_info *);
3010 : : static omp_context *maybe_lookup_ctx (gimple *);
3011 : :
3012 : : /* Duplicate #pragma omp simd, one for the scan input phase loop and one
3013 : : for scan phase loop. */
3014 : :
3015 : : static void
3016 : 83 : scan_omp_simd_scan (gimple_stmt_iterator *gsi, gomp_for *stmt,
3017 : : omp_context *outer_ctx)
3018 : : {
3019 : : /* The only change between inclusive and exclusive scan will be
3020 : : within the first simd loop, so just use inclusive in the
3021 : : worksharing loop. */
3022 : 83 : outer_ctx->scan_inclusive = true;
3023 : 83 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_INCLUSIVE);
3024 : 83 : OMP_CLAUSE_DECL (c) = integer_zero_node;
3025 : :
3026 : 83 : gomp_scan *input_stmt = gimple_build_omp_scan (NULL, NULL_TREE);
3027 : 83 : gomp_scan *scan_stmt = gimple_build_omp_scan (NULL, c);
3028 : 83 : gsi_replace (gsi, input_stmt, false);
3029 : 83 : gimple_seq input_body = NULL;
3030 : 83 : gimple_seq_add_stmt (&input_body, stmt);
3031 : 83 : gsi_insert_after (gsi, scan_stmt, GSI_NEW_STMT);
3032 : :
3033 : 83 : gimple_stmt_iterator input1_gsi = gsi_none ();
3034 : 83 : struct walk_stmt_info wi;
3035 : 83 : memset (&wi, 0, sizeof (wi));
3036 : 83 : wi.val_only = true;
3037 : 83 : wi.info = (void *) &input1_gsi;
3038 : 83 : walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), omp_find_scan, NULL, &wi);
3039 : 83 : gcc_assert (!gsi_end_p (input1_gsi));
3040 : :
3041 : 83 : gimple *input_stmt1 = gsi_stmt (input1_gsi);
3042 : 83 : gsi_next (&input1_gsi);
3043 : 83 : gimple *scan_stmt1 = gsi_stmt (input1_gsi);
3044 : 83 : gcc_assert (scan_stmt1 && gimple_code (scan_stmt1) == GIMPLE_OMP_SCAN);
3045 : 83 : c = gimple_omp_scan_clauses (as_a <gomp_scan *> (scan_stmt1));
3046 : 166 : if (c && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_EXCLUSIVE)
3047 : : std::swap (input_stmt1, scan_stmt1);
3048 : :
3049 : 83 : gimple_seq input_body1 = gimple_omp_body (input_stmt1);
3050 : 83 : gimple_omp_set_body (input_stmt1, NULL);
3051 : :
3052 : 83 : gimple_seq scan_body = copy_gimple_seq_and_replace_locals (stmt);
3053 : 83 : gomp_for *new_stmt = as_a <gomp_for *> (scan_body);
3054 : :
3055 : 83 : gimple_omp_set_body (input_stmt1, input_body1);
3056 : 83 : gimple_omp_set_body (scan_stmt1, NULL);
3057 : :
3058 : 83 : gimple_stmt_iterator input2_gsi = gsi_none ();
3059 : 83 : memset (&wi, 0, sizeof (wi));
3060 : 83 : wi.val_only = true;
3061 : 83 : wi.info = (void *) &input2_gsi;
3062 : 83 : walk_gimple_seq_mod (gimple_omp_body_ptr (new_stmt), omp_find_scan,
3063 : : NULL, &wi);
3064 : 83 : gcc_assert (!gsi_end_p (input2_gsi));
3065 : :
3066 : 83 : gimple *input_stmt2 = gsi_stmt (input2_gsi);
3067 : 83 : gsi_next (&input2_gsi);
3068 : 83 : gimple *scan_stmt2 = gsi_stmt (input2_gsi);
3069 : 83 : gcc_assert (scan_stmt2 && gimple_code (scan_stmt2) == GIMPLE_OMP_SCAN);
3070 : 166 : if (c && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_EXCLUSIVE)
3071 : : std::swap (input_stmt2, scan_stmt2);
3072 : :
3073 : 83 : gimple_omp_set_body (input_stmt2, NULL);
3074 : :
3075 : 83 : gimple_omp_set_body (input_stmt, input_body);
3076 : 83 : gimple_omp_set_body (scan_stmt, scan_body);
3077 : :
3078 : 83 : omp_context *ctx = new_omp_context (input_stmt, outer_ctx);
3079 : 83 : scan_omp (gimple_omp_body_ptr (input_stmt), ctx);
3080 : :
3081 : 83 : ctx = new_omp_context (scan_stmt, outer_ctx);
3082 : 83 : scan_omp (gimple_omp_body_ptr (scan_stmt), ctx);
3083 : :
3084 : 83 : maybe_lookup_ctx (new_stmt)->for_simd_scan_phase = true;
3085 : 83 : }
3086 : :
3087 : : /* Scan an OpenMP sections directive. */
3088 : :
3089 : : static void
3090 : 581 : scan_omp_sections (gomp_sections *stmt, omp_context *outer_ctx)
3091 : : {
3092 : 581 : omp_context *ctx;
3093 : :
3094 : 581 : ctx = new_omp_context (stmt, outer_ctx);
3095 : 581 : scan_sharing_clauses (gimple_omp_sections_clauses (stmt), ctx);
3096 : 581 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
3097 : 581 : }
3098 : :
3099 : : /* Scan an OpenMP single directive. */
3100 : :
3101 : : static void
3102 : 1228 : scan_omp_single (gomp_single *stmt, omp_context *outer_ctx)
3103 : : {
3104 : 1228 : omp_context *ctx;
3105 : 1228 : tree name;
3106 : :
3107 : 1228 : ctx = new_omp_context (stmt, outer_ctx);
3108 : 1228 : ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
3109 : 1228 : ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
3110 : 1228 : name = create_tmp_var_name (".omp_copy_s");
3111 : 1228 : name = build_decl (gimple_location (stmt),
3112 : : TYPE_DECL, name, ctx->record_type);
3113 : 1228 : TYPE_NAME (ctx->record_type) = name;
3114 : :
3115 : 1228 : scan_sharing_clauses (gimple_omp_single_clauses (stmt), ctx);
3116 : 1228 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
3117 : :
3118 : 1228 : if (TYPE_FIELDS (ctx->record_type) == NULL)
3119 : 1081 : ctx->record_type = NULL;
3120 : : else
3121 : 147 : layout_type (ctx->record_type);
3122 : 1228 : }
3123 : :
3124 : : /* Scan a GIMPLE_OMP_TARGET. */
3125 : :
3126 : : static void
3127 : 40944 : scan_omp_target (gomp_target *stmt, omp_context *outer_ctx)
3128 : : {
3129 : 40944 : omp_context *ctx;
3130 : 40944 : tree name;
3131 : 40944 : bool offloaded = is_gimple_omp_offloaded (stmt);
3132 : 40944 : tree clauses = gimple_omp_target_clauses (stmt);
3133 : :
3134 : 40944 : ctx = new_omp_context (stmt, outer_ctx);
3135 : 40944 : ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
3136 : 40944 : ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
3137 : 40944 : name = create_tmp_var_name (".omp_data_t");
3138 : 40944 : name = build_decl (gimple_location (stmt),
3139 : : TYPE_DECL, name, ctx->record_type);
3140 : 40944 : DECL_ARTIFICIAL (name) = 1;
3141 : 40944 : DECL_NAMELESS (name) = 1;
3142 : 40944 : TYPE_NAME (ctx->record_type) = name;
3143 : 40944 : TYPE_ARTIFICIAL (ctx->record_type) = 1;
3144 : :
3145 : 40944 : if (offloaded)
3146 : : {
3147 : 24265 : create_omp_child_function (ctx, false);
3148 : 24265 : gimple_omp_target_set_child_fn (stmt, ctx->cb.dst_fn);
3149 : : }
3150 : :
3151 : 40944 : scan_sharing_clauses (clauses, ctx);
3152 : 40944 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
3153 : :
3154 : 40944 : if (TYPE_FIELDS (ctx->record_type) == NULL)
3155 : 7827 : ctx->record_type = ctx->receiver_decl = NULL;
3156 : : else
3157 : : {
3158 : 33117 : TYPE_FIELDS (ctx->record_type)
3159 : 33117 : = nreverse (TYPE_FIELDS (ctx->record_type));
3160 : 33117 : if (flag_checking)
3161 : : {
3162 : 33117 : unsigned int align = DECL_ALIGN (TYPE_FIELDS (ctx->record_type));
3163 : 33117 : for (tree field = TYPE_FIELDS (ctx->record_type);
3164 : 126789 : field;
3165 : 93672 : field = DECL_CHAIN (field))
3166 : 93672 : gcc_assert (DECL_ALIGN (field) == align);
3167 : : }
3168 : 33117 : layout_type (ctx->record_type);
3169 : 33117 : if (offloaded)
3170 : 16989 : fixup_child_record_type (ctx);
3171 : : }
3172 : :
3173 : 40944 : if (ctx->teams_nested_p && ctx->nonteams_nested_p)
3174 : : {
3175 : 4 : error_at (gimple_location (stmt),
3176 : : "%<target%> construct with nested %<teams%> construct "
3177 : : "contains directives outside of the %<teams%> construct");
3178 : 4 : gimple_omp_set_body (stmt, gimple_build_bind (NULL, NULL, NULL));
3179 : : }
3180 : 40944 : }
3181 : :
3182 : : /* Scan an OpenMP teams directive. */
3183 : :
3184 : : static void
3185 : 8733 : scan_omp_teams (gomp_teams *stmt, omp_context *outer_ctx)
3186 : : {
3187 : 8733 : omp_context *ctx = new_omp_context (stmt, outer_ctx);
3188 : :
3189 : 8733 : if (!gimple_omp_teams_host (stmt))
3190 : : {
3191 : 6118 : scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx);
3192 : 6118 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
3193 : 6118 : return;
3194 : : }
3195 : 2615 : taskreg_contexts.safe_push (ctx);
3196 : 2615 : gcc_assert (taskreg_nesting_level == 1);
3197 : 2615 : ctx->field_map = splay_tree_new (splay_tree_compare_pointers, 0, 0);
3198 : 2615 : ctx->record_type = lang_hooks.types.make_type (RECORD_TYPE);
3199 : 2615 : tree name = create_tmp_var_name (".omp_data_s");
3200 : 2615 : name = build_decl (gimple_location (stmt),
3201 : : TYPE_DECL, name, ctx->record_type);
3202 : 2615 : DECL_ARTIFICIAL (name) = 1;
3203 : 2615 : DECL_NAMELESS (name) = 1;
3204 : 2615 : TYPE_NAME (ctx->record_type) = name;
3205 : 2615 : TYPE_ARTIFICIAL (ctx->record_type) = 1;
3206 : 2615 : create_omp_child_function (ctx, false);
3207 : 2615 : gimple_omp_teams_set_child_fn (stmt, ctx->cb.dst_fn);
3208 : :
3209 : 2615 : scan_sharing_clauses (gimple_omp_teams_clauses (stmt), ctx);
3210 : 2615 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
3211 : :
3212 : 2615 : if (TYPE_FIELDS (ctx->record_type) == NULL)
3213 : 1446 : ctx->record_type = ctx->receiver_decl = NULL;
3214 : : }
3215 : :
3216 : : /* Check nesting restrictions. */
3217 : : static bool
3218 : 155892 : check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
3219 : : {
3220 : 155892 : tree c;
3221 : :
3222 : : /* No nesting of non-OpenACC STMT (that is, an OpenMP one, or a GOMP builtin)
3223 : : inside an OpenACC CTX. */
3224 : 155892 : if (gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD
3225 : 155892 : || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE)
3226 : : /* ..., except for the atomic codes that OpenACC shares with OpenMP. */
3227 : : ;
3228 : 279925 : else if (!(is_gimple_omp (stmt)
3229 : 137853 : && is_gimple_omp_oacc (stmt)))
3230 : : {
3231 : 111819 : if (oacc_get_fn_attrib (cfun->decl) != NULL)
3232 : : {
3233 : 48 : error_at (gimple_location (stmt),
3234 : : "non-OpenACC construct inside of OpenACC routine");
3235 : 48 : return false;
3236 : : }
3237 : : else
3238 : 235186 : for (omp_context *octx = ctx; octx != NULL; octx = octx->outer)
3239 : 247006 : if (is_gimple_omp (octx->stmt)
3240 : 123591 : && is_gimple_omp_oacc (octx->stmt))
3241 : : {
3242 : 176 : error_at (gimple_location (stmt),
3243 : : "non-OpenACC construct inside of OpenACC region");
3244 : 176 : return false;
3245 : : }
3246 : : }
3247 : :
3248 : 155668 : if (ctx != NULL)
3249 : : {
3250 : 84103 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TARGET
3251 : 84103 : && gimple_omp_target_kind (ctx->stmt) == GF_OMP_TARGET_KIND_REGION)
3252 : : {
3253 : 8313 : c = omp_find_clause (gimple_omp_target_clauses (ctx->stmt),
3254 : : OMP_CLAUSE_DEVICE);
3255 : 8313 : if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c))
3256 : : {
3257 : 9 : error_at (gimple_location (stmt),
3258 : : "OpenMP constructs are not allowed in target region "
3259 : : "with %<ancestor%>");
3260 : 9 : return false;
3261 : : }
3262 : :
3263 : 8304 : if (gimple_code (stmt) == GIMPLE_OMP_TEAMS && !ctx->teams_nested_p)
3264 : 6114 : ctx->teams_nested_p = true;
3265 : : else
3266 : 2190 : ctx->nonteams_nested_p = true;
3267 : : }
3268 : 84094 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_SCAN
3269 : 172 : && ctx->outer
3270 : 84266 : && gimple_code (ctx->outer->stmt) == GIMPLE_OMP_FOR)
3271 : : ctx = ctx->outer;
3272 : 84094 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
3273 : 28303 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD
3274 : 85903 : && !ctx->loop_p)
3275 : : {
3276 : 1589 : c = NULL_TREE;
3277 : 1589 : if (ctx->order_concurrent
3278 : 1589 : && (gimple_code (stmt) == GIMPLE_OMP_ORDERED
3279 : 280 : || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD
3280 : 190 : || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE))
3281 : : {
3282 : 210 : error_at (gimple_location (stmt),
3283 : : "OpenMP constructs other than %<parallel%>, %<loop%>"
3284 : : " or %<simd%> may not be nested inside a region with"
3285 : : " the %<order(concurrent)%> clause");
3286 : 210 : return false;
3287 : : }
3288 : 1379 : if (gimple_code (stmt) == GIMPLE_OMP_ORDERED)
3289 : : {
3290 : 133 : c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt));
3291 : 133 : if (omp_find_clause (c, OMP_CLAUSE_SIMD))
3292 : : {
3293 : 133 : if (omp_find_clause (c, OMP_CLAUSE_THREADS)
3294 : 133 : && (ctx->outer == NULL
3295 : 29 : || !gimple_omp_for_combined_into_p (ctx->stmt)
3296 : 25 : || gimple_code (ctx->outer->stmt) != GIMPLE_OMP_FOR
3297 : 25 : || (gimple_omp_for_kind (ctx->outer->stmt)
3298 : : != GF_OMP_FOR_KIND_FOR)
3299 : 25 : || !gimple_omp_for_combined_p (ctx->outer->stmt)))
3300 : : {
3301 : 8 : error_at (gimple_location (stmt),
3302 : : "%<ordered simd threads%> must be closely "
3303 : : "nested inside of %<%s simd%> region",
3304 : 8 : lang_GNU_Fortran () ? "do" : "for");
3305 : 8 : return false;
3306 : : }
3307 : : return true;
3308 : : }
3309 : : }
3310 : : else if (gimple_code (stmt) == GIMPLE_OMP_ATOMIC_LOAD
3311 : : || gimple_code (stmt) == GIMPLE_OMP_ATOMIC_STORE
3312 : : || gimple_code (stmt) == GIMPLE_OMP_SCAN
3313 : : || gimple_code (stmt) == GIMPLE_OMP_STRUCTURED_BLOCK)
3314 : : return true;
3315 : : else if (gimple_code (stmt) == GIMPLE_OMP_FOR
3316 : : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD)
3317 : : return true;
3318 : 60 : error_at (gimple_location (stmt),
3319 : : "OpenMP constructs other than "
3320 : : "%<ordered simd%>, %<simd%>, %<loop%> or %<atomic%> may "
3321 : : "not be nested inside %<simd%> region");
3322 : 60 : return false;
3323 : : }
3324 : 82505 : else if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS)
3325 : : {
3326 : 5826 : if ((gimple_code (stmt) != GIMPLE_OMP_FOR
3327 : 5522 : || (gimple_omp_for_kind (stmt) != GF_OMP_FOR_KIND_DISTRIBUTE
3328 : 25 : && omp_find_clause (gimple_omp_for_clauses (stmt),
3329 : : OMP_CLAUSE_BIND) == NULL_TREE))
3330 : 5842 : && gimple_code (stmt) != GIMPLE_OMP_PARALLEL)
3331 : : {
3332 : 132 : error_at (gimple_location (stmt),
3333 : : "only %<distribute%>, %<parallel%> or %<loop%> "
3334 : : "regions are allowed to be strictly nested inside "
3335 : : "%<teams%> region");
3336 : 132 : return false;
3337 : : }
3338 : : }
3339 : 76679 : else if (ctx->order_concurrent
3340 : 1944 : && gimple_code (stmt) != GIMPLE_OMP_PARALLEL
3341 : 1465 : && (gimple_code (stmt) != GIMPLE_OMP_FOR
3342 : 1191 : || gimple_omp_for_kind (stmt) != GF_OMP_FOR_KIND_SIMD)
3343 : 289 : && gimple_code (stmt) != GIMPLE_OMP_SCAN
3344 : 76968 : && gimple_code (stmt) != GIMPLE_OMP_STRUCTURED_BLOCK)
3345 : : {
3346 : 285 : if (ctx->loop_p)
3347 : 135 : error_at (gimple_location (stmt),
3348 : : "OpenMP constructs other than %<parallel%>, %<loop%> or "
3349 : : "%<simd%> may not be nested inside a %<loop%> region");
3350 : : else
3351 : 150 : error_at (gimple_location (stmt),
3352 : : "OpenMP constructs other than %<parallel%>, %<loop%> or "
3353 : : "%<simd%> may not be nested inside a region with "
3354 : : "the %<order(concurrent)%> clause");
3355 : 285 : return false;
3356 : : }
3357 : : }
3358 : 153653 : switch (gimple_code (stmt))
3359 : : {
3360 : 52731 : case GIMPLE_OMP_FOR:
3361 : 52731 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_SIMD)
3362 : : return true;
3363 : 41978 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_DISTRIBUTE)
3364 : : {
3365 : 8214 : if (ctx != NULL && gimple_code (ctx->stmt) != GIMPLE_OMP_TEAMS)
3366 : : {
3367 : 0 : error_at (gimple_location (stmt),
3368 : : "%<distribute%> region must be strictly nested "
3369 : : "inside %<teams%> construct");
3370 : 0 : return false;
3371 : : }
3372 : : return true;
3373 : : }
3374 : : /* We split taskloop into task and nested taskloop in it. */
3375 : 33764 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_TASKLOOP)
3376 : : return true;
3377 : : /* For now, hope this will change and loop bind(parallel) will not
3378 : : be allowed in lots of contexts. */
3379 : 30630 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_FOR
3380 : 48751 : && omp_find_clause (gimple_omp_for_clauses (stmt), OMP_CLAUSE_BIND))
3381 : : return true;
3382 : 30001 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_OACC_LOOP)
3383 : : {
3384 : 12509 : bool ok = false;
3385 : :
3386 : 12509 : if (ctx)
3387 : 11962 : switch (gimple_code (ctx->stmt))
3388 : : {
3389 : 4049 : case GIMPLE_OMP_FOR:
3390 : 4049 : ok = (gimple_omp_for_kind (ctx->stmt)
3391 : : == GF_OMP_FOR_KIND_OACC_LOOP);
3392 : 4049 : break;
3393 : :
3394 : 7885 : case GIMPLE_OMP_TARGET:
3395 : 7885 : switch (gimple_omp_target_kind (ctx->stmt))
3396 : : {
3397 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL:
3398 : : case GF_OMP_TARGET_KIND_OACC_KERNELS:
3399 : : case GF_OMP_TARGET_KIND_OACC_SERIAL:
3400 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
3401 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
3402 : : ok = true;
3403 : : break;
3404 : :
3405 : : default:
3406 : : break;
3407 : : }
3408 : :
3409 : : default:
3410 : : break;
3411 : : }
3412 : 547 : else if (oacc_get_fn_attrib (current_function_decl))
3413 : : ok = true;
3414 : 4049 : if (!ok)
3415 : : {
3416 : 65 : error_at (gimple_location (stmt),
3417 : : "OpenACC loop directive must be associated with"
3418 : : " an OpenACC compute region");
3419 : 65 : return false;
3420 : : }
3421 : : }
3422 : : /* FALLTHRU */
3423 : 34095 : case GIMPLE_CALL:
3424 : 34095 : if (is_gimple_call (stmt)
3425 : 34095 : && (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3426 : : == BUILT_IN_GOMP_CANCEL
3427 : 3055 : || DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3428 : : == BUILT_IN_GOMP_CANCELLATION_POINT))
3429 : : {
3430 : 1907 : const char *bad = NULL;
3431 : 1907 : const char *kind = NULL;
3432 : 1907 : const char *construct
3433 : 1907 : = (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3434 : : == BUILT_IN_GOMP_CANCEL)
3435 : 1907 : ? "cancel"
3436 : 803 : : "cancellation point";
3437 : 1907 : if (ctx == NULL)
3438 : : {
3439 : 41 : error_at (gimple_location (stmt), "orphaned %qs construct",
3440 : : construct);
3441 : 41 : return false;
3442 : : }
3443 : 1866 : switch (tree_fits_shwi_p (gimple_call_arg (stmt, 0))
3444 : 1866 : ? tree_to_shwi (gimple_call_arg (stmt, 0))
3445 : : : 0)
3446 : : {
3447 : 528 : case 1:
3448 : 528 : if (gimple_code (ctx->stmt) != GIMPLE_OMP_PARALLEL)
3449 : : bad = "parallel";
3450 : 208 : else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3451 : : == BUILT_IN_GOMP_CANCEL
3452 : 208 : && !integer_zerop (gimple_call_arg (stmt, 1)))
3453 : 164 : ctx->cancellable = true;
3454 : 164 : kind = "parallel";
3455 : 164 : break;
3456 : 427 : case 2:
3457 : 427 : if (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
3458 : 427 : || gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_FOR)
3459 : : bad = "for";
3460 : 117 : else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3461 : : == BUILT_IN_GOMP_CANCEL
3462 : 117 : && !integer_zerop (gimple_call_arg (stmt, 1)))
3463 : : {
3464 : 106 : ctx->cancellable = true;
3465 : 106 : if (omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
3466 : : OMP_CLAUSE_NOWAIT))
3467 : 5 : warning_at (gimple_location (stmt), OPT_Wopenmp,
3468 : : "%<cancel for%> inside "
3469 : : "%<nowait%> for construct");
3470 : 106 : if (omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
3471 : : OMP_CLAUSE_ORDERED))
3472 : 5 : warning_at (gimple_location (stmt), OPT_Wopenmp,
3473 : : "%<cancel for%> inside "
3474 : : "%<ordered%> for construct");
3475 : : }
3476 : 5 : kind = "for";
3477 : 5 : break;
3478 : 383 : case 4:
3479 : 383 : if (gimple_code (ctx->stmt) != GIMPLE_OMP_SECTIONS
3480 : 383 : && gimple_code (ctx->stmt) != GIMPLE_OMP_SECTION)
3481 : : bad = "sections";
3482 : 93 : else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3483 : : == BUILT_IN_GOMP_CANCEL
3484 : 93 : && !integer_zerop (gimple_call_arg (stmt, 1)))
3485 : : {
3486 : 73 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_SECTIONS)
3487 : : {
3488 : 0 : ctx->cancellable = true;
3489 : 0 : if (omp_find_clause (gimple_omp_sections_clauses
3490 : 0 : (ctx->stmt),
3491 : : OMP_CLAUSE_NOWAIT))
3492 : 0 : warning_at (gimple_location (stmt), OPT_Wopenmp,
3493 : : "%<cancel sections%> inside "
3494 : : "%<nowait%> sections construct");
3495 : : }
3496 : : else
3497 : : {
3498 : 73 : gcc_assert (ctx->outer
3499 : : && gimple_code (ctx->outer->stmt)
3500 : : == GIMPLE_OMP_SECTIONS);
3501 : 73 : ctx->outer->cancellable = true;
3502 : 73 : if (omp_find_clause (gimple_omp_sections_clauses
3503 : 73 : (ctx->outer->stmt),
3504 : : OMP_CLAUSE_NOWAIT))
3505 : 10 : warning_at (gimple_location (stmt), OPT_Wopenmp,
3506 : : "%<cancel sections%> inside "
3507 : : "%<nowait%> sections construct");
3508 : : }
3509 : : }
3510 : 10 : kind = "sections";
3511 : 10 : break;
3512 : 528 : case 8:
3513 : 528 : if (!is_task_ctx (ctx)
3514 : 528 : && (!is_taskloop_ctx (ctx)
3515 : 54 : || ctx->outer == NULL
3516 : 54 : || !is_task_ctx (ctx->outer)))
3517 : : bad = "task";
3518 : : else
3519 : : {
3520 : 248 : for (omp_context *octx = ctx->outer;
3521 : 439 : octx; octx = octx->outer)
3522 : : {
3523 : 425 : switch (gimple_code (octx->stmt))
3524 : : {
3525 : : case GIMPLE_OMP_TASKGROUP:
3526 : : break;
3527 : 40 : case GIMPLE_OMP_TARGET:
3528 : 40 : if (gimple_omp_target_kind (octx->stmt)
3529 : : != GF_OMP_TARGET_KIND_REGION)
3530 : 20 : continue;
3531 : : /* FALLTHRU */
3532 : 99 : case GIMPLE_OMP_PARALLEL:
3533 : 99 : case GIMPLE_OMP_TEAMS:
3534 : 99 : error_at (gimple_location (stmt),
3535 : : "%<%s taskgroup%> construct not closely "
3536 : : "nested inside of %<taskgroup%> region",
3537 : : construct);
3538 : 99 : return false;
3539 : 104 : case GIMPLE_OMP_TASK:
3540 : 104 : if (gimple_omp_task_taskloop_p (octx->stmt)
3541 : 94 : && octx->outer
3542 : 198 : && is_taskloop_ctx (octx->outer))
3543 : : {
3544 : 94 : tree clauses
3545 : 94 : = gimple_omp_for_clauses (octx->outer->stmt);
3546 : 94 : if (!omp_find_clause (clauses, OMP_CLAUSE_NOGROUP))
3547 : : break;
3548 : : }
3549 : 60 : continue;
3550 : 111 : default:
3551 : 111 : continue;
3552 : 171 : }
3553 : : break;
3554 : : }
3555 : 149 : ctx->cancellable = true;
3556 : : }
3557 : 149 : kind = "taskgroup";
3558 : 149 : break;
3559 : 0 : default:
3560 : 0 : error_at (gimple_location (stmt), "invalid arguments");
3561 : 0 : return false;
3562 : : }
3563 : 328 : if (bad)
3564 : : {
3565 : 1200 : error_at (gimple_location (stmt),
3566 : : "%<%s %s%> construct not closely nested inside of %qs",
3567 : : construct, kind, bad);
3568 : 1200 : return false;
3569 : : }
3570 : : }
3571 : : /* FALLTHRU */
3572 : : case GIMPLE_OMP_SECTIONS:
3573 : : case GIMPLE_OMP_SINGLE:
3574 : 55552 : for (; ctx != NULL; ctx = ctx->outer)
3575 : 37498 : switch (gimple_code (ctx->stmt))
3576 : : {
3577 : 6873 : case GIMPLE_OMP_FOR:
3578 : 6873 : if (gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_FOR
3579 : 6873 : && gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_TASKLOOP)
3580 : : break;
3581 : : /* FALLTHRU */
3582 : 778 : case GIMPLE_OMP_SECTIONS:
3583 : 778 : case GIMPLE_OMP_SINGLE:
3584 : 778 : case GIMPLE_OMP_ORDERED:
3585 : 778 : case GIMPLE_OMP_MASTER:
3586 : 778 : case GIMPLE_OMP_MASKED:
3587 : 778 : case GIMPLE_OMP_TASK:
3588 : 778 : case GIMPLE_OMP_CRITICAL:
3589 : 778 : if (is_gimple_call (stmt))
3590 : : {
3591 : 707 : if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt))
3592 : : != BUILT_IN_GOMP_BARRIER)
3593 : : return true;
3594 : 23 : error_at (gimple_location (stmt),
3595 : : "barrier region may not be closely nested inside "
3596 : : "of work-sharing, %<loop%>, %<critical%>, "
3597 : : "%<ordered%>, %<master%>, %<masked%>, explicit "
3598 : : "%<task%> or %<taskloop%> region");
3599 : 23 : return false;
3600 : : }
3601 : 71 : error_at (gimple_location (stmt),
3602 : : "work-sharing region may not be closely nested inside "
3603 : : "of work-sharing, %<loop%>, %<critical%>, %<ordered%>, "
3604 : : "%<master%>, %<masked%>, explicit %<task%> or "
3605 : : "%<taskloop%> region");
3606 : 71 : return false;
3607 : : case GIMPLE_OMP_PARALLEL:
3608 : : case GIMPLE_OMP_TEAMS:
3609 : : return true;
3610 : 13434 : case GIMPLE_OMP_TARGET:
3611 : 13434 : if (gimple_omp_target_kind (ctx->stmt)
3612 : : == GF_OMP_TARGET_KIND_REGION)
3613 : : return true;
3614 : : break;
3615 : : default:
3616 : : break;
3617 : : }
3618 : : break;
3619 : : case GIMPLE_OMP_MASTER:
3620 : : case GIMPLE_OMP_MASKED:
3621 : 1513 : for (; ctx != NULL; ctx = ctx->outer)
3622 : 1008 : switch (gimple_code (ctx->stmt))
3623 : : {
3624 : 14 : case GIMPLE_OMP_FOR:
3625 : 14 : if (gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_FOR
3626 : 14 : && gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_TASKLOOP)
3627 : : break;
3628 : : /* FALLTHRU */
3629 : 30 : case GIMPLE_OMP_SECTIONS:
3630 : 30 : case GIMPLE_OMP_SINGLE:
3631 : 30 : case GIMPLE_OMP_TASK:
3632 : 60 : error_at (gimple_location (stmt),
3633 : : "%qs region may not be closely nested inside "
3634 : : "of work-sharing, %<loop%>, explicit %<task%> or "
3635 : : "%<taskloop%> region",
3636 : 30 : gimple_code (stmt) == GIMPLE_OMP_MASTER
3637 : : ? "master" : "masked");
3638 : 30 : return false;
3639 : : case GIMPLE_OMP_PARALLEL:
3640 : : case GIMPLE_OMP_TEAMS:
3641 : : return true;
3642 : 10 : case GIMPLE_OMP_TARGET:
3643 : 10 : if (gimple_omp_target_kind (ctx->stmt)
3644 : : == GF_OMP_TARGET_KIND_REGION)
3645 : : return true;
3646 : : break;
3647 : : default:
3648 : : break;
3649 : : }
3650 : : break;
3651 : : case GIMPLE_OMP_SCOPE:
3652 : 274 : for (; ctx != NULL; ctx = ctx->outer)
3653 : 175 : switch (gimple_code (ctx->stmt))
3654 : : {
3655 : 7 : case GIMPLE_OMP_FOR:
3656 : 7 : if (gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_FOR
3657 : 7 : && gimple_omp_for_kind (ctx->stmt) != GF_OMP_FOR_KIND_TASKLOOP)
3658 : : break;
3659 : : /* FALLTHRU */
3660 : 25 : case GIMPLE_OMP_SECTIONS:
3661 : 25 : case GIMPLE_OMP_SINGLE:
3662 : 25 : case GIMPLE_OMP_TASK:
3663 : 25 : case GIMPLE_OMP_CRITICAL:
3664 : 25 : case GIMPLE_OMP_ORDERED:
3665 : 25 : case GIMPLE_OMP_MASTER:
3666 : 25 : case GIMPLE_OMP_MASKED:
3667 : 25 : error_at (gimple_location (stmt),
3668 : : "%<scope%> region may not be closely nested inside "
3669 : : "of work-sharing, %<loop%>, explicit %<task%>, "
3670 : : "%<taskloop%>, %<critical%>, %<ordered%>, %<master%>, "
3671 : : "or %<masked%> region");
3672 : 25 : return false;
3673 : : case GIMPLE_OMP_PARALLEL:
3674 : : case GIMPLE_OMP_TEAMS:
3675 : : return true;
3676 : 5 : case GIMPLE_OMP_TARGET:
3677 : 5 : if (gimple_omp_target_kind (ctx->stmt)
3678 : : == GF_OMP_TARGET_KIND_REGION)
3679 : : return true;
3680 : : break;
3681 : : default:
3682 : : break;
3683 : : }
3684 : : break;
3685 : 5369 : case GIMPLE_OMP_TASK:
3686 : 22912 : for (c = gimple_omp_task_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
3687 : 17547 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS)
3688 : : {
3689 : 4 : enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_KIND (c);
3690 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
3691 : : "%<%s(%s)%> is only allowed in %<omp ordered%>",
3692 : 4 : OMP_CLAUSE_DOACROSS_DEPEND (c) ? "depend" : "doacross",
3693 : : kind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink");
3694 : 4 : return false;
3695 : : }
3696 : : break;
3697 : 1631 : case GIMPLE_OMP_ORDERED:
3698 : 2873 : for (c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt));
3699 : 2873 : c; c = OMP_CLAUSE_CHAIN (c))
3700 : : {
3701 : 1258 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DOACROSS)
3702 : : {
3703 : 169 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
3704 : : {
3705 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
3706 : : "invalid depend kind in omp %<ordered%> %<depend%>");
3707 : 4 : return false;
3708 : : }
3709 : 165 : gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREADS
3710 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMD);
3711 : 165 : continue;
3712 : : }
3713 : :
3714 : 1089 : tree oclause;
3715 : : /* Look for containing ordered(N) loop. */
3716 : 1089 : if (ctx == NULL
3717 : 1077 : || gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
3718 : 1089 : || (oclause
3719 : 1077 : = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
3720 : : OMP_CLAUSE_ORDERED)) == NULL_TREE)
3721 : : {
3722 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
3723 : : "%<ordered%> construct with %<depend%> clause "
3724 : : "must be closely nested inside an %<ordered%> loop");
3725 : 12 : return false;
3726 : : }
3727 : : }
3728 : 1615 : c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt));
3729 : 1615 : if (omp_find_clause (c, OMP_CLAUSE_SIMD))
3730 : : {
3731 : : /* ordered simd must be closely nested inside of simd region,
3732 : : and simd region must not encounter constructs other than
3733 : : ordered simd, therefore ordered simd may be either orphaned,
3734 : : or ctx->stmt must be simd. The latter case is handled already
3735 : : earlier. */
3736 : 34 : if (ctx != NULL)
3737 : : {
3738 : 10 : error_at (gimple_location (stmt),
3739 : : "%<ordered%> %<simd%> must be closely nested inside "
3740 : : "%<simd%> region");
3741 : 10 : return false;
3742 : : }
3743 : : }
3744 : 1605 : for (; ctx != NULL; ctx = ctx->outer)
3745 : 1474 : switch (gimple_code (ctx->stmt))
3746 : : {
3747 : 38 : case GIMPLE_OMP_CRITICAL:
3748 : 38 : case GIMPLE_OMP_TASK:
3749 : 38 : case GIMPLE_OMP_ORDERED:
3750 : 38 : ordered_in_taskloop:
3751 : 38 : error_at (gimple_location (stmt),
3752 : : "%<ordered%> region may not be closely nested inside "
3753 : : "of %<critical%>, %<ordered%>, explicit %<task%> or "
3754 : : "%<taskloop%> region");
3755 : 38 : return false;
3756 : 1416 : case GIMPLE_OMP_FOR:
3757 : 1416 : if (gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_TASKLOOP)
3758 : 10 : goto ordered_in_taskloop;
3759 : 1406 : tree o;
3760 : 1406 : o = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
3761 : : OMP_CLAUSE_ORDERED);
3762 : 1406 : if (o == NULL)
3763 : : {
3764 : 22 : error_at (gimple_location (stmt),
3765 : : "%<ordered%> region must be closely nested inside "
3766 : : "a loop region with an %<ordered%> clause");
3767 : 22 : return false;
3768 : : }
3769 : 1384 : if (!gimple_omp_ordered_standalone_p (stmt))
3770 : : {
3771 : 375 : if (OMP_CLAUSE_ORDERED_DOACROSS (o))
3772 : : {
3773 : 10 : error_at (gimple_location (stmt),
3774 : : "%<ordered%> construct without %<doacross%> or "
3775 : : "%<depend%> clauses must not have the same "
3776 : : "binding region as %<ordered%> construct with "
3777 : : "those clauses");
3778 : 10 : return false;
3779 : : }
3780 : 365 : else if (OMP_CLAUSE_ORDERED_EXPR (o))
3781 : : {
3782 : 23 : tree co
3783 : 23 : = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
3784 : : OMP_CLAUSE_COLLAPSE);
3785 : 23 : HOST_WIDE_INT
3786 : 23 : o_n = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (o));
3787 : 23 : HOST_WIDE_INT c_n = 1;
3788 : 23 : if (co)
3789 : 5 : c_n = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
3790 : 23 : if (o_n != c_n)
3791 : : {
3792 : 10 : error_at (gimple_location (stmt),
3793 : : "%<ordered%> construct without %<doacross%> "
3794 : : "or %<depend%> clauses binds to loop where "
3795 : : "%<collapse%> argument %wd is different from "
3796 : : "%<ordered%> argument %wd", c_n, o_n);
3797 : 10 : return false;
3798 : : }
3799 : : }
3800 : : }
3801 : : return true;
3802 : 10 : case GIMPLE_OMP_TARGET:
3803 : 10 : if (gimple_omp_target_kind (ctx->stmt)
3804 : : != GF_OMP_TARGET_KIND_REGION)
3805 : : break;
3806 : : /* FALLTHRU */
3807 : 30 : case GIMPLE_OMP_PARALLEL:
3808 : 30 : case GIMPLE_OMP_TEAMS:
3809 : 30 : error_at (gimple_location (stmt),
3810 : : "%<ordered%> region must be closely nested inside "
3811 : : "a loop region with an %<ordered%> clause");
3812 : 30 : return false;
3813 : : default:
3814 : : break;
3815 : : }
3816 : : break;
3817 : 462 : case GIMPLE_OMP_CRITICAL:
3818 : 462 : {
3819 : 462 : tree this_stmt_name
3820 : 462 : = gimple_omp_critical_name (as_a <gomp_critical *> (stmt));
3821 : 888 : for (; ctx != NULL; ctx = ctx->outer)
3822 : 432 : if (gomp_critical *other_crit
3823 : 451 : = dyn_cast <gomp_critical *> (ctx->stmt))
3824 : 25 : if (this_stmt_name == gimple_omp_critical_name (other_crit))
3825 : : {
3826 : 6 : error_at (gimple_location (stmt),
3827 : : "%<critical%> region may not be nested inside "
3828 : : "a %<critical%> region with the same name");
3829 : 6 : return false;
3830 : : }
3831 : : }
3832 : : break;
3833 : 8777 : case GIMPLE_OMP_TEAMS:
3834 : 8777 : if (ctx == NULL)
3835 : : break;
3836 : 6162 : else if (gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET
3837 : 6162 : || (gimple_omp_target_kind (ctx->stmt)
3838 : : != GF_OMP_TARGET_KIND_REGION))
3839 : : {
3840 : : /* Teams construct can appear either strictly nested inside of
3841 : : target construct with no intervening stmts, or can be encountered
3842 : : only by initial task (so must not appear inside any OpenMP
3843 : : construct. */
3844 : 44 : error_at (gimple_location (stmt),
3845 : : "%<teams%> construct must be closely nested inside of "
3846 : : "%<target%> construct or not nested in any OpenMP "
3847 : : "construct");
3848 : 44 : return false;
3849 : : }
3850 : : break;
3851 : 41327 : case GIMPLE_OMP_TARGET:
3852 : 183500 : for (c = gimple_omp_target_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
3853 : 142177 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS)
3854 : : {
3855 : 4 : enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_KIND (c);
3856 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
3857 : : "%<depend(%s)%> is only allowed in %<omp ordered%>",
3858 : : kind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink");
3859 : 4 : return false;
3860 : : }
3861 : 41323 : if (is_gimple_omp_offloaded (stmt)
3862 : 41323 : && oacc_get_fn_attrib (cfun->decl) != NULL)
3863 : : {
3864 : 4 : error_at (gimple_location (stmt),
3865 : : "OpenACC region inside of OpenACC routine, nested "
3866 : : "parallelism not supported yet");
3867 : 4 : return false;
3868 : : }
3869 : 48730 : for (; ctx != NULL; ctx = ctx->outer)
3870 : : {
3871 : 7817 : if (gimple_code (ctx->stmt) != GIMPLE_OMP_TARGET)
3872 : : {
3873 : 768 : if (is_gimple_omp (stmt)
3874 : 768 : && is_gimple_omp_oacc (stmt)
3875 : 242 : && is_gimple_omp (ctx->stmt))
3876 : : {
3877 : 242 : error_at (gimple_location (stmt),
3878 : : "OpenACC construct inside of non-OpenACC region");
3879 : 242 : return false;
3880 : : }
3881 : 526 : continue;
3882 : : }
3883 : :
3884 : 7049 : const char *stmt_name, *ctx_stmt_name;
3885 : 7049 : switch (gimple_omp_target_kind (stmt))
3886 : : {
3887 : : case GF_OMP_TARGET_KIND_REGION: stmt_name = "target"; break;
3888 : 399 : case GF_OMP_TARGET_KIND_DATA: stmt_name = "target data"; break;
3889 : 1688 : case GF_OMP_TARGET_KIND_UPDATE: stmt_name = "target update"; break;
3890 : 12 : case GF_OMP_TARGET_KIND_ENTER_DATA:
3891 : 12 : stmt_name = "target enter data"; break;
3892 : 18 : case GF_OMP_TARGET_KIND_EXIT_DATA:
3893 : 18 : stmt_name = "target exit data"; break;
3894 : 1442 : case GF_OMP_TARGET_KIND_OACC_PARALLEL: stmt_name = "parallel"; break;
3895 : 1618 : case GF_OMP_TARGET_KIND_OACC_KERNELS: stmt_name = "kernels"; break;
3896 : 183 : case GF_OMP_TARGET_KIND_OACC_SERIAL: stmt_name = "serial"; break;
3897 : 386 : case GF_OMP_TARGET_KIND_OACC_DATA: stmt_name = "data"; break;
3898 : 256 : case GF_OMP_TARGET_KIND_OACC_UPDATE: stmt_name = "update"; break;
3899 : 94 : case GF_OMP_TARGET_KIND_OACC_ENTER_DATA:
3900 : 94 : stmt_name = "enter data"; break;
3901 : 86 : case GF_OMP_TARGET_KIND_OACC_EXIT_DATA:
3902 : 86 : stmt_name = "exit data"; break;
3903 : 64 : case GF_OMP_TARGET_KIND_OACC_DECLARE: stmt_name = "declare"; break;
3904 : 128 : case GF_OMP_TARGET_KIND_OACC_HOST_DATA: stmt_name = "host_data";
3905 : 128 : break;
3906 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
3907 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
3908 : : case GF_OMP_TARGET_KIND_OACC_DATA_KERNELS:
3909 : : /* OpenACC 'kernels' decomposed parts. */
3910 : 1618 : stmt_name = "kernels"; break;
3911 : 0 : default: gcc_unreachable ();
3912 : : }
3913 : 7049 : switch (gimple_omp_target_kind (ctx->stmt))
3914 : : {
3915 : : case GF_OMP_TARGET_KIND_REGION: ctx_stmt_name = "target"; break;
3916 : 2712 : case GF_OMP_TARGET_KIND_DATA: ctx_stmt_name = "target data"; break;
3917 : 35 : case GF_OMP_TARGET_KIND_OACC_PARALLEL:
3918 : 35 : ctx_stmt_name = "parallel"; break;
3919 : : case GF_OMP_TARGET_KIND_OACC_KERNELS:
3920 : 1034 : ctx_stmt_name = "kernels"; break;
3921 : 35 : case GF_OMP_TARGET_KIND_OACC_SERIAL:
3922 : 35 : ctx_stmt_name = "serial"; break;
3923 : 3117 : case GF_OMP_TARGET_KIND_OACC_DATA: ctx_stmt_name = "data"; break;
3924 : 8 : case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
3925 : 8 : ctx_stmt_name = "host_data"; break;
3926 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
3927 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
3928 : : case GF_OMP_TARGET_KIND_OACC_DATA_KERNELS:
3929 : : /* OpenACC 'kernels' decomposed parts. */
3930 : 1034 : ctx_stmt_name = "kernels"; break;
3931 : 0 : default: gcc_unreachable ();
3932 : : }
3933 : :
3934 : : /* OpenACC/OpenMP mismatch? */
3935 : 14098 : if (is_gimple_omp_oacc (stmt)
3936 : 7049 : != is_gimple_omp_oacc (ctx->stmt))
3937 : : {
3938 : 56 : error_at (gimple_location (stmt),
3939 : : "%s %qs construct inside of %s %qs region",
3940 : : (is_gimple_omp_oacc (stmt)
3941 : : ? "OpenACC" : "OpenMP"), stmt_name,
3942 : : (is_gimple_omp_oacc (ctx->stmt)
3943 : : ? "OpenACC" : "OpenMP"), ctx_stmt_name);
3944 : 28 : return false;
3945 : : }
3946 : 7021 : if (is_gimple_omp_offloaded (ctx->stmt))
3947 : : {
3948 : : /* No GIMPLE_OMP_TARGET inside offloaded OpenACC CTX. */
3949 : 185 : if (is_gimple_omp_oacc (ctx->stmt))
3950 : : {
3951 : 105 : error_at (gimple_location (stmt),
3952 : : "%qs construct inside of %qs region",
3953 : : stmt_name, ctx_stmt_name);
3954 : 105 : return false;
3955 : : }
3956 : : else
3957 : : {
3958 : 80 : if ((gimple_omp_target_kind (ctx->stmt)
3959 : : == GF_OMP_TARGET_KIND_REGION)
3960 : 80 : && (gimple_omp_target_kind (stmt)
3961 : : == GF_OMP_TARGET_KIND_REGION))
3962 : : {
3963 : 58 : c = omp_find_clause (gimple_omp_target_clauses (stmt),
3964 : : OMP_CLAUSE_DEVICE);
3965 : 58 : if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c))
3966 : : break;
3967 : : }
3968 : 49 : warning_at (gimple_location (stmt), OPT_Wopenmp,
3969 : : "%qs construct inside of %qs region",
3970 : : stmt_name, ctx_stmt_name);
3971 : : }
3972 : : }
3973 : : }
3974 : : break;
3975 : : default:
3976 : : break;
3977 : : }
3978 : : return true;
3979 : : }
3980 : :
3981 : :
3982 : : /* Helper function scan_omp.
3983 : :
3984 : : Callback for walk_tree or operators in walk_gimple_stmt used to
3985 : : scan for OMP directives in TP. */
3986 : :
3987 : : static tree
3988 : 9203905 : scan_omp_1_op (tree *tp, int *walk_subtrees, void *data)
3989 : : {
3990 : 9203905 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
3991 : 9203905 : omp_context *ctx = (omp_context *) wi->info;
3992 : 9203905 : tree t = *tp;
3993 : 9203905 : tree tmp;
3994 : :
3995 : 9203905 : switch (TREE_CODE (t))
3996 : : {
3997 : 3996410 : case VAR_DECL:
3998 : 3996410 : case PARM_DECL:
3999 : 3996410 : case LABEL_DECL:
4000 : 3996410 : case RESULT_DECL:
4001 : 3996410 : if (ctx)
4002 : : {
4003 : 2082895 : tmp = NULL_TREE;
4004 : 2082895 : if (TREE_CODE (t) == VAR_DECL
4005 : 3728594 : && (tmp = lookup_attribute ("omp allocate var",
4006 : 1645699 : DECL_ATTRIBUTES (t))) != NULL_TREE)
4007 : 69 : t = TREE_VALUE (TREE_VALUE (tmp));
4008 : 2082895 : tree repl = remap_decl (t, &ctx->cb);
4009 : 2082895 : gcc_checking_assert (TREE_CODE (repl) != ERROR_MARK);
4010 : 2082895 : if (tmp != NULL_TREE && t != repl)
4011 : 31 : *tp = build_fold_addr_expr (repl);
4012 : 2082864 : else if (tmp == NULL_TREE)
4013 : 2082826 : *tp = repl;
4014 : : }
4015 : : break;
4016 : :
4017 : 176034 : case INDIRECT_REF:
4018 : 176034 : case MEM_REF:
4019 : 176034 : if (ctx
4020 : 76848 : && TREE_CODE (TREE_OPERAND (t, 0)) == VAR_DECL
4021 : 233868 : && ((tmp = lookup_attribute ("omp allocate var",
4022 : 57834 : DECL_ATTRIBUTES (TREE_OPERAND (t, 0))))
4023 : : != NULL_TREE))
4024 : : {
4025 : 131 : tmp = TREE_VALUE (TREE_VALUE (tmp));
4026 : 131 : tree repl = remap_decl (tmp, &ctx->cb);
4027 : 131 : gcc_checking_assert (TREE_CODE (repl) != ERROR_MARK);
4028 : 131 : if (tmp != repl)
4029 : 120 : *tp = repl;
4030 : : break;
4031 : : }
4032 : 5207364 : gcc_fallthrough ();
4033 : :
4034 : 5207364 : default:
4035 : 5207364 : if (ctx && TYPE_P (t))
4036 : 5 : *tp = remap_type (t, &ctx->cb);
4037 : 5207359 : else if (!DECL_P (t))
4038 : : {
4039 : 4344612 : *walk_subtrees = 1;
4040 : 4344612 : if (ctx)
4041 : : {
4042 : 1398579 : tree tem = remap_type (TREE_TYPE (t), &ctx->cb);
4043 : 1398579 : if (tem != TREE_TYPE (t))
4044 : : {
4045 : 9771 : if (TREE_CODE (t) == INTEGER_CST)
4046 : 4114 : *tp = wide_int_to_tree (tem, wi::to_wide (t));
4047 : : else
4048 : 5657 : TREE_TYPE (t) = tem;
4049 : : }
4050 : : }
4051 : : }
4052 : : break;
4053 : : }
4054 : :
4055 : 9203905 : return NULL_TREE;
4056 : : }
4057 : :
4058 : : /* Return true if FNDECL is a setjmp or a longjmp. */
4059 : :
4060 : : static bool
4061 : 3040 : setjmp_or_longjmp_p (const_tree fndecl)
4062 : : {
4063 : 3040 : if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
4064 : : return true;
4065 : :
4066 : 3040 : tree declname = DECL_NAME (fndecl);
4067 : 3040 : if (!declname
4068 : 3040 : || (DECL_CONTEXT (fndecl) != NULL_TREE
4069 : 2345 : && TREE_CODE (DECL_CONTEXT (fndecl)) != TRANSLATION_UNIT_DECL)
4070 : 5829 : || !TREE_PUBLIC (fndecl))
4071 : : return false;
4072 : :
4073 : 2627 : const char *name = IDENTIFIER_POINTER (declname);
4074 : 2627 : return !strcmp (name, "setjmp") || !strcmp (name, "longjmp");
4075 : : }
4076 : :
4077 : : /* Helper function for scan_omp.
4078 : :
4079 : : Callback for walk_gimple_stmt used to scan for OMP directives in
4080 : : the current statement in GSI. */
4081 : :
4082 : : static tree
4083 : 3252604 : scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
4084 : : struct walk_stmt_info *wi)
4085 : : {
4086 : 3252604 : gimple *stmt = gsi_stmt (*gsi);
4087 : 3252604 : omp_context *ctx = (omp_context *) wi->info;
4088 : :
4089 : 3252604 : if (gimple_has_location (stmt))
4090 : 2645547 : input_location = gimple_location (stmt);
4091 : :
4092 : : /* Check the nesting restrictions. */
4093 : 3252604 : bool remove = false;
4094 : 3252604 : if (is_gimple_omp (stmt))
4095 : 151673 : remove = !check_omp_nesting_restrictions (stmt, ctx);
4096 : 3100931 : else if (is_gimple_call (stmt))
4097 : : {
4098 : 225689 : tree fndecl = gimple_call_fndecl (stmt);
4099 : 225689 : if (fndecl)
4100 : : {
4101 : 210321 : if (ctx
4102 : 67403 : && gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
4103 : 14652 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD
4104 : 3040 : && setjmp_or_longjmp_p (fndecl)
4105 : 210329 : && !ctx->loop_p)
4106 : : {
4107 : 4 : remove = true;
4108 : 4 : error_at (gimple_location (stmt),
4109 : : "setjmp/longjmp inside %<simd%> construct");
4110 : : }
4111 : 210317 : else if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
4112 : 60452 : switch (DECL_FUNCTION_CODE (fndecl))
4113 : : {
4114 : 4219 : case BUILT_IN_GOMP_BARRIER:
4115 : 4219 : case BUILT_IN_GOMP_CANCEL:
4116 : 4219 : case BUILT_IN_GOMP_CANCELLATION_POINT:
4117 : 4219 : case BUILT_IN_GOMP_TASKYIELD:
4118 : 4219 : case BUILT_IN_GOMP_TASKWAIT:
4119 : 4219 : case BUILT_IN_GOMP_TASKGROUP_START:
4120 : 4219 : case BUILT_IN_GOMP_TASKGROUP_END:
4121 : 4219 : remove = !check_omp_nesting_restrictions (stmt, ctx);
4122 : 4219 : break;
4123 : : default:
4124 : : break;
4125 : : }
4126 : 149865 : else if (ctx)
4127 : : {
4128 : 45573 : omp_context *octx = ctx;
4129 : 45573 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_SCAN && ctx->outer)
4130 : 45573 : octx = ctx->outer;
4131 : 45573 : if (octx->order_concurrent && omp_runtime_api_call (fndecl))
4132 : : {
4133 : 240 : remove = true;
4134 : 240 : error_at (gimple_location (stmt),
4135 : : "OpenMP runtime API call %qD in a region with "
4136 : : "%<order(concurrent)%> clause", fndecl);
4137 : : }
4138 : 45573 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
4139 : 3293 : && omp_runtime_api_call (fndecl)
4140 : 315 : && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl))
4141 : : != strlen ("omp_get_num_teams"))
4142 : 182 : || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)),
4143 : : "omp_get_num_teams") != 0)
4144 : 45721 : && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl))
4145 : : != strlen ("omp_get_team_num"))
4146 : 121 : || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)),
4147 : : "omp_get_team_num") != 0))
4148 : : {
4149 : 27 : remove = true;
4150 : 27 : error_at (gimple_location (stmt),
4151 : : "OpenMP runtime API call %qD strictly nested in a "
4152 : : "%<teams%> region", fndecl);
4153 : : }
4154 : 45573 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TARGET
4155 : 13064 : && (gimple_omp_target_kind (ctx->stmt)
4156 : : == GF_OMP_TARGET_KIND_REGION)
4157 : 50252 : && omp_runtime_api_call (fndecl))
4158 : : {
4159 : 365 : tree tgt_clauses = gimple_omp_target_clauses (ctx->stmt);
4160 : 365 : tree c = omp_find_clause (tgt_clauses, OMP_CLAUSE_DEVICE);
4161 : 365 : if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c))
4162 : 5 : error_at (gimple_location (stmt),
4163 : : "OpenMP runtime API call %qD in a region with "
4164 : : "%<device(ancestor)%> clause", fndecl);
4165 : : }
4166 : : }
4167 : : }
4168 : : }
4169 : 201469 : if (remove)
4170 : : {
4171 : 3326 : stmt = gimple_build_nop ();
4172 : 3326 : gsi_replace (gsi, stmt, false);
4173 : : }
4174 : :
4175 : 3252604 : *handled_ops_p = true;
4176 : :
4177 : 3252604 : switch (gimple_code (stmt))
4178 : : {
4179 : 18134 : case GIMPLE_OMP_PARALLEL:
4180 : 18134 : taskreg_nesting_level++;
4181 : 18134 : scan_omp_parallel (gsi, ctx);
4182 : 18134 : taskreg_nesting_level--;
4183 : 18134 : break;
4184 : :
4185 : 5365 : case GIMPLE_OMP_TASK:
4186 : 5365 : taskreg_nesting_level++;
4187 : 5365 : scan_omp_task (gsi, ctx);
4188 : 5365 : taskreg_nesting_level--;
4189 : 5365 : break;
4190 : :
4191 : 52695 : case GIMPLE_OMP_FOR:
4192 : 52695 : if ((gimple_omp_for_kind (as_a <gomp_for *> (stmt))
4193 : : == GF_OMP_FOR_KIND_SIMD)
4194 : 10805 : && gimple_omp_for_combined_into_p (stmt)
4195 : 60387 : && gimple_code (ctx->stmt) != GIMPLE_OMP_SCAN)
4196 : : {
4197 : 7526 : tree clauses = gimple_omp_for_clauses (as_a <gomp_for *> (stmt));
4198 : 7526 : tree c = omp_find_clause (clauses, OMP_CLAUSE_REDUCTION);
4199 : 7526 : if (c && OMP_CLAUSE_REDUCTION_INSCAN (c) && !seen_error ())
4200 : : {
4201 : 83 : scan_omp_simd_scan (gsi, as_a <gomp_for *> (stmt), ctx);
4202 : 83 : break;
4203 : : }
4204 : : }
4205 : 52612 : if ((gimple_omp_for_kind (as_a <gomp_for *> (stmt))
4206 : : == GF_OMP_FOR_KIND_SIMD)
4207 : 10722 : && omp_maybe_offloaded_ctx (ctx)
4208 : 3641 : && omp_max_simt_vf ()
4209 : 52612 : && gimple_omp_for_collapse (stmt) == 1)
4210 : 0 : scan_omp_simd (gsi, as_a <gomp_for *> (stmt), ctx);
4211 : : else
4212 : 52612 : scan_omp_for (as_a <gomp_for *> (stmt), ctx);
4213 : : break;
4214 : :
4215 : 184 : case GIMPLE_OMP_SCOPE:
4216 : 184 : ctx = new_omp_context (stmt, ctx);
4217 : 184 : scan_sharing_clauses (gimple_omp_scope_clauses (stmt), ctx);
4218 : 184 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
4219 : 184 : break;
4220 : :
4221 : 852 : case GIMPLE_OMP_DISPATCH:
4222 : 852 : ctx = new_omp_context (stmt, ctx);
4223 : 852 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
4224 : 852 : break;
4225 : :
4226 : 612 : case GIMPLE_OMP_INTEROP:
4227 : 612 : ctx = new_omp_context (stmt, ctx);
4228 : 612 : break;
4229 : :
4230 : 581 : case GIMPLE_OMP_SECTIONS:
4231 : 581 : scan_omp_sections (as_a <gomp_sections *> (stmt), ctx);
4232 : 581 : break;
4233 : :
4234 : 1228 : case GIMPLE_OMP_SINGLE:
4235 : 1228 : scan_omp_single (as_a <gomp_single *> (stmt), ctx);
4236 : 1228 : break;
4237 : :
4238 : 1284 : case GIMPLE_OMP_SCAN:
4239 : 1284 : if (tree clauses = gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt)))
4240 : : {
4241 : 606 : if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_INCLUSIVE)
4242 : 304 : ctx->scan_inclusive = true;
4243 : 302 : else if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_EXCLUSIVE)
4244 : 302 : ctx->scan_exclusive = true;
4245 : : }
4246 : : /* FALLTHRU */
4247 : 6207 : case GIMPLE_OMP_SECTION:
4248 : 6207 : case GIMPLE_OMP_STRUCTURED_BLOCK:
4249 : 6207 : case GIMPLE_OMP_MASTER:
4250 : 6207 : case GIMPLE_OMP_ORDERED:
4251 : 6207 : case GIMPLE_OMP_CRITICAL:
4252 : 6207 : ctx = new_omp_context (stmt, ctx);
4253 : 6207 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
4254 : 6207 : break;
4255 : :
4256 : 447 : case GIMPLE_OMP_MASKED:
4257 : 447 : ctx = new_omp_context (stmt, ctx);
4258 : 447 : scan_sharing_clauses (gimple_omp_masked_clauses (stmt), ctx);
4259 : 447 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
4260 : 447 : break;
4261 : :
4262 : 607 : case GIMPLE_OMP_TASKGROUP:
4263 : 607 : ctx = new_omp_context (stmt, ctx);
4264 : 607 : scan_sharing_clauses (gimple_omp_taskgroup_clauses (stmt), ctx);
4265 : 607 : scan_omp (gimple_omp_body_ptr (stmt), ctx);
4266 : 607 : break;
4267 : :
4268 : 40944 : case GIMPLE_OMP_TARGET:
4269 : 40944 : if (is_gimple_omp_offloaded (stmt))
4270 : : {
4271 : 24265 : taskreg_nesting_level++;
4272 : 24265 : scan_omp_target (as_a <gomp_target *> (stmt), ctx);
4273 : 24265 : taskreg_nesting_level--;
4274 : : }
4275 : : else
4276 : 16679 : scan_omp_target (as_a <gomp_target *> (stmt), ctx);
4277 : : break;
4278 : :
4279 : 8733 : case GIMPLE_OMP_TEAMS:
4280 : 8733 : if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
4281 : : {
4282 : 2615 : taskreg_nesting_level++;
4283 : 2615 : scan_omp_teams (as_a <gomp_teams *> (stmt), ctx);
4284 : 2615 : taskreg_nesting_level--;
4285 : : }
4286 : : else
4287 : 6118 : scan_omp_teams (as_a <gomp_teams *> (stmt), ctx);
4288 : : break;
4289 : :
4290 : 273487 : case GIMPLE_BIND:
4291 : 273487 : {
4292 : 273487 : tree var;
4293 : :
4294 : 273487 : *handled_ops_p = false;
4295 : 273487 : if (ctx)
4296 : 150060 : for (var = gimple_bind_vars (as_a <gbind *> (stmt));
4297 : 565438 : var ;
4298 : 415378 : var = DECL_CHAIN (var))
4299 : 415378 : insert_decl_map (&ctx->cb, var, var);
4300 : : }
4301 : : break;
4302 : 2842528 : default:
4303 : 2842528 : *handled_ops_p = false;
4304 : 2842528 : break;
4305 : : }
4306 : :
4307 : 3252604 : return NULL_TREE;
4308 : : }
4309 : :
4310 : :
4311 : : /* Scan all the statements starting at the current statement. CTX
4312 : : contains context information about the OMP directives and
4313 : : clauses found during the scan. */
4314 : :
4315 : : static void
4316 : 256288 : scan_omp (gimple_seq *body_p, omp_context *ctx)
4317 : : {
4318 : 256288 : location_t saved_location;
4319 : 256288 : struct walk_stmt_info wi;
4320 : :
4321 : 256288 : memset (&wi, 0, sizeof (wi));
4322 : 256288 : wi.info = ctx;
4323 : 256288 : wi.want_locations = true;
4324 : :
4325 : 256288 : saved_location = input_location;
4326 : 256288 : walk_gimple_seq_mod (body_p, scan_omp_1_stmt, scan_omp_1_op, &wi);
4327 : 256288 : input_location = saved_location;
4328 : 256288 : }
4329 : :
4330 : : /* Re-gimplification and code generation routines. */
4331 : :
4332 : : /* Remove omp_member_access_dummy_var variables from gimple_bind_vars
4333 : : of BIND if in a method. */
4334 : :
4335 : : static void
4336 : 252821 : maybe_remove_omp_member_access_dummy_vars (gbind *bind)
4337 : : {
4338 : 252821 : if (DECL_ARGUMENTS (current_function_decl)
4339 : 96693 : && DECL_ARTIFICIAL (DECL_ARGUMENTS (current_function_decl))
4340 : 262742 : && (TREE_CODE (TREE_TYPE (DECL_ARGUMENTS (current_function_decl)))
4341 : : == POINTER_TYPE))
4342 : : {
4343 : 3449 : tree vars = gimple_bind_vars (bind);
4344 : 19249 : for (tree *pvar = &vars; *pvar; )
4345 : 15800 : if (omp_member_access_dummy_var (*pvar))
4346 : 719 : *pvar = DECL_CHAIN (*pvar);
4347 : : else
4348 : 15081 : pvar = &DECL_CHAIN (*pvar);
4349 : 3449 : gimple_bind_set_vars (bind, vars);
4350 : : }
4351 : 252821 : }
4352 : :
4353 : : /* Remove omp_member_access_dummy_var variables from BLOCK_VARS of
4354 : : block and its subblocks. */
4355 : :
4356 : : static void
4357 : 12849 : remove_member_access_dummy_vars (tree block)
4358 : : {
4359 : 22073 : for (tree *pvar = &BLOCK_VARS (block); *pvar; )
4360 : 9224 : if (omp_member_access_dummy_var (*pvar))
4361 : 108 : *pvar = DECL_CHAIN (*pvar);
4362 : : else
4363 : 9116 : pvar = &DECL_CHAIN (*pvar);
4364 : :
4365 : 16644 : for (block = BLOCK_SUBBLOCKS (block); block; block = BLOCK_CHAIN (block))
4366 : 3795 : remove_member_access_dummy_vars (block);
4367 : 12849 : }
4368 : :
4369 : : /* If a context was created for STMT when it was scanned, return it. */
4370 : :
4371 : : static omp_context *
4372 : 120230 : maybe_lookup_ctx (gimple *stmt)
4373 : : {
4374 : 120230 : splay_tree_node n;
4375 : 120230 : n = splay_tree_lookup (all_contexts, (splay_tree_key) stmt);
4376 : 120230 : return n ? (omp_context *) n->value : NULL;
4377 : : }
4378 : :
4379 : :
4380 : : /* Find the mapping for DECL in CTX or the immediately enclosing
4381 : : context that has a mapping for DECL.
4382 : :
4383 : : If CTX is a nested parallel directive, we may have to use the decl
4384 : : mappings created in CTX's parent context. Suppose that we have the
4385 : : following parallel nesting (variable UIDs showed for clarity):
4386 : :
4387 : : iD.1562 = 0;
4388 : : #omp parallel shared(iD.1562) -> outer parallel
4389 : : iD.1562 = iD.1562 + 1;
4390 : :
4391 : : #omp parallel shared (iD.1562) -> inner parallel
4392 : : iD.1562 = iD.1562 - 1;
4393 : :
4394 : : Each parallel structure will create a distinct .omp_data_s structure
4395 : : for copying iD.1562 in/out of the directive:
4396 : :
4397 : : outer parallel .omp_data_s.1.i -> iD.1562
4398 : : inner parallel .omp_data_s.2.i -> iD.1562
4399 : :
4400 : : A shared variable mapping will produce a copy-out operation before
4401 : : the parallel directive and a copy-in operation after it. So, in
4402 : : this case we would have:
4403 : :
4404 : : iD.1562 = 0;
4405 : : .omp_data_o.1.i = iD.1562;
4406 : : #omp parallel shared(iD.1562) -> outer parallel
4407 : : .omp_data_i.1 = &.omp_data_o.1
4408 : : .omp_data_i.1->i = .omp_data_i.1->i + 1;
4409 : :
4410 : : .omp_data_o.2.i = iD.1562; -> **
4411 : : #omp parallel shared(iD.1562) -> inner parallel
4412 : : .omp_data_i.2 = &.omp_data_o.2
4413 : : .omp_data_i.2->i = .omp_data_i.2->i - 1;
4414 : :
4415 : :
4416 : : ** This is a problem. The symbol iD.1562 cannot be referenced
4417 : : inside the body of the outer parallel region. But since we are
4418 : : emitting this copy operation while expanding the inner parallel
4419 : : directive, we need to access the CTX structure of the outer
4420 : : parallel directive to get the correct mapping:
4421 : :
4422 : : .omp_data_o.2.i = .omp_data_i.1->i
4423 : :
4424 : : Since there may be other workshare or parallel directives enclosing
4425 : : the parallel directive, it may be necessary to walk up the context
4426 : : parent chain. This is not a problem in general because nested
4427 : : parallelism happens only rarely. */
4428 : :
4429 : : static tree
4430 : 124760 : lookup_decl_in_outer_ctx (tree decl, omp_context *ctx)
4431 : : {
4432 : 124760 : tree t;
4433 : 124760 : omp_context *up;
4434 : :
4435 : 181466 : for (up = ctx->outer, t = NULL; up && t == NULL; up = up->outer)
4436 : 56706 : t = maybe_lookup_decl (decl, up);
4437 : :
4438 : 124760 : gcc_assert (!ctx->is_nested || t || is_global_var (decl));
4439 : :
4440 : 96451 : return t ? t : decl;
4441 : : }
4442 : :
4443 : :
4444 : : /* Similar to lookup_decl_in_outer_ctx, but return DECL if not found
4445 : : in outer contexts. */
4446 : :
4447 : : static tree
4448 : 354974 : maybe_lookup_decl_in_outer_ctx (tree decl, omp_context *ctx)
4449 : : {
4450 : 354974 : tree t = NULL;
4451 : 354974 : omp_context *up;
4452 : :
4453 : 626045 : for (up = ctx->outer, t = NULL; up && t == NULL; up = up->outer)
4454 : 271071 : t = maybe_lookup_decl (decl, up);
4455 : :
4456 : 354974 : return t ? t : decl;
4457 : : }
4458 : :
4459 : :
4460 : : /* Construct the initialization value for reduction operation OP. */
4461 : :
4462 : : tree
4463 : 13077 : omp_reduction_init_op (location_t loc, enum tree_code op, tree type)
4464 : : {
4465 : 13077 : switch (op)
4466 : : {
4467 : 10742 : case PLUS_EXPR:
4468 : 10742 : case MINUS_EXPR:
4469 : 10742 : case BIT_IOR_EXPR:
4470 : 10742 : case BIT_XOR_EXPR:
4471 : 10742 : case TRUTH_OR_EXPR:
4472 : 10742 : case TRUTH_ORIF_EXPR:
4473 : 10742 : case TRUTH_XOR_EXPR:
4474 : 10742 : case NE_EXPR:
4475 : 10742 : return build_zero_cst (type);
4476 : :
4477 : 1431 : case MULT_EXPR:
4478 : 1431 : case TRUTH_AND_EXPR:
4479 : 1431 : case TRUTH_ANDIF_EXPR:
4480 : 1431 : case EQ_EXPR:
4481 : 1431 : return fold_convert_loc (loc, type, integer_one_node);
4482 : :
4483 : 208 : case BIT_AND_EXPR:
4484 : 208 : return fold_convert_loc (loc, type, integer_minus_one_node);
4485 : :
4486 : 388 : case MAX_EXPR:
4487 : 388 : if (SCALAR_FLOAT_TYPE_P (type))
4488 : : {
4489 : 158 : REAL_VALUE_TYPE min;
4490 : 158 : if (HONOR_INFINITIES (type))
4491 : 158 : real_arithmetic (&min, NEGATE_EXPR, &dconstinf, NULL);
4492 : : else
4493 : 0 : real_maxval (&min, 1, TYPE_MODE (type));
4494 : 158 : return build_real (type, min);
4495 : : }
4496 : 230 : else if (POINTER_TYPE_P (type))
4497 : : {
4498 : 2 : wide_int min
4499 : 2 : = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
4500 : 2 : return wide_int_to_tree (type, min);
4501 : 2 : }
4502 : : else
4503 : : {
4504 : 228 : gcc_assert (INTEGRAL_TYPE_P (type));
4505 : 228 : return TYPE_MIN_VALUE (type);
4506 : : }
4507 : :
4508 : 308 : case MIN_EXPR:
4509 : 308 : if (SCALAR_FLOAT_TYPE_P (type))
4510 : : {
4511 : 108 : REAL_VALUE_TYPE max;
4512 : 108 : if (HONOR_INFINITIES (type))
4513 : 108 : max = dconstinf;
4514 : : else
4515 : 0 : real_maxval (&max, 0, TYPE_MODE (type));
4516 : 108 : return build_real (type, max);
4517 : : }
4518 : 200 : else if (POINTER_TYPE_P (type))
4519 : : {
4520 : 2 : wide_int max
4521 : 2 : = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
4522 : 2 : return wide_int_to_tree (type, max);
4523 : 2 : }
4524 : : else
4525 : : {
4526 : 198 : gcc_assert (INTEGRAL_TYPE_P (type));
4527 : 198 : return TYPE_MAX_VALUE (type);
4528 : : }
4529 : :
4530 : 0 : default:
4531 : 0 : gcc_unreachable ();
4532 : : }
4533 : : }
4534 : :
4535 : : /* Construct the initialization value for reduction CLAUSE. */
4536 : :
4537 : : tree
4538 : 10456 : omp_reduction_init (tree clause, tree type)
4539 : : {
4540 : 10456 : return omp_reduction_init_op (OMP_CLAUSE_LOCATION (clause),
4541 : 10456 : OMP_CLAUSE_REDUCTION_CODE (clause), type);
4542 : : }
4543 : :
4544 : : /* Return alignment to be assumed for var in CLAUSE, which should be
4545 : : OMP_CLAUSE_ALIGNED. */
4546 : :
4547 : : static tree
4548 : 140 : omp_clause_aligned_alignment (tree clause)
4549 : : {
4550 : 140 : if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
4551 : 123 : return OMP_CLAUSE_ALIGNED_ALIGNMENT (clause);
4552 : :
4553 : : /* Otherwise return implementation defined alignment. */
4554 : 17 : unsigned int al = 1;
4555 : 17 : opt_scalar_mode mode_iter;
4556 : 17 : auto_vector_modes modes;
4557 : 17 : targetm.vectorize.autovectorize_vector_modes (&modes, true);
4558 : 17 : static enum mode_class classes[]
4559 : : = { MODE_INT, MODE_VECTOR_INT, MODE_FLOAT, MODE_VECTOR_FLOAT };
4560 : 51 : for (int i = 0; i < 4; i += 2)
4561 : : /* The for loop above dictates that we only walk through scalar classes. */
4562 : 255 : FOR_EACH_MODE_IN_CLASS (mode_iter, classes[i])
4563 : : {
4564 : 221 : scalar_mode mode = mode_iter.require ();
4565 : 221 : machine_mode vmode = targetm.vectorize.preferred_simd_mode (mode);
4566 : 221 : if (GET_MODE_CLASS (vmode) != classes[i + 1])
4567 : 323 : continue;
4568 : : machine_mode alt_vmode;
4569 : 476 : for (unsigned int j = 0; j < modes.length (); ++j)
4570 : 527 : if (related_vector_mode (modes[j], mode).exists (&alt_vmode)
4571 : 578 : && known_ge (GET_MODE_SIZE (alt_vmode), GET_MODE_SIZE (vmode)))
4572 : 119 : vmode = alt_vmode;
4573 : :
4574 : 119 : tree type = lang_hooks.types.type_for_mode (mode, 1);
4575 : 119 : if (type == NULL_TREE || TYPE_MODE (type) != mode)
4576 : 17 : continue;
4577 : 102 : type = build_vector_type_for_mode (type, vmode);
4578 : 102 : if (TYPE_MODE (type) != vmode)
4579 : 0 : continue;
4580 : 102 : if (TYPE_ALIGN_UNIT (type) > al)
4581 : 17 : al = TYPE_ALIGN_UNIT (type);
4582 : : }
4583 : 17 : return build_int_cst (integer_type_node, al);
4584 : 17 : }
4585 : :
4586 : :
4587 : : /* This structure is part of the interface between lower_rec_simd_input_clauses
4588 : : and lower_rec_input_clauses. */
4589 : :
4590 : : class omplow_simd_context {
4591 : : public:
4592 : 77074 : omplow_simd_context () { memset (this, 0, sizeof (*this)); }
4593 : : tree idx;
4594 : : tree lane;
4595 : : tree lastlane;
4596 : : vec<tree, va_heap> simt_eargs;
4597 : : gimple_seq simt_dlist;
4598 : : poly_uint64 max_vf;
4599 : : bool is_simt;
4600 : : };
4601 : :
4602 : : /* Helper function of lower_rec_input_clauses, used for #pragma omp simd
4603 : : privatization. */
4604 : :
4605 : : static bool
4606 : 10229 : lower_rec_simd_input_clauses (tree new_var, omp_context *ctx,
4607 : : omplow_simd_context *sctx, tree &ivar,
4608 : : tree &lvar, tree *rvar = NULL,
4609 : : tree *rvar2 = NULL)
4610 : : {
4611 : 10229 : if (known_eq (sctx->max_vf, 0U))
4612 : : {
4613 : 4790 : sctx->max_vf = (sctx->is_simt ? omp_max_simt_vf ()
4614 : 4790 : : omp_max_vf (omp_maybe_offloaded_ctx (ctx)));
4615 : 4790 : if (maybe_gt (sctx->max_vf, 1U))
4616 : : {
4617 : 3459 : tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
4618 : : OMP_CLAUSE_SAFELEN);
4619 : 3459 : if (c)
4620 : : {
4621 : 89 : poly_uint64 safe_len;
4622 : 89 : if (!poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len)
4623 : 89 : || maybe_lt (safe_len, 1U))
4624 : 6 : sctx->max_vf = 1;
4625 : : else
4626 : 83 : sctx->max_vf = lower_bound (sctx->max_vf, safe_len);
4627 : : }
4628 : : }
4629 : 4790 : if (sctx->is_simt && !known_eq (sctx->max_vf, 1U))
4630 : : {
4631 : 0 : for (tree c = gimple_omp_for_clauses (ctx->stmt); c;
4632 : 0 : c = OMP_CLAUSE_CHAIN (c))
4633 : : {
4634 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
4635 : 0 : continue;
4636 : :
4637 : 0 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
4638 : : {
4639 : : /* UDR reductions are not supported yet for SIMT, disable
4640 : : SIMT. */
4641 : 0 : sctx->max_vf = 1;
4642 : 0 : break;
4643 : : }
4644 : :
4645 : 0 : if (truth_value_p (OMP_CLAUSE_REDUCTION_CODE (c))
4646 : 0 : && !INTEGRAL_TYPE_P (TREE_TYPE (new_var)))
4647 : : {
4648 : : /* Doing boolean operations on non-integral types is
4649 : : for conformance only, it's not worth supporting this
4650 : : for SIMT. */
4651 : 0 : sctx->max_vf = 1;
4652 : 0 : break;
4653 : : }
4654 : : }
4655 : : }
4656 : 4790 : if (maybe_gt (sctx->max_vf, 1U))
4657 : : {
4658 : 3440 : sctx->idx = create_tmp_var (unsigned_type_node);
4659 : 3440 : sctx->lane = create_tmp_var (unsigned_type_node);
4660 : : }
4661 : : }
4662 : 10229 : if (known_eq (sctx->max_vf, 1U))
4663 : : return false;
4664 : :
4665 : 7189 : if (sctx->is_simt)
4666 : : {
4667 : 0 : if (is_gimple_reg (new_var))
4668 : : {
4669 : 0 : ivar = lvar = new_var;
4670 : 0 : return true;
4671 : : }
4672 : 0 : tree type = TREE_TYPE (new_var), ptype = build_pointer_type (type);
4673 : 0 : ivar = lvar = create_tmp_var (type);
4674 : 0 : TREE_ADDRESSABLE (ivar) = 1;
4675 : 0 : DECL_ATTRIBUTES (ivar) = tree_cons (get_identifier ("omp simt private"),
4676 : 0 : NULL, DECL_ATTRIBUTES (ivar));
4677 : 0 : sctx->simt_eargs.safe_push (build1 (ADDR_EXPR, ptype, ivar));
4678 : 0 : tree clobber = build_clobber (type);
4679 : 0 : gimple *g = gimple_build_assign (ivar, clobber);
4680 : 0 : gimple_seq_add_stmt (&sctx->simt_dlist, g);
4681 : : }
4682 : : else
4683 : : {
4684 : 7189 : tree atype = build_array_type_nelts (TREE_TYPE (new_var), sctx->max_vf);
4685 : 7189 : tree avar = create_tmp_var_raw (atype);
4686 : 7189 : if (TREE_ADDRESSABLE (new_var))
4687 : 912 : TREE_ADDRESSABLE (avar) = 1;
4688 : 7189 : DECL_ATTRIBUTES (avar)
4689 : 7189 : = tree_cons (get_identifier ("omp simd array"), NULL,
4690 : 7189 : DECL_ATTRIBUTES (avar));
4691 : 7189 : gimple_add_tmp_var (avar);
4692 : 7189 : tree iavar = avar;
4693 : 7189 : if (rvar && !ctx->for_simd_scan_phase)
4694 : : {
4695 : : /* For inscan reductions, create another array temporary,
4696 : : which will hold the reduced value. */
4697 : 232 : iavar = create_tmp_var_raw (atype);
4698 : 232 : if (TREE_ADDRESSABLE (new_var))
4699 : 33 : TREE_ADDRESSABLE (iavar) = 1;
4700 : 232 : DECL_ATTRIBUTES (iavar)
4701 : 232 : = tree_cons (get_identifier ("omp simd array"), NULL,
4702 : : tree_cons (get_identifier ("omp simd inscan"), NULL,
4703 : 232 : DECL_ATTRIBUTES (iavar)));
4704 : 232 : gimple_add_tmp_var (iavar);
4705 : 232 : ctx->cb.decl_map->put (avar, iavar);
4706 : 232 : if (sctx->lastlane == NULL_TREE)
4707 : 184 : sctx->lastlane = create_tmp_var (unsigned_type_node);
4708 : 232 : *rvar = build4 (ARRAY_REF, TREE_TYPE (new_var), iavar,
4709 : : sctx->lastlane, NULL_TREE, NULL_TREE);
4710 : 232 : TREE_THIS_NOTRAP (*rvar) = 1;
4711 : :
4712 : 232 : if (ctx->scan_exclusive)
4713 : : {
4714 : : /* And for exclusive scan yet another one, which will
4715 : : hold the value during the scan phase. */
4716 : 114 : tree savar = create_tmp_var_raw (atype);
4717 : 114 : if (TREE_ADDRESSABLE (new_var))
4718 : 17 : TREE_ADDRESSABLE (savar) = 1;
4719 : 114 : DECL_ATTRIBUTES (savar)
4720 : 114 : = tree_cons (get_identifier ("omp simd array"), NULL,
4721 : : tree_cons (get_identifier ("omp simd inscan "
4722 : : "exclusive"), NULL,
4723 : 114 : DECL_ATTRIBUTES (savar)));
4724 : 114 : gimple_add_tmp_var (savar);
4725 : 114 : ctx->cb.decl_map->put (iavar, savar);
4726 : 114 : *rvar2 = build4 (ARRAY_REF, TREE_TYPE (new_var), savar,
4727 : : sctx->idx, NULL_TREE, NULL_TREE);
4728 : 114 : TREE_THIS_NOTRAP (*rvar2) = 1;
4729 : : }
4730 : : }
4731 : 7189 : ivar = build4 (ARRAY_REF, TREE_TYPE (new_var), iavar, sctx->idx,
4732 : : NULL_TREE, NULL_TREE);
4733 : 7189 : lvar = build4 (ARRAY_REF, TREE_TYPE (new_var), avar, sctx->lane,
4734 : : NULL_TREE, NULL_TREE);
4735 : 7189 : TREE_THIS_NOTRAP (ivar) = 1;
4736 : 7189 : TREE_THIS_NOTRAP (lvar) = 1;
4737 : : }
4738 : 7189 : if (DECL_P (new_var))
4739 : : {
4740 : 7035 : SET_DECL_VALUE_EXPR (new_var, lvar);
4741 : 7035 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
4742 : : }
4743 : : return true;
4744 : : }
4745 : :
4746 : : /* Helper function of lower_rec_input_clauses. For a reference
4747 : : in simd reduction, add an underlying variable it will reference. */
4748 : :
4749 : : static void
4750 : 64 : handle_simd_reference (location_t loc, tree new_vard, gimple_seq *ilist)
4751 : : {
4752 : 64 : tree z = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_vard)));
4753 : 64 : if (TREE_CONSTANT (z))
4754 : : {
4755 : 64 : z = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_vard)),
4756 : : get_name (new_vard));
4757 : 64 : gimple_add_tmp_var (z);
4758 : 64 : TREE_ADDRESSABLE (z) = 1;
4759 : 64 : z = build_fold_addr_expr_loc (loc, z);
4760 : 64 : gimplify_assign (new_vard, z, ilist);
4761 : : }
4762 : 64 : }
4763 : :
4764 : : /* Helper function for lower_rec_input_clauses. Emit into ilist sequence
4765 : : code to emit (type) (tskred_temp[idx]). */
4766 : :
4767 : : static tree
4768 : 1119 : task_reduction_read (gimple_seq *ilist, tree tskred_temp, tree type,
4769 : : unsigned idx)
4770 : : {
4771 : 1119 : unsigned HOST_WIDE_INT sz
4772 : 1119 : = tree_to_uhwi (TYPE_SIZE_UNIT (pointer_sized_int_node));
4773 : 1119 : tree r = build2 (MEM_REF, pointer_sized_int_node,
4774 : 1119 : tskred_temp, build_int_cst (TREE_TYPE (tskred_temp),
4775 : 1119 : idx * sz));
4776 : 1119 : tree v = create_tmp_var (pointer_sized_int_node);
4777 : 1119 : gimple *g = gimple_build_assign (v, r);
4778 : 1119 : gimple_seq_add_stmt (ilist, g);
4779 : 1119 : if (!useless_type_conversion_p (type, pointer_sized_int_node))
4780 : : {
4781 : 871 : v = create_tmp_var (type);
4782 : 871 : g = gimple_build_assign (v, NOP_EXPR, gimple_assign_lhs (g));
4783 : 871 : gimple_seq_add_stmt (ilist, g);
4784 : : }
4785 : 1119 : return v;
4786 : : }
4787 : :
4788 : : /* Lower early initialization of privatized variable NEW_VAR
4789 : : if it needs an allocator (has allocate clause). */
4790 : :
4791 : : static bool
4792 : 132881 : lower_private_allocate (tree var, tree new_var, tree &allocator,
4793 : : tree &allocate_ptr, gimple_seq *ilist,
4794 : : omp_context *ctx, bool is_ref, tree size)
4795 : : {
4796 : 132881 : if (allocator)
4797 : : return false;
4798 : 132787 : gcc_assert (allocate_ptr == NULL_TREE);
4799 : 132787 : if (ctx->allocate_map
4800 : 2891 : && (DECL_P (new_var) || (TYPE_P (new_var) && size)))
4801 : 2888 : if (tree *allocatorp = ctx->allocate_map->get (var))
4802 : 1022 : allocator = *allocatorp;
4803 : 132787 : if (allocator == NULL_TREE)
4804 : : return false;
4805 : 1022 : if (!is_ref && omp_privatize_by_reference (var))
4806 : : {
4807 : 0 : allocator = NULL_TREE;
4808 : 0 : return false;
4809 : : }
4810 : :
4811 : 1022 : unsigned HOST_WIDE_INT ialign = 0;
4812 : 1022 : if (TREE_CODE (allocator) == TREE_LIST)
4813 : : {
4814 : 136 : ialign = tree_to_uhwi (TREE_VALUE (allocator));
4815 : 136 : allocator = TREE_PURPOSE (allocator);
4816 : : }
4817 : 1022 : if (TREE_CODE (allocator) != INTEGER_CST)
4818 : 428 : allocator = build_outer_var_ref (allocator, ctx, OMP_CLAUSE_ALLOCATE);
4819 : 1022 : allocator = fold_convert (pointer_sized_int_node, allocator);
4820 : 1022 : if (TREE_CODE (allocator) != INTEGER_CST)
4821 : : {
4822 : 428 : tree var = create_tmp_var (TREE_TYPE (allocator));
4823 : 428 : gimplify_assign (var, allocator, ilist);
4824 : 428 : allocator = var;
4825 : : }
4826 : :
4827 : 1022 : tree ptr_type, align, sz = size;
4828 : 1022 : if (TYPE_P (new_var))
4829 : : {
4830 : 225 : ptr_type = build_pointer_type (new_var);
4831 : 225 : ialign = MAX (ialign, TYPE_ALIGN_UNIT (new_var));
4832 : : }
4833 : 797 : else if (is_ref)
4834 : : {
4835 : 86 : ptr_type = build_pointer_type (TREE_TYPE (TREE_TYPE (new_var)));
4836 : 86 : ialign = MAX (ialign, TYPE_ALIGN_UNIT (TREE_TYPE (ptr_type)));
4837 : : }
4838 : : else
4839 : : {
4840 : 711 : ptr_type = build_pointer_type (TREE_TYPE (new_var));
4841 : 711 : ialign = MAX (ialign, DECL_ALIGN_UNIT (new_var));
4842 : 711 : if (sz == NULL_TREE)
4843 : 703 : sz = fold_convert (size_type_node, DECL_SIZE_UNIT (new_var));
4844 : : }
4845 : 1022 : align = build_int_cst (size_type_node, ialign);
4846 : 1022 : if (TREE_CODE (sz) != INTEGER_CST)
4847 : : {
4848 : 27 : tree szvar = create_tmp_var (size_type_node);
4849 : 27 : gimplify_assign (szvar, sz, ilist);
4850 : 27 : sz = szvar;
4851 : : }
4852 : 1022 : allocate_ptr = create_tmp_var (ptr_type);
4853 : 1022 : tree a = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
4854 : 1022 : gimple *g = gimple_build_call (a, 3, align, sz, allocator);
4855 : 1022 : gimple_call_set_lhs (g, allocate_ptr);
4856 : 1022 : gimple_seq_add_stmt (ilist, g);
4857 : 1022 : if (!is_ref)
4858 : : {
4859 : 711 : tree x = build_simple_mem_ref (allocate_ptr);
4860 : 711 : TREE_THIS_NOTRAP (x) = 1;
4861 : 711 : SET_DECL_VALUE_EXPR (new_var, x);
4862 : 711 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
4863 : : }
4864 : : return true;
4865 : : }
4866 : :
4867 : : /* Generate code to implement the input clauses, FIRSTPRIVATE and COPYIN,
4868 : : from the receiver (aka child) side and initializers for REFERENCE_TYPE
4869 : : private variables. Initialization statements go in ILIST, while calls
4870 : : to destructors go in DLIST. */
4871 : :
4872 : : static void
4873 : 77074 : lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
4874 : : omp_context *ctx, struct omp_for_data *fd)
4875 : : {
4876 : 77074 : tree c, copyin_seq, x, ptr;
4877 : 77074 : bool copyin_by_ref = false;
4878 : 77074 : bool lastprivate_firstprivate = false;
4879 : 77074 : bool reduction_omp_orig_ref = false;
4880 : 77074 : int pass;
4881 : 77074 : bool is_simd = (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
4882 : 77074 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD);
4883 : 77074 : omplow_simd_context sctx = omplow_simd_context ();
4884 : 77074 : tree simt_lane = NULL_TREE, simtrec = NULL_TREE;
4885 : 77074 : tree ivar = NULL_TREE, lvar = NULL_TREE, uid = NULL_TREE;
4886 : 77074 : gimple_seq llist[4] = { };
4887 : 77074 : tree nonconst_simd_if = NULL_TREE;
4888 : :
4889 : 77074 : copyin_seq = NULL;
4890 : 77074 : sctx.is_simt = is_simd && omp_find_clause (clauses, OMP_CLAUSE__SIMT_);
4891 : :
4892 : : /* Set max_vf=1 (which will later enforce safelen=1) in simd loops
4893 : : with data sharing clauses referencing variable sized vars. That
4894 : : is unnecessarily hard to support and very unlikely to result in
4895 : : vectorized code anyway. */
4896 : 9353 : if (is_simd)
4897 : 61458 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
4898 : 52105 : switch (OMP_CLAUSE_CODE (c))
4899 : : {
4900 : 7575 : case OMP_CLAUSE_LINEAR:
4901 : 7575 : if (OMP_CLAUSE_LINEAR_ARRAY (c))
4902 : 216 : sctx.max_vf = 1;
4903 : : /* FALLTHRU */
4904 : 25152 : case OMP_CLAUSE_PRIVATE:
4905 : 25152 : case OMP_CLAUSE_FIRSTPRIVATE:
4906 : 25152 : case OMP_CLAUSE_LASTPRIVATE:
4907 : 25152 : if (is_variable_sized (OMP_CLAUSE_DECL (c)))
4908 : 0 : sctx.max_vf = 1;
4909 : 25152 : else if (omp_privatize_by_reference (OMP_CLAUSE_DECL (c)))
4910 : : {
4911 : 279 : tree rtype = TREE_TYPE (TREE_TYPE (OMP_CLAUSE_DECL (c)));
4912 : 279 : if (!TREE_CONSTANT (TYPE_SIZE_UNIT (rtype)))
4913 : 96 : sctx.max_vf = 1;
4914 : : }
4915 : : break;
4916 : 2578 : case OMP_CLAUSE_REDUCTION:
4917 : 2578 : case OMP_CLAUSE_IN_REDUCTION:
4918 : 2578 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF
4919 : 2578 : || is_variable_sized (OMP_CLAUSE_DECL (c)))
4920 : 180 : sctx.max_vf = 1;
4921 : 2398 : else if (omp_privatize_by_reference (OMP_CLAUSE_DECL (c)))
4922 : : {
4923 : 144 : tree rtype = TREE_TYPE (TREE_TYPE (OMP_CLAUSE_DECL (c)));
4924 : 144 : if (!TREE_CONSTANT (TYPE_SIZE_UNIT (rtype)))
4925 : 0 : sctx.max_vf = 1;
4926 : : }
4927 : : break;
4928 : 759 : case OMP_CLAUSE_IF:
4929 : 759 : if (integer_zerop (OMP_CLAUSE_IF_EXPR (c)))
4930 : 124 : sctx.max_vf = 1;
4931 : 635 : else if (TREE_CODE (OMP_CLAUSE_IF_EXPR (c)) != INTEGER_CST)
4932 : 625 : nonconst_simd_if = OMP_CLAUSE_IF_EXPR (c);
4933 : : break;
4934 : 626 : case OMP_CLAUSE_SIMDLEN:
4935 : 626 : if (integer_onep (OMP_CLAUSE_SIMDLEN_EXPR (c)))
4936 : 110 : sctx.max_vf = 1;
4937 : : break;
4938 : 184 : case OMP_CLAUSE__CONDTEMP_:
4939 : : /* FIXME: lastprivate(conditional:) not handled for SIMT yet. */
4940 : 184 : if (sctx.is_simt)
4941 : 0 : sctx.max_vf = 1;
4942 : : break;
4943 : 22806 : default:
4944 : 22806 : continue;
4945 : 22806 : }
4946 : :
4947 : : /* Add a placeholder for simduid. */
4948 : 77074 : if (sctx.is_simt && maybe_ne (sctx.max_vf, 1U))
4949 : 0 : sctx.simt_eargs.safe_push (NULL_TREE);
4950 : :
4951 : : unsigned task_reduction_cnt = 0;
4952 : : unsigned task_reduction_cntorig = 0;
4953 : : unsigned task_reduction_cnt_full = 0;
4954 : : unsigned task_reduction_cntorig_full = 0;
4955 : : unsigned task_reduction_other_cnt = 0;
4956 : 234275 : tree tskred_atype = NULL_TREE, tskred_avar = NULL_TREE;
4957 : : tree tskred_base = NULL_TREE, tskred_temp = NULL_TREE;
4958 : : /* Do all the fixed sized types in the first pass, and the variable sized
4959 : : types in the second pass. This makes sure that the scalar arguments to
4960 : : the variable sized types are processed before we use them in the
4961 : : variable sized operations. For task reductions we use 4 passes, in the
4962 : : first two we ignore them, in the third one gather arguments for
4963 : : GOMP_task_reduction_remap call and in the last pass actually handle
4964 : : the task reductions. */
4965 : 391476 : for (pass = 0; pass < ((task_reduction_cnt || task_reduction_other_cnt)
4966 : 234275 : ? 4 : 2); ++pass)
4967 : : {
4968 : 157205 : if (pass == 2 && task_reduction_cnt)
4969 : : {
4970 : 871 : tskred_atype
4971 : 871 : = build_array_type_nelts (ptr_type_node, task_reduction_cnt
4972 : 871 : + task_reduction_cntorig);
4973 : 871 : tskred_avar = create_tmp_var_raw (tskred_atype);
4974 : 871 : gimple_add_tmp_var (tskred_avar);
4975 : 871 : TREE_ADDRESSABLE (tskred_avar) = 1;
4976 : 871 : task_reduction_cnt_full = task_reduction_cnt;
4977 : 871 : task_reduction_cntorig_full = task_reduction_cntorig;
4978 : : }
4979 : 156334 : else if (pass == 3 && task_reduction_cnt)
4980 : : {
4981 : 871 : x = builtin_decl_explicit (BUILT_IN_GOMP_TASK_REDUCTION_REMAP);
4982 : 871 : gimple *g
4983 : 871 : = gimple_build_call (x, 3, size_int (task_reduction_cnt),
4984 : 871 : size_int (task_reduction_cntorig),
4985 : : build_fold_addr_expr (tskred_avar));
4986 : 871 : gimple_seq_add_stmt (ilist, g);
4987 : : }
4988 : 157205 : if (pass == 3 && task_reduction_other_cnt)
4989 : : {
4990 : : /* For reduction clauses, build
4991 : : tskred_base = (void *) tskred_temp[2]
4992 : : + omp_get_thread_num () * tskred_temp[1]
4993 : : or if tskred_temp[1] is known to be constant, that constant
4994 : : directly. This is the start of the private reduction copy block
4995 : : for the current thread. */
4996 : 837 : tree v = create_tmp_var (integer_type_node);
4997 : 837 : x = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
4998 : 837 : gimple *g = gimple_build_call (x, 0);
4999 : 837 : gimple_call_set_lhs (g, v);
5000 : 837 : gimple_seq_add_stmt (ilist, g);
5001 : 837 : c = omp_find_clause (clauses, OMP_CLAUSE__REDUCTEMP_);
5002 : 837 : tskred_temp = OMP_CLAUSE_DECL (c);
5003 : 837 : if (is_taskreg_ctx (ctx))
5004 : 556 : tskred_temp = lookup_decl (tskred_temp, ctx);
5005 : 837 : tree v2 = create_tmp_var (sizetype);
5006 : 837 : g = gimple_build_assign (v2, NOP_EXPR, v);
5007 : 837 : gimple_seq_add_stmt (ilist, g);
5008 : 837 : if (ctx->task_reductions[0])
5009 : 820 : v = fold_convert (sizetype, ctx->task_reductions[0]);
5010 : : else
5011 : 17 : v = task_reduction_read (ilist, tskred_temp, sizetype, 1);
5012 : 837 : tree v3 = create_tmp_var (sizetype);
5013 : 837 : g = gimple_build_assign (v3, MULT_EXPR, v2, v);
5014 : 837 : gimple_seq_add_stmt (ilist, g);
5015 : 837 : v = task_reduction_read (ilist, tskred_temp, ptr_type_node, 2);
5016 : 837 : tskred_base = create_tmp_var (ptr_type_node);
5017 : 837 : g = gimple_build_assign (tskred_base, POINTER_PLUS_EXPR, v, v3);
5018 : 837 : gimple_seq_add_stmt (ilist, g);
5019 : : }
5020 : 157205 : task_reduction_cnt = 0;
5021 : 157205 : task_reduction_cntorig = 0;
5022 : 157205 : task_reduction_other_cnt = 0;
5023 : 760884 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
5024 : : {
5025 : 603683 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
5026 : 603683 : tree var, new_var;
5027 : 603683 : bool by_ref;
5028 : 603683 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
5029 : 603683 : bool task_reduction_p = false;
5030 : 603683 : bool task_reduction_needs_orig_p = false;
5031 : 603683 : tree cond = NULL_TREE;
5032 : 603683 : tree allocator, allocate_ptr;
5033 : :
5034 : 603683 : switch (c_kind)
5035 : : {
5036 : 135938 : case OMP_CLAUSE_PRIVATE:
5037 : 135938 : if (OMP_CLAUSE_PRIVATE_DEBUG (c))
5038 : 435393 : continue;
5039 : : break;
5040 : 59996 : case OMP_CLAUSE_SHARED:
5041 : : /* Ignore shared directives in teams construct inside
5042 : : of target construct. */
5043 : 59996 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
5044 : 59996 : && !is_host_teams_ctx (ctx))
5045 : 23496 : continue;
5046 : 36500 : if (maybe_lookup_decl (OMP_CLAUSE_DECL (c), ctx) == NULL)
5047 : : {
5048 : 12068 : gcc_assert (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c)
5049 : : || is_global_var (OMP_CLAUSE_DECL (c)));
5050 : 12068 : continue;
5051 : : }
5052 : : case OMP_CLAUSE_FIRSTPRIVATE:
5053 : : case OMP_CLAUSE_COPYIN:
5054 : : break;
5055 : 15604 : case OMP_CLAUSE_LINEAR:
5056 : 15604 : if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c)
5057 : 15604 : && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
5058 : : lastprivate_firstprivate = true;
5059 : : break;
5060 : 37154 : case OMP_CLAUSE_REDUCTION:
5061 : 37154 : case OMP_CLAUSE_IN_REDUCTION:
5062 : 37154 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5063 : 28906 : || is_task_ctx (ctx)
5064 : 63720 : || OMP_CLAUSE_REDUCTION_TASK (c))
5065 : : {
5066 : 12776 : task_reduction_p = true;
5067 : 12776 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
5068 : : {
5069 : 4528 : task_reduction_other_cnt++;
5070 : 4528 : if (pass == 2)
5071 : 1132 : continue;
5072 : : }
5073 : : else
5074 : 8248 : task_reduction_cnt++;
5075 : 11644 : if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
5076 : : {
5077 : 696 : var = OMP_CLAUSE_DECL (c);
5078 : : /* If var is a global variable that isn't privatized
5079 : : in outer contexts, we don't need to look up the
5080 : : original address, it is always the address of the
5081 : : global variable itself. */
5082 : 696 : if (!DECL_P (var)
5083 : 272 : || omp_privatize_by_reference (var)
5084 : 923 : || !is_global_var
5085 : 227 : (maybe_lookup_decl_in_outer_ctx (var, ctx)))
5086 : : {
5087 : 594 : task_reduction_needs_orig_p = true;
5088 : 594 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
5089 : 492 : task_reduction_cntorig++;
5090 : : }
5091 : : }
5092 : : }
5093 : 24378 : else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
5094 : 357272 : reduction_omp_orig_ref = true;
5095 : : break;
5096 : 3348 : case OMP_CLAUSE__REDUCTEMP_:
5097 : 3348 : if (!is_taskreg_ctx (ctx))
5098 : 1124 : continue;
5099 : : /* FALLTHRU */
5100 : 111428 : case OMP_CLAUSE__LOOPTEMP_:
5101 : : /* Handle _looptemp_/_reductemp_ clauses only on
5102 : : parallel/task. */
5103 : 111428 : if (fd)
5104 : 69198 : continue;
5105 : : break;
5106 : 43702 : case OMP_CLAUSE_LASTPRIVATE:
5107 : 43702 : if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
5108 : : {
5109 : 2058 : lastprivate_firstprivate = true;
5110 : 2058 : if (pass != 0 || is_taskloop_ctx (ctx))
5111 : 1343 : continue;
5112 : : }
5113 : : /* Even without corresponding firstprivate, if
5114 : : decl is Fortran allocatable, it needs outer var
5115 : : reference. */
5116 : 41644 : else if (pass == 0
5117 : 62430 : && lang_hooks.decls.omp_private_outer_ref
5118 : 20786 : (OMP_CLAUSE_DECL (c)))
5119 : : lastprivate_firstprivate = true;
5120 : : break;
5121 : 280 : case OMP_CLAUSE_ALIGNED:
5122 : 280 : if (pass != 1)
5123 : 140 : continue;
5124 : 140 : var = OMP_CLAUSE_DECL (c);
5125 : 140 : if (TREE_CODE (TREE_TYPE (var)) == POINTER_TYPE
5126 : 140 : && !is_global_var (var))
5127 : : {
5128 : 76 : new_var = maybe_lookup_decl (var, ctx);
5129 : 76 : if (new_var == NULL_TREE)
5130 : 6 : new_var = maybe_lookup_decl_in_outer_ctx (var, ctx);
5131 : 76 : x = builtin_decl_explicit (BUILT_IN_ASSUME_ALIGNED);
5132 : 76 : tree alarg = omp_clause_aligned_alignment (c);
5133 : 76 : alarg = fold_convert_loc (clause_loc, size_type_node, alarg);
5134 : 76 : x = build_call_expr_loc (clause_loc, x, 2, new_var, alarg);
5135 : 76 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
5136 : 76 : x = build2 (MODIFY_EXPR, TREE_TYPE (new_var), new_var, x);
5137 : 76 : gimplify_and_add (x, ilist);
5138 : : }
5139 : 64 : else if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE
5140 : 64 : && is_global_var (var))
5141 : : {
5142 : 64 : tree ptype = build_pointer_type (TREE_TYPE (var)), t, t2;
5143 : 64 : new_var = lookup_decl (var, ctx);
5144 : 64 : t = maybe_lookup_decl_in_outer_ctx (var, ctx);
5145 : 64 : t = build_fold_addr_expr_loc (clause_loc, t);
5146 : 64 : t2 = builtin_decl_explicit (BUILT_IN_ASSUME_ALIGNED);
5147 : 64 : tree alarg = omp_clause_aligned_alignment (c);
5148 : 64 : alarg = fold_convert_loc (clause_loc, size_type_node, alarg);
5149 : 64 : t = build_call_expr_loc (clause_loc, t2, 2, t, alarg);
5150 : 64 : t = fold_convert_loc (clause_loc, ptype, t);
5151 : 64 : x = create_tmp_var (ptype);
5152 : 64 : t = build2 (MODIFY_EXPR, ptype, x, t);
5153 : 64 : gimplify_and_add (t, ilist);
5154 : 64 : t = build_simple_mem_ref_loc (clause_loc, x);
5155 : 64 : SET_DECL_VALUE_EXPR (new_var, t);
5156 : 64 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
5157 : : }
5158 : 140 : continue;
5159 : 1514 : case OMP_CLAUSE__CONDTEMP_:
5160 : 1514 : if (is_parallel_ctx (ctx)
5161 : 1514 : || (is_simd && !OMP_CLAUSE__CONDTEMP__ITER (c)))
5162 : : break;
5163 : 1094 : continue;
5164 : 135754 : default:
5165 : 135754 : continue;
5166 : 136988 : }
5167 : :
5168 : 357272 : if (task_reduction_p != (pass >= 2))
5169 : 15612 : continue;
5170 : :
5171 : 341660 : allocator = NULL_TREE;
5172 : 341660 : allocate_ptr = NULL_TREE;
5173 : 341660 : new_var = var = OMP_CLAUSE_DECL (c);
5174 : 341660 : if ((c_kind == OMP_CLAUSE_REDUCTION
5175 : 341660 : || c_kind == OMP_CLAUSE_IN_REDUCTION)
5176 : 29580 : && TREE_CODE (var) == MEM_REF)
5177 : : {
5178 : 4356 : var = TREE_OPERAND (var, 0);
5179 : 4356 : if (TREE_CODE (var) == POINTER_PLUS_EXPR)
5180 : 773 : var = TREE_OPERAND (var, 0);
5181 : 4356 : if (TREE_CODE (var) == INDIRECT_REF
5182 : 4168 : || TREE_CODE (var) == ADDR_EXPR)
5183 : 2506 : var = TREE_OPERAND (var, 0);
5184 : 4356 : if (is_variable_sized (var))
5185 : : {
5186 : 179 : gcc_assert (DECL_HAS_VALUE_EXPR_P (var));
5187 : 179 : var = DECL_VALUE_EXPR (var);
5188 : 179 : gcc_assert (TREE_CODE (var) == INDIRECT_REF);
5189 : 179 : var = TREE_OPERAND (var, 0);
5190 : 179 : gcc_assert (DECL_P (var));
5191 : : }
5192 : 4356 : new_var = var;
5193 : : }
5194 : 29580 : if (c_kind == OMP_CLAUSE_IN_REDUCTION && is_omp_target (ctx->stmt))
5195 : : {
5196 : 844 : splay_tree_key key = (splay_tree_key) &DECL_CONTEXT (var);
5197 : 844 : new_var = (tree) splay_tree_lookup (ctx->field_map, key)->value;
5198 : : }
5199 : 340816 : else if (c_kind != OMP_CLAUSE_COPYIN)
5200 : 339796 : new_var = lookup_decl (var, ctx);
5201 : :
5202 : 341660 : if (c_kind == OMP_CLAUSE_SHARED || c_kind == OMP_CLAUSE_COPYIN)
5203 : : {
5204 : 24776 : if (pass != 0)
5205 : 12387 : continue;
5206 : : }
5207 : : /* C/C++ array section reductions. */
5208 : 316884 : else if ((c_kind == OMP_CLAUSE_REDUCTION
5209 : : || c_kind == OMP_CLAUSE_IN_REDUCTION)
5210 : 316884 : && var != OMP_CLAUSE_DECL (c))
5211 : : {
5212 : 4356 : if (pass == 0)
5213 : 873 : continue;
5214 : :
5215 : 3483 : tree bias = TREE_OPERAND (OMP_CLAUSE_DECL (c), 1);
5216 : 3483 : tree orig_var = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
5217 : :
5218 : 3483 : if (TREE_CODE (orig_var) == POINTER_PLUS_EXPR)
5219 : : {
5220 : 723 : tree b = TREE_OPERAND (orig_var, 1);
5221 : 723 : if (is_omp_target (ctx->stmt))
5222 : : b = NULL_TREE;
5223 : : else
5224 : 723 : b = maybe_lookup_decl (b, ctx);
5225 : 723 : if (b == NULL)
5226 : : {
5227 : 17 : b = TREE_OPERAND (orig_var, 1);
5228 : 17 : b = maybe_lookup_decl_in_outer_ctx (b, ctx);
5229 : : }
5230 : 723 : if (integer_zerop (bias))
5231 : : bias = b;
5232 : : else
5233 : : {
5234 : 0 : bias = fold_convert_loc (clause_loc,
5235 : 0 : TREE_TYPE (b), bias);
5236 : 0 : bias = fold_build2_loc (clause_loc, PLUS_EXPR,
5237 : 0 : TREE_TYPE (b), b, bias);
5238 : : }
5239 : 723 : orig_var = TREE_OPERAND (orig_var, 0);
5240 : : }
5241 : 3483 : if (pass == 2)
5242 : : {
5243 : 1149 : tree out = maybe_lookup_decl_in_outer_ctx (var, ctx);
5244 : 1149 : if (is_global_var (out)
5245 : 241 : && TREE_CODE (TREE_TYPE (out)) != POINTER_TYPE
5246 : 1336 : && (TREE_CODE (TREE_TYPE (out)) != REFERENCE_TYPE
5247 : 0 : || (TREE_CODE (TREE_TYPE (TREE_TYPE (out)))
5248 : : != POINTER_TYPE)))
5249 : : x = var;
5250 : 962 : else if (is_omp_target (ctx->stmt))
5251 : : x = out;
5252 : : else
5253 : : {
5254 : 866 : bool by_ref = use_pointer_for_field (var, NULL);
5255 : 866 : x = build_receiver_ref (var, by_ref, ctx);
5256 : 866 : if (TREE_CODE (TREE_TYPE (var)) == REFERENCE_TYPE
5257 : 866 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (var)))
5258 : : == POINTER_TYPE))
5259 : 32 : x = build_fold_addr_expr (x);
5260 : : }
5261 : 1149 : if (TREE_CODE (orig_var) == INDIRECT_REF)
5262 : 40 : x = build_simple_mem_ref (x);
5263 : 1109 : else if (TREE_CODE (orig_var) == ADDR_EXPR)
5264 : : {
5265 : 646 : if (var == TREE_OPERAND (orig_var, 0))
5266 : 583 : x = build_fold_addr_expr (x);
5267 : : }
5268 : 1149 : bias = fold_convert (sizetype, bias);
5269 : 1149 : x = fold_convert (ptr_type_node, x);
5270 : 1149 : x = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR,
5271 : 1149 : TREE_TYPE (x), x, bias);
5272 : 1149 : unsigned cnt = task_reduction_cnt - 1;
5273 : 1149 : if (!task_reduction_needs_orig_p)
5274 : 1061 : cnt += (task_reduction_cntorig_full
5275 : 1061 : - task_reduction_cntorig);
5276 : : else
5277 : 88 : cnt = task_reduction_cntorig - 1;
5278 : 1149 : tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
5279 : 1149 : size_int (cnt), NULL_TREE, NULL_TREE);
5280 : 1149 : gimplify_assign (r, x, ilist);
5281 : 1149 : continue;
5282 : 1149 : }
5283 : :
5284 : 2334 : if (TREE_CODE (orig_var) == INDIRECT_REF
5285 : 2240 : || TREE_CODE (orig_var) == ADDR_EXPR)
5286 : 1362 : orig_var = TREE_OPERAND (orig_var, 0);
5287 : 2334 : tree d = OMP_CLAUSE_DECL (c);
5288 : 2334 : tree type = TREE_TYPE (d);
5289 : 2334 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
5290 : 2334 : tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
5291 : 2334 : tree sz = v;
5292 : 2334 : const char *name = get_name (orig_var);
5293 : 2334 : if (pass != 3 && !TREE_CONSTANT (v))
5294 : : {
5295 : 93 : tree t;
5296 : 93 : if (is_omp_target (ctx->stmt))
5297 : : t = NULL_TREE;
5298 : : else
5299 : 93 : t = maybe_lookup_decl (v, ctx);
5300 : 93 : if (t)
5301 : 88 : v = t;
5302 : : else
5303 : 5 : v = maybe_lookup_decl_in_outer_ctx (v, ctx);
5304 : 93 : gimplify_expr (&v, ilist, NULL, is_gimple_val, fb_rvalue);
5305 : 186 : t = fold_build2_loc (clause_loc, PLUS_EXPR,
5306 : 93 : TREE_TYPE (v), v,
5307 : 93 : build_int_cst (TREE_TYPE (v), 1));
5308 : 93 : sz = fold_build2_loc (clause_loc, MULT_EXPR,
5309 : 93 : TREE_TYPE (v), t,
5310 : 93 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5311 : : }
5312 : 2334 : if (pass == 3)
5313 : : {
5314 : 1461 : tree xv = create_tmp_var (ptr_type_node);
5315 : 1461 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
5316 : : {
5317 : 1149 : unsigned cnt = task_reduction_cnt - 1;
5318 : 1149 : if (!task_reduction_needs_orig_p)
5319 : 1061 : cnt += (task_reduction_cntorig_full
5320 : 1061 : - task_reduction_cntorig);
5321 : : else
5322 : 88 : cnt = task_reduction_cntorig - 1;
5323 : 1149 : x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
5324 : 1149 : size_int (cnt), NULL_TREE, NULL_TREE);
5325 : :
5326 : 1149 : gimple *g = gimple_build_assign (xv, x);
5327 : 1149 : gimple_seq_add_stmt (ilist, g);
5328 : : }
5329 : : else
5330 : : {
5331 : 312 : unsigned int idx = *ctx->task_reduction_map->get (c);
5332 : 312 : tree off;
5333 : 312 : if (ctx->task_reductions[1 + idx])
5334 : 81 : off = fold_convert (sizetype,
5335 : : ctx->task_reductions[1 + idx]);
5336 : : else
5337 : 231 : off = task_reduction_read (ilist, tskred_temp, sizetype,
5338 : 231 : 7 + 3 * idx + 1);
5339 : 312 : gimple *g = gimple_build_assign (xv, POINTER_PLUS_EXPR,
5340 : : tskred_base, off);
5341 : 312 : gimple_seq_add_stmt (ilist, g);
5342 : : }
5343 : 1461 : x = fold_convert (build_pointer_type (boolean_type_node),
5344 : : xv);
5345 : 1461 : if (TREE_CONSTANT (v))
5346 : 1065 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x,
5347 : : TYPE_SIZE_UNIT (type));
5348 : : else
5349 : : {
5350 : 396 : tree t;
5351 : 396 : if (is_omp_target (ctx->stmt))
5352 : : t = NULL_TREE;
5353 : : else
5354 : 336 : t = maybe_lookup_decl (v, ctx);
5355 : 336 : if (t)
5356 : 316 : v = t;
5357 : : else
5358 : 80 : v = maybe_lookup_decl_in_outer_ctx (v, ctx);
5359 : 396 : gimplify_expr (&v, ilist, NULL, is_gimple_val,
5360 : : fb_rvalue);
5361 : 792 : t = fold_build2_loc (clause_loc, PLUS_EXPR,
5362 : 396 : TREE_TYPE (v), v,
5363 : 396 : build_int_cst (TREE_TYPE (v), 1));
5364 : 396 : t = fold_build2_loc (clause_loc, MULT_EXPR,
5365 : 396 : TREE_TYPE (v), t,
5366 : 396 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5367 : 396 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (x), x, t);
5368 : : }
5369 : 1461 : cond = create_tmp_var (TREE_TYPE (x));
5370 : 1461 : gimplify_assign (cond, x, ilist);
5371 : 1461 : x = xv;
5372 : : }
5373 : 873 : else if (lower_private_allocate (var, type, allocator,
5374 : : allocate_ptr, ilist, ctx,
5375 : : true,
5376 : 873 : TREE_CONSTANT (v)
5377 : 780 : ? TYPE_SIZE_UNIT (type)
5378 : : : sz))
5379 : 225 : x = allocate_ptr;
5380 : 648 : else if (TREE_CONSTANT (v))
5381 : : {
5382 : 560 : x = create_tmp_var_raw (type, name);
5383 : 560 : gimple_add_tmp_var (x);
5384 : 560 : TREE_ADDRESSABLE (x) = 1;
5385 : 560 : x = build_fold_addr_expr_loc (clause_loc, x);
5386 : : }
5387 : : else
5388 : : {
5389 : 88 : tree atmp
5390 : 88 : = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
5391 : 88 : tree al = size_int (TYPE_ALIGN (TREE_TYPE (type)));
5392 : 88 : x = build_call_expr_loc (clause_loc, atmp, 2, sz, al);
5393 : : }
5394 : :
5395 : 2334 : tree ptype = build_pointer_type (TREE_TYPE (type));
5396 : 2334 : x = fold_convert_loc (clause_loc, ptype, x);
5397 : 2334 : tree y = create_tmp_var (ptype, name);
5398 : 2334 : gimplify_assign (y, x, ilist);
5399 : 2334 : x = y;
5400 : 2334 : tree yb = y;
5401 : :
5402 : 2334 : if (!integer_zerop (bias))
5403 : : {
5404 : 1512 : bias = fold_convert_loc (clause_loc, pointer_sized_int_node,
5405 : : bias);
5406 : 1512 : yb = fold_convert_loc (clause_loc, pointer_sized_int_node,
5407 : : x);
5408 : 1512 : yb = fold_build2_loc (clause_loc, MINUS_EXPR,
5409 : : pointer_sized_int_node, yb, bias);
5410 : 1512 : x = fold_convert_loc (clause_loc, TREE_TYPE (x), yb);
5411 : 1512 : yb = create_tmp_var (ptype, name);
5412 : 1512 : gimplify_assign (yb, x, ilist);
5413 : 1512 : x = yb;
5414 : : }
5415 : :
5416 : 2334 : d = TREE_OPERAND (d, 0);
5417 : 2334 : if (TREE_CODE (d) == POINTER_PLUS_EXPR)
5418 : 420 : d = TREE_OPERAND (d, 0);
5419 : 2334 : if (TREE_CODE (d) == ADDR_EXPR)
5420 : : {
5421 : 1268 : if (orig_var != var)
5422 : : {
5423 : 91 : gcc_assert (is_variable_sized (orig_var));
5424 : 91 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var),
5425 : : x);
5426 : 91 : gimplify_assign (new_var, x, ilist);
5427 : 91 : tree new_orig_var = lookup_decl (orig_var, ctx);
5428 : 91 : tree t = build_fold_indirect_ref (new_var);
5429 : 91 : DECL_IGNORED_P (new_var) = 0;
5430 : 91 : TREE_THIS_NOTRAP (t) = 1;
5431 : 91 : SET_DECL_VALUE_EXPR (new_orig_var, t);
5432 : 91 : DECL_HAS_VALUE_EXPR_P (new_orig_var) = 1;
5433 : : }
5434 : : else
5435 : : {
5436 : 1177 : x = build2 (MEM_REF, TREE_TYPE (new_var), x,
5437 : : build_int_cst (ptype, 0));
5438 : 1177 : SET_DECL_VALUE_EXPR (new_var, x);
5439 : 1177 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
5440 : : }
5441 : : }
5442 : : else
5443 : : {
5444 : 1066 : gcc_assert (orig_var == var);
5445 : 1066 : if (TREE_CODE (d) == INDIRECT_REF)
5446 : : {
5447 : 94 : x = create_tmp_var (ptype, name);
5448 : 94 : TREE_ADDRESSABLE (x) = 1;
5449 : 94 : gimplify_assign (x, yb, ilist);
5450 : 94 : x = build_fold_addr_expr_loc (clause_loc, x);
5451 : : }
5452 : 1066 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
5453 : 1066 : gimplify_assign (new_var, x, ilist);
5454 : : }
5455 : : /* GOMP_taskgroup_reduction_register memsets the whole
5456 : : array to zero. If the initializer is zero, we don't
5457 : : need to initialize it again, just mark it as ever
5458 : : used unconditionally, i.e. cond = true. */
5459 : 2334 : if (cond
5460 : 1461 : && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
5461 : 3267 : && initializer_zerop (omp_reduction_init (c,
5462 : 933 : TREE_TYPE (type))))
5463 : : {
5464 : 624 : gimple *g = gimple_build_assign (build_simple_mem_ref (cond),
5465 : : boolean_true_node);
5466 : 624 : gimple_seq_add_stmt (ilist, g);
5467 : 624 : continue;
5468 : 624 : }
5469 : 1710 : tree end = create_artificial_label (UNKNOWN_LOCATION);
5470 : 1710 : if (cond)
5471 : : {
5472 : 837 : gimple *g;
5473 : 837 : if (!is_parallel_ctx (ctx))
5474 : : {
5475 : 786 : tree condv = create_tmp_var (boolean_type_node);
5476 : 786 : g = gimple_build_assign (condv,
5477 : : build_simple_mem_ref (cond));
5478 : 786 : gimple_seq_add_stmt (ilist, g);
5479 : 786 : tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
5480 : 786 : g = gimple_build_cond (NE_EXPR, condv,
5481 : : boolean_false_node, end, lab1);
5482 : 786 : gimple_seq_add_stmt (ilist, g);
5483 : 786 : gimple_seq_add_stmt (ilist, gimple_build_label (lab1));
5484 : : }
5485 : 837 : g = gimple_build_assign (build_simple_mem_ref (cond),
5486 : : boolean_true_node);
5487 : 837 : gimple_seq_add_stmt (ilist, g);
5488 : : }
5489 : :
5490 : 1710 : tree y1 = create_tmp_var (ptype);
5491 : 1710 : gimplify_assign (y1, y, ilist);
5492 : 1710 : tree i2 = NULL_TREE, y2 = NULL_TREE;
5493 : 1710 : tree body2 = NULL_TREE, end2 = NULL_TREE;
5494 : 1710 : tree y3 = NULL_TREE, y4 = NULL_TREE;
5495 : 1710 : if (task_reduction_needs_orig_p)
5496 : : {
5497 : 112 : y3 = create_tmp_var (ptype);
5498 : 112 : tree ref;
5499 : 112 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
5500 : 88 : ref = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
5501 : 88 : size_int (task_reduction_cnt_full
5502 : : + task_reduction_cntorig - 1),
5503 : : NULL_TREE, NULL_TREE);
5504 : : else
5505 : : {
5506 : 24 : unsigned int idx = *ctx->task_reduction_map->get (c);
5507 : 24 : ref = task_reduction_read (ilist, tskred_temp, ptype,
5508 : 24 : 7 + 3 * idx);
5509 : : }
5510 : 112 : gimplify_assign (y3, ref, ilist);
5511 : : }
5512 : 1598 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd)
5513 : : {
5514 : 668 : if (pass != 3)
5515 : : {
5516 : 252 : y2 = create_tmp_var (ptype);
5517 : 252 : gimplify_assign (y2, y, ilist);
5518 : : }
5519 : 668 : if (is_simd || OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
5520 : : {
5521 : 188 : tree ref = build_outer_var_ref (var, ctx);
5522 : : /* For ref build_outer_var_ref already performs this. */
5523 : 188 : if (TREE_CODE (d) == INDIRECT_REF)
5524 : 0 : gcc_assert (omp_privatize_by_reference (var));
5525 : 188 : else if (TREE_CODE (d) == ADDR_EXPR)
5526 : 96 : ref = build_fold_addr_expr (ref);
5527 : 92 : else if (omp_privatize_by_reference (var))
5528 : 8 : ref = build_fold_addr_expr (ref);
5529 : 188 : ref = fold_convert_loc (clause_loc, ptype, ref);
5530 : 188 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
5531 : 188 : && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
5532 : : {
5533 : 8 : y3 = create_tmp_var (ptype);
5534 : 8 : gimplify_assign (y3, unshare_expr (ref), ilist);
5535 : : }
5536 : 188 : if (is_simd)
5537 : : {
5538 : 180 : y4 = create_tmp_var (ptype);
5539 : 180 : gimplify_assign (y4, ref, dlist);
5540 : : }
5541 : : }
5542 : : }
5543 : 1710 : tree i = create_tmp_var (TREE_TYPE (v));
5544 : 1710 : gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), ilist);
5545 : 1710 : tree body = create_artificial_label (UNKNOWN_LOCATION);
5546 : 1710 : gimple_seq_add_stmt (ilist, gimple_build_label (body));
5547 : 1710 : if (y2)
5548 : : {
5549 : 252 : i2 = create_tmp_var (TREE_TYPE (v));
5550 : 252 : gimplify_assign (i2, build_int_cst (TREE_TYPE (v), 0), dlist);
5551 : 252 : body2 = create_artificial_label (UNKNOWN_LOCATION);
5552 : 252 : end2 = create_artificial_label (UNKNOWN_LOCATION);
5553 : 252 : gimple_seq_add_stmt (dlist, gimple_build_label (body2));
5554 : : }
5555 : 1710 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
5556 : : {
5557 : 600 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
5558 : 600 : tree decl_placeholder
5559 : 600 : = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c);
5560 : 600 : SET_DECL_VALUE_EXPR (decl_placeholder,
5561 : : build_simple_mem_ref (y1));
5562 : 600 : DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 1;
5563 : 600 : SET_DECL_VALUE_EXPR (placeholder,
5564 : : y3 ? build_simple_mem_ref (y3)
5565 : : : error_mark_node);
5566 : 600 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
5567 : 600 : x = lang_hooks.decls.omp_clause_default_ctor
5568 : 720 : (c, build_simple_mem_ref (y1),
5569 : 120 : y3 ? build_simple_mem_ref (y3) : NULL_TREE);
5570 : 600 : if (x)
5571 : 152 : gimplify_and_add (x, ilist);
5572 : 600 : if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
5573 : : {
5574 : 576 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
5575 : 576 : lower_omp (&tseq, ctx);
5576 : 576 : gimple_seq_add_seq (ilist, tseq);
5577 : : }
5578 : 600 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
5579 : 600 : if (is_simd)
5580 : : {
5581 : 0 : SET_DECL_VALUE_EXPR (decl_placeholder,
5582 : : build_simple_mem_ref (y2));
5583 : 0 : SET_DECL_VALUE_EXPR (placeholder,
5584 : : build_simple_mem_ref (y4));
5585 : 0 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
5586 : 0 : lower_omp (&tseq, ctx);
5587 : 0 : gimple_seq_add_seq (dlist, tseq);
5588 : 0 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
5589 : : }
5590 : 600 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
5591 : 600 : DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 0;
5592 : 600 : if (y2)
5593 : : {
5594 : 72 : x = lang_hooks.decls.omp_clause_dtor
5595 : 72 : (c, build_simple_mem_ref (y2));
5596 : 72 : if (x)
5597 : 40 : gimplify_and_add (x, dlist);
5598 : : }
5599 : : }
5600 : : else
5601 : : {
5602 : 1110 : x = omp_reduction_init (c, TREE_TYPE (type));
5603 : 1110 : enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c);
5604 : :
5605 : : /* reduction(-:var) sums up the partial results, so it
5606 : : acts identically to reduction(+:var). */
5607 : 1110 : if (code == MINUS_EXPR)
5608 : 0 : code = PLUS_EXPR;
5609 : :
5610 : 1110 : gimplify_assign (build_simple_mem_ref (y1), x, ilist);
5611 : 1110 : if (is_simd)
5612 : : {
5613 : 180 : x = build2 (code, TREE_TYPE (type),
5614 : : build_simple_mem_ref (y4),
5615 : : build_simple_mem_ref (y2));
5616 : 180 : gimplify_assign (build_simple_mem_ref (y4), x, dlist);
5617 : : }
5618 : : }
5619 : 1710 : gimple *g
5620 : 1710 : = gimple_build_assign (y1, POINTER_PLUS_EXPR, y1,
5621 : 1710 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5622 : 1710 : gimple_seq_add_stmt (ilist, g);
5623 : 1710 : if (y3)
5624 : : {
5625 : 120 : g = gimple_build_assign (y3, POINTER_PLUS_EXPR, y3,
5626 : 120 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5627 : 120 : gimple_seq_add_stmt (ilist, g);
5628 : : }
5629 : 1710 : g = gimple_build_assign (i, PLUS_EXPR, i,
5630 : 1710 : build_int_cst (TREE_TYPE (i), 1));
5631 : 1710 : gimple_seq_add_stmt (ilist, g);
5632 : 1710 : g = gimple_build_cond (LE_EXPR, i, v, body, end);
5633 : 1710 : gimple_seq_add_stmt (ilist, g);
5634 : 1710 : gimple_seq_add_stmt (ilist, gimple_build_label (end));
5635 : 1710 : if (y2)
5636 : : {
5637 : 252 : g = gimple_build_assign (y2, POINTER_PLUS_EXPR, y2,
5638 : 252 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5639 : 252 : gimple_seq_add_stmt (dlist, g);
5640 : 252 : if (y4)
5641 : : {
5642 : 180 : g = gimple_build_assign
5643 : 180 : (y4, POINTER_PLUS_EXPR, y4,
5644 : 180 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5645 : 180 : gimple_seq_add_stmt (dlist, g);
5646 : : }
5647 : 252 : g = gimple_build_assign (i2, PLUS_EXPR, i2,
5648 : 252 : build_int_cst (TREE_TYPE (i2), 1));
5649 : 252 : gimple_seq_add_stmt (dlist, g);
5650 : 252 : g = gimple_build_cond (LE_EXPR, i2, v, body2, end2);
5651 : 252 : gimple_seq_add_stmt (dlist, g);
5652 : 252 : gimple_seq_add_stmt (dlist, gimple_build_label (end2));
5653 : : }
5654 : 1710 : if (allocator)
5655 : : {
5656 : 225 : tree f = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
5657 : 225 : g = gimple_build_call (f, 2, allocate_ptr, allocator);
5658 : 225 : gimple_seq_add_stmt (dlist, g);
5659 : : }
5660 : 1710 : continue;
5661 : 1710 : }
5662 : 312528 : else if (pass == 2)
5663 : : {
5664 : 913 : tree out = maybe_lookup_decl_in_outer_ctx (var, ctx);
5665 : 913 : if (is_global_var (out))
5666 : : x = var;
5667 : 361 : else if (is_omp_target (ctx->stmt))
5668 : : x = out;
5669 : : else
5670 : : {
5671 : 301 : bool by_ref = use_pointer_for_field (var, ctx);
5672 : 301 : x = build_receiver_ref (var, by_ref, ctx);
5673 : : }
5674 : 913 : if (!omp_privatize_by_reference (var))
5675 : 823 : x = build_fold_addr_expr (x);
5676 : 913 : x = fold_convert (ptr_type_node, x);
5677 : 913 : unsigned cnt = task_reduction_cnt - 1;
5678 : 913 : if (!task_reduction_needs_orig_p)
5679 : 878 : cnt += task_reduction_cntorig_full - task_reduction_cntorig;
5680 : : else
5681 : 35 : cnt = task_reduction_cntorig - 1;
5682 : 913 : tree r = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
5683 : 913 : size_int (cnt), NULL_TREE, NULL_TREE);
5684 : 913 : gimplify_assign (r, x, ilist);
5685 : 913 : continue;
5686 : 913 : }
5687 : 311615 : else if (pass == 3)
5688 : : {
5689 : 1733 : tree type = TREE_TYPE (new_var);
5690 : 1733 : if (!omp_privatize_by_reference (var))
5691 : 1627 : type = build_pointer_type (type);
5692 : 1733 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
5693 : : {
5694 : 913 : unsigned cnt = task_reduction_cnt - 1;
5695 : 913 : if (!task_reduction_needs_orig_p)
5696 : 878 : cnt += (task_reduction_cntorig_full
5697 : 878 : - task_reduction_cntorig);
5698 : : else
5699 : 35 : cnt = task_reduction_cntorig - 1;
5700 : 913 : x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
5701 : 913 : size_int (cnt), NULL_TREE, NULL_TREE);
5702 : : }
5703 : : else
5704 : : {
5705 : 820 : unsigned int idx = *ctx->task_reduction_map->get (c);
5706 : 820 : tree off;
5707 : 820 : if (ctx->task_reductions[1 + idx])
5708 : 820 : off = fold_convert (sizetype,
5709 : : ctx->task_reductions[1 + idx]);
5710 : : else
5711 : 0 : off = task_reduction_read (ilist, tskred_temp, sizetype,
5712 : 0 : 7 + 3 * idx + 1);
5713 : 820 : x = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node,
5714 : : tskred_base, off);
5715 : : }
5716 : 1733 : x = fold_convert (type, x);
5717 : 1733 : tree t;
5718 : 1733 : if (omp_privatize_by_reference (var))
5719 : : {
5720 : 106 : gimplify_assign (new_var, x, ilist);
5721 : 106 : t = new_var;
5722 : 106 : new_var = build_simple_mem_ref (new_var);
5723 : : }
5724 : : else
5725 : : {
5726 : 1627 : t = create_tmp_var (type);
5727 : 1627 : gimplify_assign (t, x, ilist);
5728 : 1627 : SET_DECL_VALUE_EXPR (new_var, build_simple_mem_ref (t));
5729 : 1627 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
5730 : : }
5731 : 1733 : t = fold_convert (build_pointer_type (boolean_type_node), t);
5732 : 1733 : t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
5733 : : TYPE_SIZE_UNIT (TREE_TYPE (type)));
5734 : 1733 : cond = create_tmp_var (TREE_TYPE (t));
5735 : 1733 : gimplify_assign (cond, t, ilist);
5736 : : }
5737 : 309882 : else if (is_variable_sized (var))
5738 : : {
5739 : : /* For variable sized types, we need to allocate the
5740 : : actual storage here. Call alloca and store the
5741 : : result in the pointer decl that we created elsewhere. */
5742 : 262 : if (pass == 0)
5743 : 134 : continue;
5744 : :
5745 : 128 : if (c_kind != OMP_CLAUSE_FIRSTPRIVATE || !is_task_ctx (ctx))
5746 : : {
5747 : 114 : tree tmp;
5748 : :
5749 : 114 : ptr = DECL_VALUE_EXPR (new_var);
5750 : 114 : gcc_assert (TREE_CODE (ptr) == INDIRECT_REF);
5751 : 114 : ptr = TREE_OPERAND (ptr, 0);
5752 : 114 : gcc_assert (DECL_P (ptr));
5753 : 114 : x = TYPE_SIZE_UNIT (TREE_TYPE (new_var));
5754 : :
5755 : 114 : if (lower_private_allocate (var, new_var, allocator,
5756 : : allocate_ptr, ilist, ctx,
5757 : : false, x))
5758 : 8 : tmp = allocate_ptr;
5759 : : else
5760 : : {
5761 : : /* void *tmp = __builtin_alloca */
5762 : 106 : tree atmp
5763 : 106 : = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
5764 : 106 : gcall *stmt
5765 : 106 : = gimple_build_call (atmp, 2, x,
5766 : 106 : size_int (DECL_ALIGN (var)));
5767 : 106 : cfun->calls_alloca = 1;
5768 : 106 : tmp = create_tmp_var_raw (ptr_type_node);
5769 : 106 : gimple_add_tmp_var (tmp);
5770 : 106 : gimple_call_set_lhs (stmt, tmp);
5771 : :
5772 : 106 : gimple_seq_add_stmt (ilist, stmt);
5773 : : }
5774 : :
5775 : 114 : x = fold_convert_loc (clause_loc, TREE_TYPE (ptr), tmp);
5776 : 114 : gimplify_assign (ptr, x, ilist);
5777 : : }
5778 : : }
5779 : 309620 : else if (omp_privatize_by_reference (var)
5780 : 309620 : && (c_kind != OMP_CLAUSE_FIRSTPRIVATE
5781 : 1992 : || !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c)))
5782 : : {
5783 : : /* For references that are being privatized for Fortran,
5784 : : allocate new backing storage for the new pointer
5785 : : variable. This allows us to avoid changing all the
5786 : : code that expects a pointer to something that expects
5787 : : a direct variable. */
5788 : 4869 : if (pass == 0)
5789 : 2537 : continue;
5790 : :
5791 : 2332 : x = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var)));
5792 : 2332 : if (c_kind == OMP_CLAUSE_FIRSTPRIVATE && is_task_ctx (ctx))
5793 : : {
5794 : 146 : x = build_receiver_ref (var, false, ctx);
5795 : 146 : if (ctx->allocate_map)
5796 : 16 : if (tree *allocatep = ctx->allocate_map->get (var))
5797 : : {
5798 : 16 : allocator = *allocatep;
5799 : 16 : if (TREE_CODE (allocator) == TREE_LIST)
5800 : 0 : allocator = TREE_PURPOSE (allocator);
5801 : 16 : if (TREE_CODE (allocator) != INTEGER_CST)
5802 : 8 : allocator = build_outer_var_ref (allocator, ctx);
5803 : 16 : allocator = fold_convert (pointer_sized_int_node,
5804 : : allocator);
5805 : 16 : allocate_ptr = unshare_expr (x);
5806 : : }
5807 : 146 : if (allocator == NULL_TREE)
5808 : 130 : x = build_fold_addr_expr_loc (clause_loc, x);
5809 : : }
5810 : 2186 : else if (lower_private_allocate (var, new_var, allocator,
5811 : : allocate_ptr,
5812 : : ilist, ctx, true, x))
5813 : 86 : x = allocate_ptr;
5814 : 2100 : else if (TREE_CONSTANT (x))
5815 : : {
5816 : : /* For reduction in SIMD loop, defer adding the
5817 : : initialization of the reference, because if we decide
5818 : : to use SIMD array for it, the initilization could cause
5819 : : expansion ICE. Ditto for other privatization clauses. */
5820 : 1404 : if (is_simd)
5821 : : x = NULL_TREE;
5822 : : else
5823 : : {
5824 : 1077 : x = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var)),
5825 : : get_name (var));
5826 : 1077 : gimple_add_tmp_var (x);
5827 : 1077 : TREE_ADDRESSABLE (x) = 1;
5828 : 1077 : x = build_fold_addr_expr_loc (clause_loc, x);
5829 : : }
5830 : : }
5831 : : else
5832 : : {
5833 : 696 : tree atmp
5834 : 696 : = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
5835 : 696 : tree rtype = TREE_TYPE (TREE_TYPE (new_var));
5836 : 696 : tree al = size_int (TYPE_ALIGN (rtype));
5837 : 696 : x = build_call_expr_loc (clause_loc, atmp, 2, x, al);
5838 : : }
5839 : :
5840 : 2005 : if (x)
5841 : : {
5842 : 2005 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
5843 : 2005 : gimplify_assign (new_var, x, ilist);
5844 : : }
5845 : :
5846 : 2332 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
5847 : : }
5848 : 304751 : else if ((c_kind == OMP_CLAUSE_REDUCTION
5849 : : || c_kind == OMP_CLAUSE_IN_REDUCTION)
5850 : 304751 : && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
5851 : : {
5852 : 1952 : if (pass == 0)
5853 : 976 : continue;
5854 : : }
5855 : 302799 : else if (pass != 0)
5856 : 151145 : continue;
5857 : :
5858 : 169212 : switch (OMP_CLAUSE_CODE (c))
5859 : : {
5860 : 11879 : case OMP_CLAUSE_SHARED:
5861 : : /* Ignore shared directives in teams construct inside
5862 : : target construct. */
5863 : 11879 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
5864 : 11879 : && !is_host_teams_ctx (ctx))
5865 : 0 : continue;
5866 : : /* Shared global vars are just accessed directly. */
5867 : 11879 : if (is_global_var (new_var))
5868 : : break;
5869 : : /* For taskloop firstprivate/lastprivate, represented
5870 : : as firstprivate and shared clause on the task, new_var
5871 : : is the firstprivate var. */
5872 : 11735 : if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
5873 : : break;
5874 : : /* Set up the DECL_VALUE_EXPR for shared variables now. This
5875 : : needs to be delayed until after fixup_child_record_type so
5876 : : that we get the correct type during the dereference. */
5877 : 11423 : by_ref = use_pointer_for_field (var, ctx);
5878 : 11423 : x = build_receiver_ref (var, by_ref, ctx);
5879 : 11423 : SET_DECL_VALUE_EXPR (new_var, x);
5880 : 11423 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
5881 : :
5882 : : /* ??? If VAR is not passed by reference, and the variable
5883 : : hasn't been initialized yet, then we'll get a warning for
5884 : : the store into the omp_data_s structure. Ideally, we'd be
5885 : : able to notice this and not store anything at all, but
5886 : : we're generating code too early. Suppress the warning. */
5887 : 11423 : if (!by_ref)
5888 : 5197 : suppress_warning (var, OPT_Wuninitialized);
5889 : : break;
5890 : :
5891 : 210 : case OMP_CLAUSE__CONDTEMP_:
5892 : 210 : if (is_parallel_ctx (ctx))
5893 : : {
5894 : 103 : x = build_receiver_ref (var, false, ctx);
5895 : 103 : SET_DECL_VALUE_EXPR (new_var, x);
5896 : 103 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
5897 : : }
5898 : 107 : else if (is_simd && !OMP_CLAUSE__CONDTEMP__ITER (c))
5899 : : {
5900 : 107 : x = build_zero_cst (TREE_TYPE (var));
5901 : 107 : goto do_private;
5902 : : }
5903 : : break;
5904 : :
5905 : 21290 : case OMP_CLAUSE_LASTPRIVATE:
5906 : 21290 : if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
5907 : : break;
5908 : : /* FALLTHRU */
5909 : :
5910 : 87351 : case OMP_CLAUSE_PRIVATE:
5911 : 87351 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_PRIVATE)
5912 : 20786 : x = build_outer_var_ref (var, ctx);
5913 : 66565 : else if (OMP_CLAUSE_PRIVATE_OUTER_REF (c))
5914 : : {
5915 : 162 : if (is_task_ctx (ctx))
5916 : 12 : x = build_receiver_ref (var, false, ctx);
5917 : : else
5918 : 150 : x = build_outer_var_ref (var, ctx, OMP_CLAUSE_PRIVATE);
5919 : : }
5920 : : else
5921 : : x = NULL;
5922 : 93991 : do_private:
5923 : 93991 : tree nx;
5924 : 93991 : bool copy_ctor;
5925 : 93991 : copy_ctor = false;
5926 : 93991 : lower_private_allocate (var, new_var, allocator, allocate_ptr,
5927 : : ilist, ctx, false, NULL_TREE);
5928 : 93991 : nx = unshare_expr (new_var);
5929 : 93991 : if (is_simd
5930 : 24196 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
5931 : 101377 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c))
5932 : 22 : copy_ctor = true;
5933 : 93991 : if (copy_ctor)
5934 : 22 : nx = lang_hooks.decls.omp_clause_copy_ctor (c, nx, x);
5935 : : else
5936 : 93969 : nx = lang_hooks.decls.omp_clause_default_ctor (c, nx, x);
5937 : 93991 : if (is_simd)
5938 : : {
5939 : 24196 : tree y = lang_hooks.decls.omp_clause_dtor (c, new_var);
5940 : 23513 : if ((TREE_ADDRESSABLE (new_var) || nx || y
5941 : 23497 : || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
5942 : 7010 : && (gimple_omp_for_collapse (ctx->stmt) != 1
5943 : 1375 : || (gimple_omp_for_index (ctx->stmt, 0)
5944 : : != new_var)))
5945 : 16789 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE__CONDTEMP_
5946 : 16682 : || omp_privatize_by_reference (var))
5947 : 31061 : && lower_rec_simd_input_clauses (new_var, ctx, &sctx,
5948 : : ivar, lvar))
5949 : : {
5950 : 5996 : if (omp_privatize_by_reference (var))
5951 : : {
5952 : 52 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
5953 : 52 : tree new_vard = TREE_OPERAND (new_var, 0);
5954 : 52 : gcc_assert (DECL_P (new_vard));
5955 : 52 : SET_DECL_VALUE_EXPR (new_vard,
5956 : : build_fold_addr_expr (lvar));
5957 : 52 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
5958 : : }
5959 : :
5960 : 5996 : if (nx)
5961 : : {
5962 : 30 : tree iv = unshare_expr (ivar);
5963 : 30 : if (copy_ctor)
5964 : 22 : x = lang_hooks.decls.omp_clause_copy_ctor (c, iv,
5965 : : x);
5966 : : else
5967 : 8 : x = lang_hooks.decls.omp_clause_default_ctor (c,
5968 : : iv,
5969 : : x);
5970 : : }
5971 : 5966 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE__CONDTEMP_)
5972 : : {
5973 : 37 : x = build2 (MODIFY_EXPR, TREE_TYPE (ivar),
5974 : : unshare_expr (ivar), x);
5975 : 37 : nx = x;
5976 : : }
5977 : 5996 : if (nx && x)
5978 : 67 : gimplify_and_add (x, &llist[0]);
5979 : 5996 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
5980 : 5996 : && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
5981 : : {
5982 : 37 : tree v = new_var;
5983 : 37 : if (!DECL_P (v))
5984 : : {
5985 : 4 : gcc_assert (TREE_CODE (v) == MEM_REF);
5986 : 4 : v = TREE_OPERAND (v, 0);
5987 : 4 : gcc_assert (DECL_P (v));
5988 : : }
5989 : 37 : v = *ctx->lastprivate_conditional_map->get (v);
5990 : 37 : tree t = create_tmp_var (TREE_TYPE (v));
5991 : 37 : tree z = build_zero_cst (TREE_TYPE (v));
5992 : 37 : tree orig_v
5993 : 37 : = build_outer_var_ref (var, ctx,
5994 : : OMP_CLAUSE_LASTPRIVATE);
5995 : 37 : gimple_seq_add_stmt (dlist,
5996 : 37 : gimple_build_assign (t, z));
5997 : 37 : gcc_assert (DECL_HAS_VALUE_EXPR_P (v));
5998 : 37 : tree civar = DECL_VALUE_EXPR (v);
5999 : 37 : gcc_assert (TREE_CODE (civar) == ARRAY_REF);
6000 : 37 : civar = unshare_expr (civar);
6001 : 37 : TREE_OPERAND (civar, 1) = sctx.idx;
6002 : 37 : x = build2 (MODIFY_EXPR, TREE_TYPE (t), t,
6003 : : unshare_expr (civar));
6004 : 74 : x = build2 (COMPOUND_EXPR, TREE_TYPE (orig_v), x,
6005 : 37 : build2 (MODIFY_EXPR, TREE_TYPE (orig_v),
6006 : : orig_v, unshare_expr (ivar)));
6007 : 37 : tree cond = build2 (LT_EXPR, boolean_type_node, t,
6008 : : civar);
6009 : 37 : x = build3 (COND_EXPR, void_type_node, cond, x,
6010 : : void_node);
6011 : 37 : gimple_seq tseq = NULL;
6012 : 37 : gimplify_and_add (x, &tseq);
6013 : 37 : if (ctx->outer)
6014 : 27 : lower_omp (&tseq, ctx->outer);
6015 : 37 : gimple_seq_add_seq (&llist[1], tseq);
6016 : : }
6017 : 5996 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
6018 : 5996 : && ctx->for_simd_scan_phase)
6019 : : {
6020 : 9 : x = unshare_expr (ivar);
6021 : 9 : tree orig_v
6022 : 9 : = build_outer_var_ref (var, ctx,
6023 : : OMP_CLAUSE_LASTPRIVATE);
6024 : 9 : x = lang_hooks.decls.omp_clause_assign_op (c, x,
6025 : : orig_v);
6026 : 9 : gimplify_and_add (x, &llist[0]);
6027 : : }
6028 : 5996 : if (y)
6029 : : {
6030 : 30 : y = lang_hooks.decls.omp_clause_dtor (c, ivar);
6031 : 30 : if (y)
6032 : 30 : gimplify_and_add (y, &llist[1]);
6033 : : }
6034 : : break;
6035 : : }
6036 : 18200 : if (omp_privatize_by_reference (var))
6037 : : {
6038 : 28 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6039 : 28 : tree new_vard = TREE_OPERAND (new_var, 0);
6040 : 28 : gcc_assert (DECL_P (new_vard));
6041 : 28 : tree type = TREE_TYPE (TREE_TYPE (new_vard));
6042 : 28 : x = TYPE_SIZE_UNIT (type);
6043 : 28 : if (TREE_CONSTANT (x))
6044 : : {
6045 : 28 : x = create_tmp_var_raw (type, get_name (var));
6046 : 28 : gimple_add_tmp_var (x);
6047 : 28 : TREE_ADDRESSABLE (x) = 1;
6048 : 28 : x = build_fold_addr_expr_loc (clause_loc, x);
6049 : 28 : x = fold_convert_loc (clause_loc,
6050 : 28 : TREE_TYPE (new_vard), x);
6051 : 28 : gimplify_assign (new_vard, x, ilist);
6052 : : }
6053 : : }
6054 : : }
6055 : 87995 : if (nx)
6056 : 485 : gimplify_and_add (nx, ilist);
6057 : 87995 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
6058 : 15148 : && is_simd
6059 : 89743 : && ctx->for_simd_scan_phase)
6060 : : {
6061 : 5 : tree orig_v = build_outer_var_ref (var, ctx,
6062 : : OMP_CLAUSE_LASTPRIVATE);
6063 : 5 : x = lang_hooks.decls.omp_clause_assign_op (c, new_var,
6064 : : orig_v);
6065 : 5 : gimplify_and_add (x, ilist);
6066 : : }
6067 : : /* FALLTHRU */
6068 : :
6069 : 118733 : do_dtor:
6070 : 118733 : x = lang_hooks.decls.omp_clause_dtor (c, new_var);
6071 : 118733 : if (x)
6072 : 1125 : gimplify_and_add (x, dlist);
6073 : 118733 : if (allocator)
6074 : : {
6075 : 847 : if (!is_gimple_val (allocator))
6076 : : {
6077 : 22 : tree avar = create_tmp_var (TREE_TYPE (allocator));
6078 : 22 : gimplify_assign (avar, allocator, dlist);
6079 : 22 : allocator = avar;
6080 : : }
6081 : 847 : if (!is_gimple_val (allocate_ptr))
6082 : : {
6083 : 50 : tree apvar = create_tmp_var (TREE_TYPE (allocate_ptr));
6084 : 50 : gimplify_assign (apvar, allocate_ptr, dlist);
6085 : 50 : allocate_ptr = apvar;
6086 : : }
6087 : 847 : tree f = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
6088 : 847 : gimple *g
6089 : 847 : = gimple_build_call (f, 2, allocate_ptr, allocator);
6090 : 847 : gimple_seq_add_stmt (dlist, g);
6091 : : }
6092 : : break;
6093 : :
6094 : 7802 : case OMP_CLAUSE_LINEAR:
6095 : 7802 : if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c))
6096 : 1269 : goto do_firstprivate;
6097 : 6533 : if (OMP_CLAUSE_LINEAR_NO_COPYOUT (c))
6098 : : x = NULL;
6099 : : else
6100 : 3596 : x = build_outer_var_ref (var, ctx);
6101 : 6533 : goto do_private;
6102 : :
6103 : 28589 : case OMP_CLAUSE_FIRSTPRIVATE:
6104 : 28589 : if (is_task_ctx (ctx))
6105 : : {
6106 : 4626 : if ((omp_privatize_by_reference (var)
6107 : 146 : && !OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c))
6108 : 4626 : || is_variable_sized (var))
6109 : 160 : goto do_dtor;
6110 : 4466 : else if (is_global_var (maybe_lookup_decl_in_outer_ctx (var,
6111 : : ctx))
6112 : 4466 : || use_pointer_for_field (var, NULL))
6113 : : {
6114 : 421 : x = build_receiver_ref (var, false, ctx);
6115 : 421 : if (ctx->allocate_map)
6116 : 34 : if (tree *allocatep = ctx->allocate_map->get (var))
6117 : : {
6118 : 34 : allocator = *allocatep;
6119 : 34 : if (TREE_CODE (allocator) == TREE_LIST)
6120 : 4 : allocator = TREE_PURPOSE (allocator);
6121 : 34 : if (TREE_CODE (allocator) != INTEGER_CST)
6122 : 14 : allocator = build_outer_var_ref (allocator, ctx);
6123 : 34 : allocator = fold_convert (pointer_sized_int_node,
6124 : : allocator);
6125 : 34 : allocate_ptr = unshare_expr (x);
6126 : 34 : x = build_simple_mem_ref (x);
6127 : 34 : TREE_THIS_NOTRAP (x) = 1;
6128 : : }
6129 : 421 : SET_DECL_VALUE_EXPR (new_var, x);
6130 : 421 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
6131 : 421 : goto do_dtor;
6132 : : }
6133 : : }
6134 : 28008 : if (OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE (c)
6135 : 28008 : && omp_privatize_by_reference (var))
6136 : : {
6137 : 0 : x = build_outer_var_ref (var, ctx);
6138 : 0 : gcc_assert (TREE_CODE (x) == MEM_REF
6139 : : && integer_zerop (TREE_OPERAND (x, 1)));
6140 : 0 : x = TREE_OPERAND (x, 0);
6141 : 0 : x = lang_hooks.decls.omp_clause_copy_ctor
6142 : 0 : (c, unshare_expr (new_var), x);
6143 : 0 : gimplify_and_add (x, ilist);
6144 : 0 : goto do_dtor;
6145 : : }
6146 : 29277 : do_firstprivate:
6147 : 29277 : lower_private_allocate (var, new_var, allocator, allocate_ptr,
6148 : : ilist, ctx, false, NULL_TREE);
6149 : 29277 : x = build_outer_var_ref (var, ctx);
6150 : 29277 : if (is_simd)
6151 : : {
6152 : 1063 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
6153 : 1063 : && gimple_omp_for_combined_into_p (ctx->stmt))
6154 : : {
6155 : 668 : tree t = OMP_CLAUSE_LINEAR_STEP (c);
6156 : 668 : if (DECL_P (t))
6157 : 114 : t = build_outer_var_ref (t, ctx);
6158 : 668 : tree stept = TREE_TYPE (t);
6159 : 668 : tree ct = omp_find_clause (clauses,
6160 : : OMP_CLAUSE__LOOPTEMP_);
6161 : 668 : gcc_assert (ct);
6162 : 668 : tree l = OMP_CLAUSE_DECL (ct);
6163 : 668 : tree n1 = fd->loop.n1;
6164 : 668 : tree step = fd->loop.step;
6165 : 668 : tree itype = TREE_TYPE (l);
6166 : 668 : if (POINTER_TYPE_P (itype))
6167 : 0 : itype = signed_type_for (itype);
6168 : 668 : l = fold_build2 (MINUS_EXPR, itype, l, n1);
6169 : 668 : if (TYPE_UNSIGNED (itype)
6170 : 668 : && fd->loop.cond_code == GT_EXPR)
6171 : 0 : l = fold_build2 (TRUNC_DIV_EXPR, itype,
6172 : : fold_build1 (NEGATE_EXPR, itype, l),
6173 : : fold_build1 (NEGATE_EXPR,
6174 : : itype, step));
6175 : : else
6176 : 668 : l = fold_build2 (TRUNC_DIV_EXPR, itype, l, step);
6177 : 668 : t = fold_build2 (MULT_EXPR, stept,
6178 : : fold_convert (stept, l), t);
6179 : :
6180 : 668 : if (OMP_CLAUSE_LINEAR_ARRAY (c))
6181 : : {
6182 : 108 : if (omp_privatize_by_reference (var))
6183 : : {
6184 : 72 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6185 : 72 : tree new_vard = TREE_OPERAND (new_var, 0);
6186 : 72 : gcc_assert (DECL_P (new_vard));
6187 : 72 : tree type = TREE_TYPE (TREE_TYPE (new_vard));
6188 : 72 : nx = TYPE_SIZE_UNIT (type);
6189 : 72 : if (TREE_CONSTANT (nx))
6190 : : {
6191 : 24 : nx = create_tmp_var_raw (type,
6192 : : get_name (var));
6193 : 24 : gimple_add_tmp_var (nx);
6194 : 24 : TREE_ADDRESSABLE (nx) = 1;
6195 : 24 : nx = build_fold_addr_expr_loc (clause_loc,
6196 : : nx);
6197 : 24 : nx = fold_convert_loc (clause_loc,
6198 : 24 : TREE_TYPE (new_vard),
6199 : : nx);
6200 : 24 : gimplify_assign (new_vard, nx, ilist);
6201 : : }
6202 : : }
6203 : :
6204 : 108 : x = lang_hooks.decls.omp_clause_linear_ctor
6205 : 108 : (c, new_var, x, t);
6206 : 108 : gimplify_and_add (x, ilist);
6207 : 108 : goto do_dtor;
6208 : : }
6209 : :
6210 : 560 : if (POINTER_TYPE_P (TREE_TYPE (x)))
6211 : 11 : x = fold_build_pointer_plus (x, t);
6212 : : else
6213 : 549 : x = fold_build2 (PLUS_EXPR, TREE_TYPE (x), x,
6214 : : fold_convert (TREE_TYPE (x), t));
6215 : : }
6216 : :
6217 : 955 : if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
6218 : 934 : || TREE_ADDRESSABLE (new_var)
6219 : 799 : || omp_privatize_by_reference (var))
6220 : 1217 : && lower_rec_simd_input_clauses (new_var, ctx, &sctx,
6221 : : ivar, lvar))
6222 : : {
6223 : 152 : if (omp_privatize_by_reference (var))
6224 : : {
6225 : 22 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6226 : 22 : tree new_vard = TREE_OPERAND (new_var, 0);
6227 : 22 : gcc_assert (DECL_P (new_vard));
6228 : 22 : SET_DECL_VALUE_EXPR (new_vard,
6229 : : build_fold_addr_expr (lvar));
6230 : 22 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
6231 : : }
6232 : 152 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR)
6233 : : {
6234 : 131 : tree iv = create_tmp_var (TREE_TYPE (new_var));
6235 : 131 : x = lang_hooks.decls.omp_clause_copy_ctor (c, iv, x);
6236 : 131 : gimplify_and_add (x, ilist);
6237 : 131 : gimple_stmt_iterator gsi
6238 : 131 : = gsi_start (*gimple_omp_body_ptr (ctx->stmt));
6239 : 131 : gassign *g
6240 : 131 : = gimple_build_assign (unshare_expr (lvar), iv);
6241 : 131 : gsi_insert_before_without_update (&gsi, g,
6242 : : GSI_SAME_STMT);
6243 : 131 : tree t = OMP_CLAUSE_LINEAR_STEP (c);
6244 : 131 : enum tree_code code = PLUS_EXPR;
6245 : 131 : if (POINTER_TYPE_P (TREE_TYPE (new_var)))
6246 : : code = POINTER_PLUS_EXPR;
6247 : 131 : g = gimple_build_assign (iv, code, iv, t);
6248 : 131 : gsi_insert_before_without_update (&gsi, g,
6249 : : GSI_SAME_STMT);
6250 : 131 : break;
6251 : : }
6252 : 21 : x = lang_hooks.decls.omp_clause_copy_ctor
6253 : 21 : (c, unshare_expr (ivar), x);
6254 : 21 : gimplify_and_add (x, &llist[0]);
6255 : 21 : x = lang_hooks.decls.omp_clause_dtor (c, ivar);
6256 : 21 : if (x)
6257 : 21 : gimplify_and_add (x, &llist[1]);
6258 : : break;
6259 : : }
6260 : 803 : if (omp_privatize_by_reference (var))
6261 : : {
6262 : 105 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6263 : 105 : tree new_vard = TREE_OPERAND (new_var, 0);
6264 : 105 : gcc_assert (DECL_P (new_vard));
6265 : 105 : tree type = TREE_TYPE (TREE_TYPE (new_vard));
6266 : 105 : nx = TYPE_SIZE_UNIT (type);
6267 : 105 : if (TREE_CONSTANT (nx))
6268 : : {
6269 : 57 : nx = create_tmp_var_raw (type, get_name (var));
6270 : 57 : gimple_add_tmp_var (nx);
6271 : 57 : TREE_ADDRESSABLE (nx) = 1;
6272 : 57 : nx = build_fold_addr_expr_loc (clause_loc, nx);
6273 : 57 : nx = fold_convert_loc (clause_loc,
6274 : 57 : TREE_TYPE (new_vard), nx);
6275 : 57 : gimplify_assign (new_vard, nx, ilist);
6276 : : }
6277 : : }
6278 : : }
6279 : 29017 : x = lang_hooks.decls.omp_clause_copy_ctor
6280 : 29017 : (c, unshare_expr (new_var), x);
6281 : 29013 : gimplify_and_add (x, ilist);
6282 : 29013 : goto do_dtor;
6283 : :
6284 : 19345 : case OMP_CLAUSE__LOOPTEMP_:
6285 : 19345 : case OMP_CLAUSE__REDUCTEMP_:
6286 : 19345 : gcc_assert (is_taskreg_ctx (ctx));
6287 : 19345 : x = build_outer_var_ref (var, ctx);
6288 : 19345 : x = build2 (MODIFY_EXPR, TREE_TYPE (new_var), new_var, x);
6289 : 19345 : gimplify_and_add (x, ilist);
6290 : 19345 : break;
6291 : :
6292 : 510 : case OMP_CLAUSE_COPYIN:
6293 : 510 : by_ref = use_pointer_for_field (var, NULL);
6294 : 510 : x = build_receiver_ref (var, by_ref, ctx);
6295 : 510 : x = lang_hooks.decls.omp_clause_assign_op (c, new_var, x);
6296 : 510 : append_to_statement_list (x, ©in_seq);
6297 : 510 : copyin_by_ref |= by_ref;
6298 : 510 : break;
6299 : :
6300 : 13022 : case OMP_CLAUSE_REDUCTION:
6301 : 13022 : case OMP_CLAUSE_IN_REDUCTION:
6302 : : /* OpenACC reductions are initialized using the
6303 : : GOACC_REDUCTION internal function. */
6304 : 13022 : if (is_gimple_omp_oacc (ctx->stmt))
6305 : : break;
6306 : 9040 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
6307 : : {
6308 : 1443 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
6309 : 1443 : gimple *tseq;
6310 : 1443 : tree ptype = TREE_TYPE (placeholder);
6311 : 1443 : if (cond)
6312 : : {
6313 : 294 : x = error_mark_node;
6314 : 294 : if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)
6315 : 294 : && !task_reduction_needs_orig_p)
6316 : 28 : x = var;
6317 : 266 : else if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c))
6318 : : {
6319 : 45 : tree pptype = build_pointer_type (ptype);
6320 : 45 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
6321 : 35 : x = build4 (ARRAY_REF, ptr_type_node, tskred_avar,
6322 : 35 : size_int (task_reduction_cnt_full
6323 : : + task_reduction_cntorig - 1),
6324 : : NULL_TREE, NULL_TREE);
6325 : : else
6326 : : {
6327 : 10 : unsigned int idx
6328 : 10 : = *ctx->task_reduction_map->get (c);
6329 : 10 : x = task_reduction_read (ilist, tskred_temp,
6330 : 10 : pptype, 7 + 3 * idx);
6331 : : }
6332 : 45 : x = fold_convert (pptype, x);
6333 : 45 : x = build_simple_mem_ref (x);
6334 : : }
6335 : : }
6336 : : else
6337 : : {
6338 : 1149 : lower_private_allocate (var, new_var, allocator,
6339 : : allocate_ptr, ilist, ctx, false,
6340 : : NULL_TREE);
6341 : 1149 : x = build_outer_var_ref (var, ctx);
6342 : :
6343 : 1149 : if (omp_privatize_by_reference (var)
6344 : 1149 : && !useless_type_conversion_p (ptype, TREE_TYPE (x)))
6345 : 49 : x = build_fold_addr_expr_loc (clause_loc, x);
6346 : : }
6347 : 1443 : SET_DECL_VALUE_EXPR (placeholder, x);
6348 : 1443 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
6349 : 1443 : tree new_vard = new_var;
6350 : 1443 : if (omp_privatize_by_reference (var))
6351 : : {
6352 : 203 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6353 : 203 : new_vard = TREE_OPERAND (new_var, 0);
6354 : 203 : gcc_assert (DECL_P (new_vard));
6355 : : }
6356 : 1443 : tree rvar = NULL_TREE, *rvarp = NULL, rvar2 = NULL_TREE;
6357 : 1443 : if (is_simd
6358 : 311 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6359 : 1754 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
6360 : : rvarp = &rvar;
6361 : 1443 : if (is_simd
6362 : 1443 : && lower_rec_simd_input_clauses (new_var, ctx, &sctx,
6363 : : ivar, lvar, rvarp,
6364 : : &rvar2))
6365 : : {
6366 : 174 : if (new_vard == new_var)
6367 : : {
6368 : 128 : gcc_assert (DECL_VALUE_EXPR (new_var) == lvar);
6369 : 128 : SET_DECL_VALUE_EXPR (new_var, ivar);
6370 : : }
6371 : : else
6372 : : {
6373 : 46 : SET_DECL_VALUE_EXPR (new_vard,
6374 : : build_fold_addr_expr (ivar));
6375 : 46 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
6376 : : }
6377 : 174 : x = lang_hooks.decls.omp_clause_default_ctor
6378 : 174 : (c, unshare_expr (ivar),
6379 : : build_outer_var_ref (var, ctx));
6380 : 174 : if (rvarp && ctx->for_simd_scan_phase)
6381 : : {
6382 : 16 : if (x)
6383 : 8 : gimplify_and_add (x, &llist[0]);
6384 : 16 : x = lang_hooks.decls.omp_clause_dtor (c, ivar);
6385 : 16 : if (x)
6386 : 8 : gimplify_and_add (x, &llist[1]);
6387 : 468 : break;
6388 : : }
6389 : 78 : else if (rvarp)
6390 : : {
6391 : 78 : if (x)
6392 : : {
6393 : 38 : gimplify_and_add (x, &llist[0]);
6394 : :
6395 : 38 : tree ivar2 = unshare_expr (lvar);
6396 : 38 : TREE_OPERAND (ivar2, 1) = sctx.idx;
6397 : 38 : x = lang_hooks.decls.omp_clause_default_ctor
6398 : 38 : (c, ivar2, build_outer_var_ref (var, ctx));
6399 : 38 : gimplify_and_add (x, &llist[0]);
6400 : :
6401 : 38 : if (rvar2)
6402 : : {
6403 : 16 : x = lang_hooks.decls.omp_clause_default_ctor
6404 : 16 : (c, unshare_expr (rvar2),
6405 : : build_outer_var_ref (var, ctx));
6406 : 16 : gimplify_and_add (x, &llist[0]);
6407 : : }
6408 : :
6409 : : /* For types that need construction, add another
6410 : : private var which will be default constructed
6411 : : and optionally initialized with
6412 : : OMP_CLAUSE_REDUCTION_GIMPLE_INIT, as in the
6413 : : loop we want to assign this value instead of
6414 : : constructing and destructing it in each
6415 : : iteration. */
6416 : 38 : tree nv = create_tmp_var_raw (TREE_TYPE (ivar));
6417 : 38 : gimple_add_tmp_var (nv);
6418 : 60 : ctx->cb.decl_map->put (TREE_OPERAND (rvar2
6419 : : ? rvar2
6420 : : : ivar, 0),
6421 : : nv);
6422 : 38 : x = lang_hooks.decls.omp_clause_default_ctor
6423 : 38 : (c, nv, build_outer_var_ref (var, ctx));
6424 : 38 : gimplify_and_add (x, ilist);
6425 : :
6426 : 38 : if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
6427 : : {
6428 : 19 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
6429 : 19 : x = DECL_VALUE_EXPR (new_vard);
6430 : 19 : tree vexpr = nv;
6431 : 19 : if (new_vard != new_var)
6432 : 11 : vexpr = build_fold_addr_expr (nv);
6433 : 19 : SET_DECL_VALUE_EXPR (new_vard, vexpr);
6434 : 19 : lower_omp (&tseq, ctx);
6435 : 19 : SET_DECL_VALUE_EXPR (new_vard, x);
6436 : 19 : gimple_seq_add_seq (ilist, tseq);
6437 : 19 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
6438 : : }
6439 : :
6440 : 38 : x = lang_hooks.decls.omp_clause_dtor (c, nv);
6441 : 38 : if (x)
6442 : 38 : gimplify_and_add (x, dlist);
6443 : : }
6444 : :
6445 : 78 : tree ref = build_outer_var_ref (var, ctx);
6446 : 78 : x = unshare_expr (ivar);
6447 : 78 : x = lang_hooks.decls.omp_clause_assign_op (c, x,
6448 : : ref);
6449 : 78 : gimplify_and_add (x, &llist[0]);
6450 : :
6451 : 78 : ref = build_outer_var_ref (var, ctx);
6452 : 78 : x = lang_hooks.decls.omp_clause_assign_op (c, ref,
6453 : : rvar);
6454 : 78 : gimplify_and_add (x, &llist[3]);
6455 : :
6456 : 78 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
6457 : 78 : if (new_vard == new_var)
6458 : 48 : SET_DECL_VALUE_EXPR (new_var, lvar);
6459 : : else
6460 : 30 : SET_DECL_VALUE_EXPR (new_vard,
6461 : : build_fold_addr_expr (lvar));
6462 : :
6463 : 78 : x = lang_hooks.decls.omp_clause_dtor (c, ivar);
6464 : 78 : if (x)
6465 : 38 : gimplify_and_add (x, &llist[1]);
6466 : :
6467 : 78 : tree ivar2 = unshare_expr (lvar);
6468 : 78 : TREE_OPERAND (ivar2, 1) = sctx.idx;
6469 : 78 : x = lang_hooks.decls.omp_clause_dtor (c, ivar2);
6470 : 78 : if (x)
6471 : 38 : gimplify_and_add (x, &llist[1]);
6472 : :
6473 : 78 : if (rvar2)
6474 : : {
6475 : 36 : x = lang_hooks.decls.omp_clause_dtor (c, rvar2);
6476 : 36 : if (x)
6477 : 16 : gimplify_and_add (x, &llist[1]);
6478 : : }
6479 : : break;
6480 : : }
6481 : 80 : if (x)
6482 : 34 : gimplify_and_add (x, &llist[0]);
6483 : 80 : if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
6484 : : {
6485 : 76 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
6486 : 76 : lower_omp (&tseq, ctx);
6487 : 76 : gimple_seq_add_seq (&llist[0], tseq);
6488 : : }
6489 : 80 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
6490 : 80 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
6491 : 80 : lower_omp (&tseq, ctx);
6492 : 80 : gimple_seq_add_seq (&llist[1], tseq);
6493 : 80 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
6494 : 80 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
6495 : 80 : if (new_vard == new_var)
6496 : 70 : SET_DECL_VALUE_EXPR (new_var, lvar);
6497 : : else
6498 : 10 : SET_DECL_VALUE_EXPR (new_vard,
6499 : : build_fold_addr_expr (lvar));
6500 : 80 : x = lang_hooks.decls.omp_clause_dtor (c, ivar);
6501 : 80 : if (x)
6502 : 38 : gimplify_and_add (x, &llist[1]);
6503 : : break;
6504 : : }
6505 : : /* If this is a reference to constant size reduction var
6506 : : with placeholder, we haven't emitted the initializer
6507 : : for it because it is undesirable if SIMD arrays are used.
6508 : : But if they aren't used, we need to emit the deferred
6509 : : initialization now. */
6510 : 1269 : else if (omp_privatize_by_reference (var) && is_simd)
6511 : 46 : handle_simd_reference (clause_loc, new_vard, ilist);
6512 : :
6513 : 1269 : tree lab2 = NULL_TREE;
6514 : 1269 : if (cond)
6515 : : {
6516 : 294 : gimple *g;
6517 : 294 : if (!is_parallel_ctx (ctx))
6518 : : {
6519 : 278 : tree condv = create_tmp_var (boolean_type_node);
6520 : 278 : tree m = build_simple_mem_ref (cond);
6521 : 278 : g = gimple_build_assign (condv, m);
6522 : 278 : gimple_seq_add_stmt (ilist, g);
6523 : 278 : tree lab1
6524 : 278 : = create_artificial_label (UNKNOWN_LOCATION);
6525 : 278 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
6526 : 278 : g = gimple_build_cond (NE_EXPR, condv,
6527 : : boolean_false_node,
6528 : : lab2, lab1);
6529 : 278 : gimple_seq_add_stmt (ilist, g);
6530 : 278 : gimple_seq_add_stmt (ilist,
6531 : 278 : gimple_build_label (lab1));
6532 : : }
6533 : 294 : g = gimple_build_assign (build_simple_mem_ref (cond),
6534 : : boolean_true_node);
6535 : 294 : gimple_seq_add_stmt (ilist, g);
6536 : : }
6537 : 294 : x = lang_hooks.decls.omp_clause_default_ctor
6538 : 1269 : (c, unshare_expr (new_var),
6539 : : cond ? NULL_TREE
6540 : 975 : : build_outer_var_ref (var, ctx));
6541 : 1269 : if (x)
6542 : 285 : gimplify_and_add (x, ilist);
6543 : :
6544 : 1269 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6545 : 1269 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
6546 : : {
6547 : 158 : if (ctx->for_simd_scan_phase)
6548 : 975 : goto do_dtor;
6549 : 142 : if (x || (!is_simd
6550 : 32 : && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)))
6551 : : {
6552 : 70 : tree nv = create_tmp_var_raw (TREE_TYPE (new_var));
6553 : 70 : gimple_add_tmp_var (nv);
6554 : 70 : ctx->cb.decl_map->put (new_vard, nv);
6555 : 70 : x = lang_hooks.decls.omp_clause_default_ctor
6556 : 70 : (c, nv, build_outer_var_ref (var, ctx));
6557 : 70 : if (x)
6558 : 70 : gimplify_and_add (x, ilist);
6559 : 70 : if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
6560 : : {
6561 : 35 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
6562 : 35 : tree vexpr = nv;
6563 : 35 : if (new_vard != new_var)
6564 : 19 : vexpr = build_fold_addr_expr (nv);
6565 : 35 : SET_DECL_VALUE_EXPR (new_vard, vexpr);
6566 : 35 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
6567 : 35 : lower_omp (&tseq, ctx);
6568 : 35 : SET_DECL_VALUE_EXPR (new_vard, NULL_TREE);
6569 : 35 : DECL_HAS_VALUE_EXPR_P (new_vard) = 0;
6570 : 35 : gimple_seq_add_seq (ilist, tseq);
6571 : : }
6572 : 70 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
6573 : 70 : if (is_simd && ctx->scan_exclusive)
6574 : : {
6575 : 16 : tree nv2
6576 : 16 : = create_tmp_var_raw (TREE_TYPE (new_var));
6577 : 16 : gimple_add_tmp_var (nv2);
6578 : 16 : ctx->cb.decl_map->put (nv, nv2);
6579 : 16 : x = lang_hooks.decls.omp_clause_default_ctor
6580 : 16 : (c, nv2, build_outer_var_ref (var, ctx));
6581 : 16 : gimplify_and_add (x, ilist);
6582 : 16 : x = lang_hooks.decls.omp_clause_dtor (c, nv2);
6583 : 16 : if (x)
6584 : 16 : gimplify_and_add (x, dlist);
6585 : : }
6586 : 70 : x = lang_hooks.decls.omp_clause_dtor (c, nv);
6587 : 70 : if (x)
6588 : 70 : gimplify_and_add (x, dlist);
6589 : : }
6590 : 72 : else if (is_simd
6591 : 40 : && ctx->scan_exclusive
6592 : 92 : && TREE_ADDRESSABLE (TREE_TYPE (new_var)))
6593 : : {
6594 : 0 : tree nv2 = create_tmp_var_raw (TREE_TYPE (new_var));
6595 : 0 : gimple_add_tmp_var (nv2);
6596 : 0 : ctx->cb.decl_map->put (new_vard, nv2);
6597 : 0 : x = lang_hooks.decls.omp_clause_dtor (c, nv2);
6598 : 0 : if (x)
6599 : 0 : gimplify_and_add (x, dlist);
6600 : : }
6601 : 142 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
6602 : 142 : goto do_dtor;
6603 : : }
6604 : :
6605 : 1111 : if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
6606 : : {
6607 : 1063 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
6608 : 1063 : if (c_kind == OMP_CLAUSE_IN_REDUCTION
6609 : 1063 : && is_omp_target (ctx->stmt))
6610 : : {
6611 : 12 : tree d = maybe_lookup_decl_in_outer_ctx (var, ctx);
6612 : 12 : tree oldv = NULL_TREE;
6613 : 12 : gcc_assert (d);
6614 : 12 : if (DECL_HAS_VALUE_EXPR_P (d))
6615 : 6 : oldv = DECL_VALUE_EXPR (d);
6616 : 12 : SET_DECL_VALUE_EXPR (d, new_vard);
6617 : 12 : DECL_HAS_VALUE_EXPR_P (d) = 1;
6618 : 12 : lower_omp (&tseq, ctx);
6619 : 12 : if (oldv)
6620 : 6 : SET_DECL_VALUE_EXPR (d, oldv);
6621 : : else
6622 : : {
6623 : 6 : SET_DECL_VALUE_EXPR (d, NULL_TREE);
6624 : 6 : DECL_HAS_VALUE_EXPR_P (d) = 0;
6625 : : }
6626 : : }
6627 : : else
6628 : 1051 : lower_omp (&tseq, ctx);
6629 : 1063 : gimple_seq_add_seq (ilist, tseq);
6630 : : }
6631 : 1111 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
6632 : 1111 : if (is_simd)
6633 : : {
6634 : 43 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
6635 : 43 : lower_omp (&tseq, ctx);
6636 : 43 : gimple_seq_add_seq (dlist, tseq);
6637 : 43 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
6638 : : }
6639 : 1111 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
6640 : 1111 : if (cond)
6641 : : {
6642 : 294 : if (lab2)
6643 : 278 : gimple_seq_add_stmt (ilist, gimple_build_label (lab2));
6644 : : break;
6645 : : }
6646 : 817 : goto do_dtor;
6647 : : }
6648 : : else
6649 : : {
6650 : 7597 : x = omp_reduction_init (c, TREE_TYPE (new_var));
6651 : 7597 : gcc_assert (TREE_CODE (TREE_TYPE (new_var)) != ARRAY_TYPE);
6652 : 7597 : enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c);
6653 : :
6654 : 7597 : if (cond)
6655 : : {
6656 : 1439 : gimple *g;
6657 : 1439 : tree lab2 = NULL_TREE;
6658 : : /* GOMP_taskgroup_reduction_register memsets the whole
6659 : : array to zero. If the initializer is zero, we don't
6660 : : need to initialize it again, just mark it as ever
6661 : : used unconditionally, i.e. cond = true. */
6662 : 1439 : if (initializer_zerop (x))
6663 : : {
6664 : 1258 : g = gimple_build_assign (build_simple_mem_ref (cond),
6665 : : boolean_true_node);
6666 : 1258 : gimple_seq_add_stmt (ilist, g);
6667 : 3223 : break;
6668 : : }
6669 : :
6670 : : /* Otherwise, emit
6671 : : if (!cond) { cond = true; new_var = x; } */
6672 : 181 : if (!is_parallel_ctx (ctx))
6673 : : {
6674 : 177 : tree condv = create_tmp_var (boolean_type_node);
6675 : 177 : tree m = build_simple_mem_ref (cond);
6676 : 177 : g = gimple_build_assign (condv, m);
6677 : 177 : gimple_seq_add_stmt (ilist, g);
6678 : 177 : tree lab1
6679 : 177 : = create_artificial_label (UNKNOWN_LOCATION);
6680 : 177 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
6681 : 177 : g = gimple_build_cond (NE_EXPR, condv,
6682 : : boolean_false_node,
6683 : : lab2, lab1);
6684 : 177 : gimple_seq_add_stmt (ilist, g);
6685 : 177 : gimple_seq_add_stmt (ilist,
6686 : 177 : gimple_build_label (lab1));
6687 : : }
6688 : 181 : g = gimple_build_assign (build_simple_mem_ref (cond),
6689 : : boolean_true_node);
6690 : 181 : gimple_seq_add_stmt (ilist, g);
6691 : 181 : gimplify_assign (new_var, x, ilist);
6692 : 181 : if (lab2)
6693 : 177 : gimple_seq_add_stmt (ilist, gimple_build_label (lab2));
6694 : : break;
6695 : : }
6696 : :
6697 : : /* reduction(-:var) sums up the partial results, so it
6698 : : acts identically to reduction(+:var). */
6699 : 6158 : if (code == MINUS_EXPR)
6700 : 33 : code = PLUS_EXPR;
6701 : :
6702 : 6158 : bool is_truth_op
6703 : 6158 : = (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR);
6704 : 6158 : tree new_vard = new_var;
6705 : 6158 : if (is_simd && omp_privatize_by_reference (var))
6706 : : {
6707 : 52 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
6708 : 52 : new_vard = TREE_OPERAND (new_var, 0);
6709 : 52 : gcc_assert (DECL_P (new_vard));
6710 : : }
6711 : 6158 : tree rvar = NULL_TREE, *rvarp = NULL, rvar2 = NULL_TREE;
6712 : 6158 : if (is_simd
6713 : 2087 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6714 : 8245 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
6715 : : rvarp = &rvar;
6716 : 6158 : if (is_simd
6717 : 6158 : && lower_rec_simd_input_clauses (new_var, ctx, &sctx,
6718 : : ivar, lvar, rvarp,
6719 : : &rvar2))
6720 : : {
6721 : 867 : if (new_vard != new_var)
6722 : : {
6723 : 34 : SET_DECL_VALUE_EXPR (new_vard,
6724 : : build_fold_addr_expr (lvar));
6725 : 34 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
6726 : : }
6727 : :
6728 : 867 : tree ref = build_outer_var_ref (var, ctx);
6729 : :
6730 : 867 : if (rvarp)
6731 : : {
6732 : 193 : if (ctx->for_simd_scan_phase)
6733 : : break;
6734 : 154 : gimplify_assign (ivar, ref, &llist[0]);
6735 : 154 : ref = build_outer_var_ref (var, ctx);
6736 : 154 : gimplify_assign (ref, rvar, &llist[3]);
6737 : 154 : break;
6738 : : }
6739 : :
6740 : 674 : gimplify_assign (unshare_expr (ivar), x, &llist[0]);
6741 : :
6742 : 674 : if (sctx.is_simt)
6743 : : {
6744 : 0 : if (!simt_lane)
6745 : 0 : simt_lane = create_tmp_var (unsigned_type_node);
6746 : 0 : x = build_call_expr_internal_loc
6747 : 0 : (UNKNOWN_LOCATION, IFN_GOMP_SIMT_XCHG_BFLY,
6748 : 0 : TREE_TYPE (ivar), 2, ivar, simt_lane);
6749 : : /* Make sure x is evaluated unconditionally. */
6750 : 0 : tree bfly_var = create_tmp_var (TREE_TYPE (ivar));
6751 : 0 : gimplify_assign (bfly_var, x, &llist[2]);
6752 : 0 : x = build2 (code, TREE_TYPE (ivar), ivar, bfly_var);
6753 : 0 : gimplify_assign (ivar, x, &llist[2]);
6754 : : }
6755 : 674 : tree ivar2 = ivar;
6756 : 674 : tree ref2 = ref;
6757 : 674 : if (is_truth_op)
6758 : : {
6759 : 99 : tree zero = build_zero_cst (TREE_TYPE (ivar));
6760 : 99 : ivar2 = fold_build2_loc (clause_loc, NE_EXPR,
6761 : : boolean_type_node, ivar,
6762 : : zero);
6763 : 99 : ref2 = fold_build2_loc (clause_loc, NE_EXPR,
6764 : : boolean_type_node, ref,
6765 : : zero);
6766 : : }
6767 : 674 : x = build2 (code, TREE_TYPE (ref), ref2, ivar2);
6768 : 674 : if (is_truth_op)
6769 : 99 : x = fold_convert (TREE_TYPE (ref), x);
6770 : 674 : ref = build_outer_var_ref (var, ctx);
6771 : 674 : gimplify_assign (ref, x, &llist[1]);
6772 : :
6773 : : }
6774 : : else
6775 : : {
6776 : 5291 : lower_private_allocate (var, new_var, allocator,
6777 : : allocate_ptr, ilist, ctx,
6778 : : false, NULL_TREE);
6779 : 5291 : if (omp_privatize_by_reference (var) && is_simd)
6780 : 18 : handle_simd_reference (clause_loc, new_vard, ilist);
6781 : 5291 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6782 : 5291 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
6783 : : break;
6784 : 4958 : gimplify_assign (new_var, x, ilist);
6785 : 4958 : if (is_simd)
6786 : : {
6787 : 1028 : tree ref = build_outer_var_ref (var, ctx);
6788 : 1028 : tree new_var2 = new_var;
6789 : 1028 : tree ref2 = ref;
6790 : 1028 : if (is_truth_op)
6791 : : {
6792 : 24 : tree zero = build_zero_cst (TREE_TYPE (new_var));
6793 : 24 : new_var2
6794 : 24 : = fold_build2_loc (clause_loc, NE_EXPR,
6795 : : boolean_type_node, new_var,
6796 : : zero);
6797 : 24 : ref2 = fold_build2_loc (clause_loc, NE_EXPR,
6798 : : boolean_type_node, ref,
6799 : : zero);
6800 : : }
6801 : 1028 : x = build2 (code, TREE_TYPE (ref2), ref2, new_var2);
6802 : 1028 : if (is_truth_op)
6803 : 24 : x = fold_convert (TREE_TYPE (new_var), x);
6804 : 1028 : ref = build_outer_var_ref (var, ctx);
6805 : 1028 : gimplify_assign (ref, x, dlist);
6806 : : }
6807 : 4958 : if (allocator)
6808 : 61 : goto do_dtor;
6809 : : }
6810 : : }
6811 : 5571 : break;
6812 : :
6813 : 0 : default:
6814 : 0 : gcc_unreachable ();
6815 : : }
6816 : : }
6817 : : }
6818 : 77070 : if (tskred_avar)
6819 : : {
6820 : 871 : tree clobber = build_clobber (TREE_TYPE (tskred_avar));
6821 : 871 : gimple_seq_add_stmt (ilist, gimple_build_assign (tskred_avar, clobber));
6822 : : }
6823 : :
6824 : 77070 : if (known_eq (sctx.max_vf, 1U))
6825 : : {
6826 : 1772 : sctx.is_simt = false;
6827 : 1772 : if (ctx->lastprivate_conditional_map)
6828 : : {
6829 : 52 : if (gimple_omp_for_combined_into_p (ctx->stmt))
6830 : : {
6831 : : /* Signal to lower_omp_1 that it should use parent context. */
6832 : 43 : ctx->combined_into_simd_safelen1 = true;
6833 : 370 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
6834 : 327 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
6835 : 327 : && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
6836 : : {
6837 : 57 : tree o = lookup_decl (OMP_CLAUSE_DECL (c), ctx);
6838 : 57 : omp_context *outer = ctx->outer;
6839 : 57 : if (gimple_code (outer->stmt) == GIMPLE_OMP_SCAN)
6840 : 6 : outer = outer->outer;
6841 : 57 : tree *v = ctx->lastprivate_conditional_map->get (o);
6842 : 57 : tree po = lookup_decl (OMP_CLAUSE_DECL (c), outer);
6843 : 57 : tree *pv = outer->lastprivate_conditional_map->get (po);
6844 : 57 : *v = *pv;
6845 : : }
6846 : : }
6847 : : else
6848 : : {
6849 : : /* When not vectorized, treat lastprivate(conditional:) like
6850 : : normal lastprivate, as there will be just one simd lane
6851 : : writing the privatized variable. */
6852 : 9 : delete ctx->lastprivate_conditional_map;
6853 : 9 : ctx->lastprivate_conditional_map = NULL;
6854 : : }
6855 : : }
6856 : : }
6857 : :
6858 : 77070 : if (nonconst_simd_if)
6859 : : {
6860 : 625 : if (sctx.lane == NULL_TREE)
6861 : : {
6862 : 570 : sctx.idx = create_tmp_var (unsigned_type_node);
6863 : 570 : sctx.lane = create_tmp_var (unsigned_type_node);
6864 : : }
6865 : : /* FIXME: For now. */
6866 : 625 : sctx.is_simt = false;
6867 : : }
6868 : :
6869 : 77070 : if (sctx.lane || sctx.is_simt)
6870 : : {
6871 : 4010 : uid = create_tmp_var (ptr_type_node, "simduid");
6872 : : /* Don't want uninit warnings on simduid, it is always uninitialized,
6873 : : but we use it not for the value, but for the DECL_UID only. */
6874 : 4010 : suppress_warning (uid, OPT_Wuninitialized);
6875 : 4010 : c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SIMDUID_);
6876 : 4010 : OMP_CLAUSE__SIMDUID__DECL (c) = uid;
6877 : 4010 : OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (ctx->stmt);
6878 : 4010 : gimple_omp_for_set_clauses (ctx->stmt, c);
6879 : : }
6880 : : /* Emit calls denoting privatized variables and initializing a pointer to
6881 : : structure that holds private variables as fields after ompdevlow pass. */
6882 : 77070 : if (sctx.is_simt)
6883 : : {
6884 : 0 : sctx.simt_eargs[0] = uid;
6885 : 0 : gimple *g
6886 : 0 : = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER, sctx.simt_eargs);
6887 : 0 : gimple_call_set_lhs (g, uid);
6888 : 0 : gimple_seq_add_stmt (ilist, g);
6889 : 0 : sctx.simt_eargs.release ();
6890 : :
6891 : 0 : simtrec = create_tmp_var (ptr_type_node, ".omp_simt");
6892 : 0 : g = gimple_build_call_internal (IFN_GOMP_SIMT_ENTER_ALLOC, 1, uid);
6893 : 0 : gimple_call_set_lhs (g, simtrec);
6894 : 0 : gimple_seq_add_stmt (ilist, g);
6895 : : }
6896 : 77070 : if (sctx.lane)
6897 : : {
6898 : 7395 : gimple *g = gimple_build_call_internal (IFN_GOMP_SIMD_LANE,
6899 : : 2 + (nonconst_simd_if != NULL),
6900 : : uid, integer_zero_node,
6901 : : nonconst_simd_if);
6902 : 4010 : gimple_call_set_lhs (g, sctx.lane);
6903 : 4010 : gimple_stmt_iterator gsi = gsi_start (*gimple_omp_body_ptr (ctx->stmt));
6904 : 4010 : gsi_insert_before_without_update (&gsi, g, GSI_SAME_STMT);
6905 : 4010 : g = gimple_build_assign (sctx.lane, INTEGER_CST,
6906 : : build_int_cst (unsigned_type_node, 0));
6907 : 4010 : gimple_seq_add_stmt (ilist, g);
6908 : 4010 : if (sctx.lastlane)
6909 : : {
6910 : 184 : g = gimple_build_call_internal (IFN_GOMP_SIMD_LAST_LANE,
6911 : : 2, uid, sctx.lane);
6912 : 184 : gimple_call_set_lhs (g, sctx.lastlane);
6913 : 184 : gimple_seq_add_stmt (dlist, g);
6914 : 184 : gimple_seq_add_seq (dlist, llist[3]);
6915 : : }
6916 : : /* Emit reductions across SIMT lanes in log_2(simt_vf) steps. */
6917 : 4010 : if (llist[2])
6918 : : {
6919 : 0 : tree simt_vf = create_tmp_var (unsigned_type_node);
6920 : 0 : g = gimple_build_call_internal (IFN_GOMP_SIMT_VF, 0);
6921 : 0 : gimple_call_set_lhs (g, simt_vf);
6922 : 0 : gimple_seq_add_stmt (dlist, g);
6923 : :
6924 : 0 : tree t = build_int_cst (unsigned_type_node, 1);
6925 : 0 : g = gimple_build_assign (simt_lane, INTEGER_CST, t);
6926 : 0 : gimple_seq_add_stmt (dlist, g);
6927 : :
6928 : 0 : t = build_int_cst (unsigned_type_node, 0);
6929 : 0 : g = gimple_build_assign (sctx.idx, INTEGER_CST, t);
6930 : 0 : gimple_seq_add_stmt (dlist, g);
6931 : :
6932 : 0 : tree body = create_artificial_label (UNKNOWN_LOCATION);
6933 : 0 : tree header = create_artificial_label (UNKNOWN_LOCATION);
6934 : 0 : tree end = create_artificial_label (UNKNOWN_LOCATION);
6935 : 0 : gimple_seq_add_stmt (dlist, gimple_build_goto (header));
6936 : 0 : gimple_seq_add_stmt (dlist, gimple_build_label (body));
6937 : :
6938 : 0 : gimple_seq_add_seq (dlist, llist[2]);
6939 : :
6940 : 0 : g = gimple_build_assign (simt_lane, LSHIFT_EXPR, simt_lane, integer_one_node);
6941 : 0 : gimple_seq_add_stmt (dlist, g);
6942 : :
6943 : 0 : gimple_seq_add_stmt (dlist, gimple_build_label (header));
6944 : 0 : g = gimple_build_cond (LT_EXPR, simt_lane, simt_vf, body, end);
6945 : 0 : gimple_seq_add_stmt (dlist, g);
6946 : :
6947 : 0 : gimple_seq_add_stmt (dlist, gimple_build_label (end));
6948 : : }
6949 : 12030 : for (int i = 0; i < 2; i++)
6950 : 8020 : if (llist[i])
6951 : : {
6952 : 1716 : tree vf = create_tmp_var (unsigned_type_node);
6953 : 1716 : g = gimple_build_call_internal (IFN_GOMP_SIMD_VF, 1, uid);
6954 : 1716 : gimple_call_set_lhs (g, vf);
6955 : 1716 : gimple_seq *seq = i == 0 ? ilist : dlist;
6956 : 1716 : gimple_seq_add_stmt (seq, g);
6957 : 1716 : tree t = build_int_cst (unsigned_type_node, 0);
6958 : 1716 : g = gimple_build_assign (sctx.idx, INTEGER_CST, t);
6959 : 1716 : gimple_seq_add_stmt (seq, g);
6960 : 1716 : tree body = create_artificial_label (UNKNOWN_LOCATION);
6961 : 1716 : tree header = create_artificial_label (UNKNOWN_LOCATION);
6962 : 1716 : tree end = create_artificial_label (UNKNOWN_LOCATION);
6963 : 1716 : gimple_seq_add_stmt (seq, gimple_build_goto (header));
6964 : 1716 : gimple_seq_add_stmt (seq, gimple_build_label (body));
6965 : 1716 : gimple_seq_add_seq (seq, llist[i]);
6966 : 1716 : t = build_int_cst (unsigned_type_node, 1);
6967 : 1716 : g = gimple_build_assign (sctx.idx, PLUS_EXPR, sctx.idx, t);
6968 : 1716 : gimple_seq_add_stmt (seq, g);
6969 : 1716 : gimple_seq_add_stmt (seq, gimple_build_label (header));
6970 : 1716 : g = gimple_build_cond (LT_EXPR, sctx.idx, vf, body, end);
6971 : 1716 : gimple_seq_add_stmt (seq, g);
6972 : 1716 : gimple_seq_add_stmt (seq, gimple_build_label (end));
6973 : : }
6974 : : }
6975 : 77070 : if (sctx.is_simt)
6976 : : {
6977 : 0 : gimple_seq_add_seq (dlist, sctx.simt_dlist);
6978 : 0 : gimple *g
6979 : 0 : = gimple_build_call_internal (IFN_GOMP_SIMT_EXIT, 1, simtrec);
6980 : 0 : gimple_seq_add_stmt (dlist, g);
6981 : : }
6982 : :
6983 : : /* The copyin sequence is not to be executed by the main thread, since
6984 : : that would result in self-copies. Perhaps not visible to scalars,
6985 : : but it certainly is to C++ operator=. */
6986 : 77070 : if (copyin_seq)
6987 : : {
6988 : 436 : x = build_call_expr (builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM),
6989 : : 0);
6990 : 436 : x = build2 (NE_EXPR, boolean_type_node, x,
6991 : 436 : build_int_cst (TREE_TYPE (x), 0));
6992 : 436 : x = build3 (COND_EXPR, void_type_node, x, copyin_seq, NULL);
6993 : 436 : gimplify_and_add (x, ilist);
6994 : : }
6995 : :
6996 : : /* If any copyin variable is passed by reference, we must ensure the
6997 : : master thread doesn't modify it before it is copied over in all
6998 : : threads. Similarly for variables in both firstprivate and
6999 : : lastprivate clauses we need to ensure the lastprivate copying
7000 : : happens after firstprivate copying in all threads. And similarly
7001 : : for UDRs if initializer expression refers to omp_orig. */
7002 : 77070 : if (copyin_by_ref || lastprivate_firstprivate
7003 : 75140 : || (reduction_omp_orig_ref
7004 : 89 : && !ctx->scan_inclusive
7005 : 89 : && !ctx->scan_exclusive))
7006 : : {
7007 : : /* Don't add any barrier for #pragma omp simd or
7008 : : #pragma omp distribute. */
7009 : 2019 : if (!is_task_ctx (ctx)
7010 : 2019 : && (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
7011 : 1485 : || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR))
7012 : 882 : gimple_seq_add_stmt (ilist, omp_build_barrier (NULL_TREE));
7013 : : }
7014 : :
7015 : : /* If max_vf is non-zero, then we can use only a vectorization factor
7016 : : up to the max_vf we chose. So stick it into the safelen clause. */
7017 : 77070 : if (maybe_ne (sctx.max_vf, 0U))
7018 : : {
7019 : 5212 : tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
7020 : : OMP_CLAUSE_SAFELEN);
7021 : 5212 : poly_uint64 safe_len;
7022 : 5212 : if (c == NULL_TREE
7023 : 5212 : || (poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len)
7024 : 613 : && maybe_gt (safe_len, sctx.max_vf)))
7025 : : {
7026 : 5122 : c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
7027 : 5122 : OMP_CLAUSE_SAFELEN_EXPR (c) = build_int_cst (integer_type_node,
7028 : 5122 : sctx.max_vf);
7029 : 5122 : OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (ctx->stmt);
7030 : 5122 : gimple_omp_for_set_clauses (ctx->stmt, c);
7031 : : }
7032 : : }
7033 : 77070 : }
7034 : :
7035 : : /* Create temporary variables for lastprivate(conditional:) implementation
7036 : : in context CTX with CLAUSES. */
7037 : :
7038 : : static void
7039 : 47243 : lower_lastprivate_conditional_clauses (tree *clauses, omp_context *ctx)
7040 : : {
7041 : 47243 : tree iter_type = NULL_TREE;
7042 : 47243 : tree cond_ptr = NULL_TREE;
7043 : 47243 : tree iter_var = NULL_TREE;
7044 : 47243 : bool is_simd = (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
7045 : 47243 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD);
7046 : 47243 : tree next = *clauses;
7047 : 226970 : for (tree c = *clauses; c; c = OMP_CLAUSE_CHAIN (c))
7048 : 179727 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7049 : 179727 : && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c))
7050 : : {
7051 : 386 : if (is_simd)
7052 : : {
7053 : 107 : tree cc = omp_find_clause (next, OMP_CLAUSE__CONDTEMP_);
7054 : 107 : gcc_assert (cc);
7055 : 107 : if (iter_type == NULL_TREE)
7056 : : {
7057 : 77 : iter_type = TREE_TYPE (OMP_CLAUSE_DECL (cc));
7058 : 77 : iter_var = create_tmp_var_raw (iter_type);
7059 : 77 : DECL_CONTEXT (iter_var) = current_function_decl;
7060 : 77 : DECL_SEEN_IN_BIND_EXPR_P (iter_var) = 1;
7061 : 77 : DECL_CHAIN (iter_var) = ctx->block_vars;
7062 : 77 : ctx->block_vars = iter_var;
7063 : 77 : tree c3
7064 : 77 : = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__CONDTEMP_);
7065 : 77 : OMP_CLAUSE__CONDTEMP__ITER (c3) = 1;
7066 : 77 : OMP_CLAUSE_DECL (c3) = iter_var;
7067 : 77 : OMP_CLAUSE_CHAIN (c3) = *clauses;
7068 : 77 : *clauses = c3;
7069 : 77 : ctx->lastprivate_conditional_map = new hash_map<tree, tree>;
7070 : : }
7071 : 107 : next = OMP_CLAUSE_CHAIN (cc);
7072 : 107 : tree o = lookup_decl (OMP_CLAUSE_DECL (c), ctx);
7073 : 107 : tree v = lookup_decl (OMP_CLAUSE_DECL (cc), ctx);
7074 : 107 : ctx->lastprivate_conditional_map->put (o, v);
7075 : 107 : continue;
7076 : 107 : }
7077 : 279 : if (iter_type == NULL)
7078 : : {
7079 : 205 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR)
7080 : : {
7081 : 193 : struct omp_for_data fd;
7082 : 193 : omp_extract_for_data (as_a <gomp_for *> (ctx->stmt), &fd,
7083 : : NULL);
7084 : 193 : iter_type = unsigned_type_for (fd.iter_type);
7085 : : }
7086 : 12 : else if (gimple_code (ctx->stmt) == GIMPLE_OMP_SECTIONS)
7087 : 12 : iter_type = unsigned_type_node;
7088 : 205 : tree c2 = omp_find_clause (*clauses, OMP_CLAUSE__CONDTEMP_);
7089 : 205 : if (c2)
7090 : : {
7091 : 103 : cond_ptr
7092 : 103 : = lookup_decl_in_outer_ctx (OMP_CLAUSE_DECL (c2), ctx);
7093 : 103 : OMP_CLAUSE_DECL (c2) = cond_ptr;
7094 : : }
7095 : : else
7096 : : {
7097 : 102 : cond_ptr = create_tmp_var_raw (build_pointer_type (iter_type));
7098 : 102 : DECL_CONTEXT (cond_ptr) = current_function_decl;
7099 : 102 : DECL_SEEN_IN_BIND_EXPR_P (cond_ptr) = 1;
7100 : 102 : DECL_CHAIN (cond_ptr) = ctx->block_vars;
7101 : 102 : ctx->block_vars = cond_ptr;
7102 : 102 : c2 = build_omp_clause (UNKNOWN_LOCATION,
7103 : : OMP_CLAUSE__CONDTEMP_);
7104 : 102 : OMP_CLAUSE_DECL (c2) = cond_ptr;
7105 : 102 : OMP_CLAUSE_CHAIN (c2) = *clauses;
7106 : 102 : *clauses = c2;
7107 : : }
7108 : 205 : iter_var = create_tmp_var_raw (iter_type);
7109 : 205 : DECL_CONTEXT (iter_var) = current_function_decl;
7110 : 205 : DECL_SEEN_IN_BIND_EXPR_P (iter_var) = 1;
7111 : 205 : DECL_CHAIN (iter_var) = ctx->block_vars;
7112 : 205 : ctx->block_vars = iter_var;
7113 : 205 : tree c3
7114 : 205 : = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__CONDTEMP_);
7115 : 205 : OMP_CLAUSE__CONDTEMP__ITER (c3) = 1;
7116 : 205 : OMP_CLAUSE_DECL (c3) = iter_var;
7117 : 205 : OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2);
7118 : 205 : OMP_CLAUSE_CHAIN (c2) = c3;
7119 : 205 : ctx->lastprivate_conditional_map = new hash_map<tree, tree>;
7120 : : }
7121 : 279 : tree v = create_tmp_var_raw (iter_type);
7122 : 279 : DECL_CONTEXT (v) = current_function_decl;
7123 : 279 : DECL_SEEN_IN_BIND_EXPR_P (v) = 1;
7124 : 279 : DECL_CHAIN (v) = ctx->block_vars;
7125 : 279 : ctx->block_vars = v;
7126 : 279 : tree o = lookup_decl (OMP_CLAUSE_DECL (c), ctx);
7127 : 279 : ctx->lastprivate_conditional_map->put (o, v);
7128 : : }
7129 : 47243 : }
7130 : :
7131 : :
7132 : : /* Generate code to implement the LASTPRIVATE clauses. This is used for
7133 : : both parallel and workshare constructs. PREDICATE may be NULL if it's
7134 : : always true. BODY_P is the sequence to insert early initialization
7135 : : if needed, STMT_LIST is where the non-conditional lastprivate handling
7136 : : goes into and CSTMT_LIST is a sequence that needs to be run in a critical
7137 : : section. */
7138 : :
7139 : : static void
7140 : 47243 : lower_lastprivate_clauses (tree clauses, tree predicate, gimple_seq *body_p,
7141 : : gimple_seq *stmt_list, gimple_seq *cstmt_list,
7142 : : omp_context *ctx)
7143 : : {
7144 : 47243 : tree x, c, label = NULL, orig_clauses = clauses;
7145 : 47243 : bool par_clauses = false;
7146 : 47243 : tree simduid = NULL, lastlane = NULL, simtcond = NULL, simtlast = NULL;
7147 : 47243 : unsigned HOST_WIDE_INT conditional_off = 0;
7148 : 47243 : gimple_seq post_stmt_list = NULL;
7149 : :
7150 : : /* Early exit if there are no lastprivate or linear clauses. */
7151 : 196231 : for (; clauses ; clauses = OMP_CLAUSE_CHAIN (clauses))
7152 : 161468 : if (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_LASTPRIVATE
7153 : 161468 : || (OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_LINEAR
7154 : 6759 : && !OMP_CLAUSE_LINEAR_NO_COPYOUT (clauses)))
7155 : : break;
7156 : 47243 : if (clauses == NULL)
7157 : : {
7158 : : /* If this was a workshare clause, see if it had been combined
7159 : : with its parallel. In that case, look for the clauses on the
7160 : : parallel statement itself. */
7161 : 34763 : if (is_parallel_ctx (ctx))
7162 : 30764 : return;
7163 : :
7164 : 34763 : ctx = ctx->outer;
7165 : 34763 : if (ctx == NULL || !is_parallel_ctx (ctx))
7166 : : return;
7167 : :
7168 : 12244 : clauses = omp_find_clause (gimple_omp_parallel_clauses (ctx->stmt),
7169 : : OMP_CLAUSE_LASTPRIVATE);
7170 : 12244 : if (clauses == NULL)
7171 : : return;
7172 : : par_clauses = true;
7173 : : }
7174 : :
7175 : 16479 : bool maybe_simt = false;
7176 : 16479 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
7177 : 16479 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD)
7178 : : {
7179 : 7422 : maybe_simt = omp_find_clause (orig_clauses, OMP_CLAUSE__SIMT_);
7180 : 7422 : simduid = omp_find_clause (orig_clauses, OMP_CLAUSE__SIMDUID_);
7181 : 7422 : if (simduid)
7182 : 3558 : simduid = OMP_CLAUSE__SIMDUID__DECL (simduid);
7183 : : }
7184 : :
7185 : 16479 : if (predicate)
7186 : : {
7187 : 16360 : gcond *stmt;
7188 : 16360 : tree label_true, arm1, arm2;
7189 : 16360 : enum tree_code pred_code = TREE_CODE (predicate);
7190 : :
7191 : 16360 : label = create_artificial_label (UNKNOWN_LOCATION);
7192 : 16360 : label_true = create_artificial_label (UNKNOWN_LOCATION);
7193 : 16360 : if (TREE_CODE_CLASS (pred_code) == tcc_comparison)
7194 : : {
7195 : 16360 : arm1 = TREE_OPERAND (predicate, 0);
7196 : 16360 : arm2 = TREE_OPERAND (predicate, 1);
7197 : 16360 : gimplify_expr (&arm1, stmt_list, NULL, is_gimple_val, fb_rvalue);
7198 : 16360 : gimplify_expr (&arm2, stmt_list, NULL, is_gimple_val, fb_rvalue);
7199 : : }
7200 : : else
7201 : : {
7202 : 0 : arm1 = predicate;
7203 : 0 : gimplify_expr (&arm1, stmt_list, NULL, is_gimple_val, fb_rvalue);
7204 : 0 : arm2 = boolean_false_node;
7205 : 0 : pred_code = NE_EXPR;
7206 : : }
7207 : 16360 : if (maybe_simt)
7208 : : {
7209 : 0 : c = build2 (pred_code, boolean_type_node, arm1, arm2);
7210 : 0 : c = fold_convert (integer_type_node, c);
7211 : 0 : simtcond = create_tmp_var (integer_type_node);
7212 : 0 : gimplify_assign (simtcond, c, stmt_list);
7213 : 0 : gcall *g = gimple_build_call_internal (IFN_GOMP_SIMT_VOTE_ANY,
7214 : : 1, simtcond);
7215 : 0 : c = create_tmp_var (integer_type_node);
7216 : 0 : gimple_call_set_lhs (g, c);
7217 : 0 : gimple_seq_add_stmt (stmt_list, g);
7218 : 0 : stmt = gimple_build_cond (NE_EXPR, c, integer_zero_node,
7219 : : label_true, label);
7220 : : }
7221 : : else
7222 : 16360 : stmt = gimple_build_cond (pred_code, arm1, arm2, label_true, label);
7223 : 16360 : gimple_seq_add_stmt (stmt_list, stmt);
7224 : 16360 : gimple_seq_add_stmt (stmt_list, gimple_build_label (label_true));
7225 : : }
7226 : :
7227 : 16479 : tree cond_ptr = NULL_TREE;
7228 : 61574 : for (c = clauses; c ;)
7229 : : {
7230 : 56347 : tree var, new_var;
7231 : 56347 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
7232 : 56347 : gimple_seq *this_stmt_list = stmt_list;
7233 : 56347 : tree lab2 = NULL_TREE;
7234 : :
7235 : 56347 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7236 : 21813 : && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
7237 : 386 : && ctx->lastprivate_conditional_map
7238 : 56720 : && !ctx->combined_into_simd_safelen1)
7239 : : {
7240 : 316 : gcc_assert (body_p);
7241 : 316 : if (simduid)
7242 : 37 : goto next;
7243 : 279 : if (cond_ptr == NULL_TREE)
7244 : : {
7245 : 205 : cond_ptr = omp_find_clause (orig_clauses, OMP_CLAUSE__CONDTEMP_);
7246 : 205 : cond_ptr = OMP_CLAUSE_DECL (cond_ptr);
7247 : : }
7248 : 279 : tree type = TREE_TYPE (TREE_TYPE (cond_ptr));
7249 : 279 : tree o = lookup_decl (OMP_CLAUSE_DECL (c), ctx);
7250 : 279 : tree v = *ctx->lastprivate_conditional_map->get (o);
7251 : 279 : gimplify_assign (v, build_zero_cst (type), body_p);
7252 : 279 : this_stmt_list = cstmt_list;
7253 : 279 : tree mem;
7254 : 279 : if (POINTER_TYPE_P (TREE_TYPE (cond_ptr)))
7255 : : {
7256 : 136 : mem = build2 (MEM_REF, type, cond_ptr,
7257 : 136 : build_int_cst (TREE_TYPE (cond_ptr),
7258 : 136 : conditional_off));
7259 : 136 : conditional_off += tree_to_uhwi (TYPE_SIZE_UNIT (type));
7260 : : }
7261 : : else
7262 : 143 : mem = build4 (ARRAY_REF, type, cond_ptr,
7263 : 143 : size_int (conditional_off++), NULL_TREE, NULL_TREE);
7264 : 279 : tree mem2 = copy_node (mem);
7265 : 279 : gimple_seq seq = NULL;
7266 : 279 : mem = force_gimple_operand (mem, &seq, true, NULL_TREE);
7267 : 279 : gimple_seq_add_seq (this_stmt_list, seq);
7268 : 279 : tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
7269 : 279 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
7270 : 279 : gimple *g = gimple_build_cond (GT_EXPR, v, mem, lab1, lab2);
7271 : 279 : gimple_seq_add_stmt (this_stmt_list, g);
7272 : 279 : gimple_seq_add_stmt (this_stmt_list, gimple_build_label (lab1));
7273 : 279 : gimplify_assign (mem2, v, this_stmt_list);
7274 : : }
7275 : 56031 : else if (predicate
7276 : 55793 : && ctx->combined_into_simd_safelen1
7277 : 116 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7278 : 57 : && OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c)
7279 : 56088 : && ctx->lastprivate_conditional_map)
7280 : : this_stmt_list = &post_stmt_list;
7281 : :
7282 : 56310 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7283 : 56310 : || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7284 : 4865 : && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c)))
7285 : : {
7286 : 26641 : var = OMP_CLAUSE_DECL (c);
7287 : 26641 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7288 : 21776 : && OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c)
7289 : 27668 : && is_taskloop_ctx (ctx))
7290 : : {
7291 : 312 : gcc_checking_assert (ctx->outer && is_task_ctx (ctx->outer));
7292 : 312 : new_var = lookup_decl (var, ctx->outer);
7293 : : }
7294 : : else
7295 : : {
7296 : 26329 : new_var = lookup_decl (var, ctx);
7297 : : /* Avoid uninitialized warnings for lastprivate and
7298 : : for linear iterators. */
7299 : 26329 : if (predicate
7300 : 52469 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7301 : 4865 : || OMP_CLAUSE_LINEAR_NO_COPYIN (c)))
7302 : 24871 : suppress_warning (new_var, OPT_Wuninitialized);
7303 : : }
7304 : :
7305 : 26641 : if (!maybe_simt && simduid && DECL_HAS_VALUE_EXPR_P (new_var))
7306 : : {
7307 : 5879 : tree val = DECL_VALUE_EXPR (new_var);
7308 : 5879 : if (TREE_CODE (val) == ARRAY_REF
7309 : 5831 : && VAR_P (TREE_OPERAND (val, 0))
7310 : 11710 : && lookup_attribute ("omp simd array",
7311 : 5831 : DECL_ATTRIBUTES (TREE_OPERAND (val,
7312 : : 0))))
7313 : : {
7314 : 5831 : if (lastlane == NULL)
7315 : : {
7316 : 2766 : lastlane = create_tmp_var (unsigned_type_node);
7317 : 2766 : gcall *g
7318 : 2766 : = gimple_build_call_internal (IFN_GOMP_SIMD_LAST_LANE,
7319 : : 2, simduid,
7320 : 2766 : TREE_OPERAND (val, 1));
7321 : 2766 : gimple_call_set_lhs (g, lastlane);
7322 : 2766 : gimple_seq_add_stmt (this_stmt_list, g);
7323 : : }
7324 : 5831 : new_var = build4 (ARRAY_REF, TREE_TYPE (val),
7325 : 5831 : TREE_OPERAND (val, 0), lastlane,
7326 : : NULL_TREE, NULL_TREE);
7327 : 5831 : TREE_THIS_NOTRAP (new_var) = 1;
7328 : : }
7329 : : }
7330 : 20762 : else if (maybe_simt)
7331 : : {
7332 : 0 : tree val = (DECL_HAS_VALUE_EXPR_P (new_var)
7333 : 0 : ? DECL_VALUE_EXPR (new_var)
7334 : : : new_var);
7335 : 0 : if (simtlast == NULL)
7336 : : {
7337 : 0 : simtlast = create_tmp_var (unsigned_type_node);
7338 : 0 : gcall *g = gimple_build_call_internal
7339 : 0 : (IFN_GOMP_SIMT_LAST_LANE, 1, simtcond);
7340 : 0 : gimple_call_set_lhs (g, simtlast);
7341 : 0 : gimple_seq_add_stmt (this_stmt_list, g);
7342 : : }
7343 : 0 : x = build_call_expr_internal_loc
7344 : 0 : (UNKNOWN_LOCATION, IFN_GOMP_SIMT_XCHG_IDX,
7345 : 0 : TREE_TYPE (val), 2, val, simtlast);
7346 : 0 : new_var = unshare_expr (new_var);
7347 : 0 : gimplify_assign (new_var, x, this_stmt_list);
7348 : 0 : new_var = unshare_expr (new_var);
7349 : : }
7350 : :
7351 : 26641 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7352 : 26641 : && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c))
7353 : : {
7354 : 7159 : lower_omp (&OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c), ctx);
7355 : 7159 : gimple_seq_add_seq (this_stmt_list,
7356 : 7159 : OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c));
7357 : 7159 : OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c) = NULL;
7358 : : }
7359 : 19482 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7360 : 19482 : && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c))
7361 : : {
7362 : 424 : lower_omp (&OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c), ctx);
7363 : 424 : gimple_seq_add_seq (this_stmt_list,
7364 : 424 : OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c));
7365 : 424 : OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c) = NULL;
7366 : : }
7367 : :
7368 : 26641 : x = NULL_TREE;
7369 : 26641 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7370 : 21776 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
7371 : 26701 : && is_taskloop_ctx (ctx))
7372 : : {
7373 : 76 : tree ovar = maybe_lookup_decl_in_outer_ctx (var,
7374 : 38 : ctx->outer->outer);
7375 : 38 : if (is_global_var (ovar))
7376 : 7 : x = ovar;
7377 : : }
7378 : 7 : if (!x)
7379 : 26634 : x = build_outer_var_ref (var, ctx, OMP_CLAUSE_LASTPRIVATE);
7380 : 26641 : if (omp_privatize_by_reference (var))
7381 : 657 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
7382 : 26641 : x = lang_hooks.decls.omp_clause_assign_op (c, x, new_var);
7383 : 26641 : gimplify_and_add (x, this_stmt_list);
7384 : :
7385 : 26641 : if (lab2)
7386 : 279 : gimple_seq_add_stmt (this_stmt_list, gimple_build_label (lab2));
7387 : : }
7388 : :
7389 : 56347 : next:
7390 : 56347 : c = OMP_CLAUSE_CHAIN (c);
7391 : 56347 : if (c == NULL && !par_clauses)
7392 : : {
7393 : : /* If this was a workshare clause, see if it had been combined
7394 : : with its parallel. In that case, continue looking for the
7395 : : clauses also on the parallel statement itself. */
7396 : 12480 : if (is_parallel_ctx (ctx))
7397 : : break;
7398 : :
7399 : 12480 : ctx = ctx->outer;
7400 : 12480 : if (ctx == NULL || !is_parallel_ctx (ctx))
7401 : : break;
7402 : :
7403 : 1228 : c = omp_find_clause (gimple_omp_parallel_clauses (ctx->stmt),
7404 : : OMP_CLAUSE_LASTPRIVATE);
7405 : 1228 : par_clauses = true;
7406 : : }
7407 : : }
7408 : :
7409 : 16479 : if (label)
7410 : 16360 : gimple_seq_add_stmt (stmt_list, gimple_build_label (label));
7411 : 16479 : gimple_seq_add_seq (stmt_list, post_stmt_list);
7412 : : }
7413 : :
7414 : : /* Lower the OpenACC reductions of CLAUSES for compute axis LEVEL
7415 : : (which might be a placeholder). INNER is true if this is an inner
7416 : : axis of a multi-axis loop. FORK and JOIN are (optional) fork and
7417 : : join markers. Generate the before-loop forking sequence in
7418 : : FORK_SEQ and the after-loop joining sequence to JOIN_SEQ. The
7419 : : general form of these sequences is
7420 : :
7421 : : GOACC_REDUCTION_SETUP
7422 : : GOACC_FORK
7423 : : GOACC_REDUCTION_INIT
7424 : : ...
7425 : : GOACC_REDUCTION_FINI
7426 : : GOACC_JOIN
7427 : : GOACC_REDUCTION_TEARDOWN. */
7428 : :
7429 : : static void
7430 : 25942 : lower_oacc_reductions (location_t loc, tree clauses, tree level, bool inner,
7431 : : gcall *fork, gcall *private_marker, gcall *join,
7432 : : gimple_seq *fork_seq, gimple_seq *join_seq,
7433 : : omp_context *ctx)
7434 : : {
7435 : 25942 : gimple_seq before_fork = NULL;
7436 : 25942 : gimple_seq after_fork = NULL;
7437 : 25942 : gimple_seq before_join = NULL;
7438 : 25942 : gimple_seq after_join = NULL;
7439 : 25942 : tree init_code = NULL_TREE, fini_code = NULL_TREE,
7440 : 25942 : setup_code = NULL_TREE, teardown_code = NULL_TREE;
7441 : 25942 : unsigned offset = 0;
7442 : :
7443 : 96490 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7444 : 70548 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
7445 : : {
7446 : : /* No 'reduction' clauses on OpenACC 'kernels'. */
7447 : 7751 : gcc_checking_assert (!is_oacc_kernels (ctx));
7448 : : /* Likewise, on OpenACC 'kernels' decomposed parts. */
7449 : 7751 : gcc_checking_assert (!is_oacc_kernels_decomposed_part (ctx));
7450 : :
7451 : 7751 : tree orig = OMP_CLAUSE_DECL (c);
7452 : 7751 : tree var = maybe_lookup_decl (orig, ctx);
7453 : 7751 : tree ref_to_res = NULL_TREE;
7454 : 7751 : tree incoming, outgoing, v1, v2, v3;
7455 : 7751 : bool is_private = false;
7456 : :
7457 : 7751 : enum tree_code rcode = OMP_CLAUSE_REDUCTION_CODE (c);
7458 : 7751 : if (rcode == MINUS_EXPR)
7459 : : rcode = PLUS_EXPR;
7460 : 6609 : else if (rcode == TRUTH_ANDIF_EXPR)
7461 : : rcode = BIT_AND_EXPR;
7462 : 6431 : else if (rcode == TRUTH_ORIF_EXPR)
7463 : 433 : rcode = BIT_IOR_EXPR;
7464 : 7751 : tree op = build_int_cst (unsigned_type_node, rcode);
7465 : :
7466 : 7751 : if (!var)
7467 : 4 : var = orig;
7468 : :
7469 : 7751 : incoming = outgoing = var;
7470 : :
7471 : 7751 : if (!inner)
7472 : : {
7473 : : /* See if an outer construct also reduces this variable. */
7474 : : omp_context *outer = ctx;
7475 : :
7476 : 7385 : while (omp_context *probe = outer->outer)
7477 : : {
7478 : 4708 : enum gimple_code type = gimple_code (probe->stmt);
7479 : 4708 : tree cls;
7480 : :
7481 : 4708 : switch (type)
7482 : : {
7483 : 2220 : case GIMPLE_OMP_FOR:
7484 : 2220 : cls = gimple_omp_for_clauses (probe->stmt);
7485 : 2220 : break;
7486 : :
7487 : 2488 : case GIMPLE_OMP_TARGET:
7488 : : /* No 'reduction' clauses inside OpenACC 'kernels'
7489 : : regions. */
7490 : 2488 : gcc_checking_assert (!is_oacc_kernels (probe));
7491 : :
7492 : 2488 : if (!is_gimple_omp_offloaded (probe->stmt))
7493 : 26 : goto do_lookup;
7494 : :
7495 : 2462 : cls = gimple_omp_target_clauses (probe->stmt);
7496 : 2462 : break;
7497 : :
7498 : 0 : default:
7499 : 0 : goto do_lookup;
7500 : : }
7501 : :
7502 : 14249 : outer = probe;
7503 : 14249 : for (; cls; cls = OMP_CLAUSE_CHAIN (cls))
7504 : 11632 : if (OMP_CLAUSE_CODE (cls) == OMP_CLAUSE_REDUCTION
7505 : 11632 : && orig == OMP_CLAUSE_DECL (cls))
7506 : : {
7507 : 1772 : incoming = outgoing = lookup_decl (orig, probe);
7508 : 1772 : goto has_outer_reduction;
7509 : : }
7510 : 9860 : else if ((OMP_CLAUSE_CODE (cls) == OMP_CLAUSE_FIRSTPRIVATE
7511 : 8971 : || OMP_CLAUSE_CODE (cls) == OMP_CLAUSE_PRIVATE)
7512 : 11164 : && orig == OMP_CLAUSE_DECL (cls))
7513 : : {
7514 : 293 : is_private = true;
7515 : 293 : goto do_lookup;
7516 : : }
7517 : : }
7518 : :
7519 : 2677 : do_lookup:
7520 : : /* This is the outermost construct with this reduction,
7521 : : see if there's a mapping for it. */
7522 : 2996 : if (gimple_code (outer->stmt) == GIMPLE_OMP_TARGET
7523 : 5856 : && maybe_lookup_field (orig, outer) && !is_private)
7524 : : {
7525 : 2553 : ref_to_res = build_receiver_ref (orig, false, outer);
7526 : 2553 : if (omp_privatize_by_reference (orig))
7527 : 79 : ref_to_res = build_simple_mem_ref (ref_to_res);
7528 : :
7529 : 2553 : tree type = TREE_TYPE (var);
7530 : 2553 : if (POINTER_TYPE_P (type))
7531 : 79 : type = TREE_TYPE (type);
7532 : :
7533 : 2553 : outgoing = var;
7534 : 2553 : incoming = omp_reduction_init_op (loc, rcode, type);
7535 : : }
7536 : : else
7537 : : {
7538 : : /* Try to look at enclosing contexts for reduction var,
7539 : : use original if no mapping found. */
7540 : 443 : tree t = NULL_TREE;
7541 : 443 : omp_context *c = ctx->outer;
7542 : 895 : while (c && !t)
7543 : : {
7544 : 452 : t = maybe_lookup_decl (orig, c);
7545 : 452 : c = c->outer;
7546 : : }
7547 : 443 : incoming = outgoing = (t ? t : orig);
7548 : : }
7549 : :
7550 : 2553 : has_outer_reduction:;
7551 : : }
7552 : :
7553 : 4325 : if (!ref_to_res)
7554 : 5198 : ref_to_res = integer_zero_node;
7555 : :
7556 : 7751 : if (omp_privatize_by_reference (orig))
7557 : : {
7558 : 159 : tree type = TREE_TYPE (var);
7559 : 159 : const char *id = IDENTIFIER_POINTER (DECL_NAME (var));
7560 : :
7561 : 159 : if (!inner)
7562 : : {
7563 : 110 : tree x = create_tmp_var (TREE_TYPE (type), id);
7564 : 110 : gimplify_assign (var, build_fold_addr_expr (x), fork_seq);
7565 : : }
7566 : :
7567 : 159 : v1 = create_tmp_var (type, id);
7568 : 159 : v2 = create_tmp_var (type, id);
7569 : 159 : v3 = create_tmp_var (type, id);
7570 : :
7571 : 159 : gimplify_assign (v1, var, fork_seq);
7572 : 159 : gimplify_assign (v2, var, fork_seq);
7573 : 159 : gimplify_assign (v3, var, fork_seq);
7574 : :
7575 : 159 : var = build_simple_mem_ref (var);
7576 : 159 : v1 = build_simple_mem_ref (v1);
7577 : 159 : v2 = build_simple_mem_ref (v2);
7578 : 159 : v3 = build_simple_mem_ref (v3);
7579 : 159 : outgoing = build_simple_mem_ref (outgoing);
7580 : :
7581 : 159 : if (!TREE_CONSTANT (incoming))
7582 : 80 : incoming = build_simple_mem_ref (incoming);
7583 : : }
7584 : : else
7585 : : /* Note that 'var' might be a mem ref. */
7586 : : v1 = v2 = v3 = var;
7587 : :
7588 : : /* Determine position in reduction buffer, which may be used
7589 : : by target. The parser has ensured that this is not a
7590 : : variable-sized type. */
7591 : 7751 : fixed_size_mode mode
7592 : 7751 : = as_a <fixed_size_mode> (TYPE_MODE (TREE_TYPE (var)));
7593 : 7751 : unsigned align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
7594 : 7751 : offset = (offset + align - 1) & ~(align - 1);
7595 : 7751 : tree off = build_int_cst (sizetype, offset);
7596 : 7751 : offset += GET_MODE_SIZE (mode);
7597 : :
7598 : 7751 : if (!init_code)
7599 : : {
7600 : 6969 : init_code = build_int_cst (integer_type_node,
7601 : : IFN_GOACC_REDUCTION_INIT);
7602 : 6969 : fini_code = build_int_cst (integer_type_node,
7603 : : IFN_GOACC_REDUCTION_FINI);
7604 : 6969 : setup_code = build_int_cst (integer_type_node,
7605 : : IFN_GOACC_REDUCTION_SETUP);
7606 : 6969 : teardown_code = build_int_cst (integer_type_node,
7607 : : IFN_GOACC_REDUCTION_TEARDOWN);
7608 : : }
7609 : :
7610 : 7751 : tree setup_call
7611 : 15502 : = build_call_expr_internal_loc (loc, IFN_GOACC_REDUCTION,
7612 : 7751 : TREE_TYPE (var), 6, setup_code,
7613 : : unshare_expr (ref_to_res),
7614 : : unshare_expr (incoming),
7615 : : level, op, off);
7616 : 7751 : tree init_call
7617 : 15502 : = build_call_expr_internal_loc (loc, IFN_GOACC_REDUCTION,
7618 : 7751 : TREE_TYPE (var), 6, init_code,
7619 : : unshare_expr (ref_to_res),
7620 : : unshare_expr (v1), level, op, off);
7621 : 7751 : tree fini_call
7622 : 15502 : = build_call_expr_internal_loc (loc, IFN_GOACC_REDUCTION,
7623 : 7751 : TREE_TYPE (var), 6, fini_code,
7624 : : unshare_expr (ref_to_res),
7625 : : unshare_expr (v2), level, op, off);
7626 : 7751 : tree teardown_call
7627 : 15502 : = build_call_expr_internal_loc (loc, IFN_GOACC_REDUCTION,
7628 : 7751 : TREE_TYPE (var), 6, teardown_code,
7629 : : ref_to_res, unshare_expr (v3),
7630 : : level, op, off);
7631 : :
7632 : 7751 : gimplify_assign (unshare_expr (v1), setup_call, &before_fork);
7633 : 7751 : gimplify_assign (unshare_expr (v2), init_call, &after_fork);
7634 : 7751 : gimplify_assign (unshare_expr (v3), fini_call, &before_join);
7635 : 7751 : gimplify_assign (unshare_expr (outgoing), teardown_call, &after_join);
7636 : : }
7637 : :
7638 : : /* Now stitch things together. */
7639 : 25942 : gimple_seq_add_seq (fork_seq, before_fork);
7640 : 25942 : if (private_marker)
7641 : 259 : gimple_seq_add_stmt (fork_seq, private_marker);
7642 : 25942 : if (fork)
7643 : 16551 : gimple_seq_add_stmt (fork_seq, fork);
7644 : 25942 : gimple_seq_add_seq (fork_seq, after_fork);
7645 : :
7646 : 25942 : gimple_seq_add_seq (join_seq, before_join);
7647 : 25942 : if (join)
7648 : 16551 : gimple_seq_add_stmt (join_seq, join);
7649 : 25942 : gimple_seq_add_seq (join_seq, after_join);
7650 : 25942 : }
7651 : :
7652 : : /* Generate code to implement the REDUCTION clauses, append it
7653 : : to STMT_SEQP. CLIST if non-NULL is a pointer to a sequence
7654 : : that should be emitted also inside of the critical section,
7655 : : in that case clear *CLIST afterwards, otherwise leave it as is
7656 : : and let the caller emit it itself. */
7657 : :
7658 : : static void
7659 : 71865 : lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp,
7660 : : gimple_seq *clist, omp_context *ctx)
7661 : : {
7662 : 71865 : gimple_seq sub_seq = NULL;
7663 : 71865 : gimple *stmt;
7664 : 71865 : tree x, c;
7665 : 71865 : int count = 0;
7666 : :
7667 : : /* OpenACC loop reductions are handled elsewhere. */
7668 : 71865 : if (is_gimple_omp_oacc (ctx->stmt))
7669 : 70840 : return;
7670 : :
7671 : : /* SIMD reductions are handled in lower_rec_input_clauses. */
7672 : 60542 : if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR
7673 : 60542 : && gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_SIMD)
7674 : : return;
7675 : :
7676 : : /* inscan reductions are handled elsewhere. */
7677 : 51189 : if (ctx->scan_inclusive || ctx->scan_exclusive)
7678 : : return;
7679 : :
7680 : : /* First see if there is exactly one reduction clause. Use OMP_ATOMIC
7681 : : update in that case, otherwise use a lock. */
7682 : 241946 : for (c = clauses; c && count < 2; c = OMP_CLAUSE_CHAIN (c))
7683 : 191778 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7684 : 191778 : && !OMP_CLAUSE_REDUCTION_TASK (c))
7685 : : {
7686 : 4581 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)
7687 : 4581 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7688 : : {
7689 : : /* Never use OMP_ATOMIC for array reductions or UDRs. */
7690 : : count = -1;
7691 : : break;
7692 : : }
7693 : 3733 : count++;
7694 : : }
7695 : :
7696 : 51016 : if (count == 0)
7697 : : return;
7698 : :
7699 : 14912 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7700 : : {
7701 : 13887 : tree var, ref, new_var, orig_var;
7702 : 13887 : enum tree_code code;
7703 : 13887 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
7704 : :
7705 : 22381 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
7706 : 13887 : || OMP_CLAUSE_REDUCTION_TASK (c))
7707 : 8494 : continue;
7708 : :
7709 : 5393 : enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION;
7710 : 5393 : orig_var = var = OMP_CLAUSE_DECL (c);
7711 : 5393 : if (TREE_CODE (var) == MEM_REF)
7712 : : {
7713 : 689 : var = TREE_OPERAND (var, 0);
7714 : 689 : if (TREE_CODE (var) == POINTER_PLUS_EXPR)
7715 : 50 : var = TREE_OPERAND (var, 0);
7716 : 689 : if (TREE_CODE (var) == ADDR_EXPR)
7717 : 304 : var = TREE_OPERAND (var, 0);
7718 : : else
7719 : : {
7720 : : /* If this is a pointer or referenced based array
7721 : : section, the var could be private in the outer
7722 : : context e.g. on orphaned loop construct. Pretend this
7723 : : is private variable's outer reference. */
7724 : 385 : ccode = OMP_CLAUSE_PRIVATE;
7725 : 385 : if (INDIRECT_REF_P (var))
7726 : 54 : var = TREE_OPERAND (var, 0);
7727 : : }
7728 : 689 : orig_var = var;
7729 : 689 : if (is_variable_sized (var))
7730 : : {
7731 : 25 : gcc_assert (DECL_HAS_VALUE_EXPR_P (var));
7732 : 25 : var = DECL_VALUE_EXPR (var);
7733 : 25 : gcc_assert (INDIRECT_REF_P (var));
7734 : 25 : var = TREE_OPERAND (var, 0);
7735 : 25 : gcc_assert (DECL_P (var));
7736 : : }
7737 : : }
7738 : 5393 : new_var = lookup_decl (var, ctx);
7739 : 5393 : if (var == OMP_CLAUSE_DECL (c)
7740 : 5393 : && omp_privatize_by_reference (var))
7741 : 152 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
7742 : 5393 : ref = build_outer_var_ref (var, ctx, ccode);
7743 : 5393 : code = OMP_CLAUSE_REDUCTION_CODE (c);
7744 : :
7745 : : /* reduction(-:var) sums up the partial results, so it acts
7746 : : identically to reduction(+:var). */
7747 : 5393 : if (code == MINUS_EXPR)
7748 : 57 : code = PLUS_EXPR;
7749 : :
7750 : 5393 : bool is_truth_op = (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR);
7751 : 5393 : if (count == 1)
7752 : : {
7753 : 3324 : tree addr = build_fold_addr_expr_loc (clause_loc, ref);
7754 : :
7755 : 3324 : addr = save_expr (addr);
7756 : 3324 : ref = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (addr)), addr);
7757 : 3324 : tree new_var2 = new_var;
7758 : 3324 : tree ref2 = ref;
7759 : 3324 : if (is_truth_op)
7760 : : {
7761 : 784 : tree zero = build_zero_cst (TREE_TYPE (new_var));
7762 : 784 : new_var2 = fold_build2_loc (clause_loc, NE_EXPR,
7763 : : boolean_type_node, new_var, zero);
7764 : 784 : ref2 = fold_build2_loc (clause_loc, NE_EXPR, boolean_type_node,
7765 : : ref, zero);
7766 : : }
7767 : 3324 : x = fold_build2_loc (clause_loc, code, TREE_TYPE (new_var2), ref2,
7768 : : new_var2);
7769 : 3324 : if (is_truth_op)
7770 : 784 : x = fold_convert (TREE_TYPE (new_var), x);
7771 : 3324 : x = build2 (OMP_ATOMIC, void_type_node, addr, x);
7772 : 3324 : OMP_ATOMIC_MEMORY_ORDER (x) = OMP_MEMORY_ORDER_RELAXED;
7773 : 3324 : gimplify_and_add (x, stmt_seqp);
7774 : 3324 : return;
7775 : : }
7776 : 2069 : else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7777 : : {
7778 : 689 : tree d = OMP_CLAUSE_DECL (c);
7779 : 689 : tree type = TREE_TYPE (d);
7780 : 689 : tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
7781 : 689 : tree i = create_tmp_var (TREE_TYPE (v));
7782 : 689 : tree ptype = build_pointer_type (TREE_TYPE (type));
7783 : 689 : tree bias = TREE_OPERAND (d, 1);
7784 : 689 : d = TREE_OPERAND (d, 0);
7785 : 689 : if (TREE_CODE (d) == POINTER_PLUS_EXPR)
7786 : : {
7787 : 50 : tree b = TREE_OPERAND (d, 1);
7788 : 50 : b = maybe_lookup_decl (b, ctx);
7789 : 50 : if (b == NULL)
7790 : : {
7791 : 2 : b = TREE_OPERAND (d, 1);
7792 : 2 : b = maybe_lookup_decl_in_outer_ctx (b, ctx);
7793 : : }
7794 : 50 : if (integer_zerop (bias))
7795 : : bias = b;
7796 : : else
7797 : : {
7798 : 0 : bias = fold_convert_loc (clause_loc, TREE_TYPE (b), bias);
7799 : 0 : bias = fold_build2_loc (clause_loc, PLUS_EXPR,
7800 : 0 : TREE_TYPE (b), b, bias);
7801 : : }
7802 : 50 : d = TREE_OPERAND (d, 0);
7803 : : }
7804 : : /* For ref build_outer_var_ref already performs this, so
7805 : : only new_var needs a dereference. */
7806 : 689 : if (INDIRECT_REF_P (d))
7807 : : {
7808 : 54 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
7809 : 54 : gcc_assert (omp_privatize_by_reference (var)
7810 : : && var == orig_var);
7811 : : }
7812 : 635 : else if (TREE_CODE (d) == ADDR_EXPR)
7813 : : {
7814 : 304 : if (orig_var == var)
7815 : : {
7816 : 279 : new_var = build_fold_addr_expr (new_var);
7817 : 279 : ref = build_fold_addr_expr (ref);
7818 : : }
7819 : : }
7820 : : else
7821 : : {
7822 : 331 : gcc_assert (orig_var == var);
7823 : 331 : if (omp_privatize_by_reference (var))
7824 : 79 : ref = build_fold_addr_expr (ref);
7825 : : }
7826 : 689 : if (DECL_P (v))
7827 : : {
7828 : 93 : tree t = maybe_lookup_decl (v, ctx);
7829 : 93 : if (t)
7830 : 88 : v = t;
7831 : : else
7832 : 5 : v = maybe_lookup_decl_in_outer_ctx (v, ctx);
7833 : 93 : gimplify_expr (&v, stmt_seqp, NULL, is_gimple_val, fb_rvalue);
7834 : : }
7835 : 689 : if (!integer_zerop (bias))
7836 : : {
7837 : 402 : bias = fold_convert_loc (clause_loc, sizetype, bias);
7838 : 804 : new_var = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR,
7839 : 402 : TREE_TYPE (new_var), new_var,
7840 : : unshare_expr (bias));
7841 : 402 : ref = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR,
7842 : 402 : TREE_TYPE (ref), ref, bias);
7843 : : }
7844 : 689 : new_var = fold_convert_loc (clause_loc, ptype, new_var);
7845 : 689 : ref = fold_convert_loc (clause_loc, ptype, ref);
7846 : 689 : tree m = create_tmp_var (ptype);
7847 : 689 : gimplify_assign (m, new_var, stmt_seqp);
7848 : 689 : new_var = m;
7849 : 689 : m = create_tmp_var (ptype);
7850 : 689 : gimplify_assign (m, ref, stmt_seqp);
7851 : 689 : ref = m;
7852 : 689 : gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), stmt_seqp);
7853 : 689 : tree body = create_artificial_label (UNKNOWN_LOCATION);
7854 : 689 : tree end = create_artificial_label (UNKNOWN_LOCATION);
7855 : 689 : gimple_seq_add_stmt (&sub_seq, gimple_build_label (body));
7856 : 689 : tree priv = build_simple_mem_ref_loc (clause_loc, new_var);
7857 : 689 : tree out = build_simple_mem_ref_loc (clause_loc, ref);
7858 : 689 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7859 : : {
7860 : 72 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7861 : 72 : tree decl_placeholder
7862 : 72 : = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c);
7863 : 72 : SET_DECL_VALUE_EXPR (placeholder, out);
7864 : 72 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
7865 : 72 : SET_DECL_VALUE_EXPR (decl_placeholder, priv);
7866 : 72 : DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 1;
7867 : 72 : lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
7868 : 72 : gimple_seq_add_seq (&sub_seq,
7869 : 72 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
7870 : 72 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
7871 : 72 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
7872 : 72 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = NULL;
7873 : : }
7874 : : else
7875 : : {
7876 : 617 : tree out2 = out;
7877 : 617 : tree priv2 = priv;
7878 : 617 : if (is_truth_op)
7879 : : {
7880 : 0 : tree zero = build_zero_cst (TREE_TYPE (out));
7881 : 0 : out2 = fold_build2_loc (clause_loc, NE_EXPR,
7882 : : boolean_type_node, out, zero);
7883 : 0 : priv2 = fold_build2_loc (clause_loc, NE_EXPR,
7884 : : boolean_type_node, priv, zero);
7885 : : }
7886 : 617 : x = build2 (code, TREE_TYPE (out2), out2, priv2);
7887 : 617 : if (is_truth_op)
7888 : 0 : x = fold_convert (TREE_TYPE (out), x);
7889 : 617 : out = unshare_expr (out);
7890 : 617 : gimplify_assign (out, x, &sub_seq);
7891 : : }
7892 : 689 : gimple *g = gimple_build_assign (new_var, POINTER_PLUS_EXPR, new_var,
7893 : 689 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
7894 : 689 : gimple_seq_add_stmt (&sub_seq, g);
7895 : 689 : g = gimple_build_assign (ref, POINTER_PLUS_EXPR, ref,
7896 : 689 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
7897 : 689 : gimple_seq_add_stmt (&sub_seq, g);
7898 : 689 : g = gimple_build_assign (i, PLUS_EXPR, i,
7899 : 689 : build_int_cst (TREE_TYPE (i), 1));
7900 : 689 : gimple_seq_add_stmt (&sub_seq, g);
7901 : 689 : g = gimple_build_cond (LE_EXPR, i, v, body, end);
7902 : 689 : gimple_seq_add_stmt (&sub_seq, g);
7903 : 689 : gimple_seq_add_stmt (&sub_seq, gimple_build_label (end));
7904 : : }
7905 : 1380 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7906 : : {
7907 : 774 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7908 : :
7909 : 774 : if (omp_privatize_by_reference (var)
7910 : 831 : && !useless_type_conversion_p (TREE_TYPE (placeholder),
7911 : 57 : TREE_TYPE (ref)))
7912 : 49 : ref = build_fold_addr_expr_loc (clause_loc, ref);
7913 : 774 : SET_DECL_VALUE_EXPR (placeholder, ref);
7914 : 774 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
7915 : 774 : lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
7916 : 774 : gimple_seq_add_seq (&sub_seq, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
7917 : 774 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
7918 : 774 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
7919 : : }
7920 : : else
7921 : : {
7922 : 606 : tree new_var2 = new_var;
7923 : 606 : tree ref2 = ref;
7924 : 606 : if (is_truth_op)
7925 : : {
7926 : 78 : tree zero = build_zero_cst (TREE_TYPE (new_var));
7927 : 78 : new_var2 = fold_build2_loc (clause_loc, NE_EXPR,
7928 : : boolean_type_node, new_var, zero);
7929 : 78 : ref2 = fold_build2_loc (clause_loc, NE_EXPR, boolean_type_node,
7930 : : ref, zero);
7931 : : }
7932 : 606 : x = build2 (code, TREE_TYPE (ref), ref2, new_var2);
7933 : 606 : if (is_truth_op)
7934 : 78 : x = fold_convert (TREE_TYPE (new_var), x);
7935 : 606 : ref = build_outer_var_ref (var, ctx);
7936 : 606 : gimplify_assign (ref, x, &sub_seq);
7937 : : }
7938 : : }
7939 : :
7940 : 1025 : stmt = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START),
7941 : : 0);
7942 : 1025 : gimple_seq_add_stmt (stmt_seqp, stmt);
7943 : :
7944 : 1025 : gimple_seq_add_seq (stmt_seqp, sub_seq);
7945 : :
7946 : 1025 : if (clist)
7947 : : {
7948 : 157 : gimple_seq_add_seq (stmt_seqp, *clist);
7949 : 157 : *clist = NULL;
7950 : : }
7951 : :
7952 : 1025 : stmt = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END),
7953 : : 0);
7954 : 1025 : gimple_seq_add_stmt (stmt_seqp, stmt);
7955 : : }
7956 : :
7957 : :
7958 : : /* Generate code to implement the COPYPRIVATE clauses. */
7959 : :
7960 : : static void
7961 : 115 : lower_copyprivate_clauses (tree clauses, gimple_seq *slist, gimple_seq *rlist,
7962 : : omp_context *ctx)
7963 : : {
7964 : 115 : tree c;
7965 : :
7966 : 463 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7967 : : {
7968 : 348 : tree var, new_var, ref, x;
7969 : 348 : bool by_ref;
7970 : 348 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
7971 : :
7972 : 348 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_COPYPRIVATE)
7973 : 6 : continue;
7974 : :
7975 : 342 : var = OMP_CLAUSE_DECL (c);
7976 : 342 : by_ref = use_pointer_for_field (var, NULL);
7977 : :
7978 : 342 : ref = build_sender_ref (var, ctx);
7979 : 342 : x = new_var = lookup_decl_in_outer_ctx (var, ctx);
7980 : 342 : if (by_ref)
7981 : : {
7982 : 74 : x = build_fold_addr_expr_loc (clause_loc, new_var);
7983 : 74 : x = fold_convert_loc (clause_loc, TREE_TYPE (ref), x);
7984 : : }
7985 : 342 : gimplify_assign (ref, x, slist);
7986 : :
7987 : 342 : ref = build_receiver_ref (var, false, ctx);
7988 : 342 : if (by_ref)
7989 : : {
7990 : 74 : ref = fold_convert_loc (clause_loc,
7991 : 74 : build_pointer_type (TREE_TYPE (new_var)),
7992 : : ref);
7993 : 74 : ref = build_fold_indirect_ref_loc (clause_loc, ref);
7994 : : }
7995 : 342 : if (omp_privatize_by_reference (var))
7996 : : {
7997 : 171 : ref = fold_convert_loc (clause_loc, TREE_TYPE (new_var), ref);
7998 : 171 : ref = build_simple_mem_ref_loc (clause_loc, ref);
7999 : 171 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
8000 : : }
8001 : 342 : x = lang_hooks.decls.omp_clause_assign_op (c, new_var, ref);
8002 : 342 : gimplify_and_add (x, rlist);
8003 : : }
8004 : 115 : }
8005 : :
8006 : :
8007 : : /* Generate code to implement the clauses, FIRSTPRIVATE, COPYIN, LASTPRIVATE,
8008 : : and REDUCTION from the sender (aka parent) side. */
8009 : :
8010 : : static void
8011 : 22344 : lower_send_clauses (tree clauses, gimple_seq *ilist, gimple_seq *olist,
8012 : : omp_context *ctx)
8013 : : {
8014 : 22344 : tree c, t;
8015 : 22344 : int ignored_looptemp = 0;
8016 : 22344 : bool is_taskloop = false;
8017 : :
8018 : : /* For taskloop, ignore first two _looptemp_ clauses, those are initialized
8019 : : by GOMP_taskloop. */
8020 : 22344 : if (is_task_ctx (ctx) && gimple_omp_task_taskloop_p (ctx->stmt))
8021 : : {
8022 : : ignored_looptemp = 2;
8023 : : is_taskloop = true;
8024 : : }
8025 : :
8026 : 116754 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
8027 : : {
8028 : 94410 : tree val, ref, x, var;
8029 : 94410 : bool by_ref, do_in = false, do_out = false;
8030 : 94410 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
8031 : :
8032 : 94410 : switch (OMP_CLAUSE_CODE (c))
8033 : : {
8034 : 4646 : case OMP_CLAUSE_PRIVATE:
8035 : 4646 : if (OMP_CLAUSE_PRIVATE_OUTER_REF (c))
8036 : : break;
8037 : 4491 : continue;
8038 : : case OMP_CLAUSE_FIRSTPRIVATE:
8039 : : case OMP_CLAUSE_COPYIN:
8040 : : case OMP_CLAUSE_LASTPRIVATE:
8041 : : case OMP_CLAUSE_IN_REDUCTION:
8042 : : case OMP_CLAUSE__REDUCTEMP_:
8043 : : break;
8044 : 4784 : case OMP_CLAUSE_REDUCTION:
8045 : 4784 : if (is_task_ctx (ctx) || OMP_CLAUSE_REDUCTION_TASK (c))
8046 : 744 : continue;
8047 : : break;
8048 : 17537 : case OMP_CLAUSE_SHARED:
8049 : 17537 : if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
8050 : : break;
8051 : 17225 : continue;
8052 : 18789 : case OMP_CLAUSE__LOOPTEMP_:
8053 : 18789 : if (ignored_looptemp)
8054 : : {
8055 : 2660 : ignored_looptemp--;
8056 : 2660 : continue;
8057 : : }
8058 : : break;
8059 : 11896 : default:
8060 : 11896 : continue;
8061 : : }
8062 : :
8063 : 57394 : val = OMP_CLAUSE_DECL (c);
8064 : 57394 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
8065 : 53354 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8066 : 59034 : && TREE_CODE (val) == MEM_REF)
8067 : : {
8068 : 1578 : val = TREE_OPERAND (val, 0);
8069 : 1578 : if (TREE_CODE (val) == POINTER_PLUS_EXPR)
8070 : 351 : val = TREE_OPERAND (val, 0);
8071 : 1578 : if (INDIRECT_REF_P (val)
8072 : 1494 : || TREE_CODE (val) == ADDR_EXPR)
8073 : 906 : val = TREE_OPERAND (val, 0);
8074 : 1578 : if (is_variable_sized (val))
8075 : 56 : continue;
8076 : : }
8077 : :
8078 : : /* For OMP_CLAUSE_SHARED_FIRSTPRIVATE, look beyond the
8079 : : outer taskloop region. */
8080 : 57338 : omp_context *ctx_for_o = ctx;
8081 : 57338 : if (is_taskloop
8082 : 3911 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
8083 : 57650 : && OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
8084 : 312 : ctx_for_o = ctx->outer;
8085 : :
8086 : 57338 : var = lookup_decl_in_outer_ctx (val, ctx_for_o);
8087 : :
8088 : 57338 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_COPYIN
8089 : 56828 : && is_global_var (var)
8090 : 59637 : && (val == OMP_CLAUSE_DECL (c)
8091 : 273 : || !is_task_ctx (ctx)
8092 : 241 : || (TREE_CODE (TREE_TYPE (val)) != POINTER_TYPE
8093 : 187 : && (TREE_CODE (TREE_TYPE (val)) != REFERENCE_TYPE
8094 : 0 : || (TREE_CODE (TREE_TYPE (TREE_TYPE (val)))
8095 : : != POINTER_TYPE)))))
8096 : 2245 : continue;
8097 : :
8098 : 55093 : t = omp_member_access_dummy_var (var);
8099 : 55093 : if (t)
8100 : : {
8101 : 249 : var = DECL_VALUE_EXPR (var);
8102 : 249 : tree o = maybe_lookup_decl_in_outer_ctx (t, ctx_for_o);
8103 : 249 : if (o != t)
8104 : 69 : var = unshare_and_remap (var, t, o);
8105 : : else
8106 : 180 : var = unshare_expr (var);
8107 : : }
8108 : :
8109 : 55093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
8110 : : {
8111 : : /* Handle taskloop firstprivate/lastprivate, where the
8112 : : lastprivate on GIMPLE_OMP_TASK is represented as
8113 : : OMP_CLAUSE_SHARED_FIRSTPRIVATE. */
8114 : 79 : tree f = lookup_sfield ((splay_tree_key) &DECL_UID (val), ctx);
8115 : 79 : x = omp_build_component_ref (ctx->sender_decl, f);
8116 : 79 : if (use_pointer_for_field (val, ctx))
8117 : 59 : var = build_fold_addr_expr (var);
8118 : 79 : gimplify_assign (x, var, ilist);
8119 : 79 : DECL_ABSTRACT_ORIGIN (f) = NULL;
8120 : 79 : continue;
8121 : 79 : }
8122 : :
8123 : 55068 : if (((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
8124 : 51719 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION)
8125 : 4431 : || val == OMP_CLAUSE_DECL (c))
8126 : 108725 : && is_variable_sized (val))
8127 : 54 : continue;
8128 : 54960 : by_ref = use_pointer_for_field (val, NULL);
8129 : :
8130 : 54960 : switch (OMP_CLAUSE_CODE (c))
8131 : : {
8132 : 26717 : case OMP_CLAUSE_FIRSTPRIVATE:
8133 : 26717 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8134 : 7217 : && !by_ref
8135 : 33882 : && is_task_ctx (ctx))
8136 : 2328 : suppress_warning (var);
8137 : : do_in = true;
8138 : : break;
8139 : :
8140 : : case OMP_CLAUSE_PRIVATE:
8141 : : case OMP_CLAUSE_COPYIN:
8142 : : case OMP_CLAUSE__LOOPTEMP_:
8143 : : case OMP_CLAUSE__REDUCTEMP_:
8144 : : do_in = true;
8145 : : break;
8146 : :
8147 : 6463 : case OMP_CLAUSE_LASTPRIVATE:
8148 : 6463 : if (by_ref || omp_privatize_by_reference (val))
8149 : : {
8150 : 383 : if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c))
8151 : 239 : continue;
8152 : : do_in = true;
8153 : : }
8154 : : else
8155 : : {
8156 : 6080 : do_out = true;
8157 : 6080 : if (lang_hooks.decls.omp_private_outer_ref (val))
8158 : : do_in = true;
8159 : : }
8160 : : break;
8161 : :
8162 : 4431 : case OMP_CLAUSE_REDUCTION:
8163 : 4431 : case OMP_CLAUSE_IN_REDUCTION:
8164 : 4431 : do_in = true;
8165 : 4431 : if (val == OMP_CLAUSE_DECL (c))
8166 : : {
8167 : 3128 : if (is_task_ctx (ctx))
8168 : 301 : by_ref = use_pointer_for_field (val, ctx);
8169 : : else
8170 : 2827 : do_out = !(by_ref || omp_privatize_by_reference (val));
8171 : : }
8172 : : else
8173 : 1303 : by_ref = TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE;
8174 : : break;
8175 : :
8176 : 0 : default:
8177 : 0 : gcc_unreachable ();
8178 : : }
8179 : :
8180 : 1604 : if (do_in)
8181 : : {
8182 : 48665 : ref = build_sender_ref (val, ctx);
8183 : 48665 : x = by_ref ? build_fold_addr_expr_loc (clause_loc, var) : var;
8184 : 48665 : gimplify_assign (ref, x, ilist);
8185 : 48665 : if (is_task_ctx (ctx))
8186 : 6227 : DECL_ABSTRACT_ORIGIN (TREE_OPERAND (ref, 1)) = NULL;
8187 : : }
8188 : :
8189 : 54721 : if (do_out)
8190 : : {
8191 : 8374 : ref = build_sender_ref (val, ctx);
8192 : 8374 : gimplify_assign (var, ref, olist);
8193 : : }
8194 : : }
8195 : 22344 : }
8196 : :
8197 : : /* Generate code to implement SHARED from the sender (aka parent)
8198 : : side. This is trickier, since GIMPLE_OMP_PARALLEL_CLAUSES doesn't
8199 : : list things that got automatically shared. */
8200 : :
8201 : : static void
8202 : 22344 : lower_send_shared_vars (gimple_seq *ilist, gimple_seq *olist, omp_context *ctx)
8203 : : {
8204 : 22344 : tree var, ovar, nvar, t, f, x, record_type;
8205 : :
8206 : 22344 : if (ctx->record_type == NULL)
8207 : 4437 : return;
8208 : :
8209 : 17907 : record_type = ctx->srecord_type ? ctx->srecord_type : ctx->record_type;
8210 : 86638 : for (f = TYPE_FIELDS (record_type); f ; f = DECL_CHAIN (f))
8211 : : {
8212 : 68731 : ovar = DECL_ABSTRACT_ORIGIN (f);
8213 : 68731 : if (!ovar || TREE_CODE (ovar) == FIELD_DECL)
8214 : 6306 : continue;
8215 : :
8216 : 62425 : nvar = maybe_lookup_decl (ovar, ctx);
8217 : 113223 : if (!nvar
8218 : 62016 : || !DECL_HAS_VALUE_EXPR_P (nvar)
8219 : 74233 : || (ctx->allocate_map
8220 : 274 : && ctx->allocate_map->get (ovar)))
8221 : 50798 : continue;
8222 : :
8223 : : /* If CTX is a nested parallel directive. Find the immediately
8224 : : enclosing parallel or workshare construct that contains a
8225 : : mapping for OVAR. */
8226 : 11627 : var = lookup_decl_in_outer_ctx (ovar, ctx);
8227 : :
8228 : 11627 : t = omp_member_access_dummy_var (var);
8229 : 11627 : if (t)
8230 : : {
8231 : 49 : var = DECL_VALUE_EXPR (var);
8232 : 49 : tree o = maybe_lookup_decl_in_outer_ctx (t, ctx);
8233 : 49 : if (o != t)
8234 : 18 : var = unshare_and_remap (var, t, o);
8235 : : else
8236 : 31 : var = unshare_expr (var);
8237 : : }
8238 : :
8239 : 11627 : if (use_pointer_for_field (ovar, ctx))
8240 : : {
8241 : 6432 : x = build_sender_ref (ovar, ctx);
8242 : 6432 : if (TREE_CODE (TREE_TYPE (f)) == ARRAY_TYPE
8243 : 6432 : && TREE_TYPE (f) == TREE_TYPE (ovar))
8244 : : {
8245 : 103 : gcc_assert (is_parallel_ctx (ctx)
8246 : : && DECL_ARTIFICIAL (ovar));
8247 : : /* _condtemp_ clause. */
8248 : 103 : var = build_constructor (TREE_TYPE (x), NULL);
8249 : : }
8250 : : else
8251 : 6329 : var = build_fold_addr_expr (var);
8252 : 6432 : gimplify_assign (x, var, ilist);
8253 : : }
8254 : : else
8255 : : {
8256 : 5195 : x = build_sender_ref (ovar, ctx);
8257 : 5195 : gimplify_assign (x, var, ilist);
8258 : :
8259 : 5195 : if (!TREE_READONLY (var)
8260 : : /* We don't need to receive a new reference to a result
8261 : : or parm decl. In fact we may not store to it as we will
8262 : : invalidate any pending RSO and generate wrong gimple
8263 : : during inlining. */
8264 : 5195 : && !((TREE_CODE (var) == RESULT_DECL
8265 : 3298 : || TREE_CODE (var) == PARM_DECL)
8266 : 182 : && DECL_BY_REFERENCE (var)))
8267 : : {
8268 : 3227 : x = build_sender_ref (ovar, ctx);
8269 : 3227 : gimplify_assign (var, x, olist);
8270 : : }
8271 : : }
8272 : : }
8273 : : }
8274 : :
8275 : : /* Emit an OpenACC head marker call, encapulating the partitioning and
8276 : : other information that must be processed by the target compiler.
8277 : : Return the maximum number of dimensions the associated loop might
8278 : : be partitioned over. */
8279 : :
8280 : : static unsigned
8281 : 9665 : lower_oacc_head_mark (location_t loc, tree ddvar, tree clauses,
8282 : : gimple_seq *seq, omp_context *ctx)
8283 : : {
8284 : 9665 : unsigned levels = 0;
8285 : 9665 : unsigned tag = 0;
8286 : 9665 : tree gang_static = NULL_TREE;
8287 : 9665 : auto_vec<tree, 5> args;
8288 : :
8289 : 19330 : args.quick_push (build_int_cst
8290 : 9665 : (integer_type_node, IFN_UNIQUE_OACC_HEAD_MARK));
8291 : 9665 : args.quick_push (ddvar);
8292 : 30854 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
8293 : : {
8294 : 21189 : switch (OMP_CLAUSE_CODE (c))
8295 : : {
8296 : 1856 : case OMP_CLAUSE_GANG:
8297 : 1856 : tag |= OLF_DIM_GANG;
8298 : 1856 : gang_static = OMP_CLAUSE_GANG_STATIC_EXPR (c);
8299 : : /* static:* is represented by -1, and we can ignore it, as
8300 : : scheduling is always static. */
8301 : 1856 : if (gang_static && integer_minus_onep (gang_static))
8302 : 70 : gang_static = NULL_TREE;
8303 : 1856 : levels++;
8304 : 1856 : break;
8305 : :
8306 : 1330 : case OMP_CLAUSE_WORKER:
8307 : 1330 : tag |= OLF_DIM_WORKER;
8308 : 1330 : levels++;
8309 : 1330 : break;
8310 : :
8311 : 1523 : case OMP_CLAUSE_VECTOR:
8312 : 1523 : tag |= OLF_DIM_VECTOR;
8313 : 1523 : levels++;
8314 : 1523 : break;
8315 : :
8316 : 314 : case OMP_CLAUSE_SEQ:
8317 : 314 : tag |= OLF_SEQ;
8318 : 314 : break;
8319 : :
8320 : 409 : case OMP_CLAUSE_AUTO:
8321 : 409 : tag |= OLF_AUTO;
8322 : 409 : break;
8323 : :
8324 : 260 : case OMP_CLAUSE_INDEPENDENT:
8325 : 260 : tag |= OLF_INDEPENDENT;
8326 : 260 : break;
8327 : :
8328 : 136 : case OMP_CLAUSE_TILE:
8329 : 136 : tag |= OLF_TILE;
8330 : 136 : break;
8331 : :
8332 : 3986 : case OMP_CLAUSE_REDUCTION:
8333 : 3986 : tag |= OLF_REDUCTION;
8334 : 3986 : break;
8335 : :
8336 : 11375 : default:
8337 : 11375 : continue;
8338 : : }
8339 : : }
8340 : :
8341 : 9665 : if (gang_static)
8342 : : {
8343 : 146 : if (DECL_P (gang_static))
8344 : 16 : gang_static = build_outer_var_ref (gang_static, ctx);
8345 : 146 : tag |= OLF_GANG_STATIC;
8346 : : }
8347 : :
8348 : 9665 : omp_context *tgt = enclosing_target_ctx (ctx);
8349 : 9665 : if (!tgt || is_oacc_parallel_or_serial (tgt))
8350 : : ;
8351 : 62 : else if (is_oacc_kernels (tgt))
8352 : : /* Not using this loops handling inside OpenACC 'kernels' regions. */
8353 : 0 : gcc_unreachable ();
8354 : 62 : else if (is_oacc_kernels_decomposed_part (tgt))
8355 : : ;
8356 : : else
8357 : 0 : gcc_unreachable ();
8358 : :
8359 : : /* In a parallel region, loops are implicitly INDEPENDENT. */
8360 : 9665 : if (!tgt || is_oacc_parallel_or_serial (tgt))
8361 : 9603 : tag |= OLF_INDEPENDENT;
8362 : :
8363 : : /* Loops inside OpenACC 'kernels' decomposed parts' regions are expected to
8364 : : have an explicit 'seq' or 'independent' clause, and no 'auto' clause. */
8365 : 9665 : if (tgt && is_oacc_kernels_decomposed_part (tgt))
8366 : : {
8367 : 62 : gcc_assert (tag & (OLF_SEQ | OLF_INDEPENDENT));
8368 : 62 : gcc_assert (!(tag & OLF_AUTO));
8369 : : }
8370 : :
8371 : 9665 : if (tag & OLF_TILE)
8372 : : /* Tiling could use all 3 levels. */
8373 : : levels = 3;
8374 : : else
8375 : : {
8376 : : /* A loop lacking SEQ, GANG, WORKER and/or VECTOR could be AUTO.
8377 : : Ensure at least one level, or 2 for possible auto
8378 : : partitioning */
8379 : 9529 : bool maybe_auto = !(tag & (((GOMP_DIM_MASK (GOMP_DIM_MAX) - 1)
8380 : : << OLF_DIM_BASE) | OLF_SEQ));
8381 : :
8382 : 9529 : if (levels < 1u + maybe_auto)
8383 : : levels = 1u + maybe_auto;
8384 : : }
8385 : :
8386 : 9665 : args.quick_push (build_int_cst (integer_type_node, levels));
8387 : 9665 : args.quick_push (build_int_cst (integer_type_node, tag));
8388 : 9665 : if (gang_static)
8389 : 146 : args.quick_push (gang_static);
8390 : :
8391 : 9665 : gcall *call = gimple_build_call_internal_vec (IFN_UNIQUE, args);
8392 : 9665 : gimple_set_location (call, loc);
8393 : 9665 : gimple_set_lhs (call, ddvar);
8394 : 9665 : gimple_seq_add_stmt (seq, call);
8395 : :
8396 : 9665 : return levels;
8397 : 9665 : }
8398 : :
8399 : : /* Emit an OpenACC lopp head or tail marker to SEQ. LEVEL is the
8400 : : partitioning level of the enclosed region. */
8401 : :
8402 : : static void
8403 : 42767 : lower_oacc_loop_marker (location_t loc, tree ddvar, bool head,
8404 : : tree tofollow, gimple_seq *seq)
8405 : : {
8406 : 42767 : int marker_kind = (head ? IFN_UNIQUE_OACC_HEAD_MARK
8407 : : : IFN_UNIQUE_OACC_TAIL_MARK);
8408 : 42767 : tree marker = build_int_cst (integer_type_node, marker_kind);
8409 : 42767 : int nargs = 2 + (tofollow != NULL_TREE);
8410 : 42767 : gcall *call = gimple_build_call_internal (IFN_UNIQUE, nargs,
8411 : : marker, ddvar, tofollow);
8412 : 42767 : gimple_set_location (call, loc);
8413 : 42767 : gimple_set_lhs (call, ddvar);
8414 : 42767 : gimple_seq_add_stmt (seq, call);
8415 : 42767 : }
8416 : :
8417 : : /* Generate the before and after OpenACC loop sequences. CLAUSES are
8418 : : the loop clauses, from which we extract reductions. Initialize
8419 : : HEAD and TAIL. */
8420 : :
8421 : : static void
8422 : 9665 : lower_oacc_head_tail (location_t loc, tree clauses, gcall *private_marker,
8423 : : gimple_seq *head, gimple_seq *tail, omp_context *ctx)
8424 : : {
8425 : 9665 : bool inner = false;
8426 : 9665 : tree ddvar = create_tmp_var (integer_type_node, ".data_dep");
8427 : 9665 : gimple_seq_add_stmt (head, gimple_build_assign (ddvar, integer_zero_node));
8428 : :
8429 : 9665 : unsigned count = lower_oacc_head_mark (loc, ddvar, clauses, head, ctx);
8430 : :
8431 : 9665 : if (private_marker)
8432 : : {
8433 : 229 : gimple_set_location (private_marker, loc);
8434 : 229 : gimple_call_set_lhs (private_marker, ddvar);
8435 : 229 : gimple_call_set_arg (private_marker, 1, ddvar);
8436 : : }
8437 : :
8438 : 9665 : tree fork_kind = build_int_cst (unsigned_type_node, IFN_UNIQUE_OACC_FORK);
8439 : 9665 : tree join_kind = build_int_cst (unsigned_type_node, IFN_UNIQUE_OACC_JOIN);
8440 : :
8441 : 9665 : gcc_assert (count);
8442 : 26216 : for (unsigned done = 1; count; count--, done++)
8443 : : {
8444 : 16551 : gimple_seq fork_seq = NULL;
8445 : 16551 : gimple_seq join_seq = NULL;
8446 : :
8447 : 16551 : tree place = build_int_cst (integer_type_node, -1);
8448 : 16551 : gcall *fork = gimple_build_call_internal (IFN_UNIQUE, 3,
8449 : : fork_kind, ddvar, place);
8450 : 16551 : gimple_set_location (fork, loc);
8451 : 16551 : gimple_set_lhs (fork, ddvar);
8452 : :
8453 : 16551 : gcall *join = gimple_build_call_internal (IFN_UNIQUE, 3,
8454 : : join_kind, ddvar, place);
8455 : 16551 : gimple_set_location (join, loc);
8456 : 16551 : gimple_set_lhs (join, ddvar);
8457 : :
8458 : : /* Mark the beginning of this level sequence. */
8459 : 16551 : if (inner)
8460 : 6886 : lower_oacc_loop_marker (loc, ddvar, true,
8461 : 6886 : build_int_cst (integer_type_node, count),
8462 : : &fork_seq);
8463 : 16551 : lower_oacc_loop_marker (loc, ddvar, false,
8464 : 16551 : build_int_cst (integer_type_node, done),
8465 : : &join_seq);
8466 : :
8467 : 23437 : lower_oacc_reductions (loc, clauses, place, inner,
8468 : : fork, (count == 1) ? private_marker : NULL,
8469 : : join, &fork_seq, &join_seq, ctx);
8470 : :
8471 : : /* Append this level to head. */
8472 : 16551 : gimple_seq_add_seq (head, fork_seq);
8473 : : /* Prepend it to tail. */
8474 : 16551 : gimple_seq_add_seq (&join_seq, *tail);
8475 : 16551 : *tail = join_seq;
8476 : :
8477 : 16551 : inner = true;
8478 : : }
8479 : :
8480 : : /* Mark the end of the sequence. */
8481 : 9665 : lower_oacc_loop_marker (loc, ddvar, true, NULL_TREE, head);
8482 : 9665 : lower_oacc_loop_marker (loc, ddvar, false, NULL_TREE, tail);
8483 : 9665 : }
8484 : :
8485 : : /* If exceptions are enabled, wrap the statements in BODY in a MUST_NOT_THROW
8486 : : catch handler and return it. This prevents programs from violating the
8487 : : structured block semantics with throws. */
8488 : :
8489 : : static gimple_seq
8490 : 94387 : maybe_catch_exception (gimple_seq body)
8491 : : {
8492 : 94387 : gimple *g;
8493 : 94387 : tree decl;
8494 : :
8495 : 94387 : if (!flag_exceptions)
8496 : : return body;
8497 : :
8498 : 42403 : if (lang_hooks.eh_protect_cleanup_actions != NULL)
8499 : 42375 : decl = lang_hooks.eh_protect_cleanup_actions ();
8500 : : else
8501 : 28 : decl = builtin_decl_explicit (BUILT_IN_TRAP);
8502 : :
8503 : 42403 : g = gimple_build_eh_must_not_throw (decl);
8504 : 42403 : g = gimple_build_try (body, gimple_seq_alloc_with_stmt (g),
8505 : : GIMPLE_TRY_CATCH);
8506 : :
8507 : 42403 : return gimple_seq_alloc_with_stmt (g);
8508 : : }
8509 : :
8510 : :
8511 : : /* Routines to lower OMP directives into OMP-GIMPLE. */
8512 : :
8513 : : /* If ctx is a worksharing context inside of a cancellable parallel
8514 : : region and it isn't nowait, add lhs to its GIMPLE_OMP_RETURN
8515 : : and conditional branch to parallel's cancel_label to handle
8516 : : cancellation in the implicit barrier. */
8517 : :
8518 : : static void
8519 : 48495 : maybe_add_implicit_barrier_cancel (omp_context *ctx, gimple *omp_return,
8520 : : gimple_seq *body)
8521 : : {
8522 : 48495 : gcc_assert (gimple_code (omp_return) == GIMPLE_OMP_RETURN);
8523 : 48495 : if (gimple_omp_return_nowait_p (omp_return))
8524 : : return;
8525 : 19551 : for (omp_context *outer = ctx->outer; outer; outer = outer->outer)
8526 : 16006 : if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL
8527 : 16006 : && outer->cancellable)
8528 : : {
8529 : 64 : tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
8530 : 64 : tree c_bool_type = TREE_TYPE (TREE_TYPE (fndecl));
8531 : 64 : tree lhs = create_tmp_var (c_bool_type);
8532 : 64 : gimple_omp_return_set_lhs (omp_return, lhs);
8533 : 64 : tree fallthru_label = create_artificial_label (UNKNOWN_LOCATION);
8534 : 64 : gimple *g = gimple_build_cond (NE_EXPR, lhs,
8535 : : fold_convert (c_bool_type,
8536 : : boolean_false_node),
8537 : : outer->cancel_label, fallthru_label);
8538 : 64 : gimple_seq_add_stmt (body, g);
8539 : 64 : gimple_seq_add_stmt (body, gimple_build_label (fallthru_label));
8540 : : }
8541 : 15942 : else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP
8542 : 15942 : && gimple_code (outer->stmt) != GIMPLE_OMP_SCOPE)
8543 : : return;
8544 : : }
8545 : :
8546 : : /* Find the first task_reduction or reduction clause or return NULL
8547 : : if there are none. */
8548 : :
8549 : : static inline tree
8550 : 48749 : omp_task_reductions_find_first (tree clauses, enum tree_code code,
8551 : : enum omp_clause_code ccode)
8552 : : {
8553 : 64067 : while (1)
8554 : : {
8555 : 56408 : clauses = omp_find_clause (clauses, ccode);
8556 : 56408 : if (clauses == NULL_TREE)
8557 : : return NULL_TREE;
8558 : 9104 : if (ccode != OMP_CLAUSE_REDUCTION
8559 : 9104 : || code == OMP_TASKLOOP
8560 : 9104 : || OMP_CLAUSE_REDUCTION_TASK (clauses))
8561 : : return clauses;
8562 : 7659 : clauses = OMP_CLAUSE_CHAIN (clauses);
8563 : : }
8564 : : }
8565 : :
8566 : : static void lower_omp_task_reductions (omp_context *, enum tree_code, tree,
8567 : : gimple_seq *, gimple_seq *);
8568 : :
8569 : : /* Lower the OpenMP sections directive in the current statement in GSI_P.
8570 : : CTX is the enclosing OMP context for the current statement. */
8571 : :
8572 : : static void
8573 : 378 : lower_omp_sections (gimple_stmt_iterator *gsi_p, omp_context *ctx)
8574 : : {
8575 : 378 : tree block, control;
8576 : 378 : gimple_stmt_iterator tgsi;
8577 : 378 : gomp_sections *stmt;
8578 : 378 : gimple *t;
8579 : 378 : gbind *new_stmt, *bind;
8580 : 378 : gimple_seq ilist, dlist, olist, tred_dlist = NULL, clist = NULL, new_body;
8581 : :
8582 : 378 : stmt = as_a <gomp_sections *> (gsi_stmt (*gsi_p));
8583 : :
8584 : 378 : push_gimplify_context ();
8585 : :
8586 : 378 : dlist = NULL;
8587 : 378 : ilist = NULL;
8588 : :
8589 : 378 : tree rclauses
8590 : 378 : = omp_task_reductions_find_first (gimple_omp_sections_clauses (stmt),
8591 : : OMP_SECTIONS, OMP_CLAUSE_REDUCTION);
8592 : 378 : tree rtmp = NULL_TREE;
8593 : 378 : if (rclauses)
8594 : : {
8595 : 8 : tree type = build_pointer_type (pointer_sized_int_node);
8596 : 8 : tree temp = create_tmp_var (type);
8597 : 8 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
8598 : 8 : OMP_CLAUSE_DECL (c) = temp;
8599 : 8 : OMP_CLAUSE_CHAIN (c) = gimple_omp_sections_clauses (stmt);
8600 : 8 : gimple_omp_sections_set_clauses (stmt, c);
8601 : 8 : lower_omp_task_reductions (ctx, OMP_SECTIONS,
8602 : : gimple_omp_sections_clauses (stmt),
8603 : : &ilist, &tred_dlist);
8604 : 8 : rclauses = c;
8605 : 8 : rtmp = make_ssa_name (type);
8606 : 8 : gimple_seq_add_stmt (&ilist, gimple_build_assign (rtmp, temp));
8607 : : }
8608 : :
8609 : 378 : tree *clauses_ptr = gimple_omp_sections_clauses_ptr (stmt);
8610 : 378 : lower_lastprivate_conditional_clauses (clauses_ptr, ctx);
8611 : :
8612 : 378 : lower_rec_input_clauses (gimple_omp_sections_clauses (stmt),
8613 : : &ilist, &dlist, ctx, NULL);
8614 : :
8615 : 378 : control = create_tmp_var (unsigned_type_node, ".section");
8616 : 378 : gimple_omp_sections_set_control (stmt, control);
8617 : :
8618 : 378 : new_body = gimple_omp_body (stmt);
8619 : 378 : gimple_omp_set_body (stmt, NULL);
8620 : 378 : tgsi = gsi_start (new_body);
8621 : 1233 : for (; !gsi_end_p (tgsi); gsi_next (&tgsi))
8622 : : {
8623 : 855 : omp_context *sctx;
8624 : 855 : gimple *sec_start;
8625 : :
8626 : 855 : sec_start = gsi_stmt (tgsi);
8627 : 855 : sctx = maybe_lookup_ctx (sec_start);
8628 : 855 : gcc_assert (sctx);
8629 : :
8630 : 855 : lower_omp (gimple_omp_body_ptr (sec_start), sctx);
8631 : 855 : gsi_insert_seq_after (&tgsi, gimple_omp_body (sec_start),
8632 : : GSI_CONTINUE_LINKING);
8633 : 855 : gimple_omp_set_body (sec_start, NULL);
8634 : :
8635 : 855 : if (gsi_one_before_end_p (tgsi))
8636 : : {
8637 : 378 : gimple_seq l = NULL;
8638 : 378 : lower_lastprivate_clauses (gimple_omp_sections_clauses (stmt), NULL,
8639 : : &ilist, &l, &clist, ctx);
8640 : 378 : gsi_insert_seq_after (&tgsi, l, GSI_CONTINUE_LINKING);
8641 : 378 : gimple_omp_section_set_last (sec_start);
8642 : : }
8643 : :
8644 : 855 : gsi_insert_after (&tgsi, gimple_build_omp_return (false),
8645 : : GSI_CONTINUE_LINKING);
8646 : : }
8647 : :
8648 : 378 : block = make_node (BLOCK);
8649 : 378 : bind = gimple_build_bind (NULL, new_body, block);
8650 : :
8651 : 378 : olist = NULL;
8652 : 378 : lower_reduction_clauses (gimple_omp_sections_clauses (stmt), &olist,
8653 : : &clist, ctx);
8654 : 378 : if (clist)
8655 : : {
8656 : 10 : tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START);
8657 : 10 : gcall *g = gimple_build_call (fndecl, 0);
8658 : 10 : gimple_seq_add_stmt (&olist, g);
8659 : 10 : gimple_seq_add_seq (&olist, clist);
8660 : 10 : fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END);
8661 : 10 : g = gimple_build_call (fndecl, 0);
8662 : 10 : gimple_seq_add_stmt (&olist, g);
8663 : : }
8664 : :
8665 : 378 : block = make_node (BLOCK);
8666 : 378 : new_stmt = gimple_build_bind (NULL, NULL, block);
8667 : 378 : gsi_replace (gsi_p, new_stmt, true);
8668 : :
8669 : 378 : pop_gimplify_context (new_stmt);
8670 : 378 : gimple_bind_append_vars (new_stmt, ctx->block_vars);
8671 : 378 : BLOCK_VARS (block) = gimple_bind_vars (bind);
8672 : 378 : if (BLOCK_VARS (block))
8673 : 0 : TREE_USED (block) = 1;
8674 : :
8675 : 378 : new_body = NULL;
8676 : 378 : gimple_seq_add_seq (&new_body, ilist);
8677 : 378 : gimple_seq_add_stmt (&new_body, stmt);
8678 : 378 : gimple_seq_add_stmt (&new_body, gimple_build_omp_sections_switch ());
8679 : 378 : gimple_seq_add_stmt (&new_body, bind);
8680 : :
8681 : 378 : t = gimple_build_omp_continue (control, control);
8682 : 378 : gimple_seq_add_stmt (&new_body, t);
8683 : :
8684 : 378 : gimple_seq_add_seq (&new_body, olist);
8685 : 378 : if (ctx->cancellable)
8686 : 19 : gimple_seq_add_stmt (&new_body, gimple_build_label (ctx->cancel_label));
8687 : 378 : gimple_seq_add_seq (&new_body, dlist);
8688 : :
8689 : 378 : new_body = maybe_catch_exception (new_body);
8690 : :
8691 : 378 : bool nowait = omp_find_clause (gimple_omp_sections_clauses (stmt),
8692 : 378 : OMP_CLAUSE_NOWAIT) != NULL_TREE;
8693 : 378 : t = gimple_build_omp_return (nowait);
8694 : 378 : gimple_seq_add_stmt (&new_body, t);
8695 : 378 : gimple_seq_add_seq (&new_body, tred_dlist);
8696 : 378 : maybe_add_implicit_barrier_cancel (ctx, t, &new_body);
8697 : :
8698 : 378 : if (rclauses)
8699 : 8 : OMP_CLAUSE_DECL (rclauses) = rtmp;
8700 : :
8701 : 378 : gimple_bind_set_body (new_stmt, new_body);
8702 : 378 : }
8703 : :
8704 : :
8705 : : /* A subroutine of lower_omp_single. Expand the simple form of
8706 : : a GIMPLE_OMP_SINGLE, without a copyprivate clause:
8707 : :
8708 : : if (GOMP_single_start ())
8709 : : BODY;
8710 : : [ GOMP_barrier (); ] -> unless 'nowait' is present.
8711 : :
8712 : : FIXME. It may be better to delay expanding the logic of this until
8713 : : pass_expand_omp. The expanded logic may make the job more difficult
8714 : : to a synchronization analysis pass. */
8715 : :
8716 : : static void
8717 : 1004 : lower_omp_single_simple (gomp_single *single_stmt, gimple_seq *pre_p)
8718 : : {
8719 : 1004 : location_t loc = gimple_location (single_stmt);
8720 : 1004 : tree tlabel = create_artificial_label (loc);
8721 : 1004 : tree flabel = create_artificial_label (loc);
8722 : 1004 : gimple *call, *cond;
8723 : 1004 : tree lhs, decl;
8724 : :
8725 : 1004 : decl = builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_START);
8726 : 1004 : lhs = create_tmp_var (TREE_TYPE (TREE_TYPE (decl)));
8727 : 1004 : call = gimple_build_call (decl, 0);
8728 : 1004 : gimple_call_set_lhs (call, lhs);
8729 : 1004 : gimple_seq_add_stmt (pre_p, call);
8730 : :
8731 : 1004 : cond = gimple_build_cond (EQ_EXPR, lhs,
8732 : 1004 : fold_convert_loc (loc, TREE_TYPE (lhs),
8733 : : boolean_true_node),
8734 : : tlabel, flabel);
8735 : 1004 : gimple_seq_add_stmt (pre_p, cond);
8736 : 1004 : gimple_seq_add_stmt (pre_p, gimple_build_label (tlabel));
8737 : 1004 : gimple_seq_add_seq (pre_p, gimple_omp_body (single_stmt));
8738 : 1004 : gimple_seq_add_stmt (pre_p, gimple_build_label (flabel));
8739 : 1004 : }
8740 : :
8741 : :
8742 : : /* A subroutine of lower_omp_single. Expand the simple form of
8743 : : a GIMPLE_OMP_SINGLE, with a copyprivate clause:
8744 : :
8745 : : #pragma omp single copyprivate (a, b, c)
8746 : :
8747 : : Create a new structure to hold copies of 'a', 'b' and 'c' and emit:
8748 : :
8749 : : {
8750 : : if ((copyout_p = GOMP_single_copy_start ()) == NULL)
8751 : : {
8752 : : BODY;
8753 : : copyout.a = a;
8754 : : copyout.b = b;
8755 : : copyout.c = c;
8756 : : GOMP_single_copy_end (©out);
8757 : : }
8758 : : else
8759 : : {
8760 : : a = copyout_p->a;
8761 : : b = copyout_p->b;
8762 : : c = copyout_p->c;
8763 : : }
8764 : : GOMP_barrier ();
8765 : : }
8766 : :
8767 : : FIXME. It may be better to delay expanding the logic of this until
8768 : : pass_expand_omp. The expanded logic may make the job more difficult
8769 : : to a synchronization analysis pass. */
8770 : :
8771 : : static void
8772 : 115 : lower_omp_single_copy (gomp_single *single_stmt, gimple_seq *pre_p,
8773 : : omp_context *ctx)
8774 : : {
8775 : 115 : tree ptr_type, t, l0, l1, l2, bfn_decl;
8776 : 115 : gimple_seq copyin_seq;
8777 : 115 : location_t loc = gimple_location (single_stmt);
8778 : :
8779 : 115 : ctx->sender_decl = create_tmp_var (ctx->record_type, ".omp_copy_o");
8780 : :
8781 : 115 : ptr_type = build_pointer_type (ctx->record_type);
8782 : 115 : ctx->receiver_decl = create_tmp_var (ptr_type, ".omp_copy_i");
8783 : :
8784 : 115 : l0 = create_artificial_label (loc);
8785 : 115 : l1 = create_artificial_label (loc);
8786 : 115 : l2 = create_artificial_label (loc);
8787 : :
8788 : 115 : bfn_decl = builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_COPY_START);
8789 : 115 : t = build_call_expr_loc (loc, bfn_decl, 0);
8790 : 115 : t = fold_convert_loc (loc, ptr_type, t);
8791 : 115 : gimplify_assign (ctx->receiver_decl, t, pre_p);
8792 : :
8793 : 115 : t = build2 (EQ_EXPR, boolean_type_node, ctx->receiver_decl,
8794 : : build_int_cst (ptr_type, 0));
8795 : 115 : t = build3 (COND_EXPR, void_type_node, t,
8796 : : build_and_jump (&l0), build_and_jump (&l1));
8797 : 115 : gimplify_and_add (t, pre_p);
8798 : :
8799 : 115 : gimple_seq_add_stmt (pre_p, gimple_build_label (l0));
8800 : :
8801 : 115 : gimple_seq_add_seq (pre_p, gimple_omp_body (single_stmt));
8802 : :
8803 : 115 : copyin_seq = NULL;
8804 : 115 : lower_copyprivate_clauses (gimple_omp_single_clauses (single_stmt), pre_p,
8805 : : ©in_seq, ctx);
8806 : :
8807 : 115 : t = build_fold_addr_expr_loc (loc, ctx->sender_decl);
8808 : 115 : bfn_decl = builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_COPY_END);
8809 : 115 : t = build_call_expr_loc (loc, bfn_decl, 1, t);
8810 : 115 : gimplify_and_add (t, pre_p);
8811 : :
8812 : 115 : t = build_and_jump (&l2);
8813 : 115 : gimplify_and_add (t, pre_p);
8814 : :
8815 : 115 : gimple_seq_add_stmt (pre_p, gimple_build_label (l1));
8816 : :
8817 : 115 : gimple_seq_add_seq (pre_p, copyin_seq);
8818 : :
8819 : 115 : gimple_seq_add_stmt (pre_p, gimple_build_label (l2));
8820 : 115 : }
8821 : :
8822 : :
8823 : : /* Expand code for an OpenMP single directive. */
8824 : :
8825 : : static void
8826 : 1119 : lower_omp_single (gimple_stmt_iterator *gsi_p, omp_context *ctx)
8827 : : {
8828 : 1119 : tree block;
8829 : 1119 : gomp_single *single_stmt = as_a <gomp_single *> (gsi_stmt (*gsi_p));
8830 : 1119 : gbind *bind;
8831 : 1119 : gimple_seq bind_body, bind_body_tail = NULL, dlist;
8832 : :
8833 : 1119 : push_gimplify_context ();
8834 : :
8835 : 1119 : block = make_node (BLOCK);
8836 : 1119 : bind = gimple_build_bind (NULL, NULL, block);
8837 : 1119 : gsi_replace (gsi_p, bind, true);
8838 : 1119 : bind_body = NULL;
8839 : 1119 : dlist = NULL;
8840 : 1119 : lower_rec_input_clauses (gimple_omp_single_clauses (single_stmt),
8841 : : &bind_body, &dlist, ctx, NULL);
8842 : 1119 : lower_omp (gimple_omp_body_ptr (single_stmt), ctx);
8843 : :
8844 : 1119 : gimple_seq_add_stmt (&bind_body, single_stmt);
8845 : :
8846 : 1119 : if (ctx->record_type)
8847 : 115 : lower_omp_single_copy (single_stmt, &bind_body, ctx);
8848 : : else
8849 : 1004 : lower_omp_single_simple (single_stmt, &bind_body);
8850 : :
8851 : 1119 : gimple_omp_set_body (single_stmt, NULL);
8852 : :
8853 : 1119 : gimple_seq_add_seq (&bind_body, dlist);
8854 : :
8855 : 1119 : bind_body = maybe_catch_exception (bind_body);
8856 : :
8857 : 1119 : bool nowait = omp_find_clause (gimple_omp_single_clauses (single_stmt),
8858 : 1119 : OMP_CLAUSE_NOWAIT) != NULL_TREE;
8859 : 1119 : gimple *g = gimple_build_omp_return (nowait);
8860 : 1119 : gimple_seq_add_stmt (&bind_body_tail, g);
8861 : 1119 : maybe_add_implicit_barrier_cancel (ctx, g, &bind_body_tail);
8862 : 1119 : if (ctx->record_type)
8863 : : {
8864 : 115 : gimple_stmt_iterator gsi = gsi_start (bind_body_tail);
8865 : 115 : tree clobber = build_clobber (ctx->record_type);
8866 : 115 : gsi_insert_after (&gsi, gimple_build_assign (ctx->sender_decl,
8867 : : clobber), GSI_SAME_STMT);
8868 : : }
8869 : 1119 : gimple_seq_add_seq (&bind_body, bind_body_tail);
8870 : 1119 : gimple_bind_set_body (bind, bind_body);
8871 : :
8872 : 1119 : pop_gimplify_context (bind);
8873 : :
8874 : 1119 : gimple_bind_append_vars (bind, ctx->block_vars);
8875 : 1119 : BLOCK_VARS (block) = ctx->block_vars;
8876 : 1119 : if (BLOCK_VARS (block))
8877 : 26 : TREE_USED (block) = 1;
8878 : 1119 : }
8879 : :
8880 : :
8881 : : /* Lower code for an OMP scope directive. */
8882 : :
8883 : : static void
8884 : 133 : lower_omp_scope (gimple_stmt_iterator *gsi_p, omp_context *ctx)
8885 : : {
8886 : 133 : tree block;
8887 : 133 : gimple *scope_stmt = gsi_stmt (*gsi_p);
8888 : 133 : gbind *bind;
8889 : 133 : gimple_seq bind_body, bind_body_tail = NULL, dlist;
8890 : 133 : gimple_seq tred_dlist = NULL;
8891 : :
8892 : 133 : push_gimplify_context ();
8893 : :
8894 : 133 : block = make_node (BLOCK);
8895 : 133 : bind = gimple_build_bind (NULL, NULL, block);
8896 : 133 : gsi_replace (gsi_p, bind, true);
8897 : 133 : bind_body = NULL;
8898 : 133 : dlist = NULL;
8899 : :
8900 : 133 : tree rclauses
8901 : 133 : = omp_task_reductions_find_first (gimple_omp_scope_clauses (scope_stmt),
8902 : : OMP_SCOPE, OMP_CLAUSE_REDUCTION);
8903 : 133 : if (rclauses)
8904 : : {
8905 : 46 : tree type = build_pointer_type (pointer_sized_int_node);
8906 : 46 : tree temp = create_tmp_var (type);
8907 : 46 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
8908 : 46 : OMP_CLAUSE_DECL (c) = temp;
8909 : 46 : OMP_CLAUSE_CHAIN (c) = gimple_omp_scope_clauses (scope_stmt);
8910 : 46 : gimple_omp_scope_set_clauses (scope_stmt, c);
8911 : 46 : lower_omp_task_reductions (ctx, OMP_SCOPE,
8912 : : gimple_omp_scope_clauses (scope_stmt),
8913 : : &bind_body, &tred_dlist);
8914 : 46 : rclauses = c;
8915 : 46 : tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_SCOPE_START);
8916 : 46 : gimple *stmt = gimple_build_call (fndecl, 1, temp);
8917 : 46 : gimple_seq_add_stmt (&bind_body, stmt);
8918 : : }
8919 : :
8920 : 133 : lower_rec_input_clauses (gimple_omp_scope_clauses (scope_stmt),
8921 : : &bind_body, &dlist, ctx, NULL);
8922 : 133 : lower_omp (gimple_omp_body_ptr (scope_stmt), ctx);
8923 : :
8924 : 133 : gimple_seq_add_stmt (&bind_body, scope_stmt);
8925 : :
8926 : 133 : gimple_seq_add_seq (&bind_body, gimple_omp_body (scope_stmt));
8927 : :
8928 : 133 : gimple_omp_set_body (scope_stmt, NULL);
8929 : :
8930 : 133 : gimple_seq clist = NULL;
8931 : 133 : lower_reduction_clauses (gimple_omp_scope_clauses (scope_stmt),
8932 : : &bind_body, &clist, ctx);
8933 : 133 : if (clist)
8934 : : {
8935 : 0 : tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START);
8936 : 0 : gcall *g = gimple_build_call (fndecl, 0);
8937 : 0 : gimple_seq_add_stmt (&bind_body, g);
8938 : 0 : gimple_seq_add_seq (&bind_body, clist);
8939 : 0 : fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END);
8940 : 0 : g = gimple_build_call (fndecl, 0);
8941 : 0 : gimple_seq_add_stmt (&bind_body, g);
8942 : : }
8943 : :
8944 : 133 : gimple_seq_add_seq (&bind_body, dlist);
8945 : :
8946 : 133 : bind_body = maybe_catch_exception (bind_body);
8947 : :
8948 : 133 : bool nowait = omp_find_clause (gimple_omp_scope_clauses (scope_stmt),
8949 : 133 : OMP_CLAUSE_NOWAIT) != NULL_TREE;
8950 : 133 : gimple *g = gimple_build_omp_return (nowait);
8951 : 133 : gimple_seq_add_stmt (&bind_body_tail, g);
8952 : 133 : gimple_seq_add_seq (&bind_body_tail, tred_dlist);
8953 : 133 : maybe_add_implicit_barrier_cancel (ctx, g, &bind_body_tail);
8954 : 133 : if (ctx->record_type)
8955 : : {
8956 : 0 : gimple_stmt_iterator gsi = gsi_start (bind_body_tail);
8957 : 0 : tree clobber = build_clobber (ctx->record_type);
8958 : 0 : gsi_insert_after (&gsi, gimple_build_assign (ctx->sender_decl,
8959 : : clobber), GSI_SAME_STMT);
8960 : : }
8961 : 133 : gimple_seq_add_seq (&bind_body, bind_body_tail);
8962 : :
8963 : 133 : gimple_bind_set_body (bind, bind_body);
8964 : :
8965 : 133 : pop_gimplify_context (bind);
8966 : :
8967 : 133 : gimple_bind_append_vars (bind, ctx->block_vars);
8968 : 133 : BLOCK_VARS (block) = ctx->block_vars;
8969 : 133 : if (BLOCK_VARS (block))
8970 : 105 : TREE_USED (block) = 1;
8971 : 133 : }
8972 : :
8973 : : /* Lower code for an OMP dispatch directive. */
8974 : :
8975 : : static void
8976 : 659 : lower_omp_dispatch (gimple_stmt_iterator *gsi_p, omp_context *ctx)
8977 : : {
8978 : 659 : tree block;
8979 : 659 : gimple *stmt = gsi_stmt (*gsi_p);
8980 : 659 : gbind *bind;
8981 : :
8982 : 659 : push_gimplify_context ();
8983 : :
8984 : 659 : block = make_node (BLOCK);
8985 : 659 : bind = gimple_build_bind (NULL, NULL, block);
8986 : 659 : gsi_replace (gsi_p, bind, true);
8987 : :
8988 : 659 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
8989 : 659 : gimple_bind_set_body (bind, maybe_catch_exception (gimple_omp_body (stmt)));
8990 : :
8991 : 659 : pop_gimplify_context (bind);
8992 : :
8993 : 659 : gimple_bind_append_vars (bind, ctx->block_vars);
8994 : 659 : BLOCK_VARS (block) = ctx->block_vars;
8995 : 659 : }
8996 : :
8997 : : /* Expand code for an OpenMP master or masked directive. */
8998 : :
8999 : : static void
9000 : 1108 : lower_omp_master (gimple_stmt_iterator *gsi_p, omp_context *ctx)
9001 : : {
9002 : 1108 : tree block, lab = NULL, x, bfn_decl;
9003 : 1108 : gimple *stmt = gsi_stmt (*gsi_p);
9004 : 1108 : gbind *bind;
9005 : 1108 : location_t loc = gimple_location (stmt);
9006 : 1108 : gimple_seq tseq;
9007 : 1108 : tree filter = integer_zero_node;
9008 : :
9009 : 1108 : push_gimplify_context ();
9010 : :
9011 : 1108 : if (gimple_code (stmt) == GIMPLE_OMP_MASKED)
9012 : : {
9013 : 377 : filter = omp_find_clause (gimple_omp_masked_clauses (stmt),
9014 : : OMP_CLAUSE_FILTER);
9015 : 377 : if (filter)
9016 : 252 : filter = fold_convert (integer_type_node,
9017 : : OMP_CLAUSE_FILTER_EXPR (filter));
9018 : : else
9019 : 125 : filter = integer_zero_node;
9020 : : }
9021 : 1108 : block = make_node (BLOCK);
9022 : 1108 : bind = gimple_build_bind (NULL, NULL, block);
9023 : 1108 : gsi_replace (gsi_p, bind, true);
9024 : 1108 : gimple_bind_add_stmt (bind, stmt);
9025 : :
9026 : 1108 : bfn_decl = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
9027 : 1108 : x = build_call_expr_loc (loc, bfn_decl, 0);
9028 : 1108 : x = build2 (EQ_EXPR, boolean_type_node, x, filter);
9029 : 1108 : x = build3 (COND_EXPR, void_type_node, x, NULL, build_and_jump (&lab));
9030 : 1108 : tseq = NULL;
9031 : 1108 : gimplify_and_add (x, &tseq);
9032 : 1108 : gimple_bind_add_seq (bind, tseq);
9033 : :
9034 : 1108 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
9035 : 1108 : gimple_omp_set_body (stmt, maybe_catch_exception (gimple_omp_body (stmt)));
9036 : 1108 : gimple_bind_add_seq (bind, gimple_omp_body (stmt));
9037 : 1108 : gimple_omp_set_body (stmt, NULL);
9038 : :
9039 : 1108 : gimple_bind_add_stmt (bind, gimple_build_label (lab));
9040 : :
9041 : 1108 : gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
9042 : :
9043 : 1108 : pop_gimplify_context (bind);
9044 : :
9045 : 1108 : gimple_bind_append_vars (bind, ctx->block_vars);
9046 : 1108 : BLOCK_VARS (block) = ctx->block_vars;
9047 : 1108 : }
9048 : :
9049 : : /* Helper function for lower_omp_task_reductions. For a specific PASS
9050 : : find out the current clause it should be processed, or return false
9051 : : if all have been processed already. */
9052 : :
9053 : : static inline bool
9054 : 7946 : omp_task_reduction_iterate (int pass, enum tree_code code,
9055 : : enum omp_clause_code ccode, tree *c, tree *decl,
9056 : : tree *type, tree *next)
9057 : : {
9058 : 11292 : for (; *c; *c = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode))
9059 : : {
9060 : 6692 : if (ccode == OMP_CLAUSE_REDUCTION
9061 : 6636 : && code != OMP_TASKLOOP
9062 : 6636 : && !OMP_CLAUSE_REDUCTION_TASK (*c))
9063 : 56 : continue;
9064 : 6580 : *decl = OMP_CLAUSE_DECL (*c);
9065 : 6580 : *type = TREE_TYPE (*decl);
9066 : 6580 : if (TREE_CODE (*decl) == MEM_REF)
9067 : : {
9068 : 1940 : if (pass != 1)
9069 : 970 : continue;
9070 : : }
9071 : : else
9072 : : {
9073 : 4640 : if (omp_privatize_by_reference (*decl))
9074 : 152 : *type = TREE_TYPE (*type);
9075 : 4640 : if (pass != (!TREE_CONSTANT (TYPE_SIZE_UNIT (*type))))
9076 : 2320 : continue;
9077 : : }
9078 : 3290 : *next = omp_find_clause (OMP_CLAUSE_CHAIN (*c), ccode);
9079 : 3290 : return true;
9080 : : }
9081 : 4656 : *decl = NULL_TREE;
9082 : 4656 : *type = NULL_TREE;
9083 : 4656 : *next = NULL_TREE;
9084 : 4656 : return false;
9085 : : }
9086 : :
9087 : : /* Lower task_reduction and reduction clauses (the latter unless CODE is
9088 : : OMP_TASKGROUP only with task modifier). Register mapping of those in
9089 : : START sequence and reducing them and unregister them in the END sequence. */
9090 : :
9091 : : static void
9092 : 1373 : lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses,
9093 : : gimple_seq *start, gimple_seq *end)
9094 : : {
9095 : 837 : enum omp_clause_code ccode
9096 : : = (code == OMP_TASKGROUP
9097 : 1373 : ? OMP_CLAUSE_TASK_REDUCTION : OMP_CLAUSE_REDUCTION);
9098 : 1373 : tree cancellable = NULL_TREE;
9099 : 1373 : clauses = omp_task_reductions_find_first (clauses, code, ccode);
9100 : 1373 : if (clauses == NULL_TREE)
9101 : 209 : return;
9102 : 1164 : if (code == OMP_FOR || code == OMP_SECTIONS || code == OMP_SCOPE)
9103 : : {
9104 : 316 : for (omp_context *outer = ctx->outer; outer; outer = outer->outer)
9105 : 238 : if (gimple_code (outer->stmt) == GIMPLE_OMP_PARALLEL
9106 : 238 : && outer->cancellable)
9107 : : {
9108 : 14 : cancellable = error_mark_node;
9109 : 14 : break;
9110 : : }
9111 : 224 : else if (gimple_code (outer->stmt) != GIMPLE_OMP_TASKGROUP
9112 : 224 : && gimple_code (outer->stmt) != GIMPLE_OMP_SCOPE)
9113 : : break;
9114 : : }
9115 : 1164 : tree record_type = lang_hooks.types.make_type (RECORD_TYPE);
9116 : 1164 : tree *last = &TYPE_FIELDS (record_type);
9117 : 1164 : unsigned cnt = 0;
9118 : 1164 : if (cancellable)
9119 : : {
9120 : 14 : tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
9121 : : ptr_type_node);
9122 : 14 : tree ifield = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
9123 : : integer_type_node);
9124 : 14 : *last = field;
9125 : 14 : DECL_CHAIN (field) = ifield;
9126 : 14 : last = &DECL_CHAIN (ifield);
9127 : 14 : DECL_CONTEXT (field) = record_type;
9128 : 14 : if (TYPE_ALIGN (record_type) < DECL_ALIGN (field))
9129 : 0 : SET_TYPE_ALIGN (record_type, DECL_ALIGN (field));
9130 : 14 : DECL_CONTEXT (ifield) = record_type;
9131 : 14 : if (TYPE_ALIGN (record_type) < DECL_ALIGN (ifield))
9132 : 0 : SET_TYPE_ALIGN (record_type, DECL_ALIGN (ifield));
9133 : : }
9134 : 3492 : for (int pass = 0; pass < 2; pass++)
9135 : : {
9136 : 2328 : tree decl, type, next;
9137 : 2328 : for (tree c = clauses;
9138 : 3973 : omp_task_reduction_iterate (pass, code, ccode,
9139 : 1645 : &c, &decl, &type, &next); c = next)
9140 : : {
9141 : 1645 : ++cnt;
9142 : 1645 : tree new_type = type;
9143 : 1645 : if (ctx->outer)
9144 : 1164 : new_type = remap_type (type, &ctx->outer->cb);
9145 : 1645 : tree field
9146 : 1645 : = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL,
9147 : 1645 : DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE,
9148 : : new_type);
9149 : 1645 : if (DECL_P (decl) && type == TREE_TYPE (decl))
9150 : : {
9151 : 1122 : SET_DECL_ALIGN (field, DECL_ALIGN (decl));
9152 : 1122 : DECL_USER_ALIGN (field) = DECL_USER_ALIGN (decl);
9153 : 1122 : TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (decl);
9154 : : }
9155 : : else
9156 : 523 : SET_DECL_ALIGN (field, TYPE_ALIGN (type));
9157 : 1645 : DECL_CONTEXT (field) = record_type;
9158 : 1645 : if (TYPE_ALIGN (record_type) < DECL_ALIGN (field))
9159 : 1186 : SET_TYPE_ALIGN (record_type, DECL_ALIGN (field));
9160 : 1645 : *last = field;
9161 : 1645 : last = &DECL_CHAIN (field);
9162 : 1645 : tree bfield
9163 : 1645 : = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL, NULL_TREE,
9164 : : boolean_type_node);
9165 : 1645 : DECL_CONTEXT (bfield) = record_type;
9166 : 1645 : if (TYPE_ALIGN (record_type) < DECL_ALIGN (bfield))
9167 : 0 : SET_TYPE_ALIGN (record_type, DECL_ALIGN (bfield));
9168 : 1645 : *last = bfield;
9169 : 1645 : last = &DECL_CHAIN (bfield);
9170 : : }
9171 : : }
9172 : 1164 : *last = NULL_TREE;
9173 : 1164 : layout_type (record_type);
9174 : :
9175 : : /* Build up an array which registers with the runtime all the reductions
9176 : : and deregisters them at the end. Format documented in libgomp/task.c. */
9177 : 1164 : tree atype = build_array_type_nelts (pointer_sized_int_node, 7 + cnt * 3);
9178 : 1164 : tree avar = create_tmp_var_raw (atype);
9179 : 1164 : gimple_add_tmp_var (avar);
9180 : 1164 : TREE_ADDRESSABLE (avar) = 1;
9181 : 1164 : tree r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_zero_node,
9182 : : NULL_TREE, NULL_TREE);
9183 : 1164 : tree t = build_int_cst (pointer_sized_int_node, cnt);
9184 : 1164 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9185 : 1164 : gimple_seq seq = NULL;
9186 : 1164 : tree sz = fold_convert (pointer_sized_int_node,
9187 : : TYPE_SIZE_UNIT (record_type));
9188 : 1164 : int cachesz = 64;
9189 : 1164 : sz = fold_build2 (PLUS_EXPR, pointer_sized_int_node, sz,
9190 : : build_int_cst (pointer_sized_int_node, cachesz - 1));
9191 : 1164 : sz = fold_build2 (BIT_AND_EXPR, pointer_sized_int_node, sz,
9192 : : build_int_cst (pointer_sized_int_node, ~(cachesz - 1)));
9193 : 1164 : ctx->task_reductions.create (1 + cnt);
9194 : 1164 : ctx->task_reduction_map = new hash_map<tree, unsigned>;
9195 : 2328 : ctx->task_reductions.quick_push (TREE_CODE (sz) == INTEGER_CST
9196 : 1204 : ? sz : NULL_TREE);
9197 : 1164 : sz = force_gimple_operand (sz, &seq, true, NULL_TREE);
9198 : 1164 : gimple_seq_add_seq (start, seq);
9199 : 1164 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_one_node,
9200 : : NULL_TREE, NULL_TREE);
9201 : 1164 : gimple_seq_add_stmt (start, gimple_build_assign (r, sz));
9202 : 1164 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2),
9203 : : NULL_TREE, NULL_TREE);
9204 : 1164 : t = build_int_cst (pointer_sized_int_node,
9205 : 1164 : MAX (TYPE_ALIGN_UNIT (record_type), (unsigned) cachesz));
9206 : 1164 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9207 : 1164 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (3),
9208 : : NULL_TREE, NULL_TREE);
9209 : 1164 : t = build_int_cst (pointer_sized_int_node, -1);
9210 : 1164 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9211 : 1164 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (4),
9212 : : NULL_TREE, NULL_TREE);
9213 : 1164 : t = build_int_cst (pointer_sized_int_node, 0);
9214 : 1164 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9215 : :
9216 : : /* In end, build a loop that iterates from 0 to < omp_get_num_threads ()
9217 : : and for each task reduction checks a bool right after the private variable
9218 : : within that thread's chunk; if the bool is clear, it hasn't been
9219 : : initialized and thus isn't going to be reduced nor destructed, otherwise
9220 : : reduce and destruct it. */
9221 : 1164 : tree idx = create_tmp_var (size_type_node);
9222 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (idx, size_zero_node));
9223 : 1164 : tree num_thr_sz = create_tmp_var (size_type_node);
9224 : 1164 : tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
9225 : 1164 : tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
9226 : 1164 : tree lab3 = NULL_TREE, lab7 = NULL_TREE;
9227 : 1164 : gimple *g;
9228 : 1164 : if (code == OMP_FOR || code == OMP_SECTIONS || code == OMP_SCOPE)
9229 : : {
9230 : : /* For worksharing constructs or scope, only perform it in the master
9231 : : thread, with the exception of cancelled implicit barriers - then only
9232 : : handle the current thread. */
9233 : 281 : tree lab4 = create_artificial_label (UNKNOWN_LOCATION);
9234 : 281 : t = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
9235 : 281 : tree thr_num = create_tmp_var (integer_type_node);
9236 : 281 : g = gimple_build_call (t, 0);
9237 : 281 : gimple_call_set_lhs (g, thr_num);
9238 : 281 : gimple_seq_add_stmt (end, g);
9239 : 281 : if (cancellable)
9240 : : {
9241 : 14 : tree c;
9242 : 14 : tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
9243 : 14 : tree lab6 = create_artificial_label (UNKNOWN_LOCATION);
9244 : 14 : lab3 = create_artificial_label (UNKNOWN_LOCATION);
9245 : 14 : if (code == OMP_FOR)
9246 : 4 : c = gimple_omp_for_clauses (ctx->stmt);
9247 : 10 : else if (code == OMP_SECTIONS)
9248 : 0 : c = gimple_omp_sections_clauses (ctx->stmt);
9249 : : else /* if (code == OMP_SCOPE) */
9250 : 10 : c = gimple_omp_scope_clauses (ctx->stmt);
9251 : 14 : c = OMP_CLAUSE_DECL (omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_));
9252 : 14 : cancellable = c;
9253 : 14 : g = gimple_build_cond (NE_EXPR, c, build_zero_cst (TREE_TYPE (c)),
9254 : : lab5, lab6);
9255 : 14 : gimple_seq_add_stmt (end, g);
9256 : 14 : gimple_seq_add_stmt (end, gimple_build_label (lab5));
9257 : 14 : g = gimple_build_assign (idx, NOP_EXPR, thr_num);
9258 : 14 : gimple_seq_add_stmt (end, g);
9259 : 14 : g = gimple_build_assign (num_thr_sz, PLUS_EXPR, idx,
9260 : 14 : build_one_cst (TREE_TYPE (idx)));
9261 : 14 : gimple_seq_add_stmt (end, g);
9262 : 14 : gimple_seq_add_stmt (end, gimple_build_goto (lab3));
9263 : 14 : gimple_seq_add_stmt (end, gimple_build_label (lab6));
9264 : : }
9265 : 281 : g = gimple_build_cond (NE_EXPR, thr_num, integer_zero_node, lab2, lab4);
9266 : 281 : gimple_seq_add_stmt (end, g);
9267 : 281 : gimple_seq_add_stmt (end, gimple_build_label (lab4));
9268 : : }
9269 : 1164 : if (code != OMP_PARALLEL)
9270 : : {
9271 : 1105 : t = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS);
9272 : 1105 : tree num_thr = create_tmp_var (integer_type_node);
9273 : 1105 : g = gimple_build_call (t, 0);
9274 : 1105 : gimple_call_set_lhs (g, num_thr);
9275 : 1105 : gimple_seq_add_stmt (end, g);
9276 : 1105 : g = gimple_build_assign (num_thr_sz, NOP_EXPR, num_thr);
9277 : 1105 : gimple_seq_add_stmt (end, g);
9278 : 1105 : if (cancellable)
9279 : 14 : gimple_seq_add_stmt (end, gimple_build_label (lab3));
9280 : : }
9281 : : else
9282 : : {
9283 : 59 : tree c = omp_find_clause (gimple_omp_parallel_clauses (ctx->stmt),
9284 : : OMP_CLAUSE__REDUCTEMP_);
9285 : 59 : t = fold_convert (pointer_sized_int_node, OMP_CLAUSE_DECL (c));
9286 : 59 : t = fold_convert (size_type_node, t);
9287 : 59 : gimplify_assign (num_thr_sz, t, end);
9288 : : }
9289 : 1164 : t = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (2),
9290 : : NULL_TREE, NULL_TREE);
9291 : 1164 : tree data = create_tmp_var (pointer_sized_int_node);
9292 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (data, t));
9293 : 1164 : if (code == OMP_TASKLOOP)
9294 : : {
9295 : 497 : lab7 = create_artificial_label (UNKNOWN_LOCATION);
9296 : 497 : g = gimple_build_cond (NE_EXPR, data,
9297 : : build_zero_cst (pointer_sized_int_node),
9298 : : lab1, lab7);
9299 : 497 : gimple_seq_add_stmt (end, g);
9300 : : }
9301 : 1164 : gimple_seq_add_stmt (end, gimple_build_label (lab1));
9302 : 1164 : tree ptr;
9303 : 1164 : if (TREE_CODE (TYPE_SIZE_UNIT (record_type)) == INTEGER_CST)
9304 : 1124 : ptr = create_tmp_var (build_pointer_type (record_type));
9305 : : else
9306 : 40 : ptr = create_tmp_var (ptr_type_node);
9307 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (ptr, NOP_EXPR, data));
9308 : :
9309 : 1164 : tree field = TYPE_FIELDS (record_type);
9310 : 1164 : cnt = 0;
9311 : 1164 : if (cancellable)
9312 : 14 : field = DECL_CHAIN (DECL_CHAIN (field));
9313 : 3492 : for (int pass = 0; pass < 2; pass++)
9314 : : {
9315 : 2328 : tree decl, type, next;
9316 : 2328 : for (tree c = clauses;
9317 : 3973 : omp_task_reduction_iterate (pass, code, ccode,
9318 : 1645 : &c, &decl, &type, &next); c = next)
9319 : : {
9320 : 1645 : tree var = decl, ref;
9321 : 1645 : if (TREE_CODE (decl) == MEM_REF)
9322 : : {
9323 : 485 : var = TREE_OPERAND (var, 0);
9324 : 485 : if (TREE_CODE (var) == POINTER_PLUS_EXPR)
9325 : 108 : var = TREE_OPERAND (var, 0);
9326 : 485 : tree v = var;
9327 : 485 : if (TREE_CODE (var) == ADDR_EXPR)
9328 : 310 : var = TREE_OPERAND (var, 0);
9329 : 175 : else if (INDIRECT_REF_P (var))
9330 : 4 : var = TREE_OPERAND (var, 0);
9331 : 485 : tree orig_var = var;
9332 : 485 : if (is_variable_sized (var))
9333 : : {
9334 : 31 : gcc_assert (DECL_HAS_VALUE_EXPR_P (var));
9335 : 31 : var = DECL_VALUE_EXPR (var);
9336 : 31 : gcc_assert (INDIRECT_REF_P (var));
9337 : 31 : var = TREE_OPERAND (var, 0);
9338 : 31 : gcc_assert (DECL_P (var));
9339 : : }
9340 : 485 : t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx);
9341 : 485 : if (orig_var != var)
9342 : 31 : gcc_assert (TREE_CODE (v) == ADDR_EXPR);
9343 : 454 : else if (TREE_CODE (v) == ADDR_EXPR)
9344 : 279 : t = build_fold_addr_expr (t);
9345 : 175 : else if (INDIRECT_REF_P (v))
9346 : 4 : t = build_fold_indirect_ref (t);
9347 : 485 : if (TREE_CODE (TREE_OPERAND (decl, 0)) == POINTER_PLUS_EXPR)
9348 : : {
9349 : 108 : tree b = TREE_OPERAND (TREE_OPERAND (decl, 0), 1);
9350 : 108 : b = maybe_lookup_decl_in_outer_ctx (b, ctx);
9351 : 108 : t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t, b);
9352 : : }
9353 : 485 : if (!integer_zerop (TREE_OPERAND (decl, 1)))
9354 : 219 : t = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (t), t,
9355 : : fold_convert (size_type_node,
9356 : : TREE_OPERAND (decl, 1)));
9357 : : }
9358 : : else
9359 : : {
9360 : 1160 : t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx);
9361 : 1160 : if (!omp_privatize_by_reference (decl))
9362 : 1122 : t = build_fold_addr_expr (t);
9363 : : }
9364 : 1645 : t = fold_convert (pointer_sized_int_node, t);
9365 : 1645 : seq = NULL;
9366 : 1645 : t = force_gimple_operand (t, &seq, true, NULL_TREE);
9367 : 1645 : gimple_seq_add_seq (start, seq);
9368 : 1645 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar,
9369 : 1645 : size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
9370 : 1645 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9371 : 1645 : t = unshare_expr (byte_position (field));
9372 : 1645 : t = fold_convert (pointer_sized_int_node, t);
9373 : 1645 : ctx->task_reduction_map->put (c, cnt);
9374 : 3290 : ctx->task_reductions.quick_push (TREE_CODE (t) == INTEGER_CST
9375 : 2017 : ? t : NULL_TREE);
9376 : 1645 : seq = NULL;
9377 : 1645 : t = force_gimple_operand (t, &seq, true, NULL_TREE);
9378 : 1645 : gimple_seq_add_seq (start, seq);
9379 : 1645 : r = build4 (ARRAY_REF, pointer_sized_int_node, avar,
9380 : 1645 : size_int (7 + cnt * 3 + 1), NULL_TREE, NULL_TREE);
9381 : 1645 : gimple_seq_add_stmt (start, gimple_build_assign (r, t));
9382 : :
9383 : 1645 : tree bfield = DECL_CHAIN (field);
9384 : 1645 : tree cond;
9385 : 1645 : if (code == OMP_PARALLEL
9386 : 1645 : || code == OMP_FOR
9387 : : || code == OMP_SECTIONS
9388 : : || code == OMP_SCOPE)
9389 : : /* In parallel, worksharing or scope all threads unconditionally
9390 : : initialize all their task reduction private variables. */
9391 : 547 : cond = boolean_true_node;
9392 : 1098 : else if (TREE_TYPE (ptr) == ptr_type_node)
9393 : : {
9394 : 261 : cond = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr,
9395 : : unshare_expr (byte_position (bfield)));
9396 : 261 : seq = NULL;
9397 : 261 : cond = force_gimple_operand (cond, &seq, true, NULL_TREE);
9398 : 261 : gimple_seq_add_seq (end, seq);
9399 : 261 : tree pbool = build_pointer_type (TREE_TYPE (bfield));
9400 : 261 : cond = build2 (MEM_REF, TREE_TYPE (bfield), cond,
9401 : : build_int_cst (pbool, 0));
9402 : : }
9403 : : else
9404 : 837 : cond = build3 (COMPONENT_REF, TREE_TYPE (bfield),
9405 : : build_simple_mem_ref (ptr), bfield, NULL_TREE);
9406 : 1645 : tree lab3 = create_artificial_label (UNKNOWN_LOCATION);
9407 : 1645 : tree lab4 = create_artificial_label (UNKNOWN_LOCATION);
9408 : 1645 : tree condv = create_tmp_var (boolean_type_node);
9409 : 1645 : gimple_seq_add_stmt (end, gimple_build_assign (condv, cond));
9410 : 1645 : g = gimple_build_cond (NE_EXPR, condv, boolean_false_node,
9411 : : lab3, lab4);
9412 : 1645 : gimple_seq_add_stmt (end, g);
9413 : 1645 : gimple_seq_add_stmt (end, gimple_build_label (lab3));
9414 : 1645 : if (cancellable && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE)
9415 : : {
9416 : : /* If this reduction doesn't need destruction and parallel
9417 : : has been cancelled, there is nothing to do for this
9418 : : reduction, so jump around the merge operation. */
9419 : 18 : tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
9420 : 18 : g = gimple_build_cond (NE_EXPR, cancellable,
9421 : 18 : build_zero_cst (TREE_TYPE (cancellable)),
9422 : : lab4, lab5);
9423 : 18 : gimple_seq_add_stmt (end, g);
9424 : 18 : gimple_seq_add_stmt (end, gimple_build_label (lab5));
9425 : : }
9426 : :
9427 : 1645 : tree new_var;
9428 : 1645 : if (TREE_TYPE (ptr) == ptr_type_node)
9429 : : {
9430 : 428 : new_var = build2 (POINTER_PLUS_EXPR, ptr_type_node, ptr,
9431 : : unshare_expr (byte_position (field)));
9432 : 428 : seq = NULL;
9433 : 428 : new_var = force_gimple_operand (new_var, &seq, true, NULL_TREE);
9434 : 428 : gimple_seq_add_seq (end, seq);
9435 : 428 : tree pbool = build_pointer_type (TREE_TYPE (field));
9436 : 428 : new_var = build2 (MEM_REF, TREE_TYPE (field), new_var,
9437 : : build_int_cst (pbool, 0));
9438 : : }
9439 : : else
9440 : 1217 : new_var = build3 (COMPONENT_REF, TREE_TYPE (field),
9441 : : build_simple_mem_ref (ptr), field, NULL_TREE);
9442 : :
9443 : 1645 : enum tree_code rcode = OMP_CLAUSE_REDUCTION_CODE (c);
9444 : 1645 : if (TREE_CODE (decl) != MEM_REF
9445 : 1645 : && omp_privatize_by_reference (decl))
9446 : 38 : ref = build_simple_mem_ref (ref);
9447 : : /* reduction(-:var) sums up the partial results, so it acts
9448 : : identically to reduction(+:var). */
9449 : 1645 : if (rcode == MINUS_EXPR)
9450 : 0 : rcode = PLUS_EXPR;
9451 : 1645 : if (TREE_CODE (decl) == MEM_REF)
9452 : : {
9453 : 485 : tree type = TREE_TYPE (new_var);
9454 : 485 : tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
9455 : 485 : tree i = create_tmp_var (TREE_TYPE (v));
9456 : 485 : tree ptype = build_pointer_type (TREE_TYPE (type));
9457 : 485 : if (DECL_P (v))
9458 : : {
9459 : 142 : v = maybe_lookup_decl_in_outer_ctx (v, ctx);
9460 : 142 : tree vv = create_tmp_var (TREE_TYPE (v));
9461 : 142 : gimplify_assign (vv, v, start);
9462 : 142 : v = vv;
9463 : : }
9464 : 485 : ref = build4 (ARRAY_REF, pointer_sized_int_node, avar,
9465 : 485 : size_int (7 + cnt * 3), NULL_TREE, NULL_TREE);
9466 : 485 : new_var = build_fold_addr_expr (new_var);
9467 : 485 : new_var = fold_convert (ptype, new_var);
9468 : 485 : ref = fold_convert (ptype, ref);
9469 : 485 : tree m = create_tmp_var (ptype);
9470 : 485 : gimplify_assign (m, new_var, end);
9471 : 485 : new_var = m;
9472 : 485 : m = create_tmp_var (ptype);
9473 : 485 : gimplify_assign (m, ref, end);
9474 : 485 : ref = m;
9475 : 485 : gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), end);
9476 : 485 : tree body = create_artificial_label (UNKNOWN_LOCATION);
9477 : 485 : tree endl = create_artificial_label (UNKNOWN_LOCATION);
9478 : 485 : gimple_seq_add_stmt (end, gimple_build_label (body));
9479 : 485 : tree priv = build_simple_mem_ref (new_var);
9480 : 485 : tree out = build_simple_mem_ref (ref);
9481 : 485 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
9482 : : {
9483 : 161 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
9484 : 161 : tree decl_placeholder
9485 : 161 : = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c);
9486 : 161 : tree lab6 = NULL_TREE;
9487 : 161 : if (cancellable)
9488 : : {
9489 : : /* If this reduction needs destruction and parallel
9490 : : has been cancelled, jump around the merge operation
9491 : : to the destruction. */
9492 : 4 : tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
9493 : 4 : lab6 = create_artificial_label (UNKNOWN_LOCATION);
9494 : 4 : tree zero = build_zero_cst (TREE_TYPE (cancellable));
9495 : 4 : g = gimple_build_cond (NE_EXPR, cancellable, zero,
9496 : : lab6, lab5);
9497 : 4 : gimple_seq_add_stmt (end, g);
9498 : 4 : gimple_seq_add_stmt (end, gimple_build_label (lab5));
9499 : : }
9500 : 161 : SET_DECL_VALUE_EXPR (placeholder, out);
9501 : 161 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
9502 : 161 : SET_DECL_VALUE_EXPR (decl_placeholder, priv);
9503 : 161 : DECL_HAS_VALUE_EXPR_P (decl_placeholder) = 1;
9504 : 161 : lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
9505 : 322 : gimple_seq_add_seq (end,
9506 : 161 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
9507 : 161 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
9508 : 161 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
9509 : : {
9510 : 56 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
9511 : 56 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = NULL;
9512 : : }
9513 : 161 : if (cancellable)
9514 : 4 : gimple_seq_add_stmt (end, gimple_build_label (lab6));
9515 : 161 : tree x = lang_hooks.decls.omp_clause_dtor (c, priv);
9516 : 161 : if (x)
9517 : : {
9518 : 137 : gimple_seq tseq = NULL;
9519 : 137 : gimplify_stmt (&x, &tseq);
9520 : 137 : gimple_seq_add_seq (end, tseq);
9521 : : }
9522 : : }
9523 : : else
9524 : : {
9525 : 324 : tree x = build2 (rcode, TREE_TYPE (out), out, priv);
9526 : 324 : out = unshare_expr (out);
9527 : 324 : gimplify_assign (out, x, end);
9528 : : }
9529 : 485 : gimple *g
9530 : 485 : = gimple_build_assign (new_var, POINTER_PLUS_EXPR, new_var,
9531 : 485 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
9532 : 485 : gimple_seq_add_stmt (end, g);
9533 : 485 : g = gimple_build_assign (ref, POINTER_PLUS_EXPR, ref,
9534 : 485 : TYPE_SIZE_UNIT (TREE_TYPE (type)));
9535 : 485 : gimple_seq_add_stmt (end, g);
9536 : 485 : g = gimple_build_assign (i, PLUS_EXPR, i,
9537 : 485 : build_int_cst (TREE_TYPE (i), 1));
9538 : 485 : gimple_seq_add_stmt (end, g);
9539 : 485 : g = gimple_build_cond (LE_EXPR, i, v, body, endl);
9540 : 485 : gimple_seq_add_stmt (end, g);
9541 : 485 : gimple_seq_add_stmt (end, gimple_build_label (endl));
9542 : : }
9543 : 1160 : else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
9544 : : {
9545 : 126 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
9546 : 126 : tree oldv = NULL_TREE;
9547 : 126 : tree lab6 = NULL_TREE;
9548 : 126 : if (cancellable)
9549 : : {
9550 : : /* If this reduction needs destruction and parallel
9551 : : has been cancelled, jump around the merge operation
9552 : : to the destruction. */
9553 : 4 : tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
9554 : 4 : lab6 = create_artificial_label (UNKNOWN_LOCATION);
9555 : 4 : tree zero = build_zero_cst (TREE_TYPE (cancellable));
9556 : 4 : g = gimple_build_cond (NE_EXPR, cancellable, zero,
9557 : : lab6, lab5);
9558 : 4 : gimple_seq_add_stmt (end, g);
9559 : 4 : gimple_seq_add_stmt (end, gimple_build_label (lab5));
9560 : : }
9561 : 126 : if (omp_privatize_by_reference (decl)
9562 : 136 : && !useless_type_conversion_p (TREE_TYPE (placeholder),
9563 : 10 : TREE_TYPE (ref)))
9564 : 0 : ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref);
9565 : 126 : ref = build_fold_addr_expr_loc (OMP_CLAUSE_LOCATION (c), ref);
9566 : 126 : tree refv = create_tmp_var (TREE_TYPE (ref));
9567 : 126 : gimplify_assign (refv, ref, end);
9568 : 126 : ref = build_simple_mem_ref_loc (OMP_CLAUSE_LOCATION (c), refv);
9569 : 126 : SET_DECL_VALUE_EXPR (placeholder, ref);
9570 : 126 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
9571 : 126 : tree d = maybe_lookup_decl (decl, ctx);
9572 : 126 : gcc_assert (d);
9573 : 126 : if (DECL_HAS_VALUE_EXPR_P (d))
9574 : 7 : oldv = DECL_VALUE_EXPR (d);
9575 : 126 : if (omp_privatize_by_reference (var))
9576 : : {
9577 : 10 : tree v = fold_convert (TREE_TYPE (d),
9578 : : build_fold_addr_expr (new_var));
9579 : 10 : SET_DECL_VALUE_EXPR (d, v);
9580 : : }
9581 : : else
9582 : 116 : SET_DECL_VALUE_EXPR (d, new_var);
9583 : 126 : DECL_HAS_VALUE_EXPR_P (d) = 1;
9584 : 126 : lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c), ctx);
9585 : 126 : if (oldv)
9586 : 7 : SET_DECL_VALUE_EXPR (d, oldv);
9587 : : else
9588 : : {
9589 : 119 : SET_DECL_VALUE_EXPR (d, NULL_TREE);
9590 : 119 : DECL_HAS_VALUE_EXPR_P (d) = 0;
9591 : : }
9592 : 126 : gimple_seq_add_seq (end, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c));
9593 : 126 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
9594 : 126 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
9595 : 24 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL;
9596 : 126 : if (cancellable)
9597 : 4 : gimple_seq_add_stmt (end, gimple_build_label (lab6));
9598 : 126 : tree x = lang_hooks.decls.omp_clause_dtor (c, new_var);
9599 : 126 : if (x)
9600 : : {
9601 : 28 : gimple_seq tseq = NULL;
9602 : 28 : gimplify_stmt (&x, &tseq);
9603 : 28 : gimple_seq_add_seq (end, tseq);
9604 : : }
9605 : : }
9606 : : else
9607 : : {
9608 : 1034 : tree x = build2 (rcode, TREE_TYPE (ref), ref, new_var);
9609 : 1034 : ref = unshare_expr (ref);
9610 : 1034 : gimplify_assign (ref, x, end);
9611 : : }
9612 : 1645 : gimple_seq_add_stmt (end, gimple_build_label (lab4));
9613 : 1645 : ++cnt;
9614 : 1645 : field = DECL_CHAIN (bfield);
9615 : : }
9616 : : }
9617 : :
9618 : 1164 : if (code == OMP_TASKGROUP)
9619 : : {
9620 : 327 : t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_REGISTER);
9621 : 327 : g = gimple_build_call (t, 1, build_fold_addr_expr (avar));
9622 : 327 : gimple_seq_add_stmt (start, g);
9623 : : }
9624 : : else
9625 : : {
9626 : 837 : tree c;
9627 : 837 : if (code == OMP_FOR)
9628 : 227 : c = gimple_omp_for_clauses (ctx->stmt);
9629 : 610 : else if (code == OMP_SECTIONS)
9630 : 8 : c = gimple_omp_sections_clauses (ctx->stmt);
9631 : 602 : else if (code == OMP_SCOPE)
9632 : 46 : c = gimple_omp_scope_clauses (ctx->stmt);
9633 : : else
9634 : 556 : c = gimple_omp_taskreg_clauses (ctx->stmt);
9635 : 837 : c = omp_find_clause (c, OMP_CLAUSE__REDUCTEMP_);
9636 : 837 : t = fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c)),
9637 : : build_fold_addr_expr (avar));
9638 : 837 : gimplify_assign (OMP_CLAUSE_DECL (c), t, start);
9639 : : }
9640 : :
9641 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (data, PLUS_EXPR, data, sz));
9642 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (idx, PLUS_EXPR, idx,
9643 : : size_one_node));
9644 : 1164 : g = gimple_build_cond (NE_EXPR, idx, num_thr_sz, lab1, lab2);
9645 : 1164 : gimple_seq_add_stmt (end, g);
9646 : 1164 : gimple_seq_add_stmt (end, gimple_build_label (lab2));
9647 : 1164 : if (code == OMP_FOR || code == OMP_SECTIONS || code == OMP_SCOPE)
9648 : : {
9649 : 281 : enum built_in_function bfn
9650 : : = BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER;
9651 : 281 : t = builtin_decl_explicit (bfn);
9652 : 281 : tree c_bool_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (t)));
9653 : 281 : tree arg;
9654 : 281 : if (cancellable)
9655 : : {
9656 : 14 : arg = create_tmp_var (c_bool_type);
9657 : 14 : gimple_seq_add_stmt (end, gimple_build_assign (arg, NOP_EXPR,
9658 : : cancellable));
9659 : : }
9660 : : else
9661 : 267 : arg = build_int_cst (c_bool_type, 0);
9662 : 281 : g = gimple_build_call (t, 1, arg);
9663 : 281 : }
9664 : : else
9665 : : {
9666 : 883 : t = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_REDUCTION_UNREGISTER);
9667 : 883 : g = gimple_build_call (t, 1, build_fold_addr_expr (avar));
9668 : : }
9669 : 1164 : gimple_seq_add_stmt (end, g);
9670 : 1164 : if (lab7)
9671 : 497 : gimple_seq_add_stmt (end, gimple_build_label (lab7));
9672 : 1164 : t = build_constructor (atype, NULL);
9673 : 1164 : TREE_THIS_VOLATILE (t) = 1;
9674 : 1164 : gimple_seq_add_stmt (end, gimple_build_assign (avar, t));
9675 : : }
9676 : :
9677 : : /* Expand code for an OpenMP taskgroup directive. */
9678 : :
9679 : : static void
9680 : 536 : lower_omp_taskgroup (gimple_stmt_iterator *gsi_p, omp_context *ctx)
9681 : : {
9682 : 536 : gimple *stmt = gsi_stmt (*gsi_p);
9683 : 536 : gcall *x;
9684 : 536 : gbind *bind;
9685 : 536 : gimple_seq dseq = NULL;
9686 : 536 : tree block = make_node (BLOCK);
9687 : :
9688 : 536 : bind = gimple_build_bind (NULL, NULL, block);
9689 : 536 : gsi_replace (gsi_p, bind, true);
9690 : 536 : gimple_bind_add_stmt (bind, stmt);
9691 : :
9692 : 536 : push_gimplify_context ();
9693 : :
9694 : 536 : x = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_START),
9695 : : 0);
9696 : 536 : gimple_bind_add_stmt (bind, x);
9697 : :
9698 : 536 : lower_omp_task_reductions (ctx, OMP_TASKGROUP,
9699 : : gimple_omp_taskgroup_clauses (stmt),
9700 : : gimple_bind_body_ptr (bind), &dseq);
9701 : :
9702 : 536 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
9703 : 536 : gimple_bind_add_seq (bind, gimple_omp_body (stmt));
9704 : 536 : gimple_omp_set_body (stmt, NULL);
9705 : :
9706 : 536 : gimple_bind_add_seq (bind, dseq);
9707 : :
9708 : 536 : pop_gimplify_context (bind);
9709 : :
9710 : 536 : gimple_bind_append_vars (bind, ctx->block_vars);
9711 : 536 : BLOCK_VARS (block) = ctx->block_vars;
9712 : 536 : }
9713 : :
9714 : :
9715 : : /* Fold the OMP_ORDERED_CLAUSES for the OMP_ORDERED in STMT if possible. */
9716 : :
9717 : : static void
9718 : 0 : lower_omp_ordered_clauses (gimple_stmt_iterator *gsi_p, gomp_ordered *ord_stmt,
9719 : : omp_context *ctx)
9720 : : {
9721 : 0 : struct omp_for_data fd;
9722 : 0 : if (!ctx->outer || gimple_code (ctx->outer->stmt) != GIMPLE_OMP_FOR)
9723 : 0 : return;
9724 : :
9725 : 0 : unsigned int len = gimple_omp_for_collapse (ctx->outer->stmt);
9726 : 0 : struct omp_for_data_loop *loops = XALLOCAVEC (struct omp_for_data_loop, len);
9727 : 0 : omp_extract_for_data (as_a <gomp_for *> (ctx->outer->stmt), &fd, loops);
9728 : 0 : if (!fd.ordered)
9729 : : return;
9730 : :
9731 : 0 : tree *list_p = gimple_omp_ordered_clauses_ptr (ord_stmt);
9732 : 0 : tree c = gimple_omp_ordered_clauses (ord_stmt);
9733 : 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS
9734 : 0 : && OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
9735 : : {
9736 : : /* Merge depend clauses from multiple adjacent
9737 : : #pragma omp ordered depend(sink:...) constructs
9738 : : into one #pragma omp ordered depend(sink:...), so that
9739 : : we can optimize them together. */
9740 : 0 : gimple_stmt_iterator gsi = *gsi_p;
9741 : 0 : gsi_next (&gsi);
9742 : 0 : while (!gsi_end_p (gsi))
9743 : : {
9744 : 0 : gimple *stmt = gsi_stmt (gsi);
9745 : 0 : if (is_gimple_debug (stmt)
9746 : 0 : || gimple_code (stmt) == GIMPLE_NOP)
9747 : : {
9748 : 0 : gsi_next (&gsi);
9749 : 0 : continue;
9750 : : }
9751 : 0 : if (gimple_code (stmt) != GIMPLE_OMP_ORDERED)
9752 : : break;
9753 : 0 : gomp_ordered *ord_stmt2 = as_a <gomp_ordered *> (stmt);
9754 : 0 : c = gimple_omp_ordered_clauses (ord_stmt2);
9755 : 0 : if (c == NULL_TREE
9756 : 0 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DOACROSS
9757 : 0 : || OMP_CLAUSE_DOACROSS_KIND (c) != OMP_CLAUSE_DOACROSS_SINK)
9758 : : break;
9759 : 0 : while (*list_p)
9760 : 0 : list_p = &OMP_CLAUSE_CHAIN (*list_p);
9761 : 0 : *list_p = c;
9762 : 0 : gsi_remove (&gsi, true);
9763 : : }
9764 : : }
9765 : :
9766 : : /* Canonicalize sink dependence clauses into one folded clause if
9767 : : possible.
9768 : :
9769 : : The basic algorithm is to create a sink vector whose first
9770 : : element is the GCD of all the first elements, and whose remaining
9771 : : elements are the minimum of the subsequent columns.
9772 : :
9773 : : We ignore dependence vectors whose first element is zero because
9774 : : such dependencies are known to be executed by the same thread.
9775 : :
9776 : : We take into account the direction of the loop, so a minimum
9777 : : becomes a maximum if the loop is iterating forwards. We also
9778 : : ignore sink clauses where the loop direction is unknown, or where
9779 : : the offsets are clearly invalid because they are not a multiple
9780 : : of the loop increment.
9781 : :
9782 : : For example:
9783 : :
9784 : : #pragma omp for ordered(2)
9785 : : for (i=0; i < N; ++i)
9786 : : for (j=0; j < M; ++j)
9787 : : {
9788 : : #pragma omp ordered \
9789 : : depend(sink:i-8,j-2) \
9790 : : depend(sink:i,j-1) \ // Completely ignored because i+0.
9791 : : depend(sink:i-4,j-3) \
9792 : : depend(sink:i-6,j-4)
9793 : : #pragma omp ordered depend(source)
9794 : : }
9795 : :
9796 : : Folded clause is:
9797 : :
9798 : : depend(sink:-gcd(8,4,6),-min(2,3,4))
9799 : : -or-
9800 : : depend(sink:-2,-2)
9801 : : */
9802 : :
9803 : : /* FIXME: Computing GCD's where the first element is zero is
9804 : : non-trivial in the presence of collapsed loops. Do this later. */
9805 : 0 : if (fd.collapse > 1)
9806 : : return;
9807 : :
9808 : 0 : wide_int *folded_deps = XALLOCAVEC (wide_int, 2 * len - 1);
9809 : :
9810 : : /* wide_int is not a POD so it must be default-constructed. */
9811 : 0 : for (unsigned i = 0; i != 2 * len - 1; ++i)
9812 : 0 : new (static_cast<void*>(folded_deps + i)) wide_int ();
9813 : :
9814 : : tree folded_dep = NULL_TREE;
9815 : : /* TRUE if the first dimension's offset is negative. */
9816 : : bool neg_offset_p = false;
9817 : :
9818 : : list_p = gimple_omp_ordered_clauses_ptr (ord_stmt);
9819 : : unsigned int i;
9820 : 0 : while ((c = *list_p) != NULL)
9821 : : {
9822 : 0 : bool remove = false;
9823 : :
9824 : 0 : gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS);
9825 : 0 : if (OMP_CLAUSE_DOACROSS_KIND (c) != OMP_CLAUSE_DOACROSS_SINK)
9826 : 0 : goto next_ordered_clause;
9827 : :
9828 : 0 : tree vec;
9829 : 0 : for (vec = OMP_CLAUSE_DECL (c), i = 0;
9830 : 0 : vec && TREE_CODE (vec) == TREE_LIST;
9831 : 0 : vec = TREE_CHAIN (vec), ++i)
9832 : : {
9833 : 0 : gcc_assert (i < len);
9834 : :
9835 : : /* omp_extract_for_data has canonicalized the condition. */
9836 : 0 : gcc_assert (fd.loops[i].cond_code == LT_EXPR
9837 : : || fd.loops[i].cond_code == GT_EXPR);
9838 : 0 : bool forward = fd.loops[i].cond_code == LT_EXPR;
9839 : 0 : bool maybe_lexically_later = true;
9840 : :
9841 : : /* While the committee makes up its mind, bail if we have any
9842 : : non-constant steps. */
9843 : 0 : if (TREE_CODE (fd.loops[i].step) != INTEGER_CST)
9844 : 0 : goto lower_omp_ordered_ret;
9845 : :
9846 : 0 : tree itype = TREE_TYPE (TREE_VALUE (vec));
9847 : 0 : if (POINTER_TYPE_P (itype))
9848 : 0 : itype = sizetype;
9849 : 0 : wide_int offset = wide_int::from (wi::to_wide (TREE_PURPOSE (vec)),
9850 : 0 : TYPE_PRECISION (itype),
9851 : 0 : TYPE_SIGN (itype));
9852 : :
9853 : : /* Ignore invalid offsets that are not multiples of the step. */
9854 : 0 : if (!wi::multiple_of_p (wi::abs (offset),
9855 : 0 : wi::abs (wi::to_wide (fd.loops[i].step)),
9856 : : UNSIGNED))
9857 : : {
9858 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9859 : : "ignoring %<sink%> clause with offset that is not "
9860 : : "a multiple of the loop step");
9861 : 0 : remove = true;
9862 : 0 : goto next_ordered_clause;
9863 : : }
9864 : :
9865 : : /* Calculate the first dimension. The first dimension of
9866 : : the folded dependency vector is the GCD of the first
9867 : : elements, while ignoring any first elements whose offset
9868 : : is 0. */
9869 : 0 : if (i == 0)
9870 : : {
9871 : : /* Ignore dependence vectors whose first dimension is 0. */
9872 : 0 : if (offset == 0)
9873 : : {
9874 : 0 : remove = true;
9875 : 0 : goto next_ordered_clause;
9876 : : }
9877 : : else
9878 : : {
9879 : 0 : if (!TYPE_UNSIGNED (itype) && (forward ^ wi::neg_p (offset)))
9880 : : {
9881 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9882 : : "first offset must be in opposite direction "
9883 : : "of loop iterations");
9884 : 0 : goto lower_omp_ordered_ret;
9885 : : }
9886 : 0 : if (forward)
9887 : 0 : offset = -offset;
9888 : 0 : neg_offset_p = forward;
9889 : : /* Initialize the first time around. */
9890 : 0 : if (folded_dep == NULL_TREE)
9891 : : {
9892 : 0 : folded_dep = c;
9893 : 0 : folded_deps[0] = offset;
9894 : : }
9895 : : else
9896 : 0 : folded_deps[0] = wi::gcd (folded_deps[0],
9897 : 0 : offset, UNSIGNED);
9898 : : }
9899 : : }
9900 : : /* Calculate minimum for the remaining dimensions. */
9901 : : else
9902 : : {
9903 : 0 : folded_deps[len + i - 1] = offset;
9904 : 0 : if (folded_dep == c)
9905 : 0 : folded_deps[i] = offset;
9906 : 0 : else if (maybe_lexically_later
9907 : 0 : && !wi::eq_p (folded_deps[i], offset))
9908 : : {
9909 : 0 : if (forward ^ wi::gts_p (folded_deps[i], offset))
9910 : : {
9911 : : unsigned int j;
9912 : 0 : folded_dep = c;
9913 : 0 : for (j = 1; j <= i; j++)
9914 : 0 : folded_deps[j] = folded_deps[len + j - 1];
9915 : : }
9916 : : else
9917 : 0 : maybe_lexically_later = false;
9918 : : }
9919 : : }
9920 : 0 : }
9921 : 0 : gcc_assert (i == len);
9922 : :
9923 : : remove = true;
9924 : :
9925 : 0 : next_ordered_clause:
9926 : 0 : if (remove)
9927 : 0 : *list_p = OMP_CLAUSE_CHAIN (c);
9928 : : else
9929 : 0 : list_p = &OMP_CLAUSE_CHAIN (c);
9930 : : }
9931 : :
9932 : 0 : if (folded_dep)
9933 : : {
9934 : 0 : if (neg_offset_p)
9935 : 0 : folded_deps[0] = -folded_deps[0];
9936 : :
9937 : 0 : tree itype = TREE_TYPE (TREE_VALUE (OMP_CLAUSE_DECL (folded_dep)));
9938 : 0 : if (POINTER_TYPE_P (itype))
9939 : 0 : itype = sizetype;
9940 : :
9941 : 0 : TREE_PURPOSE (OMP_CLAUSE_DECL (folded_dep))
9942 : 0 : = wide_int_to_tree (itype, folded_deps[0]);
9943 : 0 : OMP_CLAUSE_CHAIN (folded_dep) = gimple_omp_ordered_clauses (ord_stmt);
9944 : 0 : *gimple_omp_ordered_clauses_ptr (ord_stmt) = folded_dep;
9945 : : }
9946 : :
9947 : 0 : lower_omp_ordered_ret:
9948 : :
9949 : : /* Ordered without clauses is #pragma omp threads, while we want
9950 : : a nop instead if we remove all clauses. */
9951 : 0 : if (gimple_omp_ordered_clauses (ord_stmt) == NULL_TREE)
9952 : 0 : gsi_replace (gsi_p, gimple_build_nop (), true);
9953 : : }
9954 : :
9955 : :
9956 : : /* Expand code for an OpenMP ordered directive. */
9957 : :
9958 : : static void
9959 : 1124 : lower_omp_ordered (gimple_stmt_iterator *gsi_p, omp_context *ctx)
9960 : : {
9961 : 1124 : tree block;
9962 : 1124 : gimple *stmt = gsi_stmt (*gsi_p), *g;
9963 : 1124 : gomp_ordered *ord_stmt = as_a <gomp_ordered *> (stmt);
9964 : 1124 : gcall *x;
9965 : 1124 : gbind *bind;
9966 : 1124 : bool simd = omp_find_clause (gimple_omp_ordered_clauses (ord_stmt),
9967 : 1124 : OMP_CLAUSE_SIMD);
9968 : : /* FIXME: this should check presence of OMP_CLAUSE__SIMT_ on the enclosing
9969 : : loop. */
9970 : 1124 : bool maybe_simt
9971 : 1124 : = simd && omp_maybe_offloaded_ctx (ctx) && omp_max_simt_vf () > 1;
9972 : 1124 : bool threads = omp_find_clause (gimple_omp_ordered_clauses (ord_stmt),
9973 : 1124 : OMP_CLAUSE_THREADS);
9974 : :
9975 : 1124 : if (gimple_omp_ordered_standalone_p (ord_stmt))
9976 : : {
9977 : : /* FIXME: This is needs to be moved to the expansion to verify various
9978 : : conditions only testable on cfg with dominators computed, and also
9979 : : all the depend clauses to be merged still might need to be available
9980 : : for the runtime checks. */
9981 : : if (0)
9982 : : lower_omp_ordered_clauses (gsi_p, ord_stmt, ctx);
9983 : 1124 : return;
9984 : : }
9985 : :
9986 : 411 : push_gimplify_context ();
9987 : :
9988 : 411 : block = make_node (BLOCK);
9989 : 411 : bind = gimple_build_bind (NULL, NULL, block);
9990 : 411 : gsi_replace (gsi_p, bind, true);
9991 : 411 : gimple_bind_add_stmt (bind, stmt);
9992 : :
9993 : 411 : if (simd)
9994 : : {
9995 : 79 : x = gimple_build_call_internal (IFN_GOMP_SIMD_ORDERED_START, 1,
9996 : 79 : build_int_cst (NULL_TREE, threads));
9997 : 79 : cfun->has_simduid_loops = true;
9998 : : }
9999 : : else
10000 : 332 : x = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ORDERED_START),
10001 : : 0);
10002 : 411 : gimple_bind_add_stmt (bind, x);
10003 : :
10004 : 411 : tree counter = NULL_TREE, test = NULL_TREE, body = NULL_TREE;
10005 : 411 : if (maybe_simt)
10006 : : {
10007 : 0 : counter = create_tmp_var (integer_type_node);
10008 : 0 : g = gimple_build_call_internal (IFN_GOMP_SIMT_LANE, 0);
10009 : 0 : gimple_call_set_lhs (g, counter);
10010 : 0 : gimple_bind_add_stmt (bind, g);
10011 : :
10012 : 0 : body = create_artificial_label (UNKNOWN_LOCATION);
10013 : 0 : test = create_artificial_label (UNKNOWN_LOCATION);
10014 : 0 : gimple_bind_add_stmt (bind, gimple_build_label (body));
10015 : :
10016 : 0 : tree simt_pred = create_tmp_var (integer_type_node);
10017 : 0 : g = gimple_build_call_internal (IFN_GOMP_SIMT_ORDERED_PRED, 1, counter);
10018 : 0 : gimple_call_set_lhs (g, simt_pred);
10019 : 0 : gimple_bind_add_stmt (bind, g);
10020 : :
10021 : 0 : tree t = create_artificial_label (UNKNOWN_LOCATION);
10022 : 0 : g = gimple_build_cond (EQ_EXPR, simt_pred, integer_zero_node, t, test);
10023 : 0 : gimple_bind_add_stmt (bind, g);
10024 : :
10025 : 0 : gimple_bind_add_stmt (bind, gimple_build_label (t));
10026 : : }
10027 : 411 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
10028 : 411 : gimple_omp_set_body (stmt, maybe_catch_exception (gimple_omp_body (stmt)));
10029 : 411 : gimple_bind_add_seq (bind, gimple_omp_body (stmt));
10030 : 411 : gimple_omp_set_body (stmt, NULL);
10031 : :
10032 : 411 : if (maybe_simt)
10033 : : {
10034 : 0 : gimple_bind_add_stmt (bind, gimple_build_label (test));
10035 : 0 : g = gimple_build_assign (counter, MINUS_EXPR, counter, integer_one_node);
10036 : 0 : gimple_bind_add_stmt (bind, g);
10037 : :
10038 : 0 : tree c = build2 (GE_EXPR, boolean_type_node, counter, integer_zero_node);
10039 : 0 : tree nonneg = create_tmp_var (integer_type_node);
10040 : 0 : gimple_seq tseq = NULL;
10041 : 0 : gimplify_assign (nonneg, fold_convert (integer_type_node, c), &tseq);
10042 : 0 : gimple_bind_add_seq (bind, tseq);
10043 : :
10044 : 0 : g = gimple_build_call_internal (IFN_GOMP_SIMT_VOTE_ANY, 1, nonneg);
10045 : 0 : gimple_call_set_lhs (g, nonneg);
10046 : 0 : gimple_bind_add_stmt (bind, g);
10047 : :
10048 : 0 : tree end = create_artificial_label (UNKNOWN_LOCATION);
10049 : 0 : g = gimple_build_cond (NE_EXPR, nonneg, integer_zero_node, body, end);
10050 : 0 : gimple_bind_add_stmt (bind, g);
10051 : :
10052 : 0 : gimple_bind_add_stmt (bind, gimple_build_label (end));
10053 : : }
10054 : 411 : if (simd)
10055 : 79 : x = gimple_build_call_internal (IFN_GOMP_SIMD_ORDERED_END, 1,
10056 : 79 : build_int_cst (NULL_TREE, threads));
10057 : : else
10058 : 332 : x = gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ORDERED_END),
10059 : : 0);
10060 : 411 : gimple_bind_add_stmt (bind, x);
10061 : :
10062 : 411 : gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
10063 : :
10064 : 411 : pop_gimplify_context (bind);
10065 : :
10066 : 411 : gimple_bind_append_vars (bind, ctx->block_vars);
10067 : 411 : BLOCK_VARS (block) = gimple_bind_vars (bind);
10068 : : }
10069 : :
10070 : :
10071 : : /* Expand code for an OpenMP scan directive and the structured block
10072 : : before the scan directive. */
10073 : :
10074 : : static void
10075 : 1536 : lower_omp_scan (gimple_stmt_iterator *gsi_p, omp_context *ctx)
10076 : : {
10077 : 1536 : gimple *stmt = gsi_stmt (*gsi_p);
10078 : 1536 : bool has_clauses
10079 : 1536 : = gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt)) != NULL;
10080 : 1536 : tree lane = NULL_TREE;
10081 : 1536 : gimple_seq before = NULL;
10082 : 1536 : omp_context *octx = ctx->outer;
10083 : 1536 : gcc_assert (octx);
10084 : 1536 : if (octx->scan_exclusive && !has_clauses)
10085 : : {
10086 : 536 : gimple_stmt_iterator gsi2 = *gsi_p;
10087 : 536 : gsi_next (&gsi2);
10088 : 536 : gimple *stmt2 = gsi_stmt (gsi2);
10089 : : /* For exclusive scan, swap GIMPLE_OMP_SCAN without clauses
10090 : : with following GIMPLE_OMP_SCAN with clauses, so that input_phase,
10091 : : the one with exclusive clause(s), comes first. */
10092 : 536 : if (stmt2
10093 : 274 : && gimple_code (stmt2) == GIMPLE_OMP_SCAN
10094 : 804 : && gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt2)) != NULL)
10095 : : {
10096 : 268 : gsi_remove (gsi_p, false);
10097 : 268 : gsi_insert_after (gsi_p, stmt, GSI_SAME_STMT);
10098 : 268 : ctx = maybe_lookup_ctx (stmt2);
10099 : 268 : gcc_assert (ctx);
10100 : 268 : lower_omp_scan (gsi_p, ctx);
10101 : 268 : return;
10102 : : }
10103 : : }
10104 : :
10105 : 1268 : bool input_phase = has_clauses ^ octx->scan_inclusive;
10106 : 1268 : bool is_simd = (gimple_code (octx->stmt) == GIMPLE_OMP_FOR
10107 : 1268 : && gimple_omp_for_kind (octx->stmt) == GF_OMP_FOR_KIND_SIMD);
10108 : 1268 : bool is_for = (gimple_code (octx->stmt) == GIMPLE_OMP_FOR
10109 : 1268 : && gimple_omp_for_kind (octx->stmt) == GF_OMP_FOR_KIND_FOR
10110 : 1614 : && !gimple_omp_for_combined_p (octx->stmt));
10111 : 1268 : bool is_for_simd = is_simd && gimple_omp_for_combined_into_p (octx->stmt);
10112 : 332 : if (is_for_simd && octx->for_simd_scan_phase)
10113 : : is_simd = false;
10114 : 1102 : if (is_simd)
10115 : 756 : if (tree c = omp_find_clause (gimple_omp_for_clauses (octx->stmt),
10116 : : OMP_CLAUSE__SIMDUID_))
10117 : : {
10118 : 368 : tree uid = OMP_CLAUSE__SIMDUID__DECL (c);
10119 : 368 : lane = create_tmp_var (unsigned_type_node);
10120 : 368 : tree t = build_int_cst (integer_type_node,
10121 : 552 : input_phase ? 1
10122 : 184 : : octx->scan_inclusive ? 2 : 3);
10123 : 368 : gimple *g
10124 : 368 : = gimple_build_call_internal (IFN_GOMP_SIMD_LANE, 2, uid, t);
10125 : 368 : gimple_call_set_lhs (g, lane);
10126 : 368 : gimple_seq_add_stmt (&before, g);
10127 : : }
10128 : :
10129 : 1268 : if (is_simd || is_for)
10130 : : {
10131 : 4980 : for (tree c = gimple_omp_for_clauses (octx->stmt);
10132 : 4980 : c; c = OMP_CLAUSE_CHAIN (c))
10133 : 4044 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10134 : 4044 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
10135 : : {
10136 : 1160 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
10137 : 1160 : tree var = OMP_CLAUSE_DECL (c);
10138 : 1160 : tree new_var = lookup_decl (var, octx);
10139 : 1160 : tree val = new_var;
10140 : 1160 : tree var2 = NULL_TREE;
10141 : 1160 : tree var3 = NULL_TREE;
10142 : 1160 : tree var4 = NULL_TREE;
10143 : 1160 : tree lane0 = NULL_TREE;
10144 : 1160 : tree new_vard = new_var;
10145 : 1160 : if (omp_privatize_by_reference (var))
10146 : : {
10147 : 184 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
10148 : 184 : val = new_var;
10149 : : }
10150 : 1160 : if (DECL_HAS_VALUE_EXPR_P (new_vard))
10151 : : {
10152 : 464 : val = DECL_VALUE_EXPR (new_vard);
10153 : 464 : if (new_vard != new_var)
10154 : : {
10155 : 76 : gcc_assert (TREE_CODE (val) == ADDR_EXPR);
10156 : 76 : val = TREE_OPERAND (val, 0);
10157 : : }
10158 : 464 : if (TREE_CODE (val) == ARRAY_REF
10159 : 464 : && VAR_P (TREE_OPERAND (val, 0)))
10160 : : {
10161 : 464 : tree v = TREE_OPERAND (val, 0);
10162 : 464 : if (lookup_attribute ("omp simd array",
10163 : 464 : DECL_ATTRIBUTES (v)))
10164 : : {
10165 : 464 : val = unshare_expr (val);
10166 : 464 : lane0 = TREE_OPERAND (val, 1);
10167 : 464 : TREE_OPERAND (val, 1) = lane;
10168 : 464 : var2 = lookup_decl (v, octx);
10169 : 464 : if (octx->scan_exclusive)
10170 : 228 : var4 = lookup_decl (var2, octx);
10171 : 464 : if (input_phase
10172 : 464 : && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
10173 : 120 : var3 = maybe_lookup_decl (var4 ? var4 : var2, octx);
10174 : 464 : if (!input_phase)
10175 : : {
10176 : 232 : var2 = build4 (ARRAY_REF, TREE_TYPE (val),
10177 : : var2, lane, NULL_TREE, NULL_TREE);
10178 : 232 : TREE_THIS_NOTRAP (var2) = 1;
10179 : 232 : if (octx->scan_exclusive)
10180 : : {
10181 : 114 : var4 = build4 (ARRAY_REF, TREE_TYPE (val),
10182 : : var4, lane, NULL_TREE,
10183 : : NULL_TREE);
10184 : 114 : TREE_THIS_NOTRAP (var4) = 1;
10185 : : }
10186 : : }
10187 : : else
10188 : : var2 = val;
10189 : : }
10190 : : }
10191 : 464 : gcc_assert (var2);
10192 : : }
10193 : : else
10194 : : {
10195 : 696 : var2 = build_outer_var_ref (var, octx);
10196 : 696 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
10197 : : {
10198 : 220 : var3 = maybe_lookup_decl (new_vard, octx);
10199 : 220 : if (var3 == new_vard || var3 == NULL_TREE)
10200 : : var3 = NULL_TREE;
10201 : 108 : else if (is_simd && octx->scan_exclusive && !input_phase)
10202 : : {
10203 : 16 : var4 = maybe_lookup_decl (var3, octx);
10204 : 16 : if (var4 == var3 || var4 == NULL_TREE)
10205 : : {
10206 : 0 : if (TREE_ADDRESSABLE (TREE_TYPE (new_var)))
10207 : : {
10208 : : var4 = var3;
10209 : : var3 = NULL_TREE;
10210 : : }
10211 : : else
10212 : 16 : var4 = NULL_TREE;
10213 : : }
10214 : : }
10215 : : }
10216 : 664 : if (is_simd
10217 : 484 : && octx->scan_exclusive
10218 : 244 : && !input_phase
10219 : 244 : && var4 == NULL_TREE)
10220 : 106 : var4 = create_tmp_var (TREE_TYPE (val));
10221 : : }
10222 : 1160 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
10223 : : {
10224 : 376 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
10225 : 376 : if (input_phase)
10226 : : {
10227 : 188 : if (var3)
10228 : : {
10229 : : /* If we've added a separate identity element
10230 : : variable, copy it over into val. */
10231 : 92 : tree x = lang_hooks.decls.omp_clause_assign_op (c, val,
10232 : : var3);
10233 : 92 : gimplify_and_add (x, &before);
10234 : : }
10235 : 96 : else if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
10236 : : {
10237 : : /* Otherwise, assign to it the identity element. */
10238 : 96 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
10239 : 96 : if (is_for)
10240 : 16 : tseq = copy_gimple_seq_and_replace_locals (tseq);
10241 : 96 : tree ref = build_outer_var_ref (var, octx);
10242 : 96 : tree x = (DECL_HAS_VALUE_EXPR_P (new_vard)
10243 : 96 : ? DECL_VALUE_EXPR (new_vard) : NULL_TREE);
10244 : 40 : if (x)
10245 : : {
10246 : 40 : if (new_vard != new_var)
10247 : 8 : val = build_fold_addr_expr_loc (clause_loc, val);
10248 : 40 : SET_DECL_VALUE_EXPR (new_vard, val);
10249 : : }
10250 : 96 : SET_DECL_VALUE_EXPR (placeholder, ref);
10251 : 96 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
10252 : 96 : lower_omp (&tseq, octx);
10253 : 96 : if (x)
10254 : 40 : SET_DECL_VALUE_EXPR (new_vard, x);
10255 : 96 : SET_DECL_VALUE_EXPR (placeholder, NULL_TREE);
10256 : 96 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
10257 : 96 : gimple_seq_add_seq (&before, tseq);
10258 : 96 : if (is_simd)
10259 : 80 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
10260 : : }
10261 : : }
10262 : 188 : else if (is_simd)
10263 : : {
10264 : 156 : tree x;
10265 : 156 : if (octx->scan_exclusive)
10266 : : {
10267 : 72 : tree v4 = unshare_expr (var4);
10268 : 72 : tree v2 = unshare_expr (var2);
10269 : 72 : x = lang_hooks.decls.omp_clause_assign_op (c, v4, v2);
10270 : 72 : gimplify_and_add (x, &before);
10271 : : }
10272 : 156 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
10273 : 156 : x = (DECL_HAS_VALUE_EXPR_P (new_vard)
10274 : 156 : ? DECL_VALUE_EXPR (new_vard) : NULL_TREE);
10275 : 156 : tree vexpr = val;
10276 : 156 : if (x && new_vard != new_var)
10277 : 30 : vexpr = build_fold_addr_expr_loc (clause_loc, val);
10278 : 156 : if (x)
10279 : 78 : SET_DECL_VALUE_EXPR (new_vard, vexpr);
10280 : 156 : SET_DECL_VALUE_EXPR (placeholder, var2);
10281 : 156 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
10282 : 156 : lower_omp (&tseq, octx);
10283 : 156 : gimple_seq_add_seq (&before, tseq);
10284 : 156 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
10285 : 156 : if (x)
10286 : 78 : SET_DECL_VALUE_EXPR (new_vard, x);
10287 : 156 : SET_DECL_VALUE_EXPR (placeholder, NULL_TREE);
10288 : 156 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
10289 : 156 : if (octx->scan_inclusive)
10290 : : {
10291 : 84 : x = lang_hooks.decls.omp_clause_assign_op (c, val,
10292 : : var2);
10293 : 84 : gimplify_and_add (x, &before);
10294 : : }
10295 : 72 : else if (lane0 == NULL_TREE)
10296 : : {
10297 : 36 : x = lang_hooks.decls.omp_clause_assign_op (c, val,
10298 : : var4);
10299 : 36 : gimplify_and_add (x, &before);
10300 : : }
10301 : : }
10302 : : }
10303 : : else
10304 : : {
10305 : 784 : if (input_phase)
10306 : : {
10307 : : /* input phase. Set val to initializer before
10308 : : the body. */
10309 : 392 : tree x = omp_reduction_init (c, TREE_TYPE (new_var));
10310 : 392 : gimplify_assign (val, x, &before);
10311 : : }
10312 : 392 : else if (is_simd)
10313 : : {
10314 : : /* scan phase. */
10315 : 318 : enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c);
10316 : 318 : if (code == MINUS_EXPR)
10317 : 0 : code = PLUS_EXPR;
10318 : :
10319 : 318 : tree x = build2 (code, TREE_TYPE (var2),
10320 : : unshare_expr (var2), unshare_expr (val));
10321 : 318 : if (octx->scan_inclusive)
10322 : : {
10323 : 154 : gimplify_assign (unshare_expr (var2), x, &before);
10324 : 154 : gimplify_assign (val, var2, &before);
10325 : : }
10326 : : else
10327 : : {
10328 : 164 : gimplify_assign (unshare_expr (var4),
10329 : : unshare_expr (var2), &before);
10330 : 164 : gimplify_assign (var2, x, &before);
10331 : 164 : if (lane0 == NULL_TREE)
10332 : 86 : gimplify_assign (val, var4, &before);
10333 : : }
10334 : : }
10335 : : }
10336 : 1160 : if (octx->scan_exclusive && !input_phase && lane0)
10337 : : {
10338 : 114 : tree vexpr = unshare_expr (var4);
10339 : 114 : TREE_OPERAND (vexpr, 1) = lane0;
10340 : 114 : if (new_vard != new_var)
10341 : 16 : vexpr = build_fold_addr_expr_loc (clause_loc, vexpr);
10342 : 114 : SET_DECL_VALUE_EXPR (new_vard, vexpr);
10343 : : }
10344 : : }
10345 : : }
10346 : 1268 : if (is_simd && !is_for_simd)
10347 : : {
10348 : 590 : gsi_insert_seq_after (gsi_p, gimple_omp_body (stmt), GSI_SAME_STMT);
10349 : 590 : gsi_insert_seq_after (gsi_p, before, GSI_SAME_STMT);
10350 : 590 : gsi_replace (gsi_p, gimple_build_nop (), true);
10351 : 590 : return;
10352 : : }
10353 : 678 : lower_omp (gimple_omp_body_ptr (stmt), octx);
10354 : 678 : if (before)
10355 : : {
10356 : 256 : gimple_stmt_iterator gsi = gsi_start (*gimple_omp_body_ptr (stmt));
10357 : 256 : gsi_insert_seq_before (&gsi, before, GSI_SAME_STMT);
10358 : : }
10359 : : }
10360 : :
10361 : :
10362 : : /* Gimplify a GIMPLE_OMP_CRITICAL statement. This is a relatively simple
10363 : : substitution of a couple of function calls. But in the NAMED case,
10364 : : requires that languages coordinate a symbol name. It is therefore
10365 : : best put here in common code. */
10366 : :
10367 : : static GTY(()) hash_map<tree, tree> *critical_name_mutexes;
10368 : :
10369 : : static void
10370 : 311 : lower_omp_critical (gimple_stmt_iterator *gsi_p, omp_context *ctx)
10371 : : {
10372 : 311 : tree block;
10373 : 311 : tree name, lock, unlock;
10374 : 311 : gomp_critical *stmt = as_a <gomp_critical *> (gsi_stmt (*gsi_p));
10375 : 311 : gbind *bind;
10376 : 311 : location_t loc = gimple_location (stmt);
10377 : 311 : gimple_seq tbody;
10378 : :
10379 : 311 : name = gimple_omp_critical_name (stmt);
10380 : 311 : if (name)
10381 : : {
10382 : 88 : tree decl;
10383 : :
10384 : 88 : if (!critical_name_mutexes)
10385 : 48 : critical_name_mutexes = hash_map<tree, tree>::create_ggc (10);
10386 : :
10387 : 88 : tree *n = critical_name_mutexes->get (name);
10388 : 88 : if (n == NULL)
10389 : : {
10390 : 70 : char *new_str;
10391 : :
10392 : 70 : decl = create_tmp_var_raw (ptr_type_node);
10393 : :
10394 : 70 : new_str = ACONCAT ((".gomp_critical_user_",
10395 : : IDENTIFIER_POINTER (name), NULL));
10396 : 70 : DECL_NAME (decl) = get_identifier (new_str);
10397 : 70 : TREE_PUBLIC (decl) = 1;
10398 : 70 : TREE_STATIC (decl) = 1;
10399 : 70 : DECL_COMMON (decl) = 1;
10400 : 70 : DECL_ARTIFICIAL (decl) = 1;
10401 : 70 : DECL_IGNORED_P (decl) = 1;
10402 : :
10403 : 70 : varpool_node::finalize_decl (decl);
10404 : :
10405 : 70 : critical_name_mutexes->put (name, decl);
10406 : : }
10407 : : else
10408 : 18 : decl = *n;
10409 : :
10410 : : /* If '#pragma omp critical' is inside offloaded region or
10411 : : inside function marked as offloadable, the symbol must be
10412 : : marked as offloadable too. */
10413 : 88 : omp_context *octx;
10414 : 88 : if (cgraph_node::get (current_function_decl)->offloadable)
10415 : 1 : varpool_node::get_create (decl)->offloadable = 1;
10416 : : else
10417 : 173 : for (octx = ctx->outer; octx; octx = octx->outer)
10418 : 87 : if (is_gimple_omp_offloaded (octx->stmt))
10419 : : {
10420 : 1 : varpool_node::get_create (decl)->offloadable = 1;
10421 : 1 : break;
10422 : : }
10423 : :
10424 : 88 : lock = builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_NAME_START);
10425 : 88 : lock = build_call_expr_loc (loc, lock, 1,
10426 : : build_fold_addr_expr_loc (loc, decl));
10427 : :
10428 : 88 : unlock = builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_NAME_END);
10429 : 88 : unlock = build_call_expr_loc (loc, unlock, 1,
10430 : : build_fold_addr_expr_loc (loc, decl));
10431 : : }
10432 : : else
10433 : : {
10434 : 223 : lock = builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_START);
10435 : 223 : lock = build_call_expr_loc (loc, lock, 0);
10436 : :
10437 : 223 : unlock = builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_END);
10438 : 223 : unlock = build_call_expr_loc (loc, unlock, 0);
10439 : : }
10440 : :
10441 : 311 : push_gimplify_context ();
10442 : :
10443 : 311 : block = make_node (BLOCK);
10444 : 311 : bind = gimple_build_bind (NULL, NULL, block);
10445 : 311 : gsi_replace (gsi_p, bind, true);
10446 : 311 : gimple_bind_add_stmt (bind, stmt);
10447 : :
10448 : 311 : tbody = gimple_bind_body (bind);
10449 : 311 : gimplify_and_add (lock, &tbody);
10450 : 311 : gimple_bind_set_body (bind, tbody);
10451 : :
10452 : 311 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
10453 : 311 : gimple_omp_set_body (stmt, maybe_catch_exception (gimple_omp_body (stmt)));
10454 : 311 : gimple_bind_add_seq (bind, gimple_omp_body (stmt));
10455 : 311 : gimple_omp_set_body (stmt, NULL);
10456 : :
10457 : 311 : tbody = gimple_bind_body (bind);
10458 : 311 : gimplify_and_add (unlock, &tbody);
10459 : 311 : gimple_bind_set_body (bind, tbody);
10460 : :
10461 : 311 : gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
10462 : :
10463 : 311 : pop_gimplify_context (bind);
10464 : 311 : gimple_bind_append_vars (bind, ctx->block_vars);
10465 : 311 : BLOCK_VARS (block) = gimple_bind_vars (bind);
10466 : 311 : }
10467 : :
10468 : : /* A subroutine of lower_omp_for. Generate code to emit the predicate
10469 : : for a lastprivate clause. Given a loop control predicate of (V
10470 : : cond N2), we gate the clause on (!(V cond N2)). The lowered form
10471 : : is appended to *DLIST, iterator initialization is appended to
10472 : : *BODY_P. *CLIST is for lastprivate(conditional:) code that needs
10473 : : to be emitted in a critical section. */
10474 : :
10475 : : static void
10476 : 46865 : lower_omp_for_lastprivate (struct omp_for_data *fd, gimple_seq *body_p,
10477 : : gimple_seq *dlist, gimple_seq *clist,
10478 : : struct omp_context *ctx)
10479 : : {
10480 : 46865 : tree clauses, cond, vinit;
10481 : 46865 : enum tree_code cond_code;
10482 : 46865 : gimple_seq stmts;
10483 : :
10484 : 46865 : cond_code = fd->loop.cond_code;
10485 : 46865 : cond_code = cond_code == LT_EXPR ? GE_EXPR : LE_EXPR;
10486 : :
10487 : : /* When possible, use a strict equality expression. This can let VRP
10488 : : type optimizations deduce the value and remove a copy. */
10489 : 46865 : if (tree_fits_shwi_p (fd->loop.step))
10490 : : {
10491 : 44630 : HOST_WIDE_INT step = tree_to_shwi (fd->loop.step);
10492 : 44630 : if (step == 1 || step == -1)
10493 : 46865 : cond_code = EQ_EXPR;
10494 : : }
10495 : :
10496 : 46865 : tree n2 = fd->loop.n2;
10497 : 46865 : if (fd->collapse > 1
10498 : 11244 : && TREE_CODE (n2) != INTEGER_CST
10499 : 53079 : && gimple_omp_for_combined_into_p (fd->for_stmt))
10500 : : {
10501 : 2692 : struct omp_context *taskreg_ctx = NULL;
10502 : 2692 : if (gimple_code (ctx->outer->stmt) == GIMPLE_OMP_FOR)
10503 : : {
10504 : 1226 : gomp_for *gfor = as_a <gomp_for *> (ctx->outer->stmt);
10505 : 1226 : if (gimple_omp_for_kind (gfor) == GF_OMP_FOR_KIND_FOR
10506 : 1226 : || gimple_omp_for_kind (gfor) == GF_OMP_FOR_KIND_DISTRIBUTE)
10507 : : {
10508 : 1194 : if (gimple_omp_for_combined_into_p (gfor))
10509 : : {
10510 : 672 : gcc_assert (ctx->outer->outer
10511 : : && is_parallel_ctx (ctx->outer->outer));
10512 : : taskreg_ctx = ctx->outer->outer;
10513 : : }
10514 : : else
10515 : : {
10516 : 522 : struct omp_for_data outer_fd;
10517 : 522 : omp_extract_for_data (gfor, &outer_fd, NULL);
10518 : 522 : n2 = fold_convert (TREE_TYPE (n2), outer_fd.loop.n2);
10519 : : }
10520 : : }
10521 : 32 : else if (gimple_omp_for_kind (gfor) == GF_OMP_FOR_KIND_TASKLOOP)
10522 : 32 : taskreg_ctx = ctx->outer->outer;
10523 : : }
10524 : 1466 : else if (is_taskreg_ctx (ctx->outer))
10525 : : taskreg_ctx = ctx->outer;
10526 : 2692 : if (taskreg_ctx)
10527 : : {
10528 : 2170 : int i;
10529 : 2170 : tree taskreg_clauses
10530 : 2170 : = gimple_omp_taskreg_clauses (taskreg_ctx->stmt);
10531 : 2170 : tree innerc = omp_find_clause (taskreg_clauses,
10532 : : OMP_CLAUSE__LOOPTEMP_);
10533 : 2170 : gcc_assert (innerc);
10534 : 2170 : int count = fd->collapse;
10535 : 2170 : if (fd->non_rect
10536 : 24 : && fd->last_nonrect == fd->first_nonrect + 1)
10537 : 12 : if (tree v = gimple_omp_for_index (fd->for_stmt, fd->last_nonrect))
10538 : 12 : if (!TYPE_UNSIGNED (TREE_TYPE (v)))
10539 : 12 : count += 4;
10540 : 8582 : for (i = 0; i < count; i++)
10541 : : {
10542 : 6412 : innerc = omp_find_clause (OMP_CLAUSE_CHAIN (innerc),
10543 : : OMP_CLAUSE__LOOPTEMP_);
10544 : 6412 : gcc_assert (innerc);
10545 : : }
10546 : 2170 : innerc = omp_find_clause (OMP_CLAUSE_CHAIN (innerc),
10547 : : OMP_CLAUSE__LOOPTEMP_);
10548 : 2170 : if (innerc)
10549 : 1419 : n2 = fold_convert (TREE_TYPE (n2),
10550 : : lookup_decl (OMP_CLAUSE_DECL (innerc),
10551 : : taskreg_ctx));
10552 : : }
10553 : : }
10554 : 46865 : cond = build2 (cond_code, boolean_type_node, fd->loop.v, n2);
10555 : :
10556 : 46865 : clauses = gimple_omp_for_clauses (fd->for_stmt);
10557 : 46865 : stmts = NULL;
10558 : 46865 : lower_lastprivate_clauses (clauses, cond, body_p, &stmts, clist, ctx);
10559 : 46865 : if (!gimple_seq_empty_p (stmts))
10560 : : {
10561 : 16360 : gimple_seq_add_seq (&stmts, *dlist);
10562 : 16360 : *dlist = stmts;
10563 : :
10564 : : /* Optimize: v = 0; is usually cheaper than v = some_other_constant. */
10565 : 16360 : vinit = fd->loop.n1;
10566 : 16360 : if (cond_code == EQ_EXPR
10567 : 14373 : && tree_fits_shwi_p (fd->loop.n2)
10568 : 25919 : && ! integer_zerop (fd->loop.n2))
10569 : 8343 : vinit = build_int_cst (TREE_TYPE (fd->loop.v), 0);
10570 : : else
10571 : 8017 : vinit = unshare_expr (vinit);
10572 : :
10573 : : /* Initialize the iterator variable, so that threads that don't execute
10574 : : any iterations don't execute the lastprivate clauses by accident. */
10575 : 16360 : gimplify_assign (fd->loop.v, vinit, body_p);
10576 : : }
10577 : 46865 : }
10578 : :
10579 : : /* OpenACC privatization.
10580 : :
10581 : : Or, in other words, *sharing* at the respective OpenACC level of
10582 : : parallelism.
10583 : :
10584 : : From a correctness perspective, a non-addressable variable can't be accessed
10585 : : outside the current thread, so it can go in a (faster than shared memory)
10586 : : register -- though that register may need to be broadcast in some
10587 : : circumstances. A variable can only meaningfully be "shared" across workers
10588 : : or vector lanes if its address is taken, e.g. by a call to an atomic
10589 : : builtin.
10590 : :
10591 : : From an optimisation perspective, the answer might be fuzzier: maybe
10592 : : sometimes, using shared memory directly would be faster than
10593 : : broadcasting. */
10594 : :
10595 : : static void
10596 : 18997 : oacc_privatization_begin_diagnose_var (const dump_flags_t l_dump_flags,
10597 : : const location_t loc, const tree c,
10598 : : const tree decl)
10599 : : {
10600 : 18997 : const dump_user_location_t d_u_loc
10601 : 18997 : = dump_user_location_t::from_location_t (loc);
10602 : : /* PR100695 "Format decoder, quoting in 'dump_printf' etc." */
10603 : : #if __GNUC__ >= 10
10604 : 18997 : # pragma GCC diagnostic push
10605 : 18997 : # pragma GCC diagnostic ignored "-Wformat"
10606 : : #endif
10607 : 18997 : dump_printf_loc (l_dump_flags, d_u_loc,
10608 : : "variable %<%T%> ", decl);
10609 : : #if __GNUC__ >= 10
10610 : 18997 : # pragma GCC diagnostic pop
10611 : : #endif
10612 : 18997 : if (c)
10613 : 2797 : dump_printf (l_dump_flags,
10614 : : "in %qs clause ",
10615 : 2797 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10616 : : else
10617 : 16200 : dump_printf (l_dump_flags,
10618 : : "declared in block ");
10619 : 18997 : }
10620 : :
10621 : : static bool
10622 : 41011 : oacc_privatization_candidate_p (const location_t loc, const tree c,
10623 : : const tree decl)
10624 : : {
10625 : 41011 : dump_flags_t l_dump_flags = get_openacc_privatization_dump_flags ();
10626 : :
10627 : : /* There is some differentiation depending on block vs. clause. */
10628 : 41011 : bool block = !c;
10629 : :
10630 : 41011 : bool res = true;
10631 : :
10632 : 41011 : if (res && !VAR_P (decl))
10633 : : {
10634 : : /* A PARM_DECL (appearing in a 'private' clause) is expected to have been
10635 : : privatized into a new VAR_DECL. */
10636 : 712 : gcc_checking_assert (TREE_CODE (decl) != PARM_DECL);
10637 : :
10638 : 712 : res = false;
10639 : :
10640 : 712 : if (dump_enabled_p ())
10641 : : {
10642 : 683 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10643 : 683 : dump_printf (l_dump_flags,
10644 : : "potentially has improper OpenACC privatization level: %qs\n",
10645 : 683 : get_tree_code_name (TREE_CODE (decl)));
10646 : : }
10647 : : }
10648 : :
10649 : 40982 : if (res && block && TREE_STATIC (decl))
10650 : : {
10651 : 52 : res = false;
10652 : :
10653 : 52 : if (dump_enabled_p ())
10654 : : {
10655 : 28 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10656 : 28 : dump_printf (l_dump_flags,
10657 : : "isn%'t candidate for adjusting OpenACC privatization level: %s\n",
10658 : : "static");
10659 : : }
10660 : : }
10661 : :
10662 : 40987 : if (res && block && DECL_EXTERNAL (decl))
10663 : : {
10664 : 12 : res = false;
10665 : :
10666 : 12 : if (dump_enabled_p ())
10667 : : {
10668 : 12 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10669 : 12 : dump_printf (l_dump_flags,
10670 : : "isn%'t candidate for adjusting OpenACC privatization level: %s\n",
10671 : : "external");
10672 : : }
10673 : : }
10674 : :
10675 : 41011 : if (res && !TREE_ADDRESSABLE (decl))
10676 : : {
10677 : 39144 : res = false;
10678 : :
10679 : 39144 : if (dump_enabled_p ())
10680 : : {
10681 : 17456 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10682 : 17456 : dump_printf (l_dump_flags,
10683 : : "isn%'t candidate for adjusting OpenACC privatization level: %s\n",
10684 : : "not addressable");
10685 : : }
10686 : : }
10687 : :
10688 : : /* If an artificial variable has been added to a bind, e.g.
10689 : : a compiler-generated temporary structure used by the Fortran front-end, do
10690 : : not consider it as a privatization candidate. Note that variables on
10691 : : the stack are private per-thread by default: making them "gang-private"
10692 : : for OpenACC actually means to share a single instance of a variable
10693 : : amongst all workers and threads spawned within each gang.
10694 : : At present, no compiler-generated artificial variables require such
10695 : : sharing semantics, so this is safe. */
10696 : :
10697 : 18547 : if (res && block && DECL_ARTIFICIAL (decl))
10698 : : {
10699 : 548 : res = false;
10700 : :
10701 : 548 : if (dump_enabled_p ())
10702 : : {
10703 : 360 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10704 : 360 : dump_printf (l_dump_flags,
10705 : : "isn%'t candidate for adjusting OpenACC privatization "
10706 : : "level: %s\n", "artificial");
10707 : : }
10708 : : }
10709 : :
10710 : 40823 : if (res)
10711 : : {
10712 : 543 : if (dump_enabled_p ())
10713 : : {
10714 : 458 : oacc_privatization_begin_diagnose_var (l_dump_flags, loc, c, decl);
10715 : 458 : dump_printf (l_dump_flags,
10716 : : "is candidate for adjusting OpenACC privatization level\n");
10717 : : }
10718 : : }
10719 : :
10720 : 41011 : if (dump_file && (dump_flags & TDF_DETAILS))
10721 : : {
10722 : 0 : print_generic_decl (dump_file, decl, dump_flags);
10723 : 0 : fprintf (dump_file, "\n");
10724 : : }
10725 : :
10726 : 41011 : return res;
10727 : : }
10728 : :
10729 : : /* Scan CLAUSES for candidates for adjusting OpenACC privatization level in
10730 : : CTX. */
10731 : :
10732 : : static void
10733 : 11323 : oacc_privatization_scan_clause_chain (omp_context *ctx, tree clauses)
10734 : : {
10735 : 35216 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
10736 : 23893 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE)
10737 : : {
10738 : 12982 : tree decl = OMP_CLAUSE_DECL (c);
10739 : :
10740 : 12982 : tree new_decl = lookup_decl (decl, ctx);
10741 : :
10742 : 12982 : if (!oacc_privatization_candidate_p (OMP_CLAUSE_LOCATION (c), c,
10743 : : new_decl))
10744 : 12651 : continue;
10745 : :
10746 : 331 : gcc_checking_assert
10747 : : (!ctx->oacc_privatization_candidates.contains (new_decl));
10748 : 331 : ctx->oacc_privatization_candidates.safe_push (new_decl);
10749 : : }
10750 : 11323 : }
10751 : :
10752 : : /* Scan DECLS for candidates for adjusting OpenACC privatization level in
10753 : : CTX. */
10754 : :
10755 : : static void
10756 : 23036 : oacc_privatization_scan_decl_chain (omp_context *ctx, tree decls)
10757 : : {
10758 : 51065 : for (tree decl = decls; decl; decl = DECL_CHAIN (decl))
10759 : : {
10760 : 28029 : tree new_decl = lookup_decl (decl, ctx);
10761 : 28029 : gcc_checking_assert (new_decl == decl);
10762 : :
10763 : 28029 : if (!oacc_privatization_candidate_p (gimple_location (ctx->stmt), NULL,
10764 : : new_decl))
10765 : 27817 : continue;
10766 : :
10767 : 212 : gcc_checking_assert
10768 : : (!ctx->oacc_privatization_candidates.contains (new_decl));
10769 : 212 : ctx->oacc_privatization_candidates.safe_push (new_decl);
10770 : : }
10771 : 23036 : }
10772 : :
10773 : : /* Callback for walk_gimple_seq. Find #pragma omp scan statement. */
10774 : :
10775 : : static tree
10776 : 2225 : omp_find_scan (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
10777 : : struct walk_stmt_info *wi)
10778 : : {
10779 : 2225 : gimple *stmt = gsi_stmt (*gsi_p);
10780 : :
10781 : 2225 : *handled_ops_p = true;
10782 : 2225 : switch (gimple_code (stmt))
10783 : : {
10784 : 418 : WALK_SUBSTMTS;
10785 : :
10786 : 166 : case GIMPLE_OMP_FOR:
10787 : 166 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_SIMD
10788 : 166 : && gimple_omp_for_combined_into_p (stmt))
10789 : 166 : *handled_ops_p = false;
10790 : : break;
10791 : :
10792 : 678 : case GIMPLE_OMP_SCAN:
10793 : 678 : *(gimple_stmt_iterator *) (wi->info) = *gsi_p;
10794 : 678 : return integer_zero_node;
10795 : : default:
10796 : : break;
10797 : : }
10798 : : return NULL;
10799 : : }
10800 : :
10801 : : /* Helper function for lower_omp_for, add transformations for a worksharing
10802 : : loop with scan directives inside of it.
10803 : : For worksharing loop not combined with simd, transform:
10804 : : #pragma omp for reduction(inscan,+:r) private(i)
10805 : : for (i = 0; i < n; i = i + 1)
10806 : : {
10807 : : {
10808 : : update (r);
10809 : : }
10810 : : #pragma omp scan inclusive(r)
10811 : : {
10812 : : use (r);
10813 : : }
10814 : : }
10815 : :
10816 : : into two worksharing loops + code to merge results:
10817 : :
10818 : : num_threads = omp_get_num_threads ();
10819 : : thread_num = omp_get_thread_num ();
10820 : : if (thread_num == 0) goto <D.2099>; else goto <D.2100>;
10821 : : <D.2099>:
10822 : : var2 = r;
10823 : : goto <D.2101>;
10824 : : <D.2100>:
10825 : : // For UDRs this is UDR init, or if ctors are needed, copy from
10826 : : // var3 that has been constructed to contain the neutral element.
10827 : : var2 = 0;
10828 : : <D.2101>:
10829 : : ivar = 0;
10830 : : // The _scantemp_ clauses will arrange for rpriva to be initialized to
10831 : : // a shared array with num_threads elements and rprivb to a local array
10832 : : // number of elements equal to the number of (contiguous) iterations the
10833 : : // current thread will perform. controlb and controlp variables are
10834 : : // temporaries to handle deallocation of rprivb at the end of second
10835 : : // GOMP_FOR.
10836 : : #pragma omp for _scantemp_(rpriva) _scantemp_(rprivb) _scantemp_(controlb) \
10837 : : _scantemp_(controlp) reduction(inscan,+:r) private(i) nowait
10838 : : for (i = 0; i < n; i = i + 1)
10839 : : {
10840 : : {
10841 : : // For UDRs this is UDR init or copy from var3.
10842 : : r = 0;
10843 : : // This is the input phase from user code.
10844 : : update (r);
10845 : : }
10846 : : {
10847 : : // For UDRs this is UDR merge.
10848 : : var2 = var2 + r;
10849 : : // Rather than handing it over to the user, save to local thread's
10850 : : // array.
10851 : : rprivb[ivar] = var2;
10852 : : // For exclusive scan, the above two statements are swapped.
10853 : : ivar = ivar + 1;
10854 : : }
10855 : : }
10856 : : // And remember the final value from this thread's into the shared
10857 : : // rpriva array.
10858 : : rpriva[(sizetype) thread_num] = var2;
10859 : : // If more than one thread, compute using Work-Efficient prefix sum
10860 : : // the inclusive parallel scan of the rpriva array.
10861 : : if (num_threads > 1) goto <D.2102>; else goto <D.2103>;
10862 : : <D.2102>:
10863 : : GOMP_barrier ();
10864 : : down = 0;
10865 : : k = 1;
10866 : : num_threadsu = (unsigned int) num_threads;
10867 : : thread_numup1 = (unsigned int) thread_num + 1;
10868 : : <D.2108>:
10869 : : twok = k << 1;
10870 : : if (twok > num_threadsu) goto <D.2110>; else goto <D.2111>;
10871 : : <D.2110>:
10872 : : down = 4294967295;
10873 : : k = k >> 1;
10874 : : if (k == num_threadsu) goto <D.2112>; else goto <D.2111>;
10875 : : <D.2112>:
10876 : : k = k >> 1;
10877 : : <D.2111>:
10878 : : twok = k << 1;
10879 : : cplx = .MUL_OVERFLOW (thread_nump1, twok);
10880 : : mul = REALPART_EXPR <cplx>;
10881 : : ovf = IMAGPART_EXPR <cplx>;
10882 : : if (ovf == 0) goto <D.2116>; else goto <D.2117>;
10883 : : <D.2116>:
10884 : : andv = k & down;
10885 : : andvm1 = andv + 4294967295;
10886 : : l = mul + andvm1;
10887 : : if (l < num_threadsu) goto <D.2120>; else goto <D.2117>;
10888 : : <D.2120>:
10889 : : // For UDRs this is UDR merge, performed using var2 variable as temporary,
10890 : : // i.e. var2 = rpriva[l - k]; UDR merge (var2, rpriva[l]); rpriva[l] = var2;
10891 : : rpriva[l] = rpriva[l - k] + rpriva[l];
10892 : : <D.2117>:
10893 : : if (down == 0) goto <D.2121>; else goto <D.2122>;
10894 : : <D.2121>:
10895 : : k = k << 1;
10896 : : goto <D.2123>;
10897 : : <D.2122>:
10898 : : k = k >> 1;
10899 : : <D.2123>:
10900 : : GOMP_barrier ();
10901 : : if (k != 0) goto <D.2108>; else goto <D.2103>;
10902 : : <D.2103>:
10903 : : if (thread_num == 0) goto <D.2124>; else goto <D.2125>;
10904 : : <D.2124>:
10905 : : // For UDRs this is UDR init or copy from var3.
10906 : : var2 = 0;
10907 : : goto <D.2126>;
10908 : : <D.2125>:
10909 : : var2 = rpriva[thread_num - 1];
10910 : : <D.2126>:
10911 : : ivar = 0;
10912 : : #pragma omp for _scantemp_(controlb) _scantemp_(controlp) \
10913 : : reduction(inscan,+:r) private(i)
10914 : : for (i = 0; i < n; i = i + 1)
10915 : : {
10916 : : {
10917 : : // For UDRs, this is r = var2; UDR merge (r, rprivb[ivar]);
10918 : : r = var2 + rprivb[ivar];
10919 : : }
10920 : : {
10921 : : // This is the scan phase from user code.
10922 : : use (r);
10923 : : // Plus a bump of the iterator.
10924 : : ivar = ivar + 1;
10925 : : }
10926 : : } */
10927 : :
10928 : : static void
10929 : 173 : lower_omp_for_scan (gimple_seq *body_p, gimple_seq *dlist, gomp_for *stmt,
10930 : : struct omp_for_data *fd, omp_context *ctx)
10931 : : {
10932 : 173 : bool is_for_simd = gimple_omp_for_combined_p (stmt);
10933 : 173 : gcc_assert (ctx->scan_inclusive || ctx->scan_exclusive);
10934 : :
10935 : 173 : gimple_seq body = gimple_omp_body (stmt);
10936 : 173 : gimple_stmt_iterator input1_gsi = gsi_none ();
10937 : 173 : struct walk_stmt_info wi;
10938 : 173 : memset (&wi, 0, sizeof (wi));
10939 : 173 : wi.val_only = true;
10940 : 173 : wi.info = (void *) &input1_gsi;
10941 : 173 : walk_gimple_seq_mod (&body, omp_find_scan, NULL, &wi);
10942 : 173 : gcc_assert (!gsi_end_p (input1_gsi));
10943 : :
10944 : 173 : gimple *input_stmt1 = gsi_stmt (input1_gsi);
10945 : 173 : gimple_stmt_iterator gsi = input1_gsi;
10946 : 173 : gsi_next (&gsi);
10947 : 173 : gimple_stmt_iterator scan1_gsi = gsi;
10948 : 173 : gimple *scan_stmt1 = gsi_stmt (gsi);
10949 : 173 : gcc_assert (scan_stmt1 && gimple_code (scan_stmt1) == GIMPLE_OMP_SCAN);
10950 : :
10951 : 173 : gimple_seq input_body = gimple_omp_body (input_stmt1);
10952 : 173 : gimple_seq scan_body = gimple_omp_body (scan_stmt1);
10953 : 173 : gimple_omp_set_body (input_stmt1, NULL);
10954 : 173 : gimple_omp_set_body (scan_stmt1, NULL);
10955 : 173 : gimple_omp_set_body (stmt, NULL);
10956 : :
10957 : 173 : gomp_for *new_stmt = as_a <gomp_for *> (gimple_copy (stmt));
10958 : 173 : gimple_seq new_body = copy_gimple_seq_and_replace_locals (body);
10959 : 173 : gimple_omp_set_body (stmt, body);
10960 : 173 : gimple_omp_set_body (input_stmt1, input_body);
10961 : :
10962 : 173 : gimple_stmt_iterator input2_gsi = gsi_none ();
10963 : 173 : memset (&wi, 0, sizeof (wi));
10964 : 173 : wi.val_only = true;
10965 : 173 : wi.info = (void *) &input2_gsi;
10966 : 173 : walk_gimple_seq_mod (&new_body, omp_find_scan, NULL, &wi);
10967 : 173 : gcc_assert (!gsi_end_p (input2_gsi));
10968 : :
10969 : 173 : gimple *input_stmt2 = gsi_stmt (input2_gsi);
10970 : 173 : gsi = input2_gsi;
10971 : 173 : gsi_next (&gsi);
10972 : 173 : gimple_stmt_iterator scan2_gsi = gsi;
10973 : 173 : gimple *scan_stmt2 = gsi_stmt (gsi);
10974 : 173 : gcc_assert (scan_stmt2 && gimple_code (scan_stmt2) == GIMPLE_OMP_SCAN);
10975 : 173 : gimple_omp_set_body (scan_stmt2, scan_body);
10976 : :
10977 : 173 : gimple_stmt_iterator input3_gsi = gsi_none ();
10978 : 173 : gimple_stmt_iterator scan3_gsi = gsi_none ();
10979 : 173 : gimple_stmt_iterator input4_gsi = gsi_none ();
10980 : 173 : gimple_stmt_iterator scan4_gsi = gsi_none ();
10981 : 173 : gimple *input_stmt3 = NULL, *scan_stmt3 = NULL;
10982 : 173 : gimple *input_stmt4 = NULL, *scan_stmt4 = NULL;
10983 : 173 : omp_context *input_simd_ctx = NULL, *scan_simd_ctx = NULL;
10984 : 173 : if (is_for_simd)
10985 : : {
10986 : 83 : memset (&wi, 0, sizeof (wi));
10987 : 83 : wi.val_only = true;
10988 : 83 : wi.info = (void *) &input3_gsi;
10989 : 83 : walk_gimple_seq_mod (&input_body, omp_find_scan, NULL, &wi);
10990 : 83 : gcc_assert (!gsi_end_p (input3_gsi));
10991 : :
10992 : 83 : input_stmt3 = gsi_stmt (input3_gsi);
10993 : 83 : gsi = input3_gsi;
10994 : 83 : gsi_next (&gsi);
10995 : 83 : scan3_gsi = gsi;
10996 : 83 : scan_stmt3 = gsi_stmt (gsi);
10997 : 83 : gcc_assert (scan_stmt3 && gimple_code (scan_stmt3) == GIMPLE_OMP_SCAN);
10998 : :
10999 : 83 : memset (&wi, 0, sizeof (wi));
11000 : 83 : wi.val_only = true;
11001 : 83 : wi.info = (void *) &input4_gsi;
11002 : 83 : walk_gimple_seq_mod (&scan_body, omp_find_scan, NULL, &wi);
11003 : 83 : gcc_assert (!gsi_end_p (input4_gsi));
11004 : :
11005 : 83 : input_stmt4 = gsi_stmt (input4_gsi);
11006 : 83 : gsi = input4_gsi;
11007 : 83 : gsi_next (&gsi);
11008 : 83 : scan4_gsi = gsi;
11009 : 83 : scan_stmt4 = gsi_stmt (gsi);
11010 : 83 : gcc_assert (scan_stmt4 && gimple_code (scan_stmt4) == GIMPLE_OMP_SCAN);
11011 : :
11012 : 83 : input_simd_ctx = maybe_lookup_ctx (input_stmt3)->outer;
11013 : 83 : scan_simd_ctx = maybe_lookup_ctx (input_stmt4)->outer;
11014 : : }
11015 : :
11016 : 173 : tree num_threads = create_tmp_var (integer_type_node);
11017 : 173 : tree thread_num = create_tmp_var (integer_type_node);
11018 : 173 : tree nthreads_decl = builtin_decl_explicit (BUILT_IN_OMP_GET_NUM_THREADS);
11019 : 173 : tree threadnum_decl = builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM);
11020 : 173 : gimple *g = gimple_build_call (nthreads_decl, 0);
11021 : 173 : gimple_call_set_lhs (g, num_threads);
11022 : 173 : gimple_seq_add_stmt (body_p, g);
11023 : 173 : g = gimple_build_call (threadnum_decl, 0);
11024 : 173 : gimple_call_set_lhs (g, thread_num);
11025 : 173 : gimple_seq_add_stmt (body_p, g);
11026 : :
11027 : 173 : tree ivar = create_tmp_var (sizetype);
11028 : 173 : tree new_clauses1 = NULL_TREE, new_clauses2 = NULL_TREE;
11029 : 173 : tree *cp1 = &new_clauses1, *cp2 = &new_clauses2;
11030 : 173 : tree k = create_tmp_var (unsigned_type_node);
11031 : 173 : tree l = create_tmp_var (unsigned_type_node);
11032 : :
11033 : 173 : gimple_seq clist = NULL, mdlist = NULL;
11034 : 173 : gimple_seq thr01_list = NULL, thrn1_list = NULL;
11035 : 173 : gimple_seq thr02_list = NULL, thrn2_list = NULL;
11036 : 173 : gimple_seq scan1_list = NULL, input2_list = NULL;
11037 : 173 : gimple_seq last_list = NULL, reduc_list = NULL;
11038 : 674 : for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
11039 : 501 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
11040 : 501 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
11041 : : {
11042 : 205 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
11043 : 205 : tree var = OMP_CLAUSE_DECL (c);
11044 : 205 : tree new_var = lookup_decl (var, ctx);
11045 : 205 : tree var3 = NULL_TREE;
11046 : 205 : tree new_vard = new_var;
11047 : 205 : if (omp_privatize_by_reference (var))
11048 : 32 : new_var = build_simple_mem_ref_loc (clause_loc, new_var);
11049 : 205 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
11050 : : {
11051 : 64 : var3 = maybe_lookup_decl (new_vard, ctx);
11052 : 64 : if (var3 == new_vard)
11053 : 173 : var3 = NULL_TREE;
11054 : : }
11055 : :
11056 : 205 : tree ptype = build_pointer_type (TREE_TYPE (new_var));
11057 : 205 : tree rpriva = create_tmp_var (ptype);
11058 : 205 : tree nc = build_omp_clause (clause_loc, OMP_CLAUSE__SCANTEMP_);
11059 : 205 : OMP_CLAUSE_DECL (nc) = rpriva;
11060 : 205 : *cp1 = nc;
11061 : 205 : cp1 = &OMP_CLAUSE_CHAIN (nc);
11062 : :
11063 : 205 : tree rprivb = create_tmp_var (ptype);
11064 : 205 : nc = build_omp_clause (clause_loc, OMP_CLAUSE__SCANTEMP_);
11065 : 205 : OMP_CLAUSE_DECL (nc) = rprivb;
11066 : 205 : OMP_CLAUSE__SCANTEMP__ALLOC (nc) = 1;
11067 : 205 : *cp1 = nc;
11068 : 205 : cp1 = &OMP_CLAUSE_CHAIN (nc);
11069 : :
11070 : 205 : tree var2 = create_tmp_var_raw (TREE_TYPE (new_var));
11071 : 205 : if (new_vard != new_var)
11072 : 32 : TREE_ADDRESSABLE (var2) = 1;
11073 : 205 : gimple_add_tmp_var (var2);
11074 : :
11075 : 205 : tree x = fold_convert_loc (clause_loc, sizetype, thread_num);
11076 : 205 : x = fold_build2_loc (clause_loc, MULT_EXPR, sizetype, x,
11077 : 205 : TYPE_SIZE_UNIT (TREE_TYPE (ptype)));
11078 : 205 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (rpriva), rpriva, x);
11079 : 205 : tree rpriva_ref = build_simple_mem_ref_loc (clause_loc, x);
11080 : :
11081 : 205 : x = fold_build2_loc (clause_loc, PLUS_EXPR, integer_type_node,
11082 : : thread_num, integer_minus_one_node);
11083 : 205 : x = fold_convert_loc (clause_loc, sizetype, x);
11084 : 205 : x = fold_build2_loc (clause_loc, MULT_EXPR, sizetype, x,
11085 : 205 : TYPE_SIZE_UNIT (TREE_TYPE (ptype)));
11086 : 205 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (rpriva), rpriva, x);
11087 : 205 : tree rprivam1_ref = build_simple_mem_ref_loc (clause_loc, x);
11088 : :
11089 : 205 : x = fold_convert_loc (clause_loc, sizetype, l);
11090 : 205 : x = fold_build2_loc (clause_loc, MULT_EXPR, sizetype, x,
11091 : 205 : TYPE_SIZE_UNIT (TREE_TYPE (ptype)));
11092 : 205 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (rpriva), rpriva, x);
11093 : 205 : tree rprival_ref = build_simple_mem_ref_loc (clause_loc, x);
11094 : :
11095 : 205 : x = fold_build2_loc (clause_loc, MINUS_EXPR, unsigned_type_node, l, k);
11096 : 205 : x = fold_convert_loc (clause_loc, sizetype, x);
11097 : 205 : x = fold_build2_loc (clause_loc, MULT_EXPR, sizetype, x,
11098 : 205 : TYPE_SIZE_UNIT (TREE_TYPE (ptype)));
11099 : 205 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (rpriva), rpriva, x);
11100 : 205 : tree rprivalmk_ref = build_simple_mem_ref_loc (clause_loc, x);
11101 : :
11102 : 205 : x = fold_build2_loc (clause_loc, MULT_EXPR, sizetype, ivar,
11103 : 205 : TYPE_SIZE_UNIT (TREE_TYPE (ptype)));
11104 : 205 : x = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (rprivb), rprivb, x);
11105 : 205 : tree rprivb_ref = build_simple_mem_ref_loc (clause_loc, x);
11106 : :
11107 : 205 : tree var4 = is_for_simd ? new_var : var2;
11108 : 99 : tree var5 = NULL_TREE, var6 = NULL_TREE;
11109 : 99 : if (is_for_simd)
11110 : : {
11111 : 99 : var5 = lookup_decl (var, input_simd_ctx);
11112 : 99 : var6 = lookup_decl (var, scan_simd_ctx);
11113 : 99 : if (new_vard != new_var)
11114 : : {
11115 : 16 : var5 = build_simple_mem_ref_loc (clause_loc, var5);
11116 : 16 : var6 = build_simple_mem_ref_loc (clause_loc, var6);
11117 : : }
11118 : : }
11119 : 205 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
11120 : : {
11121 : 64 : tree placeholder = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
11122 : 64 : tree val = var2;
11123 : :
11124 : 64 : x = lang_hooks.decls.omp_clause_default_ctor
11125 : 64 : (c, var2, build_outer_var_ref (var, ctx));
11126 : 64 : if (x)
11127 : 32 : gimplify_and_add (x, &clist);
11128 : :
11129 : 64 : x = build_outer_var_ref (var, ctx);
11130 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, unshare_expr (var4),
11131 : : x);
11132 : 64 : gimplify_and_add (x, &thr01_list);
11133 : :
11134 : 64 : tree y = (DECL_HAS_VALUE_EXPR_P (new_vard)
11135 : 64 : ? DECL_VALUE_EXPR (new_vard) : NULL_TREE);
11136 : 64 : if (var3)
11137 : : {
11138 : 32 : x = unshare_expr (var4);
11139 : 32 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var3);
11140 : 32 : gimplify_and_add (x, &thrn1_list);
11141 : 32 : x = unshare_expr (var4);
11142 : 32 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var3);
11143 : 32 : gimplify_and_add (x, &thr02_list);
11144 : : }
11145 : 32 : else if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c))
11146 : : {
11147 : : /* Otherwise, assign to it the identity element. */
11148 : 32 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
11149 : 32 : tseq = copy_gimple_seq_and_replace_locals (tseq);
11150 : 32 : if (!is_for_simd)
11151 : : {
11152 : 16 : if (new_vard != new_var)
11153 : 4 : val = build_fold_addr_expr_loc (clause_loc, val);
11154 : 16 : SET_DECL_VALUE_EXPR (new_vard, val);
11155 : 16 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
11156 : : }
11157 : 32 : SET_DECL_VALUE_EXPR (placeholder, error_mark_node);
11158 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
11159 : 32 : lower_omp (&tseq, ctx);
11160 : 32 : gimple_seq_add_seq (&thrn1_list, tseq);
11161 : 32 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c);
11162 : 32 : lower_omp (&tseq, ctx);
11163 : 32 : gimple_seq_add_seq (&thr02_list, tseq);
11164 : 32 : SET_DECL_VALUE_EXPR (placeholder, NULL_TREE);
11165 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
11166 : 32 : OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c) = NULL;
11167 : 32 : if (y)
11168 : 0 : SET_DECL_VALUE_EXPR (new_vard, y);
11169 : : else
11170 : : {
11171 : 32 : DECL_HAS_VALUE_EXPR_P (new_vard) = 0;
11172 : 32 : SET_DECL_VALUE_EXPR (new_vard, NULL_TREE);
11173 : : }
11174 : : }
11175 : :
11176 : 64 : x = unshare_expr (var4);
11177 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, x, rprivam1_ref);
11178 : 64 : gimplify_and_add (x, &thrn2_list);
11179 : :
11180 : 64 : if (is_for_simd)
11181 : : {
11182 : 32 : x = unshare_expr (rprivb_ref);
11183 : 32 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var5);
11184 : 32 : gimplify_and_add (x, &scan1_list);
11185 : : }
11186 : : else
11187 : : {
11188 : 32 : if (ctx->scan_exclusive)
11189 : : {
11190 : 16 : x = unshare_expr (rprivb_ref);
11191 : 16 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var2);
11192 : 16 : gimplify_and_add (x, &scan1_list);
11193 : : }
11194 : :
11195 : 32 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
11196 : 32 : tseq = copy_gimple_seq_and_replace_locals (tseq);
11197 : 32 : SET_DECL_VALUE_EXPR (placeholder, var2);
11198 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
11199 : 32 : lower_omp (&tseq, ctx);
11200 : 32 : gimple_seq_add_seq (&scan1_list, tseq);
11201 : :
11202 : 32 : if (ctx->scan_inclusive)
11203 : : {
11204 : 16 : x = unshare_expr (rprivb_ref);
11205 : 16 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var2);
11206 : 16 : gimplify_and_add (x, &scan1_list);
11207 : : }
11208 : : }
11209 : :
11210 : 64 : x = unshare_expr (rpriva_ref);
11211 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, x,
11212 : : unshare_expr (var4));
11213 : 64 : gimplify_and_add (x, &mdlist);
11214 : :
11215 : 96 : x = unshare_expr (is_for_simd ? var6 : new_var);
11216 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, x, var4);
11217 : 64 : gimplify_and_add (x, &input2_list);
11218 : :
11219 : 64 : val = rprivb_ref;
11220 : 64 : if (new_vard != new_var)
11221 : 24 : val = build_fold_addr_expr_loc (clause_loc, val);
11222 : :
11223 : 64 : gimple_seq tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
11224 : 64 : tseq = copy_gimple_seq_and_replace_locals (tseq);
11225 : 64 : SET_DECL_VALUE_EXPR (new_vard, val);
11226 : 64 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
11227 : 64 : if (is_for_simd)
11228 : : {
11229 : 32 : SET_DECL_VALUE_EXPR (placeholder, var6);
11230 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
11231 : : }
11232 : : else
11233 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
11234 : 64 : lower_omp (&tseq, ctx);
11235 : 64 : if (y)
11236 : 0 : SET_DECL_VALUE_EXPR (new_vard, y);
11237 : : else
11238 : : {
11239 : 64 : DECL_HAS_VALUE_EXPR_P (new_vard) = 0;
11240 : 64 : SET_DECL_VALUE_EXPR (new_vard, NULL_TREE);
11241 : : }
11242 : 64 : if (!is_for_simd)
11243 : : {
11244 : 32 : SET_DECL_VALUE_EXPR (placeholder, new_var);
11245 : 32 : DECL_HAS_VALUE_EXPR_P (placeholder) = 1;
11246 : 32 : lower_omp (&tseq, ctx);
11247 : : }
11248 : 64 : gimple_seq_add_seq (&input2_list, tseq);
11249 : :
11250 : 64 : x = build_outer_var_ref (var, ctx);
11251 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, x, rpriva_ref);
11252 : 64 : gimplify_and_add (x, &last_list);
11253 : :
11254 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, var2, rprivalmk_ref);
11255 : 64 : gimplify_and_add (x, &reduc_list);
11256 : 64 : tseq = OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c);
11257 : 64 : tseq = copy_gimple_seq_and_replace_locals (tseq);
11258 : 64 : val = rprival_ref;
11259 : 64 : if (new_vard != new_var)
11260 : 24 : val = build_fold_addr_expr_loc (clause_loc, val);
11261 : 64 : SET_DECL_VALUE_EXPR (new_vard, val);
11262 : 64 : DECL_HAS_VALUE_EXPR_P (new_vard) = 1;
11263 : 64 : SET_DECL_VALUE_EXPR (placeholder, var2);
11264 : 64 : lower_omp (&tseq, ctx);
11265 : 64 : OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c) = NULL;
11266 : 64 : SET_DECL_VALUE_EXPR (placeholder, NULL_TREE);
11267 : 64 : DECL_HAS_VALUE_EXPR_P (placeholder) = 0;
11268 : 64 : if (y)
11269 : 0 : SET_DECL_VALUE_EXPR (new_vard, y);
11270 : : else
11271 : : {
11272 : 64 : DECL_HAS_VALUE_EXPR_P (new_vard) = 0;
11273 : 64 : SET_DECL_VALUE_EXPR (new_vard, NULL_TREE);
11274 : : }
11275 : 64 : gimple_seq_add_seq (&reduc_list, tseq);
11276 : 64 : x = lang_hooks.decls.omp_clause_assign_op (c, rprival_ref, var2);
11277 : 64 : gimplify_and_add (x, &reduc_list);
11278 : :
11279 : 64 : x = lang_hooks.decls.omp_clause_dtor (c, var2);
11280 : 64 : if (x)
11281 : 32 : gimplify_and_add (x, dlist);
11282 : : }
11283 : : else
11284 : : {
11285 : 141 : x = build_outer_var_ref (var, ctx);
11286 : 141 : gimplify_assign (unshare_expr (var4), x, &thr01_list);
11287 : :
11288 : 141 : x = omp_reduction_init (c, TREE_TYPE (new_var));
11289 : 141 : gimplify_assign (unshare_expr (var4), unshare_expr (x),
11290 : : &thrn1_list);
11291 : 141 : gimplify_assign (unshare_expr (var4), x, &thr02_list);
11292 : :
11293 : 141 : gimplify_assign (unshare_expr (var4), rprivam1_ref, &thrn2_list);
11294 : :
11295 : 141 : enum tree_code code = OMP_CLAUSE_REDUCTION_CODE (c);
11296 : 141 : if (code == MINUS_EXPR)
11297 : 0 : code = PLUS_EXPR;
11298 : :
11299 : 141 : if (is_for_simd)
11300 : 67 : gimplify_assign (unshare_expr (rprivb_ref), var5, &scan1_list);
11301 : : else
11302 : : {
11303 : 74 : if (ctx->scan_exclusive)
11304 : 28 : gimplify_assign (unshare_expr (rprivb_ref), var2,
11305 : : &scan1_list);
11306 : 74 : x = build2 (code, TREE_TYPE (new_var), var2, new_var);
11307 : 74 : gimplify_assign (var2, x, &scan1_list);
11308 : 74 : if (ctx->scan_inclusive)
11309 : 46 : gimplify_assign (unshare_expr (rprivb_ref), var2,
11310 : : &scan1_list);
11311 : : }
11312 : :
11313 : 141 : gimplify_assign (unshare_expr (rpriva_ref), unshare_expr (var4),
11314 : : &mdlist);
11315 : :
11316 : 141 : x = build2 (code, TREE_TYPE (new_var), var4, rprivb_ref);
11317 : 215 : gimplify_assign (is_for_simd ? var6 : new_var, x, &input2_list);
11318 : :
11319 : 141 : gimplify_assign (build_outer_var_ref (var, ctx), rpriva_ref,
11320 : : &last_list);
11321 : :
11322 : 141 : x = build2 (code, TREE_TYPE (new_var), rprivalmk_ref,
11323 : : unshare_expr (rprival_ref));
11324 : 141 : gimplify_assign (rprival_ref, x, &reduc_list);
11325 : : }
11326 : : }
11327 : :
11328 : 173 : g = gimple_build_assign (ivar, PLUS_EXPR, ivar, size_one_node);
11329 : 173 : gimple_seq_add_stmt (&scan1_list, g);
11330 : 173 : g = gimple_build_assign (ivar, PLUS_EXPR, ivar, size_one_node);
11331 : 263 : gimple_seq_add_stmt (gimple_omp_body_ptr (is_for_simd
11332 : : ? scan_stmt4 : scan_stmt2), g);
11333 : :
11334 : 173 : tree controlb = create_tmp_var (boolean_type_node);
11335 : 173 : tree controlp = create_tmp_var (ptr_type_node);
11336 : 173 : tree nc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SCANTEMP_);
11337 : 173 : OMP_CLAUSE_DECL (nc) = controlb;
11338 : 173 : OMP_CLAUSE__SCANTEMP__CONTROL (nc) = 1;
11339 : 173 : *cp1 = nc;
11340 : 173 : cp1 = &OMP_CLAUSE_CHAIN (nc);
11341 : 173 : nc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SCANTEMP_);
11342 : 173 : OMP_CLAUSE_DECL (nc) = controlp;
11343 : 173 : OMP_CLAUSE__SCANTEMP__CONTROL (nc) = 1;
11344 : 173 : *cp1 = nc;
11345 : 173 : cp1 = &OMP_CLAUSE_CHAIN (nc);
11346 : 173 : nc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SCANTEMP_);
11347 : 173 : OMP_CLAUSE_DECL (nc) = controlb;
11348 : 173 : OMP_CLAUSE__SCANTEMP__CONTROL (nc) = 1;
11349 : 173 : *cp2 = nc;
11350 : 173 : cp2 = &OMP_CLAUSE_CHAIN (nc);
11351 : 173 : nc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__SCANTEMP_);
11352 : 173 : OMP_CLAUSE_DECL (nc) = controlp;
11353 : 173 : OMP_CLAUSE__SCANTEMP__CONTROL (nc) = 1;
11354 : 173 : *cp2 = nc;
11355 : 173 : cp2 = &OMP_CLAUSE_CHAIN (nc);
11356 : :
11357 : 173 : *cp1 = gimple_omp_for_clauses (stmt);
11358 : 173 : gimple_omp_for_set_clauses (stmt, new_clauses1);
11359 : 173 : *cp2 = gimple_omp_for_clauses (new_stmt);
11360 : 173 : gimple_omp_for_set_clauses (new_stmt, new_clauses2);
11361 : :
11362 : 173 : if (is_for_simd)
11363 : : {
11364 : 83 : gimple_seq_add_seq (gimple_omp_body_ptr (scan_stmt3), scan1_list);
11365 : 83 : gimple_seq_add_seq (gimple_omp_body_ptr (input_stmt4), input2_list);
11366 : :
11367 : 83 : gsi_insert_seq_after (&input3_gsi, gimple_omp_body (input_stmt3),
11368 : : GSI_SAME_STMT);
11369 : 83 : gsi_remove (&input3_gsi, true);
11370 : 83 : gsi_insert_seq_after (&scan3_gsi, gimple_omp_body (scan_stmt3),
11371 : : GSI_SAME_STMT);
11372 : 83 : gsi_remove (&scan3_gsi, true);
11373 : 83 : gsi_insert_seq_after (&input4_gsi, gimple_omp_body (input_stmt4),
11374 : : GSI_SAME_STMT);
11375 : 83 : gsi_remove (&input4_gsi, true);
11376 : 83 : gsi_insert_seq_after (&scan4_gsi, gimple_omp_body (scan_stmt4),
11377 : : GSI_SAME_STMT);
11378 : 83 : gsi_remove (&scan4_gsi, true);
11379 : : }
11380 : : else
11381 : : {
11382 : 90 : gimple_omp_set_body (scan_stmt1, scan1_list);
11383 : 90 : gimple_omp_set_body (input_stmt2, input2_list);
11384 : : }
11385 : :
11386 : 173 : gsi_insert_seq_after (&input1_gsi, gimple_omp_body (input_stmt1),
11387 : : GSI_SAME_STMT);
11388 : 173 : gsi_remove (&input1_gsi, true);
11389 : 173 : gsi_insert_seq_after (&scan1_gsi, gimple_omp_body (scan_stmt1),
11390 : : GSI_SAME_STMT);
11391 : 173 : gsi_remove (&scan1_gsi, true);
11392 : 173 : gsi_insert_seq_after (&input2_gsi, gimple_omp_body (input_stmt2),
11393 : : GSI_SAME_STMT);
11394 : 173 : gsi_remove (&input2_gsi, true);
11395 : 173 : gsi_insert_seq_after (&scan2_gsi, gimple_omp_body (scan_stmt2),
11396 : : GSI_SAME_STMT);
11397 : 173 : gsi_remove (&scan2_gsi, true);
11398 : :
11399 : 173 : gimple_seq_add_seq (body_p, clist);
11400 : :
11401 : 173 : tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
11402 : 173 : tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
11403 : 173 : tree lab3 = create_artificial_label (UNKNOWN_LOCATION);
11404 : 173 : g = gimple_build_cond (EQ_EXPR, thread_num, integer_zero_node, lab1, lab2);
11405 : 173 : gimple_seq_add_stmt (body_p, g);
11406 : 173 : g = gimple_build_label (lab1);
11407 : 173 : gimple_seq_add_stmt (body_p, g);
11408 : 173 : gimple_seq_add_seq (body_p, thr01_list);
11409 : 173 : g = gimple_build_goto (lab3);
11410 : 173 : gimple_seq_add_stmt (body_p, g);
11411 : 173 : g = gimple_build_label (lab2);
11412 : 173 : gimple_seq_add_stmt (body_p, g);
11413 : 173 : gimple_seq_add_seq (body_p, thrn1_list);
11414 : 173 : g = gimple_build_label (lab3);
11415 : 173 : gimple_seq_add_stmt (body_p, g);
11416 : :
11417 : 173 : g = gimple_build_assign (ivar, size_zero_node);
11418 : 173 : gimple_seq_add_stmt (body_p, g);
11419 : :
11420 : 173 : gimple_seq_add_stmt (body_p, stmt);
11421 : 173 : gimple_seq_add_seq (body_p, body);
11422 : 173 : gimple_seq_add_stmt (body_p, gimple_build_omp_continue (fd->loop.v,
11423 : : fd->loop.v));
11424 : :
11425 : 173 : g = gimple_build_omp_return (true);
11426 : 173 : gimple_seq_add_stmt (body_p, g);
11427 : 173 : gimple_seq_add_seq (body_p, mdlist);
11428 : :
11429 : 173 : lab1 = create_artificial_label (UNKNOWN_LOCATION);
11430 : 173 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
11431 : 173 : g = gimple_build_cond (GT_EXPR, num_threads, integer_one_node, lab1, lab2);
11432 : 173 : gimple_seq_add_stmt (body_p, g);
11433 : 173 : g = gimple_build_label (lab1);
11434 : 173 : gimple_seq_add_stmt (body_p, g);
11435 : :
11436 : 173 : g = omp_build_barrier (NULL);
11437 : 173 : gimple_seq_add_stmt (body_p, g);
11438 : :
11439 : 173 : tree down = create_tmp_var (unsigned_type_node);
11440 : 173 : g = gimple_build_assign (down, build_zero_cst (unsigned_type_node));
11441 : 173 : gimple_seq_add_stmt (body_p, g);
11442 : :
11443 : 173 : g = gimple_build_assign (k, build_one_cst (unsigned_type_node));
11444 : 173 : gimple_seq_add_stmt (body_p, g);
11445 : :
11446 : 173 : tree num_threadsu = create_tmp_var (unsigned_type_node);
11447 : 173 : g = gimple_build_assign (num_threadsu, NOP_EXPR, num_threads);
11448 : 173 : gimple_seq_add_stmt (body_p, g);
11449 : :
11450 : 173 : tree thread_numu = create_tmp_var (unsigned_type_node);
11451 : 173 : g = gimple_build_assign (thread_numu, NOP_EXPR, thread_num);
11452 : 173 : gimple_seq_add_stmt (body_p, g);
11453 : :
11454 : 173 : tree thread_nump1 = create_tmp_var (unsigned_type_node);
11455 : 173 : g = gimple_build_assign (thread_nump1, PLUS_EXPR, thread_numu,
11456 : : build_int_cst (unsigned_type_node, 1));
11457 : 173 : gimple_seq_add_stmt (body_p, g);
11458 : :
11459 : 173 : lab3 = create_artificial_label (UNKNOWN_LOCATION);
11460 : 173 : g = gimple_build_label (lab3);
11461 : 173 : gimple_seq_add_stmt (body_p, g);
11462 : :
11463 : 173 : tree twok = create_tmp_var (unsigned_type_node);
11464 : 173 : g = gimple_build_assign (twok, LSHIFT_EXPR, k, integer_one_node);
11465 : 173 : gimple_seq_add_stmt (body_p, g);
11466 : :
11467 : 173 : tree lab4 = create_artificial_label (UNKNOWN_LOCATION);
11468 : 173 : tree lab5 = create_artificial_label (UNKNOWN_LOCATION);
11469 : 173 : tree lab6 = create_artificial_label (UNKNOWN_LOCATION);
11470 : 173 : g = gimple_build_cond (GT_EXPR, twok, num_threadsu, lab4, lab5);
11471 : 173 : gimple_seq_add_stmt (body_p, g);
11472 : 173 : g = gimple_build_label (lab4);
11473 : 173 : gimple_seq_add_stmt (body_p, g);
11474 : 173 : g = gimple_build_assign (down, build_all_ones_cst (unsigned_type_node));
11475 : 173 : gimple_seq_add_stmt (body_p, g);
11476 : 173 : g = gimple_build_assign (k, RSHIFT_EXPR, k, integer_one_node);
11477 : 173 : gimple_seq_add_stmt (body_p, g);
11478 : :
11479 : 173 : g = gimple_build_cond (EQ_EXPR, k, num_threadsu, lab6, lab5);
11480 : 173 : gimple_seq_add_stmt (body_p, g);
11481 : 173 : g = gimple_build_label (lab6);
11482 : 173 : gimple_seq_add_stmt (body_p, g);
11483 : :
11484 : 173 : g = gimple_build_assign (k, RSHIFT_EXPR, k, integer_one_node);
11485 : 173 : gimple_seq_add_stmt (body_p, g);
11486 : :
11487 : 173 : g = gimple_build_label (lab5);
11488 : 173 : gimple_seq_add_stmt (body_p, g);
11489 : :
11490 : 173 : g = gimple_build_assign (twok, LSHIFT_EXPR, k, integer_one_node);
11491 : 173 : gimple_seq_add_stmt (body_p, g);
11492 : :
11493 : 173 : tree cplx = create_tmp_var (build_complex_type (unsigned_type_node, false));
11494 : 173 : g = gimple_build_call_internal (IFN_MUL_OVERFLOW, 2, thread_nump1, twok);
11495 : 173 : gimple_call_set_lhs (g, cplx);
11496 : 173 : gimple_seq_add_stmt (body_p, g);
11497 : 173 : tree mul = create_tmp_var (unsigned_type_node);
11498 : 173 : g = gimple_build_assign (mul, REALPART_EXPR,
11499 : : build1 (REALPART_EXPR, unsigned_type_node, cplx));
11500 : 173 : gimple_seq_add_stmt (body_p, g);
11501 : 173 : tree ovf = create_tmp_var (unsigned_type_node);
11502 : 173 : g = gimple_build_assign (ovf, IMAGPART_EXPR,
11503 : : build1 (IMAGPART_EXPR, unsigned_type_node, cplx));
11504 : 173 : gimple_seq_add_stmt (body_p, g);
11505 : :
11506 : 173 : tree lab7 = create_artificial_label (UNKNOWN_LOCATION);
11507 : 173 : tree lab8 = create_artificial_label (UNKNOWN_LOCATION);
11508 : 173 : g = gimple_build_cond (EQ_EXPR, ovf, build_zero_cst (unsigned_type_node),
11509 : : lab7, lab8);
11510 : 173 : gimple_seq_add_stmt (body_p, g);
11511 : 173 : g = gimple_build_label (lab7);
11512 : 173 : gimple_seq_add_stmt (body_p, g);
11513 : :
11514 : 173 : tree andv = create_tmp_var (unsigned_type_node);
11515 : 173 : g = gimple_build_assign (andv, BIT_AND_EXPR, k, down);
11516 : 173 : gimple_seq_add_stmt (body_p, g);
11517 : 173 : tree andvm1 = create_tmp_var (unsigned_type_node);
11518 : 173 : g = gimple_build_assign (andvm1, PLUS_EXPR, andv,
11519 : : build_minus_one_cst (unsigned_type_node));
11520 : 173 : gimple_seq_add_stmt (body_p, g);
11521 : :
11522 : 173 : g = gimple_build_assign (l, PLUS_EXPR, mul, andvm1);
11523 : 173 : gimple_seq_add_stmt (body_p, g);
11524 : :
11525 : 173 : tree lab9 = create_artificial_label (UNKNOWN_LOCATION);
11526 : 173 : g = gimple_build_cond (LT_EXPR, l, num_threadsu, lab9, lab8);
11527 : 173 : gimple_seq_add_stmt (body_p, g);
11528 : 173 : g = gimple_build_label (lab9);
11529 : 173 : gimple_seq_add_stmt (body_p, g);
11530 : 173 : gimple_seq_add_seq (body_p, reduc_list);
11531 : 173 : g = gimple_build_label (lab8);
11532 : 173 : gimple_seq_add_stmt (body_p, g);
11533 : :
11534 : 173 : tree lab10 = create_artificial_label (UNKNOWN_LOCATION);
11535 : 173 : tree lab11 = create_artificial_label (UNKNOWN_LOCATION);
11536 : 173 : tree lab12 = create_artificial_label (UNKNOWN_LOCATION);
11537 : 173 : g = gimple_build_cond (EQ_EXPR, down, build_zero_cst (unsigned_type_node),
11538 : : lab10, lab11);
11539 : 173 : gimple_seq_add_stmt (body_p, g);
11540 : 173 : g = gimple_build_label (lab10);
11541 : 173 : gimple_seq_add_stmt (body_p, g);
11542 : 173 : g = gimple_build_assign (k, LSHIFT_EXPR, k, integer_one_node);
11543 : 173 : gimple_seq_add_stmt (body_p, g);
11544 : 173 : g = gimple_build_goto (lab12);
11545 : 173 : gimple_seq_add_stmt (body_p, g);
11546 : 173 : g = gimple_build_label (lab11);
11547 : 173 : gimple_seq_add_stmt (body_p, g);
11548 : 173 : g = gimple_build_assign (k, RSHIFT_EXPR, k, integer_one_node);
11549 : 173 : gimple_seq_add_stmt (body_p, g);
11550 : 173 : g = gimple_build_label (lab12);
11551 : 173 : gimple_seq_add_stmt (body_p, g);
11552 : :
11553 : 173 : g = omp_build_barrier (NULL);
11554 : 173 : gimple_seq_add_stmt (body_p, g);
11555 : :
11556 : 173 : g = gimple_build_cond (NE_EXPR, k, build_zero_cst (unsigned_type_node),
11557 : : lab3, lab2);
11558 : 173 : gimple_seq_add_stmt (body_p, g);
11559 : :
11560 : 173 : g = gimple_build_label (lab2);
11561 : 173 : gimple_seq_add_stmt (body_p, g);
11562 : :
11563 : 173 : lab1 = create_artificial_label (UNKNOWN_LOCATION);
11564 : 173 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
11565 : 173 : lab3 = create_artificial_label (UNKNOWN_LOCATION);
11566 : 173 : g = gimple_build_cond (EQ_EXPR, thread_num, integer_zero_node, lab1, lab2);
11567 : 173 : gimple_seq_add_stmt (body_p, g);
11568 : 173 : g = gimple_build_label (lab1);
11569 : 173 : gimple_seq_add_stmt (body_p, g);
11570 : 173 : gimple_seq_add_seq (body_p, thr02_list);
11571 : 173 : g = gimple_build_goto (lab3);
11572 : 173 : gimple_seq_add_stmt (body_p, g);
11573 : 173 : g = gimple_build_label (lab2);
11574 : 173 : gimple_seq_add_stmt (body_p, g);
11575 : 173 : gimple_seq_add_seq (body_p, thrn2_list);
11576 : 173 : g = gimple_build_label (lab3);
11577 : 173 : gimple_seq_add_stmt (body_p, g);
11578 : :
11579 : 173 : g = gimple_build_assign (ivar, size_zero_node);
11580 : 173 : gimple_seq_add_stmt (body_p, g);
11581 : 173 : gimple_seq_add_stmt (body_p, new_stmt);
11582 : 173 : gimple_seq_add_seq (body_p, new_body);
11583 : :
11584 : 173 : gimple_seq new_dlist = NULL;
11585 : 173 : lab1 = create_artificial_label (UNKNOWN_LOCATION);
11586 : 173 : lab2 = create_artificial_label (UNKNOWN_LOCATION);
11587 : 173 : tree num_threadsm1 = create_tmp_var (integer_type_node);
11588 : 173 : g = gimple_build_assign (num_threadsm1, PLUS_EXPR, num_threads,
11589 : : integer_minus_one_node);
11590 : 173 : gimple_seq_add_stmt (&new_dlist, g);
11591 : 173 : g = gimple_build_cond (EQ_EXPR, thread_num, num_threadsm1, lab1, lab2);
11592 : 173 : gimple_seq_add_stmt (&new_dlist, g);
11593 : 173 : g = gimple_build_label (lab1);
11594 : 173 : gimple_seq_add_stmt (&new_dlist, g);
11595 : 173 : gimple_seq_add_seq (&new_dlist, last_list);
11596 : 173 : g = gimple_build_label (lab2);
11597 : 173 : gimple_seq_add_stmt (&new_dlist, g);
11598 : 173 : gimple_seq_add_seq (&new_dlist, *dlist);
11599 : 173 : *dlist = new_dlist;
11600 : 173 : }
11601 : :
11602 : : /* Build an internal UNIQUE function with type IFN_UNIQUE_OACC_PRIVATE listing
11603 : : the addresses of variables to be made private at the surrounding
11604 : : parallelism level. Such functions appear in the gimple code stream in two
11605 : : forms, e.g. for a partitioned loop:
11606 : :
11607 : : .data_dep.6 = .UNIQUE (OACC_HEAD_MARK, .data_dep.6, 1, 68);
11608 : : .data_dep.6 = .UNIQUE (OACC_PRIVATE, .data_dep.6, -1, &w);
11609 : : .data_dep.6 = .UNIQUE (OACC_FORK, .data_dep.6, -1);
11610 : : .data_dep.6 = .UNIQUE (OACC_HEAD_MARK, .data_dep.6);
11611 : :
11612 : : or alternatively, OACC_PRIVATE can appear at the top level of a parallel,
11613 : : not as part of a HEAD_MARK sequence:
11614 : :
11615 : : .UNIQUE (OACC_PRIVATE, 0, 0, &w);
11616 : :
11617 : : For such stand-alone appearances, the 3rd argument is always 0, denoting
11618 : : gang partitioning. */
11619 : :
11620 : : static gcall *
11621 : 19722 : lower_oacc_private_marker (omp_context *ctx)
11622 : : {
11623 : 19722 : if (ctx->oacc_privatization_candidates.length () == 0)
11624 : : return NULL;
11625 : :
11626 : 307 : auto_vec<tree, 5> args;
11627 : :
11628 : 307 : args.quick_push (build_int_cst (integer_type_node, IFN_UNIQUE_OACC_PRIVATE));
11629 : 307 : args.quick_push (integer_zero_node);
11630 : 307 : args.quick_push (integer_minus_one_node);
11631 : :
11632 : 307 : int i;
11633 : 307 : tree decl;
11634 : 694 : FOR_EACH_VEC_ELT (ctx->oacc_privatization_candidates, i, decl)
11635 : : {
11636 : 387 : gcc_checking_assert (TREE_ADDRESSABLE (decl));
11637 : 387 : tree addr = build_fold_addr_expr (decl);
11638 : 387 : args.safe_push (addr);
11639 : : }
11640 : :
11641 : 307 : return gimple_build_call_internal_vec (IFN_UNIQUE, args);
11642 : 307 : }
11643 : :
11644 : : /* Lower code for an OMP loop directive. */
11645 : :
11646 : : static void
11647 : 46865 : lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
11648 : : {
11649 : 46865 : tree *rhs_p, block;
11650 : 46865 : struct omp_for_data fd, *fdp = NULL;
11651 : 46865 : gomp_for *stmt = as_a <gomp_for *> (gsi_stmt (*gsi_p));
11652 : 46865 : gbind *new_stmt;
11653 : 46865 : gimple_seq omp_for_body, body, dlist, tred_ilist = NULL, tred_dlist = NULL;
11654 : 46865 : gimple_seq cnt_list = NULL, clist = NULL;
11655 : 46865 : gimple_seq oacc_head = NULL, oacc_tail = NULL;
11656 : 46865 : size_t i;
11657 : :
11658 : 46865 : push_gimplify_context ();
11659 : :
11660 : 46865 : if (is_gimple_omp_oacc (ctx->stmt))
11661 : 11323 : oacc_privatization_scan_clause_chain (ctx, gimple_omp_for_clauses (stmt));
11662 : :
11663 : 46865 : lower_omp (gimple_omp_for_pre_body_ptr (stmt), ctx);
11664 : :
11665 : 46865 : block = make_node (BLOCK);
11666 : 46865 : new_stmt = gimple_build_bind (NULL, NULL, block);
11667 : : /* Replace at gsi right away, so that 'stmt' is no member
11668 : : of a sequence anymore as we're going to add to a different
11669 : : one below. */
11670 : 46865 : gsi_replace (gsi_p, new_stmt, true);
11671 : :
11672 : : /* Move declaration of temporaries in the loop body before we make
11673 : : it go away. */
11674 : 46865 : omp_for_body = gimple_omp_body (stmt);
11675 : 46865 : if (!gimple_seq_empty_p (omp_for_body)
11676 : 46865 : && gimple_code (gimple_seq_first_stmt (omp_for_body)) == GIMPLE_BIND)
11677 : : {
11678 : 19593 : gbind *inner_bind
11679 : 19593 : = as_a <gbind *> (gimple_seq_first_stmt (omp_for_body));
11680 : 19593 : tree vars = gimple_bind_vars (inner_bind);
11681 : 19593 : if (is_gimple_omp_oacc (ctx->stmt))
11682 : 5303 : oacc_privatization_scan_decl_chain (ctx, vars);
11683 : 19593 : gimple_bind_append_vars (new_stmt, vars);
11684 : : /* bind_vars/BLOCK_VARS are being moved to new_stmt/block, don't
11685 : : keep them on the inner_bind and it's block. */
11686 : 19593 : gimple_bind_set_vars (inner_bind, NULL_TREE);
11687 : 19593 : if (gimple_bind_block (inner_bind))
11688 : 17037 : BLOCK_VARS (gimple_bind_block (inner_bind)) = NULL_TREE;
11689 : : }
11690 : :
11691 : 46865 : if (gimple_omp_for_combined_into_p (stmt))
11692 : : {
11693 : 14595 : omp_extract_for_data (stmt, &fd, NULL);
11694 : 14595 : fdp = &fd;
11695 : :
11696 : : /* We need two temporaries with fd.loop.v type (istart/iend)
11697 : : and then (fd.collapse - 1) temporaries with the same
11698 : : type for count2 ... countN-1 vars if not constant. */
11699 : 14595 : size_t count = 2;
11700 : 14595 : tree type = fd.iter_type;
11701 : 14595 : if (fd.collapse > 1
11702 : 4864 : && TREE_CODE (fd.loop.n2) != INTEGER_CST)
11703 : 2692 : count += fd.collapse - 1;
11704 : 14595 : size_t count2 = 0;
11705 : 14595 : tree type2 = NULL_TREE;
11706 : 14595 : bool taskreg_for
11707 : 14595 : = (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_FOR
11708 : 14595 : || gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_TASKLOOP);
11709 : 14595 : tree outerc = NULL, *pc = gimple_omp_for_clauses_ptr (stmt);
11710 : 14595 : tree simtc = NULL;
11711 : 14595 : tree clauses = *pc;
11712 : 14595 : if (fd.collapse > 1
11713 : 4864 : && fd.non_rect
11714 : 137 : && fd.last_nonrect == fd.first_nonrect + 1
11715 : 89 : && TREE_CODE (fd.loop.n2) != INTEGER_CST)
11716 : 64 : if (tree v = gimple_omp_for_index (stmt, fd.last_nonrect))
11717 : 64 : if (!TYPE_UNSIGNED (TREE_TYPE (v)))
11718 : : {
11719 : 60 : v = gimple_omp_for_index (stmt, fd.first_nonrect);
11720 : 60 : type2 = TREE_TYPE (v);
11721 : 60 : count++;
11722 : 60 : count2 = 3;
11723 : : }
11724 : 14595 : if (taskreg_for)
11725 : 7591 : outerc
11726 : 7591 : = omp_find_clause (gimple_omp_taskreg_clauses (ctx->outer->stmt),
11727 : : OMP_CLAUSE__LOOPTEMP_);
11728 : 14595 : if (ctx->simt_stmt)
11729 : 0 : simtc = omp_find_clause (gimple_omp_for_clauses (ctx->simt_stmt),
11730 : : OMP_CLAUSE__LOOPTEMP_);
11731 : 49194 : for (i = 0; i < count + count2; i++)
11732 : : {
11733 : 34599 : tree temp;
11734 : 34599 : if (taskreg_for)
11735 : : {
11736 : 18063 : gcc_assert (outerc);
11737 : 18063 : temp = lookup_decl (OMP_CLAUSE_DECL (outerc), ctx->outer);
11738 : 18063 : outerc = omp_find_clause (OMP_CLAUSE_CHAIN (outerc),
11739 : : OMP_CLAUSE__LOOPTEMP_);
11740 : : }
11741 : : else
11742 : : {
11743 : : /* If there are 2 adjacent SIMD stmts, one with _simt_
11744 : : clause, another without, make sure they have the same
11745 : : decls in _looptemp_ clauses, because the outer stmt
11746 : : they are combined into will look up just one inner_stmt. */
11747 : 16536 : if (ctx->simt_stmt)
11748 : 0 : temp = OMP_CLAUSE_DECL (simtc);
11749 : : else
11750 : 32928 : temp = create_tmp_var (i >= count ? type2 : type);
11751 : 16536 : insert_decl_map (&ctx->outer->cb, temp, temp);
11752 : : }
11753 : 34599 : *pc = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__LOOPTEMP_);
11754 : 34599 : OMP_CLAUSE_DECL (*pc) = temp;
11755 : 34599 : pc = &OMP_CLAUSE_CHAIN (*pc);
11756 : 34599 : if (ctx->simt_stmt)
11757 : 0 : simtc = omp_find_clause (OMP_CLAUSE_CHAIN (simtc),
11758 : : OMP_CLAUSE__LOOPTEMP_);
11759 : : }
11760 : 14595 : *pc = clauses;
11761 : : }
11762 : :
11763 : : /* The pre-body and input clauses go before the lowered GIMPLE_OMP_FOR. */
11764 : 46865 : dlist = NULL;
11765 : 46865 : body = NULL;
11766 : 46865 : tree rclauses
11767 : 46865 : = omp_task_reductions_find_first (gimple_omp_for_clauses (stmt), OMP_FOR,
11768 : : OMP_CLAUSE_REDUCTION);
11769 : 46865 : tree rtmp = NULL_TREE;
11770 : 46865 : if (rclauses)
11771 : : {
11772 : 227 : tree type = build_pointer_type (pointer_sized_int_node);
11773 : 227 : tree temp = create_tmp_var (type);
11774 : 227 : tree c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE__REDUCTEMP_);
11775 : 227 : OMP_CLAUSE_DECL (c) = temp;
11776 : 227 : OMP_CLAUSE_CHAIN (c) = gimple_omp_for_clauses (stmt);
11777 : 227 : gimple_omp_for_set_clauses (stmt, c);
11778 : 227 : lower_omp_task_reductions (ctx, OMP_FOR,
11779 : : gimple_omp_for_clauses (stmt),
11780 : : &tred_ilist, &tred_dlist);
11781 : 227 : rclauses = c;
11782 : 227 : rtmp = make_ssa_name (type);
11783 : 227 : gimple_seq_add_stmt (&body, gimple_build_assign (rtmp, temp));
11784 : : }
11785 : :
11786 : 46865 : lower_lastprivate_conditional_clauses (gimple_omp_for_clauses_ptr (stmt),
11787 : : ctx);
11788 : :
11789 : 46865 : lower_rec_input_clauses (gimple_omp_for_clauses (stmt), &body, &dlist, ctx,
11790 : : fdp);
11791 : 93503 : gimple_seq_add_seq (rclauses ? &tred_ilist : &body,
11792 : : gimple_omp_for_pre_body (stmt));
11793 : :
11794 : 46865 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
11795 : :
11796 : 46865 : gcall *private_marker = NULL;
11797 : 46865 : if (is_gimple_omp_oacc (ctx->stmt)
11798 : 46865 : && !gimple_seq_empty_p (omp_for_body))
11799 : 10331 : private_marker = lower_oacc_private_marker (ctx);
11800 : :
11801 : : /* Lower the header expressions. At this point, we can assume that
11802 : : the header is of the form:
11803 : :
11804 : : #pragma omp for (V = VAL1; V {<|>|<=|>=} VAL2; V = V [+-] VAL3)
11805 : :
11806 : : We just need to make sure that VAL1, VAL2 and VAL3 are lowered
11807 : : using the .omp_data_s mapping, if needed. */
11808 : 115007 : for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
11809 : : {
11810 : 68142 : rhs_p = gimple_omp_for_initial_ptr (stmt, i);
11811 : 68142 : if (TREE_CODE (*rhs_p) == TREE_VEC)
11812 : : {
11813 : 639 : if (!is_gimple_min_invariant (TREE_VEC_ELT (*rhs_p, 1)))
11814 : 149 : TREE_VEC_ELT (*rhs_p, 1)
11815 : 298 : = get_formal_tmp_var (TREE_VEC_ELT (*rhs_p, 1), &cnt_list);
11816 : 639 : if (!is_gimple_min_invariant (TREE_VEC_ELT (*rhs_p, 2)))
11817 : 161 : TREE_VEC_ELT (*rhs_p, 2)
11818 : 322 : = get_formal_tmp_var (TREE_VEC_ELT (*rhs_p, 2), &cnt_list);
11819 : : }
11820 : 67503 : else if (!is_gimple_min_invariant (*rhs_p))
11821 : 11461 : *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
11822 : 56042 : else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
11823 : 4713 : recompute_tree_invariant_for_addr_expr (*rhs_p);
11824 : :
11825 : 68142 : rhs_p = gimple_omp_for_final_ptr (stmt, i);
11826 : 68142 : if (TREE_CODE (*rhs_p) == TREE_VEC)
11827 : : {
11828 : 519 : if (!is_gimple_min_invariant (TREE_VEC_ELT (*rhs_p, 1)))
11829 : 142 : TREE_VEC_ELT (*rhs_p, 1)
11830 : 284 : = get_formal_tmp_var (TREE_VEC_ELT (*rhs_p, 1), &cnt_list);
11831 : 519 : if (!is_gimple_min_invariant (TREE_VEC_ELT (*rhs_p, 2)))
11832 : 157 : TREE_VEC_ELT (*rhs_p, 2)
11833 : 314 : = get_formal_tmp_var (TREE_VEC_ELT (*rhs_p, 2), &cnt_list);
11834 : : }
11835 : 67623 : else if (!is_gimple_min_invariant (*rhs_p))
11836 : 16783 : *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
11837 : 50840 : else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
11838 : 4630 : recompute_tree_invariant_for_addr_expr (*rhs_p);
11839 : :
11840 : 68142 : rhs_p = &TREE_OPERAND (gimple_omp_for_incr (stmt, i), 1);
11841 : 68142 : if (!is_gimple_min_invariant (*rhs_p))
11842 : 6314 : *rhs_p = get_formal_tmp_var (*rhs_p, &cnt_list);
11843 : : }
11844 : 46865 : if (rclauses)
11845 : 227 : gimple_seq_add_seq (&tred_ilist, cnt_list);
11846 : : else
11847 : 46638 : gimple_seq_add_seq (&body, cnt_list);
11848 : :
11849 : : /* Once lowered, extract the bounds and clauses. */
11850 : 46865 : omp_extract_for_data (stmt, &fd, NULL);
11851 : :
11852 : 46865 : if (is_gimple_omp_oacc (ctx->stmt)
11853 : 46865 : && !ctx_in_oacc_kernels_region (ctx))
11854 : 9665 : lower_oacc_head_tail (gimple_location (stmt),
11855 : : gimple_omp_for_clauses (stmt), private_marker,
11856 : : &oacc_head, &oacc_tail, ctx);
11857 : :
11858 : : /* Add OpenACC partitioning and reduction markers just before the loop. */
11859 : 46865 : if (oacc_head)
11860 : 9665 : gimple_seq_add_seq (&body, oacc_head);
11861 : :
11862 : 46865 : lower_omp_for_lastprivate (&fd, &body, &dlist, &clist, ctx);
11863 : :
11864 : 46865 : if (gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_FOR)
11865 : 85742 : for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c))
11866 : 70188 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
11867 : 70188 : && !OMP_CLAUSE_LINEAR_NO_COPYIN (c))
11868 : : {
11869 : 227 : OMP_CLAUSE_DECL (c) = lookup_decl (OMP_CLAUSE_DECL (c), ctx);
11870 : 227 : if (DECL_P (OMP_CLAUSE_LINEAR_STEP (c)))
11871 : 42 : OMP_CLAUSE_LINEAR_STEP (c)
11872 : 84 : = maybe_lookup_decl_in_outer_ctx (OMP_CLAUSE_LINEAR_STEP (c),
11873 : : ctx);
11874 : : }
11875 : :
11876 : 46499 : if ((ctx->scan_inclusive || ctx->scan_exclusive)
11877 : 47133 : && gimple_omp_for_kind (stmt) == GF_OMP_FOR_KIND_FOR)
11878 : 173 : lower_omp_for_scan (&body, &dlist, stmt, &fd, ctx);
11879 : : else
11880 : : {
11881 : 46692 : gimple_seq_add_stmt (&body, stmt);
11882 : 46692 : gimple_seq_add_seq (&body, gimple_omp_body (stmt));
11883 : : }
11884 : :
11885 : 46865 : gimple_seq_add_stmt (&body, gimple_build_omp_continue (fd.loop.v,
11886 : : fd.loop.v));
11887 : :
11888 : : /* After the loop, add exit clauses. */
11889 : 46865 : lower_reduction_clauses (gimple_omp_for_clauses (stmt), &body, &clist, ctx);
11890 : :
11891 : 46865 : if (clist)
11892 : : {
11893 : 179 : tree fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START);
11894 : 179 : gcall *g = gimple_build_call (fndecl, 0);
11895 : 179 : gimple_seq_add_stmt (&body, g);
11896 : 179 : gimple_seq_add_seq (&body, clist);
11897 : 179 : fndecl = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END);
11898 : 179 : g = gimple_build_call (fndecl, 0);
11899 : 179 : gimple_seq_add_stmt (&body, g);
11900 : : }
11901 : :
11902 : 46865 : if (ctx->cancellable)
11903 : 84 : gimple_seq_add_stmt (&body, gimple_build_label (ctx->cancel_label));
11904 : :
11905 : 46865 : gimple_seq_add_seq (&body, dlist);
11906 : :
11907 : 46865 : if (rclauses)
11908 : : {
11909 : 227 : gimple_seq_add_seq (&tred_ilist, body);
11910 : 227 : body = tred_ilist;
11911 : : }
11912 : :
11913 : 46865 : body = maybe_catch_exception (body);
11914 : :
11915 : : /* Region exit marker goes at the end of the loop body. */
11916 : 46865 : gimple *g = gimple_build_omp_return (fd.have_nowait);
11917 : 46865 : gimple_seq_add_stmt (&body, g);
11918 : :
11919 : 46865 : gimple_seq_add_seq (&body, tred_dlist);
11920 : :
11921 : 46865 : maybe_add_implicit_barrier_cancel (ctx, g, &body);
11922 : :
11923 : 46865 : if (rclauses)
11924 : 227 : OMP_CLAUSE_DECL (rclauses) = rtmp;
11925 : :
11926 : : /* Add OpenACC joining and reduction markers just after the loop. */
11927 : 46865 : if (oacc_tail)
11928 : 9665 : gimple_seq_add_seq (&body, oacc_tail);
11929 : :
11930 : 46865 : pop_gimplify_context (new_stmt);
11931 : :
11932 : 46865 : gimple_bind_append_vars (new_stmt, ctx->block_vars);
11933 : 46865 : maybe_remove_omp_member_access_dummy_vars (new_stmt);
11934 : 46865 : BLOCK_VARS (block) = gimple_bind_vars (new_stmt);
11935 : 46865 : if (BLOCK_VARS (block))
11936 : 46228 : TREE_USED (block) = 1;
11937 : :
11938 : 46865 : gimple_bind_set_body (new_stmt, body);
11939 : 46865 : gimple_omp_set_body (stmt, NULL);
11940 : 46865 : gimple_omp_for_set_pre_body (stmt, NULL);
11941 : 46865 : }
11942 : :
11943 : : /* Callback for walk_stmts. Check if the current statement only contains
11944 : : GIMPLE_OMP_FOR or GIMPLE_OMP_SECTIONS. */
11945 : :
11946 : : static tree
11947 : 212703 : check_combined_parallel (gimple_stmt_iterator *gsi_p,
11948 : : bool *handled_ops_p,
11949 : : struct walk_stmt_info *wi)
11950 : : {
11951 : 212703 : int *info = (int *) wi->info;
11952 : 212703 : gimple *stmt = gsi_stmt (*gsi_p);
11953 : :
11954 : 212703 : *handled_ops_p = true;
11955 : 212703 : switch (gimple_code (stmt))
11956 : : {
11957 : 11454 : WALK_SUBSTMTS;
11958 : :
11959 : : case GIMPLE_DEBUG:
11960 : : break;
11961 : 1899 : case GIMPLE_OMP_FOR:
11962 : 1899 : case GIMPLE_OMP_SECTIONS:
11963 : 1899 : *info = *info == 0 ? 1 : -1;
11964 : 1899 : break;
11965 : 199311 : default:
11966 : 199311 : *info = -1;
11967 : 199311 : break;
11968 : : }
11969 : 212703 : return NULL;
11970 : : }
11971 : :
11972 : : struct omp_taskcopy_context
11973 : : {
11974 : : /* This field must be at the beginning, as we do "inheritance": Some
11975 : : callback functions for tree-inline.cc (e.g., omp_copy_decl)
11976 : : receive a copy_body_data pointer that is up-casted to an
11977 : : omp_context pointer. */
11978 : : copy_body_data cb;
11979 : : omp_context *ctx;
11980 : : };
11981 : :
11982 : : static tree
11983 : 366 : task_copyfn_copy_decl (tree var, copy_body_data *cb)
11984 : : {
11985 : 366 : struct omp_taskcopy_context *tcctx = (struct omp_taskcopy_context *) cb;
11986 : :
11987 : 366 : if (splay_tree_lookup (tcctx->ctx->sfield_map, (splay_tree_key) var))
11988 : 158 : return create_tmp_var (TREE_TYPE (var));
11989 : :
11990 : : return var;
11991 : : }
11992 : :
11993 : : static tree
11994 : 50 : task_copyfn_remap_type (struct omp_taskcopy_context *tcctx, tree orig_type)
11995 : : {
11996 : 50 : tree name, new_fields = NULL, type, f;
11997 : :
11998 : 50 : type = lang_hooks.types.make_type (RECORD_TYPE);
11999 : 50 : name = DECL_NAME (TYPE_NAME (orig_type));
12000 : 50 : name = build_decl (gimple_location (tcctx->ctx->stmt),
12001 : : TYPE_DECL, name, type);
12002 : 50 : TYPE_NAME (type) = name;
12003 : :
12004 : 1140 : for (f = TYPE_FIELDS (orig_type); f ; f = TREE_CHAIN (f))
12005 : : {
12006 : 1090 : tree new_f = copy_node (f);
12007 : 1090 : DECL_CONTEXT (new_f) = type;
12008 : 1090 : TREE_TYPE (new_f) = remap_type (TREE_TYPE (f), &tcctx->cb);
12009 : 1090 : TREE_CHAIN (new_f) = new_fields;
12010 : 1090 : walk_tree (&DECL_SIZE (new_f), copy_tree_body_r, &tcctx->cb, NULL);
12011 : 1090 : walk_tree (&DECL_SIZE_UNIT (new_f), copy_tree_body_r, &tcctx->cb, NULL);
12012 : 1090 : walk_tree (&DECL_FIELD_OFFSET (new_f), copy_tree_body_r,
12013 : : &tcctx->cb, NULL);
12014 : 1090 : new_fields = new_f;
12015 : 1090 : tcctx->cb.decl_map->put (f, new_f);
12016 : : }
12017 : 50 : TYPE_FIELDS (type) = nreverse (new_fields);
12018 : 50 : layout_type (type);
12019 : 50 : return type;
12020 : : }
12021 : :
12022 : : /* Create task copyfn. */
12023 : :
12024 : : static void
12025 : 504 : create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
12026 : : {
12027 : 504 : struct function *child_cfun;
12028 : 504 : tree child_fn, t, c, src, dst, f, sf, arg, sarg, decl;
12029 : 504 : tree record_type, srecord_type, bind, list;
12030 : 504 : bool record_needs_remap = false, srecord_needs_remap = false;
12031 : 504 : splay_tree_node n;
12032 : 504 : struct omp_taskcopy_context tcctx;
12033 : 504 : location_t loc = gimple_location (task_stmt);
12034 : 504 : size_t looptempno = 0;
12035 : :
12036 : 504 : child_fn = gimple_omp_task_copy_fn (task_stmt);
12037 : 504 : task_cpyfns.safe_push (task_stmt);
12038 : 504 : child_cfun = DECL_STRUCT_FUNCTION (child_fn);
12039 : 504 : gcc_assert (child_cfun->cfg == NULL);
12040 : 504 : DECL_SAVED_TREE (child_fn) = alloc_stmt_list ();
12041 : :
12042 : : /* Reset DECL_CONTEXT on function arguments. */
12043 : 1512 : for (t = DECL_ARGUMENTS (child_fn); t; t = DECL_CHAIN (t))
12044 : 1008 : DECL_CONTEXT (t) = child_fn;
12045 : :
12046 : : /* Populate the function. */
12047 : 504 : push_gimplify_context ();
12048 : 504 : push_cfun (child_cfun);
12049 : :
12050 : 504 : bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
12051 : 504 : TREE_SIDE_EFFECTS (bind) = 1;
12052 : 504 : list = NULL;
12053 : 504 : DECL_SAVED_TREE (child_fn) = bind;
12054 : 504 : DECL_SOURCE_LOCATION (child_fn) = gimple_location (task_stmt);
12055 : :
12056 : : /* Remap src and dst argument types if needed. */
12057 : 504 : record_type = ctx->record_type;
12058 : 504 : srecord_type = ctx->srecord_type;
12059 : 3100 : for (f = TYPE_FIELDS (record_type); f ; f = DECL_CHAIN (f))
12060 : 2621 : if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
12061 : : {
12062 : : record_needs_remap = true;
12063 : : break;
12064 : : }
12065 : 2839 : for (f = TYPE_FIELDS (srecord_type); f ; f = DECL_CHAIN (f))
12066 : 2360 : if (variably_modified_type_p (TREE_TYPE (f), ctx->cb.src_fn))
12067 : : {
12068 : : srecord_needs_remap = true;
12069 : : break;
12070 : : }
12071 : :
12072 : 504 : if (record_needs_remap || srecord_needs_remap)
12073 : : {
12074 : 25 : memset (&tcctx, '\0', sizeof (tcctx));
12075 : 25 : tcctx.cb.src_fn = ctx->cb.src_fn;
12076 : 25 : tcctx.cb.dst_fn = child_fn;
12077 : 25 : tcctx.cb.src_node = cgraph_node::get (tcctx.cb.src_fn);
12078 : 25 : gcc_checking_assert (tcctx.cb.src_node);
12079 : 25 : tcctx.cb.dst_node = tcctx.cb.src_node;
12080 : 25 : tcctx.cb.src_cfun = ctx->cb.src_cfun;
12081 : 25 : tcctx.cb.copy_decl = task_copyfn_copy_decl;
12082 : 25 : tcctx.cb.eh_lp_nr = 0;
12083 : 25 : tcctx.cb.transform_call_graph_edges = CB_CGE_MOVE;
12084 : 25 : tcctx.cb.decl_map = new hash_map<tree, tree>;
12085 : 25 : tcctx.ctx = ctx;
12086 : :
12087 : 25 : if (record_needs_remap)
12088 : 25 : record_type = task_copyfn_remap_type (&tcctx, record_type);
12089 : 25 : if (srecord_needs_remap)
12090 : 25 : srecord_type = task_copyfn_remap_type (&tcctx, srecord_type);
12091 : : }
12092 : : else
12093 : 479 : tcctx.cb.decl_map = NULL;
12094 : :
12095 : 504 : arg = DECL_ARGUMENTS (child_fn);
12096 : 504 : TREE_TYPE (arg) = build_pointer_type (record_type);
12097 : 504 : sarg = DECL_CHAIN (arg);
12098 : 504 : TREE_TYPE (sarg) = build_pointer_type (srecord_type);
12099 : :
12100 : : /* First pass: initialize temporaries used in record_type and srecord_type
12101 : : sizes and field offsets. */
12102 : 504 : if (tcctx.cb.decl_map)
12103 : 631 : for (c = gimple_omp_task_clauses (task_stmt); c; c = OMP_CLAUSE_CHAIN (c))
12104 : 606 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
12105 : : {
12106 : 497 : tree *p;
12107 : :
12108 : 497 : decl = OMP_CLAUSE_DECL (c);
12109 : 497 : p = tcctx.cb.decl_map->get (decl);
12110 : 497 : if (p == NULL)
12111 : 339 : continue;
12112 : 158 : n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl);
12113 : 158 : sf = (tree) n->value;
12114 : 158 : sf = *tcctx.cb.decl_map->get (sf);
12115 : 158 : src = build_simple_mem_ref_loc (loc, sarg);
12116 : 158 : src = omp_build_component_ref (src, sf);
12117 : 158 : t = build2 (MODIFY_EXPR, TREE_TYPE (*p), *p, src);
12118 : 158 : append_to_statement_list (t, &list);
12119 : : }
12120 : :
12121 : : /* Second pass: copy shared var pointers and copy construct non-VLA
12122 : : firstprivate vars. */
12123 : 5848 : for (c = gimple_omp_task_clauses (task_stmt); c; c = OMP_CLAUSE_CHAIN (c))
12124 : 5344 : switch (OMP_CLAUSE_CODE (c))
12125 : : {
12126 : 581 : splay_tree_key key;
12127 : 581 : case OMP_CLAUSE_SHARED:
12128 : 581 : decl = OMP_CLAUSE_DECL (c);
12129 : 581 : key = (splay_tree_key) decl;
12130 : 581 : if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c))
12131 : 273 : key = (splay_tree_key) &DECL_UID (decl);
12132 : 581 : n = splay_tree_lookup (ctx->field_map, key);
12133 : 581 : if (n == NULL)
12134 : : break;
12135 : 147 : f = (tree) n->value;
12136 : 147 : if (tcctx.cb.decl_map)
12137 : 12 : f = *tcctx.cb.decl_map->get (f);
12138 : 147 : n = splay_tree_lookup (ctx->sfield_map, key);
12139 : 147 : sf = (tree) n->value;
12140 : 147 : if (tcctx.cb.decl_map)
12141 : 12 : sf = *tcctx.cb.decl_map->get (sf);
12142 : 147 : src = build_simple_mem_ref_loc (loc, sarg);
12143 : 147 : src = omp_build_component_ref (src, sf);
12144 : 147 : dst = build_simple_mem_ref_loc (loc, arg);
12145 : 147 : dst = omp_build_component_ref (dst, f);
12146 : 147 : t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
12147 : 147 : append_to_statement_list (t, &list);
12148 : 147 : break;
12149 : 460 : case OMP_CLAUSE_REDUCTION:
12150 : 460 : case OMP_CLAUSE_IN_REDUCTION:
12151 : 460 : decl = OMP_CLAUSE_DECL (c);
12152 : 460 : if (TREE_CODE (decl) == MEM_REF)
12153 : : {
12154 : 160 : decl = TREE_OPERAND (decl, 0);
12155 : 160 : if (TREE_CODE (decl) == POINTER_PLUS_EXPR)
12156 : 38 : decl = TREE_OPERAND (decl, 0);
12157 : 160 : if (TREE_CODE (decl) == INDIRECT_REF
12158 : 128 : || TREE_CODE (decl) == ADDR_EXPR)
12159 : 95 : decl = TREE_OPERAND (decl, 0);
12160 : : }
12161 : 460 : key = (splay_tree_key) decl;
12162 : 460 : n = splay_tree_lookup (ctx->field_map, key);
12163 : 460 : if (n == NULL)
12164 : : break;
12165 : 101 : f = (tree) n->value;
12166 : 101 : if (tcctx.cb.decl_map)
12167 : 20 : f = *tcctx.cb.decl_map->get (f);
12168 : 101 : n = splay_tree_lookup (ctx->sfield_map, key);
12169 : 101 : sf = (tree) n->value;
12170 : 101 : if (tcctx.cb.decl_map)
12171 : 20 : sf = *tcctx.cb.decl_map->get (sf);
12172 : 101 : src = build_simple_mem_ref_loc (loc, sarg);
12173 : 101 : src = omp_build_component_ref (src, sf);
12174 : 101 : if (decl != OMP_CLAUSE_DECL (c)
12175 : 95 : && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
12176 : 173 : && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == POINTER_TYPE)
12177 : 32 : src = build_simple_mem_ref_loc (loc, src);
12178 : 101 : dst = build_simple_mem_ref_loc (loc, arg);
12179 : 101 : dst = omp_build_component_ref (dst, f);
12180 : 101 : t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
12181 : 101 : append_to_statement_list (t, &list);
12182 : 101 : break;
12183 : 754 : case OMP_CLAUSE__LOOPTEMP_:
12184 : : /* Fields for first two _looptemp_ clauses are initialized by
12185 : : GOMP_taskloop*, the rest are handled like firstprivate. */
12186 : 754 : if (looptempno < 2)
12187 : : {
12188 : 748 : looptempno++;
12189 : 748 : break;
12190 : : }
12191 : : /* FALLTHRU */
12192 : 1731 : case OMP_CLAUSE__REDUCTEMP_:
12193 : 1731 : case OMP_CLAUSE_FIRSTPRIVATE:
12194 : 1731 : decl = OMP_CLAUSE_DECL (c);
12195 : 1731 : if (is_variable_sized (decl))
12196 : : break;
12197 : 1717 : n = splay_tree_lookup (ctx->field_map, (splay_tree_key) decl);
12198 : 1717 : if (n == NULL)
12199 : : break;
12200 : 1717 : f = (tree) n->value;
12201 : 1717 : if (tcctx.cb.decl_map)
12202 : 490 : f = *tcctx.cb.decl_map->get (f);
12203 : 1717 : n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl);
12204 : 1717 : if (n != NULL)
12205 : : {
12206 : 1467 : sf = (tree) n->value;
12207 : 1467 : if (tcctx.cb.decl_map)
12208 : 490 : sf = *tcctx.cb.decl_map->get (sf);
12209 : 1467 : src = build_simple_mem_ref_loc (loc, sarg);
12210 : 1467 : src = omp_build_component_ref (src, sf);
12211 : 1467 : if (use_pointer_for_field (decl, NULL)
12212 : 1467 : || omp_privatize_by_reference (decl))
12213 : 317 : src = build_simple_mem_ref_loc (loc, src);
12214 : : }
12215 : : else
12216 : : src = decl;
12217 : 1717 : dst = build_simple_mem_ref_loc (loc, arg);
12218 : 1717 : dst = omp_build_component_ref (dst, f);
12219 : 1717 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
12220 : 192 : t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
12221 : : else
12222 : : {
12223 : 1525 : if (ctx->allocate_map)
12224 : 84 : if (tree *allocatorp = ctx->allocate_map->get (decl))
12225 : : {
12226 : 50 : tree allocator = *allocatorp;
12227 : 50 : HOST_WIDE_INT ialign = 0;
12228 : 50 : if (TREE_CODE (allocator) == TREE_LIST)
12229 : : {
12230 : 4 : ialign = tree_to_uhwi (TREE_VALUE (allocator));
12231 : 4 : allocator = TREE_PURPOSE (allocator);
12232 : : }
12233 : 50 : if (TREE_CODE (allocator) != INTEGER_CST)
12234 : : {
12235 : 22 : n = splay_tree_lookup (ctx->sfield_map,
12236 : : (splay_tree_key) allocator);
12237 : 22 : allocator = (tree) n->value;
12238 : 22 : if (tcctx.cb.decl_map)
12239 : 0 : allocator = *tcctx.cb.decl_map->get (allocator);
12240 : 22 : tree a = build_simple_mem_ref_loc (loc, sarg);
12241 : 22 : allocator = omp_build_component_ref (a, allocator);
12242 : : }
12243 : 50 : allocator = fold_convert (pointer_sized_int_node, allocator);
12244 : 50 : tree a = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
12245 : 50 : tree align = build_int_cst (size_type_node,
12246 : 50 : MAX (ialign,
12247 : : DECL_ALIGN_UNIT (decl)));
12248 : 50 : tree sz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (dst)));
12249 : 50 : tree ptr = build_call_expr_loc (loc, a, 3, align, sz,
12250 : : allocator);
12251 : 50 : ptr = fold_convert (TREE_TYPE (dst), ptr);
12252 : 50 : t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, ptr);
12253 : 50 : append_to_statement_list (t, &list);
12254 : 50 : dst = build_simple_mem_ref_loc (loc, dst);
12255 : : }
12256 : 1525 : t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src);
12257 : : }
12258 : 1717 : append_to_statement_list (t, &list);
12259 : 1717 : break;
12260 : 489 : case OMP_CLAUSE_PRIVATE:
12261 : 489 : if (! OMP_CLAUSE_PRIVATE_OUTER_REF (c))
12262 : : break;
12263 : 12 : decl = OMP_CLAUSE_DECL (c);
12264 : 12 : n = splay_tree_lookup (ctx->field_map, (splay_tree_key) decl);
12265 : 12 : f = (tree) n->value;
12266 : 12 : if (tcctx.cb.decl_map)
12267 : 0 : f = *tcctx.cb.decl_map->get (f);
12268 : 12 : n = splay_tree_lookup (ctx->sfield_map, (splay_tree_key) decl);
12269 : 12 : if (n != NULL)
12270 : : {
12271 : 12 : sf = (tree) n->value;
12272 : 12 : if (tcctx.cb.decl_map)
12273 : 0 : sf = *tcctx.cb.decl_map->get (sf);
12274 : 12 : src = build_simple_mem_ref_loc (loc, sarg);
12275 : 12 : src = omp_build_component_ref (src, sf);
12276 : 12 : if (use_pointer_for_field (decl, NULL))
12277 : 12 : src = build_simple_mem_ref_loc (loc, src);
12278 : : }
12279 : : else
12280 : : src = decl;
12281 : 12 : dst = build_simple_mem_ref_loc (loc, arg);
12282 : 12 : dst = omp_build_component_ref (dst, f);
12283 : 12 : t = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
12284 : 12 : append_to_statement_list (t, &list);
12285 : 12 : break;
12286 : : default:
12287 : : break;
12288 : : }
12289 : :
12290 : : /* Last pass: handle VLA firstprivates. */
12291 : 504 : if (tcctx.cb.decl_map)
12292 : 631 : for (c = gimple_omp_task_clauses (task_stmt); c; c = OMP_CLAUSE_CHAIN (c))
12293 : 606 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
12294 : : {
12295 : 497 : tree ind, ptr, df;
12296 : :
12297 : 497 : decl = OMP_CLAUSE_DECL (c);
12298 : 497 : if (!is_variable_sized (decl))
12299 : 483 : continue;
12300 : 14 : n = splay_tree_lookup (ctx->field_map, (splay_tree_key) decl);
12301 : 14 : if (n == NULL)
12302 : 0 : continue;
12303 : 14 : f = (tree) n->value;
12304 : 14 : f = *tcctx.cb.decl_map->get (f);
12305 : 14 : gcc_assert (DECL_HAS_VALUE_EXPR_P (decl));
12306 : 14 : ind = DECL_VALUE_EXPR (decl);
12307 : 14 : gcc_assert (TREE_CODE (ind) == INDIRECT_REF);
12308 : 14 : gcc_assert (DECL_P (TREE_OPERAND (ind, 0)));
12309 : 42 : n = splay_tree_lookup (ctx->sfield_map,
12310 : 14 : (splay_tree_key) TREE_OPERAND (ind, 0));
12311 : 14 : sf = (tree) n->value;
12312 : 14 : sf = *tcctx.cb.decl_map->get (sf);
12313 : 14 : src = build_simple_mem_ref_loc (loc, sarg);
12314 : 14 : src = omp_build_component_ref (src, sf);
12315 : 14 : src = build_simple_mem_ref_loc (loc, src);
12316 : 14 : dst = build_simple_mem_ref_loc (loc, arg);
12317 : 14 : dst = omp_build_component_ref (dst, f);
12318 : 14 : t = lang_hooks.decls.omp_clause_copy_ctor (c, dst, src);
12319 : 14 : append_to_statement_list (t, &list);
12320 : 42 : n = splay_tree_lookup (ctx->field_map,
12321 : 14 : (splay_tree_key) TREE_OPERAND (ind, 0));
12322 : 14 : df = (tree) n->value;
12323 : 14 : df = *tcctx.cb.decl_map->get (df);
12324 : 14 : ptr = build_simple_mem_ref_loc (loc, arg);
12325 : 14 : ptr = omp_build_component_ref (ptr, df);
12326 : 14 : t = build2 (MODIFY_EXPR, TREE_TYPE (ptr), ptr,
12327 : : build_fold_addr_expr_loc (loc, dst));
12328 : 14 : append_to_statement_list (t, &list);
12329 : : }
12330 : :
12331 : 504 : t = build1 (RETURN_EXPR, void_type_node, NULL);
12332 : 504 : append_to_statement_list (t, &list);
12333 : :
12334 : 504 : if (tcctx.cb.decl_map)
12335 : 25 : delete tcctx.cb.decl_map;
12336 : 504 : pop_gimplify_context (NULL);
12337 : 504 : BIND_EXPR_BODY (bind) = list;
12338 : 504 : pop_cfun ();
12339 : 504 : }
12340 : :
12341 : : static void
12342 : 1546 : lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq)
12343 : : {
12344 : 1546 : tree c, clauses;
12345 : 1546 : gimple *g;
12346 : 1546 : size_t cnt[5] = { 0, 0, 0, 0, 0 }, idx = 2, i;
12347 : :
12348 : 1546 : clauses = omp_find_clause (*pclauses, OMP_CLAUSE_DEPEND);
12349 : 1546 : gcc_assert (clauses);
12350 : 6305 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12351 : 4879 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
12352 : 1706 : switch (OMP_CLAUSE_DEPEND_KIND (c))
12353 : : {
12354 : 120 : case OMP_CLAUSE_DEPEND_LAST:
12355 : : /* Lowering already done at gimplification. */
12356 : 120 : return;
12357 : 481 : case OMP_CLAUSE_DEPEND_IN:
12358 : 481 : cnt[2]++;
12359 : 481 : break;
12360 : 967 : case OMP_CLAUSE_DEPEND_OUT:
12361 : 967 : case OMP_CLAUSE_DEPEND_INOUT:
12362 : 967 : cnt[0]++;
12363 : 967 : break;
12364 : 30 : case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
12365 : 30 : cnt[1]++;
12366 : 30 : break;
12367 : 76 : case OMP_CLAUSE_DEPEND_DEPOBJ:
12368 : 76 : cnt[3]++;
12369 : 76 : break;
12370 : 32 : case OMP_CLAUSE_DEPEND_INOUTSET:
12371 : 32 : cnt[4]++;
12372 : 32 : break;
12373 : 0 : default:
12374 : 0 : gcc_unreachable ();
12375 : : }
12376 : 1426 : if (cnt[1] || cnt[3] || cnt[4])
12377 : 135 : idx = 5;
12378 : 1426 : size_t total = cnt[0] + cnt[1] + cnt[2] + cnt[3] + cnt[4];
12379 : 1426 : size_t inoutidx = total + idx;
12380 : 1426 : tree type = build_array_type_nelts (ptr_type_node, total + idx + 2 * cnt[4]);
12381 : 1426 : tree array = create_tmp_var (type);
12382 : 1426 : TREE_ADDRESSABLE (array) = 1;
12383 : 1426 : tree r = build4 (ARRAY_REF, ptr_type_node, array, size_int (0), NULL_TREE,
12384 : : NULL_TREE);
12385 : 1426 : if (idx == 5)
12386 : : {
12387 : 135 : g = gimple_build_assign (r, build_int_cst (ptr_type_node, 0));
12388 : 135 : gimple_seq_add_stmt (iseq, g);
12389 : 135 : r = build4 (ARRAY_REF, ptr_type_node, array, size_int (1), NULL_TREE,
12390 : : NULL_TREE);
12391 : : }
12392 : 1426 : g = gimple_build_assign (r, build_int_cst (ptr_type_node, total));
12393 : 1426 : gimple_seq_add_stmt (iseq, g);
12394 : 7130 : for (i = 0; i < (idx == 5 ? 3 : 1); i++)
12395 : : {
12396 : 1696 : r = build4 (ARRAY_REF, ptr_type_node, array,
12397 : 1696 : size_int (i + 1 + (idx == 5)), NULL_TREE, NULL_TREE);
12398 : 1696 : g = gimple_build_assign (r, build_int_cst (ptr_type_node, cnt[i]));
12399 : 1696 : gimple_seq_add_stmt (iseq, g);
12400 : : }
12401 : 8556 : for (i = 0; i < 5; i++)
12402 : : {
12403 : 7130 : if (cnt[i] == 0)
12404 : 5648 : continue;
12405 : 6559 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12406 : 5077 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
12407 : 3352 : continue;
12408 : : else
12409 : : {
12410 : 1725 : switch (OMP_CLAUSE_DEPEND_KIND (c))
12411 : : {
12412 : 547 : case OMP_CLAUSE_DEPEND_IN:
12413 : 547 : if (i != 2)
12414 : 139 : continue;
12415 : : break;
12416 : 1023 : case OMP_CLAUSE_DEPEND_OUT:
12417 : 1023 : case OMP_CLAUSE_DEPEND_INOUT:
12418 : 1023 : if (i != 0)
12419 : 56 : continue;
12420 : : break;
12421 : 44 : case OMP_CLAUSE_DEPEND_MUTEXINOUTSET:
12422 : 44 : if (i != 1)
12423 : 14 : continue;
12424 : : break;
12425 : 79 : case OMP_CLAUSE_DEPEND_DEPOBJ:
12426 : 79 : if (i != 3)
12427 : 3 : continue;
12428 : : break;
12429 : 32 : case OMP_CLAUSE_DEPEND_INOUTSET:
12430 : 32 : if (i != 4)
12431 : 0 : continue;
12432 : : break;
12433 : 0 : default:
12434 : 0 : gcc_unreachable ();
12435 : : }
12436 : 1586 : tree t = OMP_CLAUSE_DECL (c);
12437 : 1586 : if (i == 4)
12438 : : {
12439 : 32 : t = build4 (ARRAY_REF, ptr_type_node, array,
12440 : 32 : size_int (inoutidx), NULL_TREE, NULL_TREE);
12441 : 32 : t = build_fold_addr_expr (t);
12442 : 32 : inoutidx += 2;
12443 : : }
12444 : 1586 : t = fold_convert (ptr_type_node, t);
12445 : 1586 : gimplify_expr (&t, iseq, NULL, is_gimple_val, fb_rvalue);
12446 : 1586 : r = build4 (ARRAY_REF, ptr_type_node, array, size_int (idx++),
12447 : : NULL_TREE, NULL_TREE);
12448 : 1586 : g = gimple_build_assign (r, t);
12449 : 1586 : gimple_seq_add_stmt (iseq, g);
12450 : : }
12451 : : }
12452 : 1426 : if (cnt[4])
12453 : 81 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12454 : 49 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
12455 : 49 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_INOUTSET)
12456 : : {
12457 : 32 : tree t = OMP_CLAUSE_DECL (c);
12458 : 32 : t = fold_convert (ptr_type_node, t);
12459 : 32 : gimplify_expr (&t, iseq, NULL, is_gimple_val, fb_rvalue);
12460 : 32 : r = build4 (ARRAY_REF, ptr_type_node, array, size_int (idx++),
12461 : : NULL_TREE, NULL_TREE);
12462 : 32 : g = gimple_build_assign (r, t);
12463 : 32 : gimple_seq_add_stmt (iseq, g);
12464 : 32 : t = build_int_cst (ptr_type_node, GOMP_DEPEND_INOUTSET);
12465 : 32 : r = build4 (ARRAY_REF, ptr_type_node, array, size_int (idx++),
12466 : : NULL_TREE, NULL_TREE);
12467 : 32 : g = gimple_build_assign (r, t);
12468 : 32 : gimple_seq_add_stmt (iseq, g);
12469 : : }
12470 : :
12471 : 1426 : c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_DEPEND);
12472 : 1426 : OMP_CLAUSE_DEPEND_KIND (c) = OMP_CLAUSE_DEPEND_LAST;
12473 : 1426 : OMP_CLAUSE_DECL (c) = build_fold_addr_expr (array);
12474 : 1426 : OMP_CLAUSE_CHAIN (c) = *pclauses;
12475 : 1426 : *pclauses = c;
12476 : 1426 : tree clobber = build_clobber (type);
12477 : 1426 : g = gimple_build_assign (array, clobber);
12478 : 1426 : gimple_seq_add_stmt (oseq, g);
12479 : : }
12480 : :
12481 : : /* Lower the OpenMP parallel or task directive in the current statement
12482 : : in GSI_P. CTX holds context information for the directive. */
12483 : :
12484 : : static void
12485 : 22429 : lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
12486 : : {
12487 : 22429 : tree clauses;
12488 : 22429 : tree child_fn, t;
12489 : 22429 : gimple *stmt = gsi_stmt (*gsi_p);
12490 : 22429 : gbind *par_bind, *bind, *dep_bind = NULL;
12491 : 22429 : gimple_seq par_body;
12492 : 22429 : location_t loc = gimple_location (stmt);
12493 : :
12494 : 22429 : clauses = gimple_omp_taskreg_clauses (stmt);
12495 : 22429 : if (gimple_code (stmt) == GIMPLE_OMP_TASK
12496 : 22429 : && gimple_omp_task_taskwait_p (stmt))
12497 : : {
12498 : 81 : par_bind = NULL;
12499 : 81 : par_body = NULL;
12500 : : }
12501 : : else
12502 : : {
12503 : 22348 : par_bind
12504 : 22348 : = as_a <gbind *> (gimple_seq_first_stmt (gimple_omp_body (stmt)));
12505 : 22348 : par_body = gimple_bind_body (par_bind);
12506 : : }
12507 : 22429 : child_fn = ctx->cb.dst_fn;
12508 : 22429 : if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL
12509 : 22429 : && !gimple_omp_parallel_combined_p (stmt))
12510 : : {
12511 : 4183 : struct walk_stmt_info wi;
12512 : 4183 : int ws_num = 0;
12513 : :
12514 : 4183 : memset (&wi, 0, sizeof (wi));
12515 : 4183 : wi.info = &ws_num;
12516 : 4183 : wi.val_only = true;
12517 : 4183 : walk_gimple_seq (par_body, check_combined_parallel, NULL, &wi);
12518 : 4183 : if (ws_num == 1)
12519 : 377 : gimple_omp_parallel_set_combined_p (stmt, true);
12520 : : }
12521 : 22429 : gimple_seq dep_ilist = NULL;
12522 : 22429 : gimple_seq dep_olist = NULL;
12523 : 22429 : if (gimple_code (stmt) == GIMPLE_OMP_TASK
12524 : 22429 : && omp_find_clause (clauses, OMP_CLAUSE_DEPEND))
12525 : : {
12526 : 1182 : push_gimplify_context ();
12527 : 1182 : dep_bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
12528 : 1182 : lower_depend_clauses (gimple_omp_task_clauses_ptr (stmt),
12529 : : &dep_ilist, &dep_olist);
12530 : : }
12531 : :
12532 : 22429 : if (gimple_code (stmt) == GIMPLE_OMP_TASK
12533 : 22429 : && gimple_omp_task_taskwait_p (stmt))
12534 : : {
12535 : 81 : if (dep_bind)
12536 : : {
12537 : 81 : gsi_replace (gsi_p, dep_bind, true);
12538 : 81 : gimple_bind_add_seq (dep_bind, dep_ilist);
12539 : 81 : gimple_bind_add_stmt (dep_bind, stmt);
12540 : 81 : gimple_bind_add_seq (dep_bind, dep_olist);
12541 : 81 : pop_gimplify_context (dep_bind);
12542 : : }
12543 : 81 : return;
12544 : : }
12545 : :
12546 : 22348 : if (ctx->srecord_type)
12547 : 504 : create_task_copyfn (as_a <gomp_task *> (stmt), ctx);
12548 : :
12549 : 22348 : gimple_seq tskred_ilist = NULL;
12550 : 22348 : gimple_seq tskred_olist = NULL;
12551 : 22348 : if ((is_task_ctx (ctx)
12552 : 3772 : && gimple_omp_task_taskloop_p (ctx->stmt)
12553 : 1330 : && omp_find_clause (gimple_omp_task_clauses (ctx->stmt),
12554 : : OMP_CLAUSE_REDUCTION))
12555 : 25623 : || (is_parallel_ctx (ctx)
12556 : 16083 : && omp_find_clause (gimple_omp_parallel_clauses (stmt),
12557 : : OMP_CLAUSE__REDUCTEMP_)))
12558 : : {
12559 : 556 : if (dep_bind == NULL)
12560 : : {
12561 : 556 : push_gimplify_context ();
12562 : 556 : dep_bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
12563 : : }
12564 : 615 : lower_omp_task_reductions (ctx, is_task_ctx (ctx) ? OMP_TASKLOOP
12565 : : : OMP_PARALLEL,
12566 : 556 : gimple_omp_taskreg_clauses (ctx->stmt),
12567 : : &tskred_ilist, &tskred_olist);
12568 : : }
12569 : :
12570 : 22348 : push_gimplify_context ();
12571 : :
12572 : 22348 : gimple_seq par_olist = NULL;
12573 : 22348 : gimple_seq par_ilist = NULL;
12574 : 22348 : gimple_seq par_rlist = NULL;
12575 : 22348 : lower_rec_input_clauses (clauses, &par_ilist, &par_olist, ctx, NULL);
12576 : 22344 : lower_omp (&par_body, ctx);
12577 : 22344 : if (gimple_code (stmt) != GIMPLE_OMP_TASK)
12578 : 18572 : lower_reduction_clauses (clauses, &par_rlist, NULL, ctx);
12579 : :
12580 : : /* Declare all the variables created by mapping and the variables
12581 : : declared in the scope of the parallel body. */
12582 : 22344 : record_vars_into (ctx->block_vars, child_fn);
12583 : 22344 : maybe_remove_omp_member_access_dummy_vars (par_bind);
12584 : 22344 : record_vars_into (gimple_bind_vars (par_bind), child_fn);
12585 : :
12586 : 22344 : if (ctx->record_type)
12587 : : {
12588 : 17907 : ctx->sender_decl
12589 : 35310 : = create_tmp_var (ctx->srecord_type ? ctx->srecord_type
12590 : : : ctx->record_type, ".omp_data_o");
12591 : 17907 : DECL_NAMELESS (ctx->sender_decl) = 1;
12592 : 17907 : TREE_ADDRESSABLE (ctx->sender_decl) = 1;
12593 : 17907 : gimple_omp_taskreg_set_data_arg (stmt, ctx->sender_decl);
12594 : : }
12595 : :
12596 : 22344 : gimple_seq olist = NULL;
12597 : 22344 : gimple_seq ilist = NULL;
12598 : 22344 : lower_send_clauses (clauses, &ilist, &olist, ctx);
12599 : 22344 : lower_send_shared_vars (&ilist, &olist, ctx);
12600 : :
12601 : 22344 : if (ctx->record_type)
12602 : : {
12603 : 17907 : tree clobber = build_clobber (TREE_TYPE (ctx->sender_decl));
12604 : 17907 : gimple_seq_add_stmt (&olist, gimple_build_assign (ctx->sender_decl,
12605 : : clobber));
12606 : : }
12607 : :
12608 : : /* Once all the expansions are done, sequence all the different
12609 : : fragments inside gimple_omp_body. */
12610 : :
12611 : 22344 : gimple_seq new_body = NULL;
12612 : :
12613 : 22344 : if (ctx->record_type)
12614 : : {
12615 : 17907 : t = build_fold_addr_expr_loc (loc, ctx->sender_decl);
12616 : : /* fixup_child_record_type might have changed receiver_decl's type. */
12617 : 17907 : t = fold_convert_loc (loc, TREE_TYPE (ctx->receiver_decl), t);
12618 : 17907 : gimple_seq_add_stmt (&new_body,
12619 : 17907 : gimple_build_assign (ctx->receiver_decl, t));
12620 : : }
12621 : :
12622 : 22344 : gimple_seq_add_seq (&new_body, par_ilist);
12623 : 22344 : gimple_seq_add_seq (&new_body, par_body);
12624 : 22344 : gimple_seq_add_seq (&new_body, par_rlist);
12625 : 22344 : if (ctx->cancellable)
12626 : 135 : gimple_seq_add_stmt (&new_body, gimple_build_label (ctx->cancel_label));
12627 : 22344 : gimple_seq_add_seq (&new_body, par_olist);
12628 : 22344 : new_body = maybe_catch_exception (new_body);
12629 : 22344 : if (gimple_code (stmt) == GIMPLE_OMP_TASK)
12630 : 3772 : gimple_seq_add_stmt (&new_body,
12631 : 3772 : gimple_build_omp_continue (integer_zero_node,
12632 : : integer_zero_node));
12633 : 22344 : gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
12634 : 22344 : gimple_omp_set_body (stmt, new_body);
12635 : :
12636 : 22344 : if (dep_bind && gimple_bind_block (par_bind) == NULL_TREE)
12637 : 497 : bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
12638 : : else
12639 : 21847 : bind = gimple_build_bind (NULL, NULL, gimple_bind_block (par_bind));
12640 : 43031 : gsi_replace (gsi_p, dep_bind ? dep_bind : bind, true);
12641 : 22344 : gimple_bind_add_seq (bind, ilist);
12642 : 22344 : gimple_bind_add_stmt (bind, stmt);
12643 : 22344 : gimple_bind_add_seq (bind, olist);
12644 : :
12645 : 22344 : pop_gimplify_context (NULL);
12646 : :
12647 : 22344 : if (dep_bind)
12648 : : {
12649 : 1657 : gimple_bind_add_seq (dep_bind, dep_ilist);
12650 : 1657 : gimple_bind_add_seq (dep_bind, tskred_ilist);
12651 : 1657 : gimple_bind_add_stmt (dep_bind, bind);
12652 : 1657 : gimple_bind_add_seq (dep_bind, tskred_olist);
12653 : 1657 : gimple_bind_add_seq (dep_bind, dep_olist);
12654 : 1657 : pop_gimplify_context (dep_bind);
12655 : : }
12656 : : }
12657 : :
12658 : : /* Set EXPR as the hostaddr expression that should result from the clause C
12659 : : in the target statement STMT. Returns the tree that should be
12660 : : passed as the hostaddr (a pointer to the array containing the expanded
12661 : : hostaddrs and sizes of the clause). */
12662 : :
12663 : : static tree
12664 : 35308 : lower_omp_map_iterator_expr (tree expr, tree c, gomp_target *stmt)
12665 : : {
12666 : 35308 : if (!OMP_CLAUSE_HAS_ITERATORS (c))
12667 : : return expr;
12668 : :
12669 : 96 : tree iterator = OMP_CLAUSE_ITERATORS (c);
12670 : 96 : tree elems = TREE_VEC_ELT (iterator, 7);
12671 : 96 : tree index = TREE_VEC_ELT (iterator, 8);
12672 : 96 : gimple_seq *loop_body_p = enter_omp_iterator_loop_context (c, stmt);
12673 : :
12674 : : /* IN LOOP BODY: */
12675 : : /* elems[idx] = <expr>; */
12676 : 96 : tree lhs = build4 (ARRAY_REF, ptr_type_node, elems, index,
12677 : : NULL_TREE, NULL_TREE);
12678 : 96 : tree mod_expr = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
12679 : : void_type_node, lhs, expr);
12680 : 96 : gimplify_and_add (mod_expr, loop_body_p);
12681 : 96 : exit_omp_iterator_loop_context (c);
12682 : :
12683 : 96 : return build_fold_addr_expr_with_type (elems, ptr_type_node);
12684 : : }
12685 : :
12686 : : /* Set SIZE as the size expression that should result from the clause C
12687 : : in the target statement STMT. Returns the tree that should be
12688 : : passed as the clause size (a size_int with the value SIZE_MAX, indicating
12689 : : that the clause uses an iterator). */
12690 : :
12691 : : static tree
12692 : 77145 : lower_omp_map_iterator_size (tree size, tree c, gomp_target *stmt)
12693 : : {
12694 : 77145 : if (!OMP_CLAUSE_HAS_ITERATORS (c))
12695 : : return size;
12696 : :
12697 : 96 : tree iterator = OMP_CLAUSE_ITERATORS (c);
12698 : 96 : tree elems = TREE_VEC_ELT (iterator, 7);
12699 : 96 : tree index = TREE_VEC_ELT (iterator, 8);
12700 : 96 : gimple_seq *loop_body_p = enter_omp_iterator_loop_context (c, stmt);
12701 : :
12702 : : /* IN LOOP BODY: */
12703 : : /* elems[idx+1] = <size>; */
12704 : 96 : tree lhs = build4 (ARRAY_REF, ptr_type_node, elems,
12705 : : size_binop (PLUS_EXPR, index, size_int (1)),
12706 : : NULL_TREE, NULL_TREE);
12707 : 96 : tree mod_expr = build2_loc (OMP_CLAUSE_LOCATION (c), MODIFY_EXPR,
12708 : : void_type_node, lhs, size);
12709 : 96 : gimplify_and_add (mod_expr, loop_body_p);
12710 : 96 : exit_omp_iterator_loop_context (c);
12711 : :
12712 : 96 : return size_int (SIZE_MAX);
12713 : : }
12714 : :
12715 : : /* Lower the GIMPLE_OMP_TARGET in the current statement
12716 : : in GSI_P. CTX holds context information for the directive. */
12717 : :
12718 : : static void
12719 : 36189 : lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
12720 : : {
12721 : 36189 : tree clauses;
12722 : 36189 : tree child_fn, t, c;
12723 : 36189 : gomp_target *stmt = as_a <gomp_target *> (gsi_stmt (*gsi_p));
12724 : 36189 : gbind *tgt_bind, *bind, *dep_bind = NULL;
12725 : 36189 : gimple_seq tgt_body, olist, ilist, fplist, new_body;
12726 : 36189 : location_t loc = gimple_location (stmt);
12727 : 36189 : bool offloaded, data_region;
12728 : 36189 : unsigned int map_cnt = 0;
12729 : 36189 : tree in_reduction_clauses = NULL_TREE;
12730 : :
12731 : 36189 : tree deep_map_cnt = NULL_TREE;
12732 : 36189 : tree deep_map_data = NULL_TREE;
12733 : 36189 : tree deep_map_offset_data = NULL_TREE;
12734 : 36189 : tree deep_map_offset = NULL_TREE;
12735 : :
12736 : 36189 : offloaded = is_gimple_omp_offloaded (stmt);
12737 : 36189 : switch (gimple_omp_target_kind (stmt))
12738 : : {
12739 : 11164 : case GF_OMP_TARGET_KIND_REGION:
12740 : 11164 : tree *p, *q;
12741 : 11164 : q = &in_reduction_clauses;
12742 : 75612 : for (p = gimple_omp_target_clauses_ptr (stmt); *p; )
12743 : 64448 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_IN_REDUCTION)
12744 : : {
12745 : 422 : *q = *p;
12746 : 422 : q = &OMP_CLAUSE_CHAIN (*q);
12747 : 422 : *p = OMP_CLAUSE_CHAIN (*p);
12748 : : }
12749 : : else
12750 : 64026 : p = &OMP_CLAUSE_CHAIN (*p);
12751 : 11164 : *q = NULL_TREE;
12752 : 11164 : *p = in_reduction_clauses;
12753 : : /* FALLTHRU */
12754 : : case GF_OMP_TARGET_KIND_UPDATE:
12755 : : case GF_OMP_TARGET_KIND_ENTER_DATA:
12756 : : case GF_OMP_TARGET_KIND_EXIT_DATA:
12757 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL:
12758 : : case GF_OMP_TARGET_KIND_OACC_KERNELS:
12759 : : case GF_OMP_TARGET_KIND_OACC_SERIAL:
12760 : : case GF_OMP_TARGET_KIND_OACC_UPDATE:
12761 : : case GF_OMP_TARGET_KIND_OACC_ENTER_DATA:
12762 : : case GF_OMP_TARGET_KIND_OACC_EXIT_DATA:
12763 : : case GF_OMP_TARGET_KIND_OACC_DECLARE:
12764 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
12765 : : case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
12766 : : data_region = false;
12767 : : break;
12768 : : case GF_OMP_TARGET_KIND_DATA:
12769 : : case GF_OMP_TARGET_KIND_OACC_DATA:
12770 : : case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
12771 : : case GF_OMP_TARGET_KIND_OACC_DATA_KERNELS:
12772 : : data_region = true;
12773 : : break;
12774 : 0 : default:
12775 : 0 : gcc_unreachable ();
12776 : : }
12777 : :
12778 : : /* Ensure that requires map is written via output_offload_tables, even if only
12779 : : 'target (enter/exit) data' is used in the translation unit. */
12780 : 36189 : if (ENABLE_OFFLOADING && (omp_requires_mask & OMP_REQUIRES_TARGET_USED))
12781 : : g->have_offload = true;
12782 : :
12783 : 36189 : clauses = gimple_omp_target_clauses (stmt);
12784 : :
12785 : 36189 : gimple_seq dep_ilist = NULL;
12786 : 36189 : gimple_seq dep_olist = NULL;
12787 : 36189 : bool has_depend = omp_find_clause (clauses, OMP_CLAUSE_DEPEND) != NULL_TREE;
12788 : 36189 : if (has_depend || in_reduction_clauses)
12789 : : {
12790 : 392 : push_gimplify_context ();
12791 : 392 : dep_bind = gimple_build_bind (NULL, NULL, make_node (BLOCK));
12792 : 392 : if (has_depend)
12793 : 329 : lower_depend_clauses (gimple_omp_target_clauses_ptr (stmt),
12794 : : &dep_ilist, &dep_olist);
12795 : 392 : if (in_reduction_clauses)
12796 : 314 : lower_rec_input_clauses (in_reduction_clauses, &dep_ilist, &dep_olist,
12797 : : ctx, NULL);
12798 : : }
12799 : :
12800 : 36189 : tgt_bind = NULL;
12801 : 36189 : tgt_body = NULL;
12802 : 36189 : if (offloaded)
12803 : : {
12804 : 20555 : tgt_bind = gimple_seq_first_stmt_as_a_bind (gimple_omp_body (stmt));
12805 : 20555 : tgt_body = gimple_bind_body (tgt_bind);
12806 : : }
12807 : 15634 : else if (data_region)
12808 : 4011 : tgt_body = gimple_omp_body (stmt);
12809 : 36189 : child_fn = ctx->cb.dst_fn;
12810 : :
12811 : 36189 : push_gimplify_context ();
12812 : 36189 : fplist = NULL;
12813 : :
12814 : 36189 : ilist = NULL;
12815 : 36189 : olist = NULL;
12816 : 170348 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
12817 : 134159 : switch (OMP_CLAUSE_CODE (c))
12818 : : {
12819 : : tree var, x;
12820 : :
12821 : : default:
12822 : : break;
12823 : 74922 : case OMP_CLAUSE_MAP:
12824 : : #if CHECKING_P
12825 : : /* First check what we're prepared to handle in the following. */
12826 : 74922 : switch (OMP_CLAUSE_MAP_KIND (c))
12827 : : {
12828 : : case GOMP_MAP_ALLOC:
12829 : : case GOMP_MAP_TO:
12830 : : case GOMP_MAP_FROM:
12831 : : case GOMP_MAP_TOFROM:
12832 : : case GOMP_MAP_POINTER:
12833 : : case GOMP_MAP_TO_PSET:
12834 : : case GOMP_MAP_DELETE:
12835 : : case GOMP_MAP_RELEASE:
12836 : : case GOMP_MAP_ALWAYS_TO:
12837 : : case GOMP_MAP_ALWAYS_FROM:
12838 : : case GOMP_MAP_ALWAYS_TOFROM:
12839 : : case GOMP_MAP_FORCE_PRESENT:
12840 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
12841 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
12842 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
12843 : :
12844 : : case GOMP_MAP_FIRSTPRIVATE_POINTER:
12845 : : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
12846 : : case GOMP_MAP_STRUCT:
12847 : : case GOMP_MAP_STRUCT_UNORD:
12848 : : case GOMP_MAP_ALWAYS_POINTER:
12849 : : case GOMP_MAP_ATTACH:
12850 : : case GOMP_MAP_DETACH:
12851 : : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
12852 : : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
12853 : : break;
12854 : 2578 : case GOMP_MAP_IF_PRESENT:
12855 : 2578 : case GOMP_MAP_FORCE_ALLOC:
12856 : 2578 : case GOMP_MAP_FORCE_TO:
12857 : 2578 : case GOMP_MAP_FORCE_FROM:
12858 : 2578 : case GOMP_MAP_FORCE_TOFROM:
12859 : 2578 : case GOMP_MAP_FORCE_DEVICEPTR:
12860 : 2578 : case GOMP_MAP_DEVICE_RESIDENT:
12861 : 2578 : case GOMP_MAP_LINK:
12862 : 2578 : case GOMP_MAP_FORCE_DETACH:
12863 : 2578 : gcc_assert (is_gimple_omp_oacc (stmt));
12864 : : break;
12865 : 0 : default:
12866 : 0 : gcc_unreachable ();
12867 : : }
12868 : : #endif
12869 : : /* FALLTHRU */
12870 : 86366 : case OMP_CLAUSE_TO:
12871 : 86366 : case OMP_CLAUSE_FROM:
12872 : 86366 : oacc_firstprivate:
12873 : 86366 : var = OMP_CLAUSE_DECL (c);
12874 : 86366 : {
12875 : 86366 : tree extra = lang_hooks.decls.omp_deep_mapping_cnt (stmt, c, &ilist);
12876 : 86366 : if (extra != NULL_TREE && deep_map_cnt != NULL_TREE)
12877 : 59 : deep_map_cnt = fold_build2_loc (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
12878 : : size_type_node, deep_map_cnt,
12879 : : extra);
12880 : 86307 : else if (extra != NULL_TREE)
12881 : : deep_map_cnt = extra;
12882 : : }
12883 : :
12884 : 86230 : if (deep_map_cnt
12885 : 86595 : && OMP_CLAUSE_HAS_ITERATORS (c))
12886 : 0 : sorry ("iterators used together with deep mapping are not "
12887 : : "supported yet");
12888 : :
12889 : 86366 : if (!DECL_P (var))
12890 : : {
12891 : 34883 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
12892 : 34883 : || (!OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c)
12893 : 33402 : && (OMP_CLAUSE_MAP_KIND (c)
12894 : : != GOMP_MAP_FIRSTPRIVATE_POINTER)))
12895 : 34883 : map_cnt++;
12896 : 34883 : continue;
12897 : : }
12898 : :
12899 : 51483 : if (DECL_SIZE (var)
12900 : 51483 : && !poly_int_tree_p (DECL_SIZE (var)))
12901 : : {
12902 : 717 : tree var2 = DECL_VALUE_EXPR (var);
12903 : 717 : gcc_assert (TREE_CODE (var2) == INDIRECT_REF);
12904 : 717 : var2 = TREE_OPERAND (var2, 0);
12905 : 717 : gcc_assert (DECL_P (var2));
12906 : : var = var2;
12907 : : }
12908 : :
12909 : 51483 : if (offloaded
12910 : 35875 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
12911 : 83462 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
12912 : 28806 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
12913 : : {
12914 : 3598 : if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
12915 : : {
12916 : 379 : if (is_global_var (maybe_lookup_decl_in_outer_ctx (var, ctx))
12917 : 379 : && varpool_node::get_create (var)->offloadable)
12918 : 2 : continue;
12919 : :
12920 : 377 : tree type = build_pointer_type (TREE_TYPE (var));
12921 : 377 : tree new_var = lookup_decl (var, ctx);
12922 : 377 : x = create_tmp_var_raw (type, get_name (new_var));
12923 : 377 : gimple_add_tmp_var (x);
12924 : 377 : x = build_simple_mem_ref (x);
12925 : 377 : SET_DECL_VALUE_EXPR (new_var, x);
12926 : 377 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
12927 : : }
12928 : 3596 : continue;
12929 : 3596 : }
12930 : :
12931 : 47885 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
12932 : 37922 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
12933 : 37723 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
12934 : 48133 : && is_omp_target (stmt))
12935 : : {
12936 : 228 : gcc_assert (maybe_lookup_field (c, ctx));
12937 : 228 : map_cnt++;
12938 : 228 : continue;
12939 : : }
12940 : :
12941 : 47657 : if (!maybe_lookup_field (var, ctx))
12942 : 5623 : continue;
12943 : :
12944 : : /* Don't remap compute constructs' reduction variables, because the
12945 : : intermediate result must be local to each gang. */
12946 : 69137 : if (offloaded && !(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
12947 : 23207 : && is_gimple_omp_oacc (ctx->stmt)
12948 : 13556 : && OMP_CLAUSE_MAP_IN_REDUCTION (c)))
12949 : : {
12950 : 26323 : x = build_receiver_ref (var, true, ctx);
12951 : 26323 : tree new_var = lookup_decl (var, ctx);
12952 : :
12953 : 26323 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
12954 : 22427 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
12955 : 3003 : && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c)
12956 : 29326 : && TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
12957 : 425 : x = build_simple_mem_ref (x);
12958 : 26323 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
12959 : : {
12960 : 3896 : gcc_assert (is_gimple_omp_oacc (ctx->stmt));
12961 : 3896 : if (omp_privatize_by_reference (new_var)
12962 : 3896 : && (TREE_CODE (TREE_TYPE (new_var)) != POINTER_TYPE
12963 : 44 : || DECL_BY_REFERENCE (var)))
12964 : : {
12965 : : /* Create a local object to hold the instance
12966 : : value. */
12967 : 455 : tree type = TREE_TYPE (TREE_TYPE (new_var));
12968 : 455 : const char *id = IDENTIFIER_POINTER (DECL_NAME (new_var));
12969 : 455 : tree inst = create_tmp_var (type, id);
12970 : 455 : gimplify_assign (inst, fold_indirect_ref (x), &fplist);
12971 : 455 : x = build_fold_addr_expr (inst);
12972 : : }
12973 : 3896 : gimplify_assign (new_var, x, &fplist);
12974 : : }
12975 : 22427 : else if (DECL_P (new_var))
12976 : : {
12977 : 22427 : SET_DECL_VALUE_EXPR (new_var, x);
12978 : 22427 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
12979 : : }
12980 : : else
12981 : 0 : gcc_unreachable ();
12982 : : }
12983 : 42034 : map_cnt++;
12984 : 42034 : break;
12985 : :
12986 : 14851 : case OMP_CLAUSE_FIRSTPRIVATE:
12987 : 14851 : omp_firstprivate_recv:
12988 : 14851 : gcc_checking_assert (offloaded);
12989 : 14851 : if (is_gimple_omp_oacc (ctx->stmt))
12990 : : {
12991 : : /* No 'firstprivate' clauses on OpenACC 'kernels'. */
12992 : 3896 : gcc_checking_assert (!is_oacc_kernels (ctx));
12993 : : /* Likewise, on OpenACC 'kernels' decomposed parts. */
12994 : 3896 : gcc_checking_assert (!is_oacc_kernels_decomposed_part (ctx));
12995 : :
12996 : 3896 : goto oacc_firstprivate;
12997 : : }
12998 : 10955 : map_cnt++;
12999 : 10955 : var = OMP_CLAUSE_DECL (c);
13000 : 10955 : if (!omp_privatize_by_reference (var)
13001 : 10955 : && !is_gimple_reg_type (TREE_TYPE (var)))
13002 : : {
13003 : 102 : tree new_var = lookup_decl (var, ctx);
13004 : 102 : if (is_variable_sized (var))
13005 : : {
13006 : 4 : tree pvar = DECL_VALUE_EXPR (var);
13007 : 4 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
13008 : 4 : pvar = TREE_OPERAND (pvar, 0);
13009 : 4 : gcc_assert (DECL_P (pvar));
13010 : 4 : tree new_pvar = lookup_decl (pvar, ctx);
13011 : 4 : x = build_fold_indirect_ref (new_pvar);
13012 : 4 : TREE_THIS_NOTRAP (x) = 1;
13013 : : }
13014 : : else
13015 : 98 : x = build_receiver_ref (var, true, ctx);
13016 : 102 : SET_DECL_VALUE_EXPR (new_var, x);
13017 : 102 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
13018 : : }
13019 : : /* Fortran array descriptors: firstprivate of data + attach. */
13020 : 10955 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR
13021 : 10955 : && lang_hooks.decls.omp_array_data (var, true))
13022 : 18 : map_cnt += 2;
13023 : : break;
13024 : :
13025 : 173 : case OMP_CLAUSE_PRIVATE:
13026 : 173 : gcc_checking_assert (offloaded);
13027 : 173 : if (is_gimple_omp_oacc (ctx->stmt))
13028 : : {
13029 : : /* No 'private' clauses on OpenACC 'kernels'. */
13030 : 80 : gcc_checking_assert (!is_oacc_kernels (ctx));
13031 : : /* Likewise, on OpenACC 'kernels' decomposed parts. */
13032 : 80 : gcc_checking_assert (!is_oacc_kernels_decomposed_part (ctx));
13033 : :
13034 : : break;
13035 : : }
13036 : 93 : var = OMP_CLAUSE_DECL (c);
13037 : 93 : if (is_variable_sized (var))
13038 : : {
13039 : 1 : tree new_var = lookup_decl (var, ctx);
13040 : 1 : tree pvar = DECL_VALUE_EXPR (var);
13041 : 1 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
13042 : 1 : pvar = TREE_OPERAND (pvar, 0);
13043 : 1 : gcc_assert (DECL_P (pvar));
13044 : 1 : tree new_pvar = lookup_decl (pvar, ctx);
13045 : 1 : x = build_fold_indirect_ref (new_pvar);
13046 : 1 : TREE_THIS_NOTRAP (x) = 1;
13047 : 1 : SET_DECL_VALUE_EXPR (new_var, x);
13048 : 1 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
13049 : : }
13050 : : break;
13051 : :
13052 : 2414 : case OMP_CLAUSE_USE_DEVICE_PTR:
13053 : 2414 : case OMP_CLAUSE_USE_DEVICE_ADDR:
13054 : 2414 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
13055 : 2414 : case OMP_CLAUSE_IS_DEVICE_PTR:
13056 : 2414 : var = OMP_CLAUSE_DECL (c);
13057 : 2414 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
13058 : : {
13059 : 238 : while (TREE_CODE (var) == INDIRECT_REF
13060 : 238 : || TREE_CODE (var) == ARRAY_REF)
13061 : 17 : var = TREE_OPERAND (var, 0);
13062 : 221 : if (lang_hooks.decls.omp_array_data (var, true))
13063 : 13 : goto omp_firstprivate_recv;
13064 : : }
13065 : 2401 : map_cnt++;
13066 : 2401 : if (is_variable_sized (var))
13067 : : {
13068 : 12 : tree new_var = lookup_decl (var, ctx);
13069 : 12 : tree pvar = DECL_VALUE_EXPR (var);
13070 : 12 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
13071 : 12 : pvar = TREE_OPERAND (pvar, 0);
13072 : 12 : gcc_assert (DECL_P (pvar));
13073 : 12 : tree new_pvar = lookup_decl (pvar, ctx);
13074 : 12 : x = build_fold_indirect_ref (new_pvar);
13075 : 12 : TREE_THIS_NOTRAP (x) = 1;
13076 : 12 : SET_DECL_VALUE_EXPR (new_var, x);
13077 : 12 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
13078 : : }
13079 : 2389 : else if (((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR
13080 : 532 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
13081 : 2063 : && !omp_privatize_by_reference (var)
13082 : 695 : && !omp_is_allocatable_or_ptr (var)
13083 : 556 : && !lang_hooks.decls.omp_array_data (var, true))
13084 : 4421 : || TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
13085 : : {
13086 : 381 : tree new_var = lookup_decl (var, ctx);
13087 : 381 : tree type = build_pointer_type (TREE_TYPE (var));
13088 : 381 : x = create_tmp_var_raw (type, get_name (new_var));
13089 : 381 : gimple_add_tmp_var (x);
13090 : 381 : x = build_simple_mem_ref (x);
13091 : 381 : SET_DECL_VALUE_EXPR (new_var, x);
13092 : 381 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
13093 : : }
13094 : : else
13095 : : {
13096 : 2008 : tree new_var = lookup_decl (var, ctx);
13097 : 2008 : x = create_tmp_var_raw (TREE_TYPE (new_var), get_name (new_var));
13098 : 2008 : gimple_add_tmp_var (x);
13099 : 2008 : SET_DECL_VALUE_EXPR (new_var, x);
13100 : 2008 : DECL_HAS_VALUE_EXPR_P (new_var) = 1;
13101 : : }
13102 : : break;
13103 : 10 : case OMP_CLAUSE_DEVICE_TYPE:
13104 : : /* FIXME: Ensure that 'nohost' also has not implied before that
13105 : : 'g->have_offload = true' or an implicit declare target. */
13106 : 10 : if (OMP_CLAUSE_DEVICE_TYPE_KIND (c) != OMP_CLAUSE_DEVICE_TYPE_ANY)
13107 : 5 : sorry_at (OMP_CLAUSE_LOCATION (c),
13108 : : "only the %<device_type(any)%> is supported");
13109 : : break;
13110 : : }
13111 : :
13112 : 36189 : if (offloaded)
13113 : : {
13114 : 20555 : target_nesting_level++;
13115 : 20555 : lower_omp (&tgt_body, ctx);
13116 : 20555 : target_nesting_level--;
13117 : : }
13118 : 15634 : else if (data_region)
13119 : 4011 : lower_omp (&tgt_body, ctx);
13120 : :
13121 : 36189 : if (offloaded)
13122 : : {
13123 : : /* Declare all the variables created by mapping and the variables
13124 : : declared in the scope of the target body. */
13125 : 20555 : record_vars_into (ctx->block_vars, child_fn);
13126 : 20555 : maybe_remove_omp_member_access_dummy_vars (tgt_bind);
13127 : 20555 : record_vars_into (gimple_bind_vars (tgt_bind), child_fn);
13128 : : }
13129 : :
13130 : 36189 : if (ctx->record_type)
13131 : : {
13132 : 31347 : if (deep_map_cnt && TREE_CODE (deep_map_cnt) == INTEGER_CST)
13133 : : /* map_cnt = map_cnt + tree_to_hwi (deep_map_cnt); */
13134 : : /* deep_map_cnt = NULL_TREE; */
13135 : 0 : gcc_unreachable ();
13136 : 136 : else if (deep_map_cnt)
13137 : : {
13138 : 136 : gcc_assert (flexible_array_type_p (ctx->record_type));
13139 : 136 : tree n = create_tmp_var_raw (size_type_node, "nn_map");
13140 : 136 : gimple_add_tmp_var (n);
13141 : 136 : gimplify_assign (n, deep_map_cnt, &ilist);
13142 : 136 : deep_map_cnt = n;
13143 : : }
13144 : 136 : ctx->sender_decl
13145 : 31347 : = create_tmp_var (deep_map_cnt ? build_pointer_type (ctx->record_type)
13146 : : : ctx->record_type, ".omp_data_arr");
13147 : 31347 : DECL_NAMELESS (ctx->sender_decl) = 1;
13148 : 31347 : TREE_ADDRESSABLE (ctx->sender_decl) = 1;
13149 : 62558 : t = make_tree_vec (deep_map_cnt ? 4 : 3);
13150 : 31347 : TREE_VEC_ELT (t, 0) = ctx->sender_decl;
13151 : 31347 : TREE_VEC_ELT (t, 1)
13152 : 62694 : = create_tmp_var (deep_map_cnt
13153 : 136 : ? build_pointer_type (size_type_node)
13154 : 31211 : : build_array_type_nelts (size_type_node, map_cnt),
13155 : : ".omp_data_sizes");
13156 : 31347 : DECL_NAMELESS (TREE_VEC_ELT (t, 1)) = 1;
13157 : 31347 : TREE_ADDRESSABLE (TREE_VEC_ELT (t, 1)) = 1;
13158 : 31347 : TREE_STATIC (TREE_VEC_ELT (t, 1)) = 1;
13159 : 31347 : tree tkind_type = short_unsigned_type_node;
13160 : 31347 : int talign_shift = 8;
13161 : 31347 : TREE_VEC_ELT (t, 2)
13162 : 62694 : = create_tmp_var (deep_map_cnt
13163 : 136 : ? build_pointer_type (tkind_type)
13164 : 31211 : : build_array_type_nelts (tkind_type, map_cnt),
13165 : : ".omp_data_kinds");
13166 : 31347 : DECL_NAMELESS (TREE_VEC_ELT (t, 2)) = 1;
13167 : 31347 : TREE_ADDRESSABLE (TREE_VEC_ELT (t, 2)) = 1;
13168 : 31347 : TREE_STATIC (TREE_VEC_ELT (t, 2)) = 1;
13169 : 31347 : gimple_omp_target_set_data_arg (stmt, t);
13170 : :
13171 : 31347 : if (deep_map_cnt)
13172 : : {
13173 : 136 : tree tmp, size;
13174 : 136 : size = create_tmp_var (size_type_node, NULL);
13175 : 136 : DECL_NAMELESS (size) = 1;
13176 : 136 : gimplify_assign (size,
13177 : : fold_build2_loc (UNKNOWN_LOCATION, PLUS_EXPR,
13178 : : size_type_node, deep_map_cnt,
13179 : : build_int_cst (size_type_node,
13180 : 136 : map_cnt)), &ilist);
13181 : 136 : TREE_VEC_ELT (t, 3) = size;
13182 : :
13183 : 136 : tree call = builtin_decl_explicit (BUILT_IN_MALLOC);
13184 : 136 : size = fold_build2_loc (UNKNOWN_LOCATION, MULT_EXPR,
13185 : : size_type_node, deep_map_cnt,
13186 : 136 : TYPE_SIZE_UNIT (ptr_type_node));
13187 : 136 : size = fold_build2_loc (UNKNOWN_LOCATION, PLUS_EXPR,
13188 : : size_type_node, size,
13189 : 136 : TYPE_SIZE_UNIT (ctx->record_type));
13190 : 136 : tmp = build_call_expr_loc (input_location, call, 1, size);
13191 : 136 : gimplify_assign (ctx->sender_decl, tmp, &ilist);
13192 : :
13193 : 136 : size = fold_build2_loc (UNKNOWN_LOCATION, MULT_EXPR,
13194 : 136 : size_type_node, TREE_VEC_ELT (t, 3),
13195 : 136 : TYPE_SIZE_UNIT (size_type_node));
13196 : 136 : tmp = build_call_expr_loc (input_location, call, 1, size);
13197 : 136 : gimplify_assign (TREE_VEC_ELT (t, 1), tmp, &ilist);
13198 : :
13199 : 136 : size = fold_build2_loc (UNKNOWN_LOCATION, MULT_EXPR,
13200 : 136 : size_type_node, TREE_VEC_ELT (t, 3),
13201 : 136 : TYPE_SIZE_UNIT (tkind_type));
13202 : 136 : tmp = build_call_expr_loc (input_location, call, 1, size);
13203 : 136 : gimplify_assign (TREE_VEC_ELT (t, 2), tmp, &ilist);
13204 : 136 : tree field = TYPE_FIELDS (TREE_TYPE (TREE_TYPE (ctx->sender_decl)));
13205 : 567 : for ( ; DECL_CHAIN (field) != NULL_TREE; field = DECL_CHAIN (field))
13206 : : ;
13207 : 136 : gcc_assert (TREE_CODE (TREE_TYPE (field)));
13208 : 136 : tmp = build_fold_indirect_ref (ctx->sender_decl);
13209 : 136 : deep_map_data = omp_build_component_ref (tmp, field);
13210 : 136 : deep_map_offset_data = create_tmp_var_raw (size_type_node,
13211 : : "map_offset_data");
13212 : 136 : deep_map_offset = create_tmp_var_raw (size_type_node, "map_offset");
13213 : 136 : gimple_add_tmp_var (deep_map_offset_data);
13214 : 136 : gimple_add_tmp_var (deep_map_offset);
13215 : 136 : gimplify_assign (deep_map_offset_data, build_int_cst (size_type_node,
13216 : : 0), &ilist);
13217 : 136 : gimplify_assign (deep_map_offset, build_int_cst (size_type_node,
13218 : 136 : map_cnt), &ilist);
13219 : : }
13220 : :
13221 : 31347 : vec<constructor_elt, va_gc> *vsize;
13222 : 31347 : vec<constructor_elt, va_gc> *vkind;
13223 : 31347 : vec_alloc (vsize, map_cnt);
13224 : 31347 : vec_alloc (vkind, map_cnt);
13225 : 31347 : unsigned int map_idx = 0;
13226 : :
13227 : 156267 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
13228 : 124920 : switch (OMP_CLAUSE_CODE (c))
13229 : : {
13230 : : tree ovar, nc, s, purpose, var, x, type;
13231 : : unsigned int talign;
13232 : :
13233 : : default:
13234 : 120956 : break;
13235 : :
13236 : 84875 : case OMP_CLAUSE_MAP:
13237 : 84875 : case OMP_CLAUSE_TO:
13238 : 84875 : case OMP_CLAUSE_FROM:
13239 : 84875 : oacc_firstprivate_map:
13240 : 84875 : nc = c;
13241 : 84875 : ovar = OMP_CLAUSE_DECL (c);
13242 : 84875 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13243 : 84875 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
13244 : 70090 : || (OMP_CLAUSE_MAP_KIND (c)
13245 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE)))
13246 : : break;
13247 : 81109 : if (deep_map_cnt)
13248 : : {
13249 : 397 : unsigned HOST_WIDE_INT tkind2;
13250 : 397 : switch (OMP_CLAUSE_CODE (c))
13251 : : {
13252 : 393 : case OMP_CLAUSE_MAP:
13253 : 393 : tkind2 = OMP_CLAUSE_MAP_KIND (c);
13254 : 393 : if (OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (c)
13255 : 393 : && (((tkind2 & GOMP_MAP_FLAG_SPECIAL_BITS)
13256 : : & ~GOMP_MAP_IMPLICIT)
13257 : : == 0))
13258 : : {
13259 : : /* If this is an implicit map, and the GOMP_MAP_IMPLICIT
13260 : : bits are not interfered by other special bit
13261 : : encodings, then turn the GOMP_IMPLICIT_BIT flag on
13262 : : for the runtime to see. */
13263 : 91 : tkind2 |= GOMP_MAP_IMPLICIT;
13264 : : }
13265 : : break;
13266 : : case OMP_CLAUSE_FIRSTPRIVATE: tkind2 = GOMP_MAP_TO; break;
13267 : : case OMP_CLAUSE_TO: tkind2 = GOMP_MAP_TO; break;
13268 : 2 : case OMP_CLAUSE_FROM: tkind2 = GOMP_MAP_FROM; break;
13269 : 0 : default: gcc_unreachable ();
13270 : : }
13271 : 397 : lang_hooks.decls.omp_deep_mapping (stmt, c, tkind2,
13272 : : deep_map_data,
13273 : 397 : TREE_VEC_ELT (t, 1),
13274 : 397 : TREE_VEC_ELT (t, 2),
13275 : : deep_map_offset_data,
13276 : : deep_map_offset, &ilist);
13277 : : }
13278 : 81109 : if (!DECL_P (ovar))
13279 : : {
13280 : 34883 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13281 : 34883 : && OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c))
13282 : : {
13283 : 0 : nc = OMP_CLAUSE_CHAIN (c);
13284 : 0 : gcc_checking_assert (OMP_CLAUSE_DECL (nc)
13285 : : == get_base_address (ovar));
13286 : 0 : ovar = OMP_CLAUSE_DECL (nc);
13287 : : }
13288 : : else
13289 : : {
13290 : 34883 : tree x = build_sender_ref (ovar, ctx);
13291 : 34883 : tree v = ovar;
13292 : 34883 : if (in_reduction_clauses
13293 : 163 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13294 : 35046 : && OMP_CLAUSE_MAP_IN_REDUCTION (c))
13295 : : {
13296 : 104 : v = unshare_expr (v);
13297 : 104 : tree *p = &v;
13298 : 104 : while (handled_component_p (*p)
13299 : : || TREE_CODE (*p) == INDIRECT_REF
13300 : : || TREE_CODE (*p) == ADDR_EXPR
13301 : : || TREE_CODE (*p) == MEM_REF
13302 : 256 : || TREE_CODE (*p) == NON_LVALUE_EXPR)
13303 : 152 : p = &TREE_OPERAND (*p, 0);
13304 : 104 : tree d = *p;
13305 : 104 : if (is_variable_sized (d))
13306 : : {
13307 : 16 : gcc_assert (DECL_HAS_VALUE_EXPR_P (d));
13308 : 16 : d = DECL_VALUE_EXPR (d);
13309 : 16 : gcc_assert (TREE_CODE (d) == INDIRECT_REF);
13310 : 16 : d = TREE_OPERAND (d, 0);
13311 : 16 : gcc_assert (DECL_P (d));
13312 : : }
13313 : 104 : splay_tree_key key
13314 : 104 : = (splay_tree_key) &DECL_CONTEXT (d);
13315 : 104 : tree nd = (tree) splay_tree_lookup (ctx->field_map,
13316 : 104 : key)->value;
13317 : 104 : if (d == *p)
13318 : 88 : *p = nd;
13319 : : else
13320 : 16 : *p = build_fold_indirect_ref (nd);
13321 : : }
13322 : 34883 : v = build_fold_addr_expr_with_type (v, ptr_type_node);
13323 : 34883 : v = lower_omp_map_iterator_expr (v, c, stmt);
13324 : 34883 : gimplify_assign (x, v, &ilist);
13325 : 34883 : nc = NULL_TREE;
13326 : : }
13327 : : }
13328 : : else
13329 : : {
13330 : 46226 : if (DECL_SIZE (ovar)
13331 : 46226 : && !poly_int_tree_p (DECL_SIZE (ovar)))
13332 : : {
13333 : 7 : tree ovar2 = DECL_VALUE_EXPR (ovar);
13334 : 7 : gcc_assert (TREE_CODE (ovar2) == INDIRECT_REF);
13335 : 7 : ovar2 = TREE_OPERAND (ovar2, 0);
13336 : 7 : gcc_assert (DECL_P (ovar2));
13337 : : ovar = ovar2;
13338 : : }
13339 : 46226 : if (!maybe_lookup_field (ovar, ctx)
13340 : 50320 : && !(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13341 : 4094 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
13342 : 4006 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)))
13343 : 3964 : continue;
13344 : : }
13345 : :
13346 : 77145 : talign = TYPE_ALIGN_UNIT (TREE_TYPE (ovar));
13347 : 77145 : if (DECL_P (ovar) && DECL_ALIGN_UNIT (ovar) > talign)
13348 : 6295 : talign = DECL_ALIGN_UNIT (ovar);
13349 : :
13350 : 77145 : var = NULL_TREE;
13351 : 77145 : if (nc)
13352 : : {
13353 : 42262 : if (in_reduction_clauses
13354 : 897 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13355 : 43159 : && OMP_CLAUSE_MAP_IN_REDUCTION (c))
13356 : : {
13357 : 268 : tree d = ovar;
13358 : 268 : if (is_variable_sized (d))
13359 : : {
13360 : 0 : gcc_assert (DECL_HAS_VALUE_EXPR_P (d));
13361 : 0 : d = DECL_VALUE_EXPR (d);
13362 : 0 : gcc_assert (TREE_CODE (d) == INDIRECT_REF);
13363 : 0 : d = TREE_OPERAND (d, 0);
13364 : 0 : gcc_assert (DECL_P (d));
13365 : : }
13366 : 268 : splay_tree_key key
13367 : 268 : = (splay_tree_key) &DECL_CONTEXT (d);
13368 : 268 : tree nd = (tree) splay_tree_lookup (ctx->field_map,
13369 : 268 : key)->value;
13370 : 268 : if (d == ovar)
13371 : : var = nd;
13372 : : else
13373 : 0 : var = build_fold_indirect_ref (nd);
13374 : : }
13375 : : else
13376 : 41994 : var = lookup_decl_in_outer_ctx (ovar, ctx);
13377 : : }
13378 : 42262 : if (nc
13379 : 42262 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13380 : 32299 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
13381 : 32100 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
13382 : 248 : && is_omp_target (stmt))
13383 : : {
13384 : 228 : x = build_sender_ref (c, ctx);
13385 : 228 : gimplify_assign (x, build_fold_addr_expr (var), &ilist);
13386 : : }
13387 : 76917 : else if (nc)
13388 : : {
13389 : 42034 : x = build_sender_ref (ovar, ctx);
13390 : :
13391 : 42034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
13392 : 32071 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
13393 : 5169 : && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c)
13394 : 47203 : && TREE_CODE (TREE_TYPE (ovar)) == ARRAY_TYPE)
13395 : : {
13396 : 425 : gcc_assert (offloaded);
13397 : 425 : tree avar = build_fold_addr_expr (var);
13398 : 425 : if (!OMP_CLAUSE_ITERATORS (c))
13399 : : {
13400 : 425 : tree tmp = create_tmp_var (TREE_TYPE (TREE_TYPE (x)));
13401 : 425 : mark_addressable (tmp);
13402 : 425 : gimplify_assign (tmp, avar, &ilist);
13403 : 425 : avar = tmp;
13404 : : }
13405 : 425 : talign = TYPE_ALIGN_UNIT (TREE_TYPE (TREE_TYPE (x)));
13406 : 425 : avar = build_fold_addr_expr (avar);
13407 : 425 : avar = lower_omp_map_iterator_expr (avar, c, stmt);
13408 : 425 : gimplify_assign (x, avar, &ilist);
13409 : : }
13410 : 41609 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
13411 : : {
13412 : 3896 : gcc_assert (is_gimple_omp_oacc (ctx->stmt));
13413 : 3896 : if (!omp_privatize_by_reference (var))
13414 : : {
13415 : 3441 : if (is_gimple_reg (var)
13416 : 3441 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
13417 : 2578 : suppress_warning (var);
13418 : 3441 : var = build_fold_addr_expr (var);
13419 : : }
13420 : : else
13421 : 455 : talign = TYPE_ALIGN_UNIT (TREE_TYPE (TREE_TYPE (ovar)));
13422 : 3896 : gimplify_assign (x, var, &ilist);
13423 : : }
13424 : 37713 : else if (is_gimple_reg (var))
13425 : : {
13426 : 5122 : gcc_assert (offloaded);
13427 : 5122 : tree avar = create_tmp_var (TREE_TYPE (var));
13428 : 5122 : mark_addressable (avar);
13429 : 5122 : enum gomp_map_kind map_kind = OMP_CLAUSE_MAP_KIND (c);
13430 : 5122 : if (GOMP_MAP_COPY_TO_P (map_kind)
13431 : : || map_kind == GOMP_MAP_POINTER
13432 : 475 : || map_kind == GOMP_MAP_TO_PSET
13433 : 2 : || map_kind == GOMP_MAP_FORCE_DEVICEPTR)
13434 : : {
13435 : : /* If we need to initialize a temporary
13436 : : with VAR because it is not addressable, and
13437 : : the variable hasn't been initialized yet, then
13438 : : we'll get a warning for the store to avar.
13439 : : Don't warn in that case, the mapping might
13440 : : be implicit. */
13441 : 5120 : suppress_warning (var, OPT_Wuninitialized);
13442 : 5120 : gimplify_assign (avar, var, &ilist);
13443 : : }
13444 : 5122 : avar = build_fold_addr_expr (avar);
13445 : 5122 : gimplify_assign (x, avar, &ilist);
13446 : 5122 : if ((GOMP_MAP_COPY_FROM_P (map_kind)
13447 : 1325 : || map_kind == GOMP_MAP_FORCE_DEVICEPTR)
13448 : 8919 : && !TYPE_READONLY (TREE_TYPE (var)))
13449 : : {
13450 : 3797 : x = unshare_expr (x);
13451 : 3797 : x = build_simple_mem_ref (x);
13452 : 3797 : gimplify_assign (var, x, &olist);
13453 : : }
13454 : : }
13455 : : else
13456 : : {
13457 : : /* While MAP is handled explicitly by the FE,
13458 : : for 'target update', only the identified is passed. */
13459 : 32591 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM
13460 : 27467 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO)
13461 : 33534 : && (omp_is_allocatable_or_ptr (var)
13462 : 120 : && omp_check_optional_argument (var, false)))
13463 : 0 : var = build_fold_indirect_ref (var);
13464 : 32591 : else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FROM
13465 : 27467 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TO)
13466 : 33534 : || (!omp_is_allocatable_or_ptr (var)
13467 : 5947 : && !omp_check_optional_argument (var, false)))
13468 : 32471 : var = build_fold_addr_expr (var);
13469 : 32591 : gimplify_assign (x, var, &ilist);
13470 : : }
13471 : : }
13472 : 77145 : s = NULL_TREE;
13473 : 77145 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
13474 : : {
13475 : 3896 : gcc_checking_assert (is_gimple_omp_oacc (ctx->stmt));
13476 : 3896 : s = TREE_TYPE (ovar);
13477 : 3896 : if (TREE_CODE (s) == REFERENCE_TYPE
13478 : 3896 : || omp_check_optional_argument (ovar, false))
13479 : 449 : s = TREE_TYPE (s);
13480 : 3896 : s = TYPE_SIZE_UNIT (s);
13481 : : }
13482 : : else
13483 : 73249 : s = OMP_CLAUSE_SIZE (c);
13484 : 77145 : if (s == NULL_TREE)
13485 : 123 : s = TYPE_SIZE_UNIT (TREE_TYPE (ovar));
13486 : 77145 : s = fold_convert (size_type_node, s);
13487 : 77145 : s = lower_omp_map_iterator_size (s, c, stmt);
13488 : 77145 : purpose = size_int (map_idx++);
13489 : 77145 : CONSTRUCTOR_APPEND_ELT (vsize, purpose, s);
13490 : 77145 : if (TREE_CODE (s) != INTEGER_CST)
13491 : 15580 : TREE_STATIC (TREE_VEC_ELT (t, 1)) = 0;
13492 : :
13493 : 77145 : unsigned HOST_WIDE_INT tkind, tkind_zero;
13494 : 77145 : switch (OMP_CLAUSE_CODE (c))
13495 : : {
13496 : 65701 : case OMP_CLAUSE_MAP:
13497 : 65701 : tkind = OMP_CLAUSE_MAP_KIND (c);
13498 : 65701 : tkind_zero = tkind;
13499 : 65701 : if (OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c))
13500 : 5267 : switch (tkind)
13501 : : {
13502 : : case GOMP_MAP_ALLOC:
13503 : : case GOMP_MAP_IF_PRESENT:
13504 : : case GOMP_MAP_TO:
13505 : : case GOMP_MAP_FROM:
13506 : : case GOMP_MAP_TOFROM:
13507 : : case GOMP_MAP_ALWAYS_TO:
13508 : : case GOMP_MAP_ALWAYS_FROM:
13509 : : case GOMP_MAP_ALWAYS_TOFROM:
13510 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
13511 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
13512 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
13513 : : case GOMP_MAP_RELEASE:
13514 : : case GOMP_MAP_FORCE_TO:
13515 : : case GOMP_MAP_FORCE_FROM:
13516 : : case GOMP_MAP_FORCE_TOFROM:
13517 : : case GOMP_MAP_FORCE_PRESENT:
13518 : 65701 : tkind_zero = GOMP_MAP_ZERO_LEN_ARRAY_SECTION;
13519 : : break;
13520 : 20 : case GOMP_MAP_DELETE:
13521 : 20 : tkind_zero = GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION;
13522 : : default:
13523 : : break;
13524 : : }
13525 : 65701 : if (tkind_zero != tkind)
13526 : : {
13527 : 5267 : if (integer_zerop (s))
13528 : : tkind = tkind_zero;
13529 : 4541 : else if (integer_nonzerop (s))
13530 : 65701 : tkind_zero = tkind;
13531 : : }
13532 : 65701 : if (tkind_zero == tkind
13533 : 64240 : && OMP_CLAUSE_MAP_RUNTIME_IMPLICIT_P (c)
13534 : 65701 : && (((tkind & GOMP_MAP_FLAG_SPECIAL_BITS)
13535 : 5019 : & ~GOMP_MAP_IMPLICIT)
13536 : : == 0))
13537 : : {
13538 : : /* If this is an implicit map, and the GOMP_MAP_IMPLICIT
13539 : : bits are not interfered by other special bit encodings,
13540 : : then turn the GOMP_IMPLICIT_BIT flag on for the runtime
13541 : : to see. */
13542 : 4977 : tkind |= GOMP_MAP_IMPLICIT;
13543 : 4977 : tkind_zero = tkind;
13544 : : }
13545 : : break;
13546 : 3896 : case OMP_CLAUSE_FIRSTPRIVATE:
13547 : 3896 : gcc_checking_assert (is_gimple_omp_oacc (ctx->stmt));
13548 : : tkind = GOMP_MAP_TO;
13549 : : tkind_zero = tkind;
13550 : : break;
13551 : 1583 : case OMP_CLAUSE_TO:
13552 : 1583 : tkind
13553 : 1583 : = (OMP_CLAUSE_MOTION_PRESENT (c)
13554 : 1583 : ? GOMP_MAP_ALWAYS_PRESENT_TO : GOMP_MAP_TO);
13555 : : tkind_zero = tkind;
13556 : : break;
13557 : 5965 : case OMP_CLAUSE_FROM:
13558 : 5965 : tkind
13559 : 5965 : = (OMP_CLAUSE_MOTION_PRESENT (c)
13560 : 5965 : ? GOMP_MAP_ALWAYS_PRESENT_FROM : GOMP_MAP_FROM);
13561 : : tkind_zero = tkind;
13562 : : break;
13563 : 0 : default:
13564 : 0 : gcc_unreachable ();
13565 : : }
13566 : 65701 : gcc_checking_assert (tkind
13567 : : < (HOST_WIDE_INT_C (1U) << talign_shift));
13568 : 77145 : gcc_checking_assert (tkind_zero
13569 : : < (HOST_WIDE_INT_C (1U) << talign_shift));
13570 : 77145 : talign = ceil_log2 (talign);
13571 : 77145 : tkind |= talign << talign_shift;
13572 : 77145 : tkind_zero |= talign << talign_shift;
13573 : 77145 : gcc_checking_assert (tkind
13574 : : <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
13575 : 77145 : gcc_checking_assert (tkind_zero
13576 : : <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
13577 : 77145 : if (tkind == tkind_zero)
13578 : 75684 : x = build_int_cstu (tkind_type, tkind);
13579 : : else
13580 : : {
13581 : 1461 : TREE_STATIC (TREE_VEC_ELT (t, 2)) = 0;
13582 : 1461 : x = build3 (COND_EXPR, tkind_type,
13583 : : fold_build2 (EQ_EXPR, boolean_type_node,
13584 : : unshare_expr (s), size_zero_node),
13585 : 1461 : build_int_cstu (tkind_type, tkind_zero),
13586 : 1461 : build_int_cstu (tkind_type, tkind));
13587 : : }
13588 : 77145 : CONSTRUCTOR_APPEND_ELT (vkind, purpose, x);
13589 : 77145 : if (nc && nc != c)
13590 : 0 : c = nc;
13591 : : break;
13592 : :
13593 : 14851 : case OMP_CLAUSE_FIRSTPRIVATE:
13594 : 14851 : omp_has_device_addr_descr:
13595 : 14851 : if (is_gimple_omp_oacc (ctx->stmt))
13596 : 3896 : goto oacc_firstprivate_map;
13597 : 10955 : ovar = OMP_CLAUSE_DECL (c);
13598 : 10955 : if (omp_privatize_by_reference (ovar))
13599 : 792 : talign = TYPE_ALIGN_UNIT (TREE_TYPE (TREE_TYPE (ovar)));
13600 : : else
13601 : 10163 : talign = DECL_ALIGN_UNIT (ovar);
13602 : 10955 : var = lookup_decl_in_outer_ctx (ovar, ctx);
13603 : 10955 : x = build_sender_ref (ovar, ctx);
13604 : 10955 : tkind = GOMP_MAP_FIRSTPRIVATE;
13605 : 10955 : type = TREE_TYPE (ovar);
13606 : 10955 : if (omp_privatize_by_reference (ovar))
13607 : 792 : type = TREE_TYPE (type);
13608 : 10955 : if ((INTEGRAL_TYPE_P (type)
13609 : 10632 : && TYPE_PRECISION (type) <= POINTER_SIZE)
13610 : 10965 : || TREE_CODE (type) == POINTER_TYPE)
13611 : : {
13612 : 10767 : tkind = GOMP_MAP_FIRSTPRIVATE_INT;
13613 : 10767 : tree t = var;
13614 : 10767 : if (omp_privatize_by_reference (var))
13615 : 765 : t = build_simple_mem_ref (var);
13616 : 10002 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
13617 : 8996 : suppress_warning (var);
13618 : 10767 : if (TREE_CODE (type) != POINTER_TYPE)
13619 : 10622 : t = fold_convert (pointer_sized_int_node, t);
13620 : 10767 : t = fold_convert (TREE_TYPE (x), t);
13621 : 10767 : gimplify_assign (x, t, &ilist);
13622 : : }
13623 : 188 : else if (omp_privatize_by_reference (var))
13624 : 27 : gimplify_assign (x, var, &ilist);
13625 : 161 : else if (is_gimple_reg (var))
13626 : : {
13627 : 47 : tree avar = create_tmp_var (TREE_TYPE (var));
13628 : 47 : mark_addressable (avar);
13629 : 47 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
13630 : 40 : suppress_warning (var);
13631 : 47 : gimplify_assign (avar, var, &ilist);
13632 : 47 : avar = build_fold_addr_expr (avar);
13633 : 47 : gimplify_assign (x, avar, &ilist);
13634 : : }
13635 : : else
13636 : : {
13637 : 114 : var = build_fold_addr_expr (var);
13638 : 114 : gimplify_assign (x, var, &ilist);
13639 : : }
13640 : 188 : if (tkind == GOMP_MAP_FIRSTPRIVATE_INT)
13641 : 10767 : s = size_int (0);
13642 : 188 : else if (omp_privatize_by_reference (ovar))
13643 : 27 : s = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ovar)));
13644 : : else
13645 : 161 : s = TYPE_SIZE_UNIT (TREE_TYPE (ovar));
13646 : 10955 : s = fold_convert (size_type_node, s);
13647 : 10955 : purpose = size_int (map_idx++);
13648 : 10955 : CONSTRUCTOR_APPEND_ELT (vsize, purpose, s);
13649 : 10955 : if (TREE_CODE (s) != INTEGER_CST)
13650 : 8 : TREE_STATIC (TREE_VEC_ELT (t, 1)) = 0;
13651 : :
13652 : 10955 : gcc_checking_assert (tkind
13653 : : < (HOST_WIDE_INT_C (1U) << talign_shift));
13654 : 10955 : talign = ceil_log2 (talign);
13655 : 10955 : tkind |= talign << talign_shift;
13656 : 10955 : gcc_checking_assert (tkind
13657 : : <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
13658 : 10955 : CONSTRUCTOR_APPEND_ELT (vkind, purpose,
13659 : : build_int_cstu (tkind_type, tkind));
13660 : : /* Fortran array descriptors: firstprivate of data + attach. */
13661 : 10955 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR
13662 : 10955 : && lang_hooks.decls.omp_array_data (ovar, true))
13663 : : {
13664 : 18 : tree not_null_lb, null_lb, after_lb;
13665 : 18 : tree var1, var2, size1, size2;
13666 : 18 : tree present = omp_check_optional_argument (ovar, true);
13667 : 18 : if (present)
13668 : : {
13669 : 1 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
13670 : 1 : not_null_lb = create_artificial_label (clause_loc);
13671 : 1 : null_lb = create_artificial_label (clause_loc);
13672 : 1 : after_lb = create_artificial_label (clause_loc);
13673 : 1 : gimple_seq seq = NULL;
13674 : 1 : present = force_gimple_operand (present, &seq, true,
13675 : : NULL_TREE);
13676 : 1 : gimple_seq_add_seq (&ilist, seq);
13677 : 1 : gimple_seq_add_stmt (&ilist,
13678 : 1 : gimple_build_cond_from_tree (present,
13679 : : not_null_lb, null_lb));
13680 : 1 : gimple_seq_add_stmt (&ilist,
13681 : 1 : gimple_build_label (not_null_lb));
13682 : : }
13683 : 18 : var1 = lang_hooks.decls.omp_array_data (var, false);
13684 : 18 : size1 = lang_hooks.decls.omp_array_size (var, &ilist);
13685 : 18 : var2 = build_fold_addr_expr (x);
13686 : 18 : if (!POINTER_TYPE_P (TREE_TYPE (var)))
13687 : 0 : var = build_fold_addr_expr (var);
13688 : 18 : size2 = fold_build2 (POINTER_DIFF_EXPR, ssizetype,
13689 : : build_fold_addr_expr (var1), var);
13690 : 18 : size2 = fold_convert (sizetype, size2);
13691 : 18 : if (present)
13692 : : {
13693 : 1 : tree tmp = create_tmp_var (TREE_TYPE (var1));
13694 : 1 : gimplify_assign (tmp, var1, &ilist);
13695 : 1 : var1 = tmp;
13696 : 1 : tmp = create_tmp_var (TREE_TYPE (var2));
13697 : 1 : gimplify_assign (tmp, var2, &ilist);
13698 : 1 : var2 = tmp;
13699 : 1 : tmp = create_tmp_var (TREE_TYPE (size1));
13700 : 1 : gimplify_assign (tmp, size1, &ilist);
13701 : 1 : size1 = tmp;
13702 : 1 : tmp = create_tmp_var (TREE_TYPE (size2));
13703 : 1 : gimplify_assign (tmp, size2, &ilist);
13704 : 1 : size2 = tmp;
13705 : 1 : gimple_seq_add_stmt (&ilist, gimple_build_goto (after_lb));
13706 : 1 : gimple_seq_add_stmt (&ilist, gimple_build_label (null_lb));
13707 : 1 : gimplify_assign (var1, null_pointer_node, &ilist);
13708 : 1 : gimplify_assign (var2, null_pointer_node, &ilist);
13709 : 1 : gimplify_assign (size1, size_zero_node, &ilist);
13710 : 1 : gimplify_assign (size2, size_zero_node, &ilist);
13711 : 1 : gimple_seq_add_stmt (&ilist, gimple_build_label (after_lb));
13712 : : }
13713 : 18 : x = build_sender_ref ((splay_tree_key) &DECL_NAME (ovar), ctx);
13714 : 18 : gimplify_assign (x, var1, &ilist);
13715 : 18 : tkind = GOMP_MAP_FIRSTPRIVATE;
13716 : 18 : talign = DECL_ALIGN_UNIT (ovar);
13717 : 18 : talign = ceil_log2 (talign);
13718 : 18 : tkind |= talign << talign_shift;
13719 : 18 : gcc_checking_assert (tkind
13720 : : <= tree_to_uhwi (
13721 : : TYPE_MAX_VALUE (tkind_type)));
13722 : 18 : purpose = size_int (map_idx++);
13723 : 18 : CONSTRUCTOR_APPEND_ELT (vsize, purpose, size1);
13724 : 18 : if (TREE_CODE (size1) != INTEGER_CST)
13725 : 18 : TREE_STATIC (TREE_VEC_ELT (t, 1)) = 0;
13726 : 18 : CONSTRUCTOR_APPEND_ELT (vkind, purpose,
13727 : : build_int_cstu (tkind_type, tkind));
13728 : 18 : x = build_sender_ref ((splay_tree_key) &DECL_UID (ovar), ctx);
13729 : 18 : gimplify_assign (x, var2, &ilist);
13730 : 18 : tkind = GOMP_MAP_ATTACH;
13731 : 18 : purpose = size_int (map_idx++);
13732 : 18 : CONSTRUCTOR_APPEND_ELT (vsize, purpose, size2);
13733 : 18 : CONSTRUCTOR_APPEND_ELT (vkind, purpose,
13734 : : build_int_cstu (tkind_type, tkind));
13735 : : }
13736 : : break;
13737 : :
13738 : 2414 : case OMP_CLAUSE_USE_DEVICE_PTR:
13739 : 2414 : case OMP_CLAUSE_USE_DEVICE_ADDR:
13740 : 2414 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
13741 : 2414 : case OMP_CLAUSE_IS_DEVICE_PTR:
13742 : 2414 : ovar = OMP_CLAUSE_DECL (c);
13743 : 2414 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
13744 : : {
13745 : 221 : if (lang_hooks.decls.omp_array_data (ovar, true))
13746 : 13 : goto omp_has_device_addr_descr;
13747 : 225 : while (TREE_CODE (ovar) == INDIRECT_REF
13748 : 225 : || TREE_CODE (ovar) == ARRAY_REF)
13749 : 17 : ovar = TREE_OPERAND (ovar, 0);
13750 : : }
13751 : 2401 : var = lookup_decl_in_outer_ctx (ovar, ctx);
13752 : :
13753 : 2401 : if (lang_hooks.decls.omp_array_data (ovar, true))
13754 : : {
13755 : 601 : tkind = ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IS_DEVICE_PTR
13756 : 601 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR)
13757 : 601 : ? GOMP_MAP_USE_DEVICE_PTR : GOMP_MAP_FIRSTPRIVATE_INT);
13758 : 601 : x = build_sender_ref ((splay_tree_key) &DECL_NAME (ovar), ctx);
13759 : : }
13760 : 1800 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IS_DEVICE_PTR
13761 : 1800 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR)
13762 : : {
13763 : 1453 : tkind = GOMP_MAP_USE_DEVICE_PTR;
13764 : 1453 : x = build_sender_ref ((splay_tree_key) &DECL_UID (ovar), ctx);
13765 : : }
13766 : : else
13767 : : {
13768 : 347 : tkind = GOMP_MAP_FIRSTPRIVATE_INT;
13769 : 347 : x = build_sender_ref (ovar, ctx);
13770 : : }
13771 : :
13772 : 2401 : if (is_gimple_omp_oacc (ctx->stmt))
13773 : : {
13774 : 147 : gcc_assert (tkind == GOMP_MAP_USE_DEVICE_PTR);
13775 : :
13776 : 147 : if (OMP_CLAUSE_USE_DEVICE_PTR_IF_PRESENT (c))
13777 : 57 : tkind = GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT;
13778 : : }
13779 : :
13780 : 2401 : type = TREE_TYPE (ovar);
13781 : 2401 : if (lang_hooks.decls.omp_array_data (ovar, true))
13782 : 601 : var = lang_hooks.decls.omp_array_data (var, false);
13783 : 1800 : else if (((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR
13784 : 532 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
13785 : 1476 : && !omp_privatize_by_reference (ovar)
13786 : 504 : && !omp_is_allocatable_or_ptr (ovar))
13787 : 3235 : || TREE_CODE (type) == ARRAY_TYPE)
13788 : 393 : var = build_fold_addr_expr (var);
13789 : : else
13790 : : {
13791 : 1407 : if (omp_privatize_by_reference (ovar)
13792 : 368 : || omp_check_optional_argument (ovar, false)
13793 : 1775 : || omp_is_allocatable_or_ptr (ovar))
13794 : : {
13795 : 1212 : type = TREE_TYPE (type);
13796 : 1212 : if (POINTER_TYPE_P (type)
13797 : 1212 : && TREE_CODE (type) != ARRAY_TYPE
13798 : 1571 : && ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_USE_DEVICE_ADDR
13799 : 36 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR
13800 : 28 : && !omp_is_allocatable_or_ptr (ovar))
13801 : 337 : || (omp_privatize_by_reference (ovar)
13802 : 337 : && omp_is_allocatable_or_ptr (ovar))))
13803 : 357 : var = build_simple_mem_ref (var);
13804 : 1212 : var = fold_convert (TREE_TYPE (x), var);
13805 : : }
13806 : : }
13807 : 2401 : tree present;
13808 : 2401 : present = omp_check_optional_argument (ovar, true);
13809 : 2401 : if (present)
13810 : : {
13811 : 878 : tree null_label = create_artificial_label (UNKNOWN_LOCATION);
13812 : 878 : tree notnull_label = create_artificial_label (UNKNOWN_LOCATION);
13813 : 878 : tree opt_arg_label = create_artificial_label (UNKNOWN_LOCATION);
13814 : 878 : tree new_x = unshare_expr (x);
13815 : 878 : gimplify_expr (&present, &ilist, NULL, is_gimple_val,
13816 : : fb_rvalue);
13817 : 878 : gcond *cond = gimple_build_cond_from_tree (present,
13818 : : notnull_label,
13819 : : null_label);
13820 : 878 : gimple_seq_add_stmt (&ilist, cond);
13821 : 878 : gimple_seq_add_stmt (&ilist, gimple_build_label (null_label));
13822 : 878 : gimplify_assign (new_x, null_pointer_node, &ilist);
13823 : 878 : gimple_seq_add_stmt (&ilist, gimple_build_goto (opt_arg_label));
13824 : 878 : gimple_seq_add_stmt (&ilist,
13825 : 878 : gimple_build_label (notnull_label));
13826 : 878 : gimplify_assign (x, var, &ilist);
13827 : 878 : gimple_seq_add_stmt (&ilist,
13828 : 878 : gimple_build_label (opt_arg_label));
13829 : : }
13830 : : else
13831 : 1523 : gimplify_assign (x, var, &ilist);
13832 : 2401 : s = size_int (0);
13833 : 2401 : purpose = size_int (map_idx++);
13834 : 2401 : CONSTRUCTOR_APPEND_ELT (vsize, purpose, s);
13835 : 2401 : gcc_checking_assert (tkind
13836 : : < (HOST_WIDE_INT_C (1U) << talign_shift));
13837 : 2401 : gcc_checking_assert (tkind
13838 : : <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type)));
13839 : 2401 : CONSTRUCTOR_APPEND_ELT (vkind, purpose,
13840 : : build_int_cstu (tkind_type, tkind));
13841 : 2401 : break;
13842 : : }
13843 : :
13844 : 31347 : gcc_assert (map_idx == map_cnt);
13845 : :
13846 : 31347 : if (!deep_map_cnt)
13847 : : {
13848 : 31211 : DECL_INITIAL (TREE_VEC_ELT (t, 1))
13849 : 31211 : = build_constructor (TREE_TYPE (TREE_VEC_ELT (t, 1)), vsize);
13850 : 31211 : DECL_INITIAL (TREE_VEC_ELT (t, 2))
13851 : 62422 : = build_constructor (TREE_TYPE (TREE_VEC_ELT (t, 2)), vkind);
13852 : : }
13853 : 94041 : for (int i = 1; i <= 2; i++)
13854 : 62694 : if (deep_map_cnt || !TREE_STATIC (TREE_VEC_ELT (t, i)))
13855 : : {
13856 : 9355 : tree tmp = TREE_VEC_ELT (t, i);
13857 : 9355 : if (deep_map_cnt)
13858 : : {
13859 : 272 : const char *prefix = (i == 1 ? ".omp_data_sizes0"
13860 : : : ".omp_data_kinds0");
13861 : 136 : tree type = (i == 1) ? size_type_node : tkind_type;
13862 : 272 : type = build_array_type_nelts (type, map_cnt);
13863 : 272 : tree var = create_tmp_var (type, prefix);
13864 : 272 : DECL_NAMELESS (var) = 1;
13865 : 272 : TREE_ADDRESSABLE (var) = 1;
13866 : 272 : TREE_STATIC (var) = TREE_STATIC (tmp);
13867 : 272 : DECL_INITIAL (var) = build_constructor (type, i == 1
13868 : : ? vsize : vkind);
13869 : 272 : tmp = var;
13870 : 272 : TREE_STATIC (TREE_VEC_ELT (t, i)) = 0;
13871 : : }
13872 : :
13873 : 9355 : gimple_seq initlist = NULL;
13874 : 9355 : force_gimple_operand (build1 (DECL_EXPR, void_type_node, tmp),
13875 : : &initlist, true, NULL_TREE);
13876 : 9355 : gimple_seq_add_seq (&ilist, initlist);
13877 : :
13878 : 9355 : if (deep_map_cnt)
13879 : : {
13880 : 272 : tree tmp2;
13881 : 272 : tree call = builtin_decl_explicit (BUILT_IN_MEMCPY);
13882 : 272 : tmp2 = TYPE_SIZE_UNIT (TREE_TYPE (tmp));
13883 : 544 : call = build_call_expr_loc (input_location, call, 3,
13884 : 272 : TREE_VEC_ELT (t, i),
13885 : : build_fold_addr_expr (tmp), tmp2);
13886 : 272 : gimplify_and_add (call, &ilist);
13887 : : }
13888 : :
13889 : 9355 : if (!TREE_STATIC (tmp))
13890 : : {
13891 : 9177 : tree clobber = build_clobber (TREE_TYPE (tmp));
13892 : 9177 : gimple_seq_add_stmt (&olist,
13893 : 9177 : gimple_build_assign (tmp, clobber));
13894 : : }
13895 : 9355 : if (deep_map_cnt)
13896 : : {
13897 : 272 : tmp = TREE_VEC_ELT (t, i);
13898 : 272 : tree call = builtin_decl_explicit (BUILT_IN_FREE);
13899 : 272 : call = build_call_expr_loc (input_location, call, 1, tmp);
13900 : 272 : gimplify_and_add (call, &olist);
13901 : 272 : tree clobber = build_clobber (TREE_TYPE (tmp));
13902 : 272 : gimple_seq_add_stmt (&olist,
13903 : 272 : gimple_build_assign (tmp, clobber));
13904 : : }
13905 : : }
13906 : 53339 : else if (omp_maybe_offloaded_ctx (ctx->outer))
13907 : : {
13908 : 3296 : tree id = get_identifier ("omp declare target");
13909 : 3296 : tree decl = TREE_VEC_ELT (t, i);
13910 : 3296 : DECL_ATTRIBUTES (decl)
13911 : 3296 : = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
13912 : 3296 : varpool_node *node = varpool_node::get (decl);
13913 : 3296 : if (node)
13914 : : {
13915 : 0 : node->offloadable = 1;
13916 : 0 : if (ENABLE_OFFLOADING)
13917 : : {
13918 : : g->have_offload = true;
13919 : : vec_safe_push (offload_vars, t);
13920 : : }
13921 : : }
13922 : : }
13923 : :
13924 : 31347 : if (deep_map_cnt)
13925 : : {
13926 : 136 : tree call = builtin_decl_explicit (BUILT_IN_FREE);
13927 : 136 : call = build_call_expr_loc (input_location, call, 1,
13928 : 136 : TREE_VEC_ELT (t, 0));
13929 : 136 : gimplify_and_add (call, &olist);
13930 : :
13931 : 136 : gimplify_expr (&TREE_VEC_ELT (t, 1), &ilist, NULL, is_gimple_val,
13932 : : fb_rvalue);
13933 : : }
13934 : :
13935 : 31347 : tree clobber = build_clobber (TREE_TYPE (ctx->sender_decl));
13936 : 31347 : gimple_seq_add_stmt (&olist, gimple_build_assign (ctx->sender_decl,
13937 : : clobber));
13938 : : }
13939 : :
13940 : : /* Once all the expansions are done, sequence all the different
13941 : : fragments inside gimple_omp_body. */
13942 : :
13943 : 36189 : new_body = NULL;
13944 : :
13945 : 36189 : if (offloaded
13946 : 20555 : && ctx->record_type)
13947 : : {
13948 : 15942 : t = ctx->sender_decl;
13949 : 15942 : if (!deep_map_cnt)
13950 : 15853 : t = build_fold_addr_expr_loc (loc, t);
13951 : : /* fixup_child_record_type might have changed receiver_decl's type. */
13952 : 15942 : t = fold_convert_loc (loc, TREE_TYPE (ctx->receiver_decl), t);
13953 : 15942 : if (!AGGREGATE_TYPE_P (TREE_TYPE (ctx->sender_decl)))
13954 : 89 : gimplify_assign (ctx->receiver_decl, t, &new_body);
13955 : : else
13956 : 15853 : gimple_seq_add_stmt (&new_body,
13957 : 15853 : gimple_build_assign (ctx->receiver_decl, t));
13958 : : }
13959 : 36189 : gimple_seq_add_seq (&new_body, fplist);
13960 : :
13961 : 36189 : if (offloaded || data_region)
13962 : : {
13963 : 137254 : tree prev = NULL_TREE;
13964 : 137254 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
13965 : 112688 : switch (OMP_CLAUSE_CODE (c))
13966 : : {
13967 : : tree var, x;
13968 : : default:
13969 : : break;
13970 : 14851 : case OMP_CLAUSE_FIRSTPRIVATE:
13971 : 14851 : omp_firstprivatize_data_region:
13972 : 14851 : if (is_gimple_omp_oacc (ctx->stmt))
13973 : : break;
13974 : 10955 : var = OMP_CLAUSE_DECL (c);
13975 : 10955 : if (omp_privatize_by_reference (var)
13976 : 10955 : || is_gimple_reg_type (TREE_TYPE (var)))
13977 : : {
13978 : 10853 : tree new_var = lookup_decl (var, ctx);
13979 : 10853 : tree type;
13980 : 10853 : type = TREE_TYPE (var);
13981 : 10853 : if (omp_privatize_by_reference (var))
13982 : 792 : type = TREE_TYPE (type);
13983 : 10853 : if ((INTEGRAL_TYPE_P (type)
13984 : 10632 : && TYPE_PRECISION (type) <= POINTER_SIZE)
13985 : 10863 : || TREE_CODE (type) == POINTER_TYPE)
13986 : : {
13987 : 10767 : x = build_receiver_ref (var, false, ctx);
13988 : 10767 : if (TREE_CODE (type) != POINTER_TYPE)
13989 : 10622 : x = fold_convert (pointer_sized_int_node, x);
13990 : 10767 : x = fold_convert (type, x);
13991 : 10767 : gimplify_expr (&x, &new_body, NULL, is_gimple_val,
13992 : : fb_rvalue);
13993 : 10767 : if (omp_privatize_by_reference (var))
13994 : : {
13995 : 765 : tree v = create_tmp_var_raw (type, get_name (var));
13996 : 765 : gimple_add_tmp_var (v);
13997 : 765 : TREE_ADDRESSABLE (v) = 1;
13998 : 765 : gimple_seq_add_stmt (&new_body,
13999 : 765 : gimple_build_assign (v, x));
14000 : 765 : x = build_fold_addr_expr (v);
14001 : : }
14002 : 10767 : gimple_seq_add_stmt (&new_body,
14003 : 10767 : gimple_build_assign (new_var, x));
14004 : : }
14005 : : else
14006 : : {
14007 : 86 : bool by_ref = !omp_privatize_by_reference (var);
14008 : 86 : x = build_receiver_ref (var, by_ref, ctx);
14009 : 86 : gimplify_expr (&x, &new_body, NULL, is_gimple_val,
14010 : : fb_rvalue);
14011 : 86 : gimple_seq_add_stmt (&new_body,
14012 : 86 : gimple_build_assign (new_var, x));
14013 : : }
14014 : : }
14015 : 102 : else if (is_variable_sized (var))
14016 : : {
14017 : 4 : tree pvar = DECL_VALUE_EXPR (var);
14018 : 4 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
14019 : 4 : pvar = TREE_OPERAND (pvar, 0);
14020 : 4 : gcc_assert (DECL_P (pvar));
14021 : 4 : tree new_var = lookup_decl (pvar, ctx);
14022 : 4 : x = build_receiver_ref (var, false, ctx);
14023 : 4 : gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue);
14024 : 4 : gimple_seq_add_stmt (&new_body,
14025 : 4 : gimple_build_assign (new_var, x));
14026 : : }
14027 : : break;
14028 : 173 : case OMP_CLAUSE_PRIVATE:
14029 : 173 : if (is_gimple_omp_oacc (ctx->stmt))
14030 : : break;
14031 : 93 : var = OMP_CLAUSE_DECL (c);
14032 : 93 : if (omp_privatize_by_reference (var))
14033 : : {
14034 : 5 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
14035 : 5 : tree new_var = lookup_decl (var, ctx);
14036 : 5 : x = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var)));
14037 : 5 : if (TREE_CONSTANT (x))
14038 : : {
14039 : 3 : x = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var)),
14040 : : get_name (var));
14041 : 3 : gimple_add_tmp_var (x);
14042 : 3 : TREE_ADDRESSABLE (x) = 1;
14043 : 3 : x = build_fold_addr_expr_loc (clause_loc, x);
14044 : : }
14045 : : else
14046 : : break;
14047 : :
14048 : 3 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
14049 : 3 : gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue);
14050 : 3 : gimple_seq_add_stmt (&new_body,
14051 : 3 : gimple_build_assign (new_var, x));
14052 : : }
14053 : : break;
14054 : 2414 : case OMP_CLAUSE_USE_DEVICE_PTR:
14055 : 2414 : case OMP_CLAUSE_USE_DEVICE_ADDR:
14056 : 2414 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
14057 : 2414 : case OMP_CLAUSE_IS_DEVICE_PTR:
14058 : 2414 : tree new_var;
14059 : 2414 : gimple_seq assign_body;
14060 : 2414 : bool is_array_data;
14061 : 2414 : bool do_optional_check;
14062 : 2414 : assign_body = NULL;
14063 : 2414 : do_optional_check = false;
14064 : 2414 : var = OMP_CLAUSE_DECL (c);
14065 : 2414 : is_array_data = lang_hooks.decls.omp_array_data (var, true) != NULL;
14066 : 2414 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR && is_array_data)
14067 : 13 : goto omp_firstprivatize_data_region;
14068 : :
14069 : 2401 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IS_DEVICE_PTR
14070 : 2401 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR)
14071 : 4108 : x = build_sender_ref (is_array_data
14072 : 601 : ? (splay_tree_key) &DECL_NAME (var)
14073 : 1453 : : (splay_tree_key) &DECL_UID (var), ctx);
14074 : : else
14075 : : {
14076 : 347 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
14077 : : {
14078 : 225 : while (TREE_CODE (var) == INDIRECT_REF
14079 : 225 : || TREE_CODE (var) == ARRAY_REF)
14080 : 17 : var = TREE_OPERAND (var, 0);
14081 : : }
14082 : 347 : x = build_receiver_ref (var, false, ctx);
14083 : : }
14084 : :
14085 : 2401 : if (is_array_data)
14086 : : {
14087 : 601 : bool is_ref = omp_privatize_by_reference (var);
14088 : 601 : do_optional_check = true;
14089 : : /* First, we copy the descriptor data from the host; then
14090 : : we update its data to point to the target address. */
14091 : 601 : new_var = lookup_decl (var, ctx);
14092 : 601 : new_var = DECL_VALUE_EXPR (new_var);
14093 : 601 : tree v = new_var;
14094 : 601 : tree v2 = var;
14095 : 601 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
14096 : 601 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR)
14097 : 601 : v2 = maybe_lookup_decl_in_outer_ctx (var, ctx);
14098 : :
14099 : 601 : if (is_ref)
14100 : : {
14101 : 396 : v2 = build_fold_indirect_ref (v2);
14102 : 396 : v = create_tmp_var_raw (TREE_TYPE (v2), get_name (var));
14103 : 396 : gimple_add_tmp_var (v);
14104 : 396 : TREE_ADDRESSABLE (v) = 1;
14105 : 396 : gimplify_assign (v, v2, &assign_body);
14106 : 396 : tree rhs = build_fold_addr_expr (v);
14107 : 396 : gimple_seq_add_stmt (&assign_body,
14108 : 396 : gimple_build_assign (new_var, rhs));
14109 : : }
14110 : : else
14111 : 205 : gimplify_assign (new_var, v2, &assign_body);
14112 : :
14113 : 601 : v2 = lang_hooks.decls.omp_array_data (unshare_expr (v), false);
14114 : 601 : gcc_assert (v2);
14115 : 601 : gimplify_expr (&x, &assign_body, NULL, is_gimple_val, fb_rvalue);
14116 : 1202 : gimple_seq_add_stmt (&assign_body,
14117 : 601 : gimple_build_assign (v2, x));
14118 : : }
14119 : 1800 : else if (is_variable_sized (var))
14120 : : {
14121 : 12 : tree pvar = DECL_VALUE_EXPR (var);
14122 : 12 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
14123 : 12 : pvar = TREE_OPERAND (pvar, 0);
14124 : 12 : gcc_assert (DECL_P (pvar));
14125 : 12 : new_var = lookup_decl (pvar, ctx);
14126 : 12 : gimplify_expr (&x, &assign_body, NULL, is_gimple_val, fb_rvalue);
14127 : 24 : gimple_seq_add_stmt (&assign_body,
14128 : 12 : gimple_build_assign (new_var, x));
14129 : : }
14130 : 1788 : else if (((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR
14131 : 526 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
14132 : 1468 : && !omp_privatize_by_reference (var)
14133 : 496 : && !omp_is_allocatable_or_ptr (var))
14134 : 3219 : || TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
14135 : : {
14136 : 381 : new_var = lookup_decl (var, ctx);
14137 : 381 : new_var = DECL_VALUE_EXPR (new_var);
14138 : 381 : gcc_assert (TREE_CODE (new_var) == MEM_REF);
14139 : 381 : new_var = TREE_OPERAND (new_var, 0);
14140 : 381 : gcc_assert (DECL_P (new_var));
14141 : 381 : gimplify_expr (&x, &assign_body, NULL, is_gimple_val, fb_rvalue);
14142 : 762 : gimple_seq_add_stmt (&assign_body,
14143 : 381 : gimple_build_assign (new_var, x));
14144 : : }
14145 : : else
14146 : : {
14147 : 1407 : tree type = TREE_TYPE (var);
14148 : 1407 : new_var = lookup_decl (var, ctx);
14149 : 1407 : if (omp_privatize_by_reference (var))
14150 : : {
14151 : 1039 : type = TREE_TYPE (type);
14152 : 1039 : if (POINTER_TYPE_P (type)
14153 : 1039 : && TREE_CODE (type) != ARRAY_TYPE
14154 : 1398 : && ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_USE_DEVICE_ADDR
14155 : 36 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR)
14156 : 331 : || (omp_privatize_by_reference (var)
14157 : 331 : && omp_is_allocatable_or_ptr (var))))
14158 : : {
14159 : 357 : tree v = create_tmp_var_raw (type, get_name (var));
14160 : 357 : gimple_add_tmp_var (v);
14161 : 357 : TREE_ADDRESSABLE (v) = 1;
14162 : 357 : x = fold_convert (type, x);
14163 : 357 : gimplify_expr (&x, &assign_body, NULL, is_gimple_val,
14164 : : fb_rvalue);
14165 : 357 : gimple_seq_add_stmt (&assign_body,
14166 : 357 : gimple_build_assign (v, x));
14167 : 357 : x = build_fold_addr_expr (v);
14168 : 357 : do_optional_check = true;
14169 : : }
14170 : : }
14171 : 1407 : new_var = DECL_VALUE_EXPR (new_var);
14172 : 1407 : x = fold_convert (TREE_TYPE (new_var), x);
14173 : 1407 : gimplify_expr (&x, &assign_body, NULL, is_gimple_val, fb_rvalue);
14174 : 1407 : gimple_seq_add_stmt (&assign_body,
14175 : 1407 : gimple_build_assign (new_var, x));
14176 : : }
14177 : 2401 : tree present;
14178 : 994 : present = ((do_optional_check
14179 : 958 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR
14180 : 952 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IS_DEVICE_PTR)
14181 : 2340 : ? omp_check_optional_argument (OMP_CLAUSE_DECL (c), true)
14182 : : : NULL_TREE);
14183 : 2401 : if (present)
14184 : : {
14185 : 480 : tree null_label = create_artificial_label (UNKNOWN_LOCATION);
14186 : 480 : tree notnull_label = create_artificial_label (UNKNOWN_LOCATION);
14187 : 480 : tree opt_arg_label = create_artificial_label (UNKNOWN_LOCATION);
14188 : 480 : glabel *null_glabel = gimple_build_label (null_label);
14189 : 480 : glabel *notnull_glabel = gimple_build_label (notnull_label);
14190 : 480 : ggoto *opt_arg_ggoto = gimple_build_goto (opt_arg_label);
14191 : 480 : gimplify_expr (&x, &new_body, NULL, is_gimple_val,
14192 : : fb_rvalue);
14193 : 480 : gimplify_expr (&present, &new_body, NULL, is_gimple_val,
14194 : : fb_rvalue);
14195 : 480 : gcond *cond = gimple_build_cond_from_tree (present,
14196 : : notnull_label,
14197 : : null_label);
14198 : 480 : gimple_seq_add_stmt (&new_body, cond);
14199 : 480 : gimple_seq_add_stmt (&new_body, null_glabel);
14200 : 480 : gimplify_assign (new_var, null_pointer_node, &new_body);
14201 : 480 : gimple_seq_add_stmt (&new_body, opt_arg_ggoto);
14202 : 480 : gimple_seq_add_stmt (&new_body, notnull_glabel);
14203 : 480 : gimple_seq_add_seq (&new_body, assign_body);
14204 : 480 : gimple_seq_add_stmt (&new_body,
14205 : 480 : gimple_build_label (opt_arg_label));
14206 : : }
14207 : : else
14208 : 1921 : gimple_seq_add_seq (&new_body, assign_body);
14209 : : break;
14210 : : }
14211 : : /* Handle GOMP_MAP_FIRSTPRIVATE_{POINTER,REFERENCE} in second pass,
14212 : : so that firstprivate vars holding OMP_CLAUSE_SIZE if needed
14213 : : are already handled. Similarly OMP_CLAUSE_PRIVATE for VLAs
14214 : : or references to VLAs. */
14215 : 137254 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
14216 : 112688 : switch (OMP_CLAUSE_CODE (c))
14217 : : {
14218 : : tree var;
14219 : : default:
14220 : : break;
14221 : 62344 : case OMP_CLAUSE_MAP:
14222 : 62344 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
14223 : 62344 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
14224 : : {
14225 : 3598 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
14226 : 3598 : poly_int64 offset = 0;
14227 : 3598 : gcc_assert (prev);
14228 : 3598 : var = OMP_CLAUSE_DECL (c);
14229 : 3598 : if (DECL_P (var)
14230 : 3598 : && TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE
14231 : 1089 : && is_global_var (maybe_lookup_decl_in_outer_ctx (var,
14232 : : ctx))
14233 : 3696 : && varpool_node::get_create (var)->offloadable)
14234 : : break;
14235 : 3596 : if (TREE_CODE (var) == INDIRECT_REF
14236 : 3596 : && TREE_CODE (TREE_OPERAND (var, 0)) == COMPONENT_REF)
14237 : 0 : var = TREE_OPERAND (var, 0);
14238 : 3596 : if (TREE_CODE (var) == COMPONENT_REF)
14239 : : {
14240 : 0 : var = get_addr_base_and_unit_offset (var, &offset);
14241 : 0 : gcc_assert (var != NULL_TREE && DECL_P (var));
14242 : : }
14243 : 3596 : else if (DECL_SIZE (var)
14244 : 3596 : && TREE_CODE (DECL_SIZE (var)) != INTEGER_CST)
14245 : : {
14246 : 710 : tree var2 = DECL_VALUE_EXPR (var);
14247 : 710 : gcc_assert (TREE_CODE (var2) == INDIRECT_REF);
14248 : 710 : var2 = TREE_OPERAND (var2, 0);
14249 : 710 : gcc_assert (DECL_P (var2));
14250 : : var = var2;
14251 : : }
14252 : 3596 : tree new_var = lookup_decl (var, ctx), x;
14253 : 3596 : tree type = TREE_TYPE (new_var);
14254 : 3596 : bool is_ref;
14255 : 3596 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == INDIRECT_REF
14256 : 3596 : && (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c), 0))
14257 : : == COMPONENT_REF))
14258 : : {
14259 : 0 : type = TREE_TYPE (TREE_OPERAND (OMP_CLAUSE_DECL (c), 0));
14260 : 0 : is_ref = true;
14261 : 0 : new_var = build2 (MEM_REF, type,
14262 : : build_fold_addr_expr (new_var),
14263 : : build_int_cst (build_pointer_type (type),
14264 : : offset));
14265 : : }
14266 : 3596 : else if (TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
14267 : : {
14268 : 0 : type = TREE_TYPE (OMP_CLAUSE_DECL (c));
14269 : 0 : is_ref = TREE_CODE (type) == REFERENCE_TYPE;
14270 : 0 : new_var = build2 (MEM_REF, type,
14271 : : build_fold_addr_expr (new_var),
14272 : : build_int_cst (build_pointer_type (type),
14273 : : offset));
14274 : : }
14275 : : else
14276 : 3596 : is_ref = omp_privatize_by_reference (var);
14277 : 3596 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
14278 : : is_ref = false;
14279 : 6591 : bool ref_to_array = false;
14280 : 6591 : bool ref_to_ptr = false;
14281 : 3171 : if (is_ref)
14282 : : {
14283 : 176 : type = TREE_TYPE (type);
14284 : 176 : if (TREE_CODE (type) == ARRAY_TYPE)
14285 : : {
14286 : 170 : type = build_pointer_type (type);
14287 : 170 : ref_to_array = true;
14288 : : }
14289 : : }
14290 : 3420 : else if (TREE_CODE (type) == ARRAY_TYPE)
14291 : : {
14292 : 377 : tree decl2 = DECL_VALUE_EXPR (new_var);
14293 : 377 : gcc_assert (TREE_CODE (decl2) == MEM_REF);
14294 : 377 : decl2 = TREE_OPERAND (decl2, 0);
14295 : 377 : gcc_assert (DECL_P (decl2));
14296 : 377 : new_var = decl2;
14297 : 377 : type = TREE_TYPE (new_var);
14298 : : }
14299 : 3043 : else if (TREE_CODE (type) == REFERENCE_TYPE
14300 : 3043 : && TREE_CODE (TREE_TYPE (type)) == POINTER_TYPE)
14301 : : {
14302 : 156 : type = TREE_TYPE (type);
14303 : 156 : ref_to_ptr = true;
14304 : : }
14305 : 3596 : x = build_receiver_ref (OMP_CLAUSE_DECL (prev), false, ctx);
14306 : 3596 : x = fold_convert_loc (clause_loc, type, x);
14307 : 3596 : if (!integer_zerop (OMP_CLAUSE_SIZE (c)))
14308 : : {
14309 : 702 : tree bias = OMP_CLAUSE_SIZE (c);
14310 : 702 : if (DECL_P (bias))
14311 : 304 : bias = lookup_decl (bias, ctx);
14312 : 702 : bias = fold_convert_loc (clause_loc, sizetype, bias);
14313 : 702 : bias = fold_build1_loc (clause_loc, NEGATE_EXPR, sizetype,
14314 : : bias);
14315 : 702 : x = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR,
14316 : 702 : TREE_TYPE (x), x, bias);
14317 : : }
14318 : 3596 : if (ref_to_array)
14319 : 170 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
14320 : 3596 : gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue);
14321 : 3596 : if ((is_ref && !ref_to_array)
14322 : 3590 : || ref_to_ptr)
14323 : : {
14324 : 162 : tree t = create_tmp_var_raw (type, get_name (var));
14325 : 162 : gimple_add_tmp_var (t);
14326 : 162 : TREE_ADDRESSABLE (t) = 1;
14327 : 162 : gimple_seq_add_stmt (&new_body,
14328 : 162 : gimple_build_assign (t, x));
14329 : 162 : x = build_fold_addr_expr_loc (clause_loc, t);
14330 : : }
14331 : 3596 : gimple_seq_add_stmt (&new_body,
14332 : 3596 : gimple_build_assign (new_var, x));
14333 : 3596 : prev = NULL_TREE;
14334 : : }
14335 : 58746 : else if (OMP_CLAUSE_CHAIN (c)
14336 : 42551 : && OMP_CLAUSE_CODE (OMP_CLAUSE_CHAIN (c))
14337 : : == OMP_CLAUSE_MAP
14338 : 95936 : && (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c))
14339 : : == GOMP_MAP_FIRSTPRIVATE_POINTER
14340 : 34017 : || (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c))
14341 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE)))
14342 : : prev = c;
14343 : : break;
14344 : 173 : case OMP_CLAUSE_PRIVATE:
14345 : 173 : var = OMP_CLAUSE_DECL (c);
14346 : 173 : if (is_variable_sized (var))
14347 : : {
14348 : 1 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
14349 : 1 : tree new_var = lookup_decl (var, ctx);
14350 : 1 : tree pvar = DECL_VALUE_EXPR (var);
14351 : 1 : gcc_assert (TREE_CODE (pvar) == INDIRECT_REF);
14352 : 1 : pvar = TREE_OPERAND (pvar, 0);
14353 : 1 : gcc_assert (DECL_P (pvar));
14354 : 1 : tree new_pvar = lookup_decl (pvar, ctx);
14355 : 1 : tree atmp = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
14356 : 1 : tree al = size_int (DECL_ALIGN (var));
14357 : 1 : tree x = TYPE_SIZE_UNIT (TREE_TYPE (new_var));
14358 : 1 : x = build_call_expr_loc (clause_loc, atmp, 2, x, al);
14359 : 1 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_pvar), x);
14360 : 1 : gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue);
14361 : 1 : gimple_seq_add_stmt (&new_body,
14362 : 1 : gimple_build_assign (new_pvar, x));
14363 : : }
14364 : 172 : else if (omp_privatize_by_reference (var)
14365 : 172 : && !is_gimple_omp_oacc (ctx->stmt))
14366 : : {
14367 : 5 : location_t clause_loc = OMP_CLAUSE_LOCATION (c);
14368 : 5 : tree new_var = lookup_decl (var, ctx);
14369 : 5 : tree x = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var)));
14370 : 5 : if (TREE_CONSTANT (x))
14371 : : break;
14372 : : else
14373 : : {
14374 : 2 : tree atmp
14375 : 2 : = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
14376 : 2 : tree rtype = TREE_TYPE (TREE_TYPE (new_var));
14377 : 2 : tree al = size_int (TYPE_ALIGN (rtype));
14378 : 2 : x = build_call_expr_loc (clause_loc, atmp, 2, x, al);
14379 : : }
14380 : :
14381 : 2 : x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x);
14382 : 2 : gimplify_expr (&x, &new_body, NULL, is_gimple_val, fb_rvalue);
14383 : 2 : gimple_seq_add_stmt (&new_body,
14384 : 2 : gimple_build_assign (new_var, x));
14385 : : }
14386 : : break;
14387 : : }
14388 : :
14389 : 24566 : gimple_seq fork_seq = NULL;
14390 : 24566 : gimple_seq join_seq = NULL;
14391 : :
14392 : 24566 : if (offloaded && is_gimple_omp_oacc (ctx->stmt))
14393 : : {
14394 : : /* If there are reductions on the offloaded region itself, treat
14395 : : them as a dummy GANG loop. */
14396 : 9391 : tree level = build_int_cst (integer_type_node, GOMP_DIM_GANG);
14397 : :
14398 : 9391 : gcall *private_marker = lower_oacc_private_marker (ctx);
14399 : :
14400 : 9391 : if (private_marker)
14401 : 30 : gimple_call_set_arg (private_marker, 2, level);
14402 : :
14403 : 9391 : lower_oacc_reductions (gimple_location (ctx->stmt), clauses, level,
14404 : : false, NULL, private_marker, NULL, &fork_seq,
14405 : : &join_seq, ctx);
14406 : : }
14407 : :
14408 : 24566 : gimple_seq_add_seq (&new_body, fork_seq);
14409 : 24566 : gimple_seq_add_seq (&new_body, tgt_body);
14410 : 24566 : gimple_seq_add_seq (&new_body, join_seq);
14411 : :
14412 : 24566 : if (offloaded)
14413 : : {
14414 : 20555 : new_body = maybe_catch_exception (new_body);
14415 : 20555 : gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
14416 : : }
14417 : 24566 : gimple_omp_set_body (stmt, new_body);
14418 : : }
14419 : :
14420 : 36189 : gsi_insert_seq_before (gsi_p, gimple_omp_target_iterator_loops (stmt),
14421 : : GSI_SAME_STMT);
14422 : 36189 : gimple_omp_target_set_iterator_loops (stmt, NULL);
14423 : 56744 : bind = gimple_build_bind (NULL, NULL,
14424 : 20555 : tgt_bind ? gimple_bind_block (tgt_bind)
14425 : : : NULL_TREE);
14426 : 71986 : gsi_replace (gsi_p, dep_bind ? dep_bind : bind, true);
14427 : 36189 : gimple_bind_add_seq (bind, ilist);
14428 : 36189 : gimple_bind_add_stmt (bind, stmt);
14429 : 36189 : gimple_bind_add_seq (bind, olist);
14430 : :
14431 : 36189 : pop_gimplify_context (NULL);
14432 : :
14433 : 36189 : if (dep_bind)
14434 : : {
14435 : 392 : gimple_bind_add_seq (dep_bind, dep_ilist);
14436 : 392 : gimple_bind_add_stmt (dep_bind, bind);
14437 : 392 : gimple_bind_add_seq (dep_bind, dep_olist);
14438 : 392 : pop_gimplify_context (dep_bind);
14439 : : }
14440 : 36189 : }
14441 : :
14442 : : /* Generate code to implement the action-clauses (destroy, init, use) of an
14443 : : OpenMP interop construct. */
14444 : :
14445 : : static void
14446 : 492 : lower_omp_interop_action_clauses (gimple_seq *seq, vec<tree> &objs,
14447 : : vec<tree> *interop_types = NULL,
14448 : : vec<tree> *prefer_types = NULL)
14449 : : {
14450 : 492 : if (objs.length () == 0)
14451 : 229 : return;
14452 : :
14453 : 263 : enum omp_clause_code action = OMP_CLAUSE_CODE (objs[0]);
14454 : 263 : if (action == OMP_CLAUSE_INIT)
14455 : 402 : gcc_checking_assert (objs.length () == interop_types->length ()
14456 : : && objs.length () == prefer_types->length ());
14457 : : else
14458 : 129 : gcc_assert (prefer_types == NULL && interop_types == NULL);
14459 : :
14460 : 263 : tree ret_objs = NULL_TREE, ret_interop_types = NULL_TREE,
14461 : 263 : ret_prefer_types = NULL_TREE;
14462 : :
14463 : : /* Build an array of interop objects. */
14464 : :
14465 : 263 : tree type_obj_pref = build_array_type_nelts (ptr_type_node, objs.length ());
14466 : 263 : ret_objs = create_tmp_var (type_obj_pref, "interopobjs");
14467 : :
14468 : 263 : bool have_pref_type = false;
14469 : 263 : if (action == OMP_CLAUSE_INIT)
14470 : : {
14471 : 592 : for (tree pref_type : prefer_types)
14472 : 260 : if (pref_type != NULL_TREE)
14473 : : {
14474 : : have_pref_type = true;
14475 : : break;
14476 : : }
14477 : 134 : tree type_tgtsync
14478 : 134 : = build_array_type_nelts (integer_type_node, objs.length ());
14479 : 134 : ret_interop_types = create_tmp_var (type_tgtsync, "tgt_tgtsync");
14480 : 134 : if (have_pref_type)
14481 : 70 : ret_prefer_types = create_tmp_var (type_obj_pref, "pref_type");
14482 : : else
14483 : : {
14484 : 64 : ret_prefer_types = null_pointer_node;
14485 : 64 : prefer_types->truncate (0);
14486 : : }
14487 : : }
14488 : :
14489 : 856 : for (size_t i = 0; !objs.is_empty (); i++)
14490 : : {
14491 : 593 : tree offset = build_int_cst (integer_type_node, i);
14492 : 593 : tree init = build4 (ARRAY_REF, ptr_type_node, ret_objs, offset, NULL_TREE,
14493 : : NULL_TREE);
14494 : 593 : tree obj = OMP_CLAUSE_DECL (objs.pop ());
14495 : 593 : if (TREE_CODE (TREE_TYPE (obj)) == REFERENCE_TYPE)
14496 : 6 : obj = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (obj)), obj);
14497 : 593 : if (action != OMP_CLAUSE_USE
14498 : 593 : && TREE_CODE (TREE_TYPE (obj)) != POINTER_TYPE)
14499 : : /* For modifying actions, we need a pointer. */
14500 : 483 : obj = build_fold_addr_expr (obj);
14501 : 110 : else if (action == OMP_CLAUSE_USE
14502 : 110 : && TREE_CODE (TREE_TYPE (obj)) == POINTER_TYPE)
14503 : : /* For use action, we need the value. */
14504 : 2 : obj = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (obj)), obj);
14505 : 593 : init = build2 (MODIFY_EXPR, ptr_type_node, init,
14506 : : fold_convert (ptr_type_node, obj));
14507 : 593 : gimplify_and_add (init, seq);
14508 : :
14509 : 593 : if (action == OMP_CLAUSE_INIT)
14510 : : {
14511 : 384 : init = build4 (ARRAY_REF, integer_type_node, ret_interop_types,
14512 : : offset, NULL_TREE, NULL_TREE);
14513 : 384 : init = build2 (MODIFY_EXPR, integer_type_node, init,
14514 : 384 : interop_types->pop ());
14515 : 384 : gimplify_and_add (init, seq);
14516 : :
14517 : 384 : if (have_pref_type)
14518 : : {
14519 : 194 : tree prefer_type = prefer_types->pop ();
14520 : 194 : tree pref = (prefer_type == NULL_TREE
14521 : 194 : ? null_pointer_node
14522 : 194 : : build_fold_addr_expr (prefer_type));
14523 : 194 : init = build4 (ARRAY_REF, ptr_type_node, ret_prefer_types, offset,
14524 : : NULL_TREE, NULL_TREE);
14525 : 194 : init = build2 (MODIFY_EXPR, ptr_type_node, init, pref);
14526 : 194 : gimplify_and_add (init, seq);
14527 : : }
14528 : : }
14529 : : }
14530 : 263 : if (action == OMP_CLAUSE_INIT)
14531 : : {
14532 : 134 : if (have_pref_type)
14533 : 70 : ret_prefer_types = build_fold_addr_expr (ret_prefer_types);
14534 : 134 : ret_interop_types = build_fold_addr_expr (ret_interop_types);
14535 : : }
14536 : 263 : ret_objs = build_fold_addr_expr (ret_objs);
14537 : :
14538 : 660 : gcc_assert (objs.is_empty ()
14539 : : && (!interop_types || interop_types->is_empty ())
14540 : : && (!prefer_types || prefer_types->is_empty ()));
14541 : :
14542 : 263 : objs.safe_push (ret_objs);
14543 : 263 : if (action == OMP_CLAUSE_INIT)
14544 : : {
14545 : 134 : interop_types->safe_push (ret_interop_types);
14546 : 134 : prefer_types->safe_push (ret_prefer_types);
14547 : : }
14548 : : }
14549 : :
14550 : : /* Lower code for an OpenMP interop directive. */
14551 : :
14552 : : static void
14553 : 164 : lower_omp_interop (gimple_stmt_iterator *gsi_p, omp_context *ctx)
14554 : : {
14555 : 164 : push_gimplify_context ();
14556 : :
14557 : 164 : tree block = make_node (BLOCK);
14558 : 164 : gbind *bind = gimple_build_bind (NULL, NULL, block);
14559 : 164 : gimple_seq bind_body = NULL;
14560 : :
14561 : : /* Emit call to GOMP_interop:
14562 : : void
14563 : : GOMP_interop (int device_num, int n_init, omp_interop_t **init,
14564 : : const void *target_targetsync, const void *prefer_type,
14565 : : int n_use, omp_interop_t *use, int n_destroy,
14566 : : omp_interop_t **destroy, unsigned int flags,
14567 : : void **depend) */
14568 : :
14569 : 164 : tree flags = NULL_TREE;
14570 : 164 : tree depend = null_pointer_node;
14571 : 164 : tree device_num = NULL_TREE;
14572 : :
14573 : 164 : auto_vec<tree> init_objs, use_objs, destroy_objs, prefer_type,
14574 : 164 : target_targetsync;
14575 : 164 : gimple_seq dep_ilist = NULL, dep_olist = NULL;
14576 : 164 : tree clauses = gimple_omp_interop_clauses (gsi_stmt (*gsi_p));
14577 : 868 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
14578 : : {
14579 : 704 : switch (OMP_CLAUSE_CODE (c))
14580 : : {
14581 : 384 : case OMP_CLAUSE_INIT:
14582 : 384 : {
14583 : 384 : init_objs.safe_push (c);
14584 : 384 : int target_targetsync_bits = 0;
14585 : 384 : if (OMP_CLAUSE_INIT_TARGET (c))
14586 : 229 : target_targetsync_bits |= GOMP_INTEROP_TARGET;
14587 : 384 : if (OMP_CLAUSE_INIT_TARGETSYNC (c))
14588 : 204 : target_targetsync_bits |= GOMP_INTEROP_TARGETSYNC;
14589 : 384 : tree t = build_int_cst (integer_type_node, target_targetsync_bits);
14590 : 384 : target_targetsync.safe_push (t);
14591 : 384 : prefer_type.safe_push (OMP_CLAUSE_INIT_PREFER_TYPE (c));
14592 : : }
14593 : 384 : break;
14594 : 106 : case OMP_CLAUSE_USE:
14595 : 106 : use_objs.safe_push (c);
14596 : 106 : break;
14597 : 103 : case OMP_CLAUSE_DESTROY:
14598 : 103 : destroy_objs.safe_push (c);
14599 : 103 : break;
14600 : 50 : case OMP_CLAUSE_NOWAIT:
14601 : 50 : flags = build_int_cst (integer_type_node, GOMP_INTEROP_FLAG_NOWAIT);
14602 : 50 : break;
14603 : 35 : case OMP_CLAUSE_DEPEND:
14604 : 35 : {
14605 : 35 : tree *cp = gimple_omp_interop_clauses_ptr (gsi_stmt (*gsi_p));
14606 : 35 : lower_depend_clauses (cp, &dep_ilist, &dep_olist);
14607 : 35 : depend = OMP_CLAUSE_DECL (*cp);
14608 : : }
14609 : 35 : break;
14610 : 26 : case OMP_CLAUSE_DEVICE:
14611 : 26 : device_num = OMP_CLAUSE_DEVICE_ID (c);
14612 : 26 : break;
14613 : 0 : default:
14614 : 0 : gcc_unreachable ();
14615 : : }
14616 : : }
14617 : :
14618 : 164 : if (flags == NULL_TREE)
14619 : 114 : flags = build_int_cst (integer_type_node, 0);
14620 : :
14621 : 164 : if (device_num == NULL_TREE)
14622 : 138 : device_num = build_int_cst (integer_type_node, GOMP_DEVICE_DEFAULT_OMP_61);
14623 : :
14624 : 298 : tree n_init = build_int_cst (integer_type_node, init_objs.length ());
14625 : 234 : tree n_use = build_int_cst (integer_type_node, use_objs.length ());
14626 : 223 : tree n_destroy = build_int_cst (integer_type_node, destroy_objs.length ());
14627 : :
14628 : 164 : lower_omp_interop_action_clauses (&bind_body, init_objs, &target_targetsync,
14629 : : &prefer_type);
14630 : 164 : lower_omp_interop_action_clauses (&bind_body, use_objs);
14631 : 164 : lower_omp_interop_action_clauses (&bind_body, destroy_objs);
14632 : :
14633 : 164 : gimple_seq_add_seq (&bind_body, dep_ilist);
14634 : 164 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_INTEROP);
14635 : 298 : tree init_arg = init_objs.length () ? init_objs.pop () : null_pointer_node;
14636 : 164 : tree target_targetsync_arg = target_targetsync.length ()
14637 : 134 : ? target_targetsync.pop ()
14638 : 164 : : null_pointer_node;
14639 : 164 : tree prefer_type_arg
14640 : 298 : = prefer_type.length () ? prefer_type.pop () : null_pointer_node;
14641 : 234 : tree use_arg = use_objs.length () ? use_objs.pop () : null_pointer_node;
14642 : 164 : tree destroy_arg
14643 : 223 : = destroy_objs.length () ? destroy_objs.pop () : null_pointer_node;
14644 : 164 : gcall *call
14645 : 164 : = gimple_build_call (fn, 11, device_num, n_init, init_arg,
14646 : : target_targetsync_arg, prefer_type_arg, n_use, use_arg,
14647 : : n_destroy, destroy_arg, flags, depend);
14648 : 164 : gimple_seq_add_stmt (&bind_body, call);
14649 : 164 : gimple_seq_add_seq (&bind_body, dep_olist);
14650 : :
14651 : 164 : gsi_replace (gsi_p, bind, true);
14652 : 164 : gimple_bind_set_body (bind, bind_body);
14653 : 164 : pop_gimplify_context (bind);
14654 : 164 : gimple_bind_append_vars (bind, ctx->block_vars);
14655 : 164 : BLOCK_VARS (block) = ctx->block_vars;
14656 : 164 : }
14657 : :
14658 : : /* Expand code for an OpenMP teams directive. */
14659 : :
14660 : : static void
14661 : 5917 : lower_omp_teams (gimple_stmt_iterator *gsi_p, omp_context *ctx)
14662 : : {
14663 : 5917 : gomp_teams *teams_stmt = as_a <gomp_teams *> (gsi_stmt (*gsi_p));
14664 : 5917 : push_gimplify_context ();
14665 : :
14666 : 5917 : tree block = make_node (BLOCK);
14667 : 5917 : gbind *bind = gimple_build_bind (NULL, NULL, block);
14668 : 5917 : gsi_replace (gsi_p, bind, true);
14669 : 5917 : gimple_seq bind_body = NULL;
14670 : 5917 : gimple_seq dlist = NULL;
14671 : 5917 : gimple_seq olist = NULL;
14672 : :
14673 : 5917 : tree num_teams = omp_find_clause (gimple_omp_teams_clauses (teams_stmt),
14674 : 5917 : OMP_CLAUSE_NUM_TEAMS);
14675 : 5917 : tree num_teams_lower = NULL_TREE;
14676 : 5917 : if (num_teams == NULL_TREE)
14677 : 5300 : num_teams = build_int_cst (unsigned_type_node, 0);
14678 : : else
14679 : : {
14680 : 617 : num_teams_lower = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (num_teams);
14681 : 617 : if (num_teams_lower)
14682 : : {
14683 : 148 : num_teams_lower = fold_convert (unsigned_type_node, num_teams_lower);
14684 : 148 : gimplify_expr (&num_teams_lower, &bind_body, NULL, is_gimple_val,
14685 : : fb_rvalue);
14686 : : }
14687 : 617 : num_teams = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (num_teams);
14688 : 617 : num_teams = fold_convert (unsigned_type_node, num_teams);
14689 : 617 : gimplify_expr (&num_teams, &bind_body, NULL, is_gimple_val, fb_rvalue);
14690 : : }
14691 : 5917 : if (num_teams_lower == NULL_TREE)
14692 : 5769 : num_teams_lower = num_teams;
14693 : 5917 : tree thread_limit = omp_find_clause (gimple_omp_teams_clauses (teams_stmt),
14694 : 5917 : OMP_CLAUSE_THREAD_LIMIT);
14695 : 5917 : if (thread_limit == NULL_TREE)
14696 : 5446 : thread_limit = build_int_cst (unsigned_type_node, 0);
14697 : : else
14698 : : {
14699 : 471 : thread_limit = OMP_CLAUSE_THREAD_LIMIT_EXPR (thread_limit);
14700 : 471 : thread_limit = fold_convert (unsigned_type_node, thread_limit);
14701 : 471 : gimplify_expr (&thread_limit, &bind_body, NULL, is_gimple_val,
14702 : : fb_rvalue);
14703 : : }
14704 : 5917 : location_t loc = gimple_location (teams_stmt);
14705 : 5917 : tree decl = builtin_decl_explicit (BUILT_IN_GOMP_TEAMS4);
14706 : 5917 : tree rettype = TREE_TYPE (TREE_TYPE (decl));
14707 : 5917 : tree first = create_tmp_var (rettype);
14708 : 5917 : gimple_seq_add_stmt (&bind_body,
14709 : 5917 : gimple_build_assign (first, build_one_cst (rettype)));
14710 : 5917 : tree llabel = create_artificial_label (loc);
14711 : 5917 : gimple_seq_add_stmt (&bind_body, gimple_build_label (llabel));
14712 : 5917 : gimple *call
14713 : 5917 : = gimple_build_call (decl, 4, num_teams_lower, num_teams, thread_limit,
14714 : : first);
14715 : 5917 : gimple_set_location (call, loc);
14716 : 5917 : tree temp = create_tmp_var (rettype);
14717 : 5917 : gimple_call_set_lhs (call, temp);
14718 : 5917 : gimple_seq_add_stmt (&bind_body, call);
14719 : :
14720 : 5917 : tree tlabel = create_artificial_label (loc);
14721 : 5917 : tree flabel = create_artificial_label (loc);
14722 : 5917 : gimple *cond = gimple_build_cond (NE_EXPR, temp, build_zero_cst (rettype),
14723 : : tlabel, flabel);
14724 : 5917 : gimple_seq_add_stmt (&bind_body, cond);
14725 : 5917 : gimple_seq_add_stmt (&bind_body, gimple_build_label (tlabel));
14726 : 5917 : gimple_seq_add_stmt (&bind_body,
14727 : 5917 : gimple_build_assign (first, build_zero_cst (rettype)));
14728 : :
14729 : 5917 : lower_rec_input_clauses (gimple_omp_teams_clauses (teams_stmt),
14730 : : &bind_body, &dlist, ctx, NULL);
14731 : 5917 : lower_omp (gimple_omp_body_ptr (teams_stmt), ctx);
14732 : 5917 : lower_reduction_clauses (gimple_omp_teams_clauses (teams_stmt), &olist,
14733 : : NULL, ctx);
14734 : 5917 : gimple_seq_add_stmt (&bind_body, teams_stmt);
14735 : :
14736 : 5917 : gimple_seq_add_seq (&bind_body, gimple_omp_body (teams_stmt));
14737 : 5917 : gimple_omp_set_body (teams_stmt, NULL);
14738 : 5917 : gimple_seq_add_seq (&bind_body, olist);
14739 : 5917 : gimple_seq_add_seq (&bind_body, dlist);
14740 : 5917 : gimple_seq_add_stmt (&bind_body, gimple_build_omp_return (true));
14741 : 5917 : gimple_seq_add_stmt (&bind_body, gimple_build_goto (llabel));
14742 : 5917 : gimple_seq_add_stmt (&bind_body, gimple_build_label (flabel));
14743 : 5917 : gimple_bind_set_body (bind, bind_body);
14744 : :
14745 : 5917 : pop_gimplify_context (bind);
14746 : :
14747 : 5917 : gimple_bind_append_vars (bind, ctx->block_vars);
14748 : 5917 : BLOCK_VARS (block) = ctx->block_vars;
14749 : 5917 : if (BLOCK_VARS (block))
14750 : 687 : TREE_USED (block) = 1;
14751 : 5917 : }
14752 : :
14753 : : /* Callback for lower_omp_1. Return non-NULL if *tp needs to be
14754 : : regimplified. If DATA is non-NULL, lower_omp_1 is outside
14755 : : of OMP context, but with make_addressable_vars set. */
14756 : :
14757 : : static tree
14758 : 3138294 : lower_omp_regimplify_p (tree *tp, int *walk_subtrees,
14759 : : void *data)
14760 : : {
14761 : 3138294 : tree t = *tp;
14762 : :
14763 : : /* Any variable with DECL_VALUE_EXPR needs to be regimplified. */
14764 : 3138294 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
14765 : 1459704 : && data == NULL
14766 : 1399297 : && DECL_HAS_VALUE_EXPR_P (t))
14767 : : return t;
14768 : :
14769 : 3037677 : if (make_addressable_vars
14770 : 422493 : && DECL_P (t)
14771 : 3242704 : && bitmap_bit_p (make_addressable_vars, DECL_UID (t)))
14772 : : return t;
14773 : :
14774 : : /* If a global variable has been privatized, TREE_CONSTANT on
14775 : : ADDR_EXPR might be wrong. */
14776 : 3035088 : if (data == NULL && TREE_CODE (t) == ADDR_EXPR)
14777 : 108386 : recompute_tree_invariant_for_addr_expr (t);
14778 : :
14779 : 3035088 : *walk_subtrees = !IS_TYPE_OR_DECL_P (t);
14780 : 3035088 : return NULL_TREE;
14781 : : }
14782 : :
14783 : : /* Data to be communicated between lower_omp_regimplify_operands and
14784 : : lower_omp_regimplify_operands_p. */
14785 : :
14786 : : struct lower_omp_regimplify_operands_data
14787 : : {
14788 : : omp_context *ctx;
14789 : : vec<tree> *decls;
14790 : : };
14791 : :
14792 : : /* Helper function for lower_omp_regimplify_operands. Find
14793 : : omp_member_access_dummy_var vars and adjust temporarily their
14794 : : DECL_VALUE_EXPRs if needed. */
14795 : :
14796 : : static tree
14797 : 395630 : lower_omp_regimplify_operands_p (tree *tp, int *walk_subtrees,
14798 : : void *data)
14799 : : {
14800 : 395630 : tree t = omp_member_access_dummy_var (*tp);
14801 : 395630 : if (t)
14802 : : {
14803 : 9 : struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
14804 : 9 : lower_omp_regimplify_operands_data *ldata
14805 : : = (lower_omp_regimplify_operands_data *) wi->info;
14806 : 9 : tree o = maybe_lookup_decl (t, ldata->ctx);
14807 : 9 : if (o == NULL_TREE)
14808 : 5 : o = maybe_lookup_decl_in_outer_ctx (t, ldata->ctx);
14809 : 9 : if (o != t)
14810 : : {
14811 : 9 : ldata->decls->safe_push (DECL_VALUE_EXPR (*tp));
14812 : 9 : ldata->decls->safe_push (*tp);
14813 : 9 : tree v = unshare_and_remap (DECL_VALUE_EXPR (*tp), t, o);
14814 : 9 : SET_DECL_VALUE_EXPR (*tp, v);
14815 : : }
14816 : : }
14817 : 395630 : *walk_subtrees = !IS_TYPE_OR_DECL_P (*tp);
14818 : 395630 : return NULL_TREE;
14819 : : }
14820 : :
14821 : : /* Wrapper around gimple_regimplify_operands that adjusts DECL_VALUE_EXPRs
14822 : : of omp_member_access_dummy_var vars during regimplification. */
14823 : :
14824 : : static void
14825 : 103051 : lower_omp_regimplify_operands (omp_context *ctx, gimple *stmt,
14826 : : gimple_stmt_iterator *gsi_p)
14827 : : {
14828 : 103051 : auto_vec<tree, 10> decls;
14829 : 103051 : if (ctx)
14830 : : {
14831 : 100529 : struct walk_stmt_info wi;
14832 : 100529 : memset (&wi, '\0', sizeof (wi));
14833 : 100529 : struct lower_omp_regimplify_operands_data data;
14834 : 100529 : data.ctx = ctx;
14835 : 100529 : data.decls = &decls;
14836 : 100529 : wi.info = &data;
14837 : 100529 : walk_gimple_op (stmt, lower_omp_regimplify_operands_p, &wi);
14838 : : }
14839 : 103051 : gimple_regimplify_operands (stmt, gsi_p);
14840 : 309162 : while (!decls.is_empty ())
14841 : : {
14842 : 9 : tree t = decls.pop ();
14843 : 9 : tree v = decls.pop ();
14844 : 9 : SET_DECL_VALUE_EXPR (t, v);
14845 : : }
14846 : 103051 : }
14847 : :
14848 : : static void
14849 : 2404067 : lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
14850 : : {
14851 : 2404067 : gimple *stmt = gsi_stmt (*gsi_p);
14852 : 2404067 : struct walk_stmt_info wi;
14853 : 2404067 : gcall *call_stmt;
14854 : :
14855 : 2404067 : if (gimple_has_location (stmt))
14856 : 1967514 : input_location = gimple_location (stmt);
14857 : :
14858 : 2404067 : if (make_addressable_vars)
14859 : 154028 : memset (&wi, '\0', sizeof (wi));
14860 : :
14861 : : /* If we have issued syntax errors, avoid doing any heavy lifting.
14862 : : Just replace the OMP directives with a NOP to avoid
14863 : : confusing RTL expansion. */
14864 : 2404067 : if (seen_error () && is_gimple_omp (stmt))
14865 : : {
14866 : 11394 : gsi_replace (gsi_p, gimple_build_nop (), true);
14867 : 11394 : return;
14868 : : }
14869 : :
14870 : 2392673 : switch (gimple_code (stmt))
14871 : : {
14872 : 151647 : case GIMPLE_COND:
14873 : 151647 : {
14874 : 151647 : gcond *cond_stmt = as_a <gcond *> (stmt);
14875 : 85472 : if ((ctx || make_addressable_vars)
14876 : 155255 : && (walk_tree (gimple_cond_lhs_ptr (cond_stmt),
14877 : : lower_omp_regimplify_p,
14878 : : ctx ? NULL : &wi, NULL)
14879 : 134015 : || walk_tree (gimple_cond_rhs_ptr (cond_stmt),
14880 : : lower_omp_regimplify_p,
14881 : : ctx ? NULL : &wi, NULL)))
14882 : 1245 : lower_omp_regimplify_operands (ctx, cond_stmt, gsi_p);
14883 : : }
14884 : : break;
14885 : 20 : case GIMPLE_CATCH:
14886 : 20 : lower_omp (gimple_catch_handler_ptr (as_a <gcatch *> (stmt)), ctx);
14887 : 20 : break;
14888 : 0 : case GIMPLE_EH_FILTER:
14889 : 0 : lower_omp (gimple_eh_filter_failure_ptr (stmt), ctx);
14890 : 0 : break;
14891 : 25220 : case GIMPLE_TRY:
14892 : 25220 : lower_omp (gimple_try_eval_ptr (stmt), ctx);
14893 : 25215 : lower_omp (gimple_try_cleanup_ptr (stmt), ctx);
14894 : 25215 : break;
14895 : 0 : case GIMPLE_ASSUME:
14896 : 0 : lower_omp (gimple_assume_body_ptr (stmt), ctx);
14897 : 0 : break;
14898 : 5 : case GIMPLE_TRANSACTION:
14899 : 5 : lower_omp (gimple_transaction_body_ptr (as_a <gtransaction *> (stmt)),
14900 : : ctx);
14901 : 5 : break;
14902 : 163064 : case GIMPLE_BIND:
14903 : 163064 : if (ctx && is_gimple_omp_oacc (ctx->stmt))
14904 : : {
14905 : 17733 : tree vars = gimple_bind_vars (as_a <gbind *> (stmt));
14906 : 17733 : oacc_privatization_scan_decl_chain (ctx, vars);
14907 : : }
14908 : 163064 : lower_omp (gimple_bind_body_ptr (as_a <gbind *> (stmt)), ctx);
14909 : 163057 : maybe_remove_omp_member_access_dummy_vars (as_a <gbind *> (stmt));
14910 : 163057 : break;
14911 : 19936 : case GIMPLE_OMP_PARALLEL:
14912 : 19936 : case GIMPLE_OMP_TASK:
14913 : 19936 : ctx = maybe_lookup_ctx (stmt);
14914 : 19936 : gcc_assert (ctx);
14915 : 19936 : if (ctx->cancellable)
14916 : 135 : ctx->cancel_label = create_artificial_label (UNKNOWN_LOCATION);
14917 : 19936 : lower_omp_taskreg (gsi_p, ctx);
14918 : 19936 : break;
14919 : 46865 : case GIMPLE_OMP_FOR:
14920 : 46865 : ctx = maybe_lookup_ctx (stmt);
14921 : 46865 : gcc_assert (ctx);
14922 : 46865 : if (ctx->cancellable)
14923 : 84 : ctx->cancel_label = create_artificial_label (UNKNOWN_LOCATION);
14924 : 46865 : lower_omp_for (gsi_p, ctx);
14925 : 46865 : break;
14926 : 378 : case GIMPLE_OMP_SECTIONS:
14927 : 378 : ctx = maybe_lookup_ctx (stmt);
14928 : 378 : gcc_assert (ctx);
14929 : 378 : if (ctx->cancellable)
14930 : 19 : ctx->cancel_label = create_artificial_label (UNKNOWN_LOCATION);
14931 : 378 : lower_omp_sections (gsi_p, ctx);
14932 : 378 : break;
14933 : 133 : case GIMPLE_OMP_SCOPE:
14934 : 133 : ctx = maybe_lookup_ctx (stmt);
14935 : 133 : gcc_assert (ctx);
14936 : 133 : lower_omp_scope (gsi_p, ctx);
14937 : 133 : break;
14938 : 659 : case GIMPLE_OMP_DISPATCH:
14939 : 659 : ctx = maybe_lookup_ctx (stmt);
14940 : 659 : gcc_assert (ctx);
14941 : 659 : lower_omp_dispatch (gsi_p, ctx);
14942 : 659 : break;
14943 : 164 : case GIMPLE_OMP_INTEROP:
14944 : 164 : ctx = maybe_lookup_ctx (stmt);
14945 : 164 : gcc_assert (ctx);
14946 : 164 : lower_omp_interop (gsi_p, ctx);
14947 : 164 : break;
14948 : 1119 : case GIMPLE_OMP_SINGLE:
14949 : 1119 : ctx = maybe_lookup_ctx (stmt);
14950 : 1119 : gcc_assert (ctx);
14951 : 1119 : lower_omp_single (gsi_p, ctx);
14952 : 1119 : break;
14953 : 658 : case GIMPLE_OMP_STRUCTURED_BLOCK:
14954 : : /* We have already done error checking at this point, so these nodes
14955 : : can be completely removed and replaced with their body. */
14956 : 658 : ctx = maybe_lookup_ctx (stmt);
14957 : 658 : gcc_assert (ctx);
14958 : 658 : lower_omp (gimple_omp_body_ptr (stmt), ctx);
14959 : 658 : gsi_replace_with_seq (gsi_p, gimple_omp_body (stmt), true);
14960 : 658 : break;
14961 : 1108 : case GIMPLE_OMP_MASTER:
14962 : 1108 : case GIMPLE_OMP_MASKED:
14963 : 1108 : ctx = maybe_lookup_ctx (stmt);
14964 : 1108 : gcc_assert (ctx);
14965 : 1108 : lower_omp_master (gsi_p, ctx);
14966 : 1108 : break;
14967 : 536 : case GIMPLE_OMP_TASKGROUP:
14968 : 536 : ctx = maybe_lookup_ctx (stmt);
14969 : 536 : gcc_assert (ctx);
14970 : 536 : lower_omp_taskgroup (gsi_p, ctx);
14971 : 536 : break;
14972 : 1124 : case GIMPLE_OMP_ORDERED:
14973 : 1124 : ctx = maybe_lookup_ctx (stmt);
14974 : 1124 : gcc_assert (ctx);
14975 : 1124 : lower_omp_ordered (gsi_p, ctx);
14976 : 1124 : break;
14977 : 1268 : case GIMPLE_OMP_SCAN:
14978 : 1268 : ctx = maybe_lookup_ctx (stmt);
14979 : 1268 : gcc_assert (ctx);
14980 : 1268 : lower_omp_scan (gsi_p, ctx);
14981 : 1268 : break;
14982 : 311 : case GIMPLE_OMP_CRITICAL:
14983 : 311 : ctx = maybe_lookup_ctx (stmt);
14984 : 311 : gcc_assert (ctx);
14985 : 311 : lower_omp_critical (gsi_p, ctx);
14986 : 311 : break;
14987 : 2516 : case GIMPLE_OMP_ATOMIC_LOAD:
14988 : 85 : if ((ctx || make_addressable_vars)
14989 : 2516 : && walk_tree (gimple_omp_atomic_load_rhs_ptr (
14990 : : as_a <gomp_atomic_load *> (stmt)),
14991 : : lower_omp_regimplify_p, ctx ? NULL : &wi, NULL))
14992 : 1425 : lower_omp_regimplify_operands (ctx, stmt, gsi_p);
14993 : : break;
14994 : 36189 : case GIMPLE_OMP_TARGET:
14995 : 36189 : ctx = maybe_lookup_ctx (stmt);
14996 : 36189 : gcc_assert (ctx);
14997 : 36189 : lower_omp_target (gsi_p, ctx);
14998 : 36189 : break;
14999 : 8410 : case GIMPLE_OMP_TEAMS:
15000 : 8410 : ctx = maybe_lookup_ctx (stmt);
15001 : 8410 : gcc_assert (ctx);
15002 : 8410 : if (gimple_omp_teams_host (as_a <gomp_teams *> (stmt)))
15003 : 2493 : lower_omp_taskreg (gsi_p, ctx);
15004 : : else
15005 : 5917 : lower_omp_teams (gsi_p, ctx);
15006 : : break;
15007 : 131576 : case GIMPLE_CALL:
15008 : 131576 : tree fndecl;
15009 : 131576 : call_stmt = as_a <gcall *> (stmt);
15010 : 131576 : fndecl = gimple_call_fndecl (call_stmt);
15011 : 131576 : if (fndecl
15012 : 131576 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15013 : 37285 : switch (DECL_FUNCTION_CODE (fndecl))
15014 : : {
15015 : 725 : case BUILT_IN_GOMP_BARRIER:
15016 : 725 : if (ctx == NULL)
15017 : : break;
15018 : : /* FALLTHRU */
15019 : 1035 : case BUILT_IN_GOMP_CANCEL:
15020 : 1035 : case BUILT_IN_GOMP_CANCELLATION_POINT:
15021 : 1035 : omp_context *cctx;
15022 : 1035 : cctx = ctx;
15023 : 1035 : if (gimple_code (cctx->stmt) == GIMPLE_OMP_SECTION)
15024 : 43 : cctx = cctx->outer;
15025 : 1035 : gcc_assert (gimple_call_lhs (call_stmt) == NULL_TREE);
15026 : 1035 : if (!cctx->cancellable)
15027 : : {
15028 : 677 : if (DECL_FUNCTION_CODE (fndecl)
15029 : : == BUILT_IN_GOMP_CANCELLATION_POINT)
15030 : : {
15031 : 0 : stmt = gimple_build_nop ();
15032 : 0 : gsi_replace (gsi_p, stmt, false);
15033 : : }
15034 : : break;
15035 : : }
15036 : 358 : if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_GOMP_BARRIER)
15037 : : {
15038 : 14 : fndecl = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER_CANCEL);
15039 : 14 : gimple_call_set_fndecl (call_stmt, fndecl);
15040 : 14 : gimple_call_set_fntype (call_stmt, TREE_TYPE (fndecl));
15041 : : }
15042 : 358 : tree lhs;
15043 : 358 : lhs = create_tmp_var (TREE_TYPE (TREE_TYPE (fndecl)));
15044 : 358 : gimple_call_set_lhs (call_stmt, lhs);
15045 : 358 : tree fallthru_label;
15046 : 358 : fallthru_label = create_artificial_label (UNKNOWN_LOCATION);
15047 : 358 : gimple *g;
15048 : 358 : g = gimple_build_label (fallthru_label);
15049 : 358 : gsi_insert_after (gsi_p, g, GSI_SAME_STMT);
15050 : 358 : g = gimple_build_cond (NE_EXPR, lhs,
15051 : 358 : fold_convert (TREE_TYPE (lhs),
15052 : : boolean_false_node),
15053 : : cctx->cancel_label, fallthru_label);
15054 : 358 : gsi_insert_after (gsi_p, g, GSI_SAME_STMT);
15055 : 358 : break;
15056 : : default:
15057 : : break;
15058 : : }
15059 : 131541 : goto regimplify;
15060 : :
15061 : : case GIMPLE_ASSIGN:
15062 : 1380602 : for (omp_context *up = ctx; up; up = up->outer)
15063 : : {
15064 : 667738 : if (gimple_code (up->stmt) == GIMPLE_OMP_ORDERED
15065 : : || gimple_code (up->stmt) == GIMPLE_OMP_CRITICAL
15066 : : || gimple_code (up->stmt) == GIMPLE_OMP_TASKGROUP
15067 : : || gimple_code (up->stmt) == GIMPLE_OMP_SCOPE
15068 : : || gimple_code (up->stmt) == GIMPLE_OMP_SECTION
15069 : : || gimple_code (up->stmt) == GIMPLE_OMP_SCAN
15070 : : || (gimple_code (up->stmt) == GIMPLE_OMP_TARGET
15071 : 214165 : && (gimple_omp_target_kind (up->stmt)
15072 : : == GF_OMP_TARGET_KIND_DATA)))
15073 : 90149 : continue;
15074 : 577589 : else if (!up->lastprivate_conditional_map)
15075 : : break;
15076 : 4204 : tree lhs = get_base_address (gimple_assign_lhs (stmt));
15077 : 4204 : if (TREE_CODE (lhs) == MEM_REF
15078 : 26 : && DECL_P (TREE_OPERAND (lhs, 0))
15079 : 4227 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs,
15080 : : 0))) == REFERENCE_TYPE)
15081 : 19 : lhs = TREE_OPERAND (lhs, 0);
15082 : 4204 : if (DECL_P (lhs))
15083 : 3161 : if (tree *v = up->lastprivate_conditional_map->get (lhs))
15084 : : {
15085 : 382 : tree clauses;
15086 : 382 : if (up->combined_into_simd_safelen1)
15087 : : {
15088 : 54 : up = up->outer;
15089 : 54 : if (gimple_code (up->stmt) == GIMPLE_OMP_SCAN)
15090 : 3 : up = up->outer;
15091 : : }
15092 : 382 : if (gimple_code (up->stmt) == GIMPLE_OMP_FOR)
15093 : 298 : clauses = gimple_omp_for_clauses (up->stmt);
15094 : : else
15095 : 84 : clauses = gimple_omp_sections_clauses (up->stmt);
15096 : 382 : tree c = omp_find_clause (clauses, OMP_CLAUSE__CONDTEMP_);
15097 : 382 : if (!OMP_CLAUSE__CONDTEMP__ITER (c))
15098 : 348 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c),
15099 : : OMP_CLAUSE__CONDTEMP_);
15100 : 382 : gcc_assert (OMP_CLAUSE__CONDTEMP__ITER (c));
15101 : 382 : gimple *g = gimple_build_assign (*v, OMP_CLAUSE_DECL (c));
15102 : 382 : gsi_insert_after (gsi_p, g, GSI_SAME_STMT);
15103 : : }
15104 : : }
15105 : : /* FALLTHRU */
15106 : :
15107 : 1931343 : default:
15108 : 1931343 : regimplify:
15109 : 996343 : if ((ctx || make_addressable_vars)
15110 : 2007115 : && walk_gimple_op (stmt, lower_omp_regimplify_p,
15111 : : ctx ? NULL : &wi))
15112 : : {
15113 : : /* Just remove clobbers, this should happen only if we have
15114 : : "privatized" local addressable variables in SIMD regions,
15115 : : the clobber isn't needed in that case and gimplifying address
15116 : : of the ARRAY_REF into a pointer and creating MEM_REF based
15117 : : clobber would create worse code than we get with the clobber
15118 : : dropped. */
15119 : 100536 : if (gimple_clobber_p (stmt))
15120 : : {
15121 : 155 : gsi_replace (gsi_p, gimple_build_nop (), true);
15122 : 155 : break;
15123 : : }
15124 : 100381 : lower_omp_regimplify_operands (ctx, stmt, gsi_p);
15125 : : }
15126 : : break;
15127 : : }
15128 : : }
15129 : :
15130 : : static void
15131 : 402967 : lower_omp (gimple_seq *body, omp_context *ctx)
15132 : : {
15133 : 402967 : location_t saved_location = input_location;
15134 : 402967 : gimple_stmt_iterator gsi;
15135 : 3161874 : for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi))
15136 : 2404067 : lower_omp_1 (&gsi, ctx);
15137 : : /* During gimplification, we haven't folded statments inside offloading
15138 : : or taskreg regions (gimplify.cc:maybe_fold_stmt); do that now. */
15139 : 402951 : if (target_nesting_level || taskreg_nesting_level)
15140 : 625667 : for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi))
15141 : 416490 : fold_stmt (&gsi);
15142 : 402951 : input_location = saved_location;
15143 : 402951 : }
15144 : :
15145 : : /* Main entry point. */
15146 : :
15147 : : static unsigned int
15148 : 2878309 : execute_lower_omp (void)
15149 : : {
15150 : 2878309 : gimple_seq body;
15151 : 2878309 : int i;
15152 : 2878309 : omp_context *ctx;
15153 : :
15154 : : /* This pass always runs, to provide PROP_gimple_lomp.
15155 : : But often, there is nothing to do. */
15156 : 2878309 : if (flag_openacc == 0 && flag_openmp == 0
15157 : 2825061 : && flag_openmp_simd == 0)
15158 : : return 0;
15159 : :
15160 : 55503 : all_contexts = splay_tree_new (splay_tree_compare_pointers, 0,
15161 : : delete_omp_context);
15162 : :
15163 : 55503 : body = gimple_body (current_function_decl);
15164 : :
15165 : 55503 : scan_omp (&body, NULL);
15166 : 55503 : gcc_assert (taskreg_nesting_level == 0);
15167 : 81469 : FOR_EACH_VEC_ELT (taskreg_contexts, i, ctx)
15168 : 25966 : finish_taskreg_scan (ctx);
15169 : 55503 : taskreg_contexts.release ();
15170 : :
15171 : 55503 : if (all_contexts->root)
15172 : : {
15173 : 25275 : if (make_addressable_vars)
15174 : 620 : push_gimplify_context ();
15175 : 25275 : lower_omp (&body, NULL);
15176 : 25271 : if (make_addressable_vars)
15177 : 620 : pop_gimplify_context (NULL);
15178 : : }
15179 : :
15180 : 55499 : if (all_contexts)
15181 : : {
15182 : 55499 : splay_tree_delete (all_contexts);
15183 : 55499 : all_contexts = NULL;
15184 : : }
15185 : 55499 : BITMAP_FREE (make_addressable_vars);
15186 : 55499 : BITMAP_FREE (global_nonaddressable_vars);
15187 : :
15188 : : /* If current function is a method, remove artificial dummy VAR_DECL created
15189 : : for non-static data member privatization, they aren't needed for
15190 : : debuginfo nor anything else, have been already replaced everywhere in the
15191 : : IL and cause problems with LTO. */
15192 : 55499 : if (DECL_ARGUMENTS (current_function_decl)
15193 : 31888 : && DECL_ARTIFICIAL (DECL_ARGUMENTS (current_function_decl))
15194 : 65088 : && (TREE_CODE (TREE_TYPE (DECL_ARGUMENTS (current_function_decl)))
15195 : : == POINTER_TYPE))
15196 : 9054 : remove_member_access_dummy_vars (DECL_INITIAL (current_function_decl));
15197 : :
15198 : 56475 : for (auto task_stmt : task_cpyfns)
15199 : 504 : finalize_task_copyfn (task_stmt);
15200 : 55499 : task_cpyfns.release ();
15201 : 55499 : return 0;
15202 : : }
15203 : :
15204 : : namespace {
15205 : :
15206 : : const pass_data pass_data_lower_omp =
15207 : : {
15208 : : GIMPLE_PASS, /* type */
15209 : : "omplower", /* name */
15210 : : OPTGROUP_OMP, /* optinfo_flags */
15211 : : TV_NONE, /* tv_id */
15212 : : PROP_gimple_any, /* properties_required */
15213 : : PROP_gimple_lomp | PROP_gimple_lomp_dev, /* properties_provided */
15214 : : 0, /* properties_destroyed */
15215 : : 0, /* todo_flags_start */
15216 : : 0, /* todo_flags_finish */
15217 : : };
15218 : :
15219 : : class pass_lower_omp : public gimple_opt_pass
15220 : : {
15221 : : public:
15222 : 285883 : pass_lower_omp (gcc::context *ctxt)
15223 : 571766 : : gimple_opt_pass (pass_data_lower_omp, ctxt)
15224 : : {}
15225 : :
15226 : : /* opt_pass methods: */
15227 : 2878309 : unsigned int execute (function *) final override
15228 : : {
15229 : 2878309 : return execute_lower_omp ();
15230 : : }
15231 : :
15232 : : }; // class pass_lower_omp
15233 : :
15234 : : } // anon namespace
15235 : :
15236 : : gimple_opt_pass *
15237 : 285883 : make_pass_lower_omp (gcc::context *ctxt)
15238 : : {
15239 : 285883 : return new pass_lower_omp (ctxt);
15240 : : }
15241 : :
15242 : : /* The following is a utility to diagnose structured block violations.
15243 : : It is not part of the "omplower" pass, as that's invoked too late. It
15244 : : should be invoked by the respective front ends after gimplification. */
15245 : :
15246 : : static splay_tree all_labels;
15247 : :
15248 : : /* Check for mismatched contexts and generate an error if needed. Return
15249 : : true if an error is detected. */
15250 : :
15251 : : static bool
15252 : 542374 : diagnose_sb_0 (gimple_stmt_iterator *gsi_p,
15253 : : gimple *branch_ctx, gimple *label_ctx)
15254 : : {
15255 : 542374 : gcc_checking_assert (!branch_ctx || is_gimple_omp (branch_ctx));
15256 : 542374 : gcc_checking_assert (!label_ctx || is_gimple_omp (label_ctx));
15257 : :
15258 : 542374 : if (label_ctx == branch_ctx)
15259 : : return false;
15260 : :
15261 : 174 : const char* kind = NULL;
15262 : :
15263 : 174 : if (flag_openacc)
15264 : : {
15265 : 7 : if ((branch_ctx && is_gimple_omp_oacc (branch_ctx))
15266 : 16 : || (label_ctx && is_gimple_omp_oacc (label_ctx)))
15267 : : {
15268 : : gcc_checking_assert (kind == NULL);
15269 : : kind = "OpenACC";
15270 : : }
15271 : : }
15272 : : if (kind == NULL)
15273 : : {
15274 : 158 : gcc_checking_assert (flag_openmp || flag_openmp_simd);
15275 : : kind = "OpenMP";
15276 : : }
15277 : :
15278 : : /* Previously we kept track of the label's entire context in diagnose_sb_[12]
15279 : : so we could traverse it and issue a correct "exit" or "enter" error
15280 : : message upon a structured block violation.
15281 : :
15282 : : We built the context by building a list with tree_cons'ing, but there is
15283 : : no easy counterpart in gimple tuples. It seems like far too much work
15284 : : for issuing exit/enter error messages. If someone really misses the
15285 : : distinct error message... patches welcome. */
15286 : :
15287 : : #if 0
15288 : : /* Try to avoid confusing the user by producing and error message
15289 : : with correct "exit" or "enter" verbiage. We prefer "exit"
15290 : : unless we can show that LABEL_CTX is nested within BRANCH_CTX. */
15291 : : if (branch_ctx == NULL)
15292 : : exit_p = false;
15293 : : else
15294 : : {
15295 : : while (label_ctx)
15296 : : {
15297 : : if (TREE_VALUE (label_ctx) == branch_ctx)
15298 : : {
15299 : : exit_p = false;
15300 : : break;
15301 : : }
15302 : : label_ctx = TREE_CHAIN (label_ctx);
15303 : : }
15304 : : }
15305 : :
15306 : : if (exit_p)
15307 : : error ("invalid exit from %s structured block", kind);
15308 : : else
15309 : : error ("invalid entry to %s structured block", kind);
15310 : : #endif
15311 : :
15312 : : /* If it's obvious we have an invalid entry, be specific about the error. */
15313 : 174 : if (branch_ctx == NULL)
15314 : 53 : error ("invalid entry to %s structured block", kind);
15315 : : else
15316 : : {
15317 : : /* Otherwise, be vague and lazy, but efficient. */
15318 : 121 : error ("invalid branch to/from %s structured block", kind);
15319 : : }
15320 : :
15321 : 174 : gsi_replace (gsi_p, gimple_build_nop (), false);
15322 : 174 : return true;
15323 : : }
15324 : :
15325 : : /* Pass 1: Create a minimal tree of structured blocks, and record
15326 : : where each label is found. */
15327 : :
15328 : : static tree
15329 : 3190255 : diagnose_sb_1 (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
15330 : : struct walk_stmt_info *wi)
15331 : : {
15332 : 3190255 : gimple *context = (gimple *) wi->info;
15333 : 3190255 : gimple *inner_context;
15334 : 3190255 : gimple *stmt = gsi_stmt (*gsi_p);
15335 : :
15336 : 3190255 : *handled_ops_p = true;
15337 : :
15338 : 3190255 : switch (gimple_code (stmt))
15339 : : {
15340 : 309779 : WALK_SUBSTMTS;
15341 : :
15342 : 82624 : case GIMPLE_OMP_PARALLEL:
15343 : 82624 : case GIMPLE_OMP_TASK:
15344 : 82624 : case GIMPLE_OMP_SCOPE:
15345 : 82624 : case GIMPLE_OMP_SECTIONS:
15346 : 82624 : case GIMPLE_OMP_SINGLE:
15347 : 82624 : case GIMPLE_OMP_SECTION:
15348 : 82624 : case GIMPLE_OMP_STRUCTURED_BLOCK:
15349 : 82624 : case GIMPLE_OMP_MASTER:
15350 : 82624 : case GIMPLE_OMP_MASKED:
15351 : 82624 : case GIMPLE_OMP_ORDERED:
15352 : 82624 : case GIMPLE_OMP_SCAN:
15353 : 82624 : case GIMPLE_OMP_CRITICAL:
15354 : 82624 : case GIMPLE_OMP_TARGET:
15355 : 82624 : case GIMPLE_OMP_TEAMS:
15356 : 82624 : case GIMPLE_OMP_TASKGROUP:
15357 : : /* The minimal context here is just the current OMP construct. */
15358 : 82624 : inner_context = stmt;
15359 : 82624 : wi->info = inner_context;
15360 : 82624 : walk_gimple_seq (gimple_omp_body (stmt), diagnose_sb_1, NULL, wi);
15361 : 82624 : wi->info = context;
15362 : 82624 : break;
15363 : :
15364 : 52723 : case GIMPLE_OMP_FOR:
15365 : 52723 : inner_context = stmt;
15366 : 52723 : wi->info = inner_context;
15367 : : /* gimple_omp_for_{index,initial,final} are all DECLs; no need to
15368 : : walk them. */
15369 : 52723 : walk_gimple_seq (gimple_omp_for_pre_body (stmt),
15370 : : diagnose_sb_1, NULL, wi);
15371 : 52723 : walk_gimple_seq (gimple_omp_body (stmt), diagnose_sb_1, NULL, wi);
15372 : 52723 : wi->info = context;
15373 : 52723 : break;
15374 : :
15375 : 538639 : case GIMPLE_LABEL:
15376 : 1077278 : splay_tree_insert (all_labels,
15377 : 538639 : (splay_tree_key) gimple_label_label (
15378 : 538639 : as_a <glabel *> (stmt)),
15379 : : (splay_tree_value) context);
15380 : 538639 : break;
15381 : :
15382 : : default:
15383 : : break;
15384 : : }
15385 : :
15386 : 3190255 : return NULL_TREE;
15387 : : }
15388 : :
15389 : : /* Pass 2: Check each branch and see if its context differs from that of
15390 : : the destination label's context. */
15391 : :
15392 : : static tree
15393 : 3190255 : diagnose_sb_2 (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
15394 : : struct walk_stmt_info *wi)
15395 : : {
15396 : 3190255 : gimple *context = (gimple *) wi->info;
15397 : 3190255 : splay_tree_node n;
15398 : 3190255 : gimple *stmt = gsi_stmt (*gsi_p);
15399 : :
15400 : 3190255 : *handled_ops_p = true;
15401 : :
15402 : 3190255 : switch (gimple_code (stmt))
15403 : : {
15404 : 309779 : WALK_SUBSTMTS;
15405 : :
15406 : 82624 : case GIMPLE_OMP_PARALLEL:
15407 : 82624 : case GIMPLE_OMP_TASK:
15408 : 82624 : case GIMPLE_OMP_SCOPE:
15409 : 82624 : case GIMPLE_OMP_SECTIONS:
15410 : 82624 : case GIMPLE_OMP_SINGLE:
15411 : 82624 : case GIMPLE_OMP_SECTION:
15412 : 82624 : case GIMPLE_OMP_STRUCTURED_BLOCK:
15413 : 82624 : case GIMPLE_OMP_MASTER:
15414 : 82624 : case GIMPLE_OMP_MASKED:
15415 : 82624 : case GIMPLE_OMP_ORDERED:
15416 : 82624 : case GIMPLE_OMP_SCAN:
15417 : 82624 : case GIMPLE_OMP_CRITICAL:
15418 : 82624 : case GIMPLE_OMP_TARGET:
15419 : 82624 : case GIMPLE_OMP_TEAMS:
15420 : 82624 : case GIMPLE_OMP_TASKGROUP:
15421 : 82624 : wi->info = stmt;
15422 : 82624 : walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), diagnose_sb_2, NULL, wi);
15423 : 82624 : wi->info = context;
15424 : 82624 : break;
15425 : :
15426 : 52723 : case GIMPLE_OMP_FOR:
15427 : 52723 : wi->info = stmt;
15428 : : /* gimple_omp_for_{index,initial,final} are all DECLs; no need to
15429 : : walk them. */
15430 : 52723 : walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt),
15431 : : diagnose_sb_2, NULL, wi);
15432 : 52723 : walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), diagnose_sb_2, NULL, wi);
15433 : 52723 : wi->info = context;
15434 : 52723 : break;
15435 : :
15436 : 199959 : case GIMPLE_COND:
15437 : 199959 : {
15438 : 199959 : gcond *cond_stmt = as_a <gcond *> (stmt);
15439 : 199959 : tree lab = gimple_cond_true_label (cond_stmt);
15440 : 199959 : if (lab)
15441 : : {
15442 : 199959 : n = splay_tree_lookup (all_labels,
15443 : : (splay_tree_key) lab);
15444 : 399918 : diagnose_sb_0 (gsi_p, context,
15445 : 199959 : n ? (gimple *) n->value : NULL);
15446 : : }
15447 : 199959 : lab = gimple_cond_false_label (cond_stmt);
15448 : 199959 : if (lab)
15449 : : {
15450 : 199959 : n = splay_tree_lookup (all_labels,
15451 : : (splay_tree_key) lab);
15452 : 399918 : diagnose_sb_0 (gsi_p, context,
15453 : 199959 : n ? (gimple *) n->value : NULL);
15454 : : }
15455 : : }
15456 : : break;
15457 : :
15458 : 107334 : case GIMPLE_GOTO:
15459 : 107334 : {
15460 : 107334 : tree lab = gimple_goto_dest (stmt);
15461 : 107334 : if (TREE_CODE (lab) != LABEL_DECL)
15462 : : break;
15463 : :
15464 : 107334 : n = splay_tree_lookup (all_labels, (splay_tree_key) lab);
15465 : 107334 : diagnose_sb_0 (gsi_p, context, n ? (gimple *) n->value : NULL);
15466 : : }
15467 : 107334 : break;
15468 : :
15469 : 424 : case GIMPLE_SWITCH:
15470 : 424 : {
15471 : 424 : gswitch *switch_stmt = as_a <gswitch *> (stmt);
15472 : 424 : unsigned int i;
15473 : 1724 : for (i = 0; i < gimple_switch_num_labels (switch_stmt); ++i)
15474 : : {
15475 : 1316 : tree lab = CASE_LABEL (gimple_switch_label (switch_stmt, i));
15476 : 1316 : n = splay_tree_lookup (all_labels, (splay_tree_key) lab);
15477 : 1316 : if (n && diagnose_sb_0 (gsi_p, context, (gimple *) n->value))
15478 : : break;
15479 : : }
15480 : : }
15481 : : break;
15482 : :
15483 : 33806 : case GIMPLE_RETURN:
15484 : 33806 : diagnose_sb_0 (gsi_p, context, NULL);
15485 : 33806 : break;
15486 : :
15487 : : default:
15488 : : break;
15489 : : }
15490 : :
15491 : 3190255 : return NULL_TREE;
15492 : : }
15493 : :
15494 : : static unsigned int
15495 : 55512 : diagnose_omp_structured_block_errors (void)
15496 : : {
15497 : 55512 : struct walk_stmt_info wi;
15498 : 55512 : gimple_seq body = gimple_body (current_function_decl);
15499 : :
15500 : 55512 : all_labels = splay_tree_new (splay_tree_compare_pointers, 0, 0);
15501 : :
15502 : 55512 : memset (&wi, 0, sizeof (wi));
15503 : 55512 : walk_gimple_seq (body, diagnose_sb_1, NULL, &wi);
15504 : :
15505 : 55512 : memset (&wi, 0, sizeof (wi));
15506 : 55512 : wi.want_locations = true;
15507 : 55512 : walk_gimple_seq_mod (&body, diagnose_sb_2, NULL, &wi);
15508 : :
15509 : 55512 : gimple_set_body (current_function_decl, body);
15510 : :
15511 : 55512 : splay_tree_delete (all_labels);
15512 : 55512 : all_labels = NULL;
15513 : :
15514 : 55512 : return 0;
15515 : : }
15516 : :
15517 : : namespace {
15518 : :
15519 : : const pass_data pass_data_diagnose_omp_blocks =
15520 : : {
15521 : : GIMPLE_PASS, /* type */
15522 : : "*diagnose_omp_blocks", /* name */
15523 : : OPTGROUP_OMP, /* optinfo_flags */
15524 : : TV_NONE, /* tv_id */
15525 : : PROP_gimple_any, /* properties_required */
15526 : : 0, /* properties_provided */
15527 : : 0, /* properties_destroyed */
15528 : : 0, /* todo_flags_start */
15529 : : 0, /* todo_flags_finish */
15530 : : };
15531 : :
15532 : : class pass_diagnose_omp_blocks : public gimple_opt_pass
15533 : : {
15534 : : public:
15535 : 285883 : pass_diagnose_omp_blocks (gcc::context *ctxt)
15536 : 571766 : : gimple_opt_pass (pass_data_diagnose_omp_blocks, ctxt)
15537 : : {}
15538 : :
15539 : : /* opt_pass methods: */
15540 : 2878323 : bool gate (function *) final override
15541 : : {
15542 : 2878323 : return flag_openacc || flag_openmp || flag_openmp_simd;
15543 : : }
15544 : 55512 : unsigned int execute (function *) final override
15545 : : {
15546 : 55512 : return diagnose_omp_structured_block_errors ();
15547 : : }
15548 : :
15549 : : }; // class pass_diagnose_omp_blocks
15550 : :
15551 : : } // anon namespace
15552 : :
15553 : : gimple_opt_pass *
15554 : 285883 : make_pass_diagnose_omp_blocks (gcc::context *ctxt)
15555 : : {
15556 : 285883 : return new pass_diagnose_omp_blocks (ctxt);
15557 : : }
15558 : :
15559 : :
15560 : : #include "gt-omp-low.h"
|