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.
5 Contributed by Diego Novillo <dnovillo@redhat.com>
7 Copyright (C) 2005-2017 Free Software Foundation, Inc.
9 This file is part of GCC.
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
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
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/>. */
27 #include "coretypes.h"
32 #include "tree-pass.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-fold.h"
42 #include "gimple-iterator.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"
50 #include "splay-tree.h"
51 #include "omp-general.h"
54 #include "gimple-low.h"
55 #include "symbol-summary.h"
56 #include "tree-nested.h"
58 #include "gomp-constants.h"
59 #include "gimple-pretty-print.h"
60 #include "hsa-common.h"
61 #include "stringpool.h"
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
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. */
75 /* Context structure. Used to store information about each parallel
76 directive in the code. */
80 /* This field must be at the beginning, as we do "inheritance": Some
81 callback functions for tree-inline.c (e.g., omp_copy_decl)
82 receive a copy_body_data pointer that is up-casted to an
83 omp_context pointer. */
86 /* The tree of contexts corresponding to the encountered constructs. */
87 struct omp_context
*outer
;
90 /* Map variables to fields in a structure that allows communication
91 between sending and receiving threads. */
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
;
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. */
109 /* Label to which GOMP_cancel{,llation_point} and explicit and implicit
110 barriers should jump to during omplower pass. */
113 /* The sibling GIMPLE_OMP_FOR simd with _simt_ clause or NULL
117 /* Nesting depth of this context. Used to beautify error messages re
118 invalid gotos. The outermost ctx is depth 1, with depth 0 being
119 reserved for the main body of the function. */
122 /* True if this parallel directive is nested within another. */
125 /* True if this construct can be cancelled. */
129 static splay_tree all_contexts
;
130 static int taskreg_nesting_level
;
131 static int target_nesting_level
;
132 static bitmap task_shared_vars
;
133 static vec
<omp_context
*> taskreg_contexts
;
135 static void scan_omp (gimple_seq
*, omp_context
*);
136 static tree
scan_omp_1_op (tree
*, int *, void *);
138 #define WALK_SUBSTMTS \
142 case GIMPLE_EH_FILTER: \
143 case GIMPLE_TRANSACTION: \
144 /* The sub-statements for these should be walked. */ \
145 *handled_ops_p = false; \
148 /* Return true if CTX corresponds to an oacc parallel region. */
151 is_oacc_parallel (omp_context
*ctx
)
153 enum gimple_code outer_type
= gimple_code (ctx
->stmt
);
154 return ((outer_type
== GIMPLE_OMP_TARGET
)
155 && (gimple_omp_target_kind (ctx
->stmt
)
156 == GF_OMP_TARGET_KIND_OACC_PARALLEL
));
159 /* Return true if CTX corresponds to an oacc kernels region. */
162 is_oacc_kernels (omp_context
*ctx
)
164 enum gimple_code outer_type
= gimple_code (ctx
->stmt
);
165 return ((outer_type
== GIMPLE_OMP_TARGET
)
166 && (gimple_omp_target_kind (ctx
->stmt
)
167 == GF_OMP_TARGET_KIND_OACC_KERNELS
));
170 /* If DECL is the artificial dummy VAR_DECL created for non-static
171 data member privatization, return the underlying "this" parameter,
172 otherwise return NULL. */
175 omp_member_access_dummy_var (tree decl
)
178 || !DECL_ARTIFICIAL (decl
)
179 || !DECL_IGNORED_P (decl
)
180 || !DECL_HAS_VALUE_EXPR_P (decl
)
181 || !lang_hooks
.decls
.omp_disregard_value_expr (decl
, false))
184 tree v
= DECL_VALUE_EXPR (decl
);
185 if (TREE_CODE (v
) != COMPONENT_REF
)
189 switch (TREE_CODE (v
))
195 case POINTER_PLUS_EXPR
:
196 v
= TREE_OPERAND (v
, 0);
199 if (DECL_CONTEXT (v
) == current_function_decl
200 && DECL_ARTIFICIAL (v
)
201 && TREE_CODE (TREE_TYPE (v
)) == POINTER_TYPE
)
209 /* Helper for unshare_and_remap, called through walk_tree. */
212 unshare_and_remap_1 (tree
*tp
, int *walk_subtrees
, void *data
)
214 tree
*pair
= (tree
*) data
;
217 *tp
= unshare_expr (pair
[1]);
220 else if (IS_TYPE_OR_DECL_P (*tp
))
225 /* Return unshare_expr (X) with all occurrences of FROM
229 unshare_and_remap (tree x
, tree from
, tree to
)
231 tree pair
[2] = { from
, to
};
232 x
= unshare_expr (x
);
233 walk_tree (&x
, unshare_and_remap_1
, pair
, NULL
);
237 /* Convenience function for calling scan_omp_1_op on tree operands. */
240 scan_omp_op (tree
*tp
, omp_context
*ctx
)
242 struct walk_stmt_info wi
;
244 memset (&wi
, 0, sizeof (wi
));
246 wi
.want_locations
= true;
248 return walk_tree (tp
, scan_omp_1_op
, &wi
, NULL
);
251 static void lower_omp (gimple_seq
*, omp_context
*);
252 static tree
lookup_decl_in_outer_ctx (tree
, omp_context
*);
253 static tree
maybe_lookup_decl_in_outer_ctx (tree
, omp_context
*);
255 /* Return true if CTX is for an omp parallel. */
258 is_parallel_ctx (omp_context
*ctx
)
260 return gimple_code (ctx
->stmt
) == GIMPLE_OMP_PARALLEL
;
264 /* Return true if CTX is for an omp task. */
267 is_task_ctx (omp_context
*ctx
)
269 return gimple_code (ctx
->stmt
) == GIMPLE_OMP_TASK
;
273 /* Return true if CTX is for an omp taskloop. */
276 is_taskloop_ctx (omp_context
*ctx
)
278 return gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
279 && gimple_omp_for_kind (ctx
->stmt
) == GF_OMP_FOR_KIND_TASKLOOP
;
283 /* Return true if CTX is for an omp parallel or omp task. */
286 is_taskreg_ctx (omp_context
*ctx
)
288 return is_parallel_ctx (ctx
) || is_task_ctx (ctx
);
291 /* Return true if EXPR is variable sized. */
294 is_variable_sized (const_tree expr
)
296 return !TREE_CONSTANT (TYPE_SIZE_UNIT (TREE_TYPE (expr
)));
299 /* Lookup variables. The "maybe" form
300 allows for the variable form to not have been entered, otherwise we
301 assert that the variable must have been entered. */
304 lookup_decl (tree var
, omp_context
*ctx
)
306 tree
*n
= ctx
->cb
.decl_map
->get (var
);
311 maybe_lookup_decl (const_tree var
, omp_context
*ctx
)
313 tree
*n
= ctx
->cb
.decl_map
->get (const_cast<tree
> (var
));
314 return n
? *n
: NULL_TREE
;
318 lookup_field (tree var
, omp_context
*ctx
)
321 n
= splay_tree_lookup (ctx
->field_map
, (splay_tree_key
) var
);
322 return (tree
) n
->value
;
326 lookup_sfield (splay_tree_key key
, omp_context
*ctx
)
329 n
= splay_tree_lookup (ctx
->sfield_map
330 ? ctx
->sfield_map
: ctx
->field_map
, key
);
331 return (tree
) n
->value
;
335 lookup_sfield (tree var
, omp_context
*ctx
)
337 return lookup_sfield ((splay_tree_key
) var
, ctx
);
341 maybe_lookup_field (splay_tree_key key
, omp_context
*ctx
)
344 n
= splay_tree_lookup (ctx
->field_map
, key
);
345 return n
? (tree
) n
->value
: NULL_TREE
;
349 maybe_lookup_field (tree var
, omp_context
*ctx
)
351 return maybe_lookup_field ((splay_tree_key
) var
, ctx
);
354 /* Return true if DECL should be copied by pointer. SHARED_CTX is
355 the parallel context if DECL is to be shared. */
358 use_pointer_for_field (tree decl
, omp_context
*shared_ctx
)
360 if (AGGREGATE_TYPE_P (TREE_TYPE (decl
))
361 || TYPE_ATOMIC (TREE_TYPE (decl
)))
364 /* We can only use copy-in/copy-out semantics for shared variables
365 when we know the value is not accessible from an outer scope. */
368 gcc_assert (!is_gimple_omp_oacc (shared_ctx
->stmt
));
370 /* ??? Trivially accessible from anywhere. But why would we even
371 be passing an address in this case? Should we simply assert
372 this to be false, or should we have a cleanup pass that removes
373 these from the list of mappings? */
374 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
377 /* For variables with DECL_HAS_VALUE_EXPR_P set, we cannot tell
378 without analyzing the expression whether or not its location
379 is accessible to anyone else. In the case of nested parallel
380 regions it certainly may be. */
381 if (TREE_CODE (decl
) != RESULT_DECL
&& DECL_HAS_VALUE_EXPR_P (decl
))
384 /* Do not use copy-in/copy-out for variables that have their
386 if (TREE_ADDRESSABLE (decl
))
389 /* lower_send_shared_vars only uses copy-in, but not copy-out
391 if (TREE_READONLY (decl
)
392 || ((TREE_CODE (decl
) == RESULT_DECL
393 || TREE_CODE (decl
) == PARM_DECL
)
394 && DECL_BY_REFERENCE (decl
)))
397 /* Disallow copy-in/out in nested parallel if
398 decl is shared in outer parallel, otherwise
399 each thread could store the shared variable
400 in its own copy-in location, making the
401 variable no longer really shared. */
402 if (shared_ctx
->is_nested
)
406 for (up
= shared_ctx
->outer
; up
; up
= up
->outer
)
407 if (is_taskreg_ctx (up
) && maybe_lookup_decl (decl
, up
))
414 for (c
= gimple_omp_taskreg_clauses (up
->stmt
);
415 c
; c
= OMP_CLAUSE_CHAIN (c
))
416 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
417 && OMP_CLAUSE_DECL (c
) == decl
)
421 goto maybe_mark_addressable_and_ret
;
425 /* For tasks avoid using copy-in/out. As tasks can be
426 deferred or executed in different thread, when GOMP_task
427 returns, the task hasn't necessarily terminated. */
428 if (is_task_ctx (shared_ctx
))
431 maybe_mark_addressable_and_ret
:
432 outer
= maybe_lookup_decl_in_outer_ctx (decl
, shared_ctx
);
433 if (is_gimple_reg (outer
) && !omp_member_access_dummy_var (outer
))
435 /* Taking address of OUTER in lower_send_shared_vars
436 might need regimplification of everything that uses the
438 if (!task_shared_vars
)
439 task_shared_vars
= BITMAP_ALLOC (NULL
);
440 bitmap_set_bit (task_shared_vars
, DECL_UID (outer
));
441 TREE_ADDRESSABLE (outer
) = 1;
450 /* Construct a new automatic decl similar to VAR. */
453 omp_copy_decl_2 (tree var
, tree name
, tree type
, omp_context
*ctx
)
455 tree copy
= copy_var_decl (var
, name
, type
);
457 DECL_CONTEXT (copy
) = current_function_decl
;
458 DECL_CHAIN (copy
) = ctx
->block_vars
;
459 /* If VAR is listed in task_shared_vars, it means it wasn't
460 originally addressable and is just because task needs to take
461 it's address. But we don't need to take address of privatizations
463 if (TREE_ADDRESSABLE (var
)
465 && bitmap_bit_p (task_shared_vars
, DECL_UID (var
)))
466 TREE_ADDRESSABLE (copy
) = 0;
467 ctx
->block_vars
= copy
;
473 omp_copy_decl_1 (tree var
, omp_context
*ctx
)
475 return omp_copy_decl_2 (var
, DECL_NAME (var
), TREE_TYPE (var
), ctx
);
478 /* Build COMPONENT_REF and set TREE_THIS_VOLATILE and TREE_READONLY on it
481 omp_build_component_ref (tree obj
, tree field
)
483 tree ret
= build3 (COMPONENT_REF
, TREE_TYPE (field
), obj
, field
, NULL
);
484 if (TREE_THIS_VOLATILE (field
))
485 TREE_THIS_VOLATILE (ret
) |= 1;
486 if (TREE_READONLY (field
))
487 TREE_READONLY (ret
) |= 1;
491 /* Build tree nodes to access the field for VAR on the receiver side. */
494 build_receiver_ref (tree var
, bool by_ref
, omp_context
*ctx
)
496 tree x
, field
= lookup_field (var
, ctx
);
498 /* If the receiver record type was remapped in the child function,
499 remap the field into the new record type. */
500 x
= maybe_lookup_field (field
, ctx
);
504 x
= build_simple_mem_ref (ctx
->receiver_decl
);
505 TREE_THIS_NOTRAP (x
) = 1;
506 x
= omp_build_component_ref (x
, field
);
509 x
= build_simple_mem_ref (x
);
510 TREE_THIS_NOTRAP (x
) = 1;
516 /* Build tree nodes to access VAR in the scope outer to CTX. In the case
517 of a parallel, this is a component reference; for workshare constructs
518 this is some variable. */
521 build_outer_var_ref (tree var
, omp_context
*ctx
,
522 enum omp_clause_code code
= OMP_CLAUSE_ERROR
)
526 if (is_global_var (maybe_lookup_decl_in_outer_ctx (var
, ctx
)))
528 else if (is_variable_sized (var
))
530 x
= TREE_OPERAND (DECL_VALUE_EXPR (var
), 0);
531 x
= build_outer_var_ref (x
, ctx
, code
);
532 x
= build_simple_mem_ref (x
);
534 else if (is_taskreg_ctx (ctx
))
536 bool by_ref
= use_pointer_for_field (var
, NULL
);
537 x
= build_receiver_ref (var
, by_ref
, ctx
);
539 else if ((gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
540 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
)
541 || (code
== OMP_CLAUSE_PRIVATE
542 && (gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
543 || gimple_code (ctx
->stmt
) == GIMPLE_OMP_SECTIONS
544 || gimple_code (ctx
->stmt
) == GIMPLE_OMP_SINGLE
)))
546 /* #pragma omp simd isn't a worksharing construct, and can reference
547 even private vars in its linear etc. clauses.
548 Similarly for OMP_CLAUSE_PRIVATE with outer ref, that can refer
549 to private vars in all worksharing constructs. */
551 if (ctx
->outer
&& is_taskreg_ctx (ctx
))
552 x
= lookup_decl (var
, ctx
->outer
);
554 x
= maybe_lookup_decl_in_outer_ctx (var
, ctx
);
558 else if (code
== OMP_CLAUSE_LASTPRIVATE
&& is_taskloop_ctx (ctx
))
560 gcc_assert (ctx
->outer
);
562 = splay_tree_lookup (ctx
->outer
->field_map
,
563 (splay_tree_key
) &DECL_UID (var
));
566 if (is_global_var (maybe_lookup_decl_in_outer_ctx (var
, ctx
->outer
)))
569 x
= lookup_decl (var
, ctx
->outer
);
573 tree field
= (tree
) n
->value
;
574 /* If the receiver record type was remapped in the child function,
575 remap the field into the new record type. */
576 x
= maybe_lookup_field (field
, ctx
->outer
);
580 x
= build_simple_mem_ref (ctx
->outer
->receiver_decl
);
581 x
= omp_build_component_ref (x
, field
);
582 if (use_pointer_for_field (var
, ctx
->outer
))
583 x
= build_simple_mem_ref (x
);
588 omp_context
*outer
= ctx
->outer
;
589 if (gimple_code (outer
->stmt
) == GIMPLE_OMP_GRID_BODY
)
591 outer
= outer
->outer
;
593 && gimple_code (outer
->stmt
) != GIMPLE_OMP_GRID_BODY
);
595 x
= lookup_decl (var
, outer
);
597 else if (omp_is_reference (var
))
598 /* This can happen with orphaned constructs. If var is reference, it is
599 possible it is shared and as such valid. */
601 else if (omp_member_access_dummy_var (var
))
608 tree t
= omp_member_access_dummy_var (var
);
611 x
= DECL_VALUE_EXPR (var
);
612 tree o
= maybe_lookup_decl_in_outer_ctx (t
, ctx
);
614 x
= unshare_and_remap (x
, t
, o
);
616 x
= unshare_expr (x
);
620 if (omp_is_reference (var
))
621 x
= build_simple_mem_ref (x
);
626 /* Build tree nodes to access the field for VAR on the sender side. */
629 build_sender_ref (splay_tree_key key
, omp_context
*ctx
)
631 tree field
= lookup_sfield (key
, ctx
);
632 return omp_build_component_ref (ctx
->sender_decl
, field
);
636 build_sender_ref (tree var
, omp_context
*ctx
)
638 return build_sender_ref ((splay_tree_key
) var
, ctx
);
641 /* Add a new field for VAR inside the structure CTX->SENDER_DECL. If
642 BASE_POINTERS_RESTRICT, declare the field with restrict. */
645 install_var_field (tree var
, bool by_ref
, int mask
, omp_context
*ctx
,
646 bool base_pointers_restrict
= false)
648 tree field
, type
, sfield
= NULL_TREE
;
649 splay_tree_key key
= (splay_tree_key
) var
;
653 key
= (splay_tree_key
) &DECL_UID (var
);
654 gcc_checking_assert (key
!= (splay_tree_key
) var
);
656 gcc_assert ((mask
& 1) == 0
657 || !splay_tree_lookup (ctx
->field_map
, key
));
658 gcc_assert ((mask
& 2) == 0 || !ctx
->sfield_map
659 || !splay_tree_lookup (ctx
->sfield_map
, key
));
660 gcc_assert ((mask
& 3) == 3
661 || !is_gimple_omp_oacc (ctx
->stmt
));
663 type
= TREE_TYPE (var
);
664 /* Prevent redeclaring the var in the split-off function with a restrict
665 pointer type. Note that we only clear type itself, restrict qualifiers in
666 the pointed-to type will be ignored by points-to analysis. */
667 if (POINTER_TYPE_P (type
)
668 && TYPE_RESTRICT (type
))
669 type
= build_qualified_type (type
, TYPE_QUALS (type
) & ~TYPE_QUAL_RESTRICT
);
673 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
674 type
= build_pointer_type (build_pointer_type (type
));
678 type
= build_pointer_type (type
);
679 if (base_pointers_restrict
)
680 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
682 else if ((mask
& 3) == 1 && omp_is_reference (var
))
683 type
= TREE_TYPE (type
);
685 field
= build_decl (DECL_SOURCE_LOCATION (var
),
686 FIELD_DECL
, DECL_NAME (var
), type
);
688 /* Remember what variable this field was created for. This does have a
689 side effect of making dwarf2out ignore this member, so for helpful
690 debugging we clear it later in delete_omp_context. */
691 DECL_ABSTRACT_ORIGIN (field
) = var
;
692 if (type
== TREE_TYPE (var
))
694 SET_DECL_ALIGN (field
, DECL_ALIGN (var
));
695 DECL_USER_ALIGN (field
) = DECL_USER_ALIGN (var
);
696 TREE_THIS_VOLATILE (field
) = TREE_THIS_VOLATILE (var
);
699 SET_DECL_ALIGN (field
, TYPE_ALIGN (type
));
703 insert_field_into_struct (ctx
->record_type
, field
);
704 if (ctx
->srecord_type
)
706 sfield
= build_decl (DECL_SOURCE_LOCATION (var
),
707 FIELD_DECL
, DECL_NAME (var
), type
);
708 DECL_ABSTRACT_ORIGIN (sfield
) = var
;
709 SET_DECL_ALIGN (sfield
, DECL_ALIGN (field
));
710 DECL_USER_ALIGN (sfield
) = DECL_USER_ALIGN (field
);
711 TREE_THIS_VOLATILE (sfield
) = TREE_THIS_VOLATILE (field
);
712 insert_field_into_struct (ctx
->srecord_type
, sfield
);
717 if (ctx
->srecord_type
== NULL_TREE
)
721 ctx
->srecord_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
722 ctx
->sfield_map
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
723 for (t
= TYPE_FIELDS (ctx
->record_type
); t
; t
= TREE_CHAIN (t
))
725 sfield
= build_decl (DECL_SOURCE_LOCATION (t
),
726 FIELD_DECL
, DECL_NAME (t
), TREE_TYPE (t
));
727 DECL_ABSTRACT_ORIGIN (sfield
) = DECL_ABSTRACT_ORIGIN (t
);
728 insert_field_into_struct (ctx
->srecord_type
, sfield
);
729 splay_tree_insert (ctx
->sfield_map
,
730 (splay_tree_key
) DECL_ABSTRACT_ORIGIN (t
),
731 (splay_tree_value
) sfield
);
735 insert_field_into_struct ((mask
& 1) ? ctx
->record_type
736 : ctx
->srecord_type
, field
);
740 splay_tree_insert (ctx
->field_map
, key
, (splay_tree_value
) field
);
741 if ((mask
& 2) && ctx
->sfield_map
)
742 splay_tree_insert (ctx
->sfield_map
, key
, (splay_tree_value
) sfield
);
746 install_var_local (tree var
, omp_context
*ctx
)
748 tree new_var
= omp_copy_decl_1 (var
, ctx
);
749 insert_decl_map (&ctx
->cb
, var
, new_var
);
753 /* Adjust the replacement for DECL in CTX for the new context. This means
754 copying the DECL_VALUE_EXPR, and fixing up the type. */
757 fixup_remapped_decl (tree decl
, omp_context
*ctx
, bool private_debug
)
761 new_decl
= lookup_decl (decl
, ctx
);
763 TREE_TYPE (new_decl
) = remap_type (TREE_TYPE (decl
), &ctx
->cb
);
765 if ((!TREE_CONSTANT (DECL_SIZE (new_decl
)) || private_debug
)
766 && DECL_HAS_VALUE_EXPR_P (decl
))
768 tree ve
= DECL_VALUE_EXPR (decl
);
769 walk_tree (&ve
, copy_tree_body_r
, &ctx
->cb
, NULL
);
770 SET_DECL_VALUE_EXPR (new_decl
, ve
);
771 DECL_HAS_VALUE_EXPR_P (new_decl
) = 1;
774 if (!TREE_CONSTANT (DECL_SIZE (new_decl
)))
776 size
= remap_decl (DECL_SIZE (decl
), &ctx
->cb
);
777 if (size
== error_mark_node
)
778 size
= TYPE_SIZE (TREE_TYPE (new_decl
));
779 DECL_SIZE (new_decl
) = size
;
781 size
= remap_decl (DECL_SIZE_UNIT (decl
), &ctx
->cb
);
782 if (size
== error_mark_node
)
783 size
= TYPE_SIZE_UNIT (TREE_TYPE (new_decl
));
784 DECL_SIZE_UNIT (new_decl
) = size
;
788 /* The callback for remap_decl. Search all containing contexts for a
789 mapping of the variable; this avoids having to duplicate the splay
790 tree ahead of time. We know a mapping doesn't already exist in the
791 given context. Create new mappings to implement default semantics. */
794 omp_copy_decl (tree var
, copy_body_data
*cb
)
796 omp_context
*ctx
= (omp_context
*) cb
;
799 if (TREE_CODE (var
) == LABEL_DECL
)
801 if (FORCED_LABEL (var
) || DECL_NONLOCAL (var
))
803 new_var
= create_artificial_label (DECL_SOURCE_LOCATION (var
));
804 DECL_CONTEXT (new_var
) = current_function_decl
;
805 insert_decl_map (&ctx
->cb
, var
, new_var
);
809 while (!is_taskreg_ctx (ctx
))
814 new_var
= maybe_lookup_decl (var
, ctx
);
819 if (is_global_var (var
) || decl_function_context (var
) != ctx
->cb
.src_fn
)
822 return error_mark_node
;
825 /* Create a new context, with OUTER_CTX being the surrounding context. */
828 new_omp_context (gimple
*stmt
, omp_context
*outer_ctx
)
830 omp_context
*ctx
= XCNEW (omp_context
);
832 splay_tree_insert (all_contexts
, (splay_tree_key
) stmt
,
833 (splay_tree_value
) ctx
);
838 ctx
->outer
= outer_ctx
;
839 ctx
->cb
= outer_ctx
->cb
;
840 ctx
->cb
.block
= NULL
;
841 ctx
->depth
= outer_ctx
->depth
+ 1;
845 ctx
->cb
.src_fn
= current_function_decl
;
846 ctx
->cb
.dst_fn
= current_function_decl
;
847 ctx
->cb
.src_node
= cgraph_node::get (current_function_decl
);
848 gcc_checking_assert (ctx
->cb
.src_node
);
849 ctx
->cb
.dst_node
= ctx
->cb
.src_node
;
850 ctx
->cb
.src_cfun
= cfun
;
851 ctx
->cb
.copy_decl
= omp_copy_decl
;
852 ctx
->cb
.eh_lp_nr
= 0;
853 ctx
->cb
.transform_call_graph_edges
= CB_CGE_MOVE
;
857 ctx
->cb
.decl_map
= new hash_map
<tree
, tree
>;
862 static gimple_seq
maybe_catch_exception (gimple_seq
);
864 /* Finalize task copyfn. */
867 finalize_task_copyfn (gomp_task
*task_stmt
)
869 struct function
*child_cfun
;
871 gimple_seq seq
= NULL
, new_seq
;
874 child_fn
= gimple_omp_task_copy_fn (task_stmt
);
875 if (child_fn
== NULL_TREE
)
878 child_cfun
= DECL_STRUCT_FUNCTION (child_fn
);
879 DECL_STRUCT_FUNCTION (child_fn
)->curr_properties
= cfun
->curr_properties
;
881 push_cfun (child_cfun
);
882 bind
= gimplify_body (child_fn
, false);
883 gimple_seq_add_stmt (&seq
, bind
);
884 new_seq
= maybe_catch_exception (seq
);
887 bind
= gimple_build_bind (NULL
, new_seq
, NULL
);
889 gimple_seq_add_stmt (&seq
, bind
);
891 gimple_set_body (child_fn
, seq
);
894 /* Inform the callgraph about the new function. */
895 cgraph_node
*node
= cgraph_node::get_create (child_fn
);
896 node
->parallelized_function
= 1;
897 cgraph_node::add_new_function (child_fn
, false);
900 /* Destroy a omp_context data structures. Called through the splay tree
901 value delete callback. */
904 delete_omp_context (splay_tree_value value
)
906 omp_context
*ctx
= (omp_context
*) value
;
908 delete ctx
->cb
.decl_map
;
911 splay_tree_delete (ctx
->field_map
);
913 splay_tree_delete (ctx
->sfield_map
);
915 /* We hijacked DECL_ABSTRACT_ORIGIN earlier. We need to clear it before
916 it produces corrupt debug information. */
917 if (ctx
->record_type
)
920 for (t
= TYPE_FIELDS (ctx
->record_type
); t
; t
= DECL_CHAIN (t
))
921 DECL_ABSTRACT_ORIGIN (t
) = NULL
;
923 if (ctx
->srecord_type
)
926 for (t
= TYPE_FIELDS (ctx
->srecord_type
); t
; t
= DECL_CHAIN (t
))
927 DECL_ABSTRACT_ORIGIN (t
) = NULL
;
930 if (is_task_ctx (ctx
))
931 finalize_task_copyfn (as_a
<gomp_task
*> (ctx
->stmt
));
936 /* Fix up RECEIVER_DECL with a type that has been remapped to the child
940 fixup_child_record_type (omp_context
*ctx
)
942 tree f
, type
= ctx
->record_type
;
944 if (!ctx
->receiver_decl
)
946 /* ??? It isn't sufficient to just call remap_type here, because
947 variably_modified_type_p doesn't work the way we expect for
948 record types. Testing each field for whether it needs remapping
949 and creating a new record by hand works, however. */
950 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
951 if (variably_modified_type_p (TREE_TYPE (f
), ctx
->cb
.src_fn
))
955 tree name
, new_fields
= NULL
;
957 type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
958 name
= DECL_NAME (TYPE_NAME (ctx
->record_type
));
959 name
= build_decl (DECL_SOURCE_LOCATION (ctx
->receiver_decl
),
960 TYPE_DECL
, name
, type
);
961 TYPE_NAME (type
) = name
;
963 for (f
= TYPE_FIELDS (ctx
->record_type
); f
; f
= DECL_CHAIN (f
))
965 tree new_f
= copy_node (f
);
966 DECL_CONTEXT (new_f
) = type
;
967 TREE_TYPE (new_f
) = remap_type (TREE_TYPE (f
), &ctx
->cb
);
968 DECL_CHAIN (new_f
) = new_fields
;
969 walk_tree (&DECL_SIZE (new_f
), copy_tree_body_r
, &ctx
->cb
, NULL
);
970 walk_tree (&DECL_SIZE_UNIT (new_f
), copy_tree_body_r
,
972 walk_tree (&DECL_FIELD_OFFSET (new_f
), copy_tree_body_r
,
976 /* Arrange to be able to look up the receiver field
977 given the sender field. */
978 splay_tree_insert (ctx
->field_map
, (splay_tree_key
) f
,
979 (splay_tree_value
) new_f
);
981 TYPE_FIELDS (type
) = nreverse (new_fields
);
985 /* In a target region we never modify any of the pointers in *.omp_data_i,
986 so attempt to help the optimizers. */
987 if (is_gimple_omp_offloaded (ctx
->stmt
))
988 type
= build_qualified_type (type
, TYPE_QUAL_CONST
);
990 TREE_TYPE (ctx
->receiver_decl
)
991 = build_qualified_type (build_reference_type (type
), TYPE_QUAL_RESTRICT
);
994 /* Instantiate decls as necessary in CTX to satisfy the data sharing
995 specified by CLAUSES. If BASE_POINTERS_RESTRICT, install var field with
999 scan_sharing_clauses (tree clauses
, omp_context
*ctx
,
1000 bool base_pointers_restrict
= false)
1003 bool scan_array_reductions
= false;
1005 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
1009 switch (OMP_CLAUSE_CODE (c
))
1011 case OMP_CLAUSE_PRIVATE
:
1012 decl
= OMP_CLAUSE_DECL (c
);
1013 if (OMP_CLAUSE_PRIVATE_OUTER_REF (c
))
1015 else if (!is_variable_sized (decl
))
1016 install_var_local (decl
, ctx
);
1019 case OMP_CLAUSE_SHARED
:
1020 decl
= OMP_CLAUSE_DECL (c
);
1021 /* Ignore shared directives in teams construct. */
1022 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TEAMS
)
1024 /* Global variables don't need to be copied,
1025 the receiver side will use them directly. */
1026 tree odecl
= maybe_lookup_decl_in_outer_ctx (decl
, ctx
);
1027 if (is_global_var (odecl
))
1029 insert_decl_map (&ctx
->cb
, decl
, odecl
);
1032 gcc_assert (is_taskreg_ctx (ctx
));
1033 gcc_assert (!COMPLETE_TYPE_P (TREE_TYPE (decl
))
1034 || !is_variable_sized (decl
));
1035 /* Global variables don't need to be copied,
1036 the receiver side will use them directly. */
1037 if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
)))
1039 if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
1041 use_pointer_for_field (decl
, ctx
);
1044 by_ref
= use_pointer_for_field (decl
, NULL
);
1045 if ((! TREE_READONLY (decl
) && !OMP_CLAUSE_SHARED_READONLY (c
))
1046 || TREE_ADDRESSABLE (decl
)
1048 || omp_is_reference (decl
))
1050 by_ref
= use_pointer_for_field (decl
, ctx
);
1051 install_var_field (decl
, by_ref
, 3, ctx
);
1052 install_var_local (decl
, ctx
);
1055 /* We don't need to copy const scalar vars back. */
1056 OMP_CLAUSE_SET_CODE (c
, OMP_CLAUSE_FIRSTPRIVATE
);
1059 case OMP_CLAUSE_REDUCTION
:
1060 decl
= OMP_CLAUSE_DECL (c
);
1061 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
1062 && TREE_CODE (decl
) == MEM_REF
)
1064 tree t
= TREE_OPERAND (decl
, 0);
1065 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
1066 t
= TREE_OPERAND (t
, 0);
1067 if (TREE_CODE (t
) == INDIRECT_REF
1068 || TREE_CODE (t
) == ADDR_EXPR
)
1069 t
= TREE_OPERAND (t
, 0);
1070 install_var_local (t
, ctx
);
1071 if (is_taskreg_ctx (ctx
)
1072 && !is_global_var (maybe_lookup_decl_in_outer_ctx (t
, ctx
))
1073 && !is_variable_sized (t
))
1075 by_ref
= use_pointer_for_field (t
, ctx
);
1076 install_var_field (t
, by_ref
, 3, ctx
);
1082 case OMP_CLAUSE_LASTPRIVATE
:
1083 /* Let the corresponding firstprivate clause create
1085 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
1089 case OMP_CLAUSE_FIRSTPRIVATE
:
1090 case OMP_CLAUSE_LINEAR
:
1091 decl
= OMP_CLAUSE_DECL (c
);
1093 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
1094 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IS_DEVICE_PTR
)
1095 && is_gimple_omp_offloaded (ctx
->stmt
))
1097 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
1098 install_var_field (decl
, !omp_is_reference (decl
), 3, ctx
);
1099 else if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1100 install_var_field (decl
, true, 3, ctx
);
1102 install_var_field (decl
, false, 3, ctx
);
1104 if (is_variable_sized (decl
))
1106 if (is_task_ctx (ctx
))
1107 install_var_field (decl
, false, 1, ctx
);
1110 else if (is_taskreg_ctx (ctx
))
1113 = is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
));
1114 by_ref
= use_pointer_for_field (decl
, NULL
);
1116 if (is_task_ctx (ctx
)
1117 && (global
|| by_ref
|| omp_is_reference (decl
)))
1119 install_var_field (decl
, false, 1, ctx
);
1121 install_var_field (decl
, by_ref
, 2, ctx
);
1124 install_var_field (decl
, by_ref
, 3, ctx
);
1126 install_var_local (decl
, ctx
);
1129 case OMP_CLAUSE_USE_DEVICE_PTR
:
1130 decl
= OMP_CLAUSE_DECL (c
);
1131 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1132 install_var_field (decl
, true, 3, ctx
);
1134 install_var_field (decl
, false, 3, ctx
);
1135 if (DECL_SIZE (decl
)
1136 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1138 tree decl2
= DECL_VALUE_EXPR (decl
);
1139 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
1140 decl2
= TREE_OPERAND (decl2
, 0);
1141 gcc_assert (DECL_P (decl2
));
1142 install_var_local (decl2
, ctx
);
1144 install_var_local (decl
, ctx
);
1147 case OMP_CLAUSE_IS_DEVICE_PTR
:
1148 decl
= OMP_CLAUSE_DECL (c
);
1151 case OMP_CLAUSE__LOOPTEMP_
:
1152 gcc_assert (is_taskreg_ctx (ctx
));
1153 decl
= OMP_CLAUSE_DECL (c
);
1154 install_var_field (decl
, false, 3, ctx
);
1155 install_var_local (decl
, ctx
);
1158 case OMP_CLAUSE_COPYPRIVATE
:
1159 case OMP_CLAUSE_COPYIN
:
1160 decl
= OMP_CLAUSE_DECL (c
);
1161 by_ref
= use_pointer_for_field (decl
, NULL
);
1162 install_var_field (decl
, by_ref
, 3, ctx
);
1165 case OMP_CLAUSE_FINAL
:
1167 case OMP_CLAUSE_NUM_THREADS
:
1168 case OMP_CLAUSE_NUM_TEAMS
:
1169 case OMP_CLAUSE_THREAD_LIMIT
:
1170 case OMP_CLAUSE_DEVICE
:
1171 case OMP_CLAUSE_SCHEDULE
:
1172 case OMP_CLAUSE_DIST_SCHEDULE
:
1173 case OMP_CLAUSE_DEPEND
:
1174 case OMP_CLAUSE_PRIORITY
:
1175 case OMP_CLAUSE_GRAINSIZE
:
1176 case OMP_CLAUSE_NUM_TASKS
:
1177 case OMP_CLAUSE__CILK_FOR_COUNT_
:
1178 case OMP_CLAUSE_NUM_GANGS
:
1179 case OMP_CLAUSE_NUM_WORKERS
:
1180 case OMP_CLAUSE_VECTOR_LENGTH
:
1182 scan_omp_op (&OMP_CLAUSE_OPERAND (c
, 0), ctx
->outer
);
1186 case OMP_CLAUSE_FROM
:
1187 case OMP_CLAUSE_MAP
:
1189 scan_omp_op (&OMP_CLAUSE_SIZE (c
), ctx
->outer
);
1190 decl
= OMP_CLAUSE_DECL (c
);
1191 /* Global variables with "omp declare target" attribute
1192 don't need to be copied, the receiver side will use them
1193 directly. However, global variables with "omp declare target link"
1194 attribute need to be copied. */
1195 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
1197 && ((OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FIRSTPRIVATE_POINTER
1198 && (OMP_CLAUSE_MAP_KIND (c
)
1199 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
1200 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1201 && is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
))
1202 && varpool_node::get_create (decl
)->offloadable
1203 && !lookup_attribute ("omp declare target link",
1204 DECL_ATTRIBUTES (decl
)))
1206 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
1207 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
)
1209 /* Ignore GOMP_MAP_POINTER kind for arrays in regions that are
1210 not offloaded; there is nothing to map for those. */
1211 if (!is_gimple_omp_offloaded (ctx
->stmt
)
1212 && !POINTER_TYPE_P (TREE_TYPE (decl
))
1213 && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
))
1216 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
1217 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
1218 || (OMP_CLAUSE_MAP_KIND (c
)
1219 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
)))
1221 if (TREE_CODE (decl
) == COMPONENT_REF
1222 || (TREE_CODE (decl
) == INDIRECT_REF
1223 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
1224 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
1225 == REFERENCE_TYPE
)))
1227 if (DECL_SIZE (decl
)
1228 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1230 tree decl2
= DECL_VALUE_EXPR (decl
);
1231 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
1232 decl2
= TREE_OPERAND (decl2
, 0);
1233 gcc_assert (DECL_P (decl2
));
1234 install_var_local (decl2
, ctx
);
1236 install_var_local (decl
, ctx
);
1241 if (DECL_SIZE (decl
)
1242 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1244 tree decl2
= DECL_VALUE_EXPR (decl
);
1245 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
1246 decl2
= TREE_OPERAND (decl2
, 0);
1247 gcc_assert (DECL_P (decl2
));
1248 install_var_field (decl2
, true, 3, ctx
);
1249 install_var_local (decl2
, ctx
);
1250 install_var_local (decl
, ctx
);
1254 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
1255 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
1256 && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
)
1257 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1258 install_var_field (decl
, true, 7, ctx
);
1260 install_var_field (decl
, true, 3, ctx
,
1261 base_pointers_restrict
);
1262 if (is_gimple_omp_offloaded (ctx
->stmt
)
1263 && !OMP_CLAUSE_MAP_IN_REDUCTION (c
))
1264 install_var_local (decl
, ctx
);
1269 tree base
= get_base_address (decl
);
1270 tree nc
= OMP_CLAUSE_CHAIN (c
);
1273 && OMP_CLAUSE_CODE (nc
) == OMP_CLAUSE_MAP
1274 && OMP_CLAUSE_DECL (nc
) == base
1275 && OMP_CLAUSE_MAP_KIND (nc
) == GOMP_MAP_POINTER
1276 && integer_zerop (OMP_CLAUSE_SIZE (nc
)))
1278 OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
) = 1;
1279 OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (nc
) = 1;
1285 scan_omp_op (&OMP_CLAUSE_DECL (c
), ctx
->outer
);
1286 decl
= OMP_CLAUSE_DECL (c
);
1288 gcc_assert (!splay_tree_lookup (ctx
->field_map
,
1289 (splay_tree_key
) decl
));
1291 = build_decl (OMP_CLAUSE_LOCATION (c
),
1292 FIELD_DECL
, NULL_TREE
, ptr_type_node
);
1293 SET_DECL_ALIGN (field
, TYPE_ALIGN (ptr_type_node
));
1294 insert_field_into_struct (ctx
->record_type
, field
);
1295 splay_tree_insert (ctx
->field_map
, (splay_tree_key
) decl
,
1296 (splay_tree_value
) field
);
1301 case OMP_CLAUSE__GRIDDIM_
:
1304 scan_omp_op (&OMP_CLAUSE__GRIDDIM__SIZE (c
), ctx
->outer
);
1305 scan_omp_op (&OMP_CLAUSE__GRIDDIM__GROUP (c
), ctx
->outer
);
1309 case OMP_CLAUSE_NOWAIT
:
1310 case OMP_CLAUSE_ORDERED
:
1311 case OMP_CLAUSE_COLLAPSE
:
1312 case OMP_CLAUSE_UNTIED
:
1313 case OMP_CLAUSE_MERGEABLE
:
1314 case OMP_CLAUSE_PROC_BIND
:
1315 case OMP_CLAUSE_SAFELEN
:
1316 case OMP_CLAUSE_SIMDLEN
:
1317 case OMP_CLAUSE_THREADS
:
1318 case OMP_CLAUSE_SIMD
:
1319 case OMP_CLAUSE_NOGROUP
:
1320 case OMP_CLAUSE_DEFAULTMAP
:
1321 case OMP_CLAUSE_ASYNC
:
1322 case OMP_CLAUSE_WAIT
:
1323 case OMP_CLAUSE_GANG
:
1324 case OMP_CLAUSE_WORKER
:
1325 case OMP_CLAUSE_VECTOR
:
1326 case OMP_CLAUSE_INDEPENDENT
:
1327 case OMP_CLAUSE_AUTO
:
1328 case OMP_CLAUSE_SEQ
:
1329 case OMP_CLAUSE_TILE
:
1330 case OMP_CLAUSE__SIMT_
:
1331 case OMP_CLAUSE_DEFAULT
:
1334 case OMP_CLAUSE_ALIGNED
:
1335 decl
= OMP_CLAUSE_DECL (c
);
1336 if (is_global_var (decl
)
1337 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1338 install_var_local (decl
, ctx
);
1341 case OMP_CLAUSE__CACHE_
:
1347 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
1349 switch (OMP_CLAUSE_CODE (c
))
1351 case OMP_CLAUSE_LASTPRIVATE
:
1352 /* Let the corresponding firstprivate clause create
1354 if (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
))
1355 scan_array_reductions
= true;
1356 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
1360 case OMP_CLAUSE_FIRSTPRIVATE
:
1361 case OMP_CLAUSE_PRIVATE
:
1362 case OMP_CLAUSE_LINEAR
:
1363 case OMP_CLAUSE_IS_DEVICE_PTR
:
1364 decl
= OMP_CLAUSE_DECL (c
);
1365 if (is_variable_sized (decl
))
1367 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
1368 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IS_DEVICE_PTR
)
1369 && is_gimple_omp_offloaded (ctx
->stmt
))
1371 tree decl2
= DECL_VALUE_EXPR (decl
);
1372 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
1373 decl2
= TREE_OPERAND (decl2
, 0);
1374 gcc_assert (DECL_P (decl2
));
1375 install_var_local (decl2
, ctx
);
1376 fixup_remapped_decl (decl2
, ctx
, false);
1378 install_var_local (decl
, ctx
);
1380 fixup_remapped_decl (decl
, ctx
,
1381 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
1382 && OMP_CLAUSE_PRIVATE_DEBUG (c
));
1383 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
1384 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
))
1385 scan_array_reductions
= true;
1388 case OMP_CLAUSE_REDUCTION
:
1389 decl
= OMP_CLAUSE_DECL (c
);
1390 if (TREE_CODE (decl
) != MEM_REF
)
1392 if (is_variable_sized (decl
))
1393 install_var_local (decl
, ctx
);
1394 fixup_remapped_decl (decl
, ctx
, false);
1396 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
1397 scan_array_reductions
= true;
1400 case OMP_CLAUSE_SHARED
:
1401 /* Ignore shared directives in teams construct. */
1402 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TEAMS
)
1404 decl
= OMP_CLAUSE_DECL (c
);
1405 if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
)))
1407 if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
1409 if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl
,
1412 bool by_ref
= use_pointer_for_field (decl
, ctx
);
1413 install_var_field (decl
, by_ref
, 11, ctx
);
1416 fixup_remapped_decl (decl
, ctx
, false);
1419 case OMP_CLAUSE_MAP
:
1420 if (!is_gimple_omp_offloaded (ctx
->stmt
))
1422 decl
= OMP_CLAUSE_DECL (c
);
1424 && ((OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FIRSTPRIVATE_POINTER
1425 && (OMP_CLAUSE_MAP_KIND (c
)
1426 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
1427 || TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1428 && is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
))
1429 && varpool_node::get_create (decl
)->offloadable
)
1433 if ((OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
1434 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
1435 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
1436 && !COMPLETE_TYPE_P (TREE_TYPE (decl
)))
1438 tree new_decl
= lookup_decl (decl
, ctx
);
1439 TREE_TYPE (new_decl
)
1440 = remap_type (TREE_TYPE (decl
), &ctx
->cb
);
1442 else if (DECL_SIZE (decl
)
1443 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
1445 tree decl2
= DECL_VALUE_EXPR (decl
);
1446 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
1447 decl2
= TREE_OPERAND (decl2
, 0);
1448 gcc_assert (DECL_P (decl2
));
1449 fixup_remapped_decl (decl2
, ctx
, false);
1450 fixup_remapped_decl (decl
, ctx
, true);
1453 fixup_remapped_decl (decl
, ctx
, false);
1457 case OMP_CLAUSE_COPYPRIVATE
:
1458 case OMP_CLAUSE_COPYIN
:
1459 case OMP_CLAUSE_DEFAULT
:
1461 case OMP_CLAUSE_NUM_THREADS
:
1462 case OMP_CLAUSE_NUM_TEAMS
:
1463 case OMP_CLAUSE_THREAD_LIMIT
:
1464 case OMP_CLAUSE_DEVICE
:
1465 case OMP_CLAUSE_SCHEDULE
:
1466 case OMP_CLAUSE_DIST_SCHEDULE
:
1467 case OMP_CLAUSE_NOWAIT
:
1468 case OMP_CLAUSE_ORDERED
:
1469 case OMP_CLAUSE_COLLAPSE
:
1470 case OMP_CLAUSE_UNTIED
:
1471 case OMP_CLAUSE_FINAL
:
1472 case OMP_CLAUSE_MERGEABLE
:
1473 case OMP_CLAUSE_PROC_BIND
:
1474 case OMP_CLAUSE_SAFELEN
:
1475 case OMP_CLAUSE_SIMDLEN
:
1476 case OMP_CLAUSE_ALIGNED
:
1477 case OMP_CLAUSE_DEPEND
:
1478 case OMP_CLAUSE__LOOPTEMP_
:
1480 case OMP_CLAUSE_FROM
:
1481 case OMP_CLAUSE_PRIORITY
:
1482 case OMP_CLAUSE_GRAINSIZE
:
1483 case OMP_CLAUSE_NUM_TASKS
:
1484 case OMP_CLAUSE_THREADS
:
1485 case OMP_CLAUSE_SIMD
:
1486 case OMP_CLAUSE_NOGROUP
:
1487 case OMP_CLAUSE_DEFAULTMAP
:
1488 case OMP_CLAUSE_USE_DEVICE_PTR
:
1489 case OMP_CLAUSE__CILK_FOR_COUNT_
:
1490 case OMP_CLAUSE_ASYNC
:
1491 case OMP_CLAUSE_WAIT
:
1492 case OMP_CLAUSE_NUM_GANGS
:
1493 case OMP_CLAUSE_NUM_WORKERS
:
1494 case OMP_CLAUSE_VECTOR_LENGTH
:
1495 case OMP_CLAUSE_GANG
:
1496 case OMP_CLAUSE_WORKER
:
1497 case OMP_CLAUSE_VECTOR
:
1498 case OMP_CLAUSE_INDEPENDENT
:
1499 case OMP_CLAUSE_AUTO
:
1500 case OMP_CLAUSE_SEQ
:
1501 case OMP_CLAUSE_TILE
:
1502 case OMP_CLAUSE__GRIDDIM_
:
1503 case OMP_CLAUSE__SIMT_
:
1506 case OMP_CLAUSE__CACHE_
:
1512 gcc_checking_assert (!scan_array_reductions
1513 || !is_gimple_omp_oacc (ctx
->stmt
));
1514 if (scan_array_reductions
)
1516 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
1517 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
1518 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
1520 scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
), ctx
);
1521 scan_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
), ctx
);
1523 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
1524 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
))
1525 scan_omp (&OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
), ctx
);
1526 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
1527 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
))
1528 scan_omp (&OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
), ctx
);
1532 /* Create a new name for omp child function. Returns an identifier. If
1533 IS_CILK_FOR is true then the suffix for the child function is
1537 create_omp_child_function_name (bool task_copy
, bool is_cilk_for
)
1540 return clone_function_name (current_function_decl
, "_cilk_for_fn");
1541 return clone_function_name (current_function_decl
,
1542 task_copy
? "_omp_cpyfn" : "_omp_fn");
1545 /* Returns the type of the induction variable for the child function for
1546 _Cilk_for and the types for _high and _low variables based on TYPE. */
1549 cilk_for_check_loop_diff_type (tree type
)
1551 if (TYPE_PRECISION (type
) <= TYPE_PRECISION (uint32_type_node
))
1553 if (TYPE_UNSIGNED (type
))
1554 return uint32_type_node
;
1556 return integer_type_node
;
1560 if (TYPE_UNSIGNED (type
))
1561 return uint64_type_node
;
1563 return long_long_integer_type_node
;
1567 /* Return true if CTX may belong to offloaded code: either if current function
1568 is offloaded, or any enclosing context corresponds to a target region. */
1571 omp_maybe_offloaded_ctx (omp_context
*ctx
)
1573 if (cgraph_node::get (current_function_decl
)->offloadable
)
1575 for (; ctx
; ctx
= ctx
->outer
)
1576 if (is_gimple_omp_offloaded (ctx
->stmt
))
1581 /* Build a decl for the omp child function. It'll not contain a body
1582 yet, just the bare decl. */
1585 create_omp_child_function (omp_context
*ctx
, bool task_copy
)
1587 tree decl
, type
, name
, t
;
1590 = (flag_cilkplus
&& gimple_code (ctx
->stmt
) == GIMPLE_OMP_PARALLEL
)
1591 ? omp_find_clause (gimple_omp_parallel_clauses (ctx
->stmt
),
1592 OMP_CLAUSE__CILK_FOR_COUNT_
) : NULL_TREE
;
1593 tree cilk_var_type
= NULL_TREE
;
1595 name
= create_omp_child_function_name (task_copy
,
1596 cilk_for_count
!= NULL_TREE
);
1598 type
= build_function_type_list (void_type_node
, ptr_type_node
,
1599 ptr_type_node
, NULL_TREE
);
1600 else if (cilk_for_count
)
1602 type
= TREE_TYPE (OMP_CLAUSE_OPERAND (cilk_for_count
, 0));
1603 cilk_var_type
= cilk_for_check_loop_diff_type (type
);
1604 type
= build_function_type_list (void_type_node
, ptr_type_node
,
1605 cilk_var_type
, cilk_var_type
, NULL_TREE
);
1608 type
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
1610 decl
= build_decl (gimple_location (ctx
->stmt
), FUNCTION_DECL
, name
, type
);
1612 gcc_checking_assert (!is_gimple_omp_oacc (ctx
->stmt
)
1615 ctx
->cb
.dst_fn
= decl
;
1617 gimple_omp_task_set_copy_fn (ctx
->stmt
, decl
);
1619 TREE_STATIC (decl
) = 1;
1620 TREE_USED (decl
) = 1;
1621 DECL_ARTIFICIAL (decl
) = 1;
1622 DECL_IGNORED_P (decl
) = 0;
1623 TREE_PUBLIC (decl
) = 0;
1624 DECL_UNINLINABLE (decl
) = 1;
1625 DECL_EXTERNAL (decl
) = 0;
1626 DECL_CONTEXT (decl
) = NULL_TREE
;
1627 DECL_INITIAL (decl
) = make_node (BLOCK
);
1628 BLOCK_SUPERCONTEXT (DECL_INITIAL (decl
)) = decl
;
1629 if (omp_maybe_offloaded_ctx (ctx
))
1631 cgraph_node::get_create (decl
)->offloadable
= 1;
1632 if (ENABLE_OFFLOADING
)
1633 g
->have_offload
= true;
1636 if (cgraph_node::get_create (decl
)->offloadable
1637 && !lookup_attribute ("omp declare target",
1638 DECL_ATTRIBUTES (current_function_decl
)))
1640 const char *target_attr
= (is_gimple_omp_offloaded (ctx
->stmt
)
1641 ? "omp target entrypoint"
1642 : "omp declare target");
1643 DECL_ATTRIBUTES (decl
)
1644 = tree_cons (get_identifier (target_attr
),
1645 NULL_TREE
, DECL_ATTRIBUTES (decl
));
1648 t
= build_decl (DECL_SOURCE_LOCATION (decl
),
1649 RESULT_DECL
, NULL_TREE
, void_type_node
);
1650 DECL_ARTIFICIAL (t
) = 1;
1651 DECL_IGNORED_P (t
) = 1;
1652 DECL_CONTEXT (t
) = decl
;
1653 DECL_RESULT (decl
) = t
;
1655 /* _Cilk_for's child function requires two extra parameters called
1656 __low and __high that are set the by Cilk runtime when it calls this
1660 t
= build_decl (DECL_SOURCE_LOCATION (decl
),
1661 PARM_DECL
, get_identifier ("__high"), cilk_var_type
);
1662 DECL_ARTIFICIAL (t
) = 1;
1663 DECL_NAMELESS (t
) = 1;
1664 DECL_ARG_TYPE (t
) = ptr_type_node
;
1665 DECL_CONTEXT (t
) = current_function_decl
;
1667 DECL_CHAIN (t
) = DECL_ARGUMENTS (decl
);
1668 DECL_ARGUMENTS (decl
) = t
;
1670 t
= build_decl (DECL_SOURCE_LOCATION (decl
),
1671 PARM_DECL
, get_identifier ("__low"), cilk_var_type
);
1672 DECL_ARTIFICIAL (t
) = 1;
1673 DECL_NAMELESS (t
) = 1;
1674 DECL_ARG_TYPE (t
) = ptr_type_node
;
1675 DECL_CONTEXT (t
) = current_function_decl
;
1677 DECL_CHAIN (t
) = DECL_ARGUMENTS (decl
);
1678 DECL_ARGUMENTS (decl
) = t
;
1681 tree data_name
= get_identifier (".omp_data_i");
1682 t
= build_decl (DECL_SOURCE_LOCATION (decl
), PARM_DECL
, data_name
,
1684 DECL_ARTIFICIAL (t
) = 1;
1685 DECL_NAMELESS (t
) = 1;
1686 DECL_ARG_TYPE (t
) = ptr_type_node
;
1687 DECL_CONTEXT (t
) = current_function_decl
;
1689 TREE_READONLY (t
) = 1;
1691 DECL_CHAIN (t
) = DECL_ARGUMENTS (decl
);
1692 DECL_ARGUMENTS (decl
) = t
;
1694 ctx
->receiver_decl
= t
;
1697 t
= build_decl (DECL_SOURCE_LOCATION (decl
),
1698 PARM_DECL
, get_identifier (".omp_data_o"),
1700 DECL_ARTIFICIAL (t
) = 1;
1701 DECL_NAMELESS (t
) = 1;
1702 DECL_ARG_TYPE (t
) = ptr_type_node
;
1703 DECL_CONTEXT (t
) = current_function_decl
;
1705 TREE_ADDRESSABLE (t
) = 1;
1706 DECL_CHAIN (t
) = DECL_ARGUMENTS (decl
);
1707 DECL_ARGUMENTS (decl
) = t
;
1710 /* Allocate memory for the function structure. The call to
1711 allocate_struct_function clobbers CFUN, so we need to restore
1713 push_struct_function (decl
);
1714 cfun
->function_end_locus
= gimple_location (ctx
->stmt
);
1715 init_tree_ssa (cfun
);
1719 /* Callback for walk_gimple_seq. Check if combined parallel
1720 contains gimple_omp_for_combined_into_p OMP_FOR. */
1723 omp_find_combined_for (gimple_stmt_iterator
*gsi_p
,
1724 bool *handled_ops_p
,
1725 struct walk_stmt_info
*wi
)
1727 gimple
*stmt
= gsi_stmt (*gsi_p
);
1729 *handled_ops_p
= true;
1730 switch (gimple_code (stmt
))
1734 case GIMPLE_OMP_FOR
:
1735 if (gimple_omp_for_combined_into_p (stmt
)
1736 && gimple_omp_for_kind (stmt
)
1737 == *(const enum gf_mask
*) (wi
->info
))
1740 return integer_zero_node
;
1749 /* Add _LOOPTEMP_ clauses on OpenMP parallel or task. */
1752 add_taskreg_looptemp_clauses (enum gf_mask msk
, gimple
*stmt
,
1753 omp_context
*outer_ctx
)
1755 struct walk_stmt_info wi
;
1757 memset (&wi
, 0, sizeof (wi
));
1759 wi
.info
= (void *) &msk
;
1760 walk_gimple_seq (gimple_omp_body (stmt
), omp_find_combined_for
, NULL
, &wi
);
1761 if (wi
.info
!= (void *) &msk
)
1763 gomp_for
*for_stmt
= as_a
<gomp_for
*> ((gimple
*) wi
.info
);
1764 struct omp_for_data fd
;
1765 omp_extract_for_data (for_stmt
, &fd
, NULL
);
1766 /* We need two temporaries with fd.loop.v type (istart/iend)
1767 and then (fd.collapse - 1) temporaries with the same
1768 type for count2 ... countN-1 vars if not constant. */
1769 size_t count
= 2, i
;
1770 tree type
= fd
.iter_type
;
1772 && TREE_CODE (fd
.loop
.n2
) != INTEGER_CST
)
1774 count
+= fd
.collapse
- 1;
1775 /* If there are lastprivate clauses on the inner
1776 GIMPLE_OMP_FOR, add one more temporaries for the total number
1777 of iterations (product of count1 ... countN-1). */
1778 if (omp_find_clause (gimple_omp_for_clauses (for_stmt
),
1779 OMP_CLAUSE_LASTPRIVATE
))
1781 else if (msk
== GF_OMP_FOR_KIND_FOR
1782 && omp_find_clause (gimple_omp_parallel_clauses (stmt
),
1783 OMP_CLAUSE_LASTPRIVATE
))
1786 for (i
= 0; i
< count
; i
++)
1788 tree temp
= create_tmp_var (type
);
1789 tree c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE__LOOPTEMP_
);
1790 insert_decl_map (&outer_ctx
->cb
, temp
, temp
);
1791 OMP_CLAUSE_DECL (c
) = temp
;
1792 OMP_CLAUSE_CHAIN (c
) = gimple_omp_taskreg_clauses (stmt
);
1793 gimple_omp_taskreg_set_clauses (stmt
, c
);
1798 /* Scan an OpenMP parallel directive. */
1801 scan_omp_parallel (gimple_stmt_iterator
*gsi
, omp_context
*outer_ctx
)
1805 gomp_parallel
*stmt
= as_a
<gomp_parallel
*> (gsi_stmt (*gsi
));
1807 /* Ignore parallel directives with empty bodies, unless there
1808 are copyin clauses. */
1810 && empty_body_p (gimple_omp_body (stmt
))
1811 && omp_find_clause (gimple_omp_parallel_clauses (stmt
),
1812 OMP_CLAUSE_COPYIN
) == NULL
)
1814 gsi_replace (gsi
, gimple_build_nop (), false);
1818 if (gimple_omp_parallel_combined_p (stmt
))
1819 add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_FOR
, stmt
, outer_ctx
);
1821 ctx
= new_omp_context (stmt
, outer_ctx
);
1822 taskreg_contexts
.safe_push (ctx
);
1823 if (taskreg_nesting_level
> 1)
1824 ctx
->is_nested
= true;
1825 ctx
->field_map
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
1826 ctx
->record_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
1827 name
= create_tmp_var_name (".omp_data_s");
1828 name
= build_decl (gimple_location (stmt
),
1829 TYPE_DECL
, name
, ctx
->record_type
);
1830 DECL_ARTIFICIAL (name
) = 1;
1831 DECL_NAMELESS (name
) = 1;
1832 TYPE_NAME (ctx
->record_type
) = name
;
1833 TYPE_ARTIFICIAL (ctx
->record_type
) = 1;
1834 if (!gimple_omp_parallel_grid_phony (stmt
))
1836 create_omp_child_function (ctx
, false);
1837 gimple_omp_parallel_set_child_fn (stmt
, ctx
->cb
.dst_fn
);
1840 scan_sharing_clauses (gimple_omp_parallel_clauses (stmt
), ctx
);
1841 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
1843 if (TYPE_FIELDS (ctx
->record_type
) == NULL
)
1844 ctx
->record_type
= ctx
->receiver_decl
= NULL
;
1847 /* Scan an OpenMP task directive. */
1850 scan_omp_task (gimple_stmt_iterator
*gsi
, omp_context
*outer_ctx
)
1854 gomp_task
*stmt
= as_a
<gomp_task
*> (gsi_stmt (*gsi
));
1856 /* Ignore task directives with empty bodies, unless they have depend
1859 && empty_body_p (gimple_omp_body (stmt
))
1860 && !omp_find_clause (gimple_omp_task_clauses (stmt
), OMP_CLAUSE_DEPEND
))
1862 gsi_replace (gsi
, gimple_build_nop (), false);
1866 if (gimple_omp_task_taskloop_p (stmt
))
1867 add_taskreg_looptemp_clauses (GF_OMP_FOR_KIND_TASKLOOP
, stmt
, outer_ctx
);
1869 ctx
= new_omp_context (stmt
, outer_ctx
);
1870 taskreg_contexts
.safe_push (ctx
);
1871 if (taskreg_nesting_level
> 1)
1872 ctx
->is_nested
= true;
1873 ctx
->field_map
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
1874 ctx
->record_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
1875 name
= create_tmp_var_name (".omp_data_s");
1876 name
= build_decl (gimple_location (stmt
),
1877 TYPE_DECL
, name
, ctx
->record_type
);
1878 DECL_ARTIFICIAL (name
) = 1;
1879 DECL_NAMELESS (name
) = 1;
1880 TYPE_NAME (ctx
->record_type
) = name
;
1881 TYPE_ARTIFICIAL (ctx
->record_type
) = 1;
1882 create_omp_child_function (ctx
, false);
1883 gimple_omp_task_set_child_fn (stmt
, ctx
->cb
.dst_fn
);
1885 scan_sharing_clauses (gimple_omp_task_clauses (stmt
), ctx
);
1887 if (ctx
->srecord_type
)
1889 name
= create_tmp_var_name (".omp_data_a");
1890 name
= build_decl (gimple_location (stmt
),
1891 TYPE_DECL
, name
, ctx
->srecord_type
);
1892 DECL_ARTIFICIAL (name
) = 1;
1893 DECL_NAMELESS (name
) = 1;
1894 TYPE_NAME (ctx
->srecord_type
) = name
;
1895 TYPE_ARTIFICIAL (ctx
->srecord_type
) = 1;
1896 create_omp_child_function (ctx
, true);
1899 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
1901 if (TYPE_FIELDS (ctx
->record_type
) == NULL
)
1903 ctx
->record_type
= ctx
->receiver_decl
= NULL
;
1904 t
= build_int_cst (long_integer_type_node
, 0);
1905 gimple_omp_task_set_arg_size (stmt
, t
);
1906 t
= build_int_cst (long_integer_type_node
, 1);
1907 gimple_omp_task_set_arg_align (stmt
, t
);
1911 /* Helper function for finish_taskreg_scan, called through walk_tree.
1912 If maybe_lookup_decl_in_outer_context returns non-NULL for some
1913 tree, replace it in the expression. */
1916 finish_taskreg_remap (tree
*tp
, int *walk_subtrees
, void *data
)
1920 omp_context
*ctx
= (omp_context
*) data
;
1921 tree t
= maybe_lookup_decl_in_outer_ctx (*tp
, ctx
);
1924 if (DECL_HAS_VALUE_EXPR_P (t
))
1925 t
= unshare_expr (DECL_VALUE_EXPR (t
));
1930 else if (IS_TYPE_OR_DECL_P (*tp
))
1935 /* If any decls have been made addressable during scan_omp,
1936 adjust their fields if needed, and layout record types
1937 of parallel/task constructs. */
1940 finish_taskreg_scan (omp_context
*ctx
)
1942 if (ctx
->record_type
== NULL_TREE
)
1945 /* If any task_shared_vars were needed, verify all
1946 OMP_CLAUSE_SHARED clauses on GIMPLE_OMP_{PARALLEL,TASK}
1947 statements if use_pointer_for_field hasn't changed
1948 because of that. If it did, update field types now. */
1949 if (task_shared_vars
)
1953 for (c
= gimple_omp_taskreg_clauses (ctx
->stmt
);
1954 c
; c
= OMP_CLAUSE_CHAIN (c
))
1955 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
1956 && !OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
1958 tree decl
= OMP_CLAUSE_DECL (c
);
1960 /* Global variables don't need to be copied,
1961 the receiver side will use them directly. */
1962 if (is_global_var (maybe_lookup_decl_in_outer_ctx (decl
, ctx
)))
1964 if (!bitmap_bit_p (task_shared_vars
, DECL_UID (decl
))
1965 || !use_pointer_for_field (decl
, ctx
))
1967 tree field
= lookup_field (decl
, ctx
);
1968 if (TREE_CODE (TREE_TYPE (field
)) == POINTER_TYPE
1969 && TREE_TYPE (TREE_TYPE (field
)) == TREE_TYPE (decl
))
1971 TREE_TYPE (field
) = build_pointer_type (TREE_TYPE (decl
));
1972 TREE_THIS_VOLATILE (field
) = 0;
1973 DECL_USER_ALIGN (field
) = 0;
1974 SET_DECL_ALIGN (field
, TYPE_ALIGN (TREE_TYPE (field
)));
1975 if (TYPE_ALIGN (ctx
->record_type
) < DECL_ALIGN (field
))
1976 SET_TYPE_ALIGN (ctx
->record_type
, DECL_ALIGN (field
));
1977 if (ctx
->srecord_type
)
1979 tree sfield
= lookup_sfield (decl
, ctx
);
1980 TREE_TYPE (sfield
) = TREE_TYPE (field
);
1981 TREE_THIS_VOLATILE (sfield
) = 0;
1982 DECL_USER_ALIGN (sfield
) = 0;
1983 SET_DECL_ALIGN (sfield
, DECL_ALIGN (field
));
1984 if (TYPE_ALIGN (ctx
->srecord_type
) < DECL_ALIGN (sfield
))
1985 SET_TYPE_ALIGN (ctx
->srecord_type
, DECL_ALIGN (sfield
));
1990 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_PARALLEL
)
1992 layout_type (ctx
->record_type
);
1993 fixup_child_record_type (ctx
);
1997 location_t loc
= gimple_location (ctx
->stmt
);
1998 tree
*p
, vla_fields
= NULL_TREE
, *q
= &vla_fields
;
1999 /* Move VLA fields to the end. */
2000 p
= &TYPE_FIELDS (ctx
->record_type
);
2002 if (!TYPE_SIZE_UNIT (TREE_TYPE (*p
))
2003 || ! TREE_CONSTANT (TYPE_SIZE_UNIT (TREE_TYPE (*p
))))
2006 *p
= TREE_CHAIN (*p
);
2007 TREE_CHAIN (*q
) = NULL_TREE
;
2008 q
= &TREE_CHAIN (*q
);
2011 p
= &DECL_CHAIN (*p
);
2013 if (gimple_omp_task_taskloop_p (ctx
->stmt
))
2015 /* Move fields corresponding to first and second _looptemp_
2016 clause first. There are filled by GOMP_taskloop
2017 and thus need to be in specific positions. */
2018 tree c1
= gimple_omp_task_clauses (ctx
->stmt
);
2019 c1
= omp_find_clause (c1
, OMP_CLAUSE__LOOPTEMP_
);
2020 tree c2
= omp_find_clause (OMP_CLAUSE_CHAIN (c1
),
2021 OMP_CLAUSE__LOOPTEMP_
);
2022 tree f1
= lookup_field (OMP_CLAUSE_DECL (c1
), ctx
);
2023 tree f2
= lookup_field (OMP_CLAUSE_DECL (c2
), ctx
);
2024 p
= &TYPE_FIELDS (ctx
->record_type
);
2026 if (*p
== f1
|| *p
== f2
)
2027 *p
= DECL_CHAIN (*p
);
2029 p
= &DECL_CHAIN (*p
);
2030 DECL_CHAIN (f1
) = f2
;
2031 DECL_CHAIN (f2
) = TYPE_FIELDS (ctx
->record_type
);
2032 TYPE_FIELDS (ctx
->record_type
) = f1
;
2033 if (ctx
->srecord_type
)
2035 f1
= lookup_sfield (OMP_CLAUSE_DECL (c1
), ctx
);
2036 f2
= lookup_sfield (OMP_CLAUSE_DECL (c2
), ctx
);
2037 p
= &TYPE_FIELDS (ctx
->srecord_type
);
2039 if (*p
== f1
|| *p
== f2
)
2040 *p
= DECL_CHAIN (*p
);
2042 p
= &DECL_CHAIN (*p
);
2043 DECL_CHAIN (f1
) = f2
;
2044 DECL_CHAIN (f2
) = TYPE_FIELDS (ctx
->srecord_type
);
2045 TYPE_FIELDS (ctx
->srecord_type
) = f1
;
2048 layout_type (ctx
->record_type
);
2049 fixup_child_record_type (ctx
);
2050 if (ctx
->srecord_type
)
2051 layout_type (ctx
->srecord_type
);
2052 tree t
= fold_convert_loc (loc
, long_integer_type_node
,
2053 TYPE_SIZE_UNIT (ctx
->record_type
));
2054 if (TREE_CODE (t
) != INTEGER_CST
)
2056 t
= unshare_expr (t
);
2057 walk_tree (&t
, finish_taskreg_remap
, ctx
, NULL
);
2059 gimple_omp_task_set_arg_size (ctx
->stmt
, t
);
2060 t
= build_int_cst (long_integer_type_node
,
2061 TYPE_ALIGN_UNIT (ctx
->record_type
));
2062 gimple_omp_task_set_arg_align (ctx
->stmt
, t
);
2066 /* Find the enclosing offload context. */
2068 static omp_context
*
2069 enclosing_target_ctx (omp_context
*ctx
)
2071 for (; ctx
; ctx
= ctx
->outer
)
2072 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TARGET
)
2078 /* Return true if ctx is part of an oacc kernels region. */
2081 ctx_in_oacc_kernels_region (omp_context
*ctx
)
2083 for (;ctx
!= NULL
; ctx
= ctx
->outer
)
2085 gimple
*stmt
= ctx
->stmt
;
2086 if (gimple_code (stmt
) == GIMPLE_OMP_TARGET
2087 && gimple_omp_target_kind (stmt
) == GF_OMP_TARGET_KIND_OACC_KERNELS
)
2094 /* Check the parallelism clauses inside a kernels regions.
2095 Until kernels handling moves to use the same loop indirection
2096 scheme as parallel, we need to do this checking early. */
2099 check_oacc_kernel_gwv (gomp_for
*stmt
, omp_context
*ctx
)
2101 bool checking
= true;
2102 unsigned outer_mask
= 0;
2103 unsigned this_mask
= 0;
2104 bool has_seq
= false, has_auto
= false;
2107 outer_mask
= check_oacc_kernel_gwv (NULL
, ctx
->outer
);
2111 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_FOR
)
2113 stmt
= as_a
<gomp_for
*> (ctx
->stmt
);
2116 for (tree c
= gimple_omp_for_clauses (stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
2118 switch (OMP_CLAUSE_CODE (c
))
2120 case OMP_CLAUSE_GANG
:
2121 this_mask
|= GOMP_DIM_MASK (GOMP_DIM_GANG
);
2123 case OMP_CLAUSE_WORKER
:
2124 this_mask
|= GOMP_DIM_MASK (GOMP_DIM_WORKER
);
2126 case OMP_CLAUSE_VECTOR
:
2127 this_mask
|= GOMP_DIM_MASK (GOMP_DIM_VECTOR
);
2129 case OMP_CLAUSE_SEQ
:
2132 case OMP_CLAUSE_AUTO
:
2142 if (has_seq
&& (this_mask
|| has_auto
))
2143 error_at (gimple_location (stmt
), "%<seq%> overrides other"
2144 " OpenACC loop specifiers");
2145 else if (has_auto
&& this_mask
)
2146 error_at (gimple_location (stmt
), "%<auto%> conflicts with other"
2147 " OpenACC loop specifiers");
2149 if (this_mask
& outer_mask
)
2150 error_at (gimple_location (stmt
), "inner loop uses same"
2151 " OpenACC parallelism as containing loop");
2154 return outer_mask
| this_mask
;
2157 /* Scan a GIMPLE_OMP_FOR. */
2159 static omp_context
*
2160 scan_omp_for (gomp_for
*stmt
, omp_context
*outer_ctx
)
2164 tree clauses
= gimple_omp_for_clauses (stmt
);
2166 ctx
= new_omp_context (stmt
, outer_ctx
);
2168 if (is_gimple_omp_oacc (stmt
))
2170 omp_context
*tgt
= enclosing_target_ctx (outer_ctx
);
2172 if (!tgt
|| is_oacc_parallel (tgt
))
2173 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
2175 char const *check
= NULL
;
2177 switch (OMP_CLAUSE_CODE (c
))
2179 case OMP_CLAUSE_GANG
:
2183 case OMP_CLAUSE_WORKER
:
2187 case OMP_CLAUSE_VECTOR
:
2195 if (check
&& OMP_CLAUSE_OPERAND (c
, 0))
2196 error_at (gimple_location (stmt
),
2197 "argument not permitted on %qs clause in"
2198 " OpenACC %<parallel%>", check
);
2201 if (tgt
&& is_oacc_kernels (tgt
))
2203 /* Strip out reductions, as they are not handled yet. */
2204 tree
*prev_ptr
= &clauses
;
2206 while (tree probe
= *prev_ptr
)
2208 tree
*next_ptr
= &OMP_CLAUSE_CHAIN (probe
);
2210 if (OMP_CLAUSE_CODE (probe
) == OMP_CLAUSE_REDUCTION
)
2211 *prev_ptr
= *next_ptr
;
2213 prev_ptr
= next_ptr
;
2216 gimple_omp_for_set_clauses (stmt
, clauses
);
2217 check_oacc_kernel_gwv (stmt
, ctx
);
2221 scan_sharing_clauses (clauses
, ctx
);
2223 scan_omp (gimple_omp_for_pre_body_ptr (stmt
), ctx
);
2224 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2226 scan_omp_op (gimple_omp_for_index_ptr (stmt
, i
), ctx
);
2227 scan_omp_op (gimple_omp_for_initial_ptr (stmt
, i
), ctx
);
2228 scan_omp_op (gimple_omp_for_final_ptr (stmt
, i
), ctx
);
2229 scan_omp_op (gimple_omp_for_incr_ptr (stmt
, i
), ctx
);
2231 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
2235 /* Duplicate #pragma omp simd, one for SIMT, another one for SIMD. */
2238 scan_omp_simd (gimple_stmt_iterator
*gsi
, gomp_for
*stmt
,
2239 omp_context
*outer_ctx
)
2241 gbind
*bind
= gimple_build_bind (NULL
, NULL
, NULL
);
2242 gsi_replace (gsi
, bind
, false);
2243 gimple_seq seq
= NULL
;
2244 gimple
*g
= gimple_build_call_internal (IFN_GOMP_USE_SIMT
, 0);
2245 tree cond
= create_tmp_var_raw (integer_type_node
);
2246 DECL_CONTEXT (cond
) = current_function_decl
;
2247 DECL_SEEN_IN_BIND_EXPR_P (cond
) = 1;
2248 gimple_bind_set_vars (bind
, cond
);
2249 gimple_call_set_lhs (g
, cond
);
2250 gimple_seq_add_stmt (&seq
, g
);
2251 tree lab1
= create_artificial_label (UNKNOWN_LOCATION
);
2252 tree lab2
= create_artificial_label (UNKNOWN_LOCATION
);
2253 tree lab3
= create_artificial_label (UNKNOWN_LOCATION
);
2254 g
= gimple_build_cond (NE_EXPR
, cond
, integer_zero_node
, lab1
, lab2
);
2255 gimple_seq_add_stmt (&seq
, g
);
2256 g
= gimple_build_label (lab1
);
2257 gimple_seq_add_stmt (&seq
, g
);
2258 gimple_seq new_seq
= copy_gimple_seq_and_replace_locals (stmt
);
2259 gomp_for
*new_stmt
= as_a
<gomp_for
*> (new_seq
);
2260 tree clause
= build_omp_clause (gimple_location (stmt
), OMP_CLAUSE__SIMT_
);
2261 OMP_CLAUSE_CHAIN (clause
) = gimple_omp_for_clauses (new_stmt
);
2262 gimple_omp_for_set_clauses (new_stmt
, clause
);
2263 gimple_seq_add_stmt (&seq
, new_stmt
);
2264 g
= gimple_build_goto (lab3
);
2265 gimple_seq_add_stmt (&seq
, g
);
2266 g
= gimple_build_label (lab2
);
2267 gimple_seq_add_stmt (&seq
, g
);
2268 gimple_seq_add_stmt (&seq
, stmt
);
2269 g
= gimple_build_label (lab3
);
2270 gimple_seq_add_stmt (&seq
, g
);
2271 gimple_bind_set_body (bind
, seq
);
2273 scan_omp_for (new_stmt
, outer_ctx
);
2274 scan_omp_for (stmt
, outer_ctx
)->simt_stmt
= new_stmt
;
2277 /* Scan an OpenMP sections directive. */
2280 scan_omp_sections (gomp_sections
*stmt
, omp_context
*outer_ctx
)
2284 ctx
= new_omp_context (stmt
, outer_ctx
);
2285 scan_sharing_clauses (gimple_omp_sections_clauses (stmt
), ctx
);
2286 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
2289 /* Scan an OpenMP single directive. */
2292 scan_omp_single (gomp_single
*stmt
, omp_context
*outer_ctx
)
2297 ctx
= new_omp_context (stmt
, outer_ctx
);
2298 ctx
->field_map
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
2299 ctx
->record_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
2300 name
= create_tmp_var_name (".omp_copy_s");
2301 name
= build_decl (gimple_location (stmt
),
2302 TYPE_DECL
, name
, ctx
->record_type
);
2303 TYPE_NAME (ctx
->record_type
) = name
;
2305 scan_sharing_clauses (gimple_omp_single_clauses (stmt
), ctx
);
2306 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
2308 if (TYPE_FIELDS (ctx
->record_type
) == NULL
)
2309 ctx
->record_type
= NULL
;
2311 layout_type (ctx
->record_type
);
2314 /* Return true if the CLAUSES of an omp target guarantee that the base pointers
2315 used in the corresponding offloaded function are restrict. */
2318 omp_target_base_pointers_restrict_p (tree clauses
)
2320 /* The analysis relies on the GOMP_MAP_FORCE_* mapping kinds, which are only
2322 if (flag_openacc
== 0)
2325 /* I. Basic example:
2329 unsigned int a[2], b[2];
2331 #pragma acc kernels \
2340 After gimplification, we have:
2342 #pragma omp target oacc_kernels \
2343 map(force_from:a [len: 8]) \
2344 map(force_from:b [len: 8])
2350 Because both mappings have the force prefix, we know that they will be
2351 allocated when calling the corresponding offloaded function, which means we
2352 can mark the base pointers for a and b in the offloaded function as
2356 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
2358 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
2361 switch (OMP_CLAUSE_MAP_KIND (c
))
2363 case GOMP_MAP_FORCE_ALLOC
:
2364 case GOMP_MAP_FORCE_TO
:
2365 case GOMP_MAP_FORCE_FROM
:
2366 case GOMP_MAP_FORCE_TOFROM
:
2376 /* Scan a GIMPLE_OMP_TARGET. */
2379 scan_omp_target (gomp_target
*stmt
, omp_context
*outer_ctx
)
2383 bool offloaded
= is_gimple_omp_offloaded (stmt
);
2384 tree clauses
= gimple_omp_target_clauses (stmt
);
2386 ctx
= new_omp_context (stmt
, outer_ctx
);
2387 ctx
->field_map
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
2388 ctx
->record_type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
2389 name
= create_tmp_var_name (".omp_data_t");
2390 name
= build_decl (gimple_location (stmt
),
2391 TYPE_DECL
, name
, ctx
->record_type
);
2392 DECL_ARTIFICIAL (name
) = 1;
2393 DECL_NAMELESS (name
) = 1;
2394 TYPE_NAME (ctx
->record_type
) = name
;
2395 TYPE_ARTIFICIAL (ctx
->record_type
) = 1;
2397 bool base_pointers_restrict
= false;
2400 create_omp_child_function (ctx
, false);
2401 gimple_omp_target_set_child_fn (stmt
, ctx
->cb
.dst_fn
);
2403 base_pointers_restrict
= omp_target_base_pointers_restrict_p (clauses
);
2404 if (base_pointers_restrict
2405 && dump_file
&& (dump_flags
& TDF_DETAILS
))
2407 "Base pointers in offloaded function are restrict\n");
2410 scan_sharing_clauses (clauses
, ctx
, base_pointers_restrict
);
2411 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
2413 if (TYPE_FIELDS (ctx
->record_type
) == NULL
)
2414 ctx
->record_type
= ctx
->receiver_decl
= NULL
;
2417 TYPE_FIELDS (ctx
->record_type
)
2418 = nreverse (TYPE_FIELDS (ctx
->record_type
));
2421 unsigned int align
= DECL_ALIGN (TYPE_FIELDS (ctx
->record_type
));
2422 for (tree field
= TYPE_FIELDS (ctx
->record_type
);
2424 field
= DECL_CHAIN (field
))
2425 gcc_assert (DECL_ALIGN (field
) == align
);
2427 layout_type (ctx
->record_type
);
2429 fixup_child_record_type (ctx
);
2433 /* Scan an OpenMP teams directive. */
2436 scan_omp_teams (gomp_teams
*stmt
, omp_context
*outer_ctx
)
2438 omp_context
*ctx
= new_omp_context (stmt
, outer_ctx
);
2439 scan_sharing_clauses (gimple_omp_teams_clauses (stmt
), ctx
);
2440 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
2443 /* Check nesting restrictions. */
2445 check_omp_nesting_restrictions (gimple
*stmt
, omp_context
*ctx
)
2449 if (ctx
&& gimple_code (ctx
->stmt
) == GIMPLE_OMP_GRID_BODY
)
2450 /* GRID_BODY is an artificial construct, nesting rules will be checked in
2451 the original copy of its contents. */
2454 /* No nesting of non-OpenACC STMT (that is, an OpenMP one, or a GOMP builtin)
2455 inside an OpenACC CTX. */
2456 if (!(is_gimple_omp (stmt
)
2457 && is_gimple_omp_oacc (stmt
))
2458 /* Except for atomic codes that we share with OpenMP. */
2459 && !(gimple_code (stmt
) == GIMPLE_OMP_ATOMIC_LOAD
2460 || gimple_code (stmt
) == GIMPLE_OMP_ATOMIC_STORE
))
2462 if (oacc_get_fn_attrib (cfun
->decl
) != NULL
)
2464 error_at (gimple_location (stmt
),
2465 "non-OpenACC construct inside of OpenACC routine");
2469 for (omp_context
*octx
= ctx
; octx
!= NULL
; octx
= octx
->outer
)
2470 if (is_gimple_omp (octx
->stmt
)
2471 && is_gimple_omp_oacc (octx
->stmt
))
2473 error_at (gimple_location (stmt
),
2474 "non-OpenACC construct inside of OpenACC region");
2481 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
2482 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
)
2485 if (gimple_code (stmt
) == GIMPLE_OMP_ORDERED
)
2487 c
= gimple_omp_ordered_clauses (as_a
<gomp_ordered
*> (stmt
));
2488 if (omp_find_clause (c
, OMP_CLAUSE_SIMD
))
2490 if (omp_find_clause (c
, OMP_CLAUSE_THREADS
)
2491 && (ctx
->outer
== NULL
2492 || !gimple_omp_for_combined_into_p (ctx
->stmt
)
2493 || gimple_code (ctx
->outer
->stmt
) != GIMPLE_OMP_FOR
2494 || (gimple_omp_for_kind (ctx
->outer
->stmt
)
2495 != GF_OMP_FOR_KIND_FOR
)
2496 || !gimple_omp_for_combined_p (ctx
->outer
->stmt
)))
2498 error_at (gimple_location (stmt
),
2499 "%<ordered simd threads%> must be closely "
2500 "nested inside of %<for simd%> region");
2506 error_at (gimple_location (stmt
),
2507 "OpenMP constructs other than %<#pragma omp ordered simd%>"
2508 " may not be nested inside %<simd%> region");
2511 else if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TEAMS
)
2513 if ((gimple_code (stmt
) != GIMPLE_OMP_FOR
2514 || ((gimple_omp_for_kind (stmt
) != GF_OMP_FOR_KIND_DISTRIBUTE
)
2515 && (gimple_omp_for_kind (stmt
) != GF_OMP_FOR_KIND_GRID_LOOP
)))
2516 && gimple_code (stmt
) != GIMPLE_OMP_PARALLEL
)
2518 error_at (gimple_location (stmt
),
2519 "only %<distribute%> or %<parallel%> regions are "
2520 "allowed to be strictly nested inside %<teams%> "
2526 switch (gimple_code (stmt
))
2528 case GIMPLE_OMP_FOR
:
2529 if (gimple_omp_for_kind (stmt
) & GF_OMP_FOR_SIMD
)
2531 if (gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_DISTRIBUTE
)
2533 if (ctx
!= NULL
&& gimple_code (ctx
->stmt
) != GIMPLE_OMP_TEAMS
)
2535 error_at (gimple_location (stmt
),
2536 "%<distribute%> region must be strictly nested "
2537 "inside %<teams%> construct");
2542 /* We split taskloop into task and nested taskloop in it. */
2543 if (gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_TASKLOOP
)
2545 if (gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_OACC_LOOP
)
2550 switch (gimple_code (ctx
->stmt
))
2552 case GIMPLE_OMP_FOR
:
2553 ok
= (gimple_omp_for_kind (ctx
->stmt
)
2554 == GF_OMP_FOR_KIND_OACC_LOOP
);
2557 case GIMPLE_OMP_TARGET
:
2558 switch (gimple_omp_target_kind (ctx
->stmt
))
2560 case GF_OMP_TARGET_KIND_OACC_PARALLEL
:
2561 case GF_OMP_TARGET_KIND_OACC_KERNELS
:
2572 else if (oacc_get_fn_attrib (current_function_decl
))
2576 error_at (gimple_location (stmt
),
2577 "OpenACC loop directive must be associated with"
2578 " an OpenACC compute region");
2584 if (is_gimple_call (stmt
)
2585 && (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2586 == BUILT_IN_GOMP_CANCEL
2587 || DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2588 == BUILT_IN_GOMP_CANCELLATION_POINT
))
2590 const char *bad
= NULL
;
2591 const char *kind
= NULL
;
2592 const char *construct
2593 = (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2594 == BUILT_IN_GOMP_CANCEL
)
2595 ? "#pragma omp cancel"
2596 : "#pragma omp cancellation point";
2599 error_at (gimple_location (stmt
), "orphaned %qs construct",
2603 switch (tree_fits_shwi_p (gimple_call_arg (stmt
, 0))
2604 ? tree_to_shwi (gimple_call_arg (stmt
, 0))
2608 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_PARALLEL
)
2609 bad
= "#pragma omp parallel";
2610 else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2611 == BUILT_IN_GOMP_CANCEL
2612 && !integer_zerop (gimple_call_arg (stmt
, 1)))
2613 ctx
->cancellable
= true;
2617 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_FOR
2618 || gimple_omp_for_kind (ctx
->stmt
) != GF_OMP_FOR_KIND_FOR
)
2619 bad
= "#pragma omp for";
2620 else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2621 == BUILT_IN_GOMP_CANCEL
2622 && !integer_zerop (gimple_call_arg (stmt
, 1)))
2624 ctx
->cancellable
= true;
2625 if (omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
2627 warning_at (gimple_location (stmt
), 0,
2628 "%<#pragma omp cancel for%> inside "
2629 "%<nowait%> for construct");
2630 if (omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
2631 OMP_CLAUSE_ORDERED
))
2632 warning_at (gimple_location (stmt
), 0,
2633 "%<#pragma omp cancel for%> inside "
2634 "%<ordered%> for construct");
2639 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_SECTIONS
2640 && gimple_code (ctx
->stmt
) != GIMPLE_OMP_SECTION
)
2641 bad
= "#pragma omp sections";
2642 else if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2643 == BUILT_IN_GOMP_CANCEL
2644 && !integer_zerop (gimple_call_arg (stmt
, 1)))
2646 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_SECTIONS
)
2648 ctx
->cancellable
= true;
2649 if (omp_find_clause (gimple_omp_sections_clauses
2652 warning_at (gimple_location (stmt
), 0,
2653 "%<#pragma omp cancel sections%> inside "
2654 "%<nowait%> sections construct");
2658 gcc_assert (ctx
->outer
2659 && gimple_code (ctx
->outer
->stmt
)
2660 == GIMPLE_OMP_SECTIONS
);
2661 ctx
->outer
->cancellable
= true;
2662 if (omp_find_clause (gimple_omp_sections_clauses
2665 warning_at (gimple_location (stmt
), 0,
2666 "%<#pragma omp cancel sections%> inside "
2667 "%<nowait%> sections construct");
2673 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_TASK
)
2674 bad
= "#pragma omp task";
2677 for (omp_context
*octx
= ctx
->outer
;
2678 octx
; octx
= octx
->outer
)
2680 switch (gimple_code (octx
->stmt
))
2682 case GIMPLE_OMP_TASKGROUP
:
2684 case GIMPLE_OMP_TARGET
:
2685 if (gimple_omp_target_kind (octx
->stmt
)
2686 != GF_OMP_TARGET_KIND_REGION
)
2689 case GIMPLE_OMP_PARALLEL
:
2690 case GIMPLE_OMP_TEAMS
:
2691 error_at (gimple_location (stmt
),
2692 "%<%s taskgroup%> construct not closely "
2693 "nested inside of %<taskgroup%> region",
2701 ctx
->cancellable
= true;
2706 error_at (gimple_location (stmt
), "invalid arguments");
2711 error_at (gimple_location (stmt
),
2712 "%<%s %s%> construct not closely nested inside of %qs",
2713 construct
, kind
, bad
);
2718 case GIMPLE_OMP_SECTIONS
:
2719 case GIMPLE_OMP_SINGLE
:
2720 for (; ctx
!= NULL
; ctx
= ctx
->outer
)
2721 switch (gimple_code (ctx
->stmt
))
2723 case GIMPLE_OMP_FOR
:
2724 if (gimple_omp_for_kind (ctx
->stmt
) != GF_OMP_FOR_KIND_FOR
2725 && gimple_omp_for_kind (ctx
->stmt
) != GF_OMP_FOR_KIND_TASKLOOP
)
2728 case GIMPLE_OMP_SECTIONS
:
2729 case GIMPLE_OMP_SINGLE
:
2730 case GIMPLE_OMP_ORDERED
:
2731 case GIMPLE_OMP_MASTER
:
2732 case GIMPLE_OMP_TASK
:
2733 case GIMPLE_OMP_CRITICAL
:
2734 if (is_gimple_call (stmt
))
2736 if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt
))
2737 != BUILT_IN_GOMP_BARRIER
)
2739 error_at (gimple_location (stmt
),
2740 "barrier region may not be closely nested inside "
2741 "of work-sharing, %<critical%>, %<ordered%>, "
2742 "%<master%>, explicit %<task%> or %<taskloop%> "
2746 error_at (gimple_location (stmt
),
2747 "work-sharing region may not be closely nested inside "
2748 "of work-sharing, %<critical%>, %<ordered%>, "
2749 "%<master%>, explicit %<task%> or %<taskloop%> region");
2751 case GIMPLE_OMP_PARALLEL
:
2752 case GIMPLE_OMP_TEAMS
:
2754 case GIMPLE_OMP_TARGET
:
2755 if (gimple_omp_target_kind (ctx
->stmt
)
2756 == GF_OMP_TARGET_KIND_REGION
)
2763 case GIMPLE_OMP_MASTER
:
2764 for (; ctx
!= NULL
; ctx
= ctx
->outer
)
2765 switch (gimple_code (ctx
->stmt
))
2767 case GIMPLE_OMP_FOR
:
2768 if (gimple_omp_for_kind (ctx
->stmt
) != GF_OMP_FOR_KIND_FOR
2769 && gimple_omp_for_kind (ctx
->stmt
) != GF_OMP_FOR_KIND_TASKLOOP
)
2772 case GIMPLE_OMP_SECTIONS
:
2773 case GIMPLE_OMP_SINGLE
:
2774 case GIMPLE_OMP_TASK
:
2775 error_at (gimple_location (stmt
),
2776 "%<master%> region may not be closely nested inside "
2777 "of work-sharing, explicit %<task%> or %<taskloop%> "
2780 case GIMPLE_OMP_PARALLEL
:
2781 case GIMPLE_OMP_TEAMS
:
2783 case GIMPLE_OMP_TARGET
:
2784 if (gimple_omp_target_kind (ctx
->stmt
)
2785 == GF_OMP_TARGET_KIND_REGION
)
2792 case GIMPLE_OMP_TASK
:
2793 for (c
= gimple_omp_task_clauses (stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
2794 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
2795 && (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
2796 || OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
))
2798 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_KIND (c
);
2799 error_at (OMP_CLAUSE_LOCATION (c
),
2800 "%<depend(%s)%> is only allowed in %<omp ordered%>",
2801 kind
== OMP_CLAUSE_DEPEND_SOURCE
? "source" : "sink");
2805 case GIMPLE_OMP_ORDERED
:
2806 for (c
= gimple_omp_ordered_clauses (as_a
<gomp_ordered
*> (stmt
));
2807 c
; c
= OMP_CLAUSE_CHAIN (c
))
2809 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
2811 gcc_assert (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREADS
2812 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SIMD
);
2815 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_KIND (c
);
2816 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
2817 || kind
== OMP_CLAUSE_DEPEND_SINK
)
2820 /* Look for containing ordered(N) loop. */
2822 || gimple_code (ctx
->stmt
) != GIMPLE_OMP_FOR
2824 = omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
2825 OMP_CLAUSE_ORDERED
)) == NULL_TREE
)
2827 error_at (OMP_CLAUSE_LOCATION (c
),
2828 "%<ordered%> construct with %<depend%> clause "
2829 "must be closely nested inside an %<ordered%> "
2833 else if (OMP_CLAUSE_ORDERED_EXPR (oclause
) == NULL_TREE
)
2835 error_at (OMP_CLAUSE_LOCATION (c
),
2836 "%<ordered%> construct with %<depend%> clause "
2837 "must be closely nested inside a loop with "
2838 "%<ordered%> clause with a parameter");
2844 error_at (OMP_CLAUSE_LOCATION (c
),
2845 "invalid depend kind in omp %<ordered%> %<depend%>");
2849 c
= gimple_omp_ordered_clauses (as_a
<gomp_ordered
*> (stmt
));
2850 if (omp_find_clause (c
, OMP_CLAUSE_SIMD
))
2852 /* ordered simd must be closely nested inside of simd region,
2853 and simd region must not encounter constructs other than
2854 ordered simd, therefore ordered simd may be either orphaned,
2855 or ctx->stmt must be simd. The latter case is handled already
2859 error_at (gimple_location (stmt
),
2860 "%<ordered%> %<simd%> must be closely nested inside "
2865 for (; ctx
!= NULL
; ctx
= ctx
->outer
)
2866 switch (gimple_code (ctx
->stmt
))
2868 case GIMPLE_OMP_CRITICAL
:
2869 case GIMPLE_OMP_TASK
:
2870 case GIMPLE_OMP_ORDERED
:
2871 ordered_in_taskloop
:
2872 error_at (gimple_location (stmt
),
2873 "%<ordered%> region may not be closely nested inside "
2874 "of %<critical%>, %<ordered%>, explicit %<task%> or "
2875 "%<taskloop%> region");
2877 case GIMPLE_OMP_FOR
:
2878 if (gimple_omp_for_kind (ctx
->stmt
) == GF_OMP_FOR_KIND_TASKLOOP
)
2879 goto ordered_in_taskloop
;
2880 if (omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
2881 OMP_CLAUSE_ORDERED
) == NULL
)
2883 error_at (gimple_location (stmt
),
2884 "%<ordered%> region must be closely nested inside "
2885 "a loop region with an %<ordered%> clause");
2889 case GIMPLE_OMP_TARGET
:
2890 if (gimple_omp_target_kind (ctx
->stmt
)
2891 != GF_OMP_TARGET_KIND_REGION
)
2894 case GIMPLE_OMP_PARALLEL
:
2895 case GIMPLE_OMP_TEAMS
:
2896 error_at (gimple_location (stmt
),
2897 "%<ordered%> region must be closely nested inside "
2898 "a loop region with an %<ordered%> clause");
2904 case GIMPLE_OMP_CRITICAL
:
2907 = gimple_omp_critical_name (as_a
<gomp_critical
*> (stmt
));
2908 for (; ctx
!= NULL
; ctx
= ctx
->outer
)
2909 if (gomp_critical
*other_crit
2910 = dyn_cast
<gomp_critical
*> (ctx
->stmt
))
2911 if (this_stmt_name
== gimple_omp_critical_name (other_crit
))
2913 error_at (gimple_location (stmt
),
2914 "%<critical%> region may not be nested inside "
2915 "a %<critical%> region with the same name");
2920 case GIMPLE_OMP_TEAMS
:
2922 || gimple_code (ctx
->stmt
) != GIMPLE_OMP_TARGET
2923 || gimple_omp_target_kind (ctx
->stmt
) != GF_OMP_TARGET_KIND_REGION
)
2925 error_at (gimple_location (stmt
),
2926 "%<teams%> construct not closely nested inside of "
2927 "%<target%> construct");
2931 case GIMPLE_OMP_TARGET
:
2932 for (c
= gimple_omp_target_clauses (stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
2933 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
2934 && (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
2935 || OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
))
2937 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_KIND (c
);
2938 error_at (OMP_CLAUSE_LOCATION (c
),
2939 "%<depend(%s)%> is only allowed in %<omp ordered%>",
2940 kind
== OMP_CLAUSE_DEPEND_SOURCE
? "source" : "sink");
2943 if (is_gimple_omp_offloaded (stmt
)
2944 && oacc_get_fn_attrib (cfun
->decl
) != NULL
)
2946 error_at (gimple_location (stmt
),
2947 "OpenACC region inside of OpenACC routine, nested "
2948 "parallelism not supported yet");
2951 for (; ctx
!= NULL
; ctx
= ctx
->outer
)
2953 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_TARGET
)
2955 if (is_gimple_omp (stmt
)
2956 && is_gimple_omp_oacc (stmt
)
2957 && is_gimple_omp (ctx
->stmt
))
2959 error_at (gimple_location (stmt
),
2960 "OpenACC construct inside of non-OpenACC region");
2966 const char *stmt_name
, *ctx_stmt_name
;
2967 switch (gimple_omp_target_kind (stmt
))
2969 case GF_OMP_TARGET_KIND_REGION
: stmt_name
= "target"; break;
2970 case GF_OMP_TARGET_KIND_DATA
: stmt_name
= "target data"; break;
2971 case GF_OMP_TARGET_KIND_UPDATE
: stmt_name
= "target update"; break;
2972 case GF_OMP_TARGET_KIND_ENTER_DATA
:
2973 stmt_name
= "target enter data"; break;
2974 case GF_OMP_TARGET_KIND_EXIT_DATA
:
2975 stmt_name
= "target exit data"; break;
2976 case GF_OMP_TARGET_KIND_OACC_PARALLEL
: stmt_name
= "parallel"; break;
2977 case GF_OMP_TARGET_KIND_OACC_KERNELS
: stmt_name
= "kernels"; break;
2978 case GF_OMP_TARGET_KIND_OACC_DATA
: stmt_name
= "data"; break;
2979 case GF_OMP_TARGET_KIND_OACC_UPDATE
: stmt_name
= "update"; break;
2980 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA
:
2981 stmt_name
= "enter/exit data"; break;
2982 case GF_OMP_TARGET_KIND_OACC_HOST_DATA
: stmt_name
= "host_data";
2984 default: gcc_unreachable ();
2986 switch (gimple_omp_target_kind (ctx
->stmt
))
2988 case GF_OMP_TARGET_KIND_REGION
: ctx_stmt_name
= "target"; break;
2989 case GF_OMP_TARGET_KIND_DATA
: ctx_stmt_name
= "target data"; break;
2990 case GF_OMP_TARGET_KIND_OACC_PARALLEL
:
2991 ctx_stmt_name
= "parallel"; break;
2992 case GF_OMP_TARGET_KIND_OACC_KERNELS
:
2993 ctx_stmt_name
= "kernels"; break;
2994 case GF_OMP_TARGET_KIND_OACC_DATA
: ctx_stmt_name
= "data"; break;
2995 case GF_OMP_TARGET_KIND_OACC_HOST_DATA
:
2996 ctx_stmt_name
= "host_data"; break;
2997 default: gcc_unreachable ();
3000 /* OpenACC/OpenMP mismatch? */
3001 if (is_gimple_omp_oacc (stmt
)
3002 != is_gimple_omp_oacc (ctx
->stmt
))
3004 error_at (gimple_location (stmt
),
3005 "%s %qs construct inside of %s %qs region",
3006 (is_gimple_omp_oacc (stmt
)
3007 ? "OpenACC" : "OpenMP"), stmt_name
,
3008 (is_gimple_omp_oacc (ctx
->stmt
)
3009 ? "OpenACC" : "OpenMP"), ctx_stmt_name
);
3012 if (is_gimple_omp_offloaded (ctx
->stmt
))
3014 /* No GIMPLE_OMP_TARGET inside offloaded OpenACC CTX. */
3015 if (is_gimple_omp_oacc (ctx
->stmt
))
3017 error_at (gimple_location (stmt
),
3018 "%qs construct inside of %qs region",
3019 stmt_name
, ctx_stmt_name
);
3024 warning_at (gimple_location (stmt
), 0,
3025 "%qs construct inside of %qs region",
3026 stmt_name
, ctx_stmt_name
);
3038 /* Helper function scan_omp.
3040 Callback for walk_tree or operators in walk_gimple_stmt used to
3041 scan for OMP directives in TP. */
3044 scan_omp_1_op (tree
*tp
, int *walk_subtrees
, void *data
)
3046 struct walk_stmt_info
*wi
= (struct walk_stmt_info
*) data
;
3047 omp_context
*ctx
= (omp_context
*) wi
->info
;
3050 switch (TREE_CODE (t
))
3058 tree repl
= remap_decl (t
, &ctx
->cb
);
3059 gcc_checking_assert (TREE_CODE (repl
) != ERROR_MARK
);
3065 if (ctx
&& TYPE_P (t
))
3066 *tp
= remap_type (t
, &ctx
->cb
);
3067 else if (!DECL_P (t
))
3072 tree tem
= remap_type (TREE_TYPE (t
), &ctx
->cb
);
3073 if (tem
!= TREE_TYPE (t
))
3075 if (TREE_CODE (t
) == INTEGER_CST
)
3076 *tp
= wide_int_to_tree (tem
, t
);
3078 TREE_TYPE (t
) = tem
;
3088 /* Return true if FNDECL is a setjmp or a longjmp. */
3091 setjmp_or_longjmp_p (const_tree fndecl
)
3093 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
3094 && (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_SETJMP
3095 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_LONGJMP
))
3098 tree declname
= DECL_NAME (fndecl
);
3101 const char *name
= IDENTIFIER_POINTER (declname
);
3102 return !strcmp (name
, "setjmp") || !strcmp (name
, "longjmp");
3106 /* Helper function for scan_omp.
3108 Callback for walk_gimple_stmt used to scan for OMP directives in
3109 the current statement in GSI. */
3112 scan_omp_1_stmt (gimple_stmt_iterator
*gsi
, bool *handled_ops_p
,
3113 struct walk_stmt_info
*wi
)
3115 gimple
*stmt
= gsi_stmt (*gsi
);
3116 omp_context
*ctx
= (omp_context
*) wi
->info
;
3118 if (gimple_has_location (stmt
))
3119 input_location
= gimple_location (stmt
);
3121 /* Check the nesting restrictions. */
3122 bool remove
= false;
3123 if (is_gimple_omp (stmt
))
3124 remove
= !check_omp_nesting_restrictions (stmt
, ctx
);
3125 else if (is_gimple_call (stmt
))
3127 tree fndecl
= gimple_call_fndecl (stmt
);
3130 if (setjmp_or_longjmp_p (fndecl
)
3132 && gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
3133 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
)
3136 error_at (gimple_location (stmt
),
3137 "setjmp/longjmp inside simd construct");
3139 else if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
3140 switch (DECL_FUNCTION_CODE (fndecl
))
3142 case BUILT_IN_GOMP_BARRIER
:
3143 case BUILT_IN_GOMP_CANCEL
:
3144 case BUILT_IN_GOMP_CANCELLATION_POINT
:
3145 case BUILT_IN_GOMP_TASKYIELD
:
3146 case BUILT_IN_GOMP_TASKWAIT
:
3147 case BUILT_IN_GOMP_TASKGROUP_START
:
3148 case BUILT_IN_GOMP_TASKGROUP_END
:
3149 remove
= !check_omp_nesting_restrictions (stmt
, ctx
);
3158 stmt
= gimple_build_nop ();
3159 gsi_replace (gsi
, stmt
, false);
3162 *handled_ops_p
= true;
3164 switch (gimple_code (stmt
))
3166 case GIMPLE_OMP_PARALLEL
:
3167 taskreg_nesting_level
++;
3168 scan_omp_parallel (gsi
, ctx
);
3169 taskreg_nesting_level
--;
3172 case GIMPLE_OMP_TASK
:
3173 taskreg_nesting_level
++;
3174 scan_omp_task (gsi
, ctx
);
3175 taskreg_nesting_level
--;
3178 case GIMPLE_OMP_FOR
:
3179 if (((gimple_omp_for_kind (as_a
<gomp_for
*> (stmt
))
3180 & GF_OMP_FOR_KIND_MASK
) == GF_OMP_FOR_KIND_SIMD
)
3181 && omp_maybe_offloaded_ctx (ctx
)
3182 && omp_max_simt_vf ())
3183 scan_omp_simd (gsi
, as_a
<gomp_for
*> (stmt
), ctx
);
3185 scan_omp_for (as_a
<gomp_for
*> (stmt
), ctx
);
3188 case GIMPLE_OMP_SECTIONS
:
3189 scan_omp_sections (as_a
<gomp_sections
*> (stmt
), ctx
);
3192 case GIMPLE_OMP_SINGLE
:
3193 scan_omp_single (as_a
<gomp_single
*> (stmt
), ctx
);
3196 case GIMPLE_OMP_SECTION
:
3197 case GIMPLE_OMP_MASTER
:
3198 case GIMPLE_OMP_TASKGROUP
:
3199 case GIMPLE_OMP_ORDERED
:
3200 case GIMPLE_OMP_CRITICAL
:
3201 case GIMPLE_OMP_GRID_BODY
:
3202 ctx
= new_omp_context (stmt
, ctx
);
3203 scan_omp (gimple_omp_body_ptr (stmt
), ctx
);
3206 case GIMPLE_OMP_TARGET
:
3207 scan_omp_target (as_a
<gomp_target
*> (stmt
), ctx
);
3210 case GIMPLE_OMP_TEAMS
:
3211 scan_omp_teams (as_a
<gomp_teams
*> (stmt
), ctx
);
3218 *handled_ops_p
= false;
3220 for (var
= gimple_bind_vars (as_a
<gbind
*> (stmt
));
3222 var
= DECL_CHAIN (var
))
3223 insert_decl_map (&ctx
->cb
, var
, var
);
3227 *handled_ops_p
= false;
3235 /* Scan all the statements starting at the current statement. CTX
3236 contains context information about the OMP directives and
3237 clauses found during the scan. */
3240 scan_omp (gimple_seq
*body_p
, omp_context
*ctx
)
3242 location_t saved_location
;
3243 struct walk_stmt_info wi
;
3245 memset (&wi
, 0, sizeof (wi
));
3247 wi
.want_locations
= true;
3249 saved_location
= input_location
;
3250 walk_gimple_seq_mod (body_p
, scan_omp_1_stmt
, scan_omp_1_op
, &wi
);
3251 input_location
= saved_location
;
3254 /* Re-gimplification and code generation routines. */
3256 /* If a context was created for STMT when it was scanned, return it. */
3258 static omp_context
*
3259 maybe_lookup_ctx (gimple
*stmt
)
3262 n
= splay_tree_lookup (all_contexts
, (splay_tree_key
) stmt
);
3263 return n
? (omp_context
*) n
->value
: NULL
;
3267 /* Find the mapping for DECL in CTX or the immediately enclosing
3268 context that has a mapping for DECL.
3270 If CTX is a nested parallel directive, we may have to use the decl
3271 mappings created in CTX's parent context. Suppose that we have the
3272 following parallel nesting (variable UIDs showed for clarity):
3275 #omp parallel shared(iD.1562) -> outer parallel
3276 iD.1562 = iD.1562 + 1;
3278 #omp parallel shared (iD.1562) -> inner parallel
3279 iD.1562 = iD.1562 - 1;
3281 Each parallel structure will create a distinct .omp_data_s structure
3282 for copying iD.1562 in/out of the directive:
3284 outer parallel .omp_data_s.1.i -> iD.1562
3285 inner parallel .omp_data_s.2.i -> iD.1562
3287 A shared variable mapping will produce a copy-out operation before
3288 the parallel directive and a copy-in operation after it. So, in
3289 this case we would have:
3292 .omp_data_o.1.i = iD.1562;
3293 #omp parallel shared(iD.1562) -> outer parallel
3294 .omp_data_i.1 = &.omp_data_o.1
3295 .omp_data_i.1->i = .omp_data_i.1->i + 1;
3297 .omp_data_o.2.i = iD.1562; -> **
3298 #omp parallel shared(iD.1562) -> inner parallel
3299 .omp_data_i.2 = &.omp_data_o.2
3300 .omp_data_i.2->i = .omp_data_i.2->i - 1;
3303 ** This is a problem. The symbol iD.1562 cannot be referenced
3304 inside the body of the outer parallel region. But since we are
3305 emitting this copy operation while expanding the inner parallel
3306 directive, we need to access the CTX structure of the outer
3307 parallel directive to get the correct mapping:
3309 .omp_data_o.2.i = .omp_data_i.1->i
3311 Since there may be other workshare or parallel directives enclosing
3312 the parallel directive, it may be necessary to walk up the context
3313 parent chain. This is not a problem in general because nested
3314 parallelism happens only rarely. */
3317 lookup_decl_in_outer_ctx (tree decl
, omp_context
*ctx
)
3322 for (up
= ctx
->outer
, t
= NULL
; up
&& t
== NULL
; up
= up
->outer
)
3323 t
= maybe_lookup_decl (decl
, up
);
3325 gcc_assert (!ctx
->is_nested
|| t
|| is_global_var (decl
));
3327 return t
? t
: decl
;
3331 /* Similar to lookup_decl_in_outer_ctx, but return DECL if not found
3332 in outer contexts. */
3335 maybe_lookup_decl_in_outer_ctx (tree decl
, omp_context
*ctx
)
3340 for (up
= ctx
->outer
, t
= NULL
; up
&& t
== NULL
; up
= up
->outer
)
3341 t
= maybe_lookup_decl (decl
, up
);
3343 return t
? t
: decl
;
3347 /* Construct the initialization value for reduction operation OP. */
3350 omp_reduction_init_op (location_t loc
, enum tree_code op
, tree type
)
3359 case TRUTH_ORIF_EXPR
:
3360 case TRUTH_XOR_EXPR
:
3362 return build_zero_cst (type
);
3365 case TRUTH_AND_EXPR
:
3366 case TRUTH_ANDIF_EXPR
:
3368 return fold_convert_loc (loc
, type
, integer_one_node
);
3371 return fold_convert_loc (loc
, type
, integer_minus_one_node
);
3374 if (SCALAR_FLOAT_TYPE_P (type
))
3376 REAL_VALUE_TYPE max
, min
;
3377 if (HONOR_INFINITIES (type
))
3380 real_arithmetic (&min
, NEGATE_EXPR
, &max
, NULL
);
3383 real_maxval (&min
, 1, TYPE_MODE (type
));
3384 return build_real (type
, min
);
3386 else if (POINTER_TYPE_P (type
))
3389 = wi::min_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
3390 return wide_int_to_tree (type
, min
);
3394 gcc_assert (INTEGRAL_TYPE_P (type
));
3395 return TYPE_MIN_VALUE (type
);
3399 if (SCALAR_FLOAT_TYPE_P (type
))
3401 REAL_VALUE_TYPE max
;
3402 if (HONOR_INFINITIES (type
))
3405 real_maxval (&max
, 0, TYPE_MODE (type
));
3406 return build_real (type
, max
);
3408 else if (POINTER_TYPE_P (type
))
3411 = wi::max_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
3412 return wide_int_to_tree (type
, max
);
3416 gcc_assert (INTEGRAL_TYPE_P (type
));
3417 return TYPE_MAX_VALUE (type
);
3425 /* Construct the initialization value for reduction CLAUSE. */
3428 omp_reduction_init (tree clause
, tree type
)
3430 return omp_reduction_init_op (OMP_CLAUSE_LOCATION (clause
),
3431 OMP_CLAUSE_REDUCTION_CODE (clause
), type
);
3434 /* Return alignment to be assumed for var in CLAUSE, which should be
3435 OMP_CLAUSE_ALIGNED. */
3438 omp_clause_aligned_alignment (tree clause
)
3440 if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause
))
3441 return OMP_CLAUSE_ALIGNED_ALIGNMENT (clause
);
3443 /* Otherwise return implementation defined alignment. */
3444 unsigned int al
= 1;
3445 machine_mode mode
, vmode
;
3446 int vs
= targetm
.vectorize
.autovectorize_vector_sizes ();
3448 vs
= 1 << floor_log2 (vs
);
3449 static enum mode_class classes
[]
3450 = { MODE_INT
, MODE_VECTOR_INT
, MODE_FLOAT
, MODE_VECTOR_FLOAT
};
3451 for (int i
= 0; i
< 4; i
+= 2)
3452 for (mode
= GET_CLASS_NARROWEST_MODE (classes
[i
]);
3454 mode
= GET_MODE_WIDER_MODE (mode
))
3456 vmode
= targetm
.vectorize
.preferred_simd_mode (mode
);
3457 if (GET_MODE_CLASS (vmode
) != classes
[i
+ 1])
3460 && GET_MODE_SIZE (vmode
) < vs
3461 && GET_MODE_2XWIDER_MODE (vmode
) != VOIDmode
)
3462 vmode
= GET_MODE_2XWIDER_MODE (vmode
);
3464 tree type
= lang_hooks
.types
.type_for_mode (mode
, 1);
3465 if (type
== NULL_TREE
|| TYPE_MODE (type
) != mode
)
3467 type
= build_vector_type (type
, GET_MODE_SIZE (vmode
)
3468 / GET_MODE_SIZE (mode
));
3469 if (TYPE_MODE (type
) != vmode
)
3471 if (TYPE_ALIGN_UNIT (type
) > al
)
3472 al
= TYPE_ALIGN_UNIT (type
);
3474 return build_int_cst (integer_type_node
, al
);
3478 /* This structure is part of the interface between lower_rec_simd_input_clauses
3479 and lower_rec_input_clauses. */
3481 struct omplow_simd_context
{
3484 vec
<tree
, va_heap
> simt_eargs
;
3485 gimple_seq simt_dlist
;
3490 /* Helper function of lower_rec_input_clauses, used for #pragma omp simd
3494 lower_rec_simd_input_clauses (tree new_var
, omp_context
*ctx
,
3495 omplow_simd_context
*sctx
, tree
&ivar
, tree
&lvar
)
3497 if (sctx
->max_vf
== 0)
3499 sctx
->max_vf
= sctx
->is_simt
? omp_max_simt_vf () : omp_max_vf ();
3500 if (sctx
->max_vf
> 1)
3502 tree c
= omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
3503 OMP_CLAUSE_SAFELEN
);
3505 && (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c
)) != INTEGER_CST
3506 || tree_int_cst_sgn (OMP_CLAUSE_SAFELEN_EXPR (c
)) != 1))
3508 else if (c
&& compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c
),
3509 sctx
->max_vf
) == -1)
3510 sctx
->max_vf
= tree_to_shwi (OMP_CLAUSE_SAFELEN_EXPR (c
));
3512 if (sctx
->max_vf
> 1)
3514 sctx
->idx
= create_tmp_var (unsigned_type_node
);
3515 sctx
->lane
= create_tmp_var (unsigned_type_node
);
3518 if (sctx
->max_vf
== 1)
3523 if (is_gimple_reg (new_var
))
3525 ivar
= lvar
= new_var
;
3528 tree type
= TREE_TYPE (new_var
), ptype
= build_pointer_type (type
);
3529 ivar
= lvar
= create_tmp_var (type
);
3530 TREE_ADDRESSABLE (ivar
) = 1;
3531 DECL_ATTRIBUTES (ivar
) = tree_cons (get_identifier ("omp simt private"),
3532 NULL
, DECL_ATTRIBUTES (ivar
));
3533 sctx
->simt_eargs
.safe_push (build1 (ADDR_EXPR
, ptype
, ivar
));
3534 tree clobber
= build_constructor (type
, NULL
);
3535 TREE_THIS_VOLATILE (clobber
) = 1;
3536 gimple
*g
= gimple_build_assign (ivar
, clobber
);
3537 gimple_seq_add_stmt (&sctx
->simt_dlist
, g
);
3541 tree atype
= build_array_type_nelts (TREE_TYPE (new_var
), sctx
->max_vf
);
3542 tree avar
= create_tmp_var_raw (atype
);
3543 if (TREE_ADDRESSABLE (new_var
))
3544 TREE_ADDRESSABLE (avar
) = 1;
3545 DECL_ATTRIBUTES (avar
)
3546 = tree_cons (get_identifier ("omp simd array"), NULL
,
3547 DECL_ATTRIBUTES (avar
));
3548 gimple_add_tmp_var (avar
);
3549 ivar
= build4 (ARRAY_REF
, TREE_TYPE (new_var
), avar
, sctx
->idx
,
3550 NULL_TREE
, NULL_TREE
);
3551 lvar
= build4 (ARRAY_REF
, TREE_TYPE (new_var
), avar
, sctx
->lane
,
3552 NULL_TREE
, NULL_TREE
);
3554 if (DECL_P (new_var
))
3556 SET_DECL_VALUE_EXPR (new_var
, lvar
);
3557 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
3562 /* Helper function of lower_rec_input_clauses. For a reference
3563 in simd reduction, add an underlying variable it will reference. */
3566 handle_simd_reference (location_t loc
, tree new_vard
, gimple_seq
*ilist
)
3568 tree z
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_vard
)));
3569 if (TREE_CONSTANT (z
))
3571 z
= create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_vard
)),
3572 get_name (new_vard
));
3573 gimple_add_tmp_var (z
);
3574 TREE_ADDRESSABLE (z
) = 1;
3575 z
= build_fold_addr_expr_loc (loc
, z
);
3576 gimplify_assign (new_vard
, z
, ilist
);
3580 /* Generate code to implement the input clauses, FIRSTPRIVATE and COPYIN,
3581 from the receiver (aka child) side and initializers for REFERENCE_TYPE
3582 private variables. Initialization statements go in ILIST, while calls
3583 to destructors go in DLIST. */
3586 lower_rec_input_clauses (tree clauses
, gimple_seq
*ilist
, gimple_seq
*dlist
,
3587 omp_context
*ctx
, struct omp_for_data
*fd
)
3589 tree c
, dtor
, copyin_seq
, x
, ptr
;
3590 bool copyin_by_ref
= false;
3591 bool lastprivate_firstprivate
= false;
3592 bool reduction_omp_orig_ref
= false;
3594 bool is_simd
= (gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
3595 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
);
3596 omplow_simd_context sctx
= omplow_simd_context ();
3597 tree simt_lane
= NULL_TREE
, simtrec
= NULL_TREE
;
3598 tree ivar
= NULL_TREE
, lvar
= NULL_TREE
, uid
= NULL_TREE
;
3599 gimple_seq llist
[3] = { };
3602 sctx
.is_simt
= is_simd
&& omp_find_clause (clauses
, OMP_CLAUSE__SIMT_
);
3604 /* Set max_vf=1 (which will later enforce safelen=1) in simd loops
3605 with data sharing clauses referencing variable sized vars. That
3606 is unnecessarily hard to support and very unlikely to result in
3607 vectorized code anyway. */
3609 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
3610 switch (OMP_CLAUSE_CODE (c
))
3612 case OMP_CLAUSE_LINEAR
:
3613 if (OMP_CLAUSE_LINEAR_ARRAY (c
))
3616 case OMP_CLAUSE_PRIVATE
:
3617 case OMP_CLAUSE_FIRSTPRIVATE
:
3618 case OMP_CLAUSE_LASTPRIVATE
:
3619 if (is_variable_sized (OMP_CLAUSE_DECL (c
)))
3622 case OMP_CLAUSE_REDUCTION
:
3623 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
3624 || is_variable_sized (OMP_CLAUSE_DECL (c
)))
3631 /* Add a placeholder for simduid. */
3632 if (sctx
.is_simt
&& sctx
.max_vf
!= 1)
3633 sctx
.simt_eargs
.safe_push (NULL_TREE
);
3635 /* Do all the fixed sized types in the first pass, and the variable sized
3636 types in the second pass. This makes sure that the scalar arguments to
3637 the variable sized types are processed before we use them in the
3638 variable sized operations. */
3639 for (pass
= 0; pass
< 2; ++pass
)
3641 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
3643 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
3646 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
3650 case OMP_CLAUSE_PRIVATE
:
3651 if (OMP_CLAUSE_PRIVATE_DEBUG (c
))
3654 case OMP_CLAUSE_SHARED
:
3655 /* Ignore shared directives in teams construct. */
3656 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TEAMS
)
3658 if (maybe_lookup_decl (OMP_CLAUSE_DECL (c
), ctx
) == NULL
)
3660 gcc_assert (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
)
3661 || is_global_var (OMP_CLAUSE_DECL (c
)));
3664 case OMP_CLAUSE_FIRSTPRIVATE
:
3665 case OMP_CLAUSE_COPYIN
:
3667 case OMP_CLAUSE_LINEAR
:
3668 if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
3669 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
3670 lastprivate_firstprivate
= true;
3672 case OMP_CLAUSE_REDUCTION
:
3673 if (OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
))
3674 reduction_omp_orig_ref
= true;
3676 case OMP_CLAUSE__LOOPTEMP_
:
3677 /* Handle _looptemp_ clauses only on parallel/task. */
3681 case OMP_CLAUSE_LASTPRIVATE
:
3682 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
3684 lastprivate_firstprivate
= true;
3685 if (pass
!= 0 || is_taskloop_ctx (ctx
))
3688 /* Even without corresponding firstprivate, if
3689 decl is Fortran allocatable, it needs outer var
3692 && lang_hooks
.decls
.omp_private_outer_ref
3693 (OMP_CLAUSE_DECL (c
)))
3694 lastprivate_firstprivate
= true;
3696 case OMP_CLAUSE_ALIGNED
:
3699 var
= OMP_CLAUSE_DECL (c
);
3700 if (TREE_CODE (TREE_TYPE (var
)) == POINTER_TYPE
3701 && !is_global_var (var
))
3703 new_var
= maybe_lookup_decl (var
, ctx
);
3704 if (new_var
== NULL_TREE
)
3705 new_var
= maybe_lookup_decl_in_outer_ctx (var
, ctx
);
3706 x
= builtin_decl_explicit (BUILT_IN_ASSUME_ALIGNED
);
3707 tree alarg
= omp_clause_aligned_alignment (c
);
3708 alarg
= fold_convert_loc (clause_loc
, size_type_node
, alarg
);
3709 x
= build_call_expr_loc (clause_loc
, x
, 2, new_var
, alarg
);
3710 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
3711 x
= build2 (MODIFY_EXPR
, TREE_TYPE (new_var
), new_var
, x
);
3712 gimplify_and_add (x
, ilist
);
3714 else if (TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
3715 && is_global_var (var
))
3717 tree ptype
= build_pointer_type (TREE_TYPE (var
)), t
, t2
;
3718 new_var
= lookup_decl (var
, ctx
);
3719 t
= maybe_lookup_decl_in_outer_ctx (var
, ctx
);
3720 t
= build_fold_addr_expr_loc (clause_loc
, t
);
3721 t2
= builtin_decl_explicit (BUILT_IN_ASSUME_ALIGNED
);
3722 tree alarg
= omp_clause_aligned_alignment (c
);
3723 alarg
= fold_convert_loc (clause_loc
, size_type_node
, alarg
);
3724 t
= build_call_expr_loc (clause_loc
, t2
, 2, t
, alarg
);
3725 t
= fold_convert_loc (clause_loc
, ptype
, t
);
3726 x
= create_tmp_var (ptype
);
3727 t
= build2 (MODIFY_EXPR
, ptype
, x
, t
);
3728 gimplify_and_add (t
, ilist
);
3729 t
= build_simple_mem_ref_loc (clause_loc
, x
);
3730 SET_DECL_VALUE_EXPR (new_var
, t
);
3731 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
3738 new_var
= var
= OMP_CLAUSE_DECL (c
);
3739 if (c_kind
== OMP_CLAUSE_REDUCTION
&& TREE_CODE (var
) == MEM_REF
)
3741 var
= TREE_OPERAND (var
, 0);
3742 if (TREE_CODE (var
) == POINTER_PLUS_EXPR
)
3743 var
= TREE_OPERAND (var
, 0);
3744 if (TREE_CODE (var
) == INDIRECT_REF
3745 || TREE_CODE (var
) == ADDR_EXPR
)
3746 var
= TREE_OPERAND (var
, 0);
3747 if (is_variable_sized (var
))
3749 gcc_assert (DECL_HAS_VALUE_EXPR_P (var
));
3750 var
= DECL_VALUE_EXPR (var
);
3751 gcc_assert (TREE_CODE (var
) == INDIRECT_REF
);
3752 var
= TREE_OPERAND (var
, 0);
3753 gcc_assert (DECL_P (var
));
3757 if (c_kind
!= OMP_CLAUSE_COPYIN
)
3758 new_var
= lookup_decl (var
, ctx
);
3760 if (c_kind
== OMP_CLAUSE_SHARED
|| c_kind
== OMP_CLAUSE_COPYIN
)
3765 /* C/C++ array section reductions. */
3766 else if (c_kind
== OMP_CLAUSE_REDUCTION
3767 && var
!= OMP_CLAUSE_DECL (c
))
3772 tree bias
= TREE_OPERAND (OMP_CLAUSE_DECL (c
), 1);
3773 tree orig_var
= TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0);
3774 if (TREE_CODE (orig_var
) == POINTER_PLUS_EXPR
)
3776 tree b
= TREE_OPERAND (orig_var
, 1);
3777 b
= maybe_lookup_decl (b
, ctx
);
3780 b
= TREE_OPERAND (orig_var
, 1);
3781 b
= maybe_lookup_decl_in_outer_ctx (b
, ctx
);
3783 if (integer_zerop (bias
))
3787 bias
= fold_convert_loc (clause_loc
,
3788 TREE_TYPE (b
), bias
);
3789 bias
= fold_build2_loc (clause_loc
, PLUS_EXPR
,
3790 TREE_TYPE (b
), b
, bias
);
3792 orig_var
= TREE_OPERAND (orig_var
, 0);
3794 if (TREE_CODE (orig_var
) == INDIRECT_REF
3795 || TREE_CODE (orig_var
) == ADDR_EXPR
)
3796 orig_var
= TREE_OPERAND (orig_var
, 0);
3797 tree d
= OMP_CLAUSE_DECL (c
);
3798 tree type
= TREE_TYPE (d
);
3799 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
3800 tree v
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
3801 const char *name
= get_name (orig_var
);
3802 if (TREE_CONSTANT (v
))
3804 x
= create_tmp_var_raw (type
, name
);
3805 gimple_add_tmp_var (x
);
3806 TREE_ADDRESSABLE (x
) = 1;
3807 x
= build_fold_addr_expr_loc (clause_loc
, x
);
3812 = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
3813 tree t
= maybe_lookup_decl (v
, ctx
);
3817 v
= maybe_lookup_decl_in_outer_ctx (v
, ctx
);
3818 gimplify_expr (&v
, ilist
, NULL
, is_gimple_val
, fb_rvalue
);
3819 t
= fold_build2_loc (clause_loc
, PLUS_EXPR
,
3821 build_int_cst (TREE_TYPE (v
), 1));
3822 t
= fold_build2_loc (clause_loc
, MULT_EXPR
,
3824 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
3825 tree al
= size_int (TYPE_ALIGN (TREE_TYPE (type
)));
3826 x
= build_call_expr_loc (clause_loc
, atmp
, 2, t
, al
);
3829 tree ptype
= build_pointer_type (TREE_TYPE (type
));
3830 x
= fold_convert_loc (clause_loc
, ptype
, x
);
3831 tree y
= create_tmp_var (ptype
, name
);
3832 gimplify_assign (y
, x
, ilist
);
3836 if (!integer_zerop (bias
))
3838 bias
= fold_convert_loc (clause_loc
, pointer_sized_int_node
,
3840 yb
= fold_convert_loc (clause_loc
, pointer_sized_int_node
,
3842 yb
= fold_build2_loc (clause_loc
, MINUS_EXPR
,
3843 pointer_sized_int_node
, yb
, bias
);
3844 x
= fold_convert_loc (clause_loc
, TREE_TYPE (x
), yb
);
3845 yb
= create_tmp_var (ptype
, name
);
3846 gimplify_assign (yb
, x
, ilist
);
3850 d
= TREE_OPERAND (d
, 0);
3851 if (TREE_CODE (d
) == POINTER_PLUS_EXPR
)
3852 d
= TREE_OPERAND (d
, 0);
3853 if (TREE_CODE (d
) == ADDR_EXPR
)
3855 if (orig_var
!= var
)
3857 gcc_assert (is_variable_sized (orig_var
));
3858 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
),
3860 gimplify_assign (new_var
, x
, ilist
);
3861 tree new_orig_var
= lookup_decl (orig_var
, ctx
);
3862 tree t
= build_fold_indirect_ref (new_var
);
3863 DECL_IGNORED_P (new_var
) = 0;
3864 TREE_THIS_NOTRAP (t
);
3865 SET_DECL_VALUE_EXPR (new_orig_var
, t
);
3866 DECL_HAS_VALUE_EXPR_P (new_orig_var
) = 1;
3870 x
= build2 (MEM_REF
, TREE_TYPE (new_var
), x
,
3871 build_int_cst (ptype
, 0));
3872 SET_DECL_VALUE_EXPR (new_var
, x
);
3873 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
3878 gcc_assert (orig_var
== var
);
3879 if (TREE_CODE (d
) == INDIRECT_REF
)
3881 x
= create_tmp_var (ptype
, name
);
3882 TREE_ADDRESSABLE (x
) = 1;
3883 gimplify_assign (x
, yb
, ilist
);
3884 x
= build_fold_addr_expr_loc (clause_loc
, x
);
3886 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
3887 gimplify_assign (new_var
, x
, ilist
);
3889 tree y1
= create_tmp_var (ptype
, NULL
);
3890 gimplify_assign (y1
, y
, ilist
);
3891 tree i2
= NULL_TREE
, y2
= NULL_TREE
;
3892 tree body2
= NULL_TREE
, end2
= NULL_TREE
;
3893 tree y3
= NULL_TREE
, y4
= NULL_TREE
;
3894 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) || is_simd
)
3896 y2
= create_tmp_var (ptype
, NULL
);
3897 gimplify_assign (y2
, y
, ilist
);
3898 tree ref
= build_outer_var_ref (var
, ctx
);
3899 /* For ref build_outer_var_ref already performs this. */
3900 if (TREE_CODE (d
) == INDIRECT_REF
)
3901 gcc_assert (omp_is_reference (var
));
3902 else if (TREE_CODE (d
) == ADDR_EXPR
)
3903 ref
= build_fold_addr_expr (ref
);
3904 else if (omp_is_reference (var
))
3905 ref
= build_fold_addr_expr (ref
);
3906 ref
= fold_convert_loc (clause_loc
, ptype
, ref
);
3907 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
3908 && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
))
3910 y3
= create_tmp_var (ptype
, NULL
);
3911 gimplify_assign (y3
, unshare_expr (ref
), ilist
);
3915 y4
= create_tmp_var (ptype
, NULL
);
3916 gimplify_assign (y4
, ref
, dlist
);
3919 tree i
= create_tmp_var (TREE_TYPE (v
), NULL
);
3920 gimplify_assign (i
, build_int_cst (TREE_TYPE (v
), 0), ilist
);
3921 tree body
= create_artificial_label (UNKNOWN_LOCATION
);
3922 tree end
= create_artificial_label (UNKNOWN_LOCATION
);
3923 gimple_seq_add_stmt (ilist
, gimple_build_label (body
));
3926 i2
= create_tmp_var (TREE_TYPE (v
), NULL
);
3927 gimplify_assign (i2
, build_int_cst (TREE_TYPE (v
), 0), dlist
);
3928 body2
= create_artificial_label (UNKNOWN_LOCATION
);
3929 end2
= create_artificial_label (UNKNOWN_LOCATION
);
3930 gimple_seq_add_stmt (dlist
, gimple_build_label (body2
));
3932 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
3934 tree placeholder
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
3935 tree decl_placeholder
3936 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
);
3937 SET_DECL_VALUE_EXPR (decl_placeholder
,
3938 build_simple_mem_ref (y1
));
3939 DECL_HAS_VALUE_EXPR_P (decl_placeholder
) = 1;
3940 SET_DECL_VALUE_EXPR (placeholder
,
3941 y3
? build_simple_mem_ref (y3
)
3943 DECL_HAS_VALUE_EXPR_P (placeholder
) = 1;
3944 x
= lang_hooks
.decls
.omp_clause_default_ctor
3945 (c
, build_simple_mem_ref (y1
),
3946 y3
? build_simple_mem_ref (y3
) : NULL_TREE
);
3948 gimplify_and_add (x
, ilist
);
3949 if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
))
3951 gimple_seq tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
);
3952 lower_omp (&tseq
, ctx
);
3953 gimple_seq_add_seq (ilist
, tseq
);
3955 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
) = NULL
;
3958 SET_DECL_VALUE_EXPR (decl_placeholder
,
3959 build_simple_mem_ref (y2
));
3960 SET_DECL_VALUE_EXPR (placeholder
,
3961 build_simple_mem_ref (y4
));
3962 gimple_seq tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
);
3963 lower_omp (&tseq
, ctx
);
3964 gimple_seq_add_seq (dlist
, tseq
);
3965 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
3967 DECL_HAS_VALUE_EXPR_P (placeholder
) = 0;
3968 DECL_HAS_VALUE_EXPR_P (decl_placeholder
) = 0;
3969 x
= lang_hooks
.decls
.omp_clause_dtor
3970 (c
, build_simple_mem_ref (y2
));
3973 gimple_seq tseq
= NULL
;
3975 gimplify_stmt (&dtor
, &tseq
);
3976 gimple_seq_add_seq (dlist
, tseq
);
3981 x
= omp_reduction_init (c
, TREE_TYPE (type
));
3982 enum tree_code code
= OMP_CLAUSE_REDUCTION_CODE (c
);
3984 /* reduction(-:var) sums up the partial results, so it
3985 acts identically to reduction(+:var). */
3986 if (code
== MINUS_EXPR
)
3989 gimplify_assign (build_simple_mem_ref (y1
), x
, ilist
);
3992 x
= build2 (code
, TREE_TYPE (type
),
3993 build_simple_mem_ref (y4
),
3994 build_simple_mem_ref (y2
));
3995 gimplify_assign (build_simple_mem_ref (y4
), x
, dlist
);
3999 = gimple_build_assign (y1
, POINTER_PLUS_EXPR
, y1
,
4000 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
4001 gimple_seq_add_stmt (ilist
, g
);
4004 g
= gimple_build_assign (y3
, POINTER_PLUS_EXPR
, y3
,
4005 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
4006 gimple_seq_add_stmt (ilist
, g
);
4008 g
= gimple_build_assign (i
, PLUS_EXPR
, i
,
4009 build_int_cst (TREE_TYPE (i
), 1));
4010 gimple_seq_add_stmt (ilist
, g
);
4011 g
= gimple_build_cond (LE_EXPR
, i
, v
, body
, end
);
4012 gimple_seq_add_stmt (ilist
, g
);
4013 gimple_seq_add_stmt (ilist
, gimple_build_label (end
));
4016 g
= gimple_build_assign (y2
, POINTER_PLUS_EXPR
, y2
,
4017 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
4018 gimple_seq_add_stmt (dlist
, g
);
4021 g
= gimple_build_assign
4022 (y4
, POINTER_PLUS_EXPR
, y4
,
4023 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
4024 gimple_seq_add_stmt (dlist
, g
);
4026 g
= gimple_build_assign (i2
, PLUS_EXPR
, i2
,
4027 build_int_cst (TREE_TYPE (i2
), 1));
4028 gimple_seq_add_stmt (dlist
, g
);
4029 g
= gimple_build_cond (LE_EXPR
, i2
, v
, body2
, end2
);
4030 gimple_seq_add_stmt (dlist
, g
);
4031 gimple_seq_add_stmt (dlist
, gimple_build_label (end2
));
4035 else if (is_variable_sized (var
))
4037 /* For variable sized types, we need to allocate the
4038 actual storage here. Call alloca and store the
4039 result in the pointer decl that we created elsewhere. */
4043 if (c_kind
!= OMP_CLAUSE_FIRSTPRIVATE
|| !is_task_ctx (ctx
))
4048 ptr
= DECL_VALUE_EXPR (new_var
);
4049 gcc_assert (TREE_CODE (ptr
) == INDIRECT_REF
);
4050 ptr
= TREE_OPERAND (ptr
, 0);
4051 gcc_assert (DECL_P (ptr
));
4052 x
= TYPE_SIZE_UNIT (TREE_TYPE (new_var
));
4054 /* void *tmp = __builtin_alloca */
4055 atmp
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
4056 stmt
= gimple_build_call (atmp
, 2, x
,
4057 size_int (DECL_ALIGN (var
)));
4058 tmp
= create_tmp_var_raw (ptr_type_node
);
4059 gimple_add_tmp_var (tmp
);
4060 gimple_call_set_lhs (stmt
, tmp
);
4062 gimple_seq_add_stmt (ilist
, stmt
);
4064 x
= fold_convert_loc (clause_loc
, TREE_TYPE (ptr
), tmp
);
4065 gimplify_assign (ptr
, x
, ilist
);
4068 else if (omp_is_reference (var
))
4070 /* For references that are being privatized for Fortran,
4071 allocate new backing storage for the new pointer
4072 variable. This allows us to avoid changing all the
4073 code that expects a pointer to something that expects
4074 a direct variable. */
4078 x
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var
)));
4079 if (c_kind
== OMP_CLAUSE_FIRSTPRIVATE
&& is_task_ctx (ctx
))
4081 x
= build_receiver_ref (var
, false, ctx
);
4082 x
= build_fold_addr_expr_loc (clause_loc
, x
);
4084 else if (TREE_CONSTANT (x
))
4086 /* For reduction in SIMD loop, defer adding the
4087 initialization of the reference, because if we decide
4088 to use SIMD array for it, the initilization could cause
4090 if (c_kind
== OMP_CLAUSE_REDUCTION
&& is_simd
)
4094 x
= create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var
)),
4096 gimple_add_tmp_var (x
);
4097 TREE_ADDRESSABLE (x
) = 1;
4098 x
= build_fold_addr_expr_loc (clause_loc
, x
);
4104 = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
4105 tree rtype
= TREE_TYPE (TREE_TYPE (new_var
));
4106 tree al
= size_int (TYPE_ALIGN (rtype
));
4107 x
= build_call_expr_loc (clause_loc
, atmp
, 2, x
, al
);
4112 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
4113 gimplify_assign (new_var
, x
, ilist
);
4116 new_var
= build_simple_mem_ref_loc (clause_loc
, new_var
);
4118 else if (c_kind
== OMP_CLAUSE_REDUCTION
4119 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
4127 switch (OMP_CLAUSE_CODE (c
))
4129 case OMP_CLAUSE_SHARED
:
4130 /* Ignore shared directives in teams construct. */
4131 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_TEAMS
)
4133 /* Shared global vars are just accessed directly. */
4134 if (is_global_var (new_var
))
4136 /* For taskloop firstprivate/lastprivate, represented
4137 as firstprivate and shared clause on the task, new_var
4138 is the firstprivate var. */
4139 if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
4141 /* Set up the DECL_VALUE_EXPR for shared variables now. This
4142 needs to be delayed until after fixup_child_record_type so
4143 that we get the correct type during the dereference. */
4144 by_ref
= use_pointer_for_field (var
, ctx
);
4145 x
= build_receiver_ref (var
, by_ref
, ctx
);
4146 SET_DECL_VALUE_EXPR (new_var
, x
);
4147 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
4149 /* ??? If VAR is not passed by reference, and the variable
4150 hasn't been initialized yet, then we'll get a warning for
4151 the store into the omp_data_s structure. Ideally, we'd be
4152 able to notice this and not store anything at all, but
4153 we're generating code too early. Suppress the warning. */
4155 TREE_NO_WARNING (var
) = 1;
4158 case OMP_CLAUSE_LASTPRIVATE
:
4159 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
4163 case OMP_CLAUSE_PRIVATE
:
4164 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_PRIVATE
)
4165 x
= build_outer_var_ref (var
, ctx
);
4166 else if (OMP_CLAUSE_PRIVATE_OUTER_REF (c
))
4168 if (is_task_ctx (ctx
))
4169 x
= build_receiver_ref (var
, false, ctx
);
4171 x
= build_outer_var_ref (var
, ctx
, OMP_CLAUSE_PRIVATE
);
4177 nx
= lang_hooks
.decls
.omp_clause_default_ctor
4178 (c
, unshare_expr (new_var
), x
);
4181 tree y
= lang_hooks
.decls
.omp_clause_dtor (c
, new_var
);
4182 if ((TREE_ADDRESSABLE (new_var
) || nx
|| y
4183 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
4184 && lower_rec_simd_input_clauses (new_var
, ctx
, &sctx
,
4188 x
= lang_hooks
.decls
.omp_clause_default_ctor
4189 (c
, unshare_expr (ivar
), x
);
4191 gimplify_and_add (x
, &llist
[0]);
4194 y
= lang_hooks
.decls
.omp_clause_dtor (c
, ivar
);
4197 gimple_seq tseq
= NULL
;
4200 gimplify_stmt (&dtor
, &tseq
);
4201 gimple_seq_add_seq (&llist
[1], tseq
);
4208 gimplify_and_add (nx
, ilist
);
4212 x
= lang_hooks
.decls
.omp_clause_dtor (c
, new_var
);
4215 gimple_seq tseq
= NULL
;
4218 gimplify_stmt (&dtor
, &tseq
);
4219 gimple_seq_add_seq (dlist
, tseq
);
4223 case OMP_CLAUSE_LINEAR
:
4224 if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
4225 goto do_firstprivate
;
4226 if (OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
4229 x
= build_outer_var_ref (var
, ctx
);
4232 case OMP_CLAUSE_FIRSTPRIVATE
:
4233 if (is_task_ctx (ctx
))
4235 if (omp_is_reference (var
) || is_variable_sized (var
))
4237 else if (is_global_var (maybe_lookup_decl_in_outer_ctx (var
,
4239 || use_pointer_for_field (var
, NULL
))
4241 x
= build_receiver_ref (var
, false, ctx
);
4242 SET_DECL_VALUE_EXPR (new_var
, x
);
4243 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
4248 x
= build_outer_var_ref (var
, ctx
);
4251 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
4252 && gimple_omp_for_combined_into_p (ctx
->stmt
))
4254 tree t
= OMP_CLAUSE_LINEAR_STEP (c
);
4255 tree stept
= TREE_TYPE (t
);
4256 tree ct
= omp_find_clause (clauses
,
4257 OMP_CLAUSE__LOOPTEMP_
);
4259 tree l
= OMP_CLAUSE_DECL (ct
);
4260 tree n1
= fd
->loop
.n1
;
4261 tree step
= fd
->loop
.step
;
4262 tree itype
= TREE_TYPE (l
);
4263 if (POINTER_TYPE_P (itype
))
4264 itype
= signed_type_for (itype
);
4265 l
= fold_build2 (MINUS_EXPR
, itype
, l
, n1
);
4266 if (TYPE_UNSIGNED (itype
)
4267 && fd
->loop
.cond_code
== GT_EXPR
)
4268 l
= fold_build2 (TRUNC_DIV_EXPR
, itype
,
4269 fold_build1 (NEGATE_EXPR
, itype
, l
),
4270 fold_build1 (NEGATE_EXPR
,
4273 l
= fold_build2 (TRUNC_DIV_EXPR
, itype
, l
, step
);
4274 t
= fold_build2 (MULT_EXPR
, stept
,
4275 fold_convert (stept
, l
), t
);
4277 if (OMP_CLAUSE_LINEAR_ARRAY (c
))
4279 x
= lang_hooks
.decls
.omp_clause_linear_ctor
4281 gimplify_and_add (x
, ilist
);
4285 if (POINTER_TYPE_P (TREE_TYPE (x
)))
4286 x
= fold_build2 (POINTER_PLUS_EXPR
,
4287 TREE_TYPE (x
), x
, t
);
4289 x
= fold_build2 (PLUS_EXPR
, TREE_TYPE (x
), x
, t
);
4292 if ((OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
4293 || TREE_ADDRESSABLE (new_var
))
4294 && lower_rec_simd_input_clauses (new_var
, ctx
, &sctx
,
4297 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
)
4299 tree iv
= create_tmp_var (TREE_TYPE (new_var
));
4300 x
= lang_hooks
.decls
.omp_clause_copy_ctor (c
, iv
, x
);
4301 gimplify_and_add (x
, ilist
);
4302 gimple_stmt_iterator gsi
4303 = gsi_start_1 (gimple_omp_body_ptr (ctx
->stmt
));
4305 = gimple_build_assign (unshare_expr (lvar
), iv
);
4306 gsi_insert_before_without_update (&gsi
, g
,
4308 tree t
= OMP_CLAUSE_LINEAR_STEP (c
);
4309 enum tree_code code
= PLUS_EXPR
;
4310 if (POINTER_TYPE_P (TREE_TYPE (new_var
)))
4311 code
= POINTER_PLUS_EXPR
;
4312 g
= gimple_build_assign (iv
, code
, iv
, t
);
4313 gsi_insert_before_without_update (&gsi
, g
,
4317 x
= lang_hooks
.decls
.omp_clause_copy_ctor
4318 (c
, unshare_expr (ivar
), x
);
4319 gimplify_and_add (x
, &llist
[0]);
4320 x
= lang_hooks
.decls
.omp_clause_dtor (c
, ivar
);
4323 gimple_seq tseq
= NULL
;
4326 gimplify_stmt (&dtor
, &tseq
);
4327 gimple_seq_add_seq (&llist
[1], tseq
);
4332 x
= lang_hooks
.decls
.omp_clause_copy_ctor
4333 (c
, unshare_expr (new_var
), x
);
4334 gimplify_and_add (x
, ilist
);
4337 case OMP_CLAUSE__LOOPTEMP_
:
4338 gcc_assert (is_taskreg_ctx (ctx
));
4339 x
= build_outer_var_ref (var
, ctx
);
4340 x
= build2 (MODIFY_EXPR
, TREE_TYPE (new_var
), new_var
, x
);
4341 gimplify_and_add (x
, ilist
);
4344 case OMP_CLAUSE_COPYIN
:
4345 by_ref
= use_pointer_for_field (var
, NULL
);
4346 x
= build_receiver_ref (var
, by_ref
, ctx
);
4347 x
= lang_hooks
.decls
.omp_clause_assign_op (c
, new_var
, x
);
4348 append_to_statement_list (x
, ©in_seq
);
4349 copyin_by_ref
|= by_ref
;
4352 case OMP_CLAUSE_REDUCTION
:
4353 /* OpenACC reductions are initialized using the
4354 GOACC_REDUCTION internal function. */
4355 if (is_gimple_omp_oacc (ctx
->stmt
))
4357 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
4359 tree placeholder
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
4361 x
= build_outer_var_ref (var
, ctx
);
4363 if (omp_is_reference (var
)
4364 && !useless_type_conversion_p (TREE_TYPE (placeholder
),
4366 x
= build_fold_addr_expr_loc (clause_loc
, x
);
4367 SET_DECL_VALUE_EXPR (placeholder
, x
);
4368 DECL_HAS_VALUE_EXPR_P (placeholder
) = 1;
4369 tree new_vard
= new_var
;
4370 if (omp_is_reference (var
))
4372 gcc_assert (TREE_CODE (new_var
) == MEM_REF
);
4373 new_vard
= TREE_OPERAND (new_var
, 0);
4374 gcc_assert (DECL_P (new_vard
));
4377 && lower_rec_simd_input_clauses (new_var
, ctx
, &sctx
,
4380 if (new_vard
== new_var
)
4382 gcc_assert (DECL_VALUE_EXPR (new_var
) == lvar
);
4383 SET_DECL_VALUE_EXPR (new_var
, ivar
);
4387 SET_DECL_VALUE_EXPR (new_vard
,
4388 build_fold_addr_expr (ivar
));
4389 DECL_HAS_VALUE_EXPR_P (new_vard
) = 1;
4391 x
= lang_hooks
.decls
.omp_clause_default_ctor
4392 (c
, unshare_expr (ivar
),
4393 build_outer_var_ref (var
, ctx
));
4395 gimplify_and_add (x
, &llist
[0]);
4396 if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
))
4398 tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
);
4399 lower_omp (&tseq
, ctx
);
4400 gimple_seq_add_seq (&llist
[0], tseq
);
4402 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
) = NULL
;
4403 tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
);
4404 lower_omp (&tseq
, ctx
);
4405 gimple_seq_add_seq (&llist
[1], tseq
);
4406 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
4407 DECL_HAS_VALUE_EXPR_P (placeholder
) = 0;
4408 if (new_vard
== new_var
)
4409 SET_DECL_VALUE_EXPR (new_var
, lvar
);
4411 SET_DECL_VALUE_EXPR (new_vard
,
4412 build_fold_addr_expr (lvar
));
4413 x
= lang_hooks
.decls
.omp_clause_dtor (c
, ivar
);
4418 gimplify_stmt (&dtor
, &tseq
);
4419 gimple_seq_add_seq (&llist
[1], tseq
);
4423 /* If this is a reference to constant size reduction var
4424 with placeholder, we haven't emitted the initializer
4425 for it because it is undesirable if SIMD arrays are used.
4426 But if they aren't used, we need to emit the deferred
4427 initialization now. */
4428 else if (omp_is_reference (var
) && is_simd
)
4429 handle_simd_reference (clause_loc
, new_vard
, ilist
);
4430 x
= lang_hooks
.decls
.omp_clause_default_ctor
4431 (c
, unshare_expr (new_var
),
4432 build_outer_var_ref (var
, ctx
));
4434 gimplify_and_add (x
, ilist
);
4435 if (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
))
4437 tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
);
4438 lower_omp (&tseq
, ctx
);
4439 gimple_seq_add_seq (ilist
, tseq
);
4441 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
) = NULL
;
4444 tseq
= OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
);
4445 lower_omp (&tseq
, ctx
);
4446 gimple_seq_add_seq (dlist
, tseq
);
4447 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
4449 DECL_HAS_VALUE_EXPR_P (placeholder
) = 0;
4454 x
= omp_reduction_init (c
, TREE_TYPE (new_var
));
4455 gcc_assert (TREE_CODE (TREE_TYPE (new_var
)) != ARRAY_TYPE
);
4456 enum tree_code code
= OMP_CLAUSE_REDUCTION_CODE (c
);
4458 /* reduction(-:var) sums up the partial results, so it
4459 acts identically to reduction(+:var). */
4460 if (code
== MINUS_EXPR
)
4463 tree new_vard
= new_var
;
4464 if (is_simd
&& omp_is_reference (var
))
4466 gcc_assert (TREE_CODE (new_var
) == MEM_REF
);
4467 new_vard
= TREE_OPERAND (new_var
, 0);
4468 gcc_assert (DECL_P (new_vard
));
4471 && lower_rec_simd_input_clauses (new_var
, ctx
, &sctx
,
4474 tree ref
= build_outer_var_ref (var
, ctx
);
4476 gimplify_assign (unshare_expr (ivar
), x
, &llist
[0]);
4481 simt_lane
= create_tmp_var (unsigned_type_node
);
4482 x
= build_call_expr_internal_loc
4483 (UNKNOWN_LOCATION
, IFN_GOMP_SIMT_XCHG_BFLY
,
4484 TREE_TYPE (ivar
), 2, ivar
, simt_lane
);
4485 x
= build2 (code
, TREE_TYPE (ivar
), ivar
, x
);
4486 gimplify_assign (ivar
, x
, &llist
[2]);
4488 x
= build2 (code
, TREE_TYPE (ref
), ref
, ivar
);
4489 ref
= build_outer_var_ref (var
, ctx
);
4490 gimplify_assign (ref
, x
, &llist
[1]);
4492 if (new_vard
!= new_var
)
4494 SET_DECL_VALUE_EXPR (new_vard
,
4495 build_fold_addr_expr (lvar
));
4496 DECL_HAS_VALUE_EXPR_P (new_vard
) = 1;
4501 if (omp_is_reference (var
) && is_simd
)
4502 handle_simd_reference (clause_loc
, new_vard
, ilist
);
4503 gimplify_assign (new_var
, x
, ilist
);
4506 tree ref
= build_outer_var_ref (var
, ctx
);
4508 x
= build2 (code
, TREE_TYPE (ref
), ref
, new_var
);
4509 ref
= build_outer_var_ref (var
, ctx
);
4510 gimplify_assign (ref
, x
, dlist
);
4522 if (sctx
.max_vf
== 1)
4523 sctx
.is_simt
= false;
4525 if (sctx
.lane
|| sctx
.is_simt
)
4527 uid
= create_tmp_var (ptr_type_node
, "simduid");
4528 /* Don't want uninit warnings on simduid, it is always uninitialized,
4529 but we use it not for the value, but for the DECL_UID only. */
4530 TREE_NO_WARNING (uid
) = 1;
4531 c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE__SIMDUID_
);
4532 OMP_CLAUSE__SIMDUID__DECL (c
) = uid
;
4533 OMP_CLAUSE_CHAIN (c
) = gimple_omp_for_clauses (ctx
->stmt
);
4534 gimple_omp_for_set_clauses (ctx
->stmt
, c
);
4536 /* Emit calls denoting privatized variables and initializing a pointer to
4537 structure that holds private variables as fields after ompdevlow pass. */
4540 sctx
.simt_eargs
[0] = uid
;
4542 = gimple_build_call_internal_vec (IFN_GOMP_SIMT_ENTER
, sctx
.simt_eargs
);
4543 gimple_call_set_lhs (g
, uid
);
4544 gimple_seq_add_stmt (ilist
, g
);
4545 sctx
.simt_eargs
.release ();
4547 simtrec
= create_tmp_var (ptr_type_node
, ".omp_simt");
4548 g
= gimple_build_call_internal (IFN_GOMP_SIMT_ENTER_ALLOC
, 1, uid
);
4549 gimple_call_set_lhs (g
, simtrec
);
4550 gimple_seq_add_stmt (ilist
, g
);
4555 = gimple_build_call_internal (IFN_GOMP_SIMD_LANE
, 1, uid
);
4556 gimple_call_set_lhs (g
, sctx
.lane
);
4557 gimple_stmt_iterator gsi
= gsi_start_1 (gimple_omp_body_ptr (ctx
->stmt
));
4558 gsi_insert_before_without_update (&gsi
, g
, GSI_SAME_STMT
);
4559 g
= gimple_build_assign (sctx
.lane
, INTEGER_CST
,
4560 build_int_cst (unsigned_type_node
, 0));
4561 gimple_seq_add_stmt (ilist
, g
);
4562 /* Emit reductions across SIMT lanes in log_2(simt_vf) steps. */
4565 tree simt_vf
= create_tmp_var (unsigned_type_node
);
4566 g
= gimple_build_call_internal (IFN_GOMP_SIMT_VF
, 0);
4567 gimple_call_set_lhs (g
, simt_vf
);
4568 gimple_seq_add_stmt (dlist
, g
);
4570 tree t
= build_int_cst (unsigned_type_node
, 1);
4571 g
= gimple_build_assign (simt_lane
, INTEGER_CST
, t
);
4572 gimple_seq_add_stmt (dlist
, g
);
4574 t
= build_int_cst (unsigned_type_node
, 0);
4575 g
= gimple_build_assign (sctx
.idx
, INTEGER_CST
, t
);
4576 gimple_seq_add_stmt (dlist
, g
);
4578 tree body
= create_artificial_label (UNKNOWN_LOCATION
);
4579 tree header
= create_artificial_label (UNKNOWN_LOCATION
);
4580 tree end
= create_artificial_label (UNKNOWN_LOCATION
);
4581 gimple_seq_add_stmt (dlist
, gimple_build_goto (header
));
4582 gimple_seq_add_stmt (dlist
, gimple_build_label (body
));
4584 gimple_seq_add_seq (dlist
, llist
[2]);
4586 g
= gimple_build_assign (simt_lane
, LSHIFT_EXPR
, simt_lane
, integer_one_node
);
4587 gimple_seq_add_stmt (dlist
, g
);
4589 gimple_seq_add_stmt (dlist
, gimple_build_label (header
));
4590 g
= gimple_build_cond (LT_EXPR
, simt_lane
, simt_vf
, body
, end
);
4591 gimple_seq_add_stmt (dlist
, g
);
4593 gimple_seq_add_stmt (dlist
, gimple_build_label (end
));
4595 for (int i
= 0; i
< 2; i
++)
4598 tree vf
= create_tmp_var (unsigned_type_node
);
4599 g
= gimple_build_call_internal (IFN_GOMP_SIMD_VF
, 1, uid
);
4600 gimple_call_set_lhs (g
, vf
);
4601 gimple_seq
*seq
= i
== 0 ? ilist
: dlist
;
4602 gimple_seq_add_stmt (seq
, g
);
4603 tree t
= build_int_cst (unsigned_type_node
, 0);
4604 g
= gimple_build_assign (sctx
.idx
, INTEGER_CST
, t
);
4605 gimple_seq_add_stmt (seq
, g
);
4606 tree body
= create_artificial_label (UNKNOWN_LOCATION
);
4607 tree header
= create_artificial_label (UNKNOWN_LOCATION
);
4608 tree end
= create_artificial_label (UNKNOWN_LOCATION
);
4609 gimple_seq_add_stmt (seq
, gimple_build_goto (header
));
4610 gimple_seq_add_stmt (seq
, gimple_build_label (body
));
4611 gimple_seq_add_seq (seq
, llist
[i
]);
4612 t
= build_int_cst (unsigned_type_node
, 1);
4613 g
= gimple_build_assign (sctx
.idx
, PLUS_EXPR
, sctx
.idx
, t
);
4614 gimple_seq_add_stmt (seq
, g
);
4615 gimple_seq_add_stmt (seq
, gimple_build_label (header
));
4616 g
= gimple_build_cond (LT_EXPR
, sctx
.idx
, vf
, body
, end
);
4617 gimple_seq_add_stmt (seq
, g
);
4618 gimple_seq_add_stmt (seq
, gimple_build_label (end
));
4623 gimple_seq_add_seq (dlist
, sctx
.simt_dlist
);
4625 = gimple_build_call_internal (IFN_GOMP_SIMT_EXIT
, 1, simtrec
);
4626 gimple_seq_add_stmt (dlist
, g
);
4629 /* The copyin sequence is not to be executed by the main thread, since
4630 that would result in self-copies. Perhaps not visible to scalars,
4631 but it certainly is to C++ operator=. */
4634 x
= build_call_expr (builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM
),
4636 x
= build2 (NE_EXPR
, boolean_type_node
, x
,
4637 build_int_cst (TREE_TYPE (x
), 0));
4638 x
= build3 (COND_EXPR
, void_type_node
, x
, copyin_seq
, NULL
);
4639 gimplify_and_add (x
, ilist
);
4642 /* If any copyin variable is passed by reference, we must ensure the
4643 master thread doesn't modify it before it is copied over in all
4644 threads. Similarly for variables in both firstprivate and
4645 lastprivate clauses we need to ensure the lastprivate copying
4646 happens after firstprivate copying in all threads. And similarly
4647 for UDRs if initializer expression refers to omp_orig. */
4648 if (copyin_by_ref
|| lastprivate_firstprivate
|| reduction_omp_orig_ref
)
4650 /* Don't add any barrier for #pragma omp simd or
4651 #pragma omp distribute. */
4652 if (gimple_code (ctx
->stmt
) != GIMPLE_OMP_FOR
4653 || gimple_omp_for_kind (ctx
->stmt
) == GF_OMP_FOR_KIND_FOR
)
4654 gimple_seq_add_stmt (ilist
, omp_build_barrier (NULL_TREE
));
4657 /* If max_vf is non-zero, then we can use only a vectorization factor
4658 up to the max_vf we chose. So stick it into the safelen clause. */
4661 tree c
= omp_find_clause (gimple_omp_for_clauses (ctx
->stmt
),
4662 OMP_CLAUSE_SAFELEN
);
4664 || (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c
)) == INTEGER_CST
4665 && compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c
),
4668 c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE_SAFELEN
);
4669 OMP_CLAUSE_SAFELEN_EXPR (c
) = build_int_cst (integer_type_node
,
4671 OMP_CLAUSE_CHAIN (c
) = gimple_omp_for_clauses (ctx
->stmt
);
4672 gimple_omp_for_set_clauses (ctx
->stmt
, c
);
4678 /* Generate code to implement the LASTPRIVATE clauses. This is used for
4679 both parallel and workshare constructs. PREDICATE may be NULL if it's
4683 lower_lastprivate_clauses (tree clauses
, tree predicate
, gimple_seq
*stmt_list
,
4686 tree x
, c
, label
= NULL
, orig_clauses
= clauses
;
4687 bool par_clauses
= false;
4688 tree simduid
= NULL
, lastlane
= NULL
, simtcond
= NULL
, simtlast
= NULL
;
4690 /* Early exit if there are no lastprivate or linear clauses. */
4691 for (; clauses
; clauses
= OMP_CLAUSE_CHAIN (clauses
))
4692 if (OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_LASTPRIVATE
4693 || (OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_LINEAR
4694 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (clauses
)))
4696 if (clauses
== NULL
)
4698 /* If this was a workshare clause, see if it had been combined
4699 with its parallel. In that case, look for the clauses on the
4700 parallel statement itself. */
4701 if (is_parallel_ctx (ctx
))
4705 if (ctx
== NULL
|| !is_parallel_ctx (ctx
))
4708 clauses
= omp_find_clause (gimple_omp_parallel_clauses (ctx
->stmt
),
4709 OMP_CLAUSE_LASTPRIVATE
);
4710 if (clauses
== NULL
)
4715 bool maybe_simt
= false;
4716 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
4717 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
)
4719 maybe_simt
= omp_find_clause (orig_clauses
, OMP_CLAUSE__SIMT_
);
4720 simduid
= omp_find_clause (orig_clauses
, OMP_CLAUSE__SIMDUID_
);
4722 simduid
= OMP_CLAUSE__SIMDUID__DECL (simduid
);
4728 tree label_true
, arm1
, arm2
;
4729 enum tree_code pred_code
= TREE_CODE (predicate
);
4731 label
= create_artificial_label (UNKNOWN_LOCATION
);
4732 label_true
= create_artificial_label (UNKNOWN_LOCATION
);
4733 if (TREE_CODE_CLASS (pred_code
) == tcc_comparison
)
4735 arm1
= TREE_OPERAND (predicate
, 0);
4736 arm2
= TREE_OPERAND (predicate
, 1);
4737 gimplify_expr (&arm1
, stmt_list
, NULL
, is_gimple_val
, fb_rvalue
);
4738 gimplify_expr (&arm2
, stmt_list
, NULL
, is_gimple_val
, fb_rvalue
);
4743 gimplify_expr (&arm1
, stmt_list
, NULL
, is_gimple_val
, fb_rvalue
);
4744 arm2
= boolean_false_node
;
4745 pred_code
= NE_EXPR
;
4749 c
= build2 (pred_code
, boolean_type_node
, arm1
, arm2
);
4750 c
= fold_convert (integer_type_node
, c
);
4751 simtcond
= create_tmp_var (integer_type_node
);
4752 gimplify_assign (simtcond
, c
, stmt_list
);
4753 gcall
*g
= gimple_build_call_internal (IFN_GOMP_SIMT_VOTE_ANY
,
4755 c
= create_tmp_var (integer_type_node
);
4756 gimple_call_set_lhs (g
, c
);
4757 gimple_seq_add_stmt (stmt_list
, g
);
4758 stmt
= gimple_build_cond (NE_EXPR
, c
, integer_zero_node
,
4762 stmt
= gimple_build_cond (pred_code
, arm1
, arm2
, label_true
, label
);
4763 gimple_seq_add_stmt (stmt_list
, stmt
);
4764 gimple_seq_add_stmt (stmt_list
, gimple_build_label (label_true
));
4767 for (c
= clauses
; c
;)
4770 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
4772 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
4773 || (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
4774 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)))
4776 var
= OMP_CLAUSE_DECL (c
);
4777 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
4778 && OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
)
4779 && is_taskloop_ctx (ctx
))
4781 gcc_checking_assert (ctx
->outer
&& is_task_ctx (ctx
->outer
));
4782 new_var
= lookup_decl (var
, ctx
->outer
);
4786 new_var
= lookup_decl (var
, ctx
);
4787 /* Avoid uninitialized warnings for lastprivate and
4788 for linear iterators. */
4790 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
4791 || OMP_CLAUSE_LINEAR_NO_COPYIN (c
)))
4792 TREE_NO_WARNING (new_var
) = 1;
4795 if (!maybe_simt
&& simduid
&& DECL_HAS_VALUE_EXPR_P (new_var
))
4797 tree val
= DECL_VALUE_EXPR (new_var
);
4798 if (TREE_CODE (val
) == ARRAY_REF
4799 && VAR_P (TREE_OPERAND (val
, 0))
4800 && lookup_attribute ("omp simd array",
4801 DECL_ATTRIBUTES (TREE_OPERAND (val
,
4804 if (lastlane
== NULL
)
4806 lastlane
= create_tmp_var (unsigned_type_node
);
4808 = gimple_build_call_internal (IFN_GOMP_SIMD_LAST_LANE
,
4810 TREE_OPERAND (val
, 1));
4811 gimple_call_set_lhs (g
, lastlane
);
4812 gimple_seq_add_stmt (stmt_list
, g
);
4814 new_var
= build4 (ARRAY_REF
, TREE_TYPE (val
),
4815 TREE_OPERAND (val
, 0), lastlane
,
4816 NULL_TREE
, NULL_TREE
);
4819 else if (maybe_simt
)
4821 tree val
= (DECL_HAS_VALUE_EXPR_P (new_var
)
4822 ? DECL_VALUE_EXPR (new_var
)
4824 if (simtlast
== NULL
)
4826 simtlast
= create_tmp_var (unsigned_type_node
);
4827 gcall
*g
= gimple_build_call_internal
4828 (IFN_GOMP_SIMT_LAST_LANE
, 1, simtcond
);
4829 gimple_call_set_lhs (g
, simtlast
);
4830 gimple_seq_add_stmt (stmt_list
, g
);
4832 x
= build_call_expr_internal_loc
4833 (UNKNOWN_LOCATION
, IFN_GOMP_SIMT_XCHG_IDX
,
4834 TREE_TYPE (val
), 2, val
, simtlast
);
4835 new_var
= unshare_expr (new_var
);
4836 gimplify_assign (new_var
, x
, stmt_list
);
4837 new_var
= unshare_expr (new_var
);
4840 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
4841 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
))
4843 lower_omp (&OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
), ctx
);
4844 gimple_seq_add_seq (stmt_list
,
4845 OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
));
4846 OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
) = NULL
;
4848 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
4849 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
))
4851 lower_omp (&OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
), ctx
);
4852 gimple_seq_add_seq (stmt_list
,
4853 OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
));
4854 OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
) = NULL
;
4858 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
4859 && OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
))
4861 gcc_checking_assert (is_taskloop_ctx (ctx
));
4862 tree ovar
= maybe_lookup_decl_in_outer_ctx (var
,
4864 if (is_global_var (ovar
))
4868 x
= build_outer_var_ref (var
, ctx
, OMP_CLAUSE_LASTPRIVATE
);
4869 if (omp_is_reference (var
))
4870 new_var
= build_simple_mem_ref_loc (clause_loc
, new_var
);
4871 x
= lang_hooks
.decls
.omp_clause_assign_op (c
, x
, new_var
);
4872 gimplify_and_add (x
, stmt_list
);
4874 c
= OMP_CLAUSE_CHAIN (c
);
4875 if (c
== NULL
&& !par_clauses
)
4877 /* If this was a workshare clause, see if it had been combined
4878 with its parallel. In that case, continue looking for the
4879 clauses also on the parallel statement itself. */
4880 if (is_parallel_ctx (ctx
))
4884 if (ctx
== NULL
|| !is_parallel_ctx (ctx
))
4887 c
= omp_find_clause (gimple_omp_parallel_clauses (ctx
->stmt
),
4888 OMP_CLAUSE_LASTPRIVATE
);
4894 gimple_seq_add_stmt (stmt_list
, gimple_build_label (label
));
4897 /* Lower the OpenACC reductions of CLAUSES for compute axis LEVEL
4898 (which might be a placeholder). INNER is true if this is an inner
4899 axis of a multi-axis loop. FORK and JOIN are (optional) fork and
4900 join markers. Generate the before-loop forking sequence in
4901 FORK_SEQ and the after-loop joining sequence to JOIN_SEQ. The
4902 general form of these sequences is
4904 GOACC_REDUCTION_SETUP
4906 GOACC_REDUCTION_INIT
4908 GOACC_REDUCTION_FINI
4910 GOACC_REDUCTION_TEARDOWN. */
4913 lower_oacc_reductions (location_t loc
, tree clauses
, tree level
, bool inner
,
4914 gcall
*fork
, gcall
*join
, gimple_seq
*fork_seq
,
4915 gimple_seq
*join_seq
, omp_context
*ctx
)
4917 gimple_seq before_fork
= NULL
;
4918 gimple_seq after_fork
= NULL
;
4919 gimple_seq before_join
= NULL
;
4920 gimple_seq after_join
= NULL
;
4921 tree init_code
= NULL_TREE
, fini_code
= NULL_TREE
,
4922 setup_code
= NULL_TREE
, teardown_code
= NULL_TREE
;
4923 unsigned offset
= 0;
4925 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
4926 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4928 tree orig
= OMP_CLAUSE_DECL (c
);
4929 tree var
= maybe_lookup_decl (orig
, ctx
);
4930 tree ref_to_res
= NULL_TREE
;
4931 tree incoming
, outgoing
, v1
, v2
, v3
;
4932 bool is_private
= false;
4934 enum tree_code rcode
= OMP_CLAUSE_REDUCTION_CODE (c
);
4935 if (rcode
== MINUS_EXPR
)
4937 else if (rcode
== TRUTH_ANDIF_EXPR
)
4938 rcode
= BIT_AND_EXPR
;
4939 else if (rcode
== TRUTH_ORIF_EXPR
)
4940 rcode
= BIT_IOR_EXPR
;
4941 tree op
= build_int_cst (unsigned_type_node
, rcode
);
4946 incoming
= outgoing
= var
;
4950 /* See if an outer construct also reduces this variable. */
4951 omp_context
*outer
= ctx
;
4953 while (omp_context
*probe
= outer
->outer
)
4955 enum gimple_code type
= gimple_code (probe
->stmt
);
4960 case GIMPLE_OMP_FOR
:
4961 cls
= gimple_omp_for_clauses (probe
->stmt
);
4964 case GIMPLE_OMP_TARGET
:
4965 if (gimple_omp_target_kind (probe
->stmt
)
4966 != GF_OMP_TARGET_KIND_OACC_PARALLEL
)
4969 cls
= gimple_omp_target_clauses (probe
->stmt
);
4977 for (; cls
; cls
= OMP_CLAUSE_CHAIN (cls
))
4978 if (OMP_CLAUSE_CODE (cls
) == OMP_CLAUSE_REDUCTION
4979 && orig
== OMP_CLAUSE_DECL (cls
))
4981 incoming
= outgoing
= lookup_decl (orig
, probe
);
4982 goto has_outer_reduction
;
4984 else if ((OMP_CLAUSE_CODE (cls
) == OMP_CLAUSE_FIRSTPRIVATE
4985 || OMP_CLAUSE_CODE (cls
) == OMP_CLAUSE_PRIVATE
)
4986 && orig
== OMP_CLAUSE_DECL (cls
))
4994 /* This is the outermost construct with this reduction,
4995 see if there's a mapping for it. */
4996 if (gimple_code (outer
->stmt
) == GIMPLE_OMP_TARGET
4997 && maybe_lookup_field (orig
, outer
) && !is_private
)
4999 ref_to_res
= build_receiver_ref (orig
, false, outer
);
5000 if (omp_is_reference (orig
))
5001 ref_to_res
= build_simple_mem_ref (ref_to_res
);
5003 tree type
= TREE_TYPE (var
);
5004 if (POINTER_TYPE_P (type
))
5005 type
= TREE_TYPE (type
);
5008 incoming
= omp_reduction_init_op (loc
, rcode
, type
);
5012 /* Try to look at enclosing contexts for reduction var,
5013 use original if no mapping found. */
5015 omp_context
*c
= ctx
->outer
;
5018 t
= maybe_lookup_decl (orig
, c
);
5021 incoming
= outgoing
= (t
? t
: orig
);
5024 has_outer_reduction
:;
5028 ref_to_res
= integer_zero_node
;
5030 if (omp_is_reference (orig
))
5032 tree type
= TREE_TYPE (var
);
5033 const char *id
= IDENTIFIER_POINTER (DECL_NAME (var
));
5037 tree x
= create_tmp_var (TREE_TYPE (type
), id
);
5038 gimplify_assign (var
, build_fold_addr_expr (x
), fork_seq
);
5041 v1
= create_tmp_var (type
, id
);
5042 v2
= create_tmp_var (type
, id
);
5043 v3
= create_tmp_var (type
, id
);
5045 gimplify_assign (v1
, var
, fork_seq
);
5046 gimplify_assign (v2
, var
, fork_seq
);
5047 gimplify_assign (v3
, var
, fork_seq
);
5049 var
= build_simple_mem_ref (var
);
5050 v1
= build_simple_mem_ref (v1
);
5051 v2
= build_simple_mem_ref (v2
);
5052 v3
= build_simple_mem_ref (v3
);
5053 outgoing
= build_simple_mem_ref (outgoing
);
5055 if (!TREE_CONSTANT (incoming
))
5056 incoming
= build_simple_mem_ref (incoming
);
5061 /* Determine position in reduction buffer, which may be used
5063 machine_mode mode
= TYPE_MODE (TREE_TYPE (var
));
5064 unsigned align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
5065 offset
= (offset
+ align
- 1) & ~(align
- 1);
5066 tree off
= build_int_cst (sizetype
, offset
);
5067 offset
+= GET_MODE_SIZE (mode
);
5071 init_code
= build_int_cst (integer_type_node
,
5072 IFN_GOACC_REDUCTION_INIT
);
5073 fini_code
= build_int_cst (integer_type_node
,
5074 IFN_GOACC_REDUCTION_FINI
);
5075 setup_code
= build_int_cst (integer_type_node
,
5076 IFN_GOACC_REDUCTION_SETUP
);
5077 teardown_code
= build_int_cst (integer_type_node
,
5078 IFN_GOACC_REDUCTION_TEARDOWN
);
5082 = build_call_expr_internal_loc (loc
, IFN_GOACC_REDUCTION
,
5083 TREE_TYPE (var
), 6, setup_code
,
5084 unshare_expr (ref_to_res
),
5085 incoming
, level
, op
, off
);
5087 = build_call_expr_internal_loc (loc
, IFN_GOACC_REDUCTION
,
5088 TREE_TYPE (var
), 6, init_code
,
5089 unshare_expr (ref_to_res
),
5090 v1
, level
, op
, off
);
5092 = build_call_expr_internal_loc (loc
, IFN_GOACC_REDUCTION
,
5093 TREE_TYPE (var
), 6, fini_code
,
5094 unshare_expr (ref_to_res
),
5095 v2
, level
, op
, off
);
5097 = build_call_expr_internal_loc (loc
, IFN_GOACC_REDUCTION
,
5098 TREE_TYPE (var
), 6, teardown_code
,
5099 ref_to_res
, v3
, level
, op
, off
);
5101 gimplify_assign (v1
, setup_call
, &before_fork
);
5102 gimplify_assign (v2
, init_call
, &after_fork
);
5103 gimplify_assign (v3
, fini_call
, &before_join
);
5104 gimplify_assign (outgoing
, teardown_call
, &after_join
);
5107 /* Now stitch things together. */
5108 gimple_seq_add_seq (fork_seq
, before_fork
);
5110 gimple_seq_add_stmt (fork_seq
, fork
);
5111 gimple_seq_add_seq (fork_seq
, after_fork
);
5113 gimple_seq_add_seq (join_seq
, before_join
);
5115 gimple_seq_add_stmt (join_seq
, join
);
5116 gimple_seq_add_seq (join_seq
, after_join
);
5119 /* Generate code to implement the REDUCTION clauses. */
5122 lower_reduction_clauses (tree clauses
, gimple_seq
*stmt_seqp
, omp_context
*ctx
)
5124 gimple_seq sub_seq
= NULL
;
5129 /* OpenACC loop reductions are handled elsewhere. */
5130 if (is_gimple_omp_oacc (ctx
->stmt
))
5133 /* SIMD reductions are handled in lower_rec_input_clauses. */
5134 if (gimple_code (ctx
->stmt
) == GIMPLE_OMP_FOR
5135 && gimple_omp_for_kind (ctx
->stmt
) & GF_OMP_FOR_SIMD
)
5138 /* First see if there is exactly one reduction clause. Use OMP_ATOMIC
5139 update in that case, otherwise use a lock. */
5140 for (c
= clauses
; c
&& count
< 2; c
= OMP_CLAUSE_CHAIN (c
))
5141 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
5143 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
5144 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5146 /* Never use OMP_ATOMIC for array reductions or UDRs. */
5156 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5158 tree var
, ref
, new_var
, orig_var
;
5159 enum tree_code code
;
5160 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
5162 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
5165 enum omp_clause_code ccode
= OMP_CLAUSE_REDUCTION
;
5166 orig_var
= var
= OMP_CLAUSE_DECL (c
);
5167 if (TREE_CODE (var
) == MEM_REF
)
5169 var
= TREE_OPERAND (var
, 0);
5170 if (TREE_CODE (var
) == POINTER_PLUS_EXPR
)
5171 var
= TREE_OPERAND (var
, 0);
5172 if (TREE_CODE (var
) == ADDR_EXPR
)
5173 var
= TREE_OPERAND (var
, 0);
5176 /* If this is a pointer or referenced based array
5177 section, the var could be private in the outer
5178 context e.g. on orphaned loop construct. Pretend this
5179 is private variable's outer reference. */
5180 ccode
= OMP_CLAUSE_PRIVATE
;
5181 if (TREE_CODE (var
) == INDIRECT_REF
)
5182 var
= TREE_OPERAND (var
, 0);
5185 if (is_variable_sized (var
))
5187 gcc_assert (DECL_HAS_VALUE_EXPR_P (var
));
5188 var
= DECL_VALUE_EXPR (var
);
5189 gcc_assert (TREE_CODE (var
) == INDIRECT_REF
);
5190 var
= TREE_OPERAND (var
, 0);
5191 gcc_assert (DECL_P (var
));
5194 new_var
= lookup_decl (var
, ctx
);
5195 if (var
== OMP_CLAUSE_DECL (c
) && omp_is_reference (var
))
5196 new_var
= build_simple_mem_ref_loc (clause_loc
, new_var
);
5197 ref
= build_outer_var_ref (var
, ctx
, ccode
);
5198 code
= OMP_CLAUSE_REDUCTION_CODE (c
);
5200 /* reduction(-:var) sums up the partial results, so it acts
5201 identically to reduction(+:var). */
5202 if (code
== MINUS_EXPR
)
5207 tree addr
= build_fold_addr_expr_loc (clause_loc
, ref
);
5209 addr
= save_expr (addr
);
5210 ref
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (addr
)), addr
);
5211 x
= fold_build2_loc (clause_loc
, code
, TREE_TYPE (ref
), ref
, new_var
);
5212 x
= build2 (OMP_ATOMIC
, void_type_node
, addr
, x
);
5213 gimplify_and_add (x
, stmt_seqp
);
5216 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5218 tree d
= OMP_CLAUSE_DECL (c
);
5219 tree type
= TREE_TYPE (d
);
5220 tree v
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
5221 tree i
= create_tmp_var (TREE_TYPE (v
), NULL
);
5222 tree ptype
= build_pointer_type (TREE_TYPE (type
));
5223 tree bias
= TREE_OPERAND (d
, 1);
5224 d
= TREE_OPERAND (d
, 0);
5225 if (TREE_CODE (d
) == POINTER_PLUS_EXPR
)
5227 tree b
= TREE_OPERAND (d
, 1);
5228 b
= maybe_lookup_decl (b
, ctx
);
5231 b
= TREE_OPERAND (d
, 1);
5232 b
= maybe_lookup_decl_in_outer_ctx (b
, ctx
);
5234 if (integer_zerop (bias
))
5238 bias
= fold_convert_loc (clause_loc
, TREE_TYPE (b
), bias
);
5239 bias
= fold_build2_loc (clause_loc
, PLUS_EXPR
,
5240 TREE_TYPE (b
), b
, bias
);
5242 d
= TREE_OPERAND (d
, 0);
5244 /* For ref build_outer_var_ref already performs this, so
5245 only new_var needs a dereference. */
5246 if (TREE_CODE (d
) == INDIRECT_REF
)
5248 new_var
= build_simple_mem_ref_loc (clause_loc
, new_var
);
5249 gcc_assert (omp_is_reference (var
) && var
== orig_var
);
5251 else if (TREE_CODE (d
) == ADDR_EXPR
)
5253 if (orig_var
== var
)
5255 new_var
= build_fold_addr_expr (new_var
);
5256 ref
= build_fold_addr_expr (ref
);
5261 gcc_assert (orig_var
== var
);
5262 if (omp_is_reference (var
))
5263 ref
= build_fold_addr_expr (ref
);
5267 tree t
= maybe_lookup_decl (v
, ctx
);
5271 v
= maybe_lookup_decl_in_outer_ctx (v
, ctx
);
5272 gimplify_expr (&v
, stmt_seqp
, NULL
, is_gimple_val
, fb_rvalue
);
5274 if (!integer_zerop (bias
))
5276 bias
= fold_convert_loc (clause_loc
, sizetype
, bias
);
5277 new_var
= fold_build2_loc (clause_loc
, POINTER_PLUS_EXPR
,
5278 TREE_TYPE (new_var
), new_var
,
5279 unshare_expr (bias
));
5280 ref
= fold_build2_loc (clause_loc
, POINTER_PLUS_EXPR
,
5281 TREE_TYPE (ref
), ref
, bias
);
5283 new_var
= fold_convert_loc (clause_loc
, ptype
, new_var
);
5284 ref
= fold_convert_loc (clause_loc
, ptype
, ref
);
5285 tree m
= create_tmp_var (ptype
, NULL
);
5286 gimplify_assign (m
, new_var
, stmt_seqp
);
5288 m
= create_tmp_var (ptype
, NULL
);
5289 gimplify_assign (m
, ref
, stmt_seqp
);
5291 gimplify_assign (i
, build_int_cst (TREE_TYPE (v
), 0), stmt_seqp
);
5292 tree body
= create_artificial_label (UNKNOWN_LOCATION
);
5293 tree end
= create_artificial_label (UNKNOWN_LOCATION
);
5294 gimple_seq_add_stmt (&sub_seq
, gimple_build_label (body
));
5295 tree priv
= build_simple_mem_ref_loc (clause_loc
, new_var
);
5296 tree out
= build_simple_mem_ref_loc (clause_loc
, ref
);
5297 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5299 tree placeholder
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5300 tree decl_placeholder
5301 = OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
);
5302 SET_DECL_VALUE_EXPR (placeholder
, out
);
5303 DECL_HAS_VALUE_EXPR_P (placeholder
) = 1;
5304 SET_DECL_VALUE_EXPR (decl_placeholder
, priv
);
5305 DECL_HAS_VALUE_EXPR_P (decl_placeholder
) = 1;
5306 lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
), ctx
);
5307 gimple_seq_add_seq (&sub_seq
,
5308 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
));
5309 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
5310 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL
;
5311 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = NULL
;
5315 x
= build2 (code
, TREE_TYPE (out
), out
, priv
);
5316 out
= unshare_expr (out
);
5317 gimplify_assign (out
, x
, &sub_seq
);
5319 gimple
*g
= gimple_build_assign (new_var
, POINTER_PLUS_EXPR
, new_var
,
5320 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
5321 gimple_seq_add_stmt (&sub_seq
, g
);
5322 g
= gimple_build_assign (ref
, POINTER_PLUS_EXPR
, ref
,
5323 TYPE_SIZE_UNIT (TREE_TYPE (type
)));
5324 gimple_seq_add_stmt (&sub_seq
, g
);
5325 g
= gimple_build_assign (i
, PLUS_EXPR
, i
,
5326 build_int_cst (TREE_TYPE (i
), 1));
5327 gimple_seq_add_stmt (&sub_seq
, g
);
5328 g
= gimple_build_cond (LE_EXPR
, i
, v
, body
, end
);
5329 gimple_seq_add_stmt (&sub_seq
, g
);
5330 gimple_seq_add_stmt (&sub_seq
, gimple_build_label (end
));
5332 else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5334 tree placeholder
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5336 if (omp_is_reference (var
)
5337 && !useless_type_conversion_p (TREE_TYPE (placeholder
),
5339 ref
= build_fold_addr_expr_loc (clause_loc
, ref
);
5340 SET_DECL_VALUE_EXPR (placeholder
, ref
);
5341 DECL_HAS_VALUE_EXPR_P (placeholder
) = 1;
5342 lower_omp (&OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
), ctx
);
5343 gimple_seq_add_seq (&sub_seq
, OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
));
5344 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
5345 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL
;
5349 x
= build2 (code
, TREE_TYPE (ref
), ref
, new_var
);
5350 ref
= build_outer_var_ref (var
, ctx
);
5351 gimplify_assign (ref
, x
, &sub_seq
);
5355 stmt
= gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_START
),
5357 gimple_seq_add_stmt (stmt_seqp
, stmt
);
5359 gimple_seq_add_seq (stmt_seqp
, sub_seq
);
5361 stmt
= gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END
),
5363 gimple_seq_add_stmt (stmt_seqp
, stmt
);
5367 /* Generate code to implement the COPYPRIVATE clauses. */
5370 lower_copyprivate_clauses (tree clauses
, gimple_seq
*slist
, gimple_seq
*rlist
,
5375 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5377 tree var
, new_var
, ref
, x
;
5379 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
5381 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_COPYPRIVATE
)
5384 var
= OMP_CLAUSE_DECL (c
);
5385 by_ref
= use_pointer_for_field (var
, NULL
);
5387 ref
= build_sender_ref (var
, ctx
);
5388 x
= new_var
= lookup_decl_in_outer_ctx (var
, ctx
);
5391 x
= build_fold_addr_expr_loc (clause_loc
, new_var
);
5392 x
= fold_convert_loc (clause_loc
, TREE_TYPE (ref
), x
);
5394 gimplify_assign (ref
, x
, slist
);
5396 ref
= build_receiver_ref (var
, false, ctx
);
5399 ref
= fold_convert_loc (clause_loc
,
5400 build_pointer_type (TREE_TYPE (new_var
)),
5402 ref
= build_fold_indirect_ref_loc (clause_loc
, ref
);
5404 if (omp_is_reference (var
))
5406 ref
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), ref
);
5407 ref
= build_simple_mem_ref_loc (clause_loc
, ref
);
5408 new_var
= build_simple_mem_ref_loc (clause_loc
, new_var
);
5410 x
= lang_hooks
.decls
.omp_clause_assign_op (c
, new_var
, ref
);
5411 gimplify_and_add (x
, rlist
);
5416 /* Generate code to implement the clauses, FIRSTPRIVATE, COPYIN, LASTPRIVATE,
5417 and REDUCTION from the sender (aka parent) side. */
5420 lower_send_clauses (tree clauses
, gimple_seq
*ilist
, gimple_seq
*olist
,
5424 int ignored_looptemp
= 0;
5425 bool is_taskloop
= false;
5427 /* For taskloop, ignore first two _looptemp_ clauses, those are initialized
5428 by GOMP_taskloop. */
5429 if (is_task_ctx (ctx
) && gimple_omp_task_taskloop_p (ctx
->stmt
))
5431 ignored_looptemp
= 2;
5435 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5437 tree val
, ref
, x
, var
;
5438 bool by_ref
, do_in
= false, do_out
= false;
5439 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
5441 switch (OMP_CLAUSE_CODE (c
))
5443 case OMP_CLAUSE_PRIVATE
:
5444 if (OMP_CLAUSE_PRIVATE_OUTER_REF (c
))
5447 case OMP_CLAUSE_FIRSTPRIVATE
:
5448 case OMP_CLAUSE_COPYIN
:
5449 case OMP_CLAUSE_LASTPRIVATE
:
5450 case OMP_CLAUSE_REDUCTION
:
5452 case OMP_CLAUSE_SHARED
:
5453 if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
5456 case OMP_CLAUSE__LOOPTEMP_
:
5457 if (ignored_looptemp
)
5467 val
= OMP_CLAUSE_DECL (c
);
5468 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5469 && TREE_CODE (val
) == MEM_REF
)
5471 val
= TREE_OPERAND (val
, 0);
5472 if (TREE_CODE (val
) == POINTER_PLUS_EXPR
)
5473 val
= TREE_OPERAND (val
, 0);
5474 if (TREE_CODE (val
) == INDIRECT_REF
5475 || TREE_CODE (val
) == ADDR_EXPR
)
5476 val
= TREE_OPERAND (val
, 0);
5477 if (is_variable_sized (val
))
5481 /* For OMP_CLAUSE_SHARED_FIRSTPRIVATE, look beyond the
5482 outer taskloop region. */
5483 omp_context
*ctx_for_o
= ctx
;
5485 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
5486 && OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
5487 ctx_for_o
= ctx
->outer
;
5489 var
= lookup_decl_in_outer_ctx (val
, ctx_for_o
);
5491 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_COPYIN
5492 && is_global_var (var
))
5495 t
= omp_member_access_dummy_var (var
);
5498 var
= DECL_VALUE_EXPR (var
);
5499 tree o
= maybe_lookup_decl_in_outer_ctx (t
, ctx_for_o
);
5501 var
= unshare_and_remap (var
, t
, o
);
5503 var
= unshare_expr (var
);
5506 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
)
5508 /* Handle taskloop firstprivate/lastprivate, where the
5509 lastprivate on GIMPLE_OMP_TASK is represented as
5510 OMP_CLAUSE_SHARED_FIRSTPRIVATE. */
5511 tree f
= lookup_sfield ((splay_tree_key
) &DECL_UID (val
), ctx
);
5512 x
= omp_build_component_ref (ctx
->sender_decl
, f
);
5513 if (use_pointer_for_field (val
, ctx
))
5514 var
= build_fold_addr_expr (var
);
5515 gimplify_assign (x
, var
, ilist
);
5516 DECL_ABSTRACT_ORIGIN (f
) = NULL
;
5520 if ((OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5521 || val
== OMP_CLAUSE_DECL (c
))
5522 && is_variable_sized (val
))
5524 by_ref
= use_pointer_for_field (val
, NULL
);
5526 switch (OMP_CLAUSE_CODE (c
))
5528 case OMP_CLAUSE_FIRSTPRIVATE
:
5529 if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
5531 && is_task_ctx (ctx
))
5532 TREE_NO_WARNING (var
) = 1;
5536 case OMP_CLAUSE_PRIVATE
:
5537 case OMP_CLAUSE_COPYIN
:
5538 case OMP_CLAUSE__LOOPTEMP_
:
5542 case OMP_CLAUSE_LASTPRIVATE
:
5543 if (by_ref
|| omp_is_reference (val
))
5545 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
5552 if (lang_hooks
.decls
.omp_private_outer_ref (val
))
5557 case OMP_CLAUSE_REDUCTION
:
5559 if (val
== OMP_CLAUSE_DECL (c
))
5560 do_out
= !(by_ref
|| omp_is_reference (val
));
5562 by_ref
= TREE_CODE (TREE_TYPE (val
)) == ARRAY_TYPE
;
5571 ref
= build_sender_ref (val
, ctx
);
5572 x
= by_ref
? build_fold_addr_expr_loc (clause_loc
, var
) : var
;
5573 gimplify_assign (ref
, x
, ilist
);
5574 if (is_task_ctx (ctx
))
5575 DECL_ABSTRACT_ORIGIN (TREE_OPERAND (ref
, 1)) = NULL
;
5580 ref
= build_sender_ref (val
, ctx
);
5581 gimplify_assign (var
, ref
, olist
);
5586 /* Generate code to implement SHARED from the sender (aka parent)
5587 side. This is trickier, since GIMPLE_OMP_PARALLEL_CLAUSES doesn't
5588 list things that got automatically shared. */
5591 lower_send_shared_vars (gimple_seq
*ilist
, gimple_seq
*olist
, omp_context
*ctx
)
5593 tree var
, ovar
, nvar
, t
, f
, x
, record_type
;
5595 if (ctx
->record_type
== NULL
)
5598 record_type
= ctx
->srecord_type
? ctx
->srecord_type
: ctx
->record_type
;
5599 for (f
= TYPE_FIELDS (record_type
); f
; f
= DECL_CHAIN (f
))
5601 ovar
= DECL_ABSTRACT_ORIGIN (f
);
5602 if (!ovar
|| TREE_CODE (ovar
) == FIELD_DECL
)
5605 nvar
= maybe_lookup_decl (ovar
, ctx
);
5606 if (!nvar
|| !DECL_HAS_VALUE_EXPR_P (nvar
))
5609 /* If CTX is a nested parallel directive. Find the immediately
5610 enclosing parallel or workshare construct that contains a
5611 mapping for OVAR. */
5612 var
= lookup_decl_in_outer_ctx (ovar
, ctx
);
5614 t
= omp_member_access_dummy_var (var
);
5617 var
= DECL_VALUE_EXPR (var
);
5618 tree o
= maybe_lookup_decl_in_outer_ctx (t
, ctx
);
5620 var
= unshare_and_remap (var
, t
, o
);
5622 var
= unshare_expr (var
);
5625 if (use_pointer_for_field (ovar
, ctx
))
5627 x
= build_sender_ref (ovar
, ctx
);
5628 var
= build_fold_addr_expr (var
);
5629 gimplify_assign (x
, var
, ilist
);
5633 x
= build_sender_ref (ovar
, ctx
);
5634 gimplify_assign (x
, var
, ilist
);
5636 if (!TREE_READONLY (var
)
5637 /* We don't need to receive a new reference to a result
5638 or parm decl. In fact we may not store to it as we will
5639 invalidate any pending RSO and generate wrong gimple
5641 && !((TREE_CODE (var
) == RESULT_DECL
5642 || TREE_CODE (var
) == PARM_DECL
)
5643 && DECL_BY_REFERENCE (var
)))
5645 x
= build_sender_ref (ovar
, ctx
);
5646 gimplify_assign (var
, x
, olist
);
5652 /* Emit an OpenACC head marker call, encapulating the partitioning and
5653 other information that must be processed by the target compiler.
5654 Return the maximum number of dimensions the associated loop might
5655 be partitioned over. */
5658 lower_oacc_head_mark (location_t loc
, tree ddvar
, tree clauses
,
5659 gimple_seq
*seq
, omp_context
*ctx
)
5661 unsigned levels
= 0;
5663 tree gang_static
= NULL_TREE
;
5664 auto_vec
<tree
, 5> args
;
5666 args
.quick_push (build_int_cst
5667 (integer_type_node
, IFN_UNIQUE_OACC_HEAD_MARK
));
5668 args
.quick_push (ddvar
);
5669 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5671 switch (OMP_CLAUSE_CODE (c
))
5673 case OMP_CLAUSE_GANG
:
5674 tag
|= OLF_DIM_GANG
;
5675 gang_static
= OMP_CLAUSE_GANG_STATIC_EXPR (c
);
5676 /* static:* is represented by -1, and we can ignore it, as
5677 scheduling is always static. */
5678 if (gang_static
&& integer_minus_onep (gang_static
))
5679 gang_static
= NULL_TREE
;
5683 case OMP_CLAUSE_WORKER
:
5684 tag
|= OLF_DIM_WORKER
;
5688 case OMP_CLAUSE_VECTOR
:
5689 tag
|= OLF_DIM_VECTOR
;
5693 case OMP_CLAUSE_SEQ
:
5697 case OMP_CLAUSE_AUTO
:
5701 case OMP_CLAUSE_INDEPENDENT
:
5702 tag
|= OLF_INDEPENDENT
;
5705 case OMP_CLAUSE_TILE
:
5716 if (DECL_P (gang_static
))
5717 gang_static
= build_outer_var_ref (gang_static
, ctx
);
5718 tag
|= OLF_GANG_STATIC
;
5721 /* In a parallel region, loops are implicitly INDEPENDENT. */
5722 omp_context
*tgt
= enclosing_target_ctx (ctx
);
5723 if (!tgt
|| is_oacc_parallel (tgt
))
5724 tag
|= OLF_INDEPENDENT
;
5727 /* Tiling could use all 3 levels. */
5731 /* A loop lacking SEQ, GANG, WORKER and/or VECTOR could be AUTO.
5732 Ensure at least one level, or 2 for possible auto
5734 bool maybe_auto
= !(tag
& (((GOMP_DIM_MASK (GOMP_DIM_MAX
) - 1)
5735 << OLF_DIM_BASE
) | OLF_SEQ
));
5737 if (levels
< 1u + maybe_auto
)
5738 levels
= 1u + maybe_auto
;
5741 args
.quick_push (build_int_cst (integer_type_node
, levels
));
5742 args
.quick_push (build_int_cst (integer_type_node
, tag
));
5744 args
.quick_push (gang_static
);
5746 gcall
*call
= gimple_build_call_internal_vec (IFN_UNIQUE
, args
);
5747 gimple_set_location (call
, loc
);
5748 gimple_set_lhs (call
, ddvar
);
5749 gimple_seq_add_stmt (seq
, call
);
5754 /* Emit an OpenACC lopp head or tail marker to SEQ. LEVEL is the
5755 partitioning level of the enclosed region. */
5758 lower_oacc_loop_marker (location_t loc
, tree ddvar
, bool head
,
5759 tree tofollow
, gimple_seq
*seq
)
5761 int marker_kind
= (head
? IFN_UNIQUE_OACC_HEAD_MARK
5762 : IFN_UNIQUE_OACC_TAIL_MARK
);
5763 tree marker
= build_int_cst (integer_type_node
, marker_kind
);
5764 int nargs
= 2 + (tofollow
!= NULL_TREE
);
5765 gcall
*call
= gimple_build_call_internal (IFN_UNIQUE
, nargs
,
5766 marker
, ddvar
, tofollow
);
5767 gimple_set_location (call
, loc
);
5768 gimple_set_lhs (call
, ddvar
);
5769 gimple_seq_add_stmt (seq
, call
);
5772 /* Generate the before and after OpenACC loop sequences. CLAUSES are
5773 the loop clauses, from which we extract reductions. Initialize
5777 lower_oacc_head_tail (location_t loc
, tree clauses
,
5778 gimple_seq
*head
, gimple_seq
*tail
, omp_context
*ctx
)
5781 tree ddvar
= create_tmp_var (integer_type_node
, ".data_dep");
5782 gimple_seq_add_stmt (head
, gimple_build_assign (ddvar
, integer_zero_node
));
5784 unsigned count
= lower_oacc_head_mark (loc
, ddvar
, clauses
, head
, ctx
);
5785 tree fork_kind
= build_int_cst (unsigned_type_node
, IFN_UNIQUE_OACC_FORK
);
5786 tree join_kind
= build_int_cst (unsigned_type_node
, IFN_UNIQUE_OACC_JOIN
);
5789 for (unsigned done
= 1; count
; count
--, done
++)
5791 gimple_seq fork_seq
= NULL
;
5792 gimple_seq join_seq
= NULL
;
5794 tree place
= build_int_cst (integer_type_node
, -1);
5795 gcall
*fork
= gimple_build_call_internal (IFN_UNIQUE
, 3,
5796 fork_kind
, ddvar
, place
);
5797 gimple_set_location (fork
, loc
);
5798 gimple_set_lhs (fork
, ddvar
);
5800 gcall
*join
= gimple_build_call_internal (IFN_UNIQUE
, 3,
5801 join_kind
, ddvar
, place
);
5802 gimple_set_location (join
, loc
);
5803 gimple_set_lhs (join
, ddvar
);
5805 /* Mark the beginning of this level sequence. */
5807 lower_oacc_loop_marker (loc
, ddvar
, true,
5808 build_int_cst (integer_type_node
, count
),
5810 lower_oacc_loop_marker (loc
, ddvar
, false,
5811 build_int_cst (integer_type_node
, done
),
5814 lower_oacc_reductions (loc
, clauses
, place
, inner
,
5815 fork
, join
, &fork_seq
, &join_seq
, ctx
);
5817 /* Append this level to head. */
5818 gimple_seq_add_seq (head
, fork_seq
);
5819 /* Prepend it to tail. */
5820 gimple_seq_add_seq (&join_seq
, *tail
);
5826 /* Mark the end of the sequence. */
5827 lower_oacc_loop_marker (loc
, ddvar
, true, NULL_TREE
, head
);
5828 lower_oacc_loop_marker (loc
, ddvar
, false, NULL_TREE
, tail
);
5831 /* If exceptions are enabled, wrap the statements in BODY in a MUST_NOT_THROW
5832 catch handler and return it. This prevents programs from violating the
5833 structured block semantics with throws. */
5836 maybe_catch_exception (gimple_seq body
)
5841 if (!flag_exceptions
)
5844 if (lang_hooks
.eh_protect_cleanup_actions
!= NULL
)
5845 decl
= lang_hooks
.eh_protect_cleanup_actions ();
5847 decl
= builtin_decl_explicit (BUILT_IN_TRAP
);
5849 g
= gimple_build_eh_must_not_throw (decl
);
5850 g
= gimple_build_try (body
, gimple_seq_alloc_with_stmt (g
),
5853 return gimple_seq_alloc_with_stmt (g
);
5857 /* Routines to lower OMP directives into OMP-GIMPLE. */
5859 /* If ctx is a worksharing context inside of a cancellable parallel
5860 region and it isn't nowait, add lhs to its GIMPLE_OMP_RETURN
5861 and conditional branch to parallel's cancel_label to handle
5862 cancellation in the implicit barrier. */
5865 maybe_add_implicit_barrier_cancel (omp_context
*ctx
, gimple_seq
*body
)
5867 gimple
*omp_return
= gimple_seq_last_stmt (*body
);
5868 gcc_assert (gimple_code (omp_return
) == GIMPLE_OMP_RETURN
);
5869 if (gimple_omp_return_nowait_p (omp_return
))
5872 && gimple_code (ctx
->outer
->stmt
) == GIMPLE_OMP_PARALLEL
5873 && ctx
->outer
->cancellable
)
5875 tree fndecl
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
5876 tree c_bool_type
= TREE_TYPE (TREE_TYPE (fndecl
));
5877 tree lhs
= create_tmp_var (c_bool_type
);
5878 gimple_omp_return_set_lhs (omp_return
, lhs
);
5879 tree fallthru_label
= create_artificial_label (UNKNOWN_LOCATION
);
5880 gimple
*g
= gimple_build_cond (NE_EXPR
, lhs
,
5881 fold_convert (c_bool_type
,
5882 boolean_false_node
),
5883 ctx
->outer
->cancel_label
, fallthru_label
);
5884 gimple_seq_add_stmt (body
, g
);
5885 gimple_seq_add_stmt (body
, gimple_build_label (fallthru_label
));
5889 /* Lower the OpenMP sections directive in the current statement in GSI_P.
5890 CTX is the enclosing OMP context for the current statement. */
5893 lower_omp_sections (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
5895 tree block
, control
;
5896 gimple_stmt_iterator tgsi
;
5897 gomp_sections
*stmt
;
5899 gbind
*new_stmt
, *bind
;
5900 gimple_seq ilist
, dlist
, olist
, new_body
;
5902 stmt
= as_a
<gomp_sections
*> (gsi_stmt (*gsi_p
));
5904 push_gimplify_context ();
5908 lower_rec_input_clauses (gimple_omp_sections_clauses (stmt
),
5909 &ilist
, &dlist
, ctx
, NULL
);
5911 new_body
= gimple_omp_body (stmt
);
5912 gimple_omp_set_body (stmt
, NULL
);
5913 tgsi
= gsi_start (new_body
);
5914 for (; !gsi_end_p (tgsi
); gsi_next (&tgsi
))
5919 sec_start
= gsi_stmt (tgsi
);
5920 sctx
= maybe_lookup_ctx (sec_start
);
5923 lower_omp (gimple_omp_body_ptr (sec_start
), sctx
);
5924 gsi_insert_seq_after (&tgsi
, gimple_omp_body (sec_start
),
5925 GSI_CONTINUE_LINKING
);
5926 gimple_omp_set_body (sec_start
, NULL
);
5928 if (gsi_one_before_end_p (tgsi
))
5930 gimple_seq l
= NULL
;
5931 lower_lastprivate_clauses (gimple_omp_sections_clauses (stmt
), NULL
,
5933 gsi_insert_seq_after (&tgsi
, l
, GSI_CONTINUE_LINKING
);
5934 gimple_omp_section_set_last (sec_start
);
5937 gsi_insert_after (&tgsi
, gimple_build_omp_return (false),
5938 GSI_CONTINUE_LINKING
);
5941 block
= make_node (BLOCK
);
5942 bind
= gimple_build_bind (NULL
, new_body
, block
);
5945 lower_reduction_clauses (gimple_omp_sections_clauses (stmt
), &olist
, ctx
);
5947 block
= make_node (BLOCK
);
5948 new_stmt
= gimple_build_bind (NULL
, NULL
, block
);
5949 gsi_replace (gsi_p
, new_stmt
, true);
5951 pop_gimplify_context (new_stmt
);
5952 gimple_bind_append_vars (new_stmt
, ctx
->block_vars
);
5953 BLOCK_VARS (block
) = gimple_bind_vars (bind
);
5954 if (BLOCK_VARS (block
))
5955 TREE_USED (block
) = 1;
5958 gimple_seq_add_seq (&new_body
, ilist
);
5959 gimple_seq_add_stmt (&new_body
, stmt
);
5960 gimple_seq_add_stmt (&new_body
, gimple_build_omp_sections_switch ());
5961 gimple_seq_add_stmt (&new_body
, bind
);
5963 control
= create_tmp_var (unsigned_type_node
, ".section");
5964 t
= gimple_build_omp_continue (control
, control
);
5965 gimple_omp_sections_set_control (stmt
, control
);
5966 gimple_seq_add_stmt (&new_body
, t
);
5968 gimple_seq_add_seq (&new_body
, olist
);
5969 if (ctx
->cancellable
)
5970 gimple_seq_add_stmt (&new_body
, gimple_build_label (ctx
->cancel_label
));
5971 gimple_seq_add_seq (&new_body
, dlist
);
5973 new_body
= maybe_catch_exception (new_body
);
5975 bool nowait
= omp_find_clause (gimple_omp_sections_clauses (stmt
),
5976 OMP_CLAUSE_NOWAIT
) != NULL_TREE
;
5977 t
= gimple_build_omp_return (nowait
);
5978 gimple_seq_add_stmt (&new_body
, t
);
5979 maybe_add_implicit_barrier_cancel (ctx
, &new_body
);
5981 gimple_bind_set_body (new_stmt
, new_body
);
5985 /* A subroutine of lower_omp_single. Expand the simple form of
5986 a GIMPLE_OMP_SINGLE, without a copyprivate clause:
5988 if (GOMP_single_start ())
5990 [ GOMP_barrier (); ] -> unless 'nowait' is present.
5992 FIXME. It may be better to delay expanding the logic of this until
5993 pass_expand_omp. The expanded logic may make the job more difficult
5994 to a synchronization analysis pass. */
5997 lower_omp_single_simple (gomp_single
*single_stmt
, gimple_seq
*pre_p
)
5999 location_t loc
= gimple_location (single_stmt
);
6000 tree tlabel
= create_artificial_label (loc
);
6001 tree flabel
= create_artificial_label (loc
);
6002 gimple
*call
, *cond
;
6005 decl
= builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_START
);
6006 lhs
= create_tmp_var (TREE_TYPE (TREE_TYPE (decl
)));
6007 call
= gimple_build_call (decl
, 0);
6008 gimple_call_set_lhs (call
, lhs
);
6009 gimple_seq_add_stmt (pre_p
, call
);
6011 cond
= gimple_build_cond (EQ_EXPR
, lhs
,
6012 fold_convert_loc (loc
, TREE_TYPE (lhs
),
6015 gimple_seq_add_stmt (pre_p
, cond
);
6016 gimple_seq_add_stmt (pre_p
, gimple_build_label (tlabel
));
6017 gimple_seq_add_seq (pre_p
, gimple_omp_body (single_stmt
));
6018 gimple_seq_add_stmt (pre_p
, gimple_build_label (flabel
));
6022 /* A subroutine of lower_omp_single. Expand the simple form of
6023 a GIMPLE_OMP_SINGLE, with a copyprivate clause:
6025 #pragma omp single copyprivate (a, b, c)
6027 Create a new structure to hold copies of 'a', 'b' and 'c' and emit:
6030 if ((copyout_p = GOMP_single_copy_start ()) == NULL)
6036 GOMP_single_copy_end (©out);
6047 FIXME. It may be better to delay expanding the logic of this until
6048 pass_expand_omp. The expanded logic may make the job more difficult
6049 to a synchronization analysis pass. */
6052 lower_omp_single_copy (gomp_single
*single_stmt
, gimple_seq
*pre_p
,
6055 tree ptr_type
, t
, l0
, l1
, l2
, bfn_decl
;
6056 gimple_seq copyin_seq
;
6057 location_t loc
= gimple_location (single_stmt
);
6059 ctx
->sender_decl
= create_tmp_var (ctx
->record_type
, ".omp_copy_o");
6061 ptr_type
= build_pointer_type (ctx
->record_type
);
6062 ctx
->receiver_decl
= create_tmp_var (ptr_type
, ".omp_copy_i");
6064 l0
= create_artificial_label (loc
);
6065 l1
= create_artificial_label (loc
);
6066 l2
= create_artificial_label (loc
);
6068 bfn_decl
= builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_COPY_START
);
6069 t
= build_call_expr_loc (loc
, bfn_decl
, 0);
6070 t
= fold_convert_loc (loc
, ptr_type
, t
);
6071 gimplify_assign (ctx
->receiver_decl
, t
, pre_p
);
6073 t
= build2 (EQ_EXPR
, boolean_type_node
, ctx
->receiver_decl
,
6074 build_int_cst (ptr_type
, 0));
6075 t
= build3 (COND_EXPR
, void_type_node
, t
,
6076 build_and_jump (&l0
), build_and_jump (&l1
));
6077 gimplify_and_add (t
, pre_p
);
6079 gimple_seq_add_stmt (pre_p
, gimple_build_label (l0
));
6081 gimple_seq_add_seq (pre_p
, gimple_omp_body (single_stmt
));
6084 lower_copyprivate_clauses (gimple_omp_single_clauses (single_stmt
), pre_p
,
6087 t
= build_fold_addr_expr_loc (loc
, ctx
->sender_decl
);
6088 bfn_decl
= builtin_decl_explicit (BUILT_IN_GOMP_SINGLE_COPY_END
);
6089 t
= build_call_expr_loc (loc
, bfn_decl
, 1, t
);
6090 gimplify_and_add (t
, pre_p
);
6092 t
= build_and_jump (&l2
);
6093 gimplify_and_add (t
, pre_p
);
6095 gimple_seq_add_stmt (pre_p
, gimple_build_label (l1
));
6097 gimple_seq_add_seq (pre_p
, copyin_seq
);
6099 gimple_seq_add_stmt (pre_p
, gimple_build_label (l2
));
6103 /* Expand code for an OpenMP single directive. */
6106 lower_omp_single (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6109 gomp_single
*single_stmt
= as_a
<gomp_single
*> (gsi_stmt (*gsi_p
));
6111 gimple_seq bind_body
, bind_body_tail
= NULL
, dlist
;
6113 push_gimplify_context ();
6115 block
= make_node (BLOCK
);
6116 bind
= gimple_build_bind (NULL
, NULL
, block
);
6117 gsi_replace (gsi_p
, bind
, true);
6120 lower_rec_input_clauses (gimple_omp_single_clauses (single_stmt
),
6121 &bind_body
, &dlist
, ctx
, NULL
);
6122 lower_omp (gimple_omp_body_ptr (single_stmt
), ctx
);
6124 gimple_seq_add_stmt (&bind_body
, single_stmt
);
6126 if (ctx
->record_type
)
6127 lower_omp_single_copy (single_stmt
, &bind_body
, ctx
);
6129 lower_omp_single_simple (single_stmt
, &bind_body
);
6131 gimple_omp_set_body (single_stmt
, NULL
);
6133 gimple_seq_add_seq (&bind_body
, dlist
);
6135 bind_body
= maybe_catch_exception (bind_body
);
6137 bool nowait
= omp_find_clause (gimple_omp_single_clauses (single_stmt
),
6138 OMP_CLAUSE_NOWAIT
) != NULL_TREE
;
6139 gimple
*g
= gimple_build_omp_return (nowait
);
6140 gimple_seq_add_stmt (&bind_body_tail
, g
);
6141 maybe_add_implicit_barrier_cancel (ctx
, &bind_body_tail
);
6142 if (ctx
->record_type
)
6144 gimple_stmt_iterator gsi
= gsi_start (bind_body_tail
);
6145 tree clobber
= build_constructor (ctx
->record_type
, NULL
);
6146 TREE_THIS_VOLATILE (clobber
) = 1;
6147 gsi_insert_after (&gsi
, gimple_build_assign (ctx
->sender_decl
,
6148 clobber
), GSI_SAME_STMT
);
6150 gimple_seq_add_seq (&bind_body
, bind_body_tail
);
6151 gimple_bind_set_body (bind
, bind_body
);
6153 pop_gimplify_context (bind
);
6155 gimple_bind_append_vars (bind
, ctx
->block_vars
);
6156 BLOCK_VARS (block
) = ctx
->block_vars
;
6157 if (BLOCK_VARS (block
))
6158 TREE_USED (block
) = 1;
6162 /* Expand code for an OpenMP master directive. */
6165 lower_omp_master (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6167 tree block
, lab
= NULL
, x
, bfn_decl
;
6168 gimple
*stmt
= gsi_stmt (*gsi_p
);
6170 location_t loc
= gimple_location (stmt
);
6173 push_gimplify_context ();
6175 block
= make_node (BLOCK
);
6176 bind
= gimple_build_bind (NULL
, NULL
, block
);
6177 gsi_replace (gsi_p
, bind
, true);
6178 gimple_bind_add_stmt (bind
, stmt
);
6180 bfn_decl
= builtin_decl_explicit (BUILT_IN_OMP_GET_THREAD_NUM
);
6181 x
= build_call_expr_loc (loc
, bfn_decl
, 0);
6182 x
= build2 (EQ_EXPR
, boolean_type_node
, x
, integer_zero_node
);
6183 x
= build3 (COND_EXPR
, void_type_node
, x
, NULL
, build_and_jump (&lab
));
6185 gimplify_and_add (x
, &tseq
);
6186 gimple_bind_add_seq (bind
, tseq
);
6188 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
6189 gimple_omp_set_body (stmt
, maybe_catch_exception (gimple_omp_body (stmt
)));
6190 gimple_bind_add_seq (bind
, gimple_omp_body (stmt
));
6191 gimple_omp_set_body (stmt
, NULL
);
6193 gimple_bind_add_stmt (bind
, gimple_build_label (lab
));
6195 gimple_bind_add_stmt (bind
, gimple_build_omp_return (true));
6197 pop_gimplify_context (bind
);
6199 gimple_bind_append_vars (bind
, ctx
->block_vars
);
6200 BLOCK_VARS (block
) = ctx
->block_vars
;
6204 /* Expand code for an OpenMP taskgroup directive. */
6207 lower_omp_taskgroup (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6209 gimple
*stmt
= gsi_stmt (*gsi_p
);
6212 tree block
= make_node (BLOCK
);
6214 bind
= gimple_build_bind (NULL
, NULL
, block
);
6215 gsi_replace (gsi_p
, bind
, true);
6216 gimple_bind_add_stmt (bind
, stmt
);
6218 x
= gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_START
),
6220 gimple_bind_add_stmt (bind
, x
);
6222 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
6223 gimple_bind_add_seq (bind
, gimple_omp_body (stmt
));
6224 gimple_omp_set_body (stmt
, NULL
);
6226 gimple_bind_add_stmt (bind
, gimple_build_omp_return (true));
6228 gimple_bind_append_vars (bind
, ctx
->block_vars
);
6229 BLOCK_VARS (block
) = ctx
->block_vars
;
6233 /* Fold the OMP_ORDERED_CLAUSES for the OMP_ORDERED in STMT if possible. */
6236 lower_omp_ordered_clauses (gimple_stmt_iterator
*gsi_p
, gomp_ordered
*ord_stmt
,
6239 struct omp_for_data fd
;
6240 if (!ctx
->outer
|| gimple_code (ctx
->outer
->stmt
) != GIMPLE_OMP_FOR
)
6243 unsigned int len
= gimple_omp_for_collapse (ctx
->outer
->stmt
);
6244 struct omp_for_data_loop
*loops
= XALLOCAVEC (struct omp_for_data_loop
, len
);
6245 omp_extract_for_data (as_a
<gomp_for
*> (ctx
->outer
->stmt
), &fd
, loops
);
6249 tree
*list_p
= gimple_omp_ordered_clauses_ptr (ord_stmt
);
6250 tree c
= gimple_omp_ordered_clauses (ord_stmt
);
6251 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
6252 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6254 /* Merge depend clauses from multiple adjacent
6255 #pragma omp ordered depend(sink:...) constructs
6256 into one #pragma omp ordered depend(sink:...), so that
6257 we can optimize them together. */
6258 gimple_stmt_iterator gsi
= *gsi_p
;
6260 while (!gsi_end_p (gsi
))
6262 gimple
*stmt
= gsi_stmt (gsi
);
6263 if (is_gimple_debug (stmt
)
6264 || gimple_code (stmt
) == GIMPLE_NOP
)
6269 if (gimple_code (stmt
) != GIMPLE_OMP_ORDERED
)
6271 gomp_ordered
*ord_stmt2
= as_a
<gomp_ordered
*> (stmt
);
6272 c
= gimple_omp_ordered_clauses (ord_stmt2
);
6274 || OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
6275 || OMP_CLAUSE_DEPEND_KIND (c
) != OMP_CLAUSE_DEPEND_SINK
)
6278 list_p
= &OMP_CLAUSE_CHAIN (*list_p
);
6280 gsi_remove (&gsi
, true);
6284 /* Canonicalize sink dependence clauses into one folded clause if
6287 The basic algorithm is to create a sink vector whose first
6288 element is the GCD of all the first elements, and whose remaining
6289 elements are the minimum of the subsequent columns.
6291 We ignore dependence vectors whose first element is zero because
6292 such dependencies are known to be executed by the same thread.
6294 We take into account the direction of the loop, so a minimum
6295 becomes a maximum if the loop is iterating forwards. We also
6296 ignore sink clauses where the loop direction is unknown, or where
6297 the offsets are clearly invalid because they are not a multiple
6298 of the loop increment.
6302 #pragma omp for ordered(2)
6303 for (i=0; i < N; ++i)
6304 for (j=0; j < M; ++j)
6306 #pragma omp ordered \
6307 depend(sink:i-8,j-2) \
6308 depend(sink:i,j-1) \ // Completely ignored because i+0.
6309 depend(sink:i-4,j-3) \
6310 depend(sink:i-6,j-4)
6311 #pragma omp ordered depend(source)
6316 depend(sink:-gcd(8,4,6),-min(2,3,4))
6321 /* FIXME: Computing GCD's where the first element is zero is
6322 non-trivial in the presence of collapsed loops. Do this later. */
6323 if (fd
.collapse
> 1)
6326 wide_int
*folded_deps
= XALLOCAVEC (wide_int
, 2 * len
- 1);
6328 /* wide_int is not a POD so it must be default-constructed. */
6329 for (unsigned i
= 0; i
!= 2 * len
- 1; ++i
)
6330 new (static_cast<void*>(folded_deps
+ i
)) wide_int ();
6332 tree folded_dep
= NULL_TREE
;
6333 /* TRUE if the first dimension's offset is negative. */
6334 bool neg_offset_p
= false;
6336 list_p
= gimple_omp_ordered_clauses_ptr (ord_stmt
);
6338 while ((c
= *list_p
) != NULL
)
6340 bool remove
= false;
6342 gcc_assert (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
);
6343 if (OMP_CLAUSE_DEPEND_KIND (c
) != OMP_CLAUSE_DEPEND_SINK
)
6344 goto next_ordered_clause
;
6347 for (vec
= OMP_CLAUSE_DECL (c
), i
= 0;
6348 vec
&& TREE_CODE (vec
) == TREE_LIST
;
6349 vec
= TREE_CHAIN (vec
), ++i
)
6351 gcc_assert (i
< len
);
6353 /* omp_extract_for_data has canonicalized the condition. */
6354 gcc_assert (fd
.loops
[i
].cond_code
== LT_EXPR
6355 || fd
.loops
[i
].cond_code
== GT_EXPR
);
6356 bool forward
= fd
.loops
[i
].cond_code
== LT_EXPR
;
6357 bool maybe_lexically_later
= true;
6359 /* While the committee makes up its mind, bail if we have any
6360 non-constant steps. */
6361 if (TREE_CODE (fd
.loops
[i
].step
) != INTEGER_CST
)
6362 goto lower_omp_ordered_ret
;
6364 tree itype
= TREE_TYPE (TREE_VALUE (vec
));
6365 if (POINTER_TYPE_P (itype
))
6367 wide_int offset
= wide_int::from (TREE_PURPOSE (vec
),
6368 TYPE_PRECISION (itype
),
6371 /* Ignore invalid offsets that are not multiples of the step. */
6372 if (!wi::multiple_of_p
6373 (wi::abs (offset
), wi::abs ((wide_int
) fd
.loops
[i
].step
),
6376 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6377 "ignoring sink clause with offset that is not "
6378 "a multiple of the loop step");
6380 goto next_ordered_clause
;
6383 /* Calculate the first dimension. The first dimension of
6384 the folded dependency vector is the GCD of the first
6385 elements, while ignoring any first elements whose offset
6389 /* Ignore dependence vectors whose first dimension is 0. */
6393 goto next_ordered_clause
;
6397 if (!TYPE_UNSIGNED (itype
) && (forward
^ wi::neg_p (offset
)))
6399 error_at (OMP_CLAUSE_LOCATION (c
),
6400 "first offset must be in opposite direction "
6401 "of loop iterations");
6402 goto lower_omp_ordered_ret
;
6406 neg_offset_p
= forward
;
6407 /* Initialize the first time around. */
6408 if (folded_dep
== NULL_TREE
)
6411 folded_deps
[0] = offset
;
6414 folded_deps
[0] = wi::gcd (folded_deps
[0],
6418 /* Calculate minimum for the remaining dimensions. */
6421 folded_deps
[len
+ i
- 1] = offset
;
6422 if (folded_dep
== c
)
6423 folded_deps
[i
] = offset
;
6424 else if (maybe_lexically_later
6425 && !wi::eq_p (folded_deps
[i
], offset
))
6427 if (forward
^ wi::gts_p (folded_deps
[i
], offset
))
6431 for (j
= 1; j
<= i
; j
++)
6432 folded_deps
[j
] = folded_deps
[len
+ j
- 1];
6435 maybe_lexically_later
= false;
6439 gcc_assert (i
== len
);
6443 next_ordered_clause
:
6445 *list_p
= OMP_CLAUSE_CHAIN (c
);
6447 list_p
= &OMP_CLAUSE_CHAIN (c
);
6453 folded_deps
[0] = -folded_deps
[0];
6455 tree itype
= TREE_TYPE (TREE_VALUE (OMP_CLAUSE_DECL (folded_dep
)));
6456 if (POINTER_TYPE_P (itype
))
6459 TREE_PURPOSE (OMP_CLAUSE_DECL (folded_dep
))
6460 = wide_int_to_tree (itype
, folded_deps
[0]);
6461 OMP_CLAUSE_CHAIN (folded_dep
) = gimple_omp_ordered_clauses (ord_stmt
);
6462 *gimple_omp_ordered_clauses_ptr (ord_stmt
) = folded_dep
;
6465 lower_omp_ordered_ret
:
6467 /* Ordered without clauses is #pragma omp threads, while we want
6468 a nop instead if we remove all clauses. */
6469 if (gimple_omp_ordered_clauses (ord_stmt
) == NULL_TREE
)
6470 gsi_replace (gsi_p
, gimple_build_nop (), true);
6474 /* Expand code for an OpenMP ordered directive. */
6477 lower_omp_ordered (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6480 gimple
*stmt
= gsi_stmt (*gsi_p
), *g
;
6481 gomp_ordered
*ord_stmt
= as_a
<gomp_ordered
*> (stmt
);
6484 bool simd
= omp_find_clause (gimple_omp_ordered_clauses (ord_stmt
),
6486 /* FIXME: this should check presence of OMP_CLAUSE__SIMT_ on the enclosing
6489 = simd
&& omp_maybe_offloaded_ctx (ctx
) && omp_max_simt_vf () > 1;
6490 bool threads
= omp_find_clause (gimple_omp_ordered_clauses (ord_stmt
),
6491 OMP_CLAUSE_THREADS
);
6493 if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt
),
6496 /* FIXME: This is needs to be moved to the expansion to verify various
6497 conditions only testable on cfg with dominators computed, and also
6498 all the depend clauses to be merged still might need to be available
6499 for the runtime checks. */
6501 lower_omp_ordered_clauses (gsi_p
, ord_stmt
, ctx
);
6505 push_gimplify_context ();
6507 block
= make_node (BLOCK
);
6508 bind
= gimple_build_bind (NULL
, NULL
, block
);
6509 gsi_replace (gsi_p
, bind
, true);
6510 gimple_bind_add_stmt (bind
, stmt
);
6514 x
= gimple_build_call_internal (IFN_GOMP_SIMD_ORDERED_START
, 1,
6515 build_int_cst (NULL_TREE
, threads
));
6516 cfun
->has_simduid_loops
= true;
6519 x
= gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ORDERED_START
),
6521 gimple_bind_add_stmt (bind
, x
);
6523 tree counter
= NULL_TREE
, test
= NULL_TREE
, body
= NULL_TREE
;
6526 counter
= create_tmp_var (integer_type_node
);
6527 g
= gimple_build_call_internal (IFN_GOMP_SIMT_LANE
, 0);
6528 gimple_call_set_lhs (g
, counter
);
6529 gimple_bind_add_stmt (bind
, g
);
6531 body
= create_artificial_label (UNKNOWN_LOCATION
);
6532 test
= create_artificial_label (UNKNOWN_LOCATION
);
6533 gimple_bind_add_stmt (bind
, gimple_build_label (body
));
6535 tree simt_pred
= create_tmp_var (integer_type_node
);
6536 g
= gimple_build_call_internal (IFN_GOMP_SIMT_ORDERED_PRED
, 1, counter
);
6537 gimple_call_set_lhs (g
, simt_pred
);
6538 gimple_bind_add_stmt (bind
, g
);
6540 tree t
= create_artificial_label (UNKNOWN_LOCATION
);
6541 g
= gimple_build_cond (EQ_EXPR
, simt_pred
, integer_zero_node
, t
, test
);
6542 gimple_bind_add_stmt (bind
, g
);
6544 gimple_bind_add_stmt (bind
, gimple_build_label (t
));
6546 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
6547 gimple_omp_set_body (stmt
, maybe_catch_exception (gimple_omp_body (stmt
)));
6548 gimple_bind_add_seq (bind
, gimple_omp_body (stmt
));
6549 gimple_omp_set_body (stmt
, NULL
);
6553 gimple_bind_add_stmt (bind
, gimple_build_label (test
));
6554 g
= gimple_build_assign (counter
, MINUS_EXPR
, counter
, integer_one_node
);
6555 gimple_bind_add_stmt (bind
, g
);
6557 tree c
= build2 (GE_EXPR
, boolean_type_node
, counter
, integer_zero_node
);
6558 tree nonneg
= create_tmp_var (integer_type_node
);
6559 gimple_seq tseq
= NULL
;
6560 gimplify_assign (nonneg
, fold_convert (integer_type_node
, c
), &tseq
);
6561 gimple_bind_add_seq (bind
, tseq
);
6563 g
= gimple_build_call_internal (IFN_GOMP_SIMT_VOTE_ANY
, 1, nonneg
);
6564 gimple_call_set_lhs (g
, nonneg
);
6565 gimple_bind_add_stmt (bind
, g
);
6567 tree end
= create_artificial_label (UNKNOWN_LOCATION
);
6568 g
= gimple_build_cond (NE_EXPR
, nonneg
, integer_zero_node
, body
, end
);
6569 gimple_bind_add_stmt (bind
, g
);
6571 gimple_bind_add_stmt (bind
, gimple_build_label (end
));
6574 x
= gimple_build_call_internal (IFN_GOMP_SIMD_ORDERED_END
, 1,
6575 build_int_cst (NULL_TREE
, threads
));
6577 x
= gimple_build_call (builtin_decl_explicit (BUILT_IN_GOMP_ORDERED_END
),
6579 gimple_bind_add_stmt (bind
, x
);
6581 gimple_bind_add_stmt (bind
, gimple_build_omp_return (true));
6583 pop_gimplify_context (bind
);
6585 gimple_bind_append_vars (bind
, ctx
->block_vars
);
6586 BLOCK_VARS (block
) = gimple_bind_vars (bind
);
6590 /* Gimplify a GIMPLE_OMP_CRITICAL statement. This is a relatively simple
6591 substitution of a couple of function calls. But in the NAMED case,
6592 requires that languages coordinate a symbol name. It is therefore
6593 best put here in common code. */
6595 static GTY(()) hash_map
<tree
, tree
> *critical_name_mutexes
;
6598 lower_omp_critical (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6601 tree name
, lock
, unlock
;
6602 gomp_critical
*stmt
= as_a
<gomp_critical
*> (gsi_stmt (*gsi_p
));
6604 location_t loc
= gimple_location (stmt
);
6607 name
= gimple_omp_critical_name (stmt
);
6612 if (!critical_name_mutexes
)
6613 critical_name_mutexes
= hash_map
<tree
, tree
>::create_ggc (10);
6615 tree
*n
= critical_name_mutexes
->get (name
);
6620 decl
= create_tmp_var_raw (ptr_type_node
);
6622 new_str
= ACONCAT ((".gomp_critical_user_",
6623 IDENTIFIER_POINTER (name
), NULL
));
6624 DECL_NAME (decl
) = get_identifier (new_str
);
6625 TREE_PUBLIC (decl
) = 1;
6626 TREE_STATIC (decl
) = 1;
6627 DECL_COMMON (decl
) = 1;
6628 DECL_ARTIFICIAL (decl
) = 1;
6629 DECL_IGNORED_P (decl
) = 1;
6631 varpool_node::finalize_decl (decl
);
6633 critical_name_mutexes
->put (name
, decl
);
6638 /* If '#pragma omp critical' is inside offloaded region or
6639 inside function marked as offloadable, the symbol must be
6640 marked as offloadable too. */
6642 if (cgraph_node::get (current_function_decl
)->offloadable
)
6643 varpool_node::get_create (decl
)->offloadable
= 1;
6645 for (octx
= ctx
->outer
; octx
; octx
= octx
->outer
)
6646 if (is_gimple_omp_offloaded (octx
->stmt
))
6648 varpool_node::get_create (decl
)->offloadable
= 1;
6652 lock
= builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_NAME_START
);
6653 lock
= build_call_expr_loc (loc
, lock
, 1,
6654 build_fold_addr_expr_loc (loc
, decl
));
6656 unlock
= builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_NAME_END
);
6657 unlock
= build_call_expr_loc (loc
, unlock
, 1,
6658 build_fold_addr_expr_loc (loc
, decl
));
6662 lock
= builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_START
);
6663 lock
= build_call_expr_loc (loc
, lock
, 0);
6665 unlock
= builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_END
);
6666 unlock
= build_call_expr_loc (loc
, unlock
, 0);
6669 push_gimplify_context ();
6671 block
= make_node (BLOCK
);
6672 bind
= gimple_build_bind (NULL
, NULL
, block
);
6673 gsi_replace (gsi_p
, bind
, true);
6674 gimple_bind_add_stmt (bind
, stmt
);
6676 tbody
= gimple_bind_body (bind
);
6677 gimplify_and_add (lock
, &tbody
);
6678 gimple_bind_set_body (bind
, tbody
);
6680 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
6681 gimple_omp_set_body (stmt
, maybe_catch_exception (gimple_omp_body (stmt
)));
6682 gimple_bind_add_seq (bind
, gimple_omp_body (stmt
));
6683 gimple_omp_set_body (stmt
, NULL
);
6685 tbody
= gimple_bind_body (bind
);
6686 gimplify_and_add (unlock
, &tbody
);
6687 gimple_bind_set_body (bind
, tbody
);
6689 gimple_bind_add_stmt (bind
, gimple_build_omp_return (true));
6691 pop_gimplify_context (bind
);
6692 gimple_bind_append_vars (bind
, ctx
->block_vars
);
6693 BLOCK_VARS (block
) = gimple_bind_vars (bind
);
6696 /* A subroutine of lower_omp_for. Generate code to emit the predicate
6697 for a lastprivate clause. Given a loop control predicate of (V
6698 cond N2), we gate the clause on (!(V cond N2)). The lowered form
6699 is appended to *DLIST, iterator initialization is appended to
6703 lower_omp_for_lastprivate (struct omp_for_data
*fd
, gimple_seq
*body_p
,
6704 gimple_seq
*dlist
, struct omp_context
*ctx
)
6706 tree clauses
, cond
, vinit
;
6707 enum tree_code cond_code
;
6710 cond_code
= fd
->loop
.cond_code
;
6711 cond_code
= cond_code
== LT_EXPR
? GE_EXPR
: LE_EXPR
;
6713 /* When possible, use a strict equality expression. This can let VRP
6714 type optimizations deduce the value and remove a copy. */
6715 if (tree_fits_shwi_p (fd
->loop
.step
))
6717 HOST_WIDE_INT step
= tree_to_shwi (fd
->loop
.step
);
6718 if (step
== 1 || step
== -1)
6719 cond_code
= EQ_EXPR
;
6722 if (gimple_omp_for_kind (fd
->for_stmt
) == GF_OMP_FOR_KIND_GRID_LOOP
6723 || gimple_omp_for_grid_phony (fd
->for_stmt
))
6724 cond
= omp_grid_lastprivate_predicate (fd
);
6727 tree n2
= fd
->loop
.n2
;
6728 if (fd
->collapse
> 1
6729 && TREE_CODE (n2
) != INTEGER_CST
6730 && gimple_omp_for_combined_into_p (fd
->for_stmt
))
6732 struct omp_context
*taskreg_ctx
= NULL
;
6733 if (gimple_code (ctx
->outer
->stmt
) == GIMPLE_OMP_FOR
)
6735 gomp_for
*gfor
= as_a
<gomp_for
*> (ctx
->outer
->stmt
);
6736 if (gimple_omp_for_kind (gfor
) == GF_OMP_FOR_KIND_FOR
6737 || gimple_omp_for_kind (gfor
) == GF_OMP_FOR_KIND_DISTRIBUTE
)
6739 if (gimple_omp_for_combined_into_p (gfor
))
6741 gcc_assert (ctx
->outer
->outer
6742 && is_parallel_ctx (ctx
->outer
->outer
));
6743 taskreg_ctx
= ctx
->outer
->outer
;
6747 struct omp_for_data outer_fd
;
6748 omp_extract_for_data (gfor
, &outer_fd
, NULL
);
6749 n2
= fold_convert (TREE_TYPE (n2
), outer_fd
.loop
.n2
);
6752 else if (gimple_omp_for_kind (gfor
) == GF_OMP_FOR_KIND_TASKLOOP
)
6753 taskreg_ctx
= ctx
->outer
->outer
;
6755 else if (is_taskreg_ctx (ctx
->outer
))
6756 taskreg_ctx
= ctx
->outer
;
6760 tree taskreg_clauses
6761 = gimple_omp_taskreg_clauses (taskreg_ctx
->stmt
);
6762 tree innerc
= omp_find_clause (taskreg_clauses
,
6763 OMP_CLAUSE__LOOPTEMP_
);
6764 gcc_assert (innerc
);
6765 for (i
= 0; i
< fd
->collapse
; i
++)
6767 innerc
= omp_find_clause (OMP_CLAUSE_CHAIN (innerc
),
6768 OMP_CLAUSE__LOOPTEMP_
);
6769 gcc_assert (innerc
);
6771 innerc
= omp_find_clause (OMP_CLAUSE_CHAIN (innerc
),
6772 OMP_CLAUSE__LOOPTEMP_
);
6774 n2
= fold_convert (TREE_TYPE (n2
),
6775 lookup_decl (OMP_CLAUSE_DECL (innerc
),
6779 cond
= build2 (cond_code
, boolean_type_node
, fd
->loop
.v
, n2
);
6782 clauses
= gimple_omp_for_clauses (fd
->for_stmt
);
6784 lower_lastprivate_clauses (clauses
, cond
, &stmts
, ctx
);
6785 if (!gimple_seq_empty_p (stmts
))
6787 gimple_seq_add_seq (&stmts
, *dlist
);
6790 /* Optimize: v = 0; is usually cheaper than v = some_other_constant. */
6791 vinit
= fd
->loop
.n1
;
6792 if (cond_code
== EQ_EXPR
6793 && tree_fits_shwi_p (fd
->loop
.n2
)
6794 && ! integer_zerop (fd
->loop
.n2
))
6795 vinit
= build_int_cst (TREE_TYPE (fd
->loop
.v
), 0);
6797 vinit
= unshare_expr (vinit
);
6799 /* Initialize the iterator variable, so that threads that don't execute
6800 any iterations don't execute the lastprivate clauses by accident. */
6801 gimplify_assign (fd
->loop
.v
, vinit
, body_p
);
6806 /* Lower code for an OMP loop directive. */
6809 lower_omp_for (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
6812 struct omp_for_data fd
, *fdp
= NULL
;
6813 gomp_for
*stmt
= as_a
<gomp_for
*> (gsi_stmt (*gsi_p
));
6815 gimple_seq omp_for_body
, body
, dlist
;
6816 gimple_seq oacc_head
= NULL
, oacc_tail
= NULL
;
6819 push_gimplify_context ();
6821 lower_omp (gimple_omp_for_pre_body_ptr (stmt
), ctx
);
6823 block
= make_node (BLOCK
);
6824 new_stmt
= gimple_build_bind (NULL
, NULL
, block
);
6825 /* Replace at gsi right away, so that 'stmt' is no member
6826 of a sequence anymore as we're going to add to a different
6828 gsi_replace (gsi_p
, new_stmt
, true);
6830 /* Move declaration of temporaries in the loop body before we make
6832 omp_for_body
= gimple_omp_body (stmt
);
6833 if (!gimple_seq_empty_p (omp_for_body
)
6834 && gimple_code (gimple_seq_first_stmt (omp_for_body
)) == GIMPLE_BIND
)
6837 = as_a
<gbind
*> (gimple_seq_first_stmt (omp_for_body
));
6838 tree vars
= gimple_bind_vars (inner_bind
);
6839 gimple_bind_append_vars (new_stmt
, vars
);
6840 /* bind_vars/BLOCK_VARS are being moved to new_stmt/block, don't
6841 keep them on the inner_bind and it's block. */
6842 gimple_bind_set_vars (inner_bind
, NULL_TREE
);
6843 if (gimple_bind_block (inner_bind
))
6844 BLOCK_VARS (gimple_bind_block (inner_bind
)) = NULL_TREE
;
6847 if (gimple_omp_for_combined_into_p (stmt
))
6849 omp_extract_for_data (stmt
, &fd
, NULL
);
6852 /* We need two temporaries with fd.loop.v type (istart/iend)
6853 and then (fd.collapse - 1) temporaries with the same
6854 type for count2 ... countN-1 vars if not constant. */
6856 tree type
= fd
.iter_type
;
6858 && TREE_CODE (fd
.loop
.n2
) != INTEGER_CST
)
6859 count
+= fd
.collapse
- 1;
6861 = (gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_FOR
6862 || gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_TASKLOOP
);
6863 tree outerc
= NULL
, *pc
= gimple_omp_for_clauses_ptr (stmt
);
6868 = omp_find_clause (gimple_omp_taskreg_clauses (ctx
->outer
->stmt
),
6869 OMP_CLAUSE__LOOPTEMP_
);
6871 simtc
= omp_find_clause (gimple_omp_for_clauses (ctx
->simt_stmt
),
6872 OMP_CLAUSE__LOOPTEMP_
);
6873 for (i
= 0; i
< count
; i
++)
6878 gcc_assert (outerc
);
6879 temp
= lookup_decl (OMP_CLAUSE_DECL (outerc
), ctx
->outer
);
6880 outerc
= omp_find_clause (OMP_CLAUSE_CHAIN (outerc
),
6881 OMP_CLAUSE__LOOPTEMP_
);
6885 /* If there are 2 adjacent SIMD stmts, one with _simt_
6886 clause, another without, make sure they have the same
6887 decls in _looptemp_ clauses, because the outer stmt
6888 they are combined into will look up just one inner_stmt. */
6890 temp
= OMP_CLAUSE_DECL (simtc
);
6892 temp
= create_tmp_var (type
);
6893 insert_decl_map (&ctx
->outer
->cb
, temp
, temp
);
6895 *pc
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE__LOOPTEMP_
);
6896 OMP_CLAUSE_DECL (*pc
) = temp
;
6897 pc
= &OMP_CLAUSE_CHAIN (*pc
);
6899 simtc
= omp_find_clause (OMP_CLAUSE_CHAIN (simtc
),
6900 OMP_CLAUSE__LOOPTEMP_
);
6905 /* The pre-body and input clauses go before the lowered GIMPLE_OMP_FOR. */
6908 lower_rec_input_clauses (gimple_omp_for_clauses (stmt
), &body
, &dlist
, ctx
,
6910 gimple_seq_add_seq (&body
, gimple_omp_for_pre_body (stmt
));
6912 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
6914 /* Lower the header expressions. At this point, we can assume that
6915 the header is of the form:
6917 #pragma omp for (V = VAL1; V {<|>|<=|>=} VAL2; V = V [+-] VAL3)
6919 We just need to make sure that VAL1, VAL2 and VAL3 are lowered
6920 using the .omp_data_s mapping, if needed. */
6921 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
6923 rhs_p
= gimple_omp_for_initial_ptr (stmt
, i
);
6924 if (!is_gimple_min_invariant (*rhs_p
))
6925 *rhs_p
= get_formal_tmp_var (*rhs_p
, &body
);
6927 rhs_p
= gimple_omp_for_final_ptr (stmt
, i
);
6928 if (!is_gimple_min_invariant (*rhs_p
))
6929 *rhs_p
= get_formal_tmp_var (*rhs_p
, &body
);
6931 rhs_p
= &TREE_OPERAND (gimple_omp_for_incr (stmt
, i
), 1);
6932 if (!is_gimple_min_invariant (*rhs_p
))
6933 *rhs_p
= get_formal_tmp_var (*rhs_p
, &body
);
6936 /* Once lowered, extract the bounds and clauses. */
6937 omp_extract_for_data (stmt
, &fd
, NULL
);
6939 if (is_gimple_omp_oacc (ctx
->stmt
)
6940 && !ctx_in_oacc_kernels_region (ctx
))
6941 lower_oacc_head_tail (gimple_location (stmt
),
6942 gimple_omp_for_clauses (stmt
),
6943 &oacc_head
, &oacc_tail
, ctx
);
6945 /* Add OpenACC partitioning and reduction markers just before the loop. */
6947 gimple_seq_add_seq (&body
, oacc_head
);
6949 lower_omp_for_lastprivate (&fd
, &body
, &dlist
, ctx
);
6951 if (gimple_omp_for_kind (stmt
) == GF_OMP_FOR_KIND_FOR
)
6952 for (tree c
= gimple_omp_for_clauses (stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
6953 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6954 && !OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
6956 OMP_CLAUSE_DECL (c
) = lookup_decl (OMP_CLAUSE_DECL (c
), ctx
);
6957 if (DECL_P (OMP_CLAUSE_LINEAR_STEP (c
)))
6958 OMP_CLAUSE_LINEAR_STEP (c
)
6959 = maybe_lookup_decl_in_outer_ctx (OMP_CLAUSE_LINEAR_STEP (c
),
6963 bool phony_loop
= (gimple_omp_for_kind (stmt
) != GF_OMP_FOR_KIND_GRID_LOOP
6964 && gimple_omp_for_grid_phony (stmt
));
6966 gimple_seq_add_stmt (&body
, stmt
);
6967 gimple_seq_add_seq (&body
, gimple_omp_body (stmt
));
6970 gimple_seq_add_stmt (&body
, gimple_build_omp_continue (fd
.loop
.v
,
6973 /* After the loop, add exit clauses. */
6974 lower_reduction_clauses (gimple_omp_for_clauses (stmt
), &body
, ctx
);
6976 if (ctx
->cancellable
)
6977 gimple_seq_add_stmt (&body
, gimple_build_label (ctx
->cancel_label
));
6979 gimple_seq_add_seq (&body
, dlist
);
6981 body
= maybe_catch_exception (body
);
6985 /* Region exit marker goes at the end of the loop body. */
6986 gimple_seq_add_stmt (&body
, gimple_build_omp_return (fd
.have_nowait
));
6987 maybe_add_implicit_barrier_cancel (ctx
, &body
);
6990 /* Add OpenACC joining and reduction markers just after the loop. */
6992 gimple_seq_add_seq (&body
, oacc_tail
);
6994 pop_gimplify_context (new_stmt
);
6996 gimple_bind_append_vars (new_stmt
, ctx
->block_vars
);
6997 BLOCK_VARS (block
) = gimple_bind_vars (new_stmt
);
6998 if (BLOCK_VARS (block
))
6999 TREE_USED (block
) = 1;
7001 gimple_bind_set_body (new_stmt
, body
);
7002 gimple_omp_set_body (stmt
, NULL
);
7003 gimple_omp_for_set_pre_body (stmt
, NULL
);
7006 /* Callback for walk_stmts. Check if the current statement only contains
7007 GIMPLE_OMP_FOR or GIMPLE_OMP_SECTIONS. */
7010 check_combined_parallel (gimple_stmt_iterator
*gsi_p
,
7011 bool *handled_ops_p
,
7012 struct walk_stmt_info
*wi
)
7014 int *info
= (int *) wi
->info
;
7015 gimple
*stmt
= gsi_stmt (*gsi_p
);
7017 *handled_ops_p
= true;
7018 switch (gimple_code (stmt
))
7022 case GIMPLE_OMP_FOR
:
7023 case GIMPLE_OMP_SECTIONS
:
7024 *info
= *info
== 0 ? 1 : -1;
7033 struct omp_taskcopy_context
7035 /* This field must be at the beginning, as we do "inheritance": Some
7036 callback functions for tree-inline.c (e.g., omp_copy_decl)
7037 receive a copy_body_data pointer that is up-casted to an
7038 omp_context pointer. */
7044 task_copyfn_copy_decl (tree var
, copy_body_data
*cb
)
7046 struct omp_taskcopy_context
*tcctx
= (struct omp_taskcopy_context
*) cb
;
7048 if (splay_tree_lookup (tcctx
->ctx
->sfield_map
, (splay_tree_key
) var
))
7049 return create_tmp_var (TREE_TYPE (var
));
7055 task_copyfn_remap_type (struct omp_taskcopy_context
*tcctx
, tree orig_type
)
7057 tree name
, new_fields
= NULL
, type
, f
;
7059 type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
7060 name
= DECL_NAME (TYPE_NAME (orig_type
));
7061 name
= build_decl (gimple_location (tcctx
->ctx
->stmt
),
7062 TYPE_DECL
, name
, type
);
7063 TYPE_NAME (type
) = name
;
7065 for (f
= TYPE_FIELDS (orig_type
); f
; f
= TREE_CHAIN (f
))
7067 tree new_f
= copy_node (f
);
7068 DECL_CONTEXT (new_f
) = type
;
7069 TREE_TYPE (new_f
) = remap_type (TREE_TYPE (f
), &tcctx
->cb
);
7070 TREE_CHAIN (new_f
) = new_fields
;
7071 walk_tree (&DECL_SIZE (new_f
), copy_tree_body_r
, &tcctx
->cb
, NULL
);
7072 walk_tree (&DECL_SIZE_UNIT (new_f
), copy_tree_body_r
, &tcctx
->cb
, NULL
);
7073 walk_tree (&DECL_FIELD_OFFSET (new_f
), copy_tree_body_r
,
7076 tcctx
->cb
.decl_map
->put (f
, new_f
);
7078 TYPE_FIELDS (type
) = nreverse (new_fields
);
7083 /* Create task copyfn. */
7086 create_task_copyfn (gomp_task
*task_stmt
, omp_context
*ctx
)
7088 struct function
*child_cfun
;
7089 tree child_fn
, t
, c
, src
, dst
, f
, sf
, arg
, sarg
, decl
;
7090 tree record_type
, srecord_type
, bind
, list
;
7091 bool record_needs_remap
= false, srecord_needs_remap
= false;
7093 struct omp_taskcopy_context tcctx
;
7094 location_t loc
= gimple_location (task_stmt
);
7096 child_fn
= gimple_omp_task_copy_fn (task_stmt
);
7097 child_cfun
= DECL_STRUCT_FUNCTION (child_fn
);
7098 gcc_assert (child_cfun
->cfg
== NULL
);
7099 DECL_SAVED_TREE (child_fn
) = alloc_stmt_list ();
7101 /* Reset DECL_CONTEXT on function arguments. */
7102 for (t
= DECL_ARGUMENTS (child_fn
); t
; t
= DECL_CHAIN (t
))
7103 DECL_CONTEXT (t
) = child_fn
;
7105 /* Populate the function. */
7106 push_gimplify_context ();
7107 push_cfun (child_cfun
);
7109 bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
7110 TREE_SIDE_EFFECTS (bind
) = 1;
7112 DECL_SAVED_TREE (child_fn
) = bind
;
7113 DECL_SOURCE_LOCATION (child_fn
) = gimple_location (task_stmt
);
7115 /* Remap src and dst argument types if needed. */
7116 record_type
= ctx
->record_type
;
7117 srecord_type
= ctx
->srecord_type
;
7118 for (f
= TYPE_FIELDS (record_type
); f
; f
= DECL_CHAIN (f
))
7119 if (variably_modified_type_p (TREE_TYPE (f
), ctx
->cb
.src_fn
))
7121 record_needs_remap
= true;
7124 for (f
= TYPE_FIELDS (srecord_type
); f
; f
= DECL_CHAIN (f
))
7125 if (variably_modified_type_p (TREE_TYPE (f
), ctx
->cb
.src_fn
))
7127 srecord_needs_remap
= true;
7131 if (record_needs_remap
|| srecord_needs_remap
)
7133 memset (&tcctx
, '\0', sizeof (tcctx
));
7134 tcctx
.cb
.src_fn
= ctx
->cb
.src_fn
;
7135 tcctx
.cb
.dst_fn
= child_fn
;
7136 tcctx
.cb
.src_node
= cgraph_node::get (tcctx
.cb
.src_fn
);
7137 gcc_checking_assert (tcctx
.cb
.src_node
);
7138 tcctx
.cb
.dst_node
= tcctx
.cb
.src_node
;
7139 tcctx
.cb
.src_cfun
= ctx
->cb
.src_cfun
;
7140 tcctx
.cb
.copy_decl
= task_copyfn_copy_decl
;
7141 tcctx
.cb
.eh_lp_nr
= 0;
7142 tcctx
.cb
.transform_call_graph_edges
= CB_CGE_MOVE
;
7143 tcctx
.cb
.decl_map
= new hash_map
<tree
, tree
>;
7146 if (record_needs_remap
)
7147 record_type
= task_copyfn_remap_type (&tcctx
, record_type
);
7148 if (srecord_needs_remap
)
7149 srecord_type
= task_copyfn_remap_type (&tcctx
, srecord_type
);
7152 tcctx
.cb
.decl_map
= NULL
;
7154 arg
= DECL_ARGUMENTS (child_fn
);
7155 TREE_TYPE (arg
) = build_pointer_type (record_type
);
7156 sarg
= DECL_CHAIN (arg
);
7157 TREE_TYPE (sarg
) = build_pointer_type (srecord_type
);
7159 /* First pass: initialize temporaries used in record_type and srecord_type
7160 sizes and field offsets. */
7161 if (tcctx
.cb
.decl_map
)
7162 for (c
= gimple_omp_task_clauses (task_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
7163 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7167 decl
= OMP_CLAUSE_DECL (c
);
7168 p
= tcctx
.cb
.decl_map
->get (decl
);
7171 n
= splay_tree_lookup (ctx
->sfield_map
, (splay_tree_key
) decl
);
7172 sf
= (tree
) n
->value
;
7173 sf
= *tcctx
.cb
.decl_map
->get (sf
);
7174 src
= build_simple_mem_ref_loc (loc
, sarg
);
7175 src
= omp_build_component_ref (src
, sf
);
7176 t
= build2 (MODIFY_EXPR
, TREE_TYPE (*p
), *p
, src
);
7177 append_to_statement_list (t
, &list
);
7180 /* Second pass: copy shared var pointers and copy construct non-VLA
7181 firstprivate vars. */
7182 for (c
= gimple_omp_task_clauses (task_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
7183 switch (OMP_CLAUSE_CODE (c
))
7186 case OMP_CLAUSE_SHARED
:
7187 decl
= OMP_CLAUSE_DECL (c
);
7188 key
= (splay_tree_key
) decl
;
7189 if (OMP_CLAUSE_SHARED_FIRSTPRIVATE (c
))
7190 key
= (splay_tree_key
) &DECL_UID (decl
);
7191 n
= splay_tree_lookup (ctx
->field_map
, key
);
7194 f
= (tree
) n
->value
;
7195 if (tcctx
.cb
.decl_map
)
7196 f
= *tcctx
.cb
.decl_map
->get (f
);
7197 n
= splay_tree_lookup (ctx
->sfield_map
, key
);
7198 sf
= (tree
) n
->value
;
7199 if (tcctx
.cb
.decl_map
)
7200 sf
= *tcctx
.cb
.decl_map
->get (sf
);
7201 src
= build_simple_mem_ref_loc (loc
, sarg
);
7202 src
= omp_build_component_ref (src
, sf
);
7203 dst
= build_simple_mem_ref_loc (loc
, arg
);
7204 dst
= omp_build_component_ref (dst
, f
);
7205 t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
7206 append_to_statement_list (t
, &list
);
7208 case OMP_CLAUSE_FIRSTPRIVATE
:
7209 decl
= OMP_CLAUSE_DECL (c
);
7210 if (is_variable_sized (decl
))
7212 n
= splay_tree_lookup (ctx
->field_map
, (splay_tree_key
) decl
);
7215 f
= (tree
) n
->value
;
7216 if (tcctx
.cb
.decl_map
)
7217 f
= *tcctx
.cb
.decl_map
->get (f
);
7218 n
= splay_tree_lookup (ctx
->sfield_map
, (splay_tree_key
) decl
);
7221 sf
= (tree
) n
->value
;
7222 if (tcctx
.cb
.decl_map
)
7223 sf
= *tcctx
.cb
.decl_map
->get (sf
);
7224 src
= build_simple_mem_ref_loc (loc
, sarg
);
7225 src
= omp_build_component_ref (src
, sf
);
7226 if (use_pointer_for_field (decl
, NULL
) || omp_is_reference (decl
))
7227 src
= build_simple_mem_ref_loc (loc
, src
);
7231 dst
= build_simple_mem_ref_loc (loc
, arg
);
7232 dst
= omp_build_component_ref (dst
, f
);
7233 t
= lang_hooks
.decls
.omp_clause_copy_ctor (c
, dst
, src
);
7234 append_to_statement_list (t
, &list
);
7236 case OMP_CLAUSE_PRIVATE
:
7237 if (! OMP_CLAUSE_PRIVATE_OUTER_REF (c
))
7239 decl
= OMP_CLAUSE_DECL (c
);
7240 n
= splay_tree_lookup (ctx
->field_map
, (splay_tree_key
) decl
);
7241 f
= (tree
) n
->value
;
7242 if (tcctx
.cb
.decl_map
)
7243 f
= *tcctx
.cb
.decl_map
->get (f
);
7244 n
= splay_tree_lookup (ctx
->sfield_map
, (splay_tree_key
) decl
);
7247 sf
= (tree
) n
->value
;
7248 if (tcctx
.cb
.decl_map
)
7249 sf
= *tcctx
.cb
.decl_map
->get (sf
);
7250 src
= build_simple_mem_ref_loc (loc
, sarg
);
7251 src
= omp_build_component_ref (src
, sf
);
7252 if (use_pointer_for_field (decl
, NULL
))
7253 src
= build_simple_mem_ref_loc (loc
, src
);
7257 dst
= build_simple_mem_ref_loc (loc
, arg
);
7258 dst
= omp_build_component_ref (dst
, f
);
7259 t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
7260 append_to_statement_list (t
, &list
);
7266 /* Last pass: handle VLA firstprivates. */
7267 if (tcctx
.cb
.decl_map
)
7268 for (c
= gimple_omp_task_clauses (task_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
7269 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7273 decl
= OMP_CLAUSE_DECL (c
);
7274 if (!is_variable_sized (decl
))
7276 n
= splay_tree_lookup (ctx
->field_map
, (splay_tree_key
) decl
);
7279 f
= (tree
) n
->value
;
7280 f
= *tcctx
.cb
.decl_map
->get (f
);
7281 gcc_assert (DECL_HAS_VALUE_EXPR_P (decl
));
7282 ind
= DECL_VALUE_EXPR (decl
);
7283 gcc_assert (TREE_CODE (ind
) == INDIRECT_REF
);
7284 gcc_assert (DECL_P (TREE_OPERAND (ind
, 0)));
7285 n
= splay_tree_lookup (ctx
->sfield_map
,
7286 (splay_tree_key
) TREE_OPERAND (ind
, 0));
7287 sf
= (tree
) n
->value
;
7288 sf
= *tcctx
.cb
.decl_map
->get (sf
);
7289 src
= build_simple_mem_ref_loc (loc
, sarg
);
7290 src
= omp_build_component_ref (src
, sf
);
7291 src
= build_simple_mem_ref_loc (loc
, src
);
7292 dst
= build_simple_mem_ref_loc (loc
, arg
);
7293 dst
= omp_build_component_ref (dst
, f
);
7294 t
= lang_hooks
.decls
.omp_clause_copy_ctor (c
, dst
, src
);
7295 append_to_statement_list (t
, &list
);
7296 n
= splay_tree_lookup (ctx
->field_map
,
7297 (splay_tree_key
) TREE_OPERAND (ind
, 0));
7298 df
= (tree
) n
->value
;
7299 df
= *tcctx
.cb
.decl_map
->get (df
);
7300 ptr
= build_simple_mem_ref_loc (loc
, arg
);
7301 ptr
= omp_build_component_ref (ptr
, df
);
7302 t
= build2 (MODIFY_EXPR
, TREE_TYPE (ptr
), ptr
,
7303 build_fold_addr_expr_loc (loc
, dst
));
7304 append_to_statement_list (t
, &list
);
7307 t
= build1 (RETURN_EXPR
, void_type_node
, NULL
);
7308 append_to_statement_list (t
, &list
);
7310 if (tcctx
.cb
.decl_map
)
7311 delete tcctx
.cb
.decl_map
;
7312 pop_gimplify_context (NULL
);
7313 BIND_EXPR_BODY (bind
) = list
;
7318 lower_depend_clauses (tree
*pclauses
, gimple_seq
*iseq
, gimple_seq
*oseq
)
7322 size_t n_in
= 0, n_out
= 0, idx
= 2, i
;
7324 clauses
= omp_find_clause (*pclauses
, OMP_CLAUSE_DEPEND
);
7325 gcc_assert (clauses
);
7326 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7327 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
7328 switch (OMP_CLAUSE_DEPEND_KIND (c
))
7330 case OMP_CLAUSE_DEPEND_IN
:
7333 case OMP_CLAUSE_DEPEND_OUT
:
7334 case OMP_CLAUSE_DEPEND_INOUT
:
7337 case OMP_CLAUSE_DEPEND_SOURCE
:
7338 case OMP_CLAUSE_DEPEND_SINK
:
7343 tree type
= build_array_type_nelts (ptr_type_node
, n_in
+ n_out
+ 2);
7344 tree array
= create_tmp_var (type
);
7345 TREE_ADDRESSABLE (array
) = 1;
7346 tree r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (0), NULL_TREE
,
7348 g
= gimple_build_assign (r
, build_int_cst (ptr_type_node
, n_in
+ n_out
));
7349 gimple_seq_add_stmt (iseq
, g
);
7350 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (1), NULL_TREE
,
7352 g
= gimple_build_assign (r
, build_int_cst (ptr_type_node
, n_out
));
7353 gimple_seq_add_stmt (iseq
, g
);
7354 for (i
= 0; i
< 2; i
++)
7356 if ((i
? n_in
: n_out
) == 0)
7358 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7359 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7360 && ((OMP_CLAUSE_DEPEND_KIND (c
) != OMP_CLAUSE_DEPEND_IN
) ^ i
))
7362 tree t
= OMP_CLAUSE_DECL (c
);
7363 t
= fold_convert (ptr_type_node
, t
);
7364 gimplify_expr (&t
, iseq
, NULL
, is_gimple_val
, fb_rvalue
);
7365 r
= build4 (ARRAY_REF
, ptr_type_node
, array
, size_int (idx
++),
7366 NULL_TREE
, NULL_TREE
);
7367 g
= gimple_build_assign (r
, t
);
7368 gimple_seq_add_stmt (iseq
, g
);
7371 c
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE_DEPEND
);
7372 OMP_CLAUSE_DECL (c
) = build_fold_addr_expr (array
);
7373 OMP_CLAUSE_CHAIN (c
) = *pclauses
;
7375 tree clobber
= build_constructor (type
, NULL
);
7376 TREE_THIS_VOLATILE (clobber
) = 1;
7377 g
= gimple_build_assign (array
, clobber
);
7378 gimple_seq_add_stmt (oseq
, g
);
7381 /* Lower the OpenMP parallel or task directive in the current statement
7382 in GSI_P. CTX holds context information for the directive. */
7385 lower_omp_taskreg (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
7389 gimple
*stmt
= gsi_stmt (*gsi_p
);
7390 gbind
*par_bind
, *bind
, *dep_bind
= NULL
;
7391 gimple_seq par_body
, olist
, ilist
, par_olist
, par_rlist
, par_ilist
, new_body
;
7392 location_t loc
= gimple_location (stmt
);
7394 clauses
= gimple_omp_taskreg_clauses (stmt
);
7396 = as_a
<gbind
*> (gimple_seq_first_stmt (gimple_omp_body (stmt
)));
7397 par_body
= gimple_bind_body (par_bind
);
7398 child_fn
= ctx
->cb
.dst_fn
;
7399 if (gimple_code (stmt
) == GIMPLE_OMP_PARALLEL
7400 && !gimple_omp_parallel_combined_p (stmt
))
7402 struct walk_stmt_info wi
;
7405 memset (&wi
, 0, sizeof (wi
));
7408 walk_gimple_seq (par_body
, check_combined_parallel
, NULL
, &wi
);
7410 gimple_omp_parallel_set_combined_p (stmt
, true);
7412 gimple_seq dep_ilist
= NULL
;
7413 gimple_seq dep_olist
= NULL
;
7414 if (gimple_code (stmt
) == GIMPLE_OMP_TASK
7415 && omp_find_clause (clauses
, OMP_CLAUSE_DEPEND
))
7417 push_gimplify_context ();
7418 dep_bind
= gimple_build_bind (NULL
, NULL
, make_node (BLOCK
));
7419 lower_depend_clauses (gimple_omp_task_clauses_ptr (stmt
),
7420 &dep_ilist
, &dep_olist
);
7423 if (ctx
->srecord_type
)
7424 create_task_copyfn (as_a
<gomp_task
*> (stmt
), ctx
);
7426 push_gimplify_context ();
7431 bool phony_construct
= gimple_code (stmt
) == GIMPLE_OMP_PARALLEL
7432 && gimple_omp_parallel_grid_phony (as_a
<gomp_parallel
*> (stmt
));
7433 if (phony_construct
&& ctx
->record_type
)
7435 gcc_checking_assert (!ctx
->receiver_decl
);
7436 ctx
->receiver_decl
= create_tmp_var
7437 (build_reference_type (ctx
->record_type
), ".omp_rec");
7439 lower_rec_input_clauses (clauses
, &par_ilist
, &par_olist
, ctx
, NULL
);
7440 lower_omp (&par_body
, ctx
);
7441 if (gimple_code (stmt
) == GIMPLE_OMP_PARALLEL
)
7442 lower_reduction_clauses (clauses
, &par_rlist
, ctx
);
7444 /* Declare all the variables created by mapping and the variables
7445 declared in the scope of the parallel body. */
7446 record_vars_into (ctx
->block_vars
, child_fn
);
7447 record_vars_into (gimple_bind_vars (par_bind
), child_fn
);
7449 if (ctx
->record_type
)
7452 = create_tmp_var (ctx
->srecord_type
? ctx
->srecord_type
7453 : ctx
->record_type
, ".omp_data_o");
7454 DECL_NAMELESS (ctx
->sender_decl
) = 1;
7455 TREE_ADDRESSABLE (ctx
->sender_decl
) = 1;
7456 gimple_omp_taskreg_set_data_arg (stmt
, ctx
->sender_decl
);
7461 lower_send_clauses (clauses
, &ilist
, &olist
, ctx
);
7462 lower_send_shared_vars (&ilist
, &olist
, ctx
);
7464 if (ctx
->record_type
)
7466 tree clobber
= build_constructor (TREE_TYPE (ctx
->sender_decl
), NULL
);
7467 TREE_THIS_VOLATILE (clobber
) = 1;
7468 gimple_seq_add_stmt (&olist
, gimple_build_assign (ctx
->sender_decl
,
7472 /* Once all the expansions are done, sequence all the different
7473 fragments inside gimple_omp_body. */
7477 if (ctx
->record_type
)
7479 t
= build_fold_addr_expr_loc (loc
, ctx
->sender_decl
);
7480 /* fixup_child_record_type might have changed receiver_decl's type. */
7481 t
= fold_convert_loc (loc
, TREE_TYPE (ctx
->receiver_decl
), t
);
7482 gimple_seq_add_stmt (&new_body
,
7483 gimple_build_assign (ctx
->receiver_decl
, t
));
7486 gimple_seq_add_seq (&new_body
, par_ilist
);
7487 gimple_seq_add_seq (&new_body
, par_body
);
7488 gimple_seq_add_seq (&new_body
, par_rlist
);
7489 if (ctx
->cancellable
)
7490 gimple_seq_add_stmt (&new_body
, gimple_build_label (ctx
->cancel_label
));
7491 gimple_seq_add_seq (&new_body
, par_olist
);
7492 new_body
= maybe_catch_exception (new_body
);
7493 if (gimple_code (stmt
) == GIMPLE_OMP_TASK
)
7494 gimple_seq_add_stmt (&new_body
,
7495 gimple_build_omp_continue (integer_zero_node
,
7496 integer_zero_node
));
7497 if (!phony_construct
)
7499 gimple_seq_add_stmt (&new_body
, gimple_build_omp_return (false));
7500 gimple_omp_set_body (stmt
, new_body
);
7503 bind
= gimple_build_bind (NULL
, NULL
, gimple_bind_block (par_bind
));
7504 gsi_replace (gsi_p
, dep_bind
? dep_bind
: bind
, true);
7505 gimple_bind_add_seq (bind
, ilist
);
7506 if (!phony_construct
)
7507 gimple_bind_add_stmt (bind
, stmt
);
7509 gimple_bind_add_seq (bind
, new_body
);
7510 gimple_bind_add_seq (bind
, olist
);
7512 pop_gimplify_context (NULL
);
7516 gimple_bind_add_seq (dep_bind
, dep_ilist
);
7517 gimple_bind_add_stmt (dep_bind
, bind
);
7518 gimple_bind_add_seq (dep_bind
, dep_olist
);
7519 pop_gimplify_context (dep_bind
);
7523 /* Lower the GIMPLE_OMP_TARGET in the current statement
7524 in GSI_P. CTX holds context information for the directive. */
7527 lower_omp_target (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
7530 tree child_fn
, t
, c
;
7531 gomp_target
*stmt
= as_a
<gomp_target
*> (gsi_stmt (*gsi_p
));
7532 gbind
*tgt_bind
, *bind
, *dep_bind
= NULL
;
7533 gimple_seq tgt_body
, olist
, ilist
, fplist
, new_body
;
7534 location_t loc
= gimple_location (stmt
);
7535 bool offloaded
, data_region
;
7536 unsigned int map_cnt
= 0;
7538 offloaded
= is_gimple_omp_offloaded (stmt
);
7539 switch (gimple_omp_target_kind (stmt
))
7541 case GF_OMP_TARGET_KIND_REGION
:
7542 case GF_OMP_TARGET_KIND_UPDATE
:
7543 case GF_OMP_TARGET_KIND_ENTER_DATA
:
7544 case GF_OMP_TARGET_KIND_EXIT_DATA
:
7545 case GF_OMP_TARGET_KIND_OACC_PARALLEL
:
7546 case GF_OMP_TARGET_KIND_OACC_KERNELS
:
7547 case GF_OMP_TARGET_KIND_OACC_UPDATE
:
7548 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA
:
7549 case GF_OMP_TARGET_KIND_OACC_DECLARE
:
7550 data_region
= false;
7552 case GF_OMP_TARGET_KIND_DATA
:
7553 case GF_OMP_TARGET_KIND_OACC_DATA
:
7554 case GF_OMP_TARGET_KIND_OACC_HOST_DATA
:
7561 clauses
= gimple_omp_target_clauses (stmt
);
7563 gimple_seq dep_ilist
= NULL
;
7564 gimple_seq dep_olist
= NULL
;
7565 if (omp_find_clause (clauses
, OMP_CLAUSE_DEPEND
))
7567 push_gimplify_context ();
7568 dep_bind
= gimple_build_bind (NULL
, NULL
, make_node (BLOCK
));
7569 lower_depend_clauses (gimple_omp_target_clauses_ptr (stmt
),
7570 &dep_ilist
, &dep_olist
);
7577 tgt_bind
= gimple_seq_first_stmt_as_a_bind (gimple_omp_body (stmt
));
7578 tgt_body
= gimple_bind_body (tgt_bind
);
7580 else if (data_region
)
7581 tgt_body
= gimple_omp_body (stmt
);
7582 child_fn
= ctx
->cb
.dst_fn
;
7584 push_gimplify_context ();
7587 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7588 switch (OMP_CLAUSE_CODE (c
))
7594 case OMP_CLAUSE_MAP
:
7596 /* First check what we're prepared to handle in the following. */
7597 switch (OMP_CLAUSE_MAP_KIND (c
))
7599 case GOMP_MAP_ALLOC
:
7602 case GOMP_MAP_TOFROM
:
7603 case GOMP_MAP_POINTER
:
7604 case GOMP_MAP_TO_PSET
:
7605 case GOMP_MAP_DELETE
:
7606 case GOMP_MAP_RELEASE
:
7607 case GOMP_MAP_ALWAYS_TO
:
7608 case GOMP_MAP_ALWAYS_FROM
:
7609 case GOMP_MAP_ALWAYS_TOFROM
:
7610 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
7611 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
7612 case GOMP_MAP_STRUCT
:
7613 case GOMP_MAP_ALWAYS_POINTER
:
7615 case GOMP_MAP_FORCE_ALLOC
:
7616 case GOMP_MAP_FORCE_TO
:
7617 case GOMP_MAP_FORCE_FROM
:
7618 case GOMP_MAP_FORCE_TOFROM
:
7619 case GOMP_MAP_FORCE_PRESENT
:
7620 case GOMP_MAP_FORCE_DEVICEPTR
:
7621 case GOMP_MAP_DEVICE_RESIDENT
:
7623 gcc_assert (is_gimple_omp_oacc (stmt
));
7631 case OMP_CLAUSE_FROM
:
7633 var
= OMP_CLAUSE_DECL (c
);
7636 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7637 || (!OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
)
7638 && (OMP_CLAUSE_MAP_KIND (c
)
7639 != GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7645 && TREE_CODE (DECL_SIZE (var
)) != INTEGER_CST
)
7647 tree var2
= DECL_VALUE_EXPR (var
);
7648 gcc_assert (TREE_CODE (var2
) == INDIRECT_REF
);
7649 var2
= TREE_OPERAND (var2
, 0);
7650 gcc_assert (DECL_P (var2
));
7655 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7656 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
7657 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
7659 if (TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
)
7661 if (is_global_var (maybe_lookup_decl_in_outer_ctx (var
, ctx
))
7662 && varpool_node::get_create (var
)->offloadable
)
7665 tree type
= build_pointer_type (TREE_TYPE (var
));
7666 tree new_var
= lookup_decl (var
, ctx
);
7667 x
= create_tmp_var_raw (type
, get_name (new_var
));
7668 gimple_add_tmp_var (x
);
7669 x
= build_simple_mem_ref (x
);
7670 SET_DECL_VALUE_EXPR (new_var
, x
);
7671 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7676 if (!maybe_lookup_field (var
, ctx
))
7679 /* Don't remap oacc parallel reduction variables, because the
7680 intermediate result must be local to each gang. */
7681 if (offloaded
&& !(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7682 && OMP_CLAUSE_MAP_IN_REDUCTION (c
)))
7684 x
= build_receiver_ref (var
, true, ctx
);
7685 tree new_var
= lookup_decl (var
, ctx
);
7687 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7688 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7689 && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
)
7690 && TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
)
7691 x
= build_simple_mem_ref (x
);
7692 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7694 gcc_assert (is_gimple_omp_oacc (ctx
->stmt
));
7695 if (omp_is_reference (new_var
))
7697 /* Create a local object to hold the instance
7699 tree type
= TREE_TYPE (TREE_TYPE (new_var
));
7700 const char *id
= IDENTIFIER_POINTER (DECL_NAME (new_var
));
7701 tree inst
= create_tmp_var (type
, id
);
7702 gimplify_assign (inst
, fold_indirect_ref (x
), &fplist
);
7703 x
= build_fold_addr_expr (inst
);
7705 gimplify_assign (new_var
, x
, &fplist
);
7707 else if (DECL_P (new_var
))
7709 SET_DECL_VALUE_EXPR (new_var
, x
);
7710 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7718 case OMP_CLAUSE_FIRSTPRIVATE
:
7719 if (is_oacc_parallel (ctx
))
7720 goto oacc_firstprivate
;
7722 var
= OMP_CLAUSE_DECL (c
);
7723 if (!omp_is_reference (var
)
7724 && !is_gimple_reg_type (TREE_TYPE (var
)))
7726 tree new_var
= lookup_decl (var
, ctx
);
7727 if (is_variable_sized (var
))
7729 tree pvar
= DECL_VALUE_EXPR (var
);
7730 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
7731 pvar
= TREE_OPERAND (pvar
, 0);
7732 gcc_assert (DECL_P (pvar
));
7733 tree new_pvar
= lookup_decl (pvar
, ctx
);
7734 x
= build_fold_indirect_ref (new_pvar
);
7735 TREE_THIS_NOTRAP (x
) = 1;
7738 x
= build_receiver_ref (var
, true, ctx
);
7739 SET_DECL_VALUE_EXPR (new_var
, x
);
7740 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7744 case OMP_CLAUSE_PRIVATE
:
7745 if (is_gimple_omp_oacc (ctx
->stmt
))
7747 var
= OMP_CLAUSE_DECL (c
);
7748 if (is_variable_sized (var
))
7750 tree new_var
= lookup_decl (var
, ctx
);
7751 tree pvar
= DECL_VALUE_EXPR (var
);
7752 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
7753 pvar
= TREE_OPERAND (pvar
, 0);
7754 gcc_assert (DECL_P (pvar
));
7755 tree new_pvar
= lookup_decl (pvar
, ctx
);
7756 x
= build_fold_indirect_ref (new_pvar
);
7757 TREE_THIS_NOTRAP (x
) = 1;
7758 SET_DECL_VALUE_EXPR (new_var
, x
);
7759 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7763 case OMP_CLAUSE_USE_DEVICE_PTR
:
7764 case OMP_CLAUSE_IS_DEVICE_PTR
:
7765 var
= OMP_CLAUSE_DECL (c
);
7767 if (is_variable_sized (var
))
7769 tree new_var
= lookup_decl (var
, ctx
);
7770 tree pvar
= DECL_VALUE_EXPR (var
);
7771 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
7772 pvar
= TREE_OPERAND (pvar
, 0);
7773 gcc_assert (DECL_P (pvar
));
7774 tree new_pvar
= lookup_decl (pvar
, ctx
);
7775 x
= build_fold_indirect_ref (new_pvar
);
7776 TREE_THIS_NOTRAP (x
) = 1;
7777 SET_DECL_VALUE_EXPR (new_var
, x
);
7778 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7780 else if (TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
)
7782 tree new_var
= lookup_decl (var
, ctx
);
7783 tree type
= build_pointer_type (TREE_TYPE (var
));
7784 x
= create_tmp_var_raw (type
, get_name (new_var
));
7785 gimple_add_tmp_var (x
);
7786 x
= build_simple_mem_ref (x
);
7787 SET_DECL_VALUE_EXPR (new_var
, x
);
7788 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7792 tree new_var
= lookup_decl (var
, ctx
);
7793 x
= create_tmp_var_raw (TREE_TYPE (new_var
), get_name (new_var
));
7794 gimple_add_tmp_var (x
);
7795 SET_DECL_VALUE_EXPR (new_var
, x
);
7796 DECL_HAS_VALUE_EXPR_P (new_var
) = 1;
7803 target_nesting_level
++;
7804 lower_omp (&tgt_body
, ctx
);
7805 target_nesting_level
--;
7807 else if (data_region
)
7808 lower_omp (&tgt_body
, ctx
);
7812 /* Declare all the variables created by mapping and the variables
7813 declared in the scope of the target body. */
7814 record_vars_into (ctx
->block_vars
, child_fn
);
7815 record_vars_into (gimple_bind_vars (tgt_bind
), child_fn
);
7820 if (ctx
->record_type
)
7823 = create_tmp_var (ctx
->record_type
, ".omp_data_arr");
7824 DECL_NAMELESS (ctx
->sender_decl
) = 1;
7825 TREE_ADDRESSABLE (ctx
->sender_decl
) = 1;
7826 t
= make_tree_vec (3);
7827 TREE_VEC_ELT (t
, 0) = ctx
->sender_decl
;
7829 = create_tmp_var (build_array_type_nelts (size_type_node
, map_cnt
),
7831 DECL_NAMELESS (TREE_VEC_ELT (t
, 1)) = 1;
7832 TREE_ADDRESSABLE (TREE_VEC_ELT (t
, 1)) = 1;
7833 TREE_STATIC (TREE_VEC_ELT (t
, 1)) = 1;
7834 tree tkind_type
= short_unsigned_type_node
;
7835 int talign_shift
= 8;
7837 = create_tmp_var (build_array_type_nelts (tkind_type
, map_cnt
),
7839 DECL_NAMELESS (TREE_VEC_ELT (t
, 2)) = 1;
7840 TREE_ADDRESSABLE (TREE_VEC_ELT (t
, 2)) = 1;
7841 TREE_STATIC (TREE_VEC_ELT (t
, 2)) = 1;
7842 gimple_omp_target_set_data_arg (stmt
, t
);
7844 vec
<constructor_elt
, va_gc
> *vsize
;
7845 vec
<constructor_elt
, va_gc
> *vkind
;
7846 vec_alloc (vsize
, map_cnt
);
7847 vec_alloc (vkind
, map_cnt
);
7848 unsigned int map_idx
= 0;
7850 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7851 switch (OMP_CLAUSE_CODE (c
))
7853 tree ovar
, nc
, s
, purpose
, var
, x
, type
;
7854 unsigned int talign
;
7859 case OMP_CLAUSE_MAP
:
7861 case OMP_CLAUSE_FROM
:
7862 oacc_firstprivate_map
:
7864 ovar
= OMP_CLAUSE_DECL (c
);
7865 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7866 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
7867 || (OMP_CLAUSE_MAP_KIND (c
)
7868 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
)))
7872 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7873 && OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
))
7875 gcc_checking_assert (OMP_CLAUSE_DECL (OMP_CLAUSE_CHAIN (c
))
7876 == get_base_address (ovar
));
7877 nc
= OMP_CLAUSE_CHAIN (c
);
7878 ovar
= OMP_CLAUSE_DECL (nc
);
7882 tree x
= build_sender_ref (ovar
, ctx
);
7884 = build_fold_addr_expr_with_type (ovar
, ptr_type_node
);
7885 gimplify_assign (x
, v
, &ilist
);
7891 if (DECL_SIZE (ovar
)
7892 && TREE_CODE (DECL_SIZE (ovar
)) != INTEGER_CST
)
7894 tree ovar2
= DECL_VALUE_EXPR (ovar
);
7895 gcc_assert (TREE_CODE (ovar2
) == INDIRECT_REF
);
7896 ovar2
= TREE_OPERAND (ovar2
, 0);
7897 gcc_assert (DECL_P (ovar2
));
7900 if (!maybe_lookup_field (ovar
, ctx
))
7904 talign
= TYPE_ALIGN_UNIT (TREE_TYPE (ovar
));
7905 if (DECL_P (ovar
) && DECL_ALIGN_UNIT (ovar
) > talign
)
7906 talign
= DECL_ALIGN_UNIT (ovar
);
7909 var
= lookup_decl_in_outer_ctx (ovar
, ctx
);
7910 x
= build_sender_ref (ovar
, ctx
);
7912 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7913 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7914 && !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c
)
7915 && TREE_CODE (TREE_TYPE (ovar
)) == ARRAY_TYPE
)
7917 gcc_assert (offloaded
);
7919 = create_tmp_var (TREE_TYPE (TREE_TYPE (x
)));
7920 mark_addressable (avar
);
7921 gimplify_assign (avar
, build_fold_addr_expr (var
), &ilist
);
7922 talign
= DECL_ALIGN_UNIT (avar
);
7923 avar
= build_fold_addr_expr (avar
);
7924 gimplify_assign (x
, avar
, &ilist
);
7926 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7928 gcc_assert (is_gimple_omp_oacc (ctx
->stmt
));
7929 if (!omp_is_reference (var
))
7931 if (is_gimple_reg (var
)
7932 && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
))
7933 TREE_NO_WARNING (var
) = 1;
7934 var
= build_fold_addr_expr (var
);
7937 talign
= TYPE_ALIGN_UNIT (TREE_TYPE (TREE_TYPE (ovar
)));
7938 gimplify_assign (x
, var
, &ilist
);
7940 else if (is_gimple_reg (var
))
7942 gcc_assert (offloaded
);
7943 tree avar
= create_tmp_var (TREE_TYPE (var
));
7944 mark_addressable (avar
);
7945 enum gomp_map_kind map_kind
= OMP_CLAUSE_MAP_KIND (c
);
7946 if (GOMP_MAP_COPY_TO_P (map_kind
)
7947 || map_kind
== GOMP_MAP_POINTER
7948 || map_kind
== GOMP_MAP_TO_PSET
7949 || map_kind
== GOMP_MAP_FORCE_DEVICEPTR
)
7951 /* If we need to initialize a temporary
7952 with VAR because it is not addressable, and
7953 the variable hasn't been initialized yet, then
7954 we'll get a warning for the store to avar.
7955 Don't warn in that case, the mapping might
7957 TREE_NO_WARNING (var
) = 1;
7958 gimplify_assign (avar
, var
, &ilist
);
7960 avar
= build_fold_addr_expr (avar
);
7961 gimplify_assign (x
, avar
, &ilist
);
7962 if ((GOMP_MAP_COPY_FROM_P (map_kind
)
7963 || map_kind
== GOMP_MAP_FORCE_DEVICEPTR
)
7964 && !TYPE_READONLY (TREE_TYPE (var
)))
7966 x
= unshare_expr (x
);
7967 x
= build_simple_mem_ref (x
);
7968 gimplify_assign (var
, x
, &olist
);
7973 var
= build_fold_addr_expr (var
);
7974 gimplify_assign (x
, var
, &ilist
);
7978 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
7980 gcc_checking_assert (is_gimple_omp_oacc (ctx
->stmt
));
7981 s
= TREE_TYPE (ovar
);
7982 if (TREE_CODE (s
) == REFERENCE_TYPE
)
7984 s
= TYPE_SIZE_UNIT (s
);
7987 s
= OMP_CLAUSE_SIZE (c
);
7989 s
= TYPE_SIZE_UNIT (TREE_TYPE (ovar
));
7990 s
= fold_convert (size_type_node
, s
);
7991 purpose
= size_int (map_idx
++);
7992 CONSTRUCTOR_APPEND_ELT (vsize
, purpose
, s
);
7993 if (TREE_CODE (s
) != INTEGER_CST
)
7994 TREE_STATIC (TREE_VEC_ELT (t
, 1)) = 0;
7996 unsigned HOST_WIDE_INT tkind
, tkind_zero
;
7997 switch (OMP_CLAUSE_CODE (c
))
7999 case OMP_CLAUSE_MAP
:
8000 tkind
= OMP_CLAUSE_MAP_KIND (c
);
8002 if (OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
))
8005 case GOMP_MAP_ALLOC
:
8008 case GOMP_MAP_TOFROM
:
8009 case GOMP_MAP_ALWAYS_TO
:
8010 case GOMP_MAP_ALWAYS_FROM
:
8011 case GOMP_MAP_ALWAYS_TOFROM
:
8012 case GOMP_MAP_RELEASE
:
8013 case GOMP_MAP_FORCE_TO
:
8014 case GOMP_MAP_FORCE_FROM
:
8015 case GOMP_MAP_FORCE_TOFROM
:
8016 case GOMP_MAP_FORCE_PRESENT
:
8017 tkind_zero
= GOMP_MAP_ZERO_LEN_ARRAY_SECTION
;
8019 case GOMP_MAP_DELETE
:
8020 tkind_zero
= GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION
;
8024 if (tkind_zero
!= tkind
)
8026 if (integer_zerop (s
))
8028 else if (integer_nonzerop (s
))
8032 case OMP_CLAUSE_FIRSTPRIVATE
:
8033 gcc_checking_assert (is_gimple_omp_oacc (ctx
->stmt
));
8034 tkind
= GOMP_MAP_TO
;
8038 tkind
= GOMP_MAP_TO
;
8041 case OMP_CLAUSE_FROM
:
8042 tkind
= GOMP_MAP_FROM
;
8048 gcc_checking_assert (tkind
8049 < (HOST_WIDE_INT_C (1U) << talign_shift
));
8050 gcc_checking_assert (tkind_zero
8051 < (HOST_WIDE_INT_C (1U) << talign_shift
));
8052 talign
= ceil_log2 (talign
);
8053 tkind
|= talign
<< talign_shift
;
8054 tkind_zero
|= talign
<< talign_shift
;
8055 gcc_checking_assert (tkind
8056 <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type
)));
8057 gcc_checking_assert (tkind_zero
8058 <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type
)));
8059 if (tkind
== tkind_zero
)
8060 x
= build_int_cstu (tkind_type
, tkind
);
8063 TREE_STATIC (TREE_VEC_ELT (t
, 2)) = 0;
8064 x
= build3 (COND_EXPR
, tkind_type
,
8065 fold_build2 (EQ_EXPR
, boolean_type_node
,
8066 unshare_expr (s
), size_zero_node
),
8067 build_int_cstu (tkind_type
, tkind_zero
),
8068 build_int_cstu (tkind_type
, tkind
));
8070 CONSTRUCTOR_APPEND_ELT (vkind
, purpose
, x
);
8075 case OMP_CLAUSE_FIRSTPRIVATE
:
8076 if (is_oacc_parallel (ctx
))
8077 goto oacc_firstprivate_map
;
8078 ovar
= OMP_CLAUSE_DECL (c
);
8079 if (omp_is_reference (ovar
))
8080 talign
= TYPE_ALIGN_UNIT (TREE_TYPE (TREE_TYPE (ovar
)));
8082 talign
= DECL_ALIGN_UNIT (ovar
);
8083 var
= lookup_decl_in_outer_ctx (ovar
, ctx
);
8084 x
= build_sender_ref (ovar
, ctx
);
8085 tkind
= GOMP_MAP_FIRSTPRIVATE
;
8086 type
= TREE_TYPE (ovar
);
8087 if (omp_is_reference (ovar
))
8088 type
= TREE_TYPE (type
);
8089 if ((INTEGRAL_TYPE_P (type
)
8090 && TYPE_PRECISION (type
) <= POINTER_SIZE
)
8091 || TREE_CODE (type
) == POINTER_TYPE
)
8093 tkind
= GOMP_MAP_FIRSTPRIVATE_INT
;
8095 if (omp_is_reference (var
))
8096 t
= build_simple_mem_ref (var
);
8097 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
))
8098 TREE_NO_WARNING (var
) = 1;
8099 if (TREE_CODE (type
) != POINTER_TYPE
)
8100 t
= fold_convert (pointer_sized_int_node
, t
);
8101 t
= fold_convert (TREE_TYPE (x
), t
);
8102 gimplify_assign (x
, t
, &ilist
);
8104 else if (omp_is_reference (var
))
8105 gimplify_assign (x
, var
, &ilist
);
8106 else if (is_gimple_reg (var
))
8108 tree avar
= create_tmp_var (TREE_TYPE (var
));
8109 mark_addressable (avar
);
8110 if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
))
8111 TREE_NO_WARNING (var
) = 1;
8112 gimplify_assign (avar
, var
, &ilist
);
8113 avar
= build_fold_addr_expr (avar
);
8114 gimplify_assign (x
, avar
, &ilist
);
8118 var
= build_fold_addr_expr (var
);
8119 gimplify_assign (x
, var
, &ilist
);
8121 if (tkind
== GOMP_MAP_FIRSTPRIVATE_INT
)
8123 else if (omp_is_reference (ovar
))
8124 s
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ovar
)));
8126 s
= TYPE_SIZE_UNIT (TREE_TYPE (ovar
));
8127 s
= fold_convert (size_type_node
, s
);
8128 purpose
= size_int (map_idx
++);
8129 CONSTRUCTOR_APPEND_ELT (vsize
, purpose
, s
);
8130 if (TREE_CODE (s
) != INTEGER_CST
)
8131 TREE_STATIC (TREE_VEC_ELT (t
, 1)) = 0;
8133 gcc_checking_assert (tkind
8134 < (HOST_WIDE_INT_C (1U) << talign_shift
));
8135 talign
= ceil_log2 (talign
);
8136 tkind
|= talign
<< talign_shift
;
8137 gcc_checking_assert (tkind
8138 <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type
)));
8139 CONSTRUCTOR_APPEND_ELT (vkind
, purpose
,
8140 build_int_cstu (tkind_type
, tkind
));
8143 case OMP_CLAUSE_USE_DEVICE_PTR
:
8144 case OMP_CLAUSE_IS_DEVICE_PTR
:
8145 ovar
= OMP_CLAUSE_DECL (c
);
8146 var
= lookup_decl_in_outer_ctx (ovar
, ctx
);
8147 x
= build_sender_ref (ovar
, ctx
);
8148 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
)
8149 tkind
= GOMP_MAP_USE_DEVICE_PTR
;
8151 tkind
= GOMP_MAP_FIRSTPRIVATE_INT
;
8152 type
= TREE_TYPE (ovar
);
8153 if (TREE_CODE (type
) == ARRAY_TYPE
)
8154 var
= build_fold_addr_expr (var
);
8157 if (omp_is_reference (ovar
))
8159 type
= TREE_TYPE (type
);
8160 if (TREE_CODE (type
) != ARRAY_TYPE
)
8161 var
= build_simple_mem_ref (var
);
8162 var
= fold_convert (TREE_TYPE (x
), var
);
8165 gimplify_assign (x
, var
, &ilist
);
8167 purpose
= size_int (map_idx
++);
8168 CONSTRUCTOR_APPEND_ELT (vsize
, purpose
, s
);
8169 gcc_checking_assert (tkind
8170 < (HOST_WIDE_INT_C (1U) << talign_shift
));
8171 gcc_checking_assert (tkind
8172 <= tree_to_uhwi (TYPE_MAX_VALUE (tkind_type
)));
8173 CONSTRUCTOR_APPEND_ELT (vkind
, purpose
,
8174 build_int_cstu (tkind_type
, tkind
));
8178 gcc_assert (map_idx
== map_cnt
);
8180 DECL_INITIAL (TREE_VEC_ELT (t
, 1))
8181 = build_constructor (TREE_TYPE (TREE_VEC_ELT (t
, 1)), vsize
);
8182 DECL_INITIAL (TREE_VEC_ELT (t
, 2))
8183 = build_constructor (TREE_TYPE (TREE_VEC_ELT (t
, 2)), vkind
);
8184 for (int i
= 1; i
<= 2; i
++)
8185 if (!TREE_STATIC (TREE_VEC_ELT (t
, i
)))
8187 gimple_seq initlist
= NULL
;
8188 force_gimple_operand (build1 (DECL_EXPR
, void_type_node
,
8189 TREE_VEC_ELT (t
, i
)),
8190 &initlist
, true, NULL_TREE
);
8191 gimple_seq_add_seq (&ilist
, initlist
);
8193 tree clobber
= build_constructor (TREE_TYPE (TREE_VEC_ELT (t
, i
)),
8195 TREE_THIS_VOLATILE (clobber
) = 1;
8196 gimple_seq_add_stmt (&olist
,
8197 gimple_build_assign (TREE_VEC_ELT (t
, i
),
8201 tree clobber
= build_constructor (ctx
->record_type
, NULL
);
8202 TREE_THIS_VOLATILE (clobber
) = 1;
8203 gimple_seq_add_stmt (&olist
, gimple_build_assign (ctx
->sender_decl
,
8207 /* Once all the expansions are done, sequence all the different
8208 fragments inside gimple_omp_body. */
8213 && ctx
->record_type
)
8215 t
= build_fold_addr_expr_loc (loc
, ctx
->sender_decl
);
8216 /* fixup_child_record_type might have changed receiver_decl's type. */
8217 t
= fold_convert_loc (loc
, TREE_TYPE (ctx
->receiver_decl
), t
);
8218 gimple_seq_add_stmt (&new_body
,
8219 gimple_build_assign (ctx
->receiver_decl
, t
));
8221 gimple_seq_add_seq (&new_body
, fplist
);
8223 if (offloaded
|| data_region
)
8225 tree prev
= NULL_TREE
;
8226 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8227 switch (OMP_CLAUSE_CODE (c
))
8232 case OMP_CLAUSE_FIRSTPRIVATE
:
8233 if (is_gimple_omp_oacc (ctx
->stmt
))
8235 var
= OMP_CLAUSE_DECL (c
);
8236 if (omp_is_reference (var
)
8237 || is_gimple_reg_type (TREE_TYPE (var
)))
8239 tree new_var
= lookup_decl (var
, ctx
);
8241 type
= TREE_TYPE (var
);
8242 if (omp_is_reference (var
))
8243 type
= TREE_TYPE (type
);
8244 if ((INTEGRAL_TYPE_P (type
)
8245 && TYPE_PRECISION (type
) <= POINTER_SIZE
)
8246 || TREE_CODE (type
) == POINTER_TYPE
)
8248 x
= build_receiver_ref (var
, false, ctx
);
8249 if (TREE_CODE (type
) != POINTER_TYPE
)
8250 x
= fold_convert (pointer_sized_int_node
, x
);
8251 x
= fold_convert (type
, x
);
8252 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
,
8254 if (omp_is_reference (var
))
8256 tree v
= create_tmp_var_raw (type
, get_name (var
));
8257 gimple_add_tmp_var (v
);
8258 TREE_ADDRESSABLE (v
) = 1;
8259 gimple_seq_add_stmt (&new_body
,
8260 gimple_build_assign (v
, x
));
8261 x
= build_fold_addr_expr (v
);
8263 gimple_seq_add_stmt (&new_body
,
8264 gimple_build_assign (new_var
, x
));
8268 x
= build_receiver_ref (var
, !omp_is_reference (var
), ctx
);
8269 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
,
8271 gimple_seq_add_stmt (&new_body
,
8272 gimple_build_assign (new_var
, x
));
8275 else if (is_variable_sized (var
))
8277 tree pvar
= DECL_VALUE_EXPR (var
);
8278 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
8279 pvar
= TREE_OPERAND (pvar
, 0);
8280 gcc_assert (DECL_P (pvar
));
8281 tree new_var
= lookup_decl (pvar
, ctx
);
8282 x
= build_receiver_ref (var
, false, ctx
);
8283 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8284 gimple_seq_add_stmt (&new_body
,
8285 gimple_build_assign (new_var
, x
));
8288 case OMP_CLAUSE_PRIVATE
:
8289 if (is_gimple_omp_oacc (ctx
->stmt
))
8291 var
= OMP_CLAUSE_DECL (c
);
8292 if (omp_is_reference (var
))
8294 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
8295 tree new_var
= lookup_decl (var
, ctx
);
8296 x
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var
)));
8297 if (TREE_CONSTANT (x
))
8299 x
= create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var
)),
8301 gimple_add_tmp_var (x
);
8302 TREE_ADDRESSABLE (x
) = 1;
8303 x
= build_fold_addr_expr_loc (clause_loc
, x
);
8308 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
8309 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8310 gimple_seq_add_stmt (&new_body
,
8311 gimple_build_assign (new_var
, x
));
8314 case OMP_CLAUSE_USE_DEVICE_PTR
:
8315 case OMP_CLAUSE_IS_DEVICE_PTR
:
8316 var
= OMP_CLAUSE_DECL (c
);
8317 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
)
8318 x
= build_sender_ref (var
, ctx
);
8320 x
= build_receiver_ref (var
, false, ctx
);
8321 if (is_variable_sized (var
))
8323 tree pvar
= DECL_VALUE_EXPR (var
);
8324 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
8325 pvar
= TREE_OPERAND (pvar
, 0);
8326 gcc_assert (DECL_P (pvar
));
8327 tree new_var
= lookup_decl (pvar
, ctx
);
8328 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8329 gimple_seq_add_stmt (&new_body
,
8330 gimple_build_assign (new_var
, x
));
8332 else if (TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
)
8334 tree new_var
= lookup_decl (var
, ctx
);
8335 new_var
= DECL_VALUE_EXPR (new_var
);
8336 gcc_assert (TREE_CODE (new_var
) == MEM_REF
);
8337 new_var
= TREE_OPERAND (new_var
, 0);
8338 gcc_assert (DECL_P (new_var
));
8339 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8340 gimple_seq_add_stmt (&new_body
,
8341 gimple_build_assign (new_var
, x
));
8345 tree type
= TREE_TYPE (var
);
8346 tree new_var
= lookup_decl (var
, ctx
);
8347 if (omp_is_reference (var
))
8349 type
= TREE_TYPE (type
);
8350 if (TREE_CODE (type
) != ARRAY_TYPE
)
8352 tree v
= create_tmp_var_raw (type
, get_name (var
));
8353 gimple_add_tmp_var (v
);
8354 TREE_ADDRESSABLE (v
) = 1;
8355 x
= fold_convert (type
, x
);
8356 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
,
8358 gimple_seq_add_stmt (&new_body
,
8359 gimple_build_assign (v
, x
));
8360 x
= build_fold_addr_expr (v
);
8363 new_var
= DECL_VALUE_EXPR (new_var
);
8364 x
= fold_convert (TREE_TYPE (new_var
), x
);
8365 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8366 gimple_seq_add_stmt (&new_body
,
8367 gimple_build_assign (new_var
, x
));
8371 /* Handle GOMP_MAP_FIRSTPRIVATE_{POINTER,REFERENCE} in second pass,
8372 so that firstprivate vars holding OMP_CLAUSE_SIZE if needed
8373 are already handled. Similarly OMP_CLAUSE_PRIVATE for VLAs
8374 or references to VLAs. */
8375 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8376 switch (OMP_CLAUSE_CODE (c
))
8381 case OMP_CLAUSE_MAP
:
8382 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
8383 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
8385 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
8386 HOST_WIDE_INT offset
= 0;
8388 var
= OMP_CLAUSE_DECL (c
);
8390 && TREE_CODE (TREE_TYPE (var
)) == ARRAY_TYPE
8391 && is_global_var (maybe_lookup_decl_in_outer_ctx (var
,
8393 && varpool_node::get_create (var
)->offloadable
)
8395 if (TREE_CODE (var
) == INDIRECT_REF
8396 && TREE_CODE (TREE_OPERAND (var
, 0)) == COMPONENT_REF
)
8397 var
= TREE_OPERAND (var
, 0);
8398 if (TREE_CODE (var
) == COMPONENT_REF
)
8400 var
= get_addr_base_and_unit_offset (var
, &offset
);
8401 gcc_assert (var
!= NULL_TREE
&& DECL_P (var
));
8403 else if (DECL_SIZE (var
)
8404 && TREE_CODE (DECL_SIZE (var
)) != INTEGER_CST
)
8406 tree var2
= DECL_VALUE_EXPR (var
);
8407 gcc_assert (TREE_CODE (var2
) == INDIRECT_REF
);
8408 var2
= TREE_OPERAND (var2
, 0);
8409 gcc_assert (DECL_P (var2
));
8412 tree new_var
= lookup_decl (var
, ctx
), x
;
8413 tree type
= TREE_TYPE (new_var
);
8415 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == INDIRECT_REF
8416 && (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0))
8419 type
= TREE_TYPE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0));
8421 new_var
= build2 (MEM_REF
, type
,
8422 build_fold_addr_expr (new_var
),
8423 build_int_cst (build_pointer_type (type
),
8426 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
8428 type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
8429 is_ref
= TREE_CODE (type
) == REFERENCE_TYPE
;
8430 new_var
= build2 (MEM_REF
, type
,
8431 build_fold_addr_expr (new_var
),
8432 build_int_cst (build_pointer_type (type
),
8436 is_ref
= omp_is_reference (var
);
8437 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
8439 bool ref_to_array
= false;
8442 type
= TREE_TYPE (type
);
8443 if (TREE_CODE (type
) == ARRAY_TYPE
)
8445 type
= build_pointer_type (type
);
8446 ref_to_array
= true;
8449 else if (TREE_CODE (type
) == ARRAY_TYPE
)
8451 tree decl2
= DECL_VALUE_EXPR (new_var
);
8452 gcc_assert (TREE_CODE (decl2
) == MEM_REF
);
8453 decl2
= TREE_OPERAND (decl2
, 0);
8454 gcc_assert (DECL_P (decl2
));
8456 type
= TREE_TYPE (new_var
);
8458 x
= build_receiver_ref (OMP_CLAUSE_DECL (prev
), false, ctx
);
8459 x
= fold_convert_loc (clause_loc
, type
, x
);
8460 if (!integer_zerop (OMP_CLAUSE_SIZE (c
)))
8462 tree bias
= OMP_CLAUSE_SIZE (c
);
8464 bias
= lookup_decl (bias
, ctx
);
8465 bias
= fold_convert_loc (clause_loc
, sizetype
, bias
);
8466 bias
= fold_build1_loc (clause_loc
, NEGATE_EXPR
, sizetype
,
8468 x
= fold_build2_loc (clause_loc
, POINTER_PLUS_EXPR
,
8469 TREE_TYPE (x
), x
, bias
);
8472 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
8473 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8474 if (is_ref
&& !ref_to_array
)
8476 tree t
= create_tmp_var_raw (type
, get_name (var
));
8477 gimple_add_tmp_var (t
);
8478 TREE_ADDRESSABLE (t
) = 1;
8479 gimple_seq_add_stmt (&new_body
,
8480 gimple_build_assign (t
, x
));
8481 x
= build_fold_addr_expr_loc (clause_loc
, t
);
8483 gimple_seq_add_stmt (&new_body
,
8484 gimple_build_assign (new_var
, x
));
8487 else if (OMP_CLAUSE_CHAIN (c
)
8488 && OMP_CLAUSE_CODE (OMP_CLAUSE_CHAIN (c
))
8490 && (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c
))
8491 == GOMP_MAP_FIRSTPRIVATE_POINTER
8492 || (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c
))
8493 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
)))
8496 case OMP_CLAUSE_PRIVATE
:
8497 var
= OMP_CLAUSE_DECL (c
);
8498 if (is_variable_sized (var
))
8500 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
8501 tree new_var
= lookup_decl (var
, ctx
);
8502 tree pvar
= DECL_VALUE_EXPR (var
);
8503 gcc_assert (TREE_CODE (pvar
) == INDIRECT_REF
);
8504 pvar
= TREE_OPERAND (pvar
, 0);
8505 gcc_assert (DECL_P (pvar
));
8506 tree new_pvar
= lookup_decl (pvar
, ctx
);
8507 tree atmp
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
8508 tree al
= size_int (DECL_ALIGN (var
));
8509 tree x
= TYPE_SIZE_UNIT (TREE_TYPE (new_var
));
8510 x
= build_call_expr_loc (clause_loc
, atmp
, 2, x
, al
);
8511 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_pvar
), x
);
8512 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8513 gimple_seq_add_stmt (&new_body
,
8514 gimple_build_assign (new_pvar
, x
));
8516 else if (omp_is_reference (var
) && !is_gimple_omp_oacc (ctx
->stmt
))
8518 location_t clause_loc
= OMP_CLAUSE_LOCATION (c
);
8519 tree new_var
= lookup_decl (var
, ctx
);
8520 tree x
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_var
)));
8521 if (TREE_CONSTANT (x
))
8526 = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
8527 tree rtype
= TREE_TYPE (TREE_TYPE (new_var
));
8528 tree al
= size_int (TYPE_ALIGN (rtype
));
8529 x
= build_call_expr_loc (clause_loc
, atmp
, 2, x
, al
);
8532 x
= fold_convert_loc (clause_loc
, TREE_TYPE (new_var
), x
);
8533 gimplify_expr (&x
, &new_body
, NULL
, is_gimple_val
, fb_rvalue
);
8534 gimple_seq_add_stmt (&new_body
,
8535 gimple_build_assign (new_var
, x
));
8540 gimple_seq fork_seq
= NULL
;
8541 gimple_seq join_seq
= NULL
;
8543 if (is_oacc_parallel (ctx
))
8545 /* If there are reductions on the offloaded region itself, treat
8546 them as a dummy GANG loop. */
8547 tree level
= build_int_cst (integer_type_node
, GOMP_DIM_GANG
);
8549 lower_oacc_reductions (gimple_location (ctx
->stmt
), clauses
, level
,
8550 false, NULL
, NULL
, &fork_seq
, &join_seq
, ctx
);
8553 gimple_seq_add_seq (&new_body
, fork_seq
);
8554 gimple_seq_add_seq (&new_body
, tgt_body
);
8555 gimple_seq_add_seq (&new_body
, join_seq
);
8558 new_body
= maybe_catch_exception (new_body
);
8560 gimple_seq_add_stmt (&new_body
, gimple_build_omp_return (false));
8561 gimple_omp_set_body (stmt
, new_body
);
8564 bind
= gimple_build_bind (NULL
, NULL
,
8565 tgt_bind
? gimple_bind_block (tgt_bind
)
8567 gsi_replace (gsi_p
, dep_bind
? dep_bind
: bind
, true);
8568 gimple_bind_add_seq (bind
, ilist
);
8569 gimple_bind_add_stmt (bind
, stmt
);
8570 gimple_bind_add_seq (bind
, olist
);
8572 pop_gimplify_context (NULL
);
8576 gimple_bind_add_seq (dep_bind
, dep_ilist
);
8577 gimple_bind_add_stmt (dep_bind
, bind
);
8578 gimple_bind_add_seq (dep_bind
, dep_olist
);
8579 pop_gimplify_context (dep_bind
);
8583 /* Expand code for an OpenMP teams directive. */
8586 lower_omp_teams (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
8588 gomp_teams
*teams_stmt
= as_a
<gomp_teams
*> (gsi_stmt (*gsi_p
));
8589 push_gimplify_context ();
8591 tree block
= make_node (BLOCK
);
8592 gbind
*bind
= gimple_build_bind (NULL
, NULL
, block
);
8593 gsi_replace (gsi_p
, bind
, true);
8594 gimple_seq bind_body
= NULL
;
8595 gimple_seq dlist
= NULL
;
8596 gimple_seq olist
= NULL
;
8598 tree num_teams
= omp_find_clause (gimple_omp_teams_clauses (teams_stmt
),
8599 OMP_CLAUSE_NUM_TEAMS
);
8600 if (num_teams
== NULL_TREE
)
8601 num_teams
= build_int_cst (unsigned_type_node
, 0);
8604 num_teams
= OMP_CLAUSE_NUM_TEAMS_EXPR (num_teams
);
8605 num_teams
= fold_convert (unsigned_type_node
, num_teams
);
8606 gimplify_expr (&num_teams
, &bind_body
, NULL
, is_gimple_val
, fb_rvalue
);
8608 tree thread_limit
= omp_find_clause (gimple_omp_teams_clauses (teams_stmt
),
8609 OMP_CLAUSE_THREAD_LIMIT
);
8610 if (thread_limit
== NULL_TREE
)
8611 thread_limit
= build_int_cst (unsigned_type_node
, 0);
8614 thread_limit
= OMP_CLAUSE_THREAD_LIMIT_EXPR (thread_limit
);
8615 thread_limit
= fold_convert (unsigned_type_node
, thread_limit
);
8616 gimplify_expr (&thread_limit
, &bind_body
, NULL
, is_gimple_val
,
8620 lower_rec_input_clauses (gimple_omp_teams_clauses (teams_stmt
),
8621 &bind_body
, &dlist
, ctx
, NULL
);
8622 lower_omp (gimple_omp_body_ptr (teams_stmt
), ctx
);
8623 lower_reduction_clauses (gimple_omp_teams_clauses (teams_stmt
), &olist
, ctx
);
8624 if (!gimple_omp_teams_grid_phony (teams_stmt
))
8626 gimple_seq_add_stmt (&bind_body
, teams_stmt
);
8627 location_t loc
= gimple_location (teams_stmt
);
8628 tree decl
= builtin_decl_explicit (BUILT_IN_GOMP_TEAMS
);
8629 gimple
*call
= gimple_build_call (decl
, 2, num_teams
, thread_limit
);
8630 gimple_set_location (call
, loc
);
8631 gimple_seq_add_stmt (&bind_body
, call
);
8634 gimple_seq_add_seq (&bind_body
, gimple_omp_body (teams_stmt
));
8635 gimple_omp_set_body (teams_stmt
, NULL
);
8636 gimple_seq_add_seq (&bind_body
, olist
);
8637 gimple_seq_add_seq (&bind_body
, dlist
);
8638 if (!gimple_omp_teams_grid_phony (teams_stmt
))
8639 gimple_seq_add_stmt (&bind_body
, gimple_build_omp_return (true));
8640 gimple_bind_set_body (bind
, bind_body
);
8642 pop_gimplify_context (bind
);
8644 gimple_bind_append_vars (bind
, ctx
->block_vars
);
8645 BLOCK_VARS (block
) = ctx
->block_vars
;
8646 if (BLOCK_VARS (block
))
8647 TREE_USED (block
) = 1;
8650 /* Expand code within an artificial GIMPLE_OMP_GRID_BODY OMP construct. */
8653 lower_omp_grid_body (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
8655 gimple
*stmt
= gsi_stmt (*gsi_p
);
8656 lower_omp (gimple_omp_body_ptr (stmt
), ctx
);
8657 gimple_seq_add_stmt (gimple_omp_body_ptr (stmt
),
8658 gimple_build_omp_return (false));
8662 /* Callback for lower_omp_1. Return non-NULL if *tp needs to be
8663 regimplified. If DATA is non-NULL, lower_omp_1 is outside
8664 of OMP context, but with task_shared_vars set. */
8667 lower_omp_regimplify_p (tree
*tp
, int *walk_subtrees
,
8672 /* Any variable with DECL_VALUE_EXPR needs to be regimplified. */
8673 if (VAR_P (t
) && data
== NULL
&& DECL_HAS_VALUE_EXPR_P (t
))
8676 if (task_shared_vars
8678 && bitmap_bit_p (task_shared_vars
, DECL_UID (t
)))
8681 /* If a global variable has been privatized, TREE_CONSTANT on
8682 ADDR_EXPR might be wrong. */
8683 if (data
== NULL
&& TREE_CODE (t
) == ADDR_EXPR
)
8684 recompute_tree_invariant_for_addr_expr (t
);
8686 *walk_subtrees
= !IS_TYPE_OR_DECL_P (t
);
8690 /* Data to be communicated between lower_omp_regimplify_operands and
8691 lower_omp_regimplify_operands_p. */
8693 struct lower_omp_regimplify_operands_data
8699 /* Helper function for lower_omp_regimplify_operands. Find
8700 omp_member_access_dummy_var vars and adjust temporarily their
8701 DECL_VALUE_EXPRs if needed. */
8704 lower_omp_regimplify_operands_p (tree
*tp
, int *walk_subtrees
,
8707 tree t
= omp_member_access_dummy_var (*tp
);
8710 struct walk_stmt_info
*wi
= (struct walk_stmt_info
*) data
;
8711 lower_omp_regimplify_operands_data
*ldata
8712 = (lower_omp_regimplify_operands_data
*) wi
->info
;
8713 tree o
= maybe_lookup_decl (t
, ldata
->ctx
);
8716 ldata
->decls
->safe_push (DECL_VALUE_EXPR (*tp
));
8717 ldata
->decls
->safe_push (*tp
);
8718 tree v
= unshare_and_remap (DECL_VALUE_EXPR (*tp
), t
, o
);
8719 SET_DECL_VALUE_EXPR (*tp
, v
);
8722 *walk_subtrees
= !IS_TYPE_OR_DECL_P (*tp
);
8726 /* Wrapper around gimple_regimplify_operands that adjusts DECL_VALUE_EXPRs
8727 of omp_member_access_dummy_var vars during regimplification. */
8730 lower_omp_regimplify_operands (omp_context
*ctx
, gimple
*stmt
,
8731 gimple_stmt_iterator
*gsi_p
)
8733 auto_vec
<tree
, 10> decls
;
8736 struct walk_stmt_info wi
;
8737 memset (&wi
, '\0', sizeof (wi
));
8738 struct lower_omp_regimplify_operands_data data
;
8740 data
.decls
= &decls
;
8742 walk_gimple_op (stmt
, lower_omp_regimplify_operands_p
, &wi
);
8744 gimple_regimplify_operands (stmt
, gsi_p
);
8745 while (!decls
.is_empty ())
8747 tree t
= decls
.pop ();
8748 tree v
= decls
.pop ();
8749 SET_DECL_VALUE_EXPR (t
, v
);
8754 lower_omp_1 (gimple_stmt_iterator
*gsi_p
, omp_context
*ctx
)
8756 gimple
*stmt
= gsi_stmt (*gsi_p
);
8757 struct walk_stmt_info wi
;
8760 if (gimple_has_location (stmt
))
8761 input_location
= gimple_location (stmt
);
8763 if (task_shared_vars
)
8764 memset (&wi
, '\0', sizeof (wi
));
8766 /* If we have issued syntax errors, avoid doing any heavy lifting.
8767 Just replace the OMP directives with a NOP to avoid
8768 confusing RTL expansion. */
8769 if (seen_error () && is_gimple_omp (stmt
))
8771 gsi_replace (gsi_p
, gimple_build_nop (), true);
8775 switch (gimple_code (stmt
))
8779 gcond
*cond_stmt
= as_a
<gcond
*> (stmt
);
8780 if ((ctx
|| task_shared_vars
)
8781 && (walk_tree (gimple_cond_lhs_ptr (cond_stmt
),
8782 lower_omp_regimplify_p
,
8783 ctx
? NULL
: &wi
, NULL
)
8784 || walk_tree (gimple_cond_rhs_ptr (cond_stmt
),
8785 lower_omp_regimplify_p
,
8786 ctx
? NULL
: &wi
, NULL
)))
8787 lower_omp_regimplify_operands (ctx
, cond_stmt
, gsi_p
);
8791 lower_omp (gimple_catch_handler_ptr (as_a
<gcatch
*> (stmt
)), ctx
);
8793 case GIMPLE_EH_FILTER
:
8794 lower_omp (gimple_eh_filter_failure_ptr (stmt
), ctx
);
8797 lower_omp (gimple_try_eval_ptr (stmt
), ctx
);
8798 lower_omp (gimple_try_cleanup_ptr (stmt
), ctx
);
8800 case GIMPLE_TRANSACTION
:
8801 lower_omp (gimple_transaction_body_ptr (as_a
<gtransaction
*> (stmt
)),
8805 lower_omp (gimple_bind_body_ptr (as_a
<gbind
*> (stmt
)), ctx
);
8807 case GIMPLE_OMP_PARALLEL
:
8808 case GIMPLE_OMP_TASK
:
8809 ctx
= maybe_lookup_ctx (stmt
);
8811 if (ctx
->cancellable
)
8812 ctx
->cancel_label
= create_artificial_label (UNKNOWN_LOCATION
);
8813 lower_omp_taskreg (gsi_p
, ctx
);
8815 case GIMPLE_OMP_FOR
:
8816 ctx
= maybe_lookup_ctx (stmt
);
8818 if (ctx
->cancellable
)
8819 ctx
->cancel_label
= create_artificial_label (UNKNOWN_LOCATION
);
8820 lower_omp_for (gsi_p
, ctx
);
8822 case GIMPLE_OMP_SECTIONS
:
8823 ctx
= maybe_lookup_ctx (stmt
);
8825 if (ctx
->cancellable
)
8826 ctx
->cancel_label
= create_artificial_label (UNKNOWN_LOCATION
);
8827 lower_omp_sections (gsi_p
, ctx
);
8829 case GIMPLE_OMP_SINGLE
:
8830 ctx
= maybe_lookup_ctx (stmt
);
8832 lower_omp_single (gsi_p
, ctx
);
8834 case GIMPLE_OMP_MASTER
:
8835 ctx
= maybe_lookup_ctx (stmt
);
8837 lower_omp_master (gsi_p
, ctx
);
8839 case GIMPLE_OMP_TASKGROUP
:
8840 ctx
= maybe_lookup_ctx (stmt
);
8842 lower_omp_taskgroup (gsi_p
, ctx
);
8844 case GIMPLE_OMP_ORDERED
:
8845 ctx
= maybe_lookup_ctx (stmt
);
8847 lower_omp_ordered (gsi_p
, ctx
);
8849 case GIMPLE_OMP_CRITICAL
:
8850 ctx
= maybe_lookup_ctx (stmt
);
8852 lower_omp_critical (gsi_p
, ctx
);
8854 case GIMPLE_OMP_ATOMIC_LOAD
:
8855 if ((ctx
|| task_shared_vars
)
8856 && walk_tree (gimple_omp_atomic_load_rhs_ptr (
8857 as_a
<gomp_atomic_load
*> (stmt
)),
8858 lower_omp_regimplify_p
, ctx
? NULL
: &wi
, NULL
))
8859 lower_omp_regimplify_operands (ctx
, stmt
, gsi_p
);
8861 case GIMPLE_OMP_TARGET
:
8862 ctx
= maybe_lookup_ctx (stmt
);
8864 lower_omp_target (gsi_p
, ctx
);
8866 case GIMPLE_OMP_TEAMS
:
8867 ctx
= maybe_lookup_ctx (stmt
);
8869 lower_omp_teams (gsi_p
, ctx
);
8871 case GIMPLE_OMP_GRID_BODY
:
8872 ctx
= maybe_lookup_ctx (stmt
);
8874 lower_omp_grid_body (gsi_p
, ctx
);
8878 call_stmt
= as_a
<gcall
*> (stmt
);
8879 fndecl
= gimple_call_fndecl (call_stmt
);
8881 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
8882 switch (DECL_FUNCTION_CODE (fndecl
))
8884 case BUILT_IN_GOMP_BARRIER
:
8888 case BUILT_IN_GOMP_CANCEL
:
8889 case BUILT_IN_GOMP_CANCELLATION_POINT
:
8892 if (gimple_code (cctx
->stmt
) == GIMPLE_OMP_SECTION
)
8894 gcc_assert (gimple_call_lhs (call_stmt
) == NULL_TREE
);
8895 if (!cctx
->cancellable
)
8897 if (DECL_FUNCTION_CODE (fndecl
)
8898 == BUILT_IN_GOMP_CANCELLATION_POINT
)
8900 stmt
= gimple_build_nop ();
8901 gsi_replace (gsi_p
, stmt
, false);
8905 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_GOMP_BARRIER
)
8907 fndecl
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER_CANCEL
);
8908 gimple_call_set_fndecl (call_stmt
, fndecl
);
8909 gimple_call_set_fntype (call_stmt
, TREE_TYPE (fndecl
));
8912 lhs
= create_tmp_var (TREE_TYPE (TREE_TYPE (fndecl
)));
8913 gimple_call_set_lhs (call_stmt
, lhs
);
8914 tree fallthru_label
;
8915 fallthru_label
= create_artificial_label (UNKNOWN_LOCATION
);
8917 g
= gimple_build_label (fallthru_label
);
8918 gsi_insert_after (gsi_p
, g
, GSI_SAME_STMT
);
8919 g
= gimple_build_cond (NE_EXPR
, lhs
,
8920 fold_convert (TREE_TYPE (lhs
),
8921 boolean_false_node
),
8922 cctx
->cancel_label
, fallthru_label
);
8923 gsi_insert_after (gsi_p
, g
, GSI_SAME_STMT
);
8930 if ((ctx
|| task_shared_vars
)
8931 && walk_gimple_op (stmt
, lower_omp_regimplify_p
,
8934 /* Just remove clobbers, this should happen only if we have
8935 "privatized" local addressable variables in SIMD regions,
8936 the clobber isn't needed in that case and gimplifying address
8937 of the ARRAY_REF into a pointer and creating MEM_REF based
8938 clobber would create worse code than we get with the clobber
8940 if (gimple_clobber_p (stmt
))
8942 gsi_replace (gsi_p
, gimple_build_nop (), true);
8945 lower_omp_regimplify_operands (ctx
, stmt
, gsi_p
);
8952 lower_omp (gimple_seq
*body
, omp_context
*ctx
)
8954 location_t saved_location
= input_location
;
8955 gimple_stmt_iterator gsi
;
8956 for (gsi
= gsi_start (*body
); !gsi_end_p (gsi
); gsi_next (&gsi
))
8957 lower_omp_1 (&gsi
, ctx
);
8958 /* During gimplification, we haven't folded statments inside offloading
8959 or taskreg regions (gimplify.c:maybe_fold_stmt); do that now. */
8960 if (target_nesting_level
|| taskreg_nesting_level
)
8961 for (gsi
= gsi_start (*body
); !gsi_end_p (gsi
); gsi_next (&gsi
))
8963 input_location
= saved_location
;
8966 /* Main entry point. */
8969 execute_lower_omp (void)
8975 /* This pass always runs, to provide PROP_gimple_lomp.
8976 But often, there is nothing to do. */
8977 if (flag_cilkplus
== 0 && flag_openacc
== 0 && flag_openmp
== 0
8978 && flag_openmp_simd
== 0)
8981 all_contexts
= splay_tree_new (splay_tree_compare_pointers
, 0,
8982 delete_omp_context
);
8984 body
= gimple_body (current_function_decl
);
8986 if (hsa_gen_requested_p ())
8987 omp_grid_gridify_all_targets (&body
);
8989 scan_omp (&body
, NULL
);
8990 gcc_assert (taskreg_nesting_level
== 0);
8991 FOR_EACH_VEC_ELT (taskreg_contexts
, i
, ctx
)
8992 finish_taskreg_scan (ctx
);
8993 taskreg_contexts
.release ();
8995 if (all_contexts
->root
)
8997 if (task_shared_vars
)
8998 push_gimplify_context ();
8999 lower_omp (&body
, NULL
);
9000 if (task_shared_vars
)
9001 pop_gimplify_context (NULL
);
9006 splay_tree_delete (all_contexts
);
9007 all_contexts
= NULL
;
9009 BITMAP_FREE (task_shared_vars
);
9015 const pass_data pass_data_lower_omp
=
9017 GIMPLE_PASS
, /* type */
9018 "omplower", /* name */
9019 OPTGROUP_OMP
, /* optinfo_flags */
9020 TV_NONE
, /* tv_id */
9021 PROP_gimple_any
, /* properties_required */
9022 PROP_gimple_lomp
| PROP_gimple_lomp_dev
, /* properties_provided */
9023 0, /* properties_destroyed */
9024 0, /* todo_flags_start */
9025 0, /* todo_flags_finish */
9028 class pass_lower_omp
: public gimple_opt_pass
9031 pass_lower_omp (gcc::context
*ctxt
)
9032 : gimple_opt_pass (pass_data_lower_omp
, ctxt
)
9035 /* opt_pass methods: */
9036 virtual unsigned int execute (function
*) { return execute_lower_omp (); }
9038 }; // class pass_lower_omp
9043 make_pass_lower_omp (gcc::context
*ctxt
)
9045 return new pass_lower_omp (ctxt
);
9048 /* The following is a utility to diagnose structured block violations.
9049 It is not part of the "omplower" pass, as that's invoked too late. It
9050 should be invoked by the respective front ends after gimplification. */
9052 static splay_tree all_labels
;
9054 /* Check for mismatched contexts and generate an error if needed. Return
9055 true if an error is detected. */
9058 diagnose_sb_0 (gimple_stmt_iterator
*gsi_p
,
9059 gimple
*branch_ctx
, gimple
*label_ctx
)
9061 gcc_checking_assert (!branch_ctx
|| is_gimple_omp (branch_ctx
));
9062 gcc_checking_assert (!label_ctx
|| is_gimple_omp (label_ctx
));
9064 if (label_ctx
== branch_ctx
)
9067 const char* kind
= NULL
;
9072 && gimple_code (branch_ctx
) == GIMPLE_OMP_FOR
9073 && gimple_omp_for_kind (branch_ctx
) == GF_OMP_FOR_KIND_CILKSIMD
)
9075 && gimple_code (label_ctx
) == GIMPLE_OMP_FOR
9076 && gimple_omp_for_kind (label_ctx
) == GF_OMP_FOR_KIND_CILKSIMD
))
9081 if ((branch_ctx
&& is_gimple_omp_oacc (branch_ctx
))
9082 || (label_ctx
&& is_gimple_omp_oacc (label_ctx
)))
9084 gcc_checking_assert (kind
== NULL
);
9090 gcc_checking_assert (flag_openmp
|| flag_openmp_simd
);
9094 /* Previously we kept track of the label's entire context in diagnose_sb_[12]
9095 so we could traverse it and issue a correct "exit" or "enter" error
9096 message upon a structured block violation.
9098 We built the context by building a list with tree_cons'ing, but there is
9099 no easy counterpart in gimple tuples. It seems like far too much work
9100 for issuing exit/enter error messages. If someone really misses the
9101 distinct error message... patches welcome. */
9104 /* Try to avoid confusing the user by producing and error message
9105 with correct "exit" or "enter" verbiage. We prefer "exit"
9106 unless we can show that LABEL_CTX is nested within BRANCH_CTX. */
9107 if (branch_ctx
== NULL
)
9113 if (TREE_VALUE (label_ctx
) == branch_ctx
)
9118 label_ctx
= TREE_CHAIN (label_ctx
);
9123 error ("invalid exit from %s structured block", kind
);
9125 error ("invalid entry to %s structured block", kind
);
9128 /* If it's obvious we have an invalid entry, be specific about the error. */
9129 if (branch_ctx
== NULL
)
9130 error ("invalid entry to %s structured block", kind
);
9133 /* Otherwise, be vague and lazy, but efficient. */
9134 error ("invalid branch to/from %s structured block", kind
);
9137 gsi_replace (gsi_p
, gimple_build_nop (), false);
9141 /* Pass 1: Create a minimal tree of structured blocks, and record
9142 where each label is found. */
9145 diagnose_sb_1 (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
9146 struct walk_stmt_info
*wi
)
9148 gimple
*context
= (gimple
*) wi
->info
;
9149 gimple
*inner_context
;
9150 gimple
*stmt
= gsi_stmt (*gsi_p
);
9152 *handled_ops_p
= true;
9154 switch (gimple_code (stmt
))
9158 case GIMPLE_OMP_PARALLEL
:
9159 case GIMPLE_OMP_TASK
:
9160 case GIMPLE_OMP_SECTIONS
:
9161 case GIMPLE_OMP_SINGLE
:
9162 case GIMPLE_OMP_SECTION
:
9163 case GIMPLE_OMP_MASTER
:
9164 case GIMPLE_OMP_ORDERED
:
9165 case GIMPLE_OMP_CRITICAL
:
9166 case GIMPLE_OMP_TARGET
:
9167 case GIMPLE_OMP_TEAMS
:
9168 case GIMPLE_OMP_TASKGROUP
:
9169 /* The minimal context here is just the current OMP construct. */
9170 inner_context
= stmt
;
9171 wi
->info
= inner_context
;
9172 walk_gimple_seq (gimple_omp_body (stmt
), diagnose_sb_1
, NULL
, wi
);
9176 case GIMPLE_OMP_FOR
:
9177 inner_context
= stmt
;
9178 wi
->info
= inner_context
;
9179 /* gimple_omp_for_{index,initial,final} are all DECLs; no need to
9181 walk_gimple_seq (gimple_omp_for_pre_body (stmt
),
9182 diagnose_sb_1
, NULL
, wi
);
9183 walk_gimple_seq (gimple_omp_body (stmt
), diagnose_sb_1
, NULL
, wi
);
9188 splay_tree_insert (all_labels
,
9189 (splay_tree_key
) gimple_label_label (
9190 as_a
<glabel
*> (stmt
)),
9191 (splay_tree_value
) context
);
9201 /* Pass 2: Check each branch and see if its context differs from that of
9202 the destination label's context. */
9205 diagnose_sb_2 (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
9206 struct walk_stmt_info
*wi
)
9208 gimple
*context
= (gimple
*) wi
->info
;
9210 gimple
*stmt
= gsi_stmt (*gsi_p
);
9212 *handled_ops_p
= true;
9214 switch (gimple_code (stmt
))
9218 case GIMPLE_OMP_PARALLEL
:
9219 case GIMPLE_OMP_TASK
:
9220 case GIMPLE_OMP_SECTIONS
:
9221 case GIMPLE_OMP_SINGLE
:
9222 case GIMPLE_OMP_SECTION
:
9223 case GIMPLE_OMP_MASTER
:
9224 case GIMPLE_OMP_ORDERED
:
9225 case GIMPLE_OMP_CRITICAL
:
9226 case GIMPLE_OMP_TARGET
:
9227 case GIMPLE_OMP_TEAMS
:
9228 case GIMPLE_OMP_TASKGROUP
:
9230 walk_gimple_seq_mod (gimple_omp_body_ptr (stmt
), diagnose_sb_2
, NULL
, wi
);
9234 case GIMPLE_OMP_FOR
:
9236 /* gimple_omp_for_{index,initial,final} are all DECLs; no need to
9238 walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt
),
9239 diagnose_sb_2
, NULL
, wi
);
9240 walk_gimple_seq_mod (gimple_omp_body_ptr (stmt
), diagnose_sb_2
, NULL
, wi
);
9246 gcond
*cond_stmt
= as_a
<gcond
*> (stmt
);
9247 tree lab
= gimple_cond_true_label (cond_stmt
);
9250 n
= splay_tree_lookup (all_labels
,
9251 (splay_tree_key
) lab
);
9252 diagnose_sb_0 (gsi_p
, context
,
9253 n
? (gimple
*) n
->value
: NULL
);
9255 lab
= gimple_cond_false_label (cond_stmt
);
9258 n
= splay_tree_lookup (all_labels
,
9259 (splay_tree_key
) lab
);
9260 diagnose_sb_0 (gsi_p
, context
,
9261 n
? (gimple
*) n
->value
: NULL
);
9268 tree lab
= gimple_goto_dest (stmt
);
9269 if (TREE_CODE (lab
) != LABEL_DECL
)
9272 n
= splay_tree_lookup (all_labels
, (splay_tree_key
) lab
);
9273 diagnose_sb_0 (gsi_p
, context
, n
? (gimple
*) n
->value
: NULL
);
9279 gswitch
*switch_stmt
= as_a
<gswitch
*> (stmt
);
9281 for (i
= 0; i
< gimple_switch_num_labels (switch_stmt
); ++i
)
9283 tree lab
= CASE_LABEL (gimple_switch_label (switch_stmt
, i
));
9284 n
= splay_tree_lookup (all_labels
, (splay_tree_key
) lab
);
9285 if (n
&& diagnose_sb_0 (gsi_p
, context
, (gimple
*) n
->value
))
9292 diagnose_sb_0 (gsi_p
, context
, NULL
);
9303 diagnose_omp_structured_block_errors (void)
9305 struct walk_stmt_info wi
;
9306 gimple_seq body
= gimple_body (current_function_decl
);
9308 all_labels
= splay_tree_new (splay_tree_compare_pointers
, 0, 0);
9310 memset (&wi
, 0, sizeof (wi
));
9311 walk_gimple_seq (body
, diagnose_sb_1
, NULL
, &wi
);
9313 memset (&wi
, 0, sizeof (wi
));
9314 wi
.want_locations
= true;
9315 walk_gimple_seq_mod (&body
, diagnose_sb_2
, NULL
, &wi
);
9317 gimple_set_body (current_function_decl
, body
);
9319 splay_tree_delete (all_labels
);
9327 const pass_data pass_data_diagnose_omp_blocks
=
9329 GIMPLE_PASS
, /* type */
9330 "*diagnose_omp_blocks", /* name */
9331 OPTGROUP_OMP
, /* optinfo_flags */
9332 TV_NONE
, /* tv_id */
9333 PROP_gimple_any
, /* properties_required */
9334 0, /* properties_provided */
9335 0, /* properties_destroyed */
9336 0, /* todo_flags_start */
9337 0, /* todo_flags_finish */
9340 class pass_diagnose_omp_blocks
: public gimple_opt_pass
9343 pass_diagnose_omp_blocks (gcc::context
*ctxt
)
9344 : gimple_opt_pass (pass_data_diagnose_omp_blocks
, ctxt
)
9347 /* opt_pass methods: */
9348 virtual bool gate (function
*)
9350 return flag_cilkplus
|| flag_openacc
|| flag_openmp
|| flag_openmp_simd
;
9352 virtual unsigned int execute (function
*)
9354 return diagnose_omp_structured_block_errors ();
9357 }; // class pass_diagnose_omp_blocks
9362 make_pass_diagnose_omp_blocks (gcc::context
*ctxt
)
9364 return new pass_diagnose_omp_blocks (ctxt
);
9368 #include "gt-omp-low.h"