1 /* Tree lowering pass. This pass converts the GENERIC functions-as-trees
2 tree representation into the GIMPLE form.
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4 Major work done by Sebastian Pop <s.pop@laposte.net>,
5 Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
33 #include "gimple-predict.h"
34 #include "tree-pass.h" /* FIXME: only for PROP_gimple_any */
37 #include "tree-pretty-print.h"
38 #include "diagnostic-core.h"
40 #include "fold-const.h"
45 #include "gimple-fold.h"
48 #include "gimple-iterator.h"
49 #include "stor-layout.h"
50 #include "print-tree.h"
51 #include "tree-iterator.h"
52 #include "tree-inline.h"
53 #include "langhooks.h"
56 #include "omp-general.h"
58 #include "gimple-low.h"
59 #include "gomp-constants.h"
60 #include "splay-tree.h"
61 #include "gimple-walk.h"
62 #include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name */
64 #include "stringpool.h"
69 /* Hash set of poisoned variables in a bind expr. */
70 static hash_set
<tree
> *asan_poisoned_variables
= NULL
;
72 enum gimplify_omp_var_data
78 GOVD_FIRSTPRIVATE
= 16,
79 GOVD_LASTPRIVATE
= 32,
83 GOVD_DEBUG_PRIVATE
= 512,
84 GOVD_PRIVATE_OUTER_REF
= 1024,
88 /* Flag for GOVD_MAP: don't copy back. */
89 GOVD_MAP_TO_ONLY
= 8192,
91 /* Flag for GOVD_LINEAR or GOVD_LASTPRIVATE: no outer reference. */
92 GOVD_LINEAR_LASTPRIVATE_NO_OUTER
= 16384,
94 GOVD_MAP_0LEN_ARRAY
= 32768,
96 /* Flag for GOVD_MAP, if it is always, to or always, tofrom mapping. */
97 GOVD_MAP_ALWAYS_TO
= 65536,
99 /* Flag for shared vars that are or might be stored to in the region. */
100 GOVD_WRITTEN
= 131072,
102 /* Flag for GOVD_MAP, if it is a forced mapping. */
103 GOVD_MAP_FORCE
= 262144,
105 /* Flag for GOVD_MAP: must be present already. */
106 GOVD_MAP_FORCE_PRESENT
= 524288,
108 GOVD_DATA_SHARE_CLASS
= (GOVD_SHARED
| GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
109 | GOVD_LASTPRIVATE
| GOVD_REDUCTION
| GOVD_LINEAR
116 ORT_WORKSHARE
= 0x00,
120 ORT_COMBINED_PARALLEL
= 0x03,
123 ORT_UNTIED_TASK
= 0x05,
126 ORT_COMBINED_TEAMS
= 0x09,
129 ORT_TARGET_DATA
= 0x10,
131 /* Data region with offloading. */
133 ORT_COMBINED_TARGET
= 0x21,
135 /* OpenACC variants. */
136 ORT_ACC
= 0x40, /* A generic OpenACC region. */
137 ORT_ACC_DATA
= ORT_ACC
| ORT_TARGET_DATA
, /* Data construct. */
138 ORT_ACC_PARALLEL
= ORT_ACC
| ORT_TARGET
, /* Parallel construct */
139 ORT_ACC_KERNELS
= ORT_ACC
| ORT_TARGET
| 0x80, /* Kernels construct. */
140 ORT_ACC_HOST_DATA
= ORT_ACC
| ORT_TARGET_DATA
| 0x80, /* Host data. */
142 /* Dummy OpenMP region, used to disable expansion of
143 DECL_VALUE_EXPRs in taskloop pre body. */
147 /* Gimplify hashtable helper. */
149 struct gimplify_hasher
: free_ptr_hash
<elt_t
>
151 static inline hashval_t
hash (const elt_t
*);
152 static inline bool equal (const elt_t
*, const elt_t
*);
157 struct gimplify_ctx
*prev_context
;
159 vec
<gbind
*> bind_expr_stack
;
161 gimple_seq conditional_cleanups
;
165 vec
<tree
> case_labels
;
166 hash_set
<tree
> *live_switch_vars
;
167 /* The formal temporary table. Should this be persistent? */
168 hash_table
<gimplify_hasher
> *temp_htab
;
171 unsigned into_ssa
: 1;
172 unsigned allow_rhs_cond_expr
: 1;
173 unsigned in_cleanup_point_expr
: 1;
174 unsigned keep_stack
: 1;
175 unsigned save_stack
: 1;
176 unsigned in_switch_expr
: 1;
179 struct gimplify_omp_ctx
181 struct gimplify_omp_ctx
*outer_context
;
182 splay_tree variables
;
183 hash_set
<tree
> *privatized_types
;
184 /* Iteration variables in an OMP_FOR. */
185 vec
<tree
> loop_iter_var
;
187 enum omp_clause_default_kind default_kind
;
188 enum omp_region_type region_type
;
191 bool target_map_scalars_firstprivate
;
192 bool target_map_pointers_as_0len_arrays
;
193 bool target_firstprivatize_array_bases
;
196 static struct gimplify_ctx
*gimplify_ctxp
;
197 static struct gimplify_omp_ctx
*gimplify_omp_ctxp
;
199 /* Forward declaration. */
200 static enum gimplify_status
gimplify_compound_expr (tree
*, gimple_seq
*, bool);
201 static hash_map
<tree
, tree
> *oacc_declare_returns
;
202 static enum gimplify_status
gimplify_expr (tree
*, gimple_seq
*, gimple_seq
*,
203 bool (*) (tree
), fallback_t
, bool);
205 /* Shorter alias name for the above function for use in gimplify.c
209 gimplify_seq_add_stmt (gimple_seq
*seq_p
, gimple
*gs
)
211 gimple_seq_add_stmt_without_update (seq_p
, gs
);
214 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
215 NULL, a new sequence is allocated. This function is
216 similar to gimple_seq_add_seq, but does not scan the operands.
217 During gimplification, we need to manipulate statement sequences
218 before the def/use vectors have been constructed. */
221 gimplify_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
223 gimple_stmt_iterator si
;
228 si
= gsi_last (*dst_p
);
229 gsi_insert_seq_after_without_update (&si
, src
, GSI_NEW_STMT
);
233 /* Pointer to a list of allocated gimplify_ctx structs to be used for pushing
234 and popping gimplify contexts. */
236 static struct gimplify_ctx
*ctx_pool
= NULL
;
238 /* Return a gimplify context struct from the pool. */
240 static inline struct gimplify_ctx
*
243 struct gimplify_ctx
* c
= ctx_pool
;
246 ctx_pool
= c
->prev_context
;
248 c
= XNEW (struct gimplify_ctx
);
250 memset (c
, '\0', sizeof (*c
));
254 /* Put gimplify context C back into the pool. */
257 ctx_free (struct gimplify_ctx
*c
)
259 c
->prev_context
= ctx_pool
;
263 /* Free allocated ctx stack memory. */
266 free_gimplify_stack (void)
268 struct gimplify_ctx
*c
;
270 while ((c
= ctx_pool
))
272 ctx_pool
= c
->prev_context
;
278 /* Set up a context for the gimplifier. */
281 push_gimplify_context (bool in_ssa
, bool rhs_cond_ok
)
283 struct gimplify_ctx
*c
= ctx_alloc ();
285 c
->prev_context
= gimplify_ctxp
;
287 gimplify_ctxp
->into_ssa
= in_ssa
;
288 gimplify_ctxp
->allow_rhs_cond_expr
= rhs_cond_ok
;
291 /* Tear down a context for the gimplifier. If BODY is non-null, then
292 put the temporaries into the outer BIND_EXPR. Otherwise, put them
295 BODY is not a sequence, but the first tuple in a sequence. */
298 pop_gimplify_context (gimple
*body
)
300 struct gimplify_ctx
*c
= gimplify_ctxp
;
303 && (!c
->bind_expr_stack
.exists ()
304 || c
->bind_expr_stack
.is_empty ()));
305 c
->bind_expr_stack
.release ();
306 gimplify_ctxp
= c
->prev_context
;
309 declare_vars (c
->temps
, body
, false);
311 record_vars (c
->temps
);
318 /* Push a GIMPLE_BIND tuple onto the stack of bindings. */
321 gimple_push_bind_expr (gbind
*bind_stmt
)
323 gimplify_ctxp
->bind_expr_stack
.reserve (8);
324 gimplify_ctxp
->bind_expr_stack
.safe_push (bind_stmt
);
327 /* Pop the first element off the stack of bindings. */
330 gimple_pop_bind_expr (void)
332 gimplify_ctxp
->bind_expr_stack
.pop ();
335 /* Return the first element of the stack of bindings. */
338 gimple_current_bind_expr (void)
340 return gimplify_ctxp
->bind_expr_stack
.last ();
343 /* Return the stack of bindings created during gimplification. */
346 gimple_bind_expr_stack (void)
348 return gimplify_ctxp
->bind_expr_stack
;
351 /* Return true iff there is a COND_EXPR between us and the innermost
352 CLEANUP_POINT_EXPR. This info is used by gimple_push_cleanup. */
355 gimple_conditional_context (void)
357 return gimplify_ctxp
->conditions
> 0;
360 /* Note that we've entered a COND_EXPR. */
363 gimple_push_condition (void)
365 #ifdef ENABLE_GIMPLE_CHECKING
366 if (gimplify_ctxp
->conditions
== 0)
367 gcc_assert (gimple_seq_empty_p (gimplify_ctxp
->conditional_cleanups
));
369 ++(gimplify_ctxp
->conditions
);
372 /* Note that we've left a COND_EXPR. If we're back at unconditional scope
373 now, add any conditional cleanups we've seen to the prequeue. */
376 gimple_pop_condition (gimple_seq
*pre_p
)
378 int conds
= --(gimplify_ctxp
->conditions
);
380 gcc_assert (conds
>= 0);
383 gimplify_seq_add_seq (pre_p
, gimplify_ctxp
->conditional_cleanups
);
384 gimplify_ctxp
->conditional_cleanups
= NULL
;
388 /* A stable comparison routine for use with splay trees and DECLs. */
391 splay_tree_compare_decl_uid (splay_tree_key xa
, splay_tree_key xb
)
396 return DECL_UID (a
) - DECL_UID (b
);
399 /* Create a new omp construct that deals with variable remapping. */
401 static struct gimplify_omp_ctx
*
402 new_omp_context (enum omp_region_type region_type
)
404 struct gimplify_omp_ctx
*c
;
406 c
= XCNEW (struct gimplify_omp_ctx
);
407 c
->outer_context
= gimplify_omp_ctxp
;
408 c
->variables
= splay_tree_new (splay_tree_compare_decl_uid
, 0, 0);
409 c
->privatized_types
= new hash_set
<tree
>;
410 c
->location
= input_location
;
411 c
->region_type
= region_type
;
412 if ((region_type
& ORT_TASK
) == 0)
413 c
->default_kind
= OMP_CLAUSE_DEFAULT_SHARED
;
415 c
->default_kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
420 /* Destroy an omp construct that deals with variable remapping. */
423 delete_omp_context (struct gimplify_omp_ctx
*c
)
425 splay_tree_delete (c
->variables
);
426 delete c
->privatized_types
;
427 c
->loop_iter_var
.release ();
431 static void omp_add_variable (struct gimplify_omp_ctx
*, tree
, unsigned int);
432 static bool omp_notice_variable (struct gimplify_omp_ctx
*, tree
, bool);
434 /* Both gimplify the statement T and append it to *SEQ_P. This function
435 behaves exactly as gimplify_stmt, but you don't have to pass T as a
439 gimplify_and_add (tree t
, gimple_seq
*seq_p
)
441 gimplify_stmt (&t
, seq_p
);
444 /* Gimplify statement T into sequence *SEQ_P, and return the first
445 tuple in the sequence of generated tuples for this statement.
446 Return NULL if gimplifying T produced no tuples. */
449 gimplify_and_return_first (tree t
, gimple_seq
*seq_p
)
451 gimple_stmt_iterator last
= gsi_last (*seq_p
);
453 gimplify_and_add (t
, seq_p
);
455 if (!gsi_end_p (last
))
458 return gsi_stmt (last
);
461 return gimple_seq_first_stmt (*seq_p
);
464 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
465 LHS, or for a call argument. */
468 is_gimple_mem_rhs (tree t
)
470 /* If we're dealing with a renamable type, either source or dest must be
471 a renamed variable. */
472 if (is_gimple_reg_type (TREE_TYPE (t
)))
473 return is_gimple_val (t
);
475 return is_gimple_val (t
) || is_gimple_lvalue (t
);
478 /* Return true if T is a CALL_EXPR or an expression that can be
479 assigned to a temporary. Note that this predicate should only be
480 used during gimplification. See the rationale for this in
481 gimplify_modify_expr. */
484 is_gimple_reg_rhs_or_call (tree t
)
486 return (get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
487 || TREE_CODE (t
) == CALL_EXPR
);
490 /* Return true if T is a valid memory RHS or a CALL_EXPR. Note that
491 this predicate should only be used during gimplification. See the
492 rationale for this in gimplify_modify_expr. */
495 is_gimple_mem_rhs_or_call (tree t
)
497 /* If we're dealing with a renamable type, either source or dest must be
498 a renamed variable. */
499 if (is_gimple_reg_type (TREE_TYPE (t
)))
500 return is_gimple_val (t
);
502 return (is_gimple_val (t
)
503 || is_gimple_lvalue (t
)
504 || TREE_CLOBBER_P (t
)
505 || TREE_CODE (t
) == CALL_EXPR
);
508 /* Create a temporary with a name derived from VAL. Subroutine of
509 lookup_tmp_var; nobody else should call this function. */
512 create_tmp_from_val (tree val
)
514 /* Drop all qualifiers and address-space information from the value type. */
515 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (val
));
516 tree var
= create_tmp_var (type
, get_name (val
));
517 if (TREE_CODE (TREE_TYPE (var
)) == COMPLEX_TYPE
518 || TREE_CODE (TREE_TYPE (var
)) == VECTOR_TYPE
)
519 DECL_GIMPLE_REG_P (var
) = 1;
523 /* Create a temporary to hold the value of VAL. If IS_FORMAL, try to reuse
524 an existing expression temporary. */
527 lookup_tmp_var (tree val
, bool is_formal
)
531 /* If not optimizing, never really reuse a temporary. local-alloc
532 won't allocate any variable that is used in more than one basic
533 block, which means it will go into memory, causing much extra
534 work in reload and final and poorer code generation, outweighing
535 the extra memory allocation here. */
536 if (!optimize
|| !is_formal
|| TREE_SIDE_EFFECTS (val
))
537 ret
= create_tmp_from_val (val
);
544 if (!gimplify_ctxp
->temp_htab
)
545 gimplify_ctxp
->temp_htab
= new hash_table
<gimplify_hasher
> (1000);
546 slot
= gimplify_ctxp
->temp_htab
->find_slot (&elt
, INSERT
);
549 elt_p
= XNEW (elt_t
);
551 elt_p
->temp
= ret
= create_tmp_from_val (val
);
564 /* Helper for get_formal_tmp_var and get_initialized_tmp_var. */
567 internal_get_tmp_var (tree val
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
568 bool is_formal
, bool allow_ssa
)
572 /* Notice that we explicitly allow VAL to be a CALL_EXPR so that we
573 can create an INIT_EXPR and convert it into a GIMPLE_CALL below. */
574 gimplify_expr (&val
, pre_p
, post_p
, is_gimple_reg_rhs_or_call
,
578 && gimplify_ctxp
->into_ssa
579 && is_gimple_reg_type (TREE_TYPE (val
)))
581 t
= make_ssa_name (TYPE_MAIN_VARIANT (TREE_TYPE (val
)));
582 if (! gimple_in_ssa_p (cfun
))
584 const char *name
= get_name (val
);
586 SET_SSA_NAME_VAR_OR_IDENTIFIER (t
, create_tmp_var_name (name
));
590 t
= lookup_tmp_var (val
, is_formal
);
592 mod
= build2 (INIT_EXPR
, TREE_TYPE (t
), t
, unshare_expr (val
));
594 SET_EXPR_LOCATION (mod
, EXPR_LOC_OR_LOC (val
, input_location
));
596 /* gimplify_modify_expr might want to reduce this further. */
597 gimplify_and_add (mod
, pre_p
);
603 /* Return a formal temporary variable initialized with VAL. PRE_P is as
604 in gimplify_expr. Only use this function if:
606 1) The value of the unfactored expression represented by VAL will not
607 change between the initialization and use of the temporary, and
608 2) The temporary will not be otherwise modified.
610 For instance, #1 means that this is inappropriate for SAVE_EXPR temps,
611 and #2 means it is inappropriate for && temps.
613 For other cases, use get_initialized_tmp_var instead. */
616 get_formal_tmp_var (tree val
, gimple_seq
*pre_p
)
618 return internal_get_tmp_var (val
, pre_p
, NULL
, true, true);
621 /* Return a temporary variable initialized with VAL. PRE_P and POST_P
622 are as in gimplify_expr. */
625 get_initialized_tmp_var (tree val
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
628 return internal_get_tmp_var (val
, pre_p
, post_p
, false, allow_ssa
);
631 /* Declare all the variables in VARS in SCOPE. If DEBUG_INFO is true,
632 generate debug info for them; otherwise don't. */
635 declare_vars (tree vars
, gimple
*gs
, bool debug_info
)
642 gbind
*scope
= as_a
<gbind
*> (gs
);
644 temps
= nreverse (last
);
646 block
= gimple_bind_block (scope
);
647 gcc_assert (!block
|| TREE_CODE (block
) == BLOCK
);
648 if (!block
|| !debug_info
)
650 DECL_CHAIN (last
) = gimple_bind_vars (scope
);
651 gimple_bind_set_vars (scope
, temps
);
655 /* We need to attach the nodes both to the BIND_EXPR and to its
656 associated BLOCK for debugging purposes. The key point here
657 is that the BLOCK_VARS of the BIND_EXPR_BLOCK of a BIND_EXPR
658 is a subchain of the BIND_EXPR_VARS of the BIND_EXPR. */
659 if (BLOCK_VARS (block
))
660 BLOCK_VARS (block
) = chainon (BLOCK_VARS (block
), temps
);
663 gimple_bind_set_vars (scope
,
664 chainon (gimple_bind_vars (scope
), temps
));
665 BLOCK_VARS (block
) = temps
;
671 /* For VAR a VAR_DECL of variable size, try to find a constant upper bound
672 for the size and adjust DECL_SIZE/DECL_SIZE_UNIT accordingly. Abort if
673 no such upper bound can be obtained. */
676 force_constant_size (tree var
)
678 /* The only attempt we make is by querying the maximum size of objects
679 of the variable's type. */
681 HOST_WIDE_INT max_size
;
683 gcc_assert (VAR_P (var
));
685 max_size
= max_int_size_in_bytes (TREE_TYPE (var
));
687 gcc_assert (max_size
>= 0);
690 = build_int_cst (TREE_TYPE (DECL_SIZE_UNIT (var
)), max_size
);
692 = build_int_cst (TREE_TYPE (DECL_SIZE (var
)), max_size
* BITS_PER_UNIT
);
695 /* Push the temporary variable TMP into the current binding. */
698 gimple_add_tmp_var_fn (struct function
*fn
, tree tmp
)
700 gcc_assert (!DECL_CHAIN (tmp
) && !DECL_SEEN_IN_BIND_EXPR_P (tmp
));
702 /* Later processing assumes that the object size is constant, which might
703 not be true at this point. Force the use of a constant upper bound in
705 if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp
)))
706 force_constant_size (tmp
);
708 DECL_CONTEXT (tmp
) = fn
->decl
;
709 DECL_SEEN_IN_BIND_EXPR_P (tmp
) = 1;
711 record_vars_into (tmp
, fn
->decl
);
714 /* Push the temporary variable TMP into the current binding. */
717 gimple_add_tmp_var (tree tmp
)
719 gcc_assert (!DECL_CHAIN (tmp
) && !DECL_SEEN_IN_BIND_EXPR_P (tmp
));
721 /* Later processing assumes that the object size is constant, which might
722 not be true at this point. Force the use of a constant upper bound in
724 if (!tree_fits_poly_uint64_p (DECL_SIZE_UNIT (tmp
)))
725 force_constant_size (tmp
);
727 DECL_CONTEXT (tmp
) = current_function_decl
;
728 DECL_SEEN_IN_BIND_EXPR_P (tmp
) = 1;
732 DECL_CHAIN (tmp
) = gimplify_ctxp
->temps
;
733 gimplify_ctxp
->temps
= tmp
;
735 /* Mark temporaries local within the nearest enclosing parallel. */
736 if (gimplify_omp_ctxp
)
738 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
740 && (ctx
->region_type
== ORT_WORKSHARE
741 || ctx
->region_type
== ORT_SIMD
742 || ctx
->region_type
== ORT_ACC
))
743 ctx
= ctx
->outer_context
;
745 omp_add_variable (ctx
, tmp
, GOVD_LOCAL
| GOVD_SEEN
);
754 /* This case is for nested functions. We need to expose the locals
756 body_seq
= gimple_body (current_function_decl
);
757 declare_vars (tmp
, gimple_seq_first_stmt (body_seq
), false);
763 /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
764 nodes that are referenced more than once in GENERIC functions. This is
765 necessary because gimplification (translation into GIMPLE) is performed
766 by modifying tree nodes in-place, so gimplication of a shared node in a
767 first context could generate an invalid GIMPLE form in a second context.
769 This is achieved with a simple mark/copy/unmark algorithm that walks the
770 GENERIC representation top-down, marks nodes with TREE_VISITED the first
771 time it encounters them, duplicates them if they already have TREE_VISITED
772 set, and finally removes the TREE_VISITED marks it has set.
774 The algorithm works only at the function level, i.e. it generates a GENERIC
775 representation of a function with no nodes shared within the function when
776 passed a GENERIC function (except for nodes that are allowed to be shared).
778 At the global level, it is also necessary to unshare tree nodes that are
779 referenced in more than one function, for the same aforementioned reason.
780 This requires some cooperation from the front-end. There are 2 strategies:
782 1. Manual unsharing. The front-end needs to call unshare_expr on every
783 expression that might end up being shared across functions.
785 2. Deep unsharing. This is an extension of regular unsharing. Instead
786 of calling unshare_expr on expressions that might be shared across
787 functions, the front-end pre-marks them with TREE_VISITED. This will
788 ensure that they are unshared on the first reference within functions
789 when the regular unsharing algorithm runs. The counterpart is that
790 this algorithm must look deeper than for manual unsharing, which is
791 specified by LANG_HOOKS_DEEP_UNSHARING.
793 If there are only few specific cases of node sharing across functions, it is
794 probably easier for a front-end to unshare the expressions manually. On the
795 contrary, if the expressions generated at the global level are as widespread
796 as expressions generated within functions, deep unsharing is very likely the
799 /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
800 These nodes model computations that must be done once. If we were to
801 unshare something like SAVE_EXPR(i++), the gimplification process would
802 create wrong code. However, if DATA is non-null, it must hold a pointer
803 set that is used to unshare the subtrees of these nodes. */
806 mostly_copy_tree_r (tree
*tp
, int *walk_subtrees
, void *data
)
809 enum tree_code code
= TREE_CODE (t
);
811 /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
812 copy their subtrees if we can make sure to do it only once. */
813 if (code
== SAVE_EXPR
|| code
== TARGET_EXPR
|| code
== BIND_EXPR
)
815 if (data
&& !((hash_set
<tree
> *)data
)->add (t
))
821 /* Stop at types, decls, constants like copy_tree_r. */
822 else if (TREE_CODE_CLASS (code
) == tcc_type
823 || TREE_CODE_CLASS (code
) == tcc_declaration
824 || TREE_CODE_CLASS (code
) == tcc_constant
)
827 /* Cope with the statement expression extension. */
828 else if (code
== STATEMENT_LIST
)
831 /* Leave the bulk of the work to copy_tree_r itself. */
833 copy_tree_r (tp
, walk_subtrees
, NULL
);
838 /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
839 If *TP has been visited already, then *TP is deeply copied by calling
840 mostly_copy_tree_r. DATA is passed to mostly_copy_tree_r unmodified. */
843 copy_if_shared_r (tree
*tp
, int *walk_subtrees
, void *data
)
846 enum tree_code code
= TREE_CODE (t
);
848 /* Skip types, decls, and constants. But we do want to look at their
849 types and the bounds of types. Mark them as visited so we properly
850 unmark their subtrees on the unmark pass. If we've already seen them,
851 don't look down further. */
852 if (TREE_CODE_CLASS (code
) == tcc_type
853 || TREE_CODE_CLASS (code
) == tcc_declaration
854 || TREE_CODE_CLASS (code
) == tcc_constant
)
856 if (TREE_VISITED (t
))
859 TREE_VISITED (t
) = 1;
862 /* If this node has been visited already, unshare it and don't look
864 else if (TREE_VISITED (t
))
866 walk_tree (tp
, mostly_copy_tree_r
, data
, NULL
);
870 /* Otherwise, mark the node as visited and keep looking. */
872 TREE_VISITED (t
) = 1;
877 /* Unshare most of the shared trees rooted at *TP. DATA is passed to the
878 copy_if_shared_r callback unmodified. */
881 copy_if_shared (tree
*tp
, void *data
)
883 walk_tree (tp
, copy_if_shared_r
, data
, NULL
);
886 /* Unshare all the trees in the body of FNDECL, as well as in the bodies of
887 any nested functions. */
890 unshare_body (tree fndecl
)
892 struct cgraph_node
*cgn
= cgraph_node::get (fndecl
);
893 /* If the language requires deep unsharing, we need a pointer set to make
894 sure we don't repeatedly unshare subtrees of unshareable nodes. */
895 hash_set
<tree
> *visited
896 = lang_hooks
.deep_unsharing
? new hash_set
<tree
> : NULL
;
898 copy_if_shared (&DECL_SAVED_TREE (fndecl
), visited
);
899 copy_if_shared (&DECL_SIZE (DECL_RESULT (fndecl
)), visited
);
900 copy_if_shared (&DECL_SIZE_UNIT (DECL_RESULT (fndecl
)), visited
);
905 for (cgn
= cgn
->nested
; cgn
; cgn
= cgn
->next_nested
)
906 unshare_body (cgn
->decl
);
909 /* Callback for walk_tree to unmark the visited trees rooted at *TP.
910 Subtrees are walked until the first unvisited node is encountered. */
913 unmark_visited_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
917 /* If this node has been visited, unmark it and keep looking. */
918 if (TREE_VISITED (t
))
919 TREE_VISITED (t
) = 0;
921 /* Otherwise, don't look any deeper. */
928 /* Unmark the visited trees rooted at *TP. */
931 unmark_visited (tree
*tp
)
933 walk_tree (tp
, unmark_visited_r
, NULL
, NULL
);
936 /* Likewise, but mark all trees as not visited. */
939 unvisit_body (tree fndecl
)
941 struct cgraph_node
*cgn
= cgraph_node::get (fndecl
);
943 unmark_visited (&DECL_SAVED_TREE (fndecl
));
944 unmark_visited (&DECL_SIZE (DECL_RESULT (fndecl
)));
945 unmark_visited (&DECL_SIZE_UNIT (DECL_RESULT (fndecl
)));
948 for (cgn
= cgn
->nested
; cgn
; cgn
= cgn
->next_nested
)
949 unvisit_body (cgn
->decl
);
952 /* Unconditionally make an unshared copy of EXPR. This is used when using
953 stored expressions which span multiple functions, such as BINFO_VTABLE,
954 as the normal unsharing process can't tell that they're shared. */
957 unshare_expr (tree expr
)
959 walk_tree (&expr
, mostly_copy_tree_r
, NULL
, NULL
);
963 /* Worker for unshare_expr_without_location. */
966 prune_expr_location (tree
*tp
, int *walk_subtrees
, void *)
969 SET_EXPR_LOCATION (*tp
, UNKNOWN_LOCATION
);
975 /* Similar to unshare_expr but also prune all expression locations
979 unshare_expr_without_location (tree expr
)
981 walk_tree (&expr
, mostly_copy_tree_r
, NULL
, NULL
);
983 walk_tree (&expr
, prune_expr_location
, NULL
, NULL
);
987 /* Return the EXPR_LOCATION of EXPR, if it (maybe recursively) has
988 one, OR_ELSE otherwise. The location of a STATEMENT_LISTs
989 comprising at least one DEBUG_BEGIN_STMT followed by exactly one
990 EXPR is the location of the EXPR. */
993 rexpr_location (tree expr
, location_t or_else
= UNKNOWN_LOCATION
)
998 if (EXPR_HAS_LOCATION (expr
))
999 return EXPR_LOCATION (expr
);
1001 if (TREE_CODE (expr
) != STATEMENT_LIST
)
1004 tree_stmt_iterator i
= tsi_start (expr
);
1007 while (!tsi_end_p (i
) && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
1013 if (!found
|| !tsi_one_before_end_p (i
))
1016 return rexpr_location (tsi_stmt (i
), or_else
);
1019 /* Return TRUE iff EXPR (maybe recursively) has a location; see
1020 rexpr_location for the potential recursion. */
1023 rexpr_has_location (tree expr
)
1025 return rexpr_location (expr
) != UNKNOWN_LOCATION
;
1029 /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
1030 contain statements and have a value. Assign its value to a temporary
1031 and give it void_type_node. Return the temporary, or NULL_TREE if
1032 WRAPPER was already void. */
1035 voidify_wrapper_expr (tree wrapper
, tree temp
)
1037 tree type
= TREE_TYPE (wrapper
);
1038 if (type
&& !VOID_TYPE_P (type
))
1042 /* Set p to point to the body of the wrapper. Loop until we find
1043 something that isn't a wrapper. */
1044 for (p
= &wrapper
; p
&& *p
; )
1046 switch (TREE_CODE (*p
))
1049 TREE_SIDE_EFFECTS (*p
) = 1;
1050 TREE_TYPE (*p
) = void_type_node
;
1051 /* For a BIND_EXPR, the body is operand 1. */
1052 p
= &BIND_EXPR_BODY (*p
);
1055 case CLEANUP_POINT_EXPR
:
1056 case TRY_FINALLY_EXPR
:
1057 case TRY_CATCH_EXPR
:
1058 TREE_SIDE_EFFECTS (*p
) = 1;
1059 TREE_TYPE (*p
) = void_type_node
;
1060 p
= &TREE_OPERAND (*p
, 0);
1063 case STATEMENT_LIST
:
1065 tree_stmt_iterator i
= tsi_last (*p
);
1066 TREE_SIDE_EFFECTS (*p
) = 1;
1067 TREE_TYPE (*p
) = void_type_node
;
1068 p
= tsi_end_p (i
) ? NULL
: tsi_stmt_ptr (i
);
1073 /* Advance to the last statement. Set all container types to
1075 for (; TREE_CODE (*p
) == COMPOUND_EXPR
; p
= &TREE_OPERAND (*p
, 1))
1077 TREE_SIDE_EFFECTS (*p
) = 1;
1078 TREE_TYPE (*p
) = void_type_node
;
1082 case TRANSACTION_EXPR
:
1083 TREE_SIDE_EFFECTS (*p
) = 1;
1084 TREE_TYPE (*p
) = void_type_node
;
1085 p
= &TRANSACTION_EXPR_BODY (*p
);
1089 /* Assume that any tree upon which voidify_wrapper_expr is
1090 directly called is a wrapper, and that its body is op0. */
1093 TREE_SIDE_EFFECTS (*p
) = 1;
1094 TREE_TYPE (*p
) = void_type_node
;
1095 p
= &TREE_OPERAND (*p
, 0);
1103 if (p
== NULL
|| IS_EMPTY_STMT (*p
))
1107 /* The wrapper is on the RHS of an assignment that we're pushing
1109 gcc_assert (TREE_CODE (temp
) == INIT_EXPR
1110 || TREE_CODE (temp
) == MODIFY_EXPR
);
1111 TREE_OPERAND (temp
, 1) = *p
;
1116 temp
= create_tmp_var (type
, "retval");
1117 *p
= build2 (INIT_EXPR
, type
, temp
, *p
);
1126 /* Prepare calls to builtins to SAVE and RESTORE the stack as well as
1127 a temporary through which they communicate. */
1130 build_stack_save_restore (gcall
**save
, gcall
**restore
)
1134 *save
= gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_SAVE
), 0);
1135 tmp_var
= create_tmp_var (ptr_type_node
, "saved_stack");
1136 gimple_call_set_lhs (*save
, tmp_var
);
1139 = gimple_build_call (builtin_decl_implicit (BUILT_IN_STACK_RESTORE
),
1143 /* Generate IFN_ASAN_MARK call that poisons shadow of a for DECL variable. */
1146 build_asan_poison_call_expr (tree decl
)
1148 /* Do not poison variables that have size equal to zero. */
1149 tree unit_size
= DECL_SIZE_UNIT (decl
);
1150 if (zerop (unit_size
))
1153 tree base
= build_fold_addr_expr (decl
);
1155 return build_call_expr_internal_loc (UNKNOWN_LOCATION
, IFN_ASAN_MARK
,
1157 build_int_cst (integer_type_node
,
1162 /* Generate IFN_ASAN_MARK call that would poison or unpoison, depending
1163 on POISON flag, shadow memory of a DECL variable. The call will be
1164 put on location identified by IT iterator, where BEFORE flag drives
1165 position where the stmt will be put. */
1168 asan_poison_variable (tree decl
, bool poison
, gimple_stmt_iterator
*it
,
1171 tree unit_size
= DECL_SIZE_UNIT (decl
);
1172 tree base
= build_fold_addr_expr (decl
);
1174 /* Do not poison variables that have size equal to zero. */
1175 if (zerop (unit_size
))
1178 /* It's necessary to have all stack variables aligned to ASAN granularity
1180 if (DECL_ALIGN_UNIT (decl
) <= ASAN_SHADOW_GRANULARITY
)
1181 SET_DECL_ALIGN (decl
, BITS_PER_UNIT
* ASAN_SHADOW_GRANULARITY
);
1183 HOST_WIDE_INT flags
= poison
? ASAN_MARK_POISON
: ASAN_MARK_UNPOISON
;
1186 = gimple_build_call_internal (IFN_ASAN_MARK
, 3,
1187 build_int_cst (integer_type_node
, flags
),
1191 gsi_insert_before (it
, g
, GSI_NEW_STMT
);
1193 gsi_insert_after (it
, g
, GSI_NEW_STMT
);
1196 /* Generate IFN_ASAN_MARK internal call that depending on POISON flag
1197 either poisons or unpoisons a DECL. Created statement is appended
1198 to SEQ_P gimple sequence. */
1201 asan_poison_variable (tree decl
, bool poison
, gimple_seq
*seq_p
)
1203 gimple_stmt_iterator it
= gsi_last (*seq_p
);
1204 bool before
= false;
1209 asan_poison_variable (decl
, poison
, &it
, before
);
1212 /* Sort pair of VAR_DECLs A and B by DECL_UID. */
1215 sort_by_decl_uid (const void *a
, const void *b
)
1217 const tree
*t1
= (const tree
*)a
;
1218 const tree
*t2
= (const tree
*)b
;
1220 int uid1
= DECL_UID (*t1
);
1221 int uid2
= DECL_UID (*t2
);
1225 else if (uid1
> uid2
)
1231 /* Generate IFN_ASAN_MARK internal call for all VARIABLES
1232 depending on POISON flag. Created statement is appended
1233 to SEQ_P gimple sequence. */
1236 asan_poison_variables (hash_set
<tree
> *variables
, bool poison
, gimple_seq
*seq_p
)
1238 unsigned c
= variables
->elements ();
1242 auto_vec
<tree
> sorted_variables (c
);
1244 for (hash_set
<tree
>::iterator it
= variables
->begin ();
1245 it
!= variables
->end (); ++it
)
1246 sorted_variables
.safe_push (*it
);
1248 sorted_variables
.qsort (sort_by_decl_uid
);
1252 FOR_EACH_VEC_ELT (sorted_variables
, i
, var
)
1254 asan_poison_variable (var
, poison
, seq_p
);
1256 /* Add use_after_scope_memory attribute for the variable in order
1257 to prevent re-written into SSA. */
1258 if (!lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE
,
1259 DECL_ATTRIBUTES (var
)))
1260 DECL_ATTRIBUTES (var
)
1261 = tree_cons (get_identifier (ASAN_USE_AFTER_SCOPE_ATTRIBUTE
),
1263 DECL_ATTRIBUTES (var
));
1267 /* Gimplify a BIND_EXPR. Just voidify and recurse. */
1269 static enum gimplify_status
1270 gimplify_bind_expr (tree
*expr_p
, gimple_seq
*pre_p
)
1272 tree bind_expr
= *expr_p
;
1273 bool old_keep_stack
= gimplify_ctxp
->keep_stack
;
1274 bool old_save_stack
= gimplify_ctxp
->save_stack
;
1277 gimple_seq body
, cleanup
;
1279 location_t start_locus
= 0, end_locus
= 0;
1280 tree ret_clauses
= NULL
;
1282 tree temp
= voidify_wrapper_expr (bind_expr
, NULL
);
1284 /* Mark variables seen in this bind expr. */
1285 for (t
= BIND_EXPR_VARS (bind_expr
); t
; t
= DECL_CHAIN (t
))
1289 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
1291 /* Mark variable as local. */
1292 if (ctx
&& ctx
->region_type
!= ORT_NONE
&& !DECL_EXTERNAL (t
)
1293 && (! DECL_SEEN_IN_BIND_EXPR_P (t
)
1294 || splay_tree_lookup (ctx
->variables
,
1295 (splay_tree_key
) t
) == NULL
))
1297 if (ctx
->region_type
== ORT_SIMD
1298 && TREE_ADDRESSABLE (t
)
1299 && !TREE_STATIC (t
))
1300 omp_add_variable (ctx
, t
, GOVD_PRIVATE
| GOVD_SEEN
);
1302 omp_add_variable (ctx
, t
, GOVD_LOCAL
| GOVD_SEEN
);
1305 DECL_SEEN_IN_BIND_EXPR_P (t
) = 1;
1307 if (DECL_HARD_REGISTER (t
) && !is_global_var (t
) && cfun
)
1308 cfun
->has_local_explicit_reg_vars
= true;
1311 /* Preliminarily mark non-addressed complex variables as eligible
1312 for promotion to gimple registers. We'll transform their uses
1314 if ((TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
1315 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
1316 && !TREE_THIS_VOLATILE (t
)
1317 && (VAR_P (t
) && !DECL_HARD_REGISTER (t
))
1318 && !needs_to_live_in_memory (t
))
1319 DECL_GIMPLE_REG_P (t
) = 1;
1322 bind_stmt
= gimple_build_bind (BIND_EXPR_VARS (bind_expr
), NULL
,
1323 BIND_EXPR_BLOCK (bind_expr
));
1324 gimple_push_bind_expr (bind_stmt
);
1326 gimplify_ctxp
->keep_stack
= false;
1327 gimplify_ctxp
->save_stack
= false;
1329 /* Gimplify the body into the GIMPLE_BIND tuple's body. */
1331 gimplify_stmt (&BIND_EXPR_BODY (bind_expr
), &body
);
1332 gimple_bind_set_body (bind_stmt
, body
);
1334 /* Source location wise, the cleanup code (stack_restore and clobbers)
1335 belongs to the end of the block, so propagate what we have. The
1336 stack_save operation belongs to the beginning of block, which we can
1337 infer from the bind_expr directly if the block has no explicit
1339 if (BIND_EXPR_BLOCK (bind_expr
))
1341 end_locus
= BLOCK_SOURCE_END_LOCATION (BIND_EXPR_BLOCK (bind_expr
));
1342 start_locus
= BLOCK_SOURCE_LOCATION (BIND_EXPR_BLOCK (bind_expr
));
1344 if (start_locus
== 0)
1345 start_locus
= EXPR_LOCATION (bind_expr
);
1350 /* If the code both contains VLAs and calls alloca, then we cannot reclaim
1351 the stack space allocated to the VLAs. */
1352 if (gimplify_ctxp
->save_stack
&& !gimplify_ctxp
->keep_stack
)
1354 gcall
*stack_restore
;
1356 /* Save stack on entry and restore it on exit. Add a try_finally
1357 block to achieve this. */
1358 build_stack_save_restore (&stack_save
, &stack_restore
);
1360 gimple_set_location (stack_save
, start_locus
);
1361 gimple_set_location (stack_restore
, end_locus
);
1363 gimplify_seq_add_stmt (&cleanup
, stack_restore
);
1366 /* Add clobbers for all variables that go out of scope. */
1367 for (t
= BIND_EXPR_VARS (bind_expr
); t
; t
= DECL_CHAIN (t
))
1370 && !is_global_var (t
)
1371 && DECL_CONTEXT (t
) == current_function_decl
)
1373 if (!DECL_HARD_REGISTER (t
)
1374 && !TREE_THIS_VOLATILE (t
)
1375 && !DECL_HAS_VALUE_EXPR_P (t
)
1376 /* Only care for variables that have to be in memory. Others
1377 will be rewritten into SSA names, hence moved to the
1379 && !is_gimple_reg (t
)
1380 && flag_stack_reuse
!= SR_NONE
)
1382 tree clobber
= build_clobber (TREE_TYPE (t
));
1383 gimple
*clobber_stmt
;
1384 clobber_stmt
= gimple_build_assign (t
, clobber
);
1385 gimple_set_location (clobber_stmt
, end_locus
);
1386 gimplify_seq_add_stmt (&cleanup
, clobber_stmt
);
1389 if (flag_openacc
&& oacc_declare_returns
!= NULL
)
1391 tree
*c
= oacc_declare_returns
->get (t
);
1395 OMP_CLAUSE_CHAIN (*c
) = ret_clauses
;
1399 oacc_declare_returns
->remove (t
);
1401 if (oacc_declare_returns
->elements () == 0)
1403 delete oacc_declare_returns
;
1404 oacc_declare_returns
= NULL
;
1410 if (asan_poisoned_variables
!= NULL
1411 && asan_poisoned_variables
->contains (t
))
1413 asan_poisoned_variables
->remove (t
);
1414 asan_poison_variable (t
, true, &cleanup
);
1417 if (gimplify_ctxp
->live_switch_vars
!= NULL
1418 && gimplify_ctxp
->live_switch_vars
->contains (t
))
1419 gimplify_ctxp
->live_switch_vars
->remove (t
);
1425 gimple_stmt_iterator si
= gsi_start (cleanup
);
1427 stmt
= gimple_build_omp_target (NULL
, GF_OMP_TARGET_KIND_OACC_DECLARE
,
1429 gsi_insert_seq_before_without_update (&si
, stmt
, GSI_NEW_STMT
);
1435 gimple_seq new_body
;
1438 gs
= gimple_build_try (gimple_bind_body (bind_stmt
), cleanup
,
1439 GIMPLE_TRY_FINALLY
);
1442 gimplify_seq_add_stmt (&new_body
, stack_save
);
1443 gimplify_seq_add_stmt (&new_body
, gs
);
1444 gimple_bind_set_body (bind_stmt
, new_body
);
1447 /* keep_stack propagates all the way up to the outermost BIND_EXPR. */
1448 if (!gimplify_ctxp
->keep_stack
)
1449 gimplify_ctxp
->keep_stack
= old_keep_stack
;
1450 gimplify_ctxp
->save_stack
= old_save_stack
;
1452 gimple_pop_bind_expr ();
1454 gimplify_seq_add_stmt (pre_p
, bind_stmt
);
1462 *expr_p
= NULL_TREE
;
1466 /* Maybe add early return predict statement to PRE_P sequence. */
1469 maybe_add_early_return_predict_stmt (gimple_seq
*pre_p
)
1471 /* If we are not in a conditional context, add PREDICT statement. */
1472 if (gimple_conditional_context ())
1474 gimple
*predict
= gimple_build_predict (PRED_TREE_EARLY_RETURN
,
1476 gimplify_seq_add_stmt (pre_p
, predict
);
1480 /* Gimplify a RETURN_EXPR. If the expression to be returned is not a
1481 GIMPLE value, it is assigned to a new temporary and the statement is
1482 re-written to return the temporary.
1484 PRE_P points to the sequence where side effects that must happen before
1485 STMT should be stored. */
1487 static enum gimplify_status
1488 gimplify_return_expr (tree stmt
, gimple_seq
*pre_p
)
1491 tree ret_expr
= TREE_OPERAND (stmt
, 0);
1492 tree result_decl
, result
;
1494 if (ret_expr
== error_mark_node
)
1498 || TREE_CODE (ret_expr
) == RESULT_DECL
)
1500 maybe_add_early_return_predict_stmt (pre_p
);
1501 greturn
*ret
= gimple_build_return (ret_expr
);
1502 gimple_set_no_warning (ret
, TREE_NO_WARNING (stmt
));
1503 gimplify_seq_add_stmt (pre_p
, ret
);
1507 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl
))))
1508 result_decl
= NULL_TREE
;
1511 result_decl
= TREE_OPERAND (ret_expr
, 0);
1513 /* See through a return by reference. */
1514 if (TREE_CODE (result_decl
) == INDIRECT_REF
)
1515 result_decl
= TREE_OPERAND (result_decl
, 0);
1517 gcc_assert ((TREE_CODE (ret_expr
) == MODIFY_EXPR
1518 || TREE_CODE (ret_expr
) == INIT_EXPR
)
1519 && TREE_CODE (result_decl
) == RESULT_DECL
);
1522 /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
1523 Recall that aggregate_value_p is FALSE for any aggregate type that is
1524 returned in registers. If we're returning values in registers, then
1525 we don't want to extend the lifetime of the RESULT_DECL, particularly
1526 across another call. In addition, for those aggregates for which
1527 hard_function_value generates a PARALLEL, we'll die during normal
1528 expansion of structure assignments; there's special code in expand_return
1529 to handle this case that does not exist in expand_expr. */
1532 else if (aggregate_value_p (result_decl
, TREE_TYPE (current_function_decl
)))
1534 if (TREE_CODE (DECL_SIZE (result_decl
)) != INTEGER_CST
)
1536 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (result_decl
)))
1537 gimplify_type_sizes (TREE_TYPE (result_decl
), pre_p
);
1538 /* Note that we don't use gimplify_vla_decl because the RESULT_DECL
1539 should be effectively allocated by the caller, i.e. all calls to
1540 this function must be subject to the Return Slot Optimization. */
1541 gimplify_one_sizepos (&DECL_SIZE (result_decl
), pre_p
);
1542 gimplify_one_sizepos (&DECL_SIZE_UNIT (result_decl
), pre_p
);
1544 result
= result_decl
;
1546 else if (gimplify_ctxp
->return_temp
)
1547 result
= gimplify_ctxp
->return_temp
;
1550 result
= create_tmp_reg (TREE_TYPE (result_decl
));
1552 /* ??? With complex control flow (usually involving abnormal edges),
1553 we can wind up warning about an uninitialized value for this. Due
1554 to how this variable is constructed and initialized, this is never
1555 true. Give up and never warn. */
1556 TREE_NO_WARNING (result
) = 1;
1558 gimplify_ctxp
->return_temp
= result
;
1561 /* Smash the lhs of the MODIFY_EXPR to the temporary we plan to use.
1562 Then gimplify the whole thing. */
1563 if (result
!= result_decl
)
1564 TREE_OPERAND (ret_expr
, 0) = result
;
1566 gimplify_and_add (TREE_OPERAND (stmt
, 0), pre_p
);
1568 maybe_add_early_return_predict_stmt (pre_p
);
1569 ret
= gimple_build_return (result
);
1570 gimple_set_no_warning (ret
, TREE_NO_WARNING (stmt
));
1571 gimplify_seq_add_stmt (pre_p
, ret
);
1576 /* Gimplify a variable-length array DECL. */
1579 gimplify_vla_decl (tree decl
, gimple_seq
*seq_p
)
1581 /* This is a variable-sized decl. Simplify its size and mark it
1582 for deferred expansion. */
1583 tree t
, addr
, ptr_type
;
1585 gimplify_one_sizepos (&DECL_SIZE (decl
), seq_p
);
1586 gimplify_one_sizepos (&DECL_SIZE_UNIT (decl
), seq_p
);
1588 /* Don't mess with a DECL_VALUE_EXPR set by the front-end. */
1589 if (DECL_HAS_VALUE_EXPR_P (decl
))
1592 /* All occurrences of this decl in final gimplified code will be
1593 replaced by indirection. Setting DECL_VALUE_EXPR does two
1594 things: First, it lets the rest of the gimplifier know what
1595 replacement to use. Second, it lets the debug info know
1596 where to find the value. */
1597 ptr_type
= build_pointer_type (TREE_TYPE (decl
));
1598 addr
= create_tmp_var (ptr_type
, get_name (decl
));
1599 DECL_IGNORED_P (addr
) = 0;
1600 t
= build_fold_indirect_ref (addr
);
1601 TREE_THIS_NOTRAP (t
) = 1;
1602 SET_DECL_VALUE_EXPR (decl
, t
);
1603 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1605 t
= build_alloca_call_expr (DECL_SIZE_UNIT (decl
), DECL_ALIGN (decl
),
1606 max_int_size_in_bytes (TREE_TYPE (decl
)));
1607 /* The call has been built for a variable-sized object. */
1608 CALL_ALLOCA_FOR_VAR_P (t
) = 1;
1609 t
= fold_convert (ptr_type
, t
);
1610 t
= build2 (MODIFY_EXPR
, TREE_TYPE (addr
), addr
, t
);
1612 gimplify_and_add (t
, seq_p
);
1615 /* A helper function to be called via walk_tree. Mark all labels under *TP
1616 as being forced. To be called for DECL_INITIAL of static variables. */
1619 force_labels_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1623 if (TREE_CODE (*tp
) == LABEL_DECL
)
1625 FORCED_LABEL (*tp
) = 1;
1626 cfun
->has_forced_label_in_static
= 1;
1632 /* Gimplify a DECL_EXPR node *STMT_P by making any necessary allocation
1633 and initialization explicit. */
1635 static enum gimplify_status
1636 gimplify_decl_expr (tree
*stmt_p
, gimple_seq
*seq_p
)
1638 tree stmt
= *stmt_p
;
1639 tree decl
= DECL_EXPR_DECL (stmt
);
1641 *stmt_p
= NULL_TREE
;
1643 if (TREE_TYPE (decl
) == error_mark_node
)
1646 if ((TREE_CODE (decl
) == TYPE_DECL
1648 && !TYPE_SIZES_GIMPLIFIED (TREE_TYPE (decl
)))
1650 gimplify_type_sizes (TREE_TYPE (decl
), seq_p
);
1651 if (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
)
1652 gimplify_type_sizes (TREE_TYPE (TREE_TYPE (decl
)), seq_p
);
1655 /* ??? DECL_ORIGINAL_TYPE is streamed for LTO so it needs to be gimplified
1656 in case its size expressions contain problematic nodes like CALL_EXPR. */
1657 if (TREE_CODE (decl
) == TYPE_DECL
1658 && DECL_ORIGINAL_TYPE (decl
)
1659 && !TYPE_SIZES_GIMPLIFIED (DECL_ORIGINAL_TYPE (decl
)))
1661 gimplify_type_sizes (DECL_ORIGINAL_TYPE (decl
), seq_p
);
1662 if (TREE_CODE (DECL_ORIGINAL_TYPE (decl
)) == REFERENCE_TYPE
)
1663 gimplify_type_sizes (TREE_TYPE (DECL_ORIGINAL_TYPE (decl
)), seq_p
);
1666 if (VAR_P (decl
) && !DECL_EXTERNAL (decl
))
1668 tree init
= DECL_INITIAL (decl
);
1669 bool is_vla
= false;
1671 if (TREE_CODE (DECL_SIZE_UNIT (decl
)) != INTEGER_CST
1672 || (!TREE_STATIC (decl
)
1673 && flag_stack_check
== GENERIC_STACK_CHECK
1674 && compare_tree_int (DECL_SIZE_UNIT (decl
),
1675 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1677 gimplify_vla_decl (decl
, seq_p
);
1681 if (asan_poisoned_variables
1683 && TREE_ADDRESSABLE (decl
)
1684 && !TREE_STATIC (decl
)
1685 && !DECL_HAS_VALUE_EXPR_P (decl
)
1686 && DECL_ALIGN (decl
) <= MAX_SUPPORTED_STACK_ALIGNMENT
1687 && dbg_cnt (asan_use_after_scope
)
1688 && !gimplify_omp_ctxp
)
1690 asan_poisoned_variables
->add (decl
);
1691 asan_poison_variable (decl
, false, seq_p
);
1692 if (!DECL_ARTIFICIAL (decl
) && gimplify_ctxp
->live_switch_vars
)
1693 gimplify_ctxp
->live_switch_vars
->add (decl
);
1696 /* Some front ends do not explicitly declare all anonymous
1697 artificial variables. We compensate here by declaring the
1698 variables, though it would be better if the front ends would
1699 explicitly declare them. */
1700 if (!DECL_SEEN_IN_BIND_EXPR_P (decl
)
1701 && DECL_ARTIFICIAL (decl
) && DECL_NAME (decl
) == NULL_TREE
)
1702 gimple_add_tmp_var (decl
);
1704 if (init
&& init
!= error_mark_node
)
1706 if (!TREE_STATIC (decl
))
1708 DECL_INITIAL (decl
) = NULL_TREE
;
1709 init
= build2 (INIT_EXPR
, void_type_node
, decl
, init
);
1710 gimplify_and_add (init
, seq_p
);
1714 /* We must still examine initializers for static variables
1715 as they may contain a label address. */
1716 walk_tree (&init
, force_labels_r
, NULL
, NULL
);
1723 /* Gimplify a LOOP_EXPR. Normally this just involves gimplifying the body
1724 and replacing the LOOP_EXPR with goto, but if the loop contains an
1725 EXIT_EXPR, we need to append a label for it to jump to. */
1727 static enum gimplify_status
1728 gimplify_loop_expr (tree
*expr_p
, gimple_seq
*pre_p
)
1730 tree saved_label
= gimplify_ctxp
->exit_label
;
1731 tree start_label
= create_artificial_label (UNKNOWN_LOCATION
);
1733 gimplify_seq_add_stmt (pre_p
, gimple_build_label (start_label
));
1735 gimplify_ctxp
->exit_label
= NULL_TREE
;
1737 gimplify_and_add (LOOP_EXPR_BODY (*expr_p
), pre_p
);
1739 gimplify_seq_add_stmt (pre_p
, gimple_build_goto (start_label
));
1741 if (gimplify_ctxp
->exit_label
)
1742 gimplify_seq_add_stmt (pre_p
,
1743 gimple_build_label (gimplify_ctxp
->exit_label
));
1745 gimplify_ctxp
->exit_label
= saved_label
;
1751 /* Gimplify a statement list onto a sequence. These may be created either
1752 by an enlightened front-end, or by shortcut_cond_expr. */
1754 static enum gimplify_status
1755 gimplify_statement_list (tree
*expr_p
, gimple_seq
*pre_p
)
1757 tree temp
= voidify_wrapper_expr (*expr_p
, NULL
);
1759 tree_stmt_iterator i
= tsi_start (*expr_p
);
1761 while (!tsi_end_p (i
))
1763 gimplify_stmt (tsi_stmt_ptr (i
), pre_p
);
1776 /* Callback for walk_gimple_seq. */
1779 warn_switch_unreachable_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
1780 struct walk_stmt_info
*wi
)
1782 gimple
*stmt
= gsi_stmt (*gsi_p
);
1784 *handled_ops_p
= true;
1785 switch (gimple_code (stmt
))
1788 /* A compiler-generated cleanup or a user-written try block.
1789 If it's empty, don't dive into it--that would result in
1790 worse location info. */
1791 if (gimple_try_eval (stmt
) == NULL
)
1794 return integer_zero_node
;
1799 case GIMPLE_EH_FILTER
:
1800 case GIMPLE_TRANSACTION
:
1801 /* Walk the sub-statements. */
1802 *handled_ops_p
= false;
1806 /* Ignore these. We may generate them before declarations that
1807 are never executed. If there's something to warn about,
1808 there will be non-debug stmts too, and we'll catch those. */
1812 if (gimple_call_internal_p (stmt
, IFN_ASAN_MARK
))
1814 *handled_ops_p
= false;
1819 /* Save the first "real" statement (not a decl/lexical scope/...). */
1821 return integer_zero_node
;
1826 /* Possibly warn about unreachable statements between switch's controlling
1827 expression and the first case. SEQ is the body of a switch expression. */
1830 maybe_warn_switch_unreachable (gimple_seq seq
)
1832 if (!warn_switch_unreachable
1833 /* This warning doesn't play well with Fortran when optimizations
1835 || lang_GNU_Fortran ()
1839 struct walk_stmt_info wi
;
1840 memset (&wi
, 0, sizeof (wi
));
1841 walk_gimple_seq (seq
, warn_switch_unreachable_r
, NULL
, &wi
);
1842 gimple
*stmt
= (gimple
*) wi
.info
;
1844 if (stmt
&& gimple_code (stmt
) != GIMPLE_LABEL
)
1846 if (gimple_code (stmt
) == GIMPLE_GOTO
1847 && TREE_CODE (gimple_goto_dest (stmt
)) == LABEL_DECL
1848 && DECL_ARTIFICIAL (gimple_goto_dest (stmt
)))
1849 /* Don't warn for compiler-generated gotos. These occur
1850 in Duff's devices, for example. */;
1852 warning_at (gimple_location (stmt
), OPT_Wswitch_unreachable
,
1853 "statement will never be executed");
1858 /* A label entry that pairs label and a location. */
1865 /* Find LABEL in vector of label entries VEC. */
1867 static struct label_entry
*
1868 find_label_entry (const auto_vec
<struct label_entry
> *vec
, tree label
)
1871 struct label_entry
*l
;
1873 FOR_EACH_VEC_ELT (*vec
, i
, l
)
1874 if (l
->label
== label
)
1879 /* Return true if LABEL, a LABEL_DECL, represents a case label
1880 in a vector of labels CASES. */
1883 case_label_p (const vec
<tree
> *cases
, tree label
)
1888 FOR_EACH_VEC_ELT (*cases
, i
, l
)
1889 if (CASE_LABEL (l
) == label
)
1894 /* Find the last nondebug statement in a scope STMT. */
1897 last_stmt_in_scope (gimple
*stmt
)
1902 switch (gimple_code (stmt
))
1906 gbind
*bind
= as_a
<gbind
*> (stmt
);
1907 stmt
= gimple_seq_last_nondebug_stmt (gimple_bind_body (bind
));
1908 return last_stmt_in_scope (stmt
);
1913 gtry
*try_stmt
= as_a
<gtry
*> (stmt
);
1914 stmt
= gimple_seq_last_nondebug_stmt (gimple_try_eval (try_stmt
));
1915 gimple
*last_eval
= last_stmt_in_scope (stmt
);
1916 if (gimple_stmt_may_fallthru (last_eval
)
1917 && (last_eval
== NULL
1918 || !gimple_call_internal_p (last_eval
, IFN_FALLTHROUGH
))
1919 && gimple_try_kind (try_stmt
) == GIMPLE_TRY_FINALLY
)
1921 stmt
= gimple_seq_last_nondebug_stmt (gimple_try_cleanup (try_stmt
));
1922 return last_stmt_in_scope (stmt
);
1936 /* Collect interesting labels in LABELS and return the statement preceding
1937 another case label, or a user-defined label. */
1940 collect_fallthrough_labels (gimple_stmt_iterator
*gsi_p
,
1941 auto_vec
<struct label_entry
> *labels
)
1943 gimple
*prev
= NULL
;
1947 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_BIND
)
1949 /* Recognize the special GIMPLE_BIND added by gimplify_switch_expr,
1950 which starts on a GIMPLE_SWITCH and ends with a break label.
1951 Handle that as a single statement that can fall through. */
1952 gbind
*bind
= as_a
<gbind
*> (gsi_stmt (*gsi_p
));
1953 gimple
*first
= gimple_seq_first_stmt (gimple_bind_body (bind
));
1954 gimple
*last
= gimple_seq_last_stmt (gimple_bind_body (bind
));
1956 && gimple_code (first
) == GIMPLE_SWITCH
1957 && gimple_code (last
) == GIMPLE_LABEL
)
1959 tree label
= gimple_label_label (as_a
<glabel
*> (last
));
1960 if (SWITCH_BREAK_LABEL_P (label
))
1968 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_BIND
1969 || gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_TRY
)
1971 /* Nested scope. Only look at the last statement of
1972 the innermost scope. */
1973 location_t bind_loc
= gimple_location (gsi_stmt (*gsi_p
));
1974 gimple
*last
= last_stmt_in_scope (gsi_stmt (*gsi_p
));
1978 /* It might be a label without a location. Use the
1979 location of the scope then. */
1980 if (!gimple_has_location (prev
))
1981 gimple_set_location (prev
, bind_loc
);
1987 /* Ifs are tricky. */
1988 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_COND
)
1990 gcond
*cond_stmt
= as_a
<gcond
*> (gsi_stmt (*gsi_p
));
1991 tree false_lab
= gimple_cond_false_label (cond_stmt
);
1992 location_t if_loc
= gimple_location (cond_stmt
);
1995 if (i > 1) goto <D.2259>; else goto D;
1996 we can't do much with the else-branch. */
1997 if (!DECL_ARTIFICIAL (false_lab
))
2000 /* Go on until the false label, then one step back. */
2001 for (; !gsi_end_p (*gsi_p
); gsi_next (gsi_p
))
2003 gimple
*stmt
= gsi_stmt (*gsi_p
);
2004 if (gimple_code (stmt
) == GIMPLE_LABEL
2005 && gimple_label_label (as_a
<glabel
*> (stmt
)) == false_lab
)
2009 /* Not found? Oops. */
2010 if (gsi_end_p (*gsi_p
))
2013 struct label_entry l
= { false_lab
, if_loc
};
2014 labels
->safe_push (l
);
2016 /* Go to the last statement of the then branch. */
2019 /* if (i != 0) goto <D.1759>; else goto <D.1760>;
2025 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_GOTO
2026 && !gimple_has_location (gsi_stmt (*gsi_p
)))
2028 /* Look at the statement before, it might be
2029 attribute fallthrough, in which case don't warn. */
2031 bool fallthru_before_dest
2032 = gimple_call_internal_p (gsi_stmt (*gsi_p
), IFN_FALLTHROUGH
);
2034 tree goto_dest
= gimple_goto_dest (gsi_stmt (*gsi_p
));
2035 if (!fallthru_before_dest
)
2037 struct label_entry l
= { goto_dest
, if_loc
};
2038 labels
->safe_push (l
);
2041 /* And move back. */
2045 /* Remember the last statement. Skip labels that are of no interest
2047 if (gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_LABEL
)
2049 tree label
= gimple_label_label (as_a
<glabel
*> (gsi_stmt (*gsi_p
)));
2050 if (find_label_entry (labels
, label
))
2051 prev
= gsi_stmt (*gsi_p
);
2053 else if (gimple_call_internal_p (gsi_stmt (*gsi_p
), IFN_ASAN_MARK
))
2055 else if (!is_gimple_debug (gsi_stmt (*gsi_p
)))
2056 prev
= gsi_stmt (*gsi_p
);
2059 while (!gsi_end_p (*gsi_p
)
2060 /* Stop if we find a case or a user-defined label. */
2061 && (gimple_code (gsi_stmt (*gsi_p
)) != GIMPLE_LABEL
2062 || !gimple_has_location (gsi_stmt (*gsi_p
))));
2067 /* Return true if the switch fallthough warning should occur. LABEL is
2068 the label statement that we're falling through to. */
2071 should_warn_for_implicit_fallthrough (gimple_stmt_iterator
*gsi_p
, tree label
)
2073 gimple_stmt_iterator gsi
= *gsi_p
;
2075 /* Don't warn if the label is marked with a "falls through" comment. */
2076 if (FALLTHROUGH_LABEL_P (label
))
2079 /* Don't warn for non-case labels followed by a statement:
2084 as these are likely intentional. */
2085 if (!case_label_p (&gimplify_ctxp
->case_labels
, label
))
2088 while (!gsi_end_p (gsi
)
2089 && gimple_code (gsi_stmt (gsi
)) == GIMPLE_LABEL
2090 && (l
= gimple_label_label (as_a
<glabel
*> (gsi_stmt (gsi
))))
2091 && !case_label_p (&gimplify_ctxp
->case_labels
, l
))
2092 gsi_next_nondebug (&gsi
);
2093 if (gsi_end_p (gsi
) || gimple_code (gsi_stmt (gsi
)) != GIMPLE_LABEL
)
2097 /* Don't warn for terminated branches, i.e. when the subsequent case labels
2098 immediately breaks. */
2101 /* Skip all immediately following labels. */
2102 while (!gsi_end_p (gsi
)
2103 && (gimple_code (gsi_stmt (gsi
)) == GIMPLE_LABEL
2104 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_PREDICT
))
2105 gsi_next_nondebug (&gsi
);
2107 /* { ... something; default:; } */
2109 /* { ... something; default: break; } or
2110 { ... something; default: goto L; } */
2111 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_GOTO
2112 /* { ... something; default: return; } */
2113 || gimple_code (gsi_stmt (gsi
)) == GIMPLE_RETURN
)
2119 /* Callback for walk_gimple_seq. */
2122 warn_implicit_fallthrough_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
2123 struct walk_stmt_info
*)
2125 gimple
*stmt
= gsi_stmt (*gsi_p
);
2127 *handled_ops_p
= true;
2128 switch (gimple_code (stmt
))
2133 case GIMPLE_EH_FILTER
:
2134 case GIMPLE_TRANSACTION
:
2135 /* Walk the sub-statements. */
2136 *handled_ops_p
= false;
2139 /* Find a sequence of form:
2146 and possibly warn. */
2149 /* Found a label. Skip all immediately following labels. */
2150 while (!gsi_end_p (*gsi_p
)
2151 && gimple_code (gsi_stmt (*gsi_p
)) == GIMPLE_LABEL
)
2152 gsi_next_nondebug (gsi_p
);
2154 /* There might be no more statements. */
2155 if (gsi_end_p (*gsi_p
))
2156 return integer_zero_node
;
2158 /* Vector of labels that fall through. */
2159 auto_vec
<struct label_entry
> labels
;
2160 gimple
*prev
= collect_fallthrough_labels (gsi_p
, &labels
);
2162 /* There might be no more statements. */
2163 if (gsi_end_p (*gsi_p
))
2164 return integer_zero_node
;
2166 gimple
*next
= gsi_stmt (*gsi_p
);
2168 /* If what follows is a label, then we may have a fallthrough. */
2169 if (gimple_code (next
) == GIMPLE_LABEL
2170 && gimple_has_location (next
)
2171 && (label
= gimple_label_label (as_a
<glabel
*> (next
)))
2174 struct label_entry
*l
;
2175 bool warned_p
= false;
2176 if (!should_warn_for_implicit_fallthrough (gsi_p
, label
))
2178 else if (gimple_code (prev
) == GIMPLE_LABEL
2179 && (label
= gimple_label_label (as_a
<glabel
*> (prev
)))
2180 && (l
= find_label_entry (&labels
, label
)))
2181 warned_p
= warning_at (l
->loc
, OPT_Wimplicit_fallthrough_
,
2182 "this statement may fall through");
2183 else if (!gimple_call_internal_p (prev
, IFN_FALLTHROUGH
)
2184 /* Try to be clever and don't warn when the statement
2185 can't actually fall through. */
2186 && gimple_stmt_may_fallthru (prev
)
2187 && gimple_has_location (prev
))
2188 warned_p
= warning_at (gimple_location (prev
),
2189 OPT_Wimplicit_fallthrough_
,
2190 "this statement may fall through");
2192 inform (gimple_location (next
), "here");
2194 /* Mark this label as processed so as to prevent multiple
2195 warnings in nested switches. */
2196 FALLTHROUGH_LABEL_P (label
) = true;
2198 /* So that next warn_implicit_fallthrough_r will start looking for
2199 a new sequence starting with this label. */
2210 /* Warn when a switch case falls through. */
2213 maybe_warn_implicit_fallthrough (gimple_seq seq
)
2215 if (!warn_implicit_fallthrough
)
2218 /* This warning is meant for C/C++/ObjC/ObjC++ only. */
2221 || lang_GNU_OBJC ()))
2224 struct walk_stmt_info wi
;
2225 memset (&wi
, 0, sizeof (wi
));
2226 walk_gimple_seq (seq
, warn_implicit_fallthrough_r
, NULL
, &wi
);
2229 /* Callback for walk_gimple_seq. */
2232 expand_FALLTHROUGH_r (gimple_stmt_iterator
*gsi_p
, bool *handled_ops_p
,
2233 struct walk_stmt_info
*)
2235 gimple
*stmt
= gsi_stmt (*gsi_p
);
2237 *handled_ops_p
= true;
2238 switch (gimple_code (stmt
))
2243 case GIMPLE_EH_FILTER
:
2244 case GIMPLE_TRANSACTION
:
2245 /* Walk the sub-statements. */
2246 *handled_ops_p
= false;
2249 if (gimple_call_internal_p (stmt
, IFN_FALLTHROUGH
))
2251 gsi_remove (gsi_p
, true);
2252 if (gsi_end_p (*gsi_p
))
2253 return integer_zero_node
;
2256 location_t loc
= gimple_location (stmt
);
2258 gimple_stmt_iterator gsi2
= *gsi_p
;
2259 stmt
= gsi_stmt (gsi2
);
2260 if (gimple_code (stmt
) == GIMPLE_GOTO
&& !gimple_has_location (stmt
))
2262 /* Go on until the artificial label. */
2263 tree goto_dest
= gimple_goto_dest (stmt
);
2264 for (; !gsi_end_p (gsi2
); gsi_next (&gsi2
))
2266 if (gimple_code (gsi_stmt (gsi2
)) == GIMPLE_LABEL
2267 && gimple_label_label (as_a
<glabel
*> (gsi_stmt (gsi2
)))
2272 /* Not found? Stop. */
2273 if (gsi_end_p (gsi2
))
2276 /* Look one past it. */
2280 /* We're looking for a case label or default label here. */
2281 while (!gsi_end_p (gsi2
))
2283 stmt
= gsi_stmt (gsi2
);
2284 if (gimple_code (stmt
) == GIMPLE_LABEL
)
2286 tree label
= gimple_label_label (as_a
<glabel
*> (stmt
));
2287 if (gimple_has_location (stmt
) && DECL_ARTIFICIAL (label
))
2293 else if (gimple_call_internal_p (stmt
, IFN_ASAN_MARK
))
2295 else if (!is_gimple_debug (stmt
))
2296 /* Anything else is not expected. */
2301 warning_at (loc
, 0, "attribute %<fallthrough%> not preceding "
2302 "a case label or default label");
2311 /* Expand all FALLTHROUGH () calls in SEQ. */
2314 expand_FALLTHROUGH (gimple_seq
*seq_p
)
2316 struct walk_stmt_info wi
;
2317 memset (&wi
, 0, sizeof (wi
));
2318 walk_gimple_seq_mod (seq_p
, expand_FALLTHROUGH_r
, NULL
, &wi
);
2322 /* Gimplify a SWITCH_EXPR, and collect the vector of labels it can
2325 static enum gimplify_status
2326 gimplify_switch_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2328 tree switch_expr
= *expr_p
;
2329 gimple_seq switch_body_seq
= NULL
;
2330 enum gimplify_status ret
;
2331 tree index_type
= TREE_TYPE (switch_expr
);
2332 if (index_type
== NULL_TREE
)
2333 index_type
= TREE_TYPE (SWITCH_COND (switch_expr
));
2335 ret
= gimplify_expr (&SWITCH_COND (switch_expr
), pre_p
, NULL
, is_gimple_val
,
2337 if (ret
== GS_ERROR
|| ret
== GS_UNHANDLED
)
2340 if (SWITCH_BODY (switch_expr
))
2343 vec
<tree
> saved_labels
;
2344 hash_set
<tree
> *saved_live_switch_vars
= NULL
;
2345 tree default_case
= NULL_TREE
;
2346 gswitch
*switch_stmt
;
2348 /* Save old labels, get new ones from body, then restore the old
2349 labels. Save all the things from the switch body to append after. */
2350 saved_labels
= gimplify_ctxp
->case_labels
;
2351 gimplify_ctxp
->case_labels
.create (8);
2353 /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR. */
2354 saved_live_switch_vars
= gimplify_ctxp
->live_switch_vars
;
2355 tree_code body_type
= TREE_CODE (SWITCH_BODY (switch_expr
));
2356 if (body_type
== BIND_EXPR
|| body_type
== STATEMENT_LIST
)
2357 gimplify_ctxp
->live_switch_vars
= new hash_set
<tree
> (4);
2359 gimplify_ctxp
->live_switch_vars
= NULL
;
2361 bool old_in_switch_expr
= gimplify_ctxp
->in_switch_expr
;
2362 gimplify_ctxp
->in_switch_expr
= true;
2364 gimplify_stmt (&SWITCH_BODY (switch_expr
), &switch_body_seq
);
2366 gimplify_ctxp
->in_switch_expr
= old_in_switch_expr
;
2367 maybe_warn_switch_unreachable (switch_body_seq
);
2368 maybe_warn_implicit_fallthrough (switch_body_seq
);
2369 /* Only do this for the outermost GIMPLE_SWITCH. */
2370 if (!gimplify_ctxp
->in_switch_expr
)
2371 expand_FALLTHROUGH (&switch_body_seq
);
2373 labels
= gimplify_ctxp
->case_labels
;
2374 gimplify_ctxp
->case_labels
= saved_labels
;
2376 if (gimplify_ctxp
->live_switch_vars
)
2378 gcc_assert (gimplify_ctxp
->live_switch_vars
->elements () == 0);
2379 delete gimplify_ctxp
->live_switch_vars
;
2381 gimplify_ctxp
->live_switch_vars
= saved_live_switch_vars
;
2383 preprocess_case_label_vec_for_gimple (labels
, index_type
,
2386 bool add_bind
= false;
2389 glabel
*new_default
;
2392 = build_case_label (NULL_TREE
, NULL_TREE
,
2393 create_artificial_label (UNKNOWN_LOCATION
));
2394 if (old_in_switch_expr
)
2396 SWITCH_BREAK_LABEL_P (CASE_LABEL (default_case
)) = 1;
2399 new_default
= gimple_build_label (CASE_LABEL (default_case
));
2400 gimplify_seq_add_stmt (&switch_body_seq
, new_default
);
2402 else if (old_in_switch_expr
)
2404 gimple
*last
= gimple_seq_last_stmt (switch_body_seq
);
2405 if (last
&& gimple_code (last
) == GIMPLE_LABEL
)
2407 tree label
= gimple_label_label (as_a
<glabel
*> (last
));
2408 if (SWITCH_BREAK_LABEL_P (label
))
2413 switch_stmt
= gimple_build_switch (SWITCH_COND (switch_expr
),
2414 default_case
, labels
);
2415 /* For the benefit of -Wimplicit-fallthrough, if switch_body_seq
2416 ends with a GIMPLE_LABEL holding SWITCH_BREAK_LABEL_P LABEL_DECL,
2417 wrap the GIMPLE_SWITCH up to that GIMPLE_LABEL into a GIMPLE_BIND,
2418 so that we can easily find the start and end of the switch
2422 gimple_seq bind_body
= NULL
;
2423 gimplify_seq_add_stmt (&bind_body
, switch_stmt
);
2424 gimple_seq_add_seq (&bind_body
, switch_body_seq
);
2425 gbind
*bind
= gimple_build_bind (NULL_TREE
, bind_body
, NULL_TREE
);
2426 gimple_set_location (bind
, EXPR_LOCATION (switch_expr
));
2427 gimplify_seq_add_stmt (pre_p
, bind
);
2431 gimplify_seq_add_stmt (pre_p
, switch_stmt
);
2432 gimplify_seq_add_seq (pre_p
, switch_body_seq
);
2442 /* Gimplify the LABEL_EXPR pointed to by EXPR_P. */
2444 static enum gimplify_status
2445 gimplify_label_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2447 gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p
))
2448 == current_function_decl
);
2450 tree label
= LABEL_EXPR_LABEL (*expr_p
);
2451 glabel
*label_stmt
= gimple_build_label (label
);
2452 gimple_set_location (label_stmt
, EXPR_LOCATION (*expr_p
));
2453 gimplify_seq_add_stmt (pre_p
, label_stmt
);
2455 if (lookup_attribute ("cold", DECL_ATTRIBUTES (label
)))
2456 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_COLD_LABEL
,
2458 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (label
)))
2459 gimple_seq_add_stmt (pre_p
, gimple_build_predict (PRED_HOT_LABEL
,
2465 /* Gimplify the CASE_LABEL_EXPR pointed to by EXPR_P. */
2467 static enum gimplify_status
2468 gimplify_case_label_expr (tree
*expr_p
, gimple_seq
*pre_p
)
2470 struct gimplify_ctx
*ctxp
;
2473 /* Invalid programs can play Duff's Device type games with, for example,
2474 #pragma omp parallel. At least in the C front end, we don't
2475 detect such invalid branches until after gimplification, in the
2476 diagnose_omp_blocks pass. */
2477 for (ctxp
= gimplify_ctxp
; ; ctxp
= ctxp
->prev_context
)
2478 if (ctxp
->case_labels
.exists ())
2481 label_stmt
= gimple_build_label (CASE_LABEL (*expr_p
));
2482 gimple_set_location (label_stmt
, EXPR_LOCATION (*expr_p
));
2483 ctxp
->case_labels
.safe_push (*expr_p
);
2484 gimplify_seq_add_stmt (pre_p
, label_stmt
);
2489 /* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first
2493 build_and_jump (tree
*label_p
)
2495 if (label_p
== NULL
)
2496 /* If there's nowhere to jump, just fall through. */
2499 if (*label_p
== NULL_TREE
)
2501 tree label
= create_artificial_label (UNKNOWN_LOCATION
);
2505 return build1 (GOTO_EXPR
, void_type_node
, *label_p
);
2508 /* Gimplify an EXIT_EXPR by converting to a GOTO_EXPR inside a COND_EXPR.
2509 This also involves building a label to jump to and communicating it to
2510 gimplify_loop_expr through gimplify_ctxp->exit_label. */
2512 static enum gimplify_status
2513 gimplify_exit_expr (tree
*expr_p
)
2515 tree cond
= TREE_OPERAND (*expr_p
, 0);
2518 expr
= build_and_jump (&gimplify_ctxp
->exit_label
);
2519 expr
= build3 (COND_EXPR
, void_type_node
, cond
, expr
, NULL_TREE
);
2525 /* *EXPR_P is a COMPONENT_REF being used as an rvalue. If its type is
2526 different from its canonical type, wrap the whole thing inside a
2527 NOP_EXPR and force the type of the COMPONENT_REF to be the canonical
2530 The canonical type of a COMPONENT_REF is the type of the field being
2531 referenced--unless the field is a bit-field which can be read directly
2532 in a smaller mode, in which case the canonical type is the
2533 sign-appropriate type corresponding to that mode. */
2536 canonicalize_component_ref (tree
*expr_p
)
2538 tree expr
= *expr_p
;
2541 gcc_assert (TREE_CODE (expr
) == COMPONENT_REF
);
2543 if (INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
2544 type
= TREE_TYPE (get_unwidened (expr
, NULL_TREE
));
2546 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
2548 /* One could argue that all the stuff below is not necessary for
2549 the non-bitfield case and declare it a FE error if type
2550 adjustment would be needed. */
2551 if (TREE_TYPE (expr
) != type
)
2553 #ifdef ENABLE_TYPES_CHECKING
2554 tree old_type
= TREE_TYPE (expr
);
2558 /* We need to preserve qualifiers and propagate them from
2560 type_quals
= TYPE_QUALS (type
)
2561 | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr
, 0)));
2562 if (TYPE_QUALS (type
) != type_quals
)
2563 type
= build_qualified_type (TYPE_MAIN_VARIANT (type
), type_quals
);
2565 /* Set the type of the COMPONENT_REF to the underlying type. */
2566 TREE_TYPE (expr
) = type
;
2568 #ifdef ENABLE_TYPES_CHECKING
2569 /* It is now a FE error, if the conversion from the canonical
2570 type to the original expression type is not useless. */
2571 gcc_assert (useless_type_conversion_p (old_type
, type
));
2576 /* If a NOP conversion is changing a pointer to array of foo to a pointer
2577 to foo, embed that change in the ADDR_EXPR by converting
2582 where L is the lower bound. For simplicity, only do this for constant
2584 The constraint is that the type of &array[L] is trivially convertible
2588 canonicalize_addr_expr (tree
*expr_p
)
2590 tree expr
= *expr_p
;
2591 tree addr_expr
= TREE_OPERAND (expr
, 0);
2592 tree datype
, ddatype
, pddatype
;
2594 /* We simplify only conversions from an ADDR_EXPR to a pointer type. */
2595 if (!POINTER_TYPE_P (TREE_TYPE (expr
))
2596 || TREE_CODE (addr_expr
) != ADDR_EXPR
)
2599 /* The addr_expr type should be a pointer to an array. */
2600 datype
= TREE_TYPE (TREE_TYPE (addr_expr
));
2601 if (TREE_CODE (datype
) != ARRAY_TYPE
)
2604 /* The pointer to element type shall be trivially convertible to
2605 the expression pointer type. */
2606 ddatype
= TREE_TYPE (datype
);
2607 pddatype
= build_pointer_type (ddatype
);
2608 if (!useless_type_conversion_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr
)),
2612 /* The lower bound and element sizes must be constant. */
2613 if (!TYPE_SIZE_UNIT (ddatype
)
2614 || TREE_CODE (TYPE_SIZE_UNIT (ddatype
)) != INTEGER_CST
2615 || !TYPE_DOMAIN (datype
) || !TYPE_MIN_VALUE (TYPE_DOMAIN (datype
))
2616 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (datype
))) != INTEGER_CST
)
2619 /* All checks succeeded. Build a new node to merge the cast. */
2620 *expr_p
= build4 (ARRAY_REF
, ddatype
, TREE_OPERAND (addr_expr
, 0),
2621 TYPE_MIN_VALUE (TYPE_DOMAIN (datype
)),
2622 NULL_TREE
, NULL_TREE
);
2623 *expr_p
= build1 (ADDR_EXPR
, pddatype
, *expr_p
);
2625 /* We can have stripped a required restrict qualifier above. */
2626 if (!useless_type_conversion_p (TREE_TYPE (expr
), TREE_TYPE (*expr_p
)))
2627 *expr_p
= fold_convert (TREE_TYPE (expr
), *expr_p
);
2630 /* *EXPR_P is a NOP_EXPR or CONVERT_EXPR. Remove it and/or other conversions
2631 underneath as appropriate. */
2633 static enum gimplify_status
2634 gimplify_conversion (tree
*expr_p
)
2636 location_t loc
= EXPR_LOCATION (*expr_p
);
2637 gcc_assert (CONVERT_EXPR_P (*expr_p
));
2639 /* Then strip away all but the outermost conversion. */
2640 STRIP_SIGN_NOPS (TREE_OPERAND (*expr_p
, 0));
2642 /* And remove the outermost conversion if it's useless. */
2643 if (tree_ssa_useless_type_conversion (*expr_p
))
2644 *expr_p
= TREE_OPERAND (*expr_p
, 0);
2646 /* If we still have a conversion at the toplevel,
2647 then canonicalize some constructs. */
2648 if (CONVERT_EXPR_P (*expr_p
))
2650 tree sub
= TREE_OPERAND (*expr_p
, 0);
2652 /* If a NOP conversion is changing the type of a COMPONENT_REF
2653 expression, then canonicalize its type now in order to expose more
2654 redundant conversions. */
2655 if (TREE_CODE (sub
) == COMPONENT_REF
)
2656 canonicalize_component_ref (&TREE_OPERAND (*expr_p
, 0));
2658 /* If a NOP conversion is changing a pointer to array of foo
2659 to a pointer to foo, embed that change in the ADDR_EXPR. */
2660 else if (TREE_CODE (sub
) == ADDR_EXPR
)
2661 canonicalize_addr_expr (expr_p
);
2664 /* If we have a conversion to a non-register type force the
2665 use of a VIEW_CONVERT_EXPR instead. */
2666 if (CONVERT_EXPR_P (*expr_p
) && !is_gimple_reg_type (TREE_TYPE (*expr_p
)))
2667 *expr_p
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (*expr_p
),
2668 TREE_OPERAND (*expr_p
, 0));
2670 /* Canonicalize CONVERT_EXPR to NOP_EXPR. */
2671 if (TREE_CODE (*expr_p
) == CONVERT_EXPR
)
2672 TREE_SET_CODE (*expr_p
, NOP_EXPR
);
2677 /* Gimplify a VAR_DECL or PARM_DECL. Return GS_OK if we expanded a
2678 DECL_VALUE_EXPR, and it's worth re-examining things. */
2680 static enum gimplify_status
2681 gimplify_var_or_parm_decl (tree
*expr_p
)
2683 tree decl
= *expr_p
;
2685 /* ??? If this is a local variable, and it has not been seen in any
2686 outer BIND_EXPR, then it's probably the result of a duplicate
2687 declaration, for which we've already issued an error. It would
2688 be really nice if the front end wouldn't leak these at all.
2689 Currently the only known culprit is C++ destructors, as seen
2690 in g++.old-deja/g++.jason/binding.C. */
2692 && !DECL_SEEN_IN_BIND_EXPR_P (decl
)
2693 && !TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
)
2694 && decl_function_context (decl
) == current_function_decl
)
2696 gcc_assert (seen_error ());
2700 /* When within an OMP context, notice uses of variables. */
2701 if (gimplify_omp_ctxp
&& omp_notice_variable (gimplify_omp_ctxp
, decl
, true))
2704 /* If the decl is an alias for another expression, substitute it now. */
2705 if (DECL_HAS_VALUE_EXPR_P (decl
))
2707 *expr_p
= unshare_expr (DECL_VALUE_EXPR (decl
));
2714 /* Recalculate the value of the TREE_SIDE_EFFECTS flag for T. */
2717 recalculate_side_effects (tree t
)
2719 enum tree_code code
= TREE_CODE (t
);
2720 int len
= TREE_OPERAND_LENGTH (t
);
2723 switch (TREE_CODE_CLASS (code
))
2725 case tcc_expression
:
2731 case PREDECREMENT_EXPR
:
2732 case PREINCREMENT_EXPR
:
2733 case POSTDECREMENT_EXPR
:
2734 case POSTINCREMENT_EXPR
:
2735 /* All of these have side-effects, no matter what their
2744 case tcc_comparison
: /* a comparison expression */
2745 case tcc_unary
: /* a unary arithmetic expression */
2746 case tcc_binary
: /* a binary arithmetic expression */
2747 case tcc_reference
: /* a reference */
2748 case tcc_vl_exp
: /* a function call */
2749 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
2750 for (i
= 0; i
< len
; ++i
)
2752 tree op
= TREE_OPERAND (t
, i
);
2753 if (op
&& TREE_SIDE_EFFECTS (op
))
2754 TREE_SIDE_EFFECTS (t
) = 1;
2759 /* No side-effects. */
2767 /* Gimplify the COMPONENT_REF, ARRAY_REF, REALPART_EXPR or IMAGPART_EXPR
2771 : min_lval '[' val ']'
2773 | compound_lval '[' val ']'
2774 | compound_lval '.' ID
2776 This is not part of the original SIMPLE definition, which separates
2777 array and member references, but it seems reasonable to handle them
2778 together. Also, this way we don't run into problems with union
2779 aliasing; gcc requires that for accesses through a union to alias, the
2780 union reference must be explicit, which was not always the case when we
2781 were splitting up array and member refs.
2783 PRE_P points to the sequence where side effects that must happen before
2784 *EXPR_P should be stored.
2786 POST_P points to the sequence where side effects that must happen after
2787 *EXPR_P should be stored. */
2789 static enum gimplify_status
2790 gimplify_compound_lval (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
2791 fallback_t fallback
)
2794 enum gimplify_status ret
= GS_ALL_DONE
, tret
;
2796 location_t loc
= EXPR_LOCATION (*expr_p
);
2797 tree expr
= *expr_p
;
2799 /* Create a stack of the subexpressions so later we can walk them in
2800 order from inner to outer. */
2801 auto_vec
<tree
, 10> expr_stack
;
2803 /* We can handle anything that get_inner_reference can deal with. */
2804 for (p
= expr_p
; ; p
= &TREE_OPERAND (*p
, 0))
2807 /* Fold INDIRECT_REFs now to turn them into ARRAY_REFs. */
2808 if (TREE_CODE (*p
) == INDIRECT_REF
)
2809 *p
= fold_indirect_ref_loc (loc
, *p
);
2811 if (handled_component_p (*p
))
2813 /* Expand DECL_VALUE_EXPR now. In some cases that may expose
2814 additional COMPONENT_REFs. */
2815 else if ((VAR_P (*p
) || TREE_CODE (*p
) == PARM_DECL
)
2816 && gimplify_var_or_parm_decl (p
) == GS_OK
)
2821 expr_stack
.safe_push (*p
);
2824 gcc_assert (expr_stack
.length ());
2826 /* Now EXPR_STACK is a stack of pointers to all the refs we've
2827 walked through and P points to the innermost expression.
2829 Java requires that we elaborated nodes in source order. That
2830 means we must gimplify the inner expression followed by each of
2831 the indices, in order. But we can't gimplify the inner
2832 expression until we deal with any variable bounds, sizes, or
2833 positions in order to deal with PLACEHOLDER_EXPRs.
2835 So we do this in three steps. First we deal with the annotations
2836 for any variables in the components, then we gimplify the base,
2837 then we gimplify any indices, from left to right. */
2838 for (i
= expr_stack
.length () - 1; i
>= 0; i
--)
2840 tree t
= expr_stack
[i
];
2842 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
2844 /* Gimplify the low bound and element type size and put them into
2845 the ARRAY_REF. If these values are set, they have already been
2847 if (TREE_OPERAND (t
, 2) == NULL_TREE
)
2849 tree low
= unshare_expr (array_ref_low_bound (t
));
2850 if (!is_gimple_min_invariant (low
))
2852 TREE_OPERAND (t
, 2) = low
;
2853 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
,
2854 post_p
, is_gimple_reg
,
2856 ret
= MIN (ret
, tret
);
2861 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
, post_p
,
2862 is_gimple_reg
, fb_rvalue
);
2863 ret
= MIN (ret
, tret
);
2866 if (TREE_OPERAND (t
, 3) == NULL_TREE
)
2868 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0)));
2869 tree elmt_size
= unshare_expr (array_ref_element_size (t
));
2870 tree factor
= size_int (TYPE_ALIGN_UNIT (elmt_type
));
2872 /* Divide the element size by the alignment of the element
2875 = size_binop_loc (loc
, EXACT_DIV_EXPR
, elmt_size
, factor
);
2877 if (!is_gimple_min_invariant (elmt_size
))
2879 TREE_OPERAND (t
, 3) = elmt_size
;
2880 tret
= gimplify_expr (&TREE_OPERAND (t
, 3), pre_p
,
2881 post_p
, is_gimple_reg
,
2883 ret
= MIN (ret
, tret
);
2888 tret
= gimplify_expr (&TREE_OPERAND (t
, 3), pre_p
, post_p
,
2889 is_gimple_reg
, fb_rvalue
);
2890 ret
= MIN (ret
, tret
);
2893 else if (TREE_CODE (t
) == COMPONENT_REF
)
2895 /* Set the field offset into T and gimplify it. */
2896 if (TREE_OPERAND (t
, 2) == NULL_TREE
)
2898 tree offset
= unshare_expr (component_ref_field_offset (t
));
2899 tree field
= TREE_OPERAND (t
, 1);
2901 = size_int (DECL_OFFSET_ALIGN (field
) / BITS_PER_UNIT
);
2903 /* Divide the offset by its alignment. */
2904 offset
= size_binop_loc (loc
, EXACT_DIV_EXPR
, offset
, factor
);
2906 if (!is_gimple_min_invariant (offset
))
2908 TREE_OPERAND (t
, 2) = offset
;
2909 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
,
2910 post_p
, is_gimple_reg
,
2912 ret
= MIN (ret
, tret
);
2917 tret
= gimplify_expr (&TREE_OPERAND (t
, 2), pre_p
, post_p
,
2918 is_gimple_reg
, fb_rvalue
);
2919 ret
= MIN (ret
, tret
);
2924 /* Step 2 is to gimplify the base expression. Make sure lvalue is set
2925 so as to match the min_lval predicate. Failure to do so may result
2926 in the creation of large aggregate temporaries. */
2927 tret
= gimplify_expr (p
, pre_p
, post_p
, is_gimple_min_lval
,
2928 fallback
| fb_lvalue
);
2929 ret
= MIN (ret
, tret
);
2931 /* And finally, the indices and operands of ARRAY_REF. During this
2932 loop we also remove any useless conversions. */
2933 for (; expr_stack
.length () > 0; )
2935 tree t
= expr_stack
.pop ();
2937 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
2939 /* Gimplify the dimension. */
2940 if (!is_gimple_min_invariant (TREE_OPERAND (t
, 1)))
2942 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), pre_p
, post_p
,
2943 is_gimple_val
, fb_rvalue
);
2944 ret
= MIN (ret
, tret
);
2948 STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t
, 0));
2950 /* The innermost expression P may have originally had
2951 TREE_SIDE_EFFECTS set which would have caused all the outer
2952 expressions in *EXPR_P leading to P to also have had
2953 TREE_SIDE_EFFECTS set. */
2954 recalculate_side_effects (t
);
2957 /* If the outermost expression is a COMPONENT_REF, canonicalize its type. */
2958 if ((fallback
& fb_rvalue
) && TREE_CODE (*expr_p
) == COMPONENT_REF
)
2960 canonicalize_component_ref (expr_p
);
2963 expr_stack
.release ();
2965 gcc_assert (*expr_p
== expr
|| ret
!= GS_ALL_DONE
);
2970 /* Gimplify the self modifying expression pointed to by EXPR_P
2973 PRE_P points to the list where side effects that must happen before
2974 *EXPR_P should be stored.
2976 POST_P points to the list where side effects that must happen after
2977 *EXPR_P should be stored.
2979 WANT_VALUE is nonzero iff we want to use the value of this expression
2980 in another expression.
2982 ARITH_TYPE is the type the computation should be performed in. */
2984 enum gimplify_status
2985 gimplify_self_mod_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
2986 bool want_value
, tree arith_type
)
2988 enum tree_code code
;
2989 tree lhs
, lvalue
, rhs
, t1
;
2990 gimple_seq post
= NULL
, *orig_post_p
= post_p
;
2992 enum tree_code arith_code
;
2993 enum gimplify_status ret
;
2994 location_t loc
= EXPR_LOCATION (*expr_p
);
2996 code
= TREE_CODE (*expr_p
);
2998 gcc_assert (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
2999 || code
== PREINCREMENT_EXPR
|| code
== PREDECREMENT_EXPR
);
3001 /* Prefix or postfix? */
3002 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
3003 /* Faster to treat as prefix if result is not used. */
3004 postfix
= want_value
;
3008 /* For postfix, make sure the inner expression's post side effects
3009 are executed after side effects from this expression. */
3013 /* Add or subtract? */
3014 if (code
== PREINCREMENT_EXPR
|| code
== POSTINCREMENT_EXPR
)
3015 arith_code
= PLUS_EXPR
;
3017 arith_code
= MINUS_EXPR
;
3019 /* Gimplify the LHS into a GIMPLE lvalue. */
3020 lvalue
= TREE_OPERAND (*expr_p
, 0);
3021 ret
= gimplify_expr (&lvalue
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
3022 if (ret
== GS_ERROR
)
3025 /* Extract the operands to the arithmetic operation. */
3027 rhs
= TREE_OPERAND (*expr_p
, 1);
3029 /* For postfix operator, we evaluate the LHS to an rvalue and then use
3030 that as the result value and in the postqueue operation. */
3033 ret
= gimplify_expr (&lhs
, pre_p
, post_p
, is_gimple_val
, fb_rvalue
);
3034 if (ret
== GS_ERROR
)
3037 lhs
= get_initialized_tmp_var (lhs
, pre_p
, NULL
);
3040 /* For POINTERs increment, use POINTER_PLUS_EXPR. */
3041 if (POINTER_TYPE_P (TREE_TYPE (lhs
)))
3043 rhs
= convert_to_ptrofftype_loc (loc
, rhs
);
3044 if (arith_code
== MINUS_EXPR
)
3045 rhs
= fold_build1_loc (loc
, NEGATE_EXPR
, TREE_TYPE (rhs
), rhs
);
3046 t1
= fold_build2 (POINTER_PLUS_EXPR
, TREE_TYPE (*expr_p
), lhs
, rhs
);
3049 t1
= fold_convert (TREE_TYPE (*expr_p
),
3050 fold_build2 (arith_code
, arith_type
,
3051 fold_convert (arith_type
, lhs
),
3052 fold_convert (arith_type
, rhs
)));
3056 gimplify_assign (lvalue
, t1
, pre_p
);
3057 gimplify_seq_add_seq (orig_post_p
, post
);
3063 *expr_p
= build2 (MODIFY_EXPR
, TREE_TYPE (lvalue
), lvalue
, t1
);
3068 /* If *EXPR_P has a variable sized type, wrap it in a WITH_SIZE_EXPR. */
3071 maybe_with_size_expr (tree
*expr_p
)
3073 tree expr
= *expr_p
;
3074 tree type
= TREE_TYPE (expr
);
3077 /* If we've already wrapped this or the type is error_mark_node, we can't do
3079 if (TREE_CODE (expr
) == WITH_SIZE_EXPR
3080 || type
== error_mark_node
)
3083 /* If the size isn't known or is a constant, we have nothing to do. */
3084 size
= TYPE_SIZE_UNIT (type
);
3085 if (!size
|| poly_int_tree_p (size
))
3088 /* Otherwise, make a WITH_SIZE_EXPR. */
3089 size
= unshare_expr (size
);
3090 size
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, expr
);
3091 *expr_p
= build2 (WITH_SIZE_EXPR
, type
, expr
, size
);
3094 /* Helper for gimplify_call_expr. Gimplify a single argument *ARG_P
3095 Store any side-effects in PRE_P. CALL_LOCATION is the location of
3096 the CALL_EXPR. If ALLOW_SSA is set the actual parameter may be
3097 gimplified to an SSA name. */
3099 enum gimplify_status
3100 gimplify_arg (tree
*arg_p
, gimple_seq
*pre_p
, location_t call_location
,
3103 bool (*test
) (tree
);
3106 /* In general, we allow lvalues for function arguments to avoid
3107 extra overhead of copying large aggregates out of even larger
3108 aggregates into temporaries only to copy the temporaries to
3109 the argument list. Make optimizers happy by pulling out to
3110 temporaries those types that fit in registers. */
3111 if (is_gimple_reg_type (TREE_TYPE (*arg_p
)))
3112 test
= is_gimple_val
, fb
= fb_rvalue
;
3115 test
= is_gimple_lvalue
, fb
= fb_either
;
3116 /* Also strip a TARGET_EXPR that would force an extra copy. */
3117 if (TREE_CODE (*arg_p
) == TARGET_EXPR
)
3119 tree init
= TARGET_EXPR_INITIAL (*arg_p
);
3121 && !VOID_TYPE_P (TREE_TYPE (init
)))
3126 /* If this is a variable sized type, we must remember the size. */
3127 maybe_with_size_expr (arg_p
);
3129 /* FIXME diagnostics: This will mess up gcc.dg/Warray-bounds.c. */
3130 /* Make sure arguments have the same location as the function call
3132 protected_set_expr_location (*arg_p
, call_location
);
3134 /* There is a sequence point before a function call. Side effects in
3135 the argument list must occur before the actual call. So, when
3136 gimplifying arguments, force gimplify_expr to use an internal
3137 post queue which is then appended to the end of PRE_P. */
3138 return gimplify_expr (arg_p
, pre_p
, NULL
, test
, fb
, allow_ssa
);
3141 /* Don't fold inside offloading or taskreg regions: it can break code by
3142 adding decl references that weren't in the source. We'll do it during
3143 omplower pass instead. */
3146 maybe_fold_stmt (gimple_stmt_iterator
*gsi
)
3148 struct gimplify_omp_ctx
*ctx
;
3149 for (ctx
= gimplify_omp_ctxp
; ctx
; ctx
= ctx
->outer_context
)
3150 if ((ctx
->region_type
& (ORT_TARGET
| ORT_PARALLEL
| ORT_TASK
)) != 0)
3152 return fold_stmt (gsi
);
3155 /* Gimplify the CALL_EXPR node *EXPR_P into the GIMPLE sequence PRE_P.
3156 WANT_VALUE is true if the result of the call is desired. */
3158 static enum gimplify_status
3159 gimplify_call_expr (tree
*expr_p
, gimple_seq
*pre_p
, bool want_value
)
3161 tree fndecl
, parms
, p
, fnptrtype
;
3162 enum gimplify_status ret
;
3165 bool builtin_va_start_p
= false;
3166 location_t loc
= EXPR_LOCATION (*expr_p
);
3168 gcc_assert (TREE_CODE (*expr_p
) == CALL_EXPR
);
3170 /* For reliable diagnostics during inlining, it is necessary that
3171 every call_expr be annotated with file and line. */
3172 if (! EXPR_HAS_LOCATION (*expr_p
))
3173 SET_EXPR_LOCATION (*expr_p
, input_location
);
3175 /* Gimplify internal functions created in the FEs. */
3176 if (CALL_EXPR_FN (*expr_p
) == NULL_TREE
)
3181 nargs
= call_expr_nargs (*expr_p
);
3182 enum internal_fn ifn
= CALL_EXPR_IFN (*expr_p
);
3183 auto_vec
<tree
> vargs (nargs
);
3185 for (i
= 0; i
< nargs
; i
++)
3187 gimplify_arg (&CALL_EXPR_ARG (*expr_p
, i
), pre_p
,
3188 EXPR_LOCATION (*expr_p
));
3189 vargs
.quick_push (CALL_EXPR_ARG (*expr_p
, i
));
3192 gcall
*call
= gimple_build_call_internal_vec (ifn
, vargs
);
3193 gimple_call_set_nothrow (call
, TREE_NOTHROW (*expr_p
));
3194 gimplify_seq_add_stmt (pre_p
, call
);
3198 /* This may be a call to a builtin function.
3200 Builtin function calls may be transformed into different
3201 (and more efficient) builtin function calls under certain
3202 circumstances. Unfortunately, gimplification can muck things
3203 up enough that the builtin expanders are not aware that certain
3204 transformations are still valid.
3206 So we attempt transformation/gimplification of the call before
3207 we gimplify the CALL_EXPR. At this time we do not manage to
3208 transform all calls in the same manner as the expanders do, but
3209 we do transform most of them. */
3210 fndecl
= get_callee_fndecl (*expr_p
);
3212 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
3213 switch (DECL_FUNCTION_CODE (fndecl
))
3215 CASE_BUILT_IN_ALLOCA
:
3216 /* If the call has been built for a variable-sized object, then we
3217 want to restore the stack level when the enclosing BIND_EXPR is
3218 exited to reclaim the allocated space; otherwise, we precisely
3219 need to do the opposite and preserve the latest stack level. */
3220 if (CALL_ALLOCA_FOR_VAR_P (*expr_p
))
3221 gimplify_ctxp
->save_stack
= true;
3223 gimplify_ctxp
->keep_stack
= true;
3226 case BUILT_IN_VA_START
:
3228 builtin_va_start_p
= TRUE
;
3229 if (call_expr_nargs (*expr_p
) < 2)
3231 error ("too few arguments to function %<va_start%>");
3232 *expr_p
= build_empty_stmt (EXPR_LOCATION (*expr_p
));
3236 if (fold_builtin_next_arg (*expr_p
, true))
3238 *expr_p
= build_empty_stmt (EXPR_LOCATION (*expr_p
));
3247 if (fndecl
&& DECL_BUILT_IN (fndecl
))
3249 tree new_tree
= fold_call_expr (input_location
, *expr_p
, !want_value
);
3250 if (new_tree
&& new_tree
!= *expr_p
)
3252 /* There was a transformation of this call which computes the
3253 same value, but in a more efficient way. Return and try
3260 /* Remember the original function pointer type. */
3261 fnptrtype
= TREE_TYPE (CALL_EXPR_FN (*expr_p
));
3263 /* There is a sequence point before the call, so any side effects in
3264 the calling expression must occur before the actual call. Force
3265 gimplify_expr to use an internal post queue. */
3266 ret
= gimplify_expr (&CALL_EXPR_FN (*expr_p
), pre_p
, NULL
,
3267 is_gimple_call_addr
, fb_rvalue
);
3269 nargs
= call_expr_nargs (*expr_p
);
3271 /* Get argument types for verification. */
3272 fndecl
= get_callee_fndecl (*expr_p
);
3275 parms
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
3277 parms
= TYPE_ARG_TYPES (TREE_TYPE (fnptrtype
));
3279 if (fndecl
&& DECL_ARGUMENTS (fndecl
))
3280 p
= DECL_ARGUMENTS (fndecl
);
3285 for (i
= 0; i
< nargs
&& p
; i
++, p
= TREE_CHAIN (p
))
3288 /* If the last argument is __builtin_va_arg_pack () and it is not
3289 passed as a named argument, decrease the number of CALL_EXPR
3290 arguments and set instead the CALL_EXPR_VA_ARG_PACK flag. */
3293 && TREE_CODE (CALL_EXPR_ARG (*expr_p
, nargs
- 1)) == CALL_EXPR
)
3295 tree last_arg
= CALL_EXPR_ARG (*expr_p
, nargs
- 1);
3296 tree last_arg_fndecl
= get_callee_fndecl (last_arg
);
3299 && TREE_CODE (last_arg_fndecl
) == FUNCTION_DECL
3300 && DECL_BUILT_IN_CLASS (last_arg_fndecl
) == BUILT_IN_NORMAL
3301 && DECL_FUNCTION_CODE (last_arg_fndecl
) == BUILT_IN_VA_ARG_PACK
)
3303 tree call
= *expr_p
;
3306 *expr_p
= build_call_array_loc (loc
, TREE_TYPE (call
),
3307 CALL_EXPR_FN (call
),
3308 nargs
, CALL_EXPR_ARGP (call
));
3310 /* Copy all CALL_EXPR flags, location and block, except
3311 CALL_EXPR_VA_ARG_PACK flag. */
3312 CALL_EXPR_STATIC_CHAIN (*expr_p
) = CALL_EXPR_STATIC_CHAIN (call
);
3313 CALL_EXPR_TAILCALL (*expr_p
) = CALL_EXPR_TAILCALL (call
);
3314 CALL_EXPR_RETURN_SLOT_OPT (*expr_p
)
3315 = CALL_EXPR_RETURN_SLOT_OPT (call
);
3316 CALL_FROM_THUNK_P (*expr_p
) = CALL_FROM_THUNK_P (call
);
3317 SET_EXPR_LOCATION (*expr_p
, EXPR_LOCATION (call
));
3319 /* Set CALL_EXPR_VA_ARG_PACK. */
3320 CALL_EXPR_VA_ARG_PACK (*expr_p
) = 1;
3324 /* If the call returns twice then after building the CFG the call
3325 argument computations will no longer dominate the call because
3326 we add an abnormal incoming edge to the call. So do not use SSA
3328 bool returns_twice
= call_expr_flags (*expr_p
) & ECF_RETURNS_TWICE
;
3330 /* Gimplify the function arguments. */
3333 for (i
= (PUSH_ARGS_REVERSED
? nargs
- 1 : 0);
3334 PUSH_ARGS_REVERSED
? i
>= 0 : i
< nargs
;
3335 PUSH_ARGS_REVERSED
? i
-- : i
++)
3337 enum gimplify_status t
;
3339 /* Avoid gimplifying the second argument to va_start, which needs to
3340 be the plain PARM_DECL. */
3341 if ((i
!= 1) || !builtin_va_start_p
)
3343 t
= gimplify_arg (&CALL_EXPR_ARG (*expr_p
, i
), pre_p
,
3344 EXPR_LOCATION (*expr_p
), ! returns_twice
);
3352 /* Gimplify the static chain. */
3353 if (CALL_EXPR_STATIC_CHAIN (*expr_p
))
3355 if (fndecl
&& !DECL_STATIC_CHAIN (fndecl
))
3356 CALL_EXPR_STATIC_CHAIN (*expr_p
) = NULL
;
3359 enum gimplify_status t
;
3360 t
= gimplify_arg (&CALL_EXPR_STATIC_CHAIN (*expr_p
), pre_p
,
3361 EXPR_LOCATION (*expr_p
), ! returns_twice
);
3367 /* Verify the function result. */
3368 if (want_value
&& fndecl
3369 && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fnptrtype
))))
3371 error_at (loc
, "using result of function returning %<void%>");
3375 /* Try this again in case gimplification exposed something. */
3376 if (ret
!= GS_ERROR
)
3378 tree new_tree
= fold_call_expr (input_location
, *expr_p
, !want_value
);
3380 if (new_tree
&& new_tree
!= *expr_p
)
3382 /* There was a transformation of this call which computes the
3383 same value, but in a more efficient way. Return and try
3391 *expr_p
= error_mark_node
;
3395 /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
3396 decl. This allows us to eliminate redundant or useless
3397 calls to "const" functions. */
3398 if (TREE_CODE (*expr_p
) == CALL_EXPR
)
3400 int flags
= call_expr_flags (*expr_p
);
3401 if (flags
& (ECF_CONST
| ECF_PURE
)
3402 /* An infinite loop is considered a side effect. */
3403 && !(flags
& (ECF_LOOPING_CONST_OR_PURE
)))
3404 TREE_SIDE_EFFECTS (*expr_p
) = 0;
3407 /* If the value is not needed by the caller, emit a new GIMPLE_CALL
3408 and clear *EXPR_P. Otherwise, leave *EXPR_P in its gimplified
3409 form and delegate the creation of a GIMPLE_CALL to
3410 gimplify_modify_expr. This is always possible because when
3411 WANT_VALUE is true, the caller wants the result of this call into
3412 a temporary, which means that we will emit an INIT_EXPR in
3413 internal_get_tmp_var which will then be handled by
3414 gimplify_modify_expr. */
3417 /* The CALL_EXPR in *EXPR_P is already in GIMPLE form, so all we
3418 have to do is replicate it as a GIMPLE_CALL tuple. */
3419 gimple_stmt_iterator gsi
;
3420 call
= gimple_build_call_from_tree (*expr_p
, fnptrtype
);
3421 notice_special_calls (call
);
3422 gimplify_seq_add_stmt (pre_p
, call
);
3423 gsi
= gsi_last (*pre_p
);
3424 maybe_fold_stmt (&gsi
);
3425 *expr_p
= NULL_TREE
;
3428 /* Remember the original function type. */
3429 CALL_EXPR_FN (*expr_p
) = build1 (NOP_EXPR
, fnptrtype
,
3430 CALL_EXPR_FN (*expr_p
));
3435 /* Handle shortcut semantics in the predicate operand of a COND_EXPR by
3436 rewriting it into multiple COND_EXPRs, and possibly GOTO_EXPRs.
3438 TRUE_LABEL_P and FALSE_LABEL_P point to the labels to jump to if the
3439 condition is true or false, respectively. If null, we should generate
3440 our own to skip over the evaluation of this specific expression.
3442 LOCUS is the source location of the COND_EXPR.
3444 This function is the tree equivalent of do_jump.
3446 shortcut_cond_r should only be called by shortcut_cond_expr. */
3449 shortcut_cond_r (tree pred
, tree
*true_label_p
, tree
*false_label_p
,
3452 tree local_label
= NULL_TREE
;
3453 tree t
, expr
= NULL
;
3455 /* OK, it's not a simple case; we need to pull apart the COND_EXPR to
3456 retain the shortcut semantics. Just insert the gotos here;
3457 shortcut_cond_expr will append the real blocks later. */
3458 if (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
3460 location_t new_locus
;
3462 /* Turn if (a && b) into
3464 if (a); else goto no;
3465 if (b) goto yes; else goto no;
3468 if (false_label_p
== NULL
)
3469 false_label_p
= &local_label
;
3471 /* Keep the original source location on the first 'if'. */
3472 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), NULL
, false_label_p
, locus
);
3473 append_to_statement_list (t
, &expr
);
3475 /* Set the source location of the && on the second 'if'. */
3476 new_locus
= rexpr_location (pred
, locus
);
3477 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
, false_label_p
,
3479 append_to_statement_list (t
, &expr
);
3481 else if (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
3483 location_t new_locus
;
3485 /* Turn if (a || b) into
3488 if (b) goto yes; else goto no;
3491 if (true_label_p
== NULL
)
3492 true_label_p
= &local_label
;
3494 /* Keep the original source location on the first 'if'. */
3495 t
= shortcut_cond_r (TREE_OPERAND (pred
, 0), true_label_p
, NULL
, locus
);
3496 append_to_statement_list (t
, &expr
);
3498 /* Set the source location of the || on the second 'if'. */
3499 new_locus
= rexpr_location (pred
, locus
);
3500 t
= shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
, false_label_p
,
3502 append_to_statement_list (t
, &expr
);
3504 else if (TREE_CODE (pred
) == COND_EXPR
3505 && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred
, 1)))
3506 && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred
, 2))))
3508 location_t new_locus
;
3510 /* As long as we're messing with gotos, turn if (a ? b : c) into
3512 if (b) goto yes; else goto no;
3514 if (c) goto yes; else goto no;
3516 Don't do this if one of the arms has void type, which can happen
3517 in C++ when the arm is throw. */
3519 /* Keep the original source location on the first 'if'. Set the source
3520 location of the ? on the second 'if'. */
3521 new_locus
= rexpr_location (pred
, locus
);
3522 expr
= build3 (COND_EXPR
, void_type_node
, TREE_OPERAND (pred
, 0),
3523 shortcut_cond_r (TREE_OPERAND (pred
, 1), true_label_p
,
3524 false_label_p
, locus
),
3525 shortcut_cond_r (TREE_OPERAND (pred
, 2), true_label_p
,
3526 false_label_p
, new_locus
));
3530 expr
= build3 (COND_EXPR
, void_type_node
, pred
,
3531 build_and_jump (true_label_p
),
3532 build_and_jump (false_label_p
));
3533 SET_EXPR_LOCATION (expr
, locus
);
3538 t
= build1 (LABEL_EXPR
, void_type_node
, local_label
);
3539 append_to_statement_list (t
, &expr
);
3545 /* If EXPR is a GOTO_EXPR, return it. If it is a STATEMENT_LIST, skip
3546 any of its leading DEBUG_BEGIN_STMTS and recurse on the subsequent
3547 statement, if it is the last one. Otherwise, return NULL. */
3550 find_goto (tree expr
)
3555 if (TREE_CODE (expr
) == GOTO_EXPR
)
3558 if (TREE_CODE (expr
) != STATEMENT_LIST
)
3561 tree_stmt_iterator i
= tsi_start (expr
);
3563 while (!tsi_end_p (i
) && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
3566 if (!tsi_one_before_end_p (i
))
3569 return find_goto (tsi_stmt (i
));
3572 /* Same as find_goto, except that it returns NULL if the destination
3573 is not a LABEL_DECL. */
3576 find_goto_label (tree expr
)
3578 tree dest
= find_goto (expr
);
3579 if (dest
&& TREE_CODE (GOTO_DESTINATION (dest
)) == LABEL_DECL
)
3584 /* Given a conditional expression EXPR with short-circuit boolean
3585 predicates using TRUTH_ANDIF_EXPR or TRUTH_ORIF_EXPR, break the
3586 predicate apart into the equivalent sequence of conditionals. */
3589 shortcut_cond_expr (tree expr
)
3591 tree pred
= TREE_OPERAND (expr
, 0);
3592 tree then_
= TREE_OPERAND (expr
, 1);
3593 tree else_
= TREE_OPERAND (expr
, 2);
3594 tree true_label
, false_label
, end_label
, t
;
3596 tree
*false_label_p
;
3597 bool emit_end
, emit_false
, jump_over_else
;
3598 bool then_se
= then_
&& TREE_SIDE_EFFECTS (then_
);
3599 bool else_se
= else_
&& TREE_SIDE_EFFECTS (else_
);
3601 /* First do simple transformations. */
3604 /* If there is no 'else', turn
3607 if (a) if (b) then c. */
3608 while (TREE_CODE (pred
) == TRUTH_ANDIF_EXPR
)
3610 /* Keep the original source location on the first 'if'. */
3611 location_t locus
= EXPR_LOC_OR_LOC (expr
, input_location
);
3612 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
3613 /* Set the source location of the && on the second 'if'. */
3614 if (rexpr_has_location (pred
))
3615 SET_EXPR_LOCATION (expr
, rexpr_location (pred
));
3616 then_
= shortcut_cond_expr (expr
);
3617 then_se
= then_
&& TREE_SIDE_EFFECTS (then_
);
3618 pred
= TREE_OPERAND (pred
, 0);
3619 expr
= build3 (COND_EXPR
, void_type_node
, pred
, then_
, NULL_TREE
);
3620 SET_EXPR_LOCATION (expr
, locus
);
3626 /* If there is no 'then', turn
3629 if (a); else if (b); else d. */
3630 while (TREE_CODE (pred
) == TRUTH_ORIF_EXPR
)
3632 /* Keep the original source location on the first 'if'. */
3633 location_t locus
= EXPR_LOC_OR_LOC (expr
, input_location
);
3634 TREE_OPERAND (expr
, 0) = TREE_OPERAND (pred
, 1);
3635 /* Set the source location of the || on the second 'if'. */
3636 if (rexpr_has_location (pred
))
3637 SET_EXPR_LOCATION (expr
, rexpr_location (pred
));
3638 else_
= shortcut_cond_expr (expr
);
3639 else_se
= else_
&& TREE_SIDE_EFFECTS (else_
);
3640 pred
= TREE_OPERAND (pred
, 0);
3641 expr
= build3 (COND_EXPR
, void_type_node
, pred
, NULL_TREE
, else_
);
3642 SET_EXPR_LOCATION (expr
, locus
);
3646 /* If we're done, great. */
3647 if (TREE_CODE (pred
) != TRUTH_ANDIF_EXPR
3648 && TREE_CODE (pred
) != TRUTH_ORIF_EXPR
)
3651 /* Otherwise we need to mess with gotos. Change
3654 if (a); else goto no;
3657 and recursively gimplify the condition. */
3659 true_label
= false_label
= end_label
= NULL_TREE
;
3661 /* If our arms just jump somewhere, hijack those labels so we don't
3662 generate jumps to jumps. */
3664 if (tree then_goto
= find_goto_label (then_
))
3666 true_label
= GOTO_DESTINATION (then_goto
);
3671 if (tree else_goto
= find_goto_label (else_
))
3673 false_label
= GOTO_DESTINATION (else_goto
);
3678 /* If we aren't hijacking a label for the 'then' branch, it falls through. */
3680 true_label_p
= &true_label
;
3682 true_label_p
= NULL
;
3684 /* The 'else' branch also needs a label if it contains interesting code. */
3685 if (false_label
|| else_se
)
3686 false_label_p
= &false_label
;
3688 false_label_p
= NULL
;
3690 /* If there was nothing else in our arms, just forward the label(s). */
3691 if (!then_se
&& !else_se
)
3692 return shortcut_cond_r (pred
, true_label_p
, false_label_p
,
3693 EXPR_LOC_OR_LOC (expr
, input_location
));
3695 /* If our last subexpression already has a terminal label, reuse it. */
3697 t
= expr_last (else_
);
3699 t
= expr_last (then_
);
3702 if (t
&& TREE_CODE (t
) == LABEL_EXPR
)
3703 end_label
= LABEL_EXPR_LABEL (t
);
3705 /* If we don't care about jumping to the 'else' branch, jump to the end
3706 if the condition is false. */
3708 false_label_p
= &end_label
;
3710 /* We only want to emit these labels if we aren't hijacking them. */
3711 emit_end
= (end_label
== NULL_TREE
);
3712 emit_false
= (false_label
== NULL_TREE
);
3714 /* We only emit the jump over the else clause if we have to--if the
3715 then clause may fall through. Otherwise we can wind up with a
3716 useless jump and a useless label at the end of gimplified code,
3717 which will cause us to think that this conditional as a whole
3718 falls through even if it doesn't. If we then inline a function
3719 which ends with such a condition, that can cause us to issue an
3720 inappropriate warning about control reaching the end of a
3721 non-void function. */
3722 jump_over_else
= block_may_fallthru (then_
);
3724 pred
= shortcut_cond_r (pred
, true_label_p
, false_label_p
,
3725 EXPR_LOC_OR_LOC (expr
, input_location
));
3728 append_to_statement_list (pred
, &expr
);
3730 append_to_statement_list (then_
, &expr
);
3735 tree last
= expr_last (expr
);
3736 t
= build_and_jump (&end_label
);
3737 if (rexpr_has_location (last
))
3738 SET_EXPR_LOCATION (t
, rexpr_location (last
));
3739 append_to_statement_list (t
, &expr
);
3743 t
= build1 (LABEL_EXPR
, void_type_node
, false_label
);
3744 append_to_statement_list (t
, &expr
);
3746 append_to_statement_list (else_
, &expr
);
3748 if (emit_end
&& end_label
)
3750 t
= build1 (LABEL_EXPR
, void_type_node
, end_label
);
3751 append_to_statement_list (t
, &expr
);
3757 /* EXPR is used in a boolean context; make sure it has BOOLEAN_TYPE. */
3760 gimple_boolify (tree expr
)
3762 tree type
= TREE_TYPE (expr
);
3763 location_t loc
= EXPR_LOCATION (expr
);
3765 if (TREE_CODE (expr
) == NE_EXPR
3766 && TREE_CODE (TREE_OPERAND (expr
, 0)) == CALL_EXPR
3767 && integer_zerop (TREE_OPERAND (expr
, 1)))
3769 tree call
= TREE_OPERAND (expr
, 0);
3770 tree fn
= get_callee_fndecl (call
);
3772 /* For __builtin_expect ((long) (x), y) recurse into x as well
3773 if x is truth_value_p. */
3775 && DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
3776 && DECL_FUNCTION_CODE (fn
) == BUILT_IN_EXPECT
3777 && call_expr_nargs (call
) == 2)
3779 tree arg
= CALL_EXPR_ARG (call
, 0);
3782 if (TREE_CODE (arg
) == NOP_EXPR
3783 && TREE_TYPE (arg
) == TREE_TYPE (call
))
3784 arg
= TREE_OPERAND (arg
, 0);
3785 if (truth_value_p (TREE_CODE (arg
)))
3787 arg
= gimple_boolify (arg
);
3788 CALL_EXPR_ARG (call
, 0)
3789 = fold_convert_loc (loc
, TREE_TYPE (call
), arg
);
3795 switch (TREE_CODE (expr
))
3797 case TRUTH_AND_EXPR
:
3799 case TRUTH_XOR_EXPR
:
3800 case TRUTH_ANDIF_EXPR
:
3801 case TRUTH_ORIF_EXPR
:
3802 /* Also boolify the arguments of truth exprs. */
3803 TREE_OPERAND (expr
, 1) = gimple_boolify (TREE_OPERAND (expr
, 1));
3806 case TRUTH_NOT_EXPR
:
3807 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
3809 /* These expressions always produce boolean results. */
3810 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3811 TREE_TYPE (expr
) = boolean_type_node
;
3815 switch ((enum annot_expr_kind
) TREE_INT_CST_LOW (TREE_OPERAND (expr
, 1)))
3817 case annot_expr_ivdep_kind
:
3818 case annot_expr_unroll_kind
:
3819 case annot_expr_no_vector_kind
:
3820 case annot_expr_vector_kind
:
3821 case annot_expr_parallel_kind
:
3822 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
3823 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3824 TREE_TYPE (expr
) = boolean_type_node
;
3831 if (COMPARISON_CLASS_P (expr
))
3833 /* There expressions always prduce boolean results. */
3834 if (TREE_CODE (type
) != BOOLEAN_TYPE
)
3835 TREE_TYPE (expr
) = boolean_type_node
;
3838 /* Other expressions that get here must have boolean values, but
3839 might need to be converted to the appropriate mode. */
3840 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
3842 return fold_convert_loc (loc
, boolean_type_node
, expr
);
3846 /* Given a conditional expression *EXPR_P without side effects, gimplify
3847 its operands. New statements are inserted to PRE_P. */
3849 static enum gimplify_status
3850 gimplify_pure_cond_expr (tree
*expr_p
, gimple_seq
*pre_p
)
3852 tree expr
= *expr_p
, cond
;
3853 enum gimplify_status ret
, tret
;
3854 enum tree_code code
;
3856 cond
= gimple_boolify (COND_EXPR_COND (expr
));
3858 /* We need to handle && and || specially, as their gimplification
3859 creates pure cond_expr, thus leading to an infinite cycle otherwise. */
3860 code
= TREE_CODE (cond
);
3861 if (code
== TRUTH_ANDIF_EXPR
)
3862 TREE_SET_CODE (cond
, TRUTH_AND_EXPR
);
3863 else if (code
== TRUTH_ORIF_EXPR
)
3864 TREE_SET_CODE (cond
, TRUTH_OR_EXPR
);
3865 ret
= gimplify_expr (&cond
, pre_p
, NULL
, is_gimple_condexpr
, fb_rvalue
);
3866 COND_EXPR_COND (*expr_p
) = cond
;
3868 tret
= gimplify_expr (&COND_EXPR_THEN (expr
), pre_p
, NULL
,
3869 is_gimple_val
, fb_rvalue
);
3870 ret
= MIN (ret
, tret
);
3871 tret
= gimplify_expr (&COND_EXPR_ELSE (expr
), pre_p
, NULL
,
3872 is_gimple_val
, fb_rvalue
);
3874 return MIN (ret
, tret
);
3877 /* Return true if evaluating EXPR could trap.
3878 EXPR is GENERIC, while tree_could_trap_p can be called
3882 generic_expr_could_trap_p (tree expr
)
3886 if (!expr
|| is_gimple_val (expr
))
3889 if (!EXPR_P (expr
) || tree_could_trap_p (expr
))
3892 n
= TREE_OPERAND_LENGTH (expr
);
3893 for (i
= 0; i
< n
; i
++)
3894 if (generic_expr_could_trap_p (TREE_OPERAND (expr
, i
)))
3900 /* Convert the conditional expression pointed to by EXPR_P '(p) ? a : b;'
3909 The second form is used when *EXPR_P is of type void.
3911 PRE_P points to the list where side effects that must happen before
3912 *EXPR_P should be stored. */
3914 static enum gimplify_status
3915 gimplify_cond_expr (tree
*expr_p
, gimple_seq
*pre_p
, fallback_t fallback
)
3917 tree expr
= *expr_p
;
3918 tree type
= TREE_TYPE (expr
);
3919 location_t loc
= EXPR_LOCATION (expr
);
3920 tree tmp
, arm1
, arm2
;
3921 enum gimplify_status ret
;
3922 tree label_true
, label_false
, label_cont
;
3923 bool have_then_clause_p
, have_else_clause_p
;
3925 enum tree_code pred_code
;
3926 gimple_seq seq
= NULL
;
3928 /* If this COND_EXPR has a value, copy the values into a temporary within
3930 if (!VOID_TYPE_P (type
))
3932 tree then_
= TREE_OPERAND (expr
, 1), else_
= TREE_OPERAND (expr
, 2);
3935 /* If either an rvalue is ok or we do not require an lvalue, create the
3936 temporary. But we cannot do that if the type is addressable. */
3937 if (((fallback
& fb_rvalue
) || !(fallback
& fb_lvalue
))
3938 && !TREE_ADDRESSABLE (type
))
3940 if (gimplify_ctxp
->allow_rhs_cond_expr
3941 /* If either branch has side effects or could trap, it can't be
3942 evaluated unconditionally. */
3943 && !TREE_SIDE_EFFECTS (then_
)
3944 && !generic_expr_could_trap_p (then_
)
3945 && !TREE_SIDE_EFFECTS (else_
)
3946 && !generic_expr_could_trap_p (else_
))
3947 return gimplify_pure_cond_expr (expr_p
, pre_p
);
3949 tmp
= create_tmp_var (type
, "iftmp");
3953 /* Otherwise, only create and copy references to the values. */
3956 type
= build_pointer_type (type
);
3958 if (!VOID_TYPE_P (TREE_TYPE (then_
)))
3959 then_
= build_fold_addr_expr_loc (loc
, then_
);
3961 if (!VOID_TYPE_P (TREE_TYPE (else_
)))
3962 else_
= build_fold_addr_expr_loc (loc
, else_
);
3965 = build3 (COND_EXPR
, type
, TREE_OPERAND (expr
, 0), then_
, else_
);
3967 tmp
= create_tmp_var (type
, "iftmp");
3968 result
= build_simple_mem_ref_loc (loc
, tmp
);
3971 /* Build the new then clause, `tmp = then_;'. But don't build the
3972 assignment if the value is void; in C++ it can be if it's a throw. */
3973 if (!VOID_TYPE_P (TREE_TYPE (then_
)))
3974 TREE_OPERAND (expr
, 1) = build2 (MODIFY_EXPR
, type
, tmp
, then_
);
3976 /* Similarly, build the new else clause, `tmp = else_;'. */
3977 if (!VOID_TYPE_P (TREE_TYPE (else_
)))
3978 TREE_OPERAND (expr
, 2) = build2 (MODIFY_EXPR
, type
, tmp
, else_
);
3980 TREE_TYPE (expr
) = void_type_node
;
3981 recalculate_side_effects (expr
);
3983 /* Move the COND_EXPR to the prequeue. */
3984 gimplify_stmt (&expr
, pre_p
);
3990 /* Remove any COMPOUND_EXPR so the following cases will be caught. */
3991 STRIP_TYPE_NOPS (TREE_OPERAND (expr
, 0));
3992 if (TREE_CODE (TREE_OPERAND (expr
, 0)) == COMPOUND_EXPR
)
3993 gimplify_compound_expr (&TREE_OPERAND (expr
, 0), pre_p
, true);
3995 /* Make sure the condition has BOOLEAN_TYPE. */
3996 TREE_OPERAND (expr
, 0) = gimple_boolify (TREE_OPERAND (expr
, 0));
3998 /* Break apart && and || conditions. */
3999 if (TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ANDIF_EXPR
4000 || TREE_CODE (TREE_OPERAND (expr
, 0)) == TRUTH_ORIF_EXPR
)
4002 expr
= shortcut_cond_expr (expr
);
4004 if (expr
!= *expr_p
)
4008 /* We can't rely on gimplify_expr to re-gimplify the expanded
4009 form properly, as cleanups might cause the target labels to be
4010 wrapped in a TRY_FINALLY_EXPR. To prevent that, we need to
4011 set up a conditional context. */
4012 gimple_push_condition ();
4013 gimplify_stmt (expr_p
, &seq
);
4014 gimple_pop_condition (pre_p
);
4015 gimple_seq_add_seq (pre_p
, seq
);
4021 /* Now do the normal gimplification. */
4023 /* Gimplify condition. */
4024 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, NULL
, is_gimple_condexpr
,
4026 if (ret
== GS_ERROR
)
4028 gcc_assert (TREE_OPERAND (expr
, 0) != NULL_TREE
);
4030 gimple_push_condition ();
4032 have_then_clause_p
= have_else_clause_p
= false;
4033 label_true
= find_goto_label (TREE_OPERAND (expr
, 1));
4035 && DECL_CONTEXT (GOTO_DESTINATION (label_true
)) == current_function_decl
4036 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
4037 have different locations, otherwise we end up with incorrect
4038 location information on the branches. */
4040 || !EXPR_HAS_LOCATION (expr
)
4041 || !rexpr_has_location (label_true
)
4042 || EXPR_LOCATION (expr
) == rexpr_location (label_true
)))
4044 have_then_clause_p
= true;
4045 label_true
= GOTO_DESTINATION (label_true
);
4048 label_true
= create_artificial_label (UNKNOWN_LOCATION
);
4049 label_false
= find_goto_label (TREE_OPERAND (expr
, 2));
4051 && DECL_CONTEXT (GOTO_DESTINATION (label_false
)) == current_function_decl
4052 /* For -O0 avoid this optimization if the COND_EXPR and GOTO_EXPR
4053 have different locations, otherwise we end up with incorrect
4054 location information on the branches. */
4056 || !EXPR_HAS_LOCATION (expr
)
4057 || !rexpr_has_location (label_false
)
4058 || EXPR_LOCATION (expr
) == rexpr_location (label_false
)))
4060 have_else_clause_p
= true;
4061 label_false
= GOTO_DESTINATION (label_false
);
4064 label_false
= create_artificial_label (UNKNOWN_LOCATION
);
4066 gimple_cond_get_ops_from_tree (COND_EXPR_COND (expr
), &pred_code
, &arm1
,
4068 cond_stmt
= gimple_build_cond (pred_code
, arm1
, arm2
, label_true
,
4070 gimple_set_no_warning (cond_stmt
, TREE_NO_WARNING (COND_EXPR_COND (expr
)));
4071 gimplify_seq_add_stmt (&seq
, cond_stmt
);
4072 gimple_stmt_iterator gsi
= gsi_last (seq
);
4073 maybe_fold_stmt (&gsi
);
4075 label_cont
= NULL_TREE
;
4076 if (!have_then_clause_p
)
4078 /* For if (...) {} else { code; } put label_true after
4080 if (TREE_OPERAND (expr
, 1) == NULL_TREE
4081 && !have_else_clause_p
4082 && TREE_OPERAND (expr
, 2) != NULL_TREE
)
4083 label_cont
= label_true
;
4086 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_true
));
4087 have_then_clause_p
= gimplify_stmt (&TREE_OPERAND (expr
, 1), &seq
);
4088 /* For if (...) { code; } else {} or
4089 if (...) { code; } else goto label; or
4090 if (...) { code; return; } else { ... }
4091 label_cont isn't needed. */
4092 if (!have_else_clause_p
4093 && TREE_OPERAND (expr
, 2) != NULL_TREE
4094 && gimple_seq_may_fallthru (seq
))
4097 label_cont
= create_artificial_label (UNKNOWN_LOCATION
);
4099 g
= gimple_build_goto (label_cont
);
4101 /* GIMPLE_COND's are very low level; they have embedded
4102 gotos. This particular embedded goto should not be marked
4103 with the location of the original COND_EXPR, as it would
4104 correspond to the COND_EXPR's condition, not the ELSE or the
4105 THEN arms. To avoid marking it with the wrong location, flag
4106 it as "no location". */
4107 gimple_set_do_not_emit_location (g
);
4109 gimplify_seq_add_stmt (&seq
, g
);
4113 if (!have_else_clause_p
)
4115 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_false
));
4116 have_else_clause_p
= gimplify_stmt (&TREE_OPERAND (expr
, 2), &seq
);
4119 gimplify_seq_add_stmt (&seq
, gimple_build_label (label_cont
));
4121 gimple_pop_condition (pre_p
);
4122 gimple_seq_add_seq (pre_p
, seq
);
4124 if (ret
== GS_ERROR
)
4126 else if (have_then_clause_p
|| have_else_clause_p
)
4130 /* Both arms are empty; replace the COND_EXPR with its predicate. */
4131 expr
= TREE_OPERAND (expr
, 0);
4132 gimplify_stmt (&expr
, pre_p
);
4139 /* Prepare the node pointed to by EXPR_P, an is_gimple_addressable expression,
4140 to be marked addressable.
4142 We cannot rely on such an expression being directly markable if a temporary
4143 has been created by the gimplification. In this case, we create another
4144 temporary and initialize it with a copy, which will become a store after we
4145 mark it addressable. This can happen if the front-end passed us something
4146 that it could not mark addressable yet, like a Fortran pass-by-reference
4147 parameter (int) floatvar. */
4150 prepare_gimple_addressable (tree
*expr_p
, gimple_seq
*seq_p
)
4152 while (handled_component_p (*expr_p
))
4153 expr_p
= &TREE_OPERAND (*expr_p
, 0);
4154 if (is_gimple_reg (*expr_p
))
4156 /* Do not allow an SSA name as the temporary. */
4157 tree var
= get_initialized_tmp_var (*expr_p
, seq_p
, NULL
, false);
4158 DECL_GIMPLE_REG_P (var
) = 0;
4163 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with
4164 a call to __builtin_memcpy. */
4166 static enum gimplify_status
4167 gimplify_modify_expr_to_memcpy (tree
*expr_p
, tree size
, bool want_value
,
4170 tree t
, to
, to_ptr
, from
, from_ptr
;
4172 location_t loc
= EXPR_LOCATION (*expr_p
);
4174 to
= TREE_OPERAND (*expr_p
, 0);
4175 from
= TREE_OPERAND (*expr_p
, 1);
4177 /* Mark the RHS addressable. Beware that it may not be possible to do so
4178 directly if a temporary has been created by the gimplification. */
4179 prepare_gimple_addressable (&from
, seq_p
);
4181 mark_addressable (from
);
4182 from_ptr
= build_fold_addr_expr_loc (loc
, from
);
4183 gimplify_arg (&from_ptr
, seq_p
, loc
);
4185 mark_addressable (to
);
4186 to_ptr
= build_fold_addr_expr_loc (loc
, to
);
4187 gimplify_arg (&to_ptr
, seq_p
, loc
);
4189 t
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
4191 gs
= gimple_build_call (t
, 3, to_ptr
, from_ptr
, size
);
4195 /* tmp = memcpy() */
4196 t
= create_tmp_var (TREE_TYPE (to_ptr
));
4197 gimple_call_set_lhs (gs
, t
);
4198 gimplify_seq_add_stmt (seq_p
, gs
);
4200 *expr_p
= build_simple_mem_ref (t
);
4204 gimplify_seq_add_stmt (seq_p
, gs
);
4209 /* A subroutine of gimplify_modify_expr. Replace a MODIFY_EXPR with
4210 a call to __builtin_memset. In this case we know that the RHS is
4211 a CONSTRUCTOR with an empty element list. */
4213 static enum gimplify_status
4214 gimplify_modify_expr_to_memset (tree
*expr_p
, tree size
, bool want_value
,
4217 tree t
, from
, to
, to_ptr
;
4219 location_t loc
= EXPR_LOCATION (*expr_p
);
4221 /* Assert our assumptions, to abort instead of producing wrong code
4222 silently if they are not met. Beware that the RHS CONSTRUCTOR might
4223 not be immediately exposed. */
4224 from
= TREE_OPERAND (*expr_p
, 1);
4225 if (TREE_CODE (from
) == WITH_SIZE_EXPR
)
4226 from
= TREE_OPERAND (from
, 0);
4228 gcc_assert (TREE_CODE (from
) == CONSTRUCTOR
4229 && vec_safe_is_empty (CONSTRUCTOR_ELTS (from
)));
4232 to
= TREE_OPERAND (*expr_p
, 0);
4234 to_ptr
= build_fold_addr_expr_loc (loc
, to
);
4235 gimplify_arg (&to_ptr
, seq_p
, loc
);
4236 t
= builtin_decl_implicit (BUILT_IN_MEMSET
);
4238 gs
= gimple_build_call (t
, 3, to_ptr
, integer_zero_node
, size
);
4242 /* tmp = memset() */
4243 t
= create_tmp_var (TREE_TYPE (to_ptr
));
4244 gimple_call_set_lhs (gs
, t
);
4245 gimplify_seq_add_stmt (seq_p
, gs
);
4247 *expr_p
= build1 (INDIRECT_REF
, TREE_TYPE (to
), t
);
4251 gimplify_seq_add_stmt (seq_p
, gs
);
4256 /* A subroutine of gimplify_init_ctor_preeval. Called via walk_tree,
4257 determine, cautiously, if a CONSTRUCTOR overlaps the lhs of an
4258 assignment. Return non-null if we detect a potential overlap. */
4260 struct gimplify_init_ctor_preeval_data
4262 /* The base decl of the lhs object. May be NULL, in which case we
4263 have to assume the lhs is indirect. */
4266 /* The alias set of the lhs object. */
4267 alias_set_type lhs_alias_set
;
4271 gimplify_init_ctor_preeval_1 (tree
*tp
, int *walk_subtrees
, void *xdata
)
4273 struct gimplify_init_ctor_preeval_data
*data
4274 = (struct gimplify_init_ctor_preeval_data
*) xdata
;
4277 /* If we find the base object, obviously we have overlap. */
4278 if (data
->lhs_base_decl
== t
)
4281 /* If the constructor component is indirect, determine if we have a
4282 potential overlap with the lhs. The only bits of information we
4283 have to go on at this point are addressability and alias sets. */
4284 if ((INDIRECT_REF_P (t
)
4285 || TREE_CODE (t
) == MEM_REF
)
4286 && (!data
->lhs_base_decl
|| TREE_ADDRESSABLE (data
->lhs_base_decl
))
4287 && alias_sets_conflict_p (data
->lhs_alias_set
, get_alias_set (t
)))
4290 /* If the constructor component is a call, determine if it can hide a
4291 potential overlap with the lhs through an INDIRECT_REF like above.
4292 ??? Ugh - this is completely broken. In fact this whole analysis
4293 doesn't look conservative. */
4294 if (TREE_CODE (t
) == CALL_EXPR
)
4296 tree type
, fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (t
)));
4298 for (type
= TYPE_ARG_TYPES (fntype
); type
; type
= TREE_CHAIN (type
))
4299 if (POINTER_TYPE_P (TREE_VALUE (type
))
4300 && (!data
->lhs_base_decl
|| TREE_ADDRESSABLE (data
->lhs_base_decl
))
4301 && alias_sets_conflict_p (data
->lhs_alias_set
,
4303 (TREE_TYPE (TREE_VALUE (type
)))))
4307 if (IS_TYPE_OR_DECL_P (t
))
4312 /* A subroutine of gimplify_init_constructor. Pre-evaluate EXPR,
4313 force values that overlap with the lhs (as described by *DATA)
4314 into temporaries. */
4317 gimplify_init_ctor_preeval (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
4318 struct gimplify_init_ctor_preeval_data
*data
)
4320 enum gimplify_status one
;
4322 /* If the value is constant, then there's nothing to pre-evaluate. */
4323 if (TREE_CONSTANT (*expr_p
))
4325 /* Ensure it does not have side effects, it might contain a reference to
4326 the object we're initializing. */
4327 gcc_assert (!TREE_SIDE_EFFECTS (*expr_p
));
4331 /* If the type has non-trivial constructors, we can't pre-evaluate. */
4332 if (TREE_ADDRESSABLE (TREE_TYPE (*expr_p
)))
4335 /* Recurse for nested constructors. */
4336 if (TREE_CODE (*expr_p
) == CONSTRUCTOR
)
4338 unsigned HOST_WIDE_INT ix
;
4339 constructor_elt
*ce
;
4340 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (*expr_p
);
4342 FOR_EACH_VEC_SAFE_ELT (v
, ix
, ce
)
4343 gimplify_init_ctor_preeval (&ce
->value
, pre_p
, post_p
, data
);
4348 /* If this is a variable sized type, we must remember the size. */
4349 maybe_with_size_expr (expr_p
);
4351 /* Gimplify the constructor element to something appropriate for the rhs
4352 of a MODIFY_EXPR. Given that we know the LHS is an aggregate, we know
4353 the gimplifier will consider this a store to memory. Doing this
4354 gimplification now means that we won't have to deal with complicated
4355 language-specific trees, nor trees like SAVE_EXPR that can induce
4356 exponential search behavior. */
4357 one
= gimplify_expr (expr_p
, pre_p
, post_p
, is_gimple_mem_rhs
, fb_rvalue
);
4358 if (one
== GS_ERROR
)
4364 /* If we gimplified to a bare decl, we can be sure that it doesn't overlap
4365 with the lhs, since "a = { .x=a }" doesn't make sense. This will
4366 always be true for all scalars, since is_gimple_mem_rhs insists on a
4367 temporary variable for them. */
4368 if (DECL_P (*expr_p
))
4371 /* If this is of variable size, we have no choice but to assume it doesn't
4372 overlap since we can't make a temporary for it. */
4373 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (*expr_p
))) != INTEGER_CST
)
4376 /* Otherwise, we must search for overlap ... */
4377 if (!walk_tree (expr_p
, gimplify_init_ctor_preeval_1
, data
, NULL
))
4380 /* ... and if found, force the value into a temporary. */
4381 *expr_p
= get_formal_tmp_var (*expr_p
, pre_p
);
4384 /* A subroutine of gimplify_init_ctor_eval. Create a loop for
4385 a RANGE_EXPR in a CONSTRUCTOR for an array.
4389 object[var] = value;
4396 We increment var _after_ the loop exit check because we might otherwise
4397 fail if upper == TYPE_MAX_VALUE (type for upper).
4399 Note that we never have to deal with SAVE_EXPRs here, because this has
4400 already been taken care of for us, in gimplify_init_ctor_preeval(). */
4402 static void gimplify_init_ctor_eval (tree
, vec
<constructor_elt
, va_gc
> *,
4403 gimple_seq
*, bool);
4406 gimplify_init_ctor_eval_range (tree object
, tree lower
, tree upper
,
4407 tree value
, tree array_elt_type
,
4408 gimple_seq
*pre_p
, bool cleared
)
4410 tree loop_entry_label
, loop_exit_label
, fall_thru_label
;
4411 tree var
, var_type
, cref
, tmp
;
4413 loop_entry_label
= create_artificial_label (UNKNOWN_LOCATION
);
4414 loop_exit_label
= create_artificial_label (UNKNOWN_LOCATION
);
4415 fall_thru_label
= create_artificial_label (UNKNOWN_LOCATION
);
4417 /* Create and initialize the index variable. */
4418 var_type
= TREE_TYPE (upper
);
4419 var
= create_tmp_var (var_type
);
4420 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (var
, lower
));
4422 /* Add the loop entry label. */
4423 gimplify_seq_add_stmt (pre_p
, gimple_build_label (loop_entry_label
));
4425 /* Build the reference. */
4426 cref
= build4 (ARRAY_REF
, array_elt_type
, unshare_expr (object
),
4427 var
, NULL_TREE
, NULL_TREE
);
4429 /* If we are a constructor, just call gimplify_init_ctor_eval to do
4430 the store. Otherwise just assign value to the reference. */
4432 if (TREE_CODE (value
) == CONSTRUCTOR
)
4433 /* NB we might have to call ourself recursively through
4434 gimplify_init_ctor_eval if the value is a constructor. */
4435 gimplify_init_ctor_eval (cref
, CONSTRUCTOR_ELTS (value
),
4438 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (cref
, value
));
4440 /* We exit the loop when the index var is equal to the upper bound. */
4441 gimplify_seq_add_stmt (pre_p
,
4442 gimple_build_cond (EQ_EXPR
, var
, upper
,
4443 loop_exit_label
, fall_thru_label
));
4445 gimplify_seq_add_stmt (pre_p
, gimple_build_label (fall_thru_label
));
4447 /* Otherwise, increment the index var... */
4448 tmp
= build2 (PLUS_EXPR
, var_type
, var
,
4449 fold_convert (var_type
, integer_one_node
));
4450 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (var
, tmp
));
4452 /* ...and jump back to the loop entry. */
4453 gimplify_seq_add_stmt (pre_p
, gimple_build_goto (loop_entry_label
));
4455 /* Add the loop exit label. */
4456 gimplify_seq_add_stmt (pre_p
, gimple_build_label (loop_exit_label
));
4459 /* Return true if FDECL is accessing a field that is zero sized. */
4462 zero_sized_field_decl (const_tree fdecl
)
4464 if (TREE_CODE (fdecl
) == FIELD_DECL
&& DECL_SIZE (fdecl
)
4465 && integer_zerop (DECL_SIZE (fdecl
)))
4470 /* Return true if TYPE is zero sized. */
4473 zero_sized_type (const_tree type
)
4475 if (AGGREGATE_TYPE_P (type
) && TYPE_SIZE (type
)
4476 && integer_zerop (TYPE_SIZE (type
)))
4481 /* A subroutine of gimplify_init_constructor. Generate individual
4482 MODIFY_EXPRs for a CONSTRUCTOR. OBJECT is the LHS against which the
4483 assignments should happen. ELTS is the CONSTRUCTOR_ELTS of the
4484 CONSTRUCTOR. CLEARED is true if the entire LHS object has been
4488 gimplify_init_ctor_eval (tree object
, vec
<constructor_elt
, va_gc
> *elts
,
4489 gimple_seq
*pre_p
, bool cleared
)
4491 tree array_elt_type
= NULL
;
4492 unsigned HOST_WIDE_INT ix
;
4493 tree purpose
, value
;
4495 if (TREE_CODE (TREE_TYPE (object
)) == ARRAY_TYPE
)
4496 array_elt_type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (object
)));
4498 FOR_EACH_CONSTRUCTOR_ELT (elts
, ix
, purpose
, value
)
4502 /* NULL values are created above for gimplification errors. */
4506 if (cleared
&& initializer_zerop (value
))
4509 /* ??? Here's to hoping the front end fills in all of the indices,
4510 so we don't have to figure out what's missing ourselves. */
4511 gcc_assert (purpose
);
4513 /* Skip zero-sized fields, unless value has side-effects. This can
4514 happen with calls to functions returning a zero-sized type, which
4515 we shouldn't discard. As a number of downstream passes don't
4516 expect sets of zero-sized fields, we rely on the gimplification of
4517 the MODIFY_EXPR we make below to drop the assignment statement. */
4518 if (! TREE_SIDE_EFFECTS (value
) && zero_sized_field_decl (purpose
))
4521 /* If we have a RANGE_EXPR, we have to build a loop to assign the
4523 if (TREE_CODE (purpose
) == RANGE_EXPR
)
4525 tree lower
= TREE_OPERAND (purpose
, 0);
4526 tree upper
= TREE_OPERAND (purpose
, 1);
4528 /* If the lower bound is equal to upper, just treat it as if
4529 upper was the index. */
4530 if (simple_cst_equal (lower
, upper
))
4534 gimplify_init_ctor_eval_range (object
, lower
, upper
, value
,
4535 array_elt_type
, pre_p
, cleared
);
4542 /* Do not use bitsizetype for ARRAY_REF indices. */
4543 if (TYPE_DOMAIN (TREE_TYPE (object
)))
4545 = fold_convert (TREE_TYPE (TYPE_DOMAIN (TREE_TYPE (object
))),
4547 cref
= build4 (ARRAY_REF
, array_elt_type
, unshare_expr (object
),
4548 purpose
, NULL_TREE
, NULL_TREE
);
4552 gcc_assert (TREE_CODE (purpose
) == FIELD_DECL
);
4553 cref
= build3 (COMPONENT_REF
, TREE_TYPE (purpose
),
4554 unshare_expr (object
), purpose
, NULL_TREE
);
4557 if (TREE_CODE (value
) == CONSTRUCTOR
4558 && TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
)
4559 gimplify_init_ctor_eval (cref
, CONSTRUCTOR_ELTS (value
),
4563 tree init
= build2 (INIT_EXPR
, TREE_TYPE (cref
), cref
, value
);
4564 gimplify_and_add (init
, pre_p
);
4570 /* Return the appropriate RHS predicate for this LHS. */
4573 rhs_predicate_for (tree lhs
)
4575 if (is_gimple_reg (lhs
))
4576 return is_gimple_reg_rhs_or_call
;
4578 return is_gimple_mem_rhs_or_call
;
4581 /* Return the initial guess for an appropriate RHS predicate for this LHS,
4582 before the LHS has been gimplified. */
4584 static gimple_predicate
4585 initial_rhs_predicate_for (tree lhs
)
4587 if (is_gimple_reg_type (TREE_TYPE (lhs
)))
4588 return is_gimple_reg_rhs_or_call
;
4590 return is_gimple_mem_rhs_or_call
;
4593 /* Gimplify a C99 compound literal expression. This just means adding
4594 the DECL_EXPR before the current statement and using its anonymous
4597 static enum gimplify_status
4598 gimplify_compound_literal_expr (tree
*expr_p
, gimple_seq
*pre_p
,
4599 bool (*gimple_test_f
) (tree
),
4600 fallback_t fallback
)
4602 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p
);
4603 tree decl
= DECL_EXPR_DECL (decl_s
);
4604 tree init
= DECL_INITIAL (decl
);
4605 /* Mark the decl as addressable if the compound literal
4606 expression is addressable now, otherwise it is marked too late
4607 after we gimplify the initialization expression. */
4608 if (TREE_ADDRESSABLE (*expr_p
))
4609 TREE_ADDRESSABLE (decl
) = 1;
4610 /* Otherwise, if we don't need an lvalue and have a literal directly
4611 substitute it. Check if it matches the gimple predicate, as
4612 otherwise we'd generate a new temporary, and we can as well just
4613 use the decl we already have. */
4614 else if (!TREE_ADDRESSABLE (decl
)
4616 && (fallback
& fb_lvalue
) == 0
4617 && gimple_test_f (init
))
4623 /* Preliminarily mark non-addressed complex variables as eligible
4624 for promotion to gimple registers. We'll transform their uses
4626 if ((TREE_CODE (TREE_TYPE (decl
)) == COMPLEX_TYPE
4627 || TREE_CODE (TREE_TYPE (decl
)) == VECTOR_TYPE
)
4628 && !TREE_THIS_VOLATILE (decl
)
4629 && !needs_to_live_in_memory (decl
))
4630 DECL_GIMPLE_REG_P (decl
) = 1;
4632 /* If the decl is not addressable, then it is being used in some
4633 expression or on the right hand side of a statement, and it can
4634 be put into a readonly data section. */
4635 if (!TREE_ADDRESSABLE (decl
) && (fallback
& fb_lvalue
) == 0)
4636 TREE_READONLY (decl
) = 1;
4638 /* This decl isn't mentioned in the enclosing block, so add it to the
4639 list of temps. FIXME it seems a bit of a kludge to say that
4640 anonymous artificial vars aren't pushed, but everything else is. */
4641 if (DECL_NAME (decl
) == NULL_TREE
&& !DECL_SEEN_IN_BIND_EXPR_P (decl
))
4642 gimple_add_tmp_var (decl
);
4644 gimplify_and_add (decl_s
, pre_p
);
4649 /* Optimize embedded COMPOUND_LITERAL_EXPRs within a CONSTRUCTOR,
4650 return a new CONSTRUCTOR if something changed. */
4653 optimize_compound_literals_in_ctor (tree orig_ctor
)
4655 tree ctor
= orig_ctor
;
4656 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (ctor
);
4657 unsigned int idx
, num
= vec_safe_length (elts
);
4659 for (idx
= 0; idx
< num
; idx
++)
4661 tree value
= (*elts
)[idx
].value
;
4662 tree newval
= value
;
4663 if (TREE_CODE (value
) == CONSTRUCTOR
)
4664 newval
= optimize_compound_literals_in_ctor (value
);
4665 else if (TREE_CODE (value
) == COMPOUND_LITERAL_EXPR
)
4667 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (value
);
4668 tree decl
= DECL_EXPR_DECL (decl_s
);
4669 tree init
= DECL_INITIAL (decl
);
4671 if (!TREE_ADDRESSABLE (value
)
4672 && !TREE_ADDRESSABLE (decl
)
4674 && TREE_CODE (init
) == CONSTRUCTOR
)
4675 newval
= optimize_compound_literals_in_ctor (init
);
4677 if (newval
== value
)
4680 if (ctor
== orig_ctor
)
4682 ctor
= copy_node (orig_ctor
);
4683 CONSTRUCTOR_ELTS (ctor
) = vec_safe_copy (elts
);
4684 elts
= CONSTRUCTOR_ELTS (ctor
);
4686 (*elts
)[idx
].value
= newval
;
4691 /* A subroutine of gimplify_modify_expr. Break out elements of a
4692 CONSTRUCTOR used as an initializer into separate MODIFY_EXPRs.
4694 Note that we still need to clear any elements that don't have explicit
4695 initializers, so if not all elements are initialized we keep the
4696 original MODIFY_EXPR, we just remove all of the constructor elements.
4698 If NOTIFY_TEMP_CREATION is true, do not gimplify, just return
4699 GS_ERROR if we would have to create a temporary when gimplifying
4700 this constructor. Otherwise, return GS_OK.
4702 If NOTIFY_TEMP_CREATION is false, just do the gimplification. */
4704 static enum gimplify_status
4705 gimplify_init_constructor (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
4706 bool want_value
, bool notify_temp_creation
)
4708 tree object
, ctor
, type
;
4709 enum gimplify_status ret
;
4710 vec
<constructor_elt
, va_gc
> *elts
;
4712 gcc_assert (TREE_CODE (TREE_OPERAND (*expr_p
, 1)) == CONSTRUCTOR
);
4714 if (!notify_temp_creation
)
4716 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
4717 is_gimple_lvalue
, fb_lvalue
);
4718 if (ret
== GS_ERROR
)
4722 object
= TREE_OPERAND (*expr_p
, 0);
4723 ctor
= TREE_OPERAND (*expr_p
, 1)
4724 = optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p
, 1));
4725 type
= TREE_TYPE (ctor
);
4726 elts
= CONSTRUCTOR_ELTS (ctor
);
4729 switch (TREE_CODE (type
))
4733 case QUAL_UNION_TYPE
:
4736 struct gimplify_init_ctor_preeval_data preeval_data
;
4737 HOST_WIDE_INT num_ctor_elements
, num_nonzero_elements
;
4738 bool cleared
, complete_p
, valid_const_initializer
;
4740 /* Aggregate types must lower constructors to initialization of
4741 individual elements. The exception is that a CONSTRUCTOR node
4742 with no elements indicates zero-initialization of the whole. */
4743 if (vec_safe_is_empty (elts
))
4745 if (notify_temp_creation
)
4750 /* Fetch information about the constructor to direct later processing.
4751 We might want to make static versions of it in various cases, and
4752 can only do so if it known to be a valid constant initializer. */
4753 valid_const_initializer
4754 = categorize_ctor_elements (ctor
, &num_nonzero_elements
,
4755 &num_ctor_elements
, &complete_p
);
4757 /* If a const aggregate variable is being initialized, then it
4758 should never be a lose to promote the variable to be static. */
4759 if (valid_const_initializer
4760 && num_nonzero_elements
> 1
4761 && TREE_READONLY (object
)
4763 && (flag_merge_constants
>= 2 || !TREE_ADDRESSABLE (object
)))
4765 if (notify_temp_creation
)
4767 DECL_INITIAL (object
) = ctor
;
4768 TREE_STATIC (object
) = 1;
4769 if (!DECL_NAME (object
))
4770 DECL_NAME (object
) = create_tmp_var_name ("C");
4771 walk_tree (&DECL_INITIAL (object
), force_labels_r
, NULL
, NULL
);
4773 /* ??? C++ doesn't automatically append a .<number> to the
4774 assembler name, and even when it does, it looks at FE private
4775 data structures to figure out what that number should be,
4776 which are not set for this variable. I suppose this is
4777 important for local statics for inline functions, which aren't
4778 "local" in the object file sense. So in order to get a unique
4779 TU-local symbol, we must invoke the lhd version now. */
4780 lhd_set_decl_assembler_name (object
);
4782 *expr_p
= NULL_TREE
;
4786 /* If there are "lots" of initialized elements, even discounting
4787 those that are not address constants (and thus *must* be
4788 computed at runtime), then partition the constructor into
4789 constant and non-constant parts. Block copy the constant
4790 parts in, then generate code for the non-constant parts. */
4791 /* TODO. There's code in cp/typeck.c to do this. */
4793 if (int_size_in_bytes (TREE_TYPE (ctor
)) < 0)
4794 /* store_constructor will ignore the clearing of variable-sized
4795 objects. Initializers for such objects must explicitly set
4796 every field that needs to be set. */
4798 else if (!complete_p
)
4799 /* If the constructor isn't complete, clear the whole object
4800 beforehand, unless CONSTRUCTOR_NO_CLEARING is set on it.
4802 ??? This ought not to be needed. For any element not present
4803 in the initializer, we should simply set them to zero. Except
4804 we'd need to *find* the elements that are not present, and that
4805 requires trickery to avoid quadratic compile-time behavior in
4806 large cases or excessive memory use in small cases. */
4807 cleared
= !CONSTRUCTOR_NO_CLEARING (ctor
);
4808 else if (num_ctor_elements
- num_nonzero_elements
4809 > CLEAR_RATIO (optimize_function_for_speed_p (cfun
))
4810 && num_nonzero_elements
< num_ctor_elements
/ 4)
4811 /* If there are "lots" of zeros, it's more efficient to clear
4812 the memory and then set the nonzero elements. */
4817 /* If there are "lots" of initialized elements, and all of them
4818 are valid address constants, then the entire initializer can
4819 be dropped to memory, and then memcpy'd out. Don't do this
4820 for sparse arrays, though, as it's more efficient to follow
4821 the standard CONSTRUCTOR behavior of memset followed by
4822 individual element initialization. Also don't do this for small
4823 all-zero initializers (which aren't big enough to merit
4824 clearing), and don't try to make bitwise copies of
4825 TREE_ADDRESSABLE types. */
4827 if (valid_const_initializer
4828 && !(cleared
|| num_nonzero_elements
== 0)
4829 && !TREE_ADDRESSABLE (type
))
4831 HOST_WIDE_INT size
= int_size_in_bytes (type
);
4834 /* ??? We can still get unbounded array types, at least
4835 from the C++ front end. This seems wrong, but attempt
4836 to work around it for now. */
4839 size
= int_size_in_bytes (TREE_TYPE (object
));
4841 TREE_TYPE (ctor
) = type
= TREE_TYPE (object
);
4844 /* Find the maximum alignment we can assume for the object. */
4845 /* ??? Make use of DECL_OFFSET_ALIGN. */
4846 if (DECL_P (object
))
4847 align
= DECL_ALIGN (object
);
4849 align
= TYPE_ALIGN (type
);
4851 /* Do a block move either if the size is so small as to make
4852 each individual move a sub-unit move on average, or if it
4853 is so large as to make individual moves inefficient. */
4855 && num_nonzero_elements
> 1
4856 && (size
< num_nonzero_elements
4857 || !can_move_by_pieces (size
, align
)))
4859 if (notify_temp_creation
)
4862 walk_tree (&ctor
, force_labels_r
, NULL
, NULL
);
4863 ctor
= tree_output_constant_def (ctor
);
4864 if (!useless_type_conversion_p (type
, TREE_TYPE (ctor
)))
4865 ctor
= build1 (VIEW_CONVERT_EXPR
, type
, ctor
);
4866 TREE_OPERAND (*expr_p
, 1) = ctor
;
4868 /* This is no longer an assignment of a CONSTRUCTOR, but
4869 we still may have processing to do on the LHS. So
4870 pretend we didn't do anything here to let that happen. */
4871 return GS_UNHANDLED
;
4875 /* If the target is volatile, we have non-zero elements and more than
4876 one field to assign, initialize the target from a temporary. */
4877 if (TREE_THIS_VOLATILE (object
)
4878 && !TREE_ADDRESSABLE (type
)
4879 && num_nonzero_elements
> 0
4880 && vec_safe_length (elts
) > 1)
4882 tree temp
= create_tmp_var (TYPE_MAIN_VARIANT (type
));
4883 TREE_OPERAND (*expr_p
, 0) = temp
;
4884 *expr_p
= build2 (COMPOUND_EXPR
, TREE_TYPE (*expr_p
),
4886 build2 (MODIFY_EXPR
, void_type_node
,
4891 if (notify_temp_creation
)
4894 /* If there are nonzero elements and if needed, pre-evaluate to capture
4895 elements overlapping with the lhs into temporaries. We must do this
4896 before clearing to fetch the values before they are zeroed-out. */
4897 if (num_nonzero_elements
> 0 && TREE_CODE (*expr_p
) != INIT_EXPR
)
4899 preeval_data
.lhs_base_decl
= get_base_address (object
);
4900 if (!DECL_P (preeval_data
.lhs_base_decl
))
4901 preeval_data
.lhs_base_decl
= NULL
;
4902 preeval_data
.lhs_alias_set
= get_alias_set (object
);
4904 gimplify_init_ctor_preeval (&TREE_OPERAND (*expr_p
, 1),
4905 pre_p
, post_p
, &preeval_data
);
4908 bool ctor_has_side_effects_p
4909 = TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p
, 1));
4913 /* Zap the CONSTRUCTOR element list, which simplifies this case.
4914 Note that we still have to gimplify, in order to handle the
4915 case of variable sized types. Avoid shared tree structures. */
4916 CONSTRUCTOR_ELTS (ctor
) = NULL
;
4917 TREE_SIDE_EFFECTS (ctor
) = 0;
4918 object
= unshare_expr (object
);
4919 gimplify_stmt (expr_p
, pre_p
);
4922 /* If we have not block cleared the object, or if there are nonzero
4923 elements in the constructor, or if the constructor has side effects,
4924 add assignments to the individual scalar fields of the object. */
4926 || num_nonzero_elements
> 0
4927 || ctor_has_side_effects_p
)
4928 gimplify_init_ctor_eval (object
, elts
, pre_p
, cleared
);
4930 *expr_p
= NULL_TREE
;
4938 if (notify_temp_creation
)
4941 /* Extract the real and imaginary parts out of the ctor. */
4942 gcc_assert (elts
->length () == 2);
4943 r
= (*elts
)[0].value
;
4944 i
= (*elts
)[1].value
;
4945 if (r
== NULL
|| i
== NULL
)
4947 tree zero
= build_zero_cst (TREE_TYPE (type
));
4954 /* Complex types have either COMPLEX_CST or COMPLEX_EXPR to
4955 represent creation of a complex value. */
4956 if (TREE_CONSTANT (r
) && TREE_CONSTANT (i
))
4958 ctor
= build_complex (type
, r
, i
);
4959 TREE_OPERAND (*expr_p
, 1) = ctor
;
4963 ctor
= build2 (COMPLEX_EXPR
, type
, r
, i
);
4964 TREE_OPERAND (*expr_p
, 1) = ctor
;
4965 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1),
4968 rhs_predicate_for (TREE_OPERAND (*expr_p
, 0)),
4976 unsigned HOST_WIDE_INT ix
;
4977 constructor_elt
*ce
;
4979 if (notify_temp_creation
)
4982 /* Go ahead and simplify constant constructors to VECTOR_CST. */
4983 if (TREE_CONSTANT (ctor
))
4985 bool constant_p
= true;
4988 /* Even when ctor is constant, it might contain non-*_CST
4989 elements, such as addresses or trapping values like
4990 1.0/0.0 - 1.0/0.0. Such expressions don't belong
4991 in VECTOR_CST nodes. */
4992 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
4993 if (!CONSTANT_CLASS_P (value
))
5001 TREE_OPERAND (*expr_p
, 1) = build_vector_from_ctor (type
, elts
);
5005 TREE_CONSTANT (ctor
) = 0;
5008 /* Vector types use CONSTRUCTOR all the way through gimple
5009 compilation as a general initializer. */
5010 FOR_EACH_VEC_SAFE_ELT (elts
, ix
, ce
)
5012 enum gimplify_status tret
;
5013 tret
= gimplify_expr (&ce
->value
, pre_p
, post_p
, is_gimple_val
,
5015 if (tret
== GS_ERROR
)
5017 else if (TREE_STATIC (ctor
)
5018 && !initializer_constant_valid_p (ce
->value
,
5019 TREE_TYPE (ce
->value
)))
5020 TREE_STATIC (ctor
) = 0;
5022 if (!is_gimple_reg (TREE_OPERAND (*expr_p
, 0)))
5023 TREE_OPERAND (*expr_p
, 1) = get_formal_tmp_var (ctor
, pre_p
);
5028 /* So how did we get a CONSTRUCTOR for a scalar type? */
5032 if (ret
== GS_ERROR
)
5034 /* If we have gimplified both sides of the initializer but have
5035 not emitted an assignment, do so now. */
5038 tree lhs
= TREE_OPERAND (*expr_p
, 0);
5039 tree rhs
= TREE_OPERAND (*expr_p
, 1);
5040 if (want_value
&& object
== lhs
)
5041 lhs
= unshare_expr (lhs
);
5042 gassign
*init
= gimple_build_assign (lhs
, rhs
);
5043 gimplify_seq_add_stmt (pre_p
, init
);
5057 /* Given a pointer value OP0, return a simplified version of an
5058 indirection through OP0, or NULL_TREE if no simplification is
5059 possible. This may only be applied to a rhs of an expression.
5060 Note that the resulting type may be different from the type pointed
5061 to in the sense that it is still compatible from the langhooks
5065 gimple_fold_indirect_ref_rhs (tree t
)
5067 return gimple_fold_indirect_ref (t
);
5070 /* Subroutine of gimplify_modify_expr to do simplifications of
5071 MODIFY_EXPRs based on the code of the RHS. We loop for as long as
5072 something changes. */
5074 static enum gimplify_status
5075 gimplify_modify_expr_rhs (tree
*expr_p
, tree
*from_p
, tree
*to_p
,
5076 gimple_seq
*pre_p
, gimple_seq
*post_p
,
5079 enum gimplify_status ret
= GS_UNHANDLED
;
5085 switch (TREE_CODE (*from_p
))
5088 /* If we're assigning from a read-only variable initialized with
5089 a constructor, do the direct assignment from the constructor,
5090 but only if neither source nor target are volatile since this
5091 latter assignment might end up being done on a per-field basis. */
5092 if (DECL_INITIAL (*from_p
)
5093 && TREE_READONLY (*from_p
)
5094 && !TREE_THIS_VOLATILE (*from_p
)
5095 && !TREE_THIS_VOLATILE (*to_p
)
5096 && TREE_CODE (DECL_INITIAL (*from_p
)) == CONSTRUCTOR
)
5098 tree old_from
= *from_p
;
5099 enum gimplify_status subret
;
5101 /* Move the constructor into the RHS. */
5102 *from_p
= unshare_expr (DECL_INITIAL (*from_p
));
5104 /* Let's see if gimplify_init_constructor will need to put
5106 subret
= gimplify_init_constructor (expr_p
, NULL
, NULL
,
5108 if (subret
== GS_ERROR
)
5110 /* If so, revert the change. */
5122 /* If we have code like
5126 where the type of "x" is a (possibly cv-qualified variant
5127 of "A"), treat the entire expression as identical to "x".
5128 This kind of code arises in C++ when an object is bound
5129 to a const reference, and if "x" is a TARGET_EXPR we want
5130 to take advantage of the optimization below. */
5131 bool volatile_p
= TREE_THIS_VOLATILE (*from_p
);
5132 tree t
= gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p
, 0));
5135 if (TREE_THIS_VOLATILE (t
) != volatile_p
)
5138 t
= build_simple_mem_ref_loc (EXPR_LOCATION (*from_p
),
5139 build_fold_addr_expr (t
));
5140 if (REFERENCE_CLASS_P (t
))
5141 TREE_THIS_VOLATILE (t
) = volatile_p
;
5152 /* If we are initializing something from a TARGET_EXPR, strip the
5153 TARGET_EXPR and initialize it directly, if possible. This can't
5154 be done if the initializer is void, since that implies that the
5155 temporary is set in some non-trivial way.
5157 ??? What about code that pulls out the temp and uses it
5158 elsewhere? I think that such code never uses the TARGET_EXPR as
5159 an initializer. If I'm wrong, we'll die because the temp won't
5160 have any RTL. In that case, I guess we'll need to replace
5161 references somehow. */
5162 tree init
= TARGET_EXPR_INITIAL (*from_p
);
5165 && (TREE_CODE (*expr_p
) != MODIFY_EXPR
5166 || !TARGET_EXPR_NO_ELIDE (*from_p
))
5167 && !VOID_TYPE_P (TREE_TYPE (init
)))
5177 /* Remove any COMPOUND_EXPR in the RHS so the following cases will be
5179 gimplify_compound_expr (from_p
, pre_p
, true);
5185 /* If we already made some changes, let the front end have a
5186 crack at this before we break it down. */
5187 if (ret
!= GS_UNHANDLED
)
5189 /* If we're initializing from a CONSTRUCTOR, break this into
5190 individual MODIFY_EXPRs. */
5191 return gimplify_init_constructor (expr_p
, pre_p
, post_p
, want_value
,
5195 /* If we're assigning to a non-register type, push the assignment
5196 down into the branches. This is mandatory for ADDRESSABLE types,
5197 since we cannot generate temporaries for such, but it saves a
5198 copy in other cases as well. */
5199 if (!is_gimple_reg_type (TREE_TYPE (*from_p
)))
5201 /* This code should mirror the code in gimplify_cond_expr. */
5202 enum tree_code code
= TREE_CODE (*expr_p
);
5203 tree cond
= *from_p
;
5204 tree result
= *to_p
;
5206 ret
= gimplify_expr (&result
, pre_p
, post_p
,
5207 is_gimple_lvalue
, fb_lvalue
);
5208 if (ret
!= GS_ERROR
)
5211 /* If we are going to write RESULT more than once, clear
5212 TREE_READONLY flag, otherwise we might incorrectly promote
5213 the variable to static const and initialize it at compile
5214 time in one of the branches. */
5216 && TREE_TYPE (TREE_OPERAND (cond
, 1)) != void_type_node
5217 && TREE_TYPE (TREE_OPERAND (cond
, 2)) != void_type_node
)
5218 TREE_READONLY (result
) = 0;
5219 if (TREE_TYPE (TREE_OPERAND (cond
, 1)) != void_type_node
)
5220 TREE_OPERAND (cond
, 1)
5221 = build2 (code
, void_type_node
, result
,
5222 TREE_OPERAND (cond
, 1));
5223 if (TREE_TYPE (TREE_OPERAND (cond
, 2)) != void_type_node
)
5224 TREE_OPERAND (cond
, 2)
5225 = build2 (code
, void_type_node
, unshare_expr (result
),
5226 TREE_OPERAND (cond
, 2));
5228 TREE_TYPE (cond
) = void_type_node
;
5229 recalculate_side_effects (cond
);
5233 gimplify_and_add (cond
, pre_p
);
5234 *expr_p
= unshare_expr (result
);
5243 /* For calls that return in memory, give *to_p as the CALL_EXPR's
5244 return slot so that we don't generate a temporary. */
5245 if (!CALL_EXPR_RETURN_SLOT_OPT (*from_p
)
5246 && aggregate_value_p (*from_p
, *from_p
))
5250 if (!(rhs_predicate_for (*to_p
))(*from_p
))
5251 /* If we need a temporary, *to_p isn't accurate. */
5253 /* It's OK to use the return slot directly unless it's an NRV. */
5254 else if (TREE_CODE (*to_p
) == RESULT_DECL
5255 && DECL_NAME (*to_p
) == NULL_TREE
5256 && needs_to_live_in_memory (*to_p
))
5258 else if (is_gimple_reg_type (TREE_TYPE (*to_p
))
5259 || (DECL_P (*to_p
) && DECL_REGISTER (*to_p
)))
5260 /* Don't force regs into memory. */
5262 else if (TREE_CODE (*expr_p
) == INIT_EXPR
)
5263 /* It's OK to use the target directly if it's being
5266 else if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p
)))
5268 /* Always use the target and thus RSO for variable-sized types.
5269 GIMPLE cannot deal with a variable-sized assignment
5270 embedded in a call statement. */
5272 else if (TREE_CODE (*to_p
) != SSA_NAME
5273 && (!is_gimple_variable (*to_p
)
5274 || needs_to_live_in_memory (*to_p
)))
5275 /* Don't use the original target if it's already addressable;
5276 if its address escapes, and the called function uses the
5277 NRV optimization, a conforming program could see *to_p
5278 change before the called function returns; see c++/19317.
5279 When optimizing, the return_slot pass marks more functions
5280 as safe after we have escape info. */
5287 CALL_EXPR_RETURN_SLOT_OPT (*from_p
) = 1;
5288 mark_addressable (*to_p
);
5293 case WITH_SIZE_EXPR
:
5294 /* Likewise for calls that return an aggregate of non-constant size,
5295 since we would not be able to generate a temporary at all. */
5296 if (TREE_CODE (TREE_OPERAND (*from_p
, 0)) == CALL_EXPR
)
5298 *from_p
= TREE_OPERAND (*from_p
, 0);
5299 /* We don't change ret in this case because the
5300 WITH_SIZE_EXPR might have been added in
5301 gimplify_modify_expr, so returning GS_OK would lead to an
5307 /* If we're initializing from a container, push the initialization
5309 case CLEANUP_POINT_EXPR
:
5311 case STATEMENT_LIST
:
5313 tree wrap
= *from_p
;
5316 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_min_lval
,
5318 if (ret
!= GS_ERROR
)
5321 t
= voidify_wrapper_expr (wrap
, *expr_p
);
5322 gcc_assert (t
== *expr_p
);
5326 gimplify_and_add (wrap
, pre_p
);
5327 *expr_p
= unshare_expr (*to_p
);
5334 case COMPOUND_LITERAL_EXPR
:
5336 tree complit
= TREE_OPERAND (*expr_p
, 1);
5337 tree decl_s
= COMPOUND_LITERAL_EXPR_DECL_EXPR (complit
);
5338 tree decl
= DECL_EXPR_DECL (decl_s
);
5339 tree init
= DECL_INITIAL (decl
);
5341 /* struct T x = (struct T) { 0, 1, 2 } can be optimized
5342 into struct T x = { 0, 1, 2 } if the address of the
5343 compound literal has never been taken. */
5344 if (!TREE_ADDRESSABLE (complit
)
5345 && !TREE_ADDRESSABLE (decl
)
5348 *expr_p
= copy_node (*expr_p
);
5349 TREE_OPERAND (*expr_p
, 1) = init
;
5364 /* Return true if T looks like a valid GIMPLE statement. */
5367 is_gimple_stmt (tree t
)
5369 const enum tree_code code
= TREE_CODE (t
);
5374 /* The only valid NOP_EXPR is the empty statement. */
5375 return IS_EMPTY_STMT (t
);
5379 /* These are only valid if they're void. */
5380 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
5386 case CASE_LABEL_EXPR
:
5387 case TRY_CATCH_EXPR
:
5388 case TRY_FINALLY_EXPR
:
5389 case EH_FILTER_EXPR
:
5392 case STATEMENT_LIST
:
5396 case OACC_HOST_DATA
:
5399 case OACC_ENTER_DATA
:
5400 case OACC_EXIT_DATA
:
5405 case OMP_DISTRIBUTE
:
5416 case OMP_TARGET_DATA
:
5417 case OMP_TARGET_UPDATE
:
5418 case OMP_TARGET_ENTER_DATA
:
5419 case OMP_TARGET_EXIT_DATA
:
5422 /* These are always void. */
5428 /* These are valid regardless of their type. */
5437 /* Promote partial stores to COMPLEX variables to total stores. *EXPR_P is
5438 a MODIFY_EXPR with a lhs of a REAL/IMAGPART_EXPR of a variable with
5439 DECL_GIMPLE_REG_P set.
5441 IMPORTANT NOTE: This promotion is performed by introducing a load of the
5442 other, unmodified part of the complex object just before the total store.
5443 As a consequence, if the object is still uninitialized, an undefined value
5444 will be loaded into a register, which may result in a spurious exception
5445 if the register is floating-point and the value happens to be a signaling
5446 NaN for example. Then the fully-fledged complex operations lowering pass
5447 followed by a DCE pass are necessary in order to fix things up. */
5449 static enum gimplify_status
5450 gimplify_modify_expr_complex_part (tree
*expr_p
, gimple_seq
*pre_p
,
5453 enum tree_code code
, ocode
;
5454 tree lhs
, rhs
, new_rhs
, other
, realpart
, imagpart
;
5456 lhs
= TREE_OPERAND (*expr_p
, 0);
5457 rhs
= TREE_OPERAND (*expr_p
, 1);
5458 code
= TREE_CODE (lhs
);
5459 lhs
= TREE_OPERAND (lhs
, 0);
5461 ocode
= code
== REALPART_EXPR
? IMAGPART_EXPR
: REALPART_EXPR
;
5462 other
= build1 (ocode
, TREE_TYPE (rhs
), lhs
);
5463 TREE_NO_WARNING (other
) = 1;
5464 other
= get_formal_tmp_var (other
, pre_p
);
5466 realpart
= code
== REALPART_EXPR
? rhs
: other
;
5467 imagpart
= code
== REALPART_EXPR
? other
: rhs
;
5469 if (TREE_CONSTANT (realpart
) && TREE_CONSTANT (imagpart
))
5470 new_rhs
= build_complex (TREE_TYPE (lhs
), realpart
, imagpart
);
5472 new_rhs
= build2 (COMPLEX_EXPR
, TREE_TYPE (lhs
), realpart
, imagpart
);
5474 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (lhs
, new_rhs
));
5475 *expr_p
= (want_value
) ? rhs
: NULL_TREE
;
5480 /* Gimplify the MODIFY_EXPR node pointed to by EXPR_P.
5486 PRE_P points to the list where side effects that must happen before
5487 *EXPR_P should be stored.
5489 POST_P points to the list where side effects that must happen after
5490 *EXPR_P should be stored.
5492 WANT_VALUE is nonzero iff we want to use the value of this expression
5493 in another expression. */
5495 static enum gimplify_status
5496 gimplify_modify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
5499 tree
*from_p
= &TREE_OPERAND (*expr_p
, 1);
5500 tree
*to_p
= &TREE_OPERAND (*expr_p
, 0);
5501 enum gimplify_status ret
= GS_UNHANDLED
;
5503 location_t loc
= EXPR_LOCATION (*expr_p
);
5504 gimple_stmt_iterator gsi
;
5506 gcc_assert (TREE_CODE (*expr_p
) == MODIFY_EXPR
5507 || TREE_CODE (*expr_p
) == INIT_EXPR
);
5509 /* Trying to simplify a clobber using normal logic doesn't work,
5510 so handle it here. */
5511 if (TREE_CLOBBER_P (*from_p
))
5513 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
5514 if (ret
== GS_ERROR
)
5516 gcc_assert (!want_value
);
5517 if (!VAR_P (*to_p
) && TREE_CODE (*to_p
) != MEM_REF
)
5519 tree addr
= get_initialized_tmp_var (build_fold_addr_expr (*to_p
),
5521 *to_p
= build_simple_mem_ref_loc (EXPR_LOCATION (*to_p
), addr
);
5523 gimplify_seq_add_stmt (pre_p
, gimple_build_assign (*to_p
, *from_p
));
5528 /* Insert pointer conversions required by the middle-end that are not
5529 required by the frontend. This fixes middle-end type checking for
5530 for example gcc.dg/redecl-6.c. */
5531 if (POINTER_TYPE_P (TREE_TYPE (*to_p
)))
5533 STRIP_USELESS_TYPE_CONVERSION (*from_p
);
5534 if (!useless_type_conversion_p (TREE_TYPE (*to_p
), TREE_TYPE (*from_p
)))
5535 *from_p
= fold_convert_loc (loc
, TREE_TYPE (*to_p
), *from_p
);
5538 /* See if any simplifications can be done based on what the RHS is. */
5539 ret
= gimplify_modify_expr_rhs (expr_p
, from_p
, to_p
, pre_p
, post_p
,
5541 if (ret
!= GS_UNHANDLED
)
5544 /* For zero sized types only gimplify the left hand side and right hand
5545 side as statements and throw away the assignment. Do this after
5546 gimplify_modify_expr_rhs so we handle TARGET_EXPRs of addressable
5548 if (zero_sized_type (TREE_TYPE (*from_p
))
5550 /* Don't do this for calls that return addressable types, expand_call
5551 relies on those having a lhs. */
5552 && !(TREE_ADDRESSABLE (TREE_TYPE (*from_p
))
5553 && TREE_CODE (*from_p
) == CALL_EXPR
))
5555 gimplify_stmt (from_p
, pre_p
);
5556 gimplify_stmt (to_p
, pre_p
);
5557 *expr_p
= NULL_TREE
;
5561 /* If the value being copied is of variable width, compute the length
5562 of the copy into a WITH_SIZE_EXPR. Note that we need to do this
5563 before gimplifying any of the operands so that we can resolve any
5564 PLACEHOLDER_EXPRs in the size. Also note that the RTL expander uses
5565 the size of the expression to be copied, not of the destination, so
5566 that is what we must do here. */
5567 maybe_with_size_expr (from_p
);
5569 /* As a special case, we have to temporarily allow for assignments
5570 with a CALL_EXPR on the RHS. Since in GIMPLE a function call is
5571 a toplevel statement, when gimplifying the GENERIC expression
5572 MODIFY_EXPR <a, CALL_EXPR <foo>>, we cannot create the tuple
5573 GIMPLE_ASSIGN <a, GIMPLE_CALL <foo>>.
5575 Instead, we need to create the tuple GIMPLE_CALL <a, foo>. To
5576 prevent gimplify_expr from trying to create a new temporary for
5577 foo's LHS, we tell it that it should only gimplify until it
5578 reaches the CALL_EXPR. On return from gimplify_expr, the newly
5579 created GIMPLE_CALL <foo> will be the last statement in *PRE_P
5580 and all we need to do here is set 'a' to be its LHS. */
5582 /* Gimplify the RHS first for C++17 and bug 71104. */
5583 gimple_predicate initial_pred
= initial_rhs_predicate_for (*to_p
);
5584 ret
= gimplify_expr (from_p
, pre_p
, post_p
, initial_pred
, fb_rvalue
);
5585 if (ret
== GS_ERROR
)
5588 /* Then gimplify the LHS. */
5589 /* If we gimplified the RHS to a CALL_EXPR and that call may return
5590 twice we have to make sure to gimplify into non-SSA as otherwise
5591 the abnormal edge added later will make those defs not dominate
5593 ??? Technically this applies only to the registers used in the
5594 resulting non-register *TO_P. */
5595 bool saved_into_ssa
= gimplify_ctxp
->into_ssa
;
5597 && TREE_CODE (*from_p
) == CALL_EXPR
5598 && call_expr_flags (*from_p
) & ECF_RETURNS_TWICE
)
5599 gimplify_ctxp
->into_ssa
= false;
5600 ret
= gimplify_expr (to_p
, pre_p
, post_p
, is_gimple_lvalue
, fb_lvalue
);
5601 gimplify_ctxp
->into_ssa
= saved_into_ssa
;
5602 if (ret
== GS_ERROR
)
5605 /* Now that the LHS is gimplified, re-gimplify the RHS if our initial
5606 guess for the predicate was wrong. */
5607 gimple_predicate final_pred
= rhs_predicate_for (*to_p
);
5608 if (final_pred
!= initial_pred
)
5610 ret
= gimplify_expr (from_p
, pre_p
, post_p
, final_pred
, fb_rvalue
);
5611 if (ret
== GS_ERROR
)
5615 /* In case of va_arg internal fn wrappped in a WITH_SIZE_EXPR, add the type
5616 size as argument to the call. */
5617 if (TREE_CODE (*from_p
) == WITH_SIZE_EXPR
)
5619 tree call
= TREE_OPERAND (*from_p
, 0);
5620 tree vlasize
= TREE_OPERAND (*from_p
, 1);
5622 if (TREE_CODE (call
) == CALL_EXPR
5623 && CALL_EXPR_IFN (call
) == IFN_VA_ARG
)
5625 int nargs
= call_expr_nargs (call
);
5626 tree type
= TREE_TYPE (call
);
5627 tree ap
= CALL_EXPR_ARG (call
, 0);
5628 tree tag
= CALL_EXPR_ARG (call
, 1);
5629 tree aptag
= CALL_EXPR_ARG (call
, 2);
5630 tree newcall
= build_call_expr_internal_loc (EXPR_LOCATION (call
),
5634 TREE_OPERAND (*from_p
, 0) = newcall
;
5638 /* Now see if the above changed *from_p to something we handle specially. */
5639 ret
= gimplify_modify_expr_rhs (expr_p
, from_p
, to_p
, pre_p
, post_p
,
5641 if (ret
!= GS_UNHANDLED
)
5644 /* If we've got a variable sized assignment between two lvalues (i.e. does
5645 not involve a call), then we can make things a bit more straightforward
5646 by converting the assignment to memcpy or memset. */
5647 if (TREE_CODE (*from_p
) == WITH_SIZE_EXPR
)
5649 tree from
= TREE_OPERAND (*from_p
, 0);
5650 tree size
= TREE_OPERAND (*from_p
, 1);
5652 if (TREE_CODE (from
) == CONSTRUCTOR
)
5653 return gimplify_modify_expr_to_memset (expr_p
, size
, want_value
, pre_p
);
5655 if (is_gimple_addressable (from
))
5658 return gimplify_modify_expr_to_memcpy (expr_p
, size
, want_value
,
5663 /* Transform partial stores to non-addressable complex variables into
5664 total stores. This allows us to use real instead of virtual operands
5665 for these variables, which improves optimization. */
5666 if ((TREE_CODE (*to_p
) == REALPART_EXPR
5667 || TREE_CODE (*to_p
) == IMAGPART_EXPR
)
5668 && is_gimple_reg (TREE_OPERAND (*to_p
, 0)))
5669 return gimplify_modify_expr_complex_part (expr_p
, pre_p
, want_value
);
5671 /* Try to alleviate the effects of the gimplification creating artificial
5672 temporaries (see for example is_gimple_reg_rhs) on the debug info, but
5673 make sure not to create DECL_DEBUG_EXPR links across functions. */
5674 if (!gimplify_ctxp
->into_ssa
5676 && DECL_IGNORED_P (*from_p
)
5678 && !DECL_IGNORED_P (*to_p
)
5679 && decl_function_context (*to_p
) == current_function_decl
5680 && decl_function_context (*from_p
) == current_function_decl
)
5682 if (!DECL_NAME (*from_p
) && DECL_NAME (*to_p
))
5684 = create_tmp_var_name (IDENTIFIER_POINTER (DECL_NAME (*to_p
)));
5685 DECL_HAS_DEBUG_EXPR_P (*from_p
) = 1;
5686 SET_DECL_DEBUG_EXPR (*from_p
, *to_p
);
5689 if (want_value
&& TREE_THIS_VOLATILE (*to_p
))
5690 *from_p
= get_initialized_tmp_var (*from_p
, pre_p
, post_p
);
5692 if (TREE_CODE (*from_p
) == CALL_EXPR
)
5694 /* Since the RHS is a CALL_EXPR, we need to create a GIMPLE_CALL
5695 instead of a GIMPLE_ASSIGN. */
5697 if (CALL_EXPR_FN (*from_p
) == NULL_TREE
)
5699 /* Gimplify internal functions created in the FEs. */
5700 int nargs
= call_expr_nargs (*from_p
), i
;
5701 enum internal_fn ifn
= CALL_EXPR_IFN (*from_p
);
5702 auto_vec
<tree
> vargs (nargs
);
5704 for (i
= 0; i
< nargs
; i
++)
5706 gimplify_arg (&CALL_EXPR_ARG (*from_p
, i
), pre_p
,
5707 EXPR_LOCATION (*from_p
));
5708 vargs
.quick_push (CALL_EXPR_ARG (*from_p
, i
));
5710 call_stmt
= gimple_build_call_internal_vec (ifn
, vargs
);
5711 gimple_call_set_nothrow (call_stmt
, TREE_NOTHROW (*from_p
));
5712 gimple_set_location (call_stmt
, EXPR_LOCATION (*expr_p
));
5716 tree fnptrtype
= TREE_TYPE (CALL_EXPR_FN (*from_p
));
5717 CALL_EXPR_FN (*from_p
) = TREE_OPERAND (CALL_EXPR_FN (*from_p
), 0);
5718 STRIP_USELESS_TYPE_CONVERSION (CALL_EXPR_FN (*from_p
));
5719 tree fndecl
= get_callee_fndecl (*from_p
);
5721 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
5722 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_EXPECT
5723 && call_expr_nargs (*from_p
) == 3)
5724 call_stmt
= gimple_build_call_internal (IFN_BUILTIN_EXPECT
, 3,
5725 CALL_EXPR_ARG (*from_p
, 0),
5726 CALL_EXPR_ARG (*from_p
, 1),
5727 CALL_EXPR_ARG (*from_p
, 2));
5730 call_stmt
= gimple_build_call_from_tree (*from_p
, fnptrtype
);
5733 notice_special_calls (call_stmt
);
5734 if (!gimple_call_noreturn_p (call_stmt
) || !should_remove_lhs_p (*to_p
))
5735 gimple_call_set_lhs (call_stmt
, *to_p
);
5736 else if (TREE_CODE (*to_p
) == SSA_NAME
)
5737 /* The above is somewhat premature, avoid ICEing later for a
5738 SSA name w/o a definition. We may have uses in the GIMPLE IL.
5739 ??? This doesn't make it a default-def. */
5740 SSA_NAME_DEF_STMT (*to_p
) = gimple_build_nop ();
5746 assign
= gimple_build_assign (*to_p
, *from_p
);
5747 gimple_set_location (assign
, EXPR_LOCATION (*expr_p
));
5748 if (COMPARISON_CLASS_P (*from_p
))
5749 gimple_set_no_warning (assign
, TREE_NO_WARNING (*from_p
));
5752 if (gimplify_ctxp
->into_ssa
&& is_gimple_reg (*to_p
))
5754 /* We should have got an SSA name from the start. */
5755 gcc_assert (TREE_CODE (*to_p
) == SSA_NAME
5756 || ! gimple_in_ssa_p (cfun
));
5759 gimplify_seq_add_stmt (pre_p
, assign
);
5760 gsi
= gsi_last (*pre_p
);
5761 maybe_fold_stmt (&gsi
);
5765 *expr_p
= TREE_THIS_VOLATILE (*to_p
) ? *from_p
: unshare_expr (*to_p
);
5774 /* Gimplify a comparison between two variable-sized objects. Do this
5775 with a call to BUILT_IN_MEMCMP. */
5777 static enum gimplify_status
5778 gimplify_variable_sized_compare (tree
*expr_p
)
5780 location_t loc
= EXPR_LOCATION (*expr_p
);
5781 tree op0
= TREE_OPERAND (*expr_p
, 0);
5782 tree op1
= TREE_OPERAND (*expr_p
, 1);
5783 tree t
, arg
, dest
, src
, expr
;
5785 arg
= TYPE_SIZE_UNIT (TREE_TYPE (op0
));
5786 arg
= unshare_expr (arg
);
5787 arg
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (arg
, op0
);
5788 src
= build_fold_addr_expr_loc (loc
, op1
);
5789 dest
= build_fold_addr_expr_loc (loc
, op0
);
5790 t
= builtin_decl_implicit (BUILT_IN_MEMCMP
);
5791 t
= build_call_expr_loc (loc
, t
, 3, dest
, src
, arg
);
5794 = build2 (TREE_CODE (*expr_p
), TREE_TYPE (*expr_p
), t
, integer_zero_node
);
5795 SET_EXPR_LOCATION (expr
, loc
);
5801 /* Gimplify a comparison between two aggregate objects of integral scalar
5802 mode as a comparison between the bitwise equivalent scalar values. */
5804 static enum gimplify_status
5805 gimplify_scalar_mode_aggregate_compare (tree
*expr_p
)
5807 location_t loc
= EXPR_LOCATION (*expr_p
);
5808 tree op0
= TREE_OPERAND (*expr_p
, 0);
5809 tree op1
= TREE_OPERAND (*expr_p
, 1);
5811 tree type
= TREE_TYPE (op0
);
5812 tree scalar_type
= lang_hooks
.types
.type_for_mode (TYPE_MODE (type
), 1);
5814 op0
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, scalar_type
, op0
);
5815 op1
= fold_build1_loc (loc
, VIEW_CONVERT_EXPR
, scalar_type
, op1
);
5818 = fold_build2_loc (loc
, TREE_CODE (*expr_p
), TREE_TYPE (*expr_p
), op0
, op1
);
5823 /* Gimplify an expression sequence. This function gimplifies each
5824 expression and rewrites the original expression with the last
5825 expression of the sequence in GIMPLE form.
5827 PRE_P points to the list where the side effects for all the
5828 expressions in the sequence will be emitted.
5830 WANT_VALUE is true when the result of the last COMPOUND_EXPR is used. */
5832 static enum gimplify_status
5833 gimplify_compound_expr (tree
*expr_p
, gimple_seq
*pre_p
, bool want_value
)
5839 tree
*sub_p
= &TREE_OPERAND (t
, 0);
5841 if (TREE_CODE (*sub_p
) == COMPOUND_EXPR
)
5842 gimplify_compound_expr (sub_p
, pre_p
, false);
5844 gimplify_stmt (sub_p
, pre_p
);
5846 t
= TREE_OPERAND (t
, 1);
5848 while (TREE_CODE (t
) == COMPOUND_EXPR
);
5855 gimplify_stmt (expr_p
, pre_p
);
5860 /* Gimplify a SAVE_EXPR node. EXPR_P points to the expression to
5861 gimplify. After gimplification, EXPR_P will point to a new temporary
5862 that holds the original value of the SAVE_EXPR node.
5864 PRE_P points to the list where side effects that must happen before
5865 *EXPR_P should be stored. */
5867 static enum gimplify_status
5868 gimplify_save_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
5870 enum gimplify_status ret
= GS_ALL_DONE
;
5873 gcc_assert (TREE_CODE (*expr_p
) == SAVE_EXPR
);
5874 val
= TREE_OPERAND (*expr_p
, 0);
5876 /* If the SAVE_EXPR has not been resolved, then evaluate it once. */
5877 if (!SAVE_EXPR_RESOLVED_P (*expr_p
))
5879 /* The operand may be a void-valued expression. It is
5880 being executed only for its side-effects. */
5881 if (TREE_TYPE (val
) == void_type_node
)
5883 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
5884 is_gimple_stmt
, fb_none
);
5888 /* The temporary may not be an SSA name as later abnormal and EH
5889 control flow may invalidate use/def domination. When in SSA
5890 form then assume there are no such issues and SAVE_EXPRs only
5891 appear via GENERIC foldings. */
5892 val
= get_initialized_tmp_var (val
, pre_p
, post_p
,
5893 gimple_in_ssa_p (cfun
));
5895 TREE_OPERAND (*expr_p
, 0) = val
;
5896 SAVE_EXPR_RESOLVED_P (*expr_p
) = 1;
5904 /* Rewrite the ADDR_EXPR node pointed to by EXPR_P
5911 PRE_P points to the list where side effects that must happen before
5912 *EXPR_P should be stored.
5914 POST_P points to the list where side effects that must happen after
5915 *EXPR_P should be stored. */
5917 static enum gimplify_status
5918 gimplify_addr_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
5920 tree expr
= *expr_p
;
5921 tree op0
= TREE_OPERAND (expr
, 0);
5922 enum gimplify_status ret
;
5923 location_t loc
= EXPR_LOCATION (*expr_p
);
5925 switch (TREE_CODE (op0
))
5929 /* Check if we are dealing with an expression of the form '&*ptr'.
5930 While the front end folds away '&*ptr' into 'ptr', these
5931 expressions may be generated internally by the compiler (e.g.,
5932 builtins like __builtin_va_end). */
5933 /* Caution: the silent array decomposition semantics we allow for
5934 ADDR_EXPR means we can't always discard the pair. */
5935 /* Gimplification of the ADDR_EXPR operand may drop
5936 cv-qualification conversions, so make sure we add them if
5939 tree op00
= TREE_OPERAND (op0
, 0);
5940 tree t_expr
= TREE_TYPE (expr
);
5941 tree t_op00
= TREE_TYPE (op00
);
5943 if (!useless_type_conversion_p (t_expr
, t_op00
))
5944 op00
= fold_convert_loc (loc
, TREE_TYPE (expr
), op00
);
5950 case VIEW_CONVERT_EXPR
:
5951 /* Take the address of our operand and then convert it to the type of
5954 ??? The interactions of VIEW_CONVERT_EXPR and aliasing is not at
5955 all clear. The impact of this transformation is even less clear. */
5957 /* If the operand is a useless conversion, look through it. Doing so
5958 guarantees that the ADDR_EXPR and its operand will remain of the
5960 if (tree_ssa_useless_type_conversion (TREE_OPERAND (op0
, 0)))
5961 op0
= TREE_OPERAND (op0
, 0);
5963 *expr_p
= fold_convert_loc (loc
, TREE_TYPE (expr
),
5964 build_fold_addr_expr_loc (loc
,
5965 TREE_OPERAND (op0
, 0)));
5970 if (integer_zerop (TREE_OPERAND (op0
, 1)))
5971 goto do_indirect_ref
;
5976 /* If we see a call to a declared builtin or see its address
5977 being taken (we can unify those cases here) then we can mark
5978 the builtin for implicit generation by GCC. */
5979 if (TREE_CODE (op0
) == FUNCTION_DECL
5980 && DECL_BUILT_IN_CLASS (op0
) == BUILT_IN_NORMAL
5981 && builtin_decl_declared_p (DECL_FUNCTION_CODE (op0
)))
5982 set_builtin_decl_implicit_p (DECL_FUNCTION_CODE (op0
), true);
5984 /* We use fb_either here because the C frontend sometimes takes
5985 the address of a call that returns a struct; see
5986 gcc.dg/c99-array-lval-1.c. The gimplifier will correctly make
5987 the implied temporary explicit. */
5989 /* Make the operand addressable. */
5990 ret
= gimplify_expr (&TREE_OPERAND (expr
, 0), pre_p
, post_p
,
5991 is_gimple_addressable
, fb_either
);
5992 if (ret
== GS_ERROR
)
5995 /* Then mark it. Beware that it may not be possible to do so directly
5996 if a temporary has been created by the gimplification. */
5997 prepare_gimple_addressable (&TREE_OPERAND (expr
, 0), pre_p
);
5999 op0
= TREE_OPERAND (expr
, 0);
6001 /* For various reasons, the gimplification of the expression
6002 may have made a new INDIRECT_REF. */
6003 if (TREE_CODE (op0
) == INDIRECT_REF
)
6004 goto do_indirect_ref
;
6006 mark_addressable (TREE_OPERAND (expr
, 0));
6008 /* The FEs may end up building ADDR_EXPRs early on a decl with
6009 an incomplete type. Re-build ADDR_EXPRs in canonical form
6011 if (!types_compatible_p (TREE_TYPE (op0
), TREE_TYPE (TREE_TYPE (expr
))))
6012 *expr_p
= build_fold_addr_expr (op0
);
6014 /* Make sure TREE_CONSTANT and TREE_SIDE_EFFECTS are set properly. */
6015 recompute_tree_invariant_for_addr_expr (*expr_p
);
6017 /* If we re-built the ADDR_EXPR add a conversion to the original type
6019 if (!useless_type_conversion_p (TREE_TYPE (expr
), TREE_TYPE (*expr_p
)))
6020 *expr_p
= fold_convert (TREE_TYPE (expr
), *expr_p
);
6028 /* Gimplify the operands of an ASM_EXPR. Input operands should be a gimple
6029 value; output operands should be a gimple lvalue. */
6031 static enum gimplify_status
6032 gimplify_asm_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
6036 const char **oconstraints
;
6039 const char *constraint
;
6040 bool allows_mem
, allows_reg
, is_inout
;
6041 enum gimplify_status ret
, tret
;
6043 vec
<tree
, va_gc
> *inputs
;
6044 vec
<tree
, va_gc
> *outputs
;
6045 vec
<tree
, va_gc
> *clobbers
;
6046 vec
<tree
, va_gc
> *labels
;
6050 noutputs
= list_length (ASM_OUTPUTS (expr
));
6051 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
6059 link_next
= NULL_TREE
;
6060 for (i
= 0, link
= ASM_OUTPUTS (expr
); link
; ++i
, link
= link_next
)
6063 size_t constraint_len
;
6065 link_next
= TREE_CHAIN (link
);
6069 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
6070 constraint_len
= strlen (constraint
);
6071 if (constraint_len
== 0)
6074 ok
= parse_output_constraint (&constraint
, i
, 0, 0,
6075 &allows_mem
, &allows_reg
, &is_inout
);
6082 if (!allows_reg
&& allows_mem
)
6083 mark_addressable (TREE_VALUE (link
));
6085 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6086 is_inout
? is_gimple_min_lval
: is_gimple_lvalue
,
6087 fb_lvalue
| fb_mayfail
);
6088 if (tret
== GS_ERROR
)
6090 error ("invalid lvalue in asm output %d", i
);
6094 /* If the constraint does not allow memory make sure we gimplify
6095 it to a register if it is not already but its base is. This
6096 happens for complex and vector components. */
6099 tree op
= TREE_VALUE (link
);
6100 if (! is_gimple_val (op
)
6101 && is_gimple_reg_type (TREE_TYPE (op
))
6102 && is_gimple_reg (get_base_address (op
)))
6104 tree tem
= create_tmp_reg (TREE_TYPE (op
));
6108 ass
= build2 (MODIFY_EXPR
, TREE_TYPE (tem
),
6109 tem
, unshare_expr (op
));
6110 gimplify_and_add (ass
, pre_p
);
6112 ass
= build2 (MODIFY_EXPR
, TREE_TYPE (tem
), op
, tem
);
6113 gimplify_and_add (ass
, post_p
);
6115 TREE_VALUE (link
) = tem
;
6120 vec_safe_push (outputs
, link
);
6121 TREE_CHAIN (link
) = NULL_TREE
;
6125 /* An input/output operand. To give the optimizers more
6126 flexibility, split it into separate input and output
6129 /* Buffer big enough to format a 32-bit UINT_MAX into. */
6132 /* Turn the in/out constraint into an output constraint. */
6133 char *p
= xstrdup (constraint
);
6135 TREE_VALUE (TREE_PURPOSE (link
)) = build_string (constraint_len
, p
);
6137 /* And add a matching input constraint. */
6140 sprintf (buf
, "%u", i
);
6142 /* If there are multiple alternatives in the constraint,
6143 handle each of them individually. Those that allow register
6144 will be replaced with operand number, the others will stay
6146 if (strchr (p
, ',') != NULL
)
6148 size_t len
= 0, buflen
= strlen (buf
);
6149 char *beg
, *end
, *str
, *dst
;
6153 end
= strchr (beg
, ',');
6155 end
= strchr (beg
, '\0');
6156 if ((size_t) (end
- beg
) < buflen
)
6159 len
+= end
- beg
+ 1;
6166 str
= (char *) alloca (len
);
6167 for (beg
= p
+ 1, dst
= str
;;)
6170 bool mem_p
, reg_p
, inout_p
;
6172 end
= strchr (beg
, ',');
6177 parse_output_constraint (&tem
, i
, 0, 0,
6178 &mem_p
, ®_p
, &inout_p
);
6183 memcpy (dst
, buf
, buflen
);
6192 memcpy (dst
, beg
, len
);
6201 input
= build_string (dst
- str
, str
);
6204 input
= build_string (strlen (buf
), buf
);
6207 input
= build_string (constraint_len
- 1, constraint
+ 1);
6211 input
= build_tree_list (build_tree_list (NULL_TREE
, input
),
6212 unshare_expr (TREE_VALUE (link
)));
6213 ASM_INPUTS (expr
) = chainon (ASM_INPUTS (expr
), input
);
6217 link_next
= NULL_TREE
;
6218 for (link
= ASM_INPUTS (expr
); link
; ++i
, link
= link_next
)
6220 link_next
= TREE_CHAIN (link
);
6221 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
6222 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
6223 oconstraints
, &allows_mem
, &allows_reg
);
6225 /* If we can't make copies, we can only accept memory. */
6226 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link
))))
6232 error ("impossible constraint in %<asm%>");
6233 error ("non-memory input %d must stay in memory", i
);
6238 /* If the operand is a memory input, it should be an lvalue. */
6239 if (!allows_reg
&& allows_mem
)
6241 tree inputv
= TREE_VALUE (link
);
6242 STRIP_NOPS (inputv
);
6243 if (TREE_CODE (inputv
) == PREDECREMENT_EXPR
6244 || TREE_CODE (inputv
) == PREINCREMENT_EXPR
6245 || TREE_CODE (inputv
) == POSTDECREMENT_EXPR
6246 || TREE_CODE (inputv
) == POSTINCREMENT_EXPR
6247 || TREE_CODE (inputv
) == MODIFY_EXPR
)
6248 TREE_VALUE (link
) = error_mark_node
;
6249 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6250 is_gimple_lvalue
, fb_lvalue
| fb_mayfail
);
6251 if (tret
!= GS_ERROR
)
6253 /* Unlike output operands, memory inputs are not guaranteed
6254 to be lvalues by the FE, and while the expressions are
6255 marked addressable there, if it is e.g. a statement
6256 expression, temporaries in it might not end up being
6257 addressable. They might be already used in the IL and thus
6258 it is too late to make them addressable now though. */
6259 tree x
= TREE_VALUE (link
);
6260 while (handled_component_p (x
))
6261 x
= TREE_OPERAND (x
, 0);
6262 if (TREE_CODE (x
) == MEM_REF
6263 && TREE_CODE (TREE_OPERAND (x
, 0)) == ADDR_EXPR
)
6264 x
= TREE_OPERAND (TREE_OPERAND (x
, 0), 0);
6266 || TREE_CODE (x
) == PARM_DECL
6267 || TREE_CODE (x
) == RESULT_DECL
)
6268 && !TREE_ADDRESSABLE (x
)
6269 && is_gimple_reg (x
))
6271 warning_at (EXPR_LOC_OR_LOC (TREE_VALUE (link
),
6273 "memory input %d is not directly addressable",
6275 prepare_gimple_addressable (&TREE_VALUE (link
), pre_p
);
6278 mark_addressable (TREE_VALUE (link
));
6279 if (tret
== GS_ERROR
)
6281 error_at (EXPR_LOC_OR_LOC (TREE_VALUE (link
), input_location
),
6282 "memory input %d is not directly addressable", i
);
6288 tret
= gimplify_expr (&TREE_VALUE (link
), pre_p
, post_p
,
6289 is_gimple_asm_val
, fb_rvalue
);
6290 if (tret
== GS_ERROR
)
6294 TREE_CHAIN (link
) = NULL_TREE
;
6295 vec_safe_push (inputs
, link
);
6298 link_next
= NULL_TREE
;
6299 for (link
= ASM_CLOBBERS (expr
); link
; ++i
, link
= link_next
)
6301 link_next
= TREE_CHAIN (link
);
6302 TREE_CHAIN (link
) = NULL_TREE
;
6303 vec_safe_push (clobbers
, link
);
6306 link_next
= NULL_TREE
;
6307 for (link
= ASM_LABELS (expr
); link
; ++i
, link
= link_next
)
6309 link_next
= TREE_CHAIN (link
);
6310 TREE_CHAIN (link
) = NULL_TREE
;
6311 vec_safe_push (labels
, link
);
6314 /* Do not add ASMs with errors to the gimple IL stream. */
6315 if (ret
!= GS_ERROR
)
6317 stmt
= gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr
)),
6318 inputs
, outputs
, clobbers
, labels
);
6320 gimple_asm_set_volatile (stmt
, ASM_VOLATILE_P (expr
) || noutputs
== 0);
6321 gimple_asm_set_input (stmt
, ASM_INPUT_P (expr
));
6323 gimplify_seq_add_stmt (pre_p
, stmt
);
6329 /* Gimplify a CLEANUP_POINT_EXPR. Currently this works by adding
6330 GIMPLE_WITH_CLEANUP_EXPRs to the prequeue as we encounter cleanups while
6331 gimplifying the body, and converting them to TRY_FINALLY_EXPRs when we
6332 return to this function.
6334 FIXME should we complexify the prequeue handling instead? Or use flags
6335 for all the cleanups and let the optimizer tighten them up? The current
6336 code seems pretty fragile; it will break on a cleanup within any
6337 non-conditional nesting. But any such nesting would be broken, anyway;
6338 we can't write a TRY_FINALLY_EXPR that starts inside a nesting construct
6339 and continues out of it. We can do that at the RTL level, though, so
6340 having an optimizer to tighten up try/finally regions would be a Good
6343 static enum gimplify_status
6344 gimplify_cleanup_point_expr (tree
*expr_p
, gimple_seq
*pre_p
)
6346 gimple_stmt_iterator iter
;
6347 gimple_seq body_sequence
= NULL
;
6349 tree temp
= voidify_wrapper_expr (*expr_p
, NULL
);
6351 /* We only care about the number of conditions between the innermost
6352 CLEANUP_POINT_EXPR and the cleanup. So save and reset the count and
6353 any cleanups collected outside the CLEANUP_POINT_EXPR. */
6354 int old_conds
= gimplify_ctxp
->conditions
;
6355 gimple_seq old_cleanups
= gimplify_ctxp
->conditional_cleanups
;
6356 bool old_in_cleanup_point_expr
= gimplify_ctxp
->in_cleanup_point_expr
;
6357 gimplify_ctxp
->conditions
= 0;
6358 gimplify_ctxp
->conditional_cleanups
= NULL
;
6359 gimplify_ctxp
->in_cleanup_point_expr
= true;
6361 gimplify_stmt (&TREE_OPERAND (*expr_p
, 0), &body_sequence
);
6363 gimplify_ctxp
->conditions
= old_conds
;
6364 gimplify_ctxp
->conditional_cleanups
= old_cleanups
;
6365 gimplify_ctxp
->in_cleanup_point_expr
= old_in_cleanup_point_expr
;
6367 for (iter
= gsi_start (body_sequence
); !gsi_end_p (iter
); )
6369 gimple
*wce
= gsi_stmt (iter
);
6371 if (gimple_code (wce
) == GIMPLE_WITH_CLEANUP_EXPR
)
6373 if (gsi_one_before_end_p (iter
))
6375 /* Note that gsi_insert_seq_before and gsi_remove do not
6376 scan operands, unlike some other sequence mutators. */
6377 if (!gimple_wce_cleanup_eh_only (wce
))
6378 gsi_insert_seq_before_without_update (&iter
,
6379 gimple_wce_cleanup (wce
),
6381 gsi_remove (&iter
, true);
6388 enum gimple_try_flags kind
;
6390 if (gimple_wce_cleanup_eh_only (wce
))
6391 kind
= GIMPLE_TRY_CATCH
;
6393 kind
= GIMPLE_TRY_FINALLY
;
6394 seq
= gsi_split_seq_after (iter
);
6396 gtry
= gimple_build_try (seq
, gimple_wce_cleanup (wce
), kind
);
6397 /* Do not use gsi_replace here, as it may scan operands.
6398 We want to do a simple structural modification only. */
6399 gsi_set_stmt (&iter
, gtry
);
6400 iter
= gsi_start (gtry
->eval
);
6407 gimplify_seq_add_seq (pre_p
, body_sequence
);
6420 /* Insert a cleanup marker for gimplify_cleanup_point_expr. CLEANUP
6421 is the cleanup action required. EH_ONLY is true if the cleanup should
6422 only be executed if an exception is thrown, not on normal exit.
6423 If FORCE_UNCOND is true perform the cleanup unconditionally; this is
6424 only valid for clobbers. */
6427 gimple_push_cleanup (tree var
, tree cleanup
, bool eh_only
, gimple_seq
*pre_p
,
6428 bool force_uncond
= false)
6431 gimple_seq cleanup_stmts
= NULL
;
6433 /* Errors can result in improperly nested cleanups. Which results in
6434 confusion when trying to resolve the GIMPLE_WITH_CLEANUP_EXPR. */
6438 if (gimple_conditional_context ())
6440 /* If we're in a conditional context, this is more complex. We only
6441 want to run the cleanup if we actually ran the initialization that
6442 necessitates it, but we want to run it after the end of the
6443 conditional context. So we wrap the try/finally around the
6444 condition and use a flag to determine whether or not to actually
6445 run the destructor. Thus
6449 becomes (approximately)
6453 if (test) { A::A(temp); flag = 1; val = f(temp); }
6456 if (flag) A::~A(temp);
6462 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6463 wce
= gimple_build_wce (cleanup_stmts
);
6464 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, wce
);
6468 tree flag
= create_tmp_var (boolean_type_node
, "cleanup");
6469 gassign
*ffalse
= gimple_build_assign (flag
, boolean_false_node
);
6470 gassign
*ftrue
= gimple_build_assign (flag
, boolean_true_node
);
6472 cleanup
= build3 (COND_EXPR
, void_type_node
, flag
, cleanup
, NULL
);
6473 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6474 wce
= gimple_build_wce (cleanup_stmts
);
6476 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, ffalse
);
6477 gimplify_seq_add_stmt (&gimplify_ctxp
->conditional_cleanups
, wce
);
6478 gimplify_seq_add_stmt (pre_p
, ftrue
);
6480 /* Because of this manipulation, and the EH edges that jump
6481 threading cannot redirect, the temporary (VAR) will appear
6482 to be used uninitialized. Don't warn. */
6483 TREE_NO_WARNING (var
) = 1;
6488 gimplify_stmt (&cleanup
, &cleanup_stmts
);
6489 wce
= gimple_build_wce (cleanup_stmts
);
6490 gimple_wce_set_cleanup_eh_only (wce
, eh_only
);
6491 gimplify_seq_add_stmt (pre_p
, wce
);
6495 /* Gimplify a TARGET_EXPR which doesn't appear on the rhs of an INIT_EXPR. */
6497 static enum gimplify_status
6498 gimplify_target_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
)
6500 tree targ
= *expr_p
;
6501 tree temp
= TARGET_EXPR_SLOT (targ
);
6502 tree init
= TARGET_EXPR_INITIAL (targ
);
6503 enum gimplify_status ret
;
6505 bool unpoison_empty_seq
= false;
6506 gimple_stmt_iterator unpoison_it
;
6510 tree cleanup
= NULL_TREE
;
6512 /* TARGET_EXPR temps aren't part of the enclosing block, so add it
6513 to the temps list. Handle also variable length TARGET_EXPRs. */
6514 if (TREE_CODE (DECL_SIZE (temp
)) != INTEGER_CST
)
6516 if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (temp
)))
6517 gimplify_type_sizes (TREE_TYPE (temp
), pre_p
);
6518 gimplify_vla_decl (temp
, pre_p
);
6522 /* Save location where we need to place unpoisoning. It's possible
6523 that a variable will be converted to needs_to_live_in_memory. */
6524 unpoison_it
= gsi_last (*pre_p
);
6525 unpoison_empty_seq
= gsi_end_p (unpoison_it
);
6527 gimple_add_tmp_var (temp
);
6530 /* If TARGET_EXPR_INITIAL is void, then the mere evaluation of the
6531 expression is supposed to initialize the slot. */
6532 if (VOID_TYPE_P (TREE_TYPE (init
)))
6533 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
6536 tree init_expr
= build2 (INIT_EXPR
, void_type_node
, temp
, init
);
6538 ret
= gimplify_expr (&init
, pre_p
, post_p
, is_gimple_stmt
, fb_none
);
6540 ggc_free (init_expr
);
6542 if (ret
== GS_ERROR
)
6544 /* PR c++/28266 Make sure this is expanded only once. */
6545 TARGET_EXPR_INITIAL (targ
) = NULL_TREE
;
6549 gimplify_and_add (init
, pre_p
);
6551 /* If needed, push the cleanup for the temp. */
6552 if (TARGET_EXPR_CLEANUP (targ
))
6554 if (CLEANUP_EH_ONLY (targ
))
6555 gimple_push_cleanup (temp
, TARGET_EXPR_CLEANUP (targ
),
6556 CLEANUP_EH_ONLY (targ
), pre_p
);
6558 cleanup
= TARGET_EXPR_CLEANUP (targ
);
6561 /* Add a clobber for the temporary going out of scope, like
6562 gimplify_bind_expr. */
6563 if (gimplify_ctxp
->in_cleanup_point_expr
6564 && needs_to_live_in_memory (temp
))
6566 if (flag_stack_reuse
== SR_ALL
)
6568 tree clobber
= build_clobber (TREE_TYPE (temp
));
6569 clobber
= build2 (MODIFY_EXPR
, TREE_TYPE (temp
), temp
, clobber
);
6570 gimple_push_cleanup (temp
, clobber
, false, pre_p
, true);
6572 if (asan_poisoned_variables
6573 && DECL_ALIGN (temp
) <= MAX_SUPPORTED_STACK_ALIGNMENT
6574 && dbg_cnt (asan_use_after_scope
)
6575 && !gimplify_omp_ctxp
)
6577 tree asan_cleanup
= build_asan_poison_call_expr (temp
);
6580 if (unpoison_empty_seq
)
6581 unpoison_it
= gsi_start (*pre_p
);
6583 asan_poison_variable (temp
, false, &unpoison_it
,
6584 unpoison_empty_seq
);
6585 gimple_push_cleanup (temp
, asan_cleanup
, false, pre_p
);
6590 gimple_push_cleanup (temp
, cleanup
, false, pre_p
);
6592 /* Only expand this once. */
6593 TREE_OPERAND (targ
, 3) = init
;
6594 TARGET_EXPR_INITIAL (targ
) = NULL_TREE
;
6597 /* We should have expanded this before. */
6598 gcc_assert (DECL_SEEN_IN_BIND_EXPR_P (temp
));
6604 /* Gimplification of expression trees. */
6606 /* Gimplify an expression which appears at statement context. The
6607 corresponding GIMPLE statements are added to *SEQ_P. If *SEQ_P is
6608 NULL, a new sequence is allocated.
6610 Return true if we actually added a statement to the queue. */
6613 gimplify_stmt (tree
*stmt_p
, gimple_seq
*seq_p
)
6615 gimple_seq_node last
;
6617 last
= gimple_seq_last (*seq_p
);
6618 gimplify_expr (stmt_p
, seq_p
, NULL
, is_gimple_stmt
, fb_none
);
6619 return last
!= gimple_seq_last (*seq_p
);
6622 /* Add FIRSTPRIVATE entries for DECL in the OpenMP the surrounding parallels
6623 to CTX. If entries already exist, force them to be some flavor of private.
6624 If there is no enclosing parallel, do nothing. */
6627 omp_firstprivatize_variable (struct gimplify_omp_ctx
*ctx
, tree decl
)
6631 if (decl
== NULL
|| !DECL_P (decl
) || ctx
->region_type
== ORT_NONE
)
6636 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
6639 if (n
->value
& GOVD_SHARED
)
6640 n
->value
= GOVD_FIRSTPRIVATE
| (n
->value
& GOVD_SEEN
);
6641 else if (n
->value
& GOVD_MAP
)
6642 n
->value
|= GOVD_MAP_TO_ONLY
;
6646 else if ((ctx
->region_type
& ORT_TARGET
) != 0)
6648 if (ctx
->target_map_scalars_firstprivate
)
6649 omp_add_variable (ctx
, decl
, GOVD_FIRSTPRIVATE
);
6651 omp_add_variable (ctx
, decl
, GOVD_MAP
| GOVD_MAP_TO_ONLY
);
6653 else if (ctx
->region_type
!= ORT_WORKSHARE
6654 && ctx
->region_type
!= ORT_SIMD
6655 && ctx
->region_type
!= ORT_ACC
6656 && !(ctx
->region_type
& ORT_TARGET_DATA
))
6657 omp_add_variable (ctx
, decl
, GOVD_FIRSTPRIVATE
);
6659 ctx
= ctx
->outer_context
;
6664 /* Similarly for each of the type sizes of TYPE. */
6667 omp_firstprivatize_type_sizes (struct gimplify_omp_ctx
*ctx
, tree type
)
6669 if (type
== NULL
|| type
== error_mark_node
)
6671 type
= TYPE_MAIN_VARIANT (type
);
6673 if (ctx
->privatized_types
->add (type
))
6676 switch (TREE_CODE (type
))
6682 case FIXED_POINT_TYPE
:
6683 omp_firstprivatize_variable (ctx
, TYPE_MIN_VALUE (type
));
6684 omp_firstprivatize_variable (ctx
, TYPE_MAX_VALUE (type
));
6688 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (type
));
6689 omp_firstprivatize_type_sizes (ctx
, TYPE_DOMAIN (type
));
6694 case QUAL_UNION_TYPE
:
6697 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
6698 if (TREE_CODE (field
) == FIELD_DECL
)
6700 omp_firstprivatize_variable (ctx
, DECL_FIELD_OFFSET (field
));
6701 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (field
));
6707 case REFERENCE_TYPE
:
6708 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (type
));
6715 omp_firstprivatize_variable (ctx
, TYPE_SIZE (type
));
6716 omp_firstprivatize_variable (ctx
, TYPE_SIZE_UNIT (type
));
6717 lang_hooks
.types
.omp_firstprivatize_type_sizes (ctx
, type
);
6720 /* Add an entry for DECL in the OMP context CTX with FLAGS. */
6723 omp_add_variable (struct gimplify_omp_ctx
*ctx
, tree decl
, unsigned int flags
)
6726 unsigned int nflags
;
6729 if (error_operand_p (decl
) || ctx
->region_type
== ORT_NONE
)
6732 /* Never elide decls whose type has TREE_ADDRESSABLE set. This means
6733 there are constructors involved somewhere. Exception is a shared clause,
6734 there is nothing privatized in that case. */
6735 if ((flags
& GOVD_SHARED
) == 0
6736 && (TREE_ADDRESSABLE (TREE_TYPE (decl
))
6737 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
))))
6740 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
6741 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
6743 /* We shouldn't be re-adding the decl with the same data
6745 gcc_assert ((n
->value
& GOVD_DATA_SHARE_CLASS
& flags
) == 0);
6746 nflags
= n
->value
| flags
;
6747 /* The only combination of data sharing classes we should see is
6748 FIRSTPRIVATE and LASTPRIVATE. However, OpenACC permits
6749 reduction variables to be used in data sharing clauses. */
6750 gcc_assert ((ctx
->region_type
& ORT_ACC
) != 0
6751 || ((nflags
& GOVD_DATA_SHARE_CLASS
)
6752 == (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
))
6753 || (flags
& GOVD_DATA_SHARE_CLASS
) == 0);
6758 /* When adding a variable-sized variable, we have to handle all sorts
6759 of additional bits of data: the pointer replacement variable, and
6760 the parameters of the type. */
6761 if (DECL_SIZE (decl
) && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
6763 /* Add the pointer replacement variable as PRIVATE if the variable
6764 replacement is private, else FIRSTPRIVATE since we'll need the
6765 address of the original variable either for SHARED, or for the
6766 copy into or out of the context. */
6767 if (!(flags
& GOVD_LOCAL
))
6769 if (flags
& GOVD_MAP
)
6770 nflags
= GOVD_MAP
| GOVD_MAP_TO_ONLY
| GOVD_EXPLICIT
;
6771 else if (flags
& GOVD_PRIVATE
)
6772 nflags
= GOVD_PRIVATE
;
6773 else if ((ctx
->region_type
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0
6774 && (flags
& GOVD_FIRSTPRIVATE
))
6775 nflags
= GOVD_PRIVATE
| GOVD_EXPLICIT
;
6777 nflags
= GOVD_FIRSTPRIVATE
;
6778 nflags
|= flags
& GOVD_SEEN
;
6779 t
= DECL_VALUE_EXPR (decl
);
6780 gcc_assert (TREE_CODE (t
) == INDIRECT_REF
);
6781 t
= TREE_OPERAND (t
, 0);
6782 gcc_assert (DECL_P (t
));
6783 omp_add_variable (ctx
, t
, nflags
);
6786 /* Add all of the variable and type parameters (which should have
6787 been gimplified to a formal temporary) as FIRSTPRIVATE. */
6788 omp_firstprivatize_variable (ctx
, DECL_SIZE_UNIT (decl
));
6789 omp_firstprivatize_variable (ctx
, DECL_SIZE (decl
));
6790 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (decl
));
6792 /* The variable-sized variable itself is never SHARED, only some form
6793 of PRIVATE. The sharing would take place via the pointer variable
6794 which we remapped above. */
6795 if (flags
& GOVD_SHARED
)
6796 flags
= GOVD_SHARED
| GOVD_DEBUG_PRIVATE
6797 | (flags
& (GOVD_SEEN
| GOVD_EXPLICIT
));
6799 /* We're going to make use of the TYPE_SIZE_UNIT at least in the
6800 alloca statement we generate for the variable, so make sure it
6801 is available. This isn't automatically needed for the SHARED
6802 case, since we won't be allocating local storage then.
6803 For local variables TYPE_SIZE_UNIT might not be gimplified yet,
6804 in this case omp_notice_variable will be called later
6805 on when it is gimplified. */
6806 else if (! (flags
& (GOVD_LOCAL
| GOVD_MAP
))
6807 && DECL_P (TYPE_SIZE_UNIT (TREE_TYPE (decl
))))
6808 omp_notice_variable (ctx
, TYPE_SIZE_UNIT (TREE_TYPE (decl
)), true);
6810 else if ((flags
& (GOVD_MAP
| GOVD_LOCAL
)) == 0
6811 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
6813 omp_firstprivatize_type_sizes (ctx
, TREE_TYPE (decl
));
6815 /* Similar to the direct variable sized case above, we'll need the
6816 size of references being privatized. */
6817 if ((flags
& GOVD_SHARED
) == 0)
6819 t
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)));
6821 omp_notice_variable (ctx
, t
, true);
6828 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl
, flags
);
6830 /* For reductions clauses in OpenACC loop directives, by default create a
6831 copy clause on the enclosing parallel construct for carrying back the
6833 if (ctx
->region_type
== ORT_ACC
&& (flags
& GOVD_REDUCTION
))
6835 struct gimplify_omp_ctx
*outer_ctx
= ctx
->outer_context
;
6838 n
= splay_tree_lookup (outer_ctx
->variables
, (splay_tree_key
)decl
);
6841 /* Ignore local variables and explicitly declared clauses. */
6842 if (n
->value
& (GOVD_LOCAL
| GOVD_EXPLICIT
))
6844 else if (outer_ctx
->region_type
== ORT_ACC_KERNELS
)
6846 /* According to the OpenACC spec, such a reduction variable
6847 should already have a copy map on a kernels construct,
6848 verify that here. */
6849 gcc_assert (!(n
->value
& GOVD_FIRSTPRIVATE
)
6850 && (n
->value
& GOVD_MAP
));
6852 else if (outer_ctx
->region_type
== ORT_ACC_PARALLEL
)
6854 /* Remove firstprivate and make it a copy map. */
6855 n
->value
&= ~GOVD_FIRSTPRIVATE
;
6856 n
->value
|= GOVD_MAP
;
6859 else if (outer_ctx
->region_type
== ORT_ACC_PARALLEL
)
6861 splay_tree_insert (outer_ctx
->variables
, (splay_tree_key
)decl
,
6862 GOVD_MAP
| GOVD_SEEN
);
6865 outer_ctx
= outer_ctx
->outer_context
;
6870 /* Notice a threadprivate variable DECL used in OMP context CTX.
6871 This just prints out diagnostics about threadprivate variable uses
6872 in untied tasks. If DECL2 is non-NULL, prevent this warning
6873 on that variable. */
6876 omp_notice_threadprivate_variable (struct gimplify_omp_ctx
*ctx
, tree decl
,
6880 struct gimplify_omp_ctx
*octx
;
6882 for (octx
= ctx
; octx
; octx
= octx
->outer_context
)
6883 if ((octx
->region_type
& ORT_TARGET
) != 0)
6885 n
= splay_tree_lookup (octx
->variables
, (splay_tree_key
)decl
);
6888 error ("threadprivate variable %qE used in target region",
6890 error_at (octx
->location
, "enclosing target region");
6891 splay_tree_insert (octx
->variables
, (splay_tree_key
)decl
, 0);
6894 splay_tree_insert (octx
->variables
, (splay_tree_key
)decl2
, 0);
6897 if (ctx
->region_type
!= ORT_UNTIED_TASK
)
6899 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
6902 error ("threadprivate variable %qE used in untied task",
6904 error_at (ctx
->location
, "enclosing task");
6905 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl
, 0);
6908 splay_tree_insert (ctx
->variables
, (splay_tree_key
)decl2
, 0);
6912 /* Return true if global var DECL is device resident. */
6915 device_resident_p (tree decl
)
6917 tree attr
= lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (decl
));
6922 for (tree t
= TREE_VALUE (attr
); t
; t
= TREE_PURPOSE (t
))
6924 tree c
= TREE_VALUE (t
);
6925 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DEVICE_RESIDENT
)
6932 /* Return true if DECL has an ACC DECLARE attribute. */
6935 is_oacc_declared (tree decl
)
6937 tree t
= TREE_CODE (decl
) == MEM_REF
? TREE_OPERAND (decl
, 0) : decl
;
6938 tree declared
= lookup_attribute ("oacc declare target", DECL_ATTRIBUTES (t
));
6939 return declared
!= NULL_TREE
;
6942 /* Determine outer default flags for DECL mentioned in an OMP region
6943 but not declared in an enclosing clause.
6945 ??? Some compiler-generated variables (like SAVE_EXPRs) could be
6946 remapped firstprivate instead of shared. To some extent this is
6947 addressed in omp_firstprivatize_type_sizes, but not
6951 omp_default_clause (struct gimplify_omp_ctx
*ctx
, tree decl
,
6952 bool in_code
, unsigned flags
)
6954 enum omp_clause_default_kind default_kind
= ctx
->default_kind
;
6955 enum omp_clause_default_kind kind
;
6957 kind
= lang_hooks
.decls
.omp_predetermined_sharing (decl
);
6958 if (kind
!= OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6959 default_kind
= kind
;
6961 switch (default_kind
)
6963 case OMP_CLAUSE_DEFAULT_NONE
:
6967 if (ctx
->region_type
& ORT_PARALLEL
)
6969 else if (ctx
->region_type
& ORT_TASK
)
6971 else if (ctx
->region_type
& ORT_TEAMS
)
6976 error ("%qE not specified in enclosing %qs",
6977 DECL_NAME (lang_hooks
.decls
.omp_report_decl (decl
)), rtype
);
6978 error_at (ctx
->location
, "enclosing %qs", rtype
);
6981 case OMP_CLAUSE_DEFAULT_SHARED
:
6982 flags
|= GOVD_SHARED
;
6984 case OMP_CLAUSE_DEFAULT_PRIVATE
:
6985 flags
|= GOVD_PRIVATE
;
6987 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE
:
6988 flags
|= GOVD_FIRSTPRIVATE
;
6990 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
6991 /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */
6992 gcc_assert ((ctx
->region_type
& ORT_TASK
) != 0);
6993 if (struct gimplify_omp_ctx
*octx
= ctx
->outer_context
)
6995 omp_notice_variable (octx
, decl
, in_code
);
6996 for (; octx
; octx
= octx
->outer_context
)
7000 n2
= splay_tree_lookup (octx
->variables
, (splay_tree_key
) decl
);
7001 if ((octx
->region_type
& (ORT_TARGET_DATA
| ORT_TARGET
)) != 0
7002 && (n2
== NULL
|| (n2
->value
& GOVD_DATA_SHARE_CLASS
) == 0))
7004 if (n2
&& (n2
->value
& GOVD_DATA_SHARE_CLASS
) != GOVD_SHARED
)
7006 flags
|= GOVD_FIRSTPRIVATE
;
7009 if ((octx
->region_type
& (ORT_PARALLEL
| ORT_TEAMS
)) != 0)
7011 flags
|= GOVD_SHARED
;
7017 if (TREE_CODE (decl
) == PARM_DECL
7018 || (!is_global_var (decl
)
7019 && DECL_CONTEXT (decl
) == current_function_decl
))
7020 flags
|= GOVD_FIRSTPRIVATE
;
7022 flags
|= GOVD_SHARED
;
7034 /* Determine outer default flags for DECL mentioned in an OACC region
7035 but not declared in an enclosing clause. */
7038 oacc_default_clause (struct gimplify_omp_ctx
*ctx
, tree decl
, unsigned flags
)
7041 bool on_device
= false;
7042 bool declared
= is_oacc_declared (decl
);
7043 tree type
= TREE_TYPE (decl
);
7045 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7046 type
= TREE_TYPE (type
);
7048 if ((ctx
->region_type
& (ORT_ACC_PARALLEL
| ORT_ACC_KERNELS
)) != 0
7049 && is_global_var (decl
)
7050 && device_resident_p (decl
))
7053 flags
|= GOVD_MAP_TO_ONLY
;
7056 switch (ctx
->region_type
)
7058 case ORT_ACC_KERNELS
:
7061 if (AGGREGATE_TYPE_P (type
))
7063 /* Aggregates default to 'present_or_copy', or 'present'. */
7064 if (ctx
->default_kind
!= OMP_CLAUSE_DEFAULT_PRESENT
)
7067 flags
|= GOVD_MAP
| GOVD_MAP_FORCE_PRESENT
;
7070 /* Scalars default to 'copy'. */
7071 flags
|= GOVD_MAP
| GOVD_MAP_FORCE
;
7075 case ORT_ACC_PARALLEL
:
7078 if (on_device
|| declared
)
7080 else if (AGGREGATE_TYPE_P (type
))
7082 /* Aggregates default to 'present_or_copy', or 'present'. */
7083 if (ctx
->default_kind
!= OMP_CLAUSE_DEFAULT_PRESENT
)
7086 flags
|= GOVD_MAP
| GOVD_MAP_FORCE_PRESENT
;
7089 /* Scalars default to 'firstprivate'. */
7090 flags
|= GOVD_FIRSTPRIVATE
;
7098 if (DECL_ARTIFICIAL (decl
))
7099 ; /* We can get compiler-generated decls, and should not complain
7101 else if (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_NONE
)
7103 error ("%qE not specified in enclosing OpenACC %qs construct",
7104 DECL_NAME (lang_hooks
.decls
.omp_report_decl (decl
)), rkind
);
7105 inform (ctx
->location
, "enclosing OpenACC %qs construct", rkind
);
7107 else if (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_PRESENT
)
7108 ; /* Handled above. */
7110 gcc_checking_assert (ctx
->default_kind
== OMP_CLAUSE_DEFAULT_SHARED
);
7115 /* Record the fact that DECL was used within the OMP context CTX.
7116 IN_CODE is true when real code uses DECL, and false when we should
7117 merely emit default(none) errors. Return true if DECL is going to
7118 be remapped and thus DECL shouldn't be gimplified into its
7119 DECL_VALUE_EXPR (if any). */
7122 omp_notice_variable (struct gimplify_omp_ctx
*ctx
, tree decl
, bool in_code
)
7125 unsigned flags
= in_code
? GOVD_SEEN
: 0;
7126 bool ret
= false, shared
;
7128 if (error_operand_p (decl
))
7131 if (ctx
->region_type
== ORT_NONE
)
7132 return lang_hooks
.decls
.omp_disregard_value_expr (decl
, false);
7134 if (is_global_var (decl
))
7136 /* Threadprivate variables are predetermined. */
7137 if (DECL_THREAD_LOCAL_P (decl
))
7138 return omp_notice_threadprivate_variable (ctx
, decl
, NULL_TREE
);
7140 if (DECL_HAS_VALUE_EXPR_P (decl
))
7142 tree value
= get_base_address (DECL_VALUE_EXPR (decl
));
7144 if (value
&& DECL_P (value
) && DECL_THREAD_LOCAL_P (value
))
7145 return omp_notice_threadprivate_variable (ctx
, decl
, value
);
7148 if (gimplify_omp_ctxp
->outer_context
== NULL
7150 && oacc_get_fn_attrib (current_function_decl
))
7152 location_t loc
= DECL_SOURCE_LOCATION (decl
);
7154 if (lookup_attribute ("omp declare target link",
7155 DECL_ATTRIBUTES (decl
)))
7158 "%qE with %<link%> clause used in %<routine%> function",
7162 else if (!lookup_attribute ("omp declare target",
7163 DECL_ATTRIBUTES (decl
)))
7166 "%qE requires a %<declare%> directive for use "
7167 "in a %<routine%> function", DECL_NAME (decl
));
7173 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7174 if ((ctx
->region_type
& ORT_TARGET
) != 0)
7176 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, true);
7179 unsigned nflags
= flags
;
7180 if (ctx
->target_map_pointers_as_0len_arrays
7181 || ctx
->target_map_scalars_firstprivate
)
7183 bool is_declare_target
= false;
7184 bool is_scalar
= false;
7185 if (is_global_var (decl
)
7186 && varpool_node::get_create (decl
)->offloadable
)
7188 struct gimplify_omp_ctx
*octx
;
7189 for (octx
= ctx
->outer_context
;
7190 octx
; octx
= octx
->outer_context
)
7192 n
= splay_tree_lookup (octx
->variables
,
7193 (splay_tree_key
)decl
);
7195 && (n
->value
& GOVD_DATA_SHARE_CLASS
) != GOVD_SHARED
7196 && (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
7199 is_declare_target
= octx
== NULL
;
7201 if (!is_declare_target
&& ctx
->target_map_scalars_firstprivate
)
7202 is_scalar
= lang_hooks
.decls
.omp_scalar_p (decl
);
7203 if (is_declare_target
)
7205 else if (ctx
->target_map_pointers_as_0len_arrays
7206 && (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
7207 || (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
7208 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl
)))
7210 nflags
|= GOVD_MAP
| GOVD_MAP_0LEN_ARRAY
;
7212 nflags
|= GOVD_FIRSTPRIVATE
;
7215 struct gimplify_omp_ctx
*octx
= ctx
->outer_context
;
7216 if ((ctx
->region_type
& ORT_ACC
) && octx
)
7218 /* Look in outer OpenACC contexts, to see if there's a
7219 data attribute for this variable. */
7220 omp_notice_variable (octx
, decl
, in_code
);
7222 for (; octx
; octx
= octx
->outer_context
)
7224 if (!(octx
->region_type
& (ORT_TARGET_DATA
| ORT_TARGET
)))
7227 = splay_tree_lookup (octx
->variables
,
7228 (splay_tree_key
) decl
);
7231 if (octx
->region_type
== ORT_ACC_HOST_DATA
)
7232 error ("variable %qE declared in enclosing "
7233 "%<host_data%> region", DECL_NAME (decl
));
7235 if (octx
->region_type
== ORT_ACC_DATA
7236 && (n2
->value
& GOVD_MAP_0LEN_ARRAY
))
7237 nflags
|= GOVD_MAP_0LEN_ARRAY
;
7244 tree type
= TREE_TYPE (decl
);
7247 && gimplify_omp_ctxp
->target_firstprivatize_array_bases
7248 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7249 type
= TREE_TYPE (type
);
7251 && !lang_hooks
.types
.omp_mappable_type (type
))
7253 error ("%qD referenced in target region does not have "
7254 "a mappable type", decl
);
7255 nflags
|= GOVD_MAP
| GOVD_EXPLICIT
;
7257 else if (nflags
== flags
)
7259 if ((ctx
->region_type
& ORT_ACC
) != 0)
7260 nflags
= oacc_default_clause (ctx
, decl
, flags
);
7266 omp_add_variable (ctx
, decl
, nflags
);
7270 /* If nothing changed, there's nothing left to do. */
7271 if ((n
->value
& flags
) == flags
)
7281 if (ctx
->region_type
== ORT_WORKSHARE
7282 || ctx
->region_type
== ORT_SIMD
7283 || ctx
->region_type
== ORT_ACC
7284 || (ctx
->region_type
& ORT_TARGET_DATA
) != 0)
7287 flags
= omp_default_clause (ctx
, decl
, in_code
, flags
);
7289 if ((flags
& GOVD_PRIVATE
)
7290 && lang_hooks
.decls
.omp_private_outer_ref (decl
))
7291 flags
|= GOVD_PRIVATE_OUTER_REF
;
7293 omp_add_variable (ctx
, decl
, flags
);
7295 shared
= (flags
& GOVD_SHARED
) != 0;
7296 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, shared
);
7300 if ((n
->value
& (GOVD_SEEN
| GOVD_LOCAL
)) == 0
7301 && (flags
& (GOVD_SEEN
| GOVD_LOCAL
)) == GOVD_SEEN
7302 && DECL_SIZE (decl
))
7304 if (TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
7307 tree t
= DECL_VALUE_EXPR (decl
);
7308 gcc_assert (TREE_CODE (t
) == INDIRECT_REF
);
7309 t
= TREE_OPERAND (t
, 0);
7310 gcc_assert (DECL_P (t
));
7311 n2
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
7312 n2
->value
|= GOVD_SEEN
;
7314 else if (lang_hooks
.decls
.omp_privatize_by_reference (decl
)
7315 && TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)))
7316 && (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
))))
7320 tree t
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
)));
7321 gcc_assert (DECL_P (t
));
7322 n2
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
7324 omp_notice_variable (ctx
, t
, true);
7328 shared
= ((flags
| n
->value
) & GOVD_SHARED
) != 0;
7329 ret
= lang_hooks
.decls
.omp_disregard_value_expr (decl
, shared
);
7331 /* If nothing changed, there's nothing left to do. */
7332 if ((n
->value
& flags
) == flags
)
7338 /* If the variable is private in the current context, then we don't
7339 need to propagate anything to an outer context. */
7340 if ((flags
& GOVD_PRIVATE
) && !(flags
& GOVD_PRIVATE_OUTER_REF
))
7342 if ((flags
& (GOVD_LINEAR
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7343 == (GOVD_LINEAR
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7345 if ((flags
& (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
7346 | GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7347 == (GOVD_LASTPRIVATE
| GOVD_LINEAR_LASTPRIVATE_NO_OUTER
))
7349 if (ctx
->outer_context
7350 && omp_notice_variable (ctx
->outer_context
, decl
, in_code
))
7355 /* Verify that DECL is private within CTX. If there's specific information
7356 to the contrary in the innermost scope, generate an error. */
7359 omp_is_private (struct gimplify_omp_ctx
*ctx
, tree decl
, int simd
)
7363 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7366 if (n
->value
& GOVD_SHARED
)
7368 if (ctx
== gimplify_omp_ctxp
)
7371 error ("iteration variable %qE is predetermined linear",
7374 error ("iteration variable %qE should be private",
7376 n
->value
= GOVD_PRIVATE
;
7382 else if ((n
->value
& GOVD_EXPLICIT
) != 0
7383 && (ctx
== gimplify_omp_ctxp
7384 || (ctx
->region_type
== ORT_COMBINED_PARALLEL
7385 && gimplify_omp_ctxp
->outer_context
== ctx
)))
7387 if ((n
->value
& GOVD_FIRSTPRIVATE
) != 0)
7388 error ("iteration variable %qE should not be firstprivate",
7390 else if ((n
->value
& GOVD_REDUCTION
) != 0)
7391 error ("iteration variable %qE should not be reduction",
7393 else if (simd
== 0 && (n
->value
& GOVD_LINEAR
) != 0)
7394 error ("iteration variable %qE should not be linear",
7396 else if (simd
== 1 && (n
->value
& GOVD_LASTPRIVATE
) != 0)
7397 error ("iteration variable %qE should not be lastprivate",
7399 else if (simd
&& (n
->value
& GOVD_PRIVATE
) != 0)
7400 error ("iteration variable %qE should not be private",
7402 else if (simd
== 2 && (n
->value
& GOVD_LINEAR
) != 0)
7403 error ("iteration variable %qE is predetermined linear",
7406 return (ctx
== gimplify_omp_ctxp
7407 || (ctx
->region_type
== ORT_COMBINED_PARALLEL
7408 && gimplify_omp_ctxp
->outer_context
== ctx
));
7411 if (ctx
->region_type
!= ORT_WORKSHARE
7412 && ctx
->region_type
!= ORT_SIMD
7413 && ctx
->region_type
!= ORT_ACC
)
7415 else if (ctx
->outer_context
)
7416 return omp_is_private (ctx
->outer_context
, decl
, simd
);
7420 /* Return true if DECL is private within a parallel region
7421 that binds to the current construct's context or in parallel
7422 region's REDUCTION clause. */
7425 omp_check_private (struct gimplify_omp_ctx
*ctx
, tree decl
, bool copyprivate
)
7431 ctx
= ctx
->outer_context
;
7434 if (is_global_var (decl
))
7437 /* References might be private, but might be shared too,
7438 when checking for copyprivate, assume they might be
7439 private, otherwise assume they might be shared. */
7443 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
7446 /* Treat C++ privatized non-static data members outside
7447 of the privatization the same. */
7448 if (omp_member_access_dummy_var (decl
))
7454 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
7456 if ((ctx
->region_type
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0
7457 && (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0))
7462 if ((n
->value
& GOVD_LOCAL
) != 0
7463 && omp_member_access_dummy_var (decl
))
7465 return (n
->value
& GOVD_SHARED
) == 0;
7468 while (ctx
->region_type
== ORT_WORKSHARE
7469 || ctx
->region_type
== ORT_SIMD
7470 || ctx
->region_type
== ORT_ACC
);
7474 /* Callback for walk_tree to find a DECL_EXPR for the given DECL. */
7477 find_decl_expr (tree
*tp
, int *walk_subtrees
, void *data
)
7481 /* If this node has been visited, unmark it and keep looking. */
7482 if (TREE_CODE (t
) == DECL_EXPR
&& DECL_EXPR_DECL (t
) == (tree
) data
)
7485 if (IS_TYPE_OR_DECL_P (t
))
7490 /* Scan the OMP clauses in *LIST_P, installing mappings into a new
7491 and previous omp contexts. */
7494 gimplify_scan_omp_clauses (tree
*list_p
, gimple_seq
*pre_p
,
7495 enum omp_region_type region_type
,
7496 enum tree_code code
)
7498 struct gimplify_omp_ctx
*ctx
, *outer_ctx
;
7500 hash_map
<tree
, tree
> *struct_map_to_clause
= NULL
;
7501 tree
*prev_list_p
= NULL
;
7503 ctx
= new_omp_context (region_type
);
7504 outer_ctx
= ctx
->outer_context
;
7505 if (code
== OMP_TARGET
)
7507 if (!lang_GNU_Fortran ())
7508 ctx
->target_map_pointers_as_0len_arrays
= true;
7509 ctx
->target_map_scalars_firstprivate
= true;
7511 if (!lang_GNU_Fortran ())
7515 case OMP_TARGET_DATA
:
7516 case OMP_TARGET_ENTER_DATA
:
7517 case OMP_TARGET_EXIT_DATA
:
7519 case OACC_HOST_DATA
:
7520 ctx
->target_firstprivatize_array_bases
= true;
7525 while ((c
= *list_p
) != NULL
)
7527 bool remove
= false;
7528 bool notice_outer
= true;
7529 const char *check_non_private
= NULL
;
7533 switch (OMP_CLAUSE_CODE (c
))
7535 case OMP_CLAUSE_PRIVATE
:
7536 flags
= GOVD_PRIVATE
| GOVD_EXPLICIT
;
7537 if (lang_hooks
.decls
.omp_private_outer_ref (OMP_CLAUSE_DECL (c
)))
7539 flags
|= GOVD_PRIVATE_OUTER_REF
;
7540 OMP_CLAUSE_PRIVATE_OUTER_REF (c
) = 1;
7543 notice_outer
= false;
7545 case OMP_CLAUSE_SHARED
:
7546 flags
= GOVD_SHARED
| GOVD_EXPLICIT
;
7548 case OMP_CLAUSE_FIRSTPRIVATE
:
7549 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
7550 check_non_private
= "firstprivate";
7552 case OMP_CLAUSE_LASTPRIVATE
:
7553 flags
= GOVD_LASTPRIVATE
| GOVD_SEEN
| GOVD_EXPLICIT
;
7554 check_non_private
= "lastprivate";
7555 decl
= OMP_CLAUSE_DECL (c
);
7556 if (error_operand_p (decl
))
7559 && (outer_ctx
->region_type
== ORT_COMBINED_PARALLEL
7560 || outer_ctx
->region_type
== ORT_COMBINED_TEAMS
)
7561 && splay_tree_lookup (outer_ctx
->variables
,
7562 (splay_tree_key
) decl
) == NULL
)
7564 omp_add_variable (outer_ctx
, decl
, GOVD_SHARED
| GOVD_SEEN
);
7565 if (outer_ctx
->outer_context
)
7566 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
7569 && (outer_ctx
->region_type
& ORT_TASK
) != 0
7570 && outer_ctx
->combined_loop
7571 && splay_tree_lookup (outer_ctx
->variables
,
7572 (splay_tree_key
) decl
) == NULL
)
7574 omp_add_variable (outer_ctx
, decl
, GOVD_LASTPRIVATE
| GOVD_SEEN
);
7575 if (outer_ctx
->outer_context
)
7576 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
7579 && (outer_ctx
->region_type
== ORT_WORKSHARE
7580 || outer_ctx
->region_type
== ORT_ACC
)
7581 && outer_ctx
->combined_loop
7582 && splay_tree_lookup (outer_ctx
->variables
,
7583 (splay_tree_key
) decl
) == NULL
7584 && !omp_check_private (outer_ctx
, decl
, false))
7586 omp_add_variable (outer_ctx
, decl
, GOVD_LASTPRIVATE
| GOVD_SEEN
);
7587 if (outer_ctx
->outer_context
7588 && (outer_ctx
->outer_context
->region_type
7589 == ORT_COMBINED_PARALLEL
)
7590 && splay_tree_lookup (outer_ctx
->outer_context
->variables
,
7591 (splay_tree_key
) decl
) == NULL
)
7593 struct gimplify_omp_ctx
*octx
= outer_ctx
->outer_context
;
7594 omp_add_variable (octx
, decl
, GOVD_SHARED
| GOVD_SEEN
);
7595 if (octx
->outer_context
)
7597 octx
= octx
->outer_context
;
7598 if (octx
->region_type
== ORT_WORKSHARE
7599 && octx
->combined_loop
7600 && splay_tree_lookup (octx
->variables
,
7601 (splay_tree_key
) decl
) == NULL
7602 && !omp_check_private (octx
, decl
, false))
7604 omp_add_variable (octx
, decl
,
7605 GOVD_LASTPRIVATE
| GOVD_SEEN
);
7606 octx
= octx
->outer_context
;
7608 && octx
->region_type
== ORT_COMBINED_TEAMS
7609 && (splay_tree_lookup (octx
->variables
,
7610 (splay_tree_key
) decl
)
7613 omp_add_variable (octx
, decl
,
7614 GOVD_SHARED
| GOVD_SEEN
);
7615 octx
= octx
->outer_context
;
7619 omp_notice_variable (octx
, decl
, true);
7622 else if (outer_ctx
->outer_context
)
7623 omp_notice_variable (outer_ctx
->outer_context
, decl
, true);
7626 case OMP_CLAUSE_REDUCTION
:
7627 flags
= GOVD_REDUCTION
| GOVD_SEEN
| GOVD_EXPLICIT
;
7628 /* OpenACC permits reductions on private variables. */
7629 if (!(region_type
& ORT_ACC
))
7630 check_non_private
= "reduction";
7631 decl
= OMP_CLAUSE_DECL (c
);
7632 if (TREE_CODE (decl
) == MEM_REF
)
7634 tree type
= TREE_TYPE (decl
);
7635 if (gimplify_expr (&TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), pre_p
,
7636 NULL
, is_gimple_val
, fb_rvalue
, false)
7642 tree v
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
7645 omp_firstprivatize_variable (ctx
, v
);
7646 omp_notice_variable (ctx
, v
, true);
7648 decl
= TREE_OPERAND (decl
, 0);
7649 if (TREE_CODE (decl
) == POINTER_PLUS_EXPR
)
7651 if (gimplify_expr (&TREE_OPERAND (decl
, 1), pre_p
,
7652 NULL
, is_gimple_val
, fb_rvalue
, false)
7658 v
= TREE_OPERAND (decl
, 1);
7661 omp_firstprivatize_variable (ctx
, v
);
7662 omp_notice_variable (ctx
, v
, true);
7664 decl
= TREE_OPERAND (decl
, 0);
7666 if (TREE_CODE (decl
) == ADDR_EXPR
7667 || TREE_CODE (decl
) == INDIRECT_REF
)
7668 decl
= TREE_OPERAND (decl
, 0);
7671 case OMP_CLAUSE_LINEAR
:
7672 if (gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c
), pre_p
, NULL
,
7673 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
7680 if (code
== OMP_SIMD
7681 && !OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
7683 struct gimplify_omp_ctx
*octx
= outer_ctx
;
7685 && octx
->region_type
== ORT_WORKSHARE
7686 && octx
->combined_loop
7687 && !octx
->distribute
)
7689 if (octx
->outer_context
7690 && (octx
->outer_context
->region_type
7691 == ORT_COMBINED_PARALLEL
))
7692 octx
= octx
->outer_context
->outer_context
;
7694 octx
= octx
->outer_context
;
7697 && octx
->region_type
== ORT_WORKSHARE
7698 && octx
->combined_loop
7699 && octx
->distribute
)
7701 error_at (OMP_CLAUSE_LOCATION (c
),
7702 "%<linear%> clause for variable other than "
7703 "loop iterator specified on construct "
7704 "combined with %<distribute%>");
7709 /* For combined #pragma omp parallel for simd, need to put
7710 lastprivate and perhaps firstprivate too on the
7711 parallel. Similarly for #pragma omp for simd. */
7712 struct gimplify_omp_ctx
*octx
= outer_ctx
;
7716 if (OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
7717 && OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
7719 decl
= OMP_CLAUSE_DECL (c
);
7720 if (error_operand_p (decl
))
7726 if (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
))
7727 flags
|= GOVD_FIRSTPRIVATE
;
7728 if (!OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
7729 flags
|= GOVD_LASTPRIVATE
;
7731 && octx
->region_type
== ORT_WORKSHARE
7732 && octx
->combined_loop
)
7734 if (octx
->outer_context
7735 && (octx
->outer_context
->region_type
7736 == ORT_COMBINED_PARALLEL
))
7737 octx
= octx
->outer_context
;
7738 else if (omp_check_private (octx
, decl
, false))
7742 && (octx
->region_type
& ORT_TASK
) != 0
7743 && octx
->combined_loop
)
7746 && octx
->region_type
== ORT_COMBINED_PARALLEL
7747 && ctx
->region_type
== ORT_WORKSHARE
7748 && octx
== outer_ctx
)
7749 flags
= GOVD_SEEN
| GOVD_SHARED
;
7751 && octx
->region_type
== ORT_COMBINED_TEAMS
)
7752 flags
= GOVD_SEEN
| GOVD_SHARED
;
7754 && octx
->region_type
== ORT_COMBINED_TARGET
)
7756 flags
&= ~GOVD_LASTPRIVATE
;
7757 if (flags
== GOVD_SEEN
)
7763 = splay_tree_lookup (octx
->variables
,
7764 (splay_tree_key
) decl
);
7765 if (on
&& (on
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
7770 omp_add_variable (octx
, decl
, flags
);
7771 if (octx
->outer_context
== NULL
)
7773 octx
= octx
->outer_context
;
7778 && (!OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
7779 || !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)))
7780 omp_notice_variable (octx
, decl
, true);
7782 flags
= GOVD_LINEAR
| GOVD_EXPLICIT
;
7783 if (OMP_CLAUSE_LINEAR_NO_COPYIN (c
)
7784 && OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
7786 notice_outer
= false;
7787 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
7791 case OMP_CLAUSE_MAP
:
7792 decl
= OMP_CLAUSE_DECL (c
);
7793 if (error_operand_p (decl
))
7800 if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
7803 case OMP_TARGET_DATA
:
7804 case OMP_TARGET_ENTER_DATA
:
7805 case OMP_TARGET_EXIT_DATA
:
7806 case OACC_ENTER_DATA
:
7807 case OACC_EXIT_DATA
:
7808 case OACC_HOST_DATA
:
7809 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
7810 || (OMP_CLAUSE_MAP_KIND (c
)
7811 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
7812 /* For target {,enter ,exit }data only the array slice is
7813 mapped, but not the pointer to it. */
7821 if (DECL_P (decl
) && outer_ctx
&& (region_type
& ORT_ACC
))
7823 struct gimplify_omp_ctx
*octx
;
7824 for (octx
= outer_ctx
; octx
; octx
= octx
->outer_context
)
7826 if (octx
->region_type
!= ORT_ACC_HOST_DATA
)
7829 = splay_tree_lookup (octx
->variables
,
7830 (splay_tree_key
) decl
);
7832 error_at (OMP_CLAUSE_LOCATION (c
), "variable %qE "
7833 "declared in enclosing %<host_data%> region",
7837 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7838 OMP_CLAUSE_SIZE (c
) = DECL_P (decl
) ? DECL_SIZE_UNIT (decl
)
7839 : TYPE_SIZE_UNIT (TREE_TYPE (decl
));
7840 if (gimplify_expr (&OMP_CLAUSE_SIZE (c
), pre_p
,
7841 NULL
, is_gimple_val
, fb_rvalue
) == GS_ERROR
)
7846 else if ((OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
7847 || (OMP_CLAUSE_MAP_KIND (c
)
7848 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
7849 && TREE_CODE (OMP_CLAUSE_SIZE (c
)) != INTEGER_CST
)
7852 = get_initialized_tmp_var (OMP_CLAUSE_SIZE (c
), pre_p
, NULL
,
7854 omp_add_variable (ctx
, OMP_CLAUSE_SIZE (c
),
7855 GOVD_FIRSTPRIVATE
| GOVD_SEEN
);
7860 if (TREE_CODE (d
) == ARRAY_REF
)
7862 while (TREE_CODE (d
) == ARRAY_REF
)
7863 d
= TREE_OPERAND (d
, 0);
7864 if (TREE_CODE (d
) == COMPONENT_REF
7865 && TREE_CODE (TREE_TYPE (d
)) == ARRAY_TYPE
)
7868 pd
= &OMP_CLAUSE_DECL (c
);
7870 && TREE_CODE (decl
) == INDIRECT_REF
7871 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
7872 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
7875 pd
= &TREE_OPERAND (decl
, 0);
7876 decl
= TREE_OPERAND (decl
, 0);
7878 if (TREE_CODE (decl
) == COMPONENT_REF
)
7880 while (TREE_CODE (decl
) == COMPONENT_REF
)
7881 decl
= TREE_OPERAND (decl
, 0);
7882 if (TREE_CODE (decl
) == INDIRECT_REF
7883 && DECL_P (TREE_OPERAND (decl
, 0))
7884 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
7886 decl
= TREE_OPERAND (decl
, 0);
7888 if (gimplify_expr (pd
, pre_p
, NULL
, is_gimple_lvalue
, fb_lvalue
)
7896 if (error_operand_p (decl
))
7902 tree stype
= TREE_TYPE (decl
);
7903 if (TREE_CODE (stype
) == REFERENCE_TYPE
)
7904 stype
= TREE_TYPE (stype
);
7905 if (TYPE_SIZE_UNIT (stype
) == NULL
7906 || TREE_CODE (TYPE_SIZE_UNIT (stype
)) != INTEGER_CST
)
7908 error_at (OMP_CLAUSE_LOCATION (c
),
7909 "mapping field %qE of variable length "
7910 "structure", OMP_CLAUSE_DECL (c
));
7915 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
)
7917 /* Error recovery. */
7918 if (prev_list_p
== NULL
)
7923 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
7925 tree ch
= OMP_CLAUSE_CHAIN (*prev_list_p
);
7926 if (ch
== NULL_TREE
|| OMP_CLAUSE_CHAIN (ch
) != c
)
7935 poly_int64 bitsize
, bitpos
;
7937 int unsignedp
, reversep
, volatilep
= 0;
7938 tree base
= OMP_CLAUSE_DECL (c
);
7939 while (TREE_CODE (base
) == ARRAY_REF
)
7940 base
= TREE_OPERAND (base
, 0);
7941 if (TREE_CODE (base
) == INDIRECT_REF
)
7942 base
= TREE_OPERAND (base
, 0);
7943 base
= get_inner_reference (base
, &bitsize
, &bitpos
, &offset
,
7944 &mode
, &unsignedp
, &reversep
,
7946 tree orig_base
= base
;
7947 if ((TREE_CODE (base
) == INDIRECT_REF
7948 || (TREE_CODE (base
) == MEM_REF
7949 && integer_zerop (TREE_OPERAND (base
, 1))))
7950 && DECL_P (TREE_OPERAND (base
, 0))
7951 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base
, 0)))
7953 base
= TREE_OPERAND (base
, 0);
7954 gcc_assert (base
== decl
7955 && (offset
== NULL_TREE
7956 || poly_int_tree_p (offset
)));
7959 = splay_tree_lookup (ctx
->variables
, (splay_tree_key
)decl
);
7960 bool ptr
= (OMP_CLAUSE_MAP_KIND (c
)
7961 == GOMP_MAP_ALWAYS_POINTER
);
7962 if (n
== NULL
|| (n
->value
& GOVD_MAP
) == 0)
7964 tree l
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7966 OMP_CLAUSE_SET_MAP_KIND (l
, GOMP_MAP_STRUCT
);
7967 if (orig_base
!= base
)
7968 OMP_CLAUSE_DECL (l
) = unshare_expr (orig_base
);
7970 OMP_CLAUSE_DECL (l
) = decl
;
7971 OMP_CLAUSE_SIZE (l
) = size_int (1);
7972 if (struct_map_to_clause
== NULL
)
7973 struct_map_to_clause
= new hash_map
<tree
, tree
>;
7974 struct_map_to_clause
->put (decl
, l
);
7977 enum gomp_map_kind mkind
7978 = code
== OMP_TARGET_EXIT_DATA
7979 ? GOMP_MAP_RELEASE
: GOMP_MAP_ALLOC
;
7980 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7982 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
7983 OMP_CLAUSE_DECL (c2
)
7984 = unshare_expr (OMP_CLAUSE_DECL (c
));
7985 OMP_CLAUSE_CHAIN (c2
) = *prev_list_p
;
7986 OMP_CLAUSE_SIZE (c2
)
7987 = TYPE_SIZE_UNIT (ptr_type_node
);
7988 OMP_CLAUSE_CHAIN (l
) = c2
;
7989 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
7991 tree c4
= OMP_CLAUSE_CHAIN (*prev_list_p
);
7993 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7995 OMP_CLAUSE_SET_MAP_KIND (c3
, mkind
);
7996 OMP_CLAUSE_DECL (c3
)
7997 = unshare_expr (OMP_CLAUSE_DECL (c4
));
7998 OMP_CLAUSE_SIZE (c3
)
7999 = TYPE_SIZE_UNIT (ptr_type_node
);
8000 OMP_CLAUSE_CHAIN (c3
) = *prev_list_p
;
8001 OMP_CLAUSE_CHAIN (c2
) = c3
;
8008 OMP_CLAUSE_CHAIN (l
) = c
;
8010 list_p
= &OMP_CLAUSE_CHAIN (l
);
8012 if (orig_base
!= base
&& code
== OMP_TARGET
)
8014 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8016 enum gomp_map_kind mkind
8017 = GOMP_MAP_FIRSTPRIVATE_REFERENCE
;
8018 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
8019 OMP_CLAUSE_DECL (c2
) = decl
;
8020 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
8021 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (l
);
8022 OMP_CLAUSE_CHAIN (l
) = c2
;
8024 flags
= GOVD_MAP
| GOVD_EXPLICIT
;
8025 if (GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) || ptr
)
8031 tree
*osc
= struct_map_to_clause
->get (decl
);
8032 tree
*sc
= NULL
, *scp
= NULL
;
8033 if (GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) || ptr
)
8034 n
->value
|= GOVD_SEEN
;
8035 poly_offset_int o1
, o2
;
8037 o1
= wi::to_poly_offset (offset
);
8040 if (maybe_ne (bitpos
, 0))
8041 o1
+= bits_to_bytes_round_down (bitpos
);
8042 sc
= &OMP_CLAUSE_CHAIN (*osc
);
8044 && (OMP_CLAUSE_MAP_KIND (*sc
)
8045 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
8046 sc
= &OMP_CLAUSE_CHAIN (*sc
);
8047 for (; *sc
!= c
; sc
= &OMP_CLAUSE_CHAIN (*sc
))
8048 if (ptr
&& sc
== prev_list_p
)
8050 else if (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8052 && (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8054 && (TREE_CODE (OMP_CLAUSE_DECL (*sc
))
8060 poly_int64 bitsize2
, bitpos2
;
8061 base
= OMP_CLAUSE_DECL (*sc
);
8062 if (TREE_CODE (base
) == ARRAY_REF
)
8064 while (TREE_CODE (base
) == ARRAY_REF
)
8065 base
= TREE_OPERAND (base
, 0);
8066 if (TREE_CODE (base
) != COMPONENT_REF
8067 || (TREE_CODE (TREE_TYPE (base
))
8071 else if (TREE_CODE (base
) == INDIRECT_REF
8072 && (TREE_CODE (TREE_OPERAND (base
, 0))
8074 && (TREE_CODE (TREE_TYPE
8075 (TREE_OPERAND (base
, 0)))
8077 base
= TREE_OPERAND (base
, 0);
8078 base
= get_inner_reference (base
, &bitsize2
,
8081 &reversep
, &volatilep
);
8082 if ((TREE_CODE (base
) == INDIRECT_REF
8083 || (TREE_CODE (base
) == MEM_REF
8084 && integer_zerop (TREE_OPERAND (base
,
8086 && DECL_P (TREE_OPERAND (base
, 0))
8087 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base
,
8090 base
= TREE_OPERAND (base
, 0);
8095 gcc_assert (offset
== NULL_TREE
8096 || poly_int_tree_p (offset
));
8097 tree d1
= OMP_CLAUSE_DECL (*sc
);
8098 tree d2
= OMP_CLAUSE_DECL (c
);
8099 while (TREE_CODE (d1
) == ARRAY_REF
)
8100 d1
= TREE_OPERAND (d1
, 0);
8101 while (TREE_CODE (d2
) == ARRAY_REF
)
8102 d2
= TREE_OPERAND (d2
, 0);
8103 if (TREE_CODE (d1
) == INDIRECT_REF
)
8104 d1
= TREE_OPERAND (d1
, 0);
8105 if (TREE_CODE (d2
) == INDIRECT_REF
)
8106 d2
= TREE_OPERAND (d2
, 0);
8107 while (TREE_CODE (d1
) == COMPONENT_REF
)
8108 if (TREE_CODE (d2
) == COMPONENT_REF
8109 && TREE_OPERAND (d1
, 1)
8110 == TREE_OPERAND (d2
, 1))
8112 d1
= TREE_OPERAND (d1
, 0);
8113 d2
= TREE_OPERAND (d2
, 0);
8119 error_at (OMP_CLAUSE_LOCATION (c
),
8120 "%qE appears more than once in map "
8121 "clauses", OMP_CLAUSE_DECL (c
));
8126 o2
= wi::to_poly_offset (offset2
);
8129 o2
+= bits_to_bytes_round_down (bitpos2
);
8130 if (maybe_lt (o1
, o2
)
8131 || (known_eq (o1
, 2)
8132 && maybe_lt (bitpos
, bitpos2
)))
8142 OMP_CLAUSE_SIZE (*osc
)
8143 = size_binop (PLUS_EXPR
, OMP_CLAUSE_SIZE (*osc
),
8147 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8149 tree cl
= NULL_TREE
;
8150 enum gomp_map_kind mkind
8151 = code
== OMP_TARGET_EXIT_DATA
8152 ? GOMP_MAP_RELEASE
: GOMP_MAP_ALLOC
;
8153 OMP_CLAUSE_SET_MAP_KIND (c2
, mkind
);
8154 OMP_CLAUSE_DECL (c2
)
8155 = unshare_expr (OMP_CLAUSE_DECL (c
));
8156 OMP_CLAUSE_CHAIN (c2
) = scp
? *scp
: *prev_list_p
;
8157 OMP_CLAUSE_SIZE (c2
)
8158 = TYPE_SIZE_UNIT (ptr_type_node
);
8159 cl
= scp
? *prev_list_p
: c2
;
8160 if (OMP_CLAUSE_CHAIN (*prev_list_p
) != c
)
8162 tree c4
= OMP_CLAUSE_CHAIN (*prev_list_p
);
8164 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8166 OMP_CLAUSE_SET_MAP_KIND (c3
, mkind
);
8167 OMP_CLAUSE_DECL (c3
)
8168 = unshare_expr (OMP_CLAUSE_DECL (c4
));
8169 OMP_CLAUSE_SIZE (c3
)
8170 = TYPE_SIZE_UNIT (ptr_type_node
);
8171 OMP_CLAUSE_CHAIN (c3
) = *prev_list_p
;
8173 OMP_CLAUSE_CHAIN (c2
) = c3
;
8179 if (sc
== prev_list_p
)
8186 *prev_list_p
= OMP_CLAUSE_CHAIN (c
);
8187 list_p
= prev_list_p
;
8189 OMP_CLAUSE_CHAIN (c
) = *sc
;
8196 *list_p
= OMP_CLAUSE_CHAIN (c
);
8197 OMP_CLAUSE_CHAIN (c
) = *sc
;
8204 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ALWAYS_POINTER
8205 && OMP_CLAUSE_CHAIN (c
)
8206 && OMP_CLAUSE_CODE (OMP_CLAUSE_CHAIN (c
)) == OMP_CLAUSE_MAP
8207 && (OMP_CLAUSE_MAP_KIND (OMP_CLAUSE_CHAIN (c
))
8208 == GOMP_MAP_ALWAYS_POINTER
))
8209 prev_list_p
= list_p
;
8212 flags
= GOVD_MAP
| GOVD_EXPLICIT
;
8213 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_TO
8214 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_TOFROM
)
8215 flags
|= GOVD_MAP_ALWAYS_TO
;
8218 case OMP_CLAUSE_DEPEND
:
8219 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
8221 tree deps
= OMP_CLAUSE_DECL (c
);
8222 while (deps
&& TREE_CODE (deps
) == TREE_LIST
)
8224 if (TREE_CODE (TREE_PURPOSE (deps
)) == TRUNC_DIV_EXPR
8225 && DECL_P (TREE_OPERAND (TREE_PURPOSE (deps
), 1)))
8226 gimplify_expr (&TREE_OPERAND (TREE_PURPOSE (deps
), 1),
8227 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8228 deps
= TREE_CHAIN (deps
);
8232 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
)
8234 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPOUND_EXPR
)
8236 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0), pre_p
,
8237 NULL
, is_gimple_val
, fb_rvalue
);
8238 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (OMP_CLAUSE_DECL (c
), 1);
8240 if (error_operand_p (OMP_CLAUSE_DECL (c
)))
8245 OMP_CLAUSE_DECL (c
) = build_fold_addr_expr (OMP_CLAUSE_DECL (c
));
8246 if (gimplify_expr (&OMP_CLAUSE_DECL (c
), pre_p
, NULL
,
8247 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8255 case OMP_CLAUSE_FROM
:
8256 case OMP_CLAUSE__CACHE_
:
8257 decl
= OMP_CLAUSE_DECL (c
);
8258 if (error_operand_p (decl
))
8263 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8264 OMP_CLAUSE_SIZE (c
) = DECL_P (decl
) ? DECL_SIZE_UNIT (decl
)
8265 : TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8266 if (gimplify_expr (&OMP_CLAUSE_SIZE (c
), pre_p
,
8267 NULL
, is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8274 if (gimplify_expr (&OMP_CLAUSE_DECL (c
), pre_p
,
8275 NULL
, is_gimple_lvalue
, fb_lvalue
)
8285 case OMP_CLAUSE_USE_DEVICE_PTR
:
8286 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
8288 case OMP_CLAUSE_IS_DEVICE_PTR
:
8289 flags
= GOVD_FIRSTPRIVATE
| GOVD_EXPLICIT
;
8293 decl
= OMP_CLAUSE_DECL (c
);
8295 if (error_operand_p (decl
))
8300 if (DECL_NAME (decl
) == NULL_TREE
&& (flags
& GOVD_SHARED
) == 0)
8302 tree t
= omp_member_access_dummy_var (decl
);
8305 tree v
= DECL_VALUE_EXPR (decl
);
8306 DECL_NAME (decl
) = DECL_NAME (TREE_OPERAND (v
, 1));
8308 omp_notice_variable (outer_ctx
, t
, true);
8311 if (code
== OACC_DATA
8312 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8313 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
8314 flags
|= GOVD_MAP_0LEN_ARRAY
;
8315 omp_add_variable (ctx
, decl
, flags
);
8316 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8317 && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
8319 omp_add_variable (ctx
, OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
),
8320 GOVD_LOCAL
| GOVD_SEEN
);
8321 if (OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
)
8322 && walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
8324 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
),
8326 omp_add_variable (ctx
,
8327 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
),
8328 GOVD_LOCAL
| GOVD_SEEN
);
8329 gimplify_omp_ctxp
= ctx
;
8330 push_gimplify_context ();
8332 OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
) = NULL
;
8333 OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
) = NULL
;
8335 gimplify_and_add (OMP_CLAUSE_REDUCTION_INIT (c
),
8336 &OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
));
8337 pop_gimplify_context
8338 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_INIT (c
)));
8339 push_gimplify_context ();
8340 gimplify_and_add (OMP_CLAUSE_REDUCTION_MERGE (c
),
8341 &OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
));
8342 pop_gimplify_context
8343 (gimple_seq_first_stmt (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE (c
)));
8344 OMP_CLAUSE_REDUCTION_INIT (c
) = NULL_TREE
;
8345 OMP_CLAUSE_REDUCTION_MERGE (c
) = NULL_TREE
;
8347 gimplify_omp_ctxp
= outer_ctx
;
8349 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8350 && OMP_CLAUSE_LASTPRIVATE_STMT (c
))
8352 gimplify_omp_ctxp
= ctx
;
8353 push_gimplify_context ();
8354 if (TREE_CODE (OMP_CLAUSE_LASTPRIVATE_STMT (c
)) != BIND_EXPR
)
8356 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
,
8358 TREE_SIDE_EFFECTS (bind
) = 1;
8359 BIND_EXPR_BODY (bind
) = OMP_CLAUSE_LASTPRIVATE_STMT (c
);
8360 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = bind
;
8362 gimplify_and_add (OMP_CLAUSE_LASTPRIVATE_STMT (c
),
8363 &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
));
8364 pop_gimplify_context
8365 (gimple_seq_first_stmt (OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
)));
8366 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = NULL_TREE
;
8368 gimplify_omp_ctxp
= outer_ctx
;
8370 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
8371 && OMP_CLAUSE_LINEAR_STMT (c
))
8373 gimplify_omp_ctxp
= ctx
;
8374 push_gimplify_context ();
8375 if (TREE_CODE (OMP_CLAUSE_LINEAR_STMT (c
)) != BIND_EXPR
)
8377 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
,
8379 TREE_SIDE_EFFECTS (bind
) = 1;
8380 BIND_EXPR_BODY (bind
) = OMP_CLAUSE_LINEAR_STMT (c
);
8381 OMP_CLAUSE_LINEAR_STMT (c
) = bind
;
8383 gimplify_and_add (OMP_CLAUSE_LINEAR_STMT (c
),
8384 &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
));
8385 pop_gimplify_context
8386 (gimple_seq_first_stmt (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
)));
8387 OMP_CLAUSE_LINEAR_STMT (c
) = NULL_TREE
;
8389 gimplify_omp_ctxp
= outer_ctx
;
8395 case OMP_CLAUSE_COPYIN
:
8396 case OMP_CLAUSE_COPYPRIVATE
:
8397 decl
= OMP_CLAUSE_DECL (c
);
8398 if (error_operand_p (decl
))
8403 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_COPYPRIVATE
8405 && !omp_check_private (ctx
, decl
, true))
8408 if (is_global_var (decl
))
8410 if (DECL_THREAD_LOCAL_P (decl
))
8412 else if (DECL_HAS_VALUE_EXPR_P (decl
))
8414 tree value
= get_base_address (DECL_VALUE_EXPR (decl
));
8418 && DECL_THREAD_LOCAL_P (value
))
8423 error_at (OMP_CLAUSE_LOCATION (c
),
8424 "copyprivate variable %qE is not threadprivate"
8425 " or private in outer context", DECL_NAME (decl
));
8429 omp_notice_variable (outer_ctx
, decl
, true);
8430 if (check_non_private
8431 && region_type
== ORT_WORKSHARE
8432 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
8433 || decl
== OMP_CLAUSE_DECL (c
)
8434 || (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
8435 && (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0))
8437 || (TREE_CODE (TREE_OPERAND (OMP_CLAUSE_DECL (c
), 0))
8438 == POINTER_PLUS_EXPR
8439 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND
8440 (OMP_CLAUSE_DECL (c
), 0), 0))
8442 && omp_check_private (ctx
, decl
, false))
8444 error ("%s variable %qE is private in outer context",
8445 check_non_private
, DECL_NAME (decl
));
8451 if (OMP_CLAUSE_IF_MODIFIER (c
) != ERROR_MARK
8452 && OMP_CLAUSE_IF_MODIFIER (c
) != code
)
8455 for (int i
= 0; i
< 2; i
++)
8456 switch (i
? OMP_CLAUSE_IF_MODIFIER (c
) : code
)
8458 case OMP_PARALLEL
: p
[i
] = "parallel"; break;
8459 case OMP_TASK
: p
[i
] = "task"; break;
8460 case OMP_TASKLOOP
: p
[i
] = "taskloop"; break;
8461 case OMP_TARGET_DATA
: p
[i
] = "target data"; break;
8462 case OMP_TARGET
: p
[i
] = "target"; break;
8463 case OMP_TARGET_UPDATE
: p
[i
] = "target update"; break;
8464 case OMP_TARGET_ENTER_DATA
:
8465 p
[i
] = "target enter data"; break;
8466 case OMP_TARGET_EXIT_DATA
: p
[i
] = "target exit data"; break;
8467 default: gcc_unreachable ();
8469 error_at (OMP_CLAUSE_LOCATION (c
),
8470 "expected %qs %<if%> clause modifier rather than %qs",
8476 case OMP_CLAUSE_FINAL
:
8477 OMP_CLAUSE_OPERAND (c
, 0)
8478 = gimple_boolify (OMP_CLAUSE_OPERAND (c
, 0));
8481 case OMP_CLAUSE_SCHEDULE
:
8482 case OMP_CLAUSE_NUM_THREADS
:
8483 case OMP_CLAUSE_NUM_TEAMS
:
8484 case OMP_CLAUSE_THREAD_LIMIT
:
8485 case OMP_CLAUSE_DIST_SCHEDULE
:
8486 case OMP_CLAUSE_DEVICE
:
8487 case OMP_CLAUSE_PRIORITY
:
8488 case OMP_CLAUSE_GRAINSIZE
:
8489 case OMP_CLAUSE_NUM_TASKS
:
8490 case OMP_CLAUSE_HINT
:
8491 case OMP_CLAUSE_ASYNC
:
8492 case OMP_CLAUSE_WAIT
:
8493 case OMP_CLAUSE_NUM_GANGS
:
8494 case OMP_CLAUSE_NUM_WORKERS
:
8495 case OMP_CLAUSE_VECTOR_LENGTH
:
8496 case OMP_CLAUSE_WORKER
:
8497 case OMP_CLAUSE_VECTOR
:
8498 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 0), pre_p
, NULL
,
8499 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8503 case OMP_CLAUSE_GANG
:
8504 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 0), pre_p
, NULL
,
8505 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8507 if (gimplify_expr (&OMP_CLAUSE_OPERAND (c
, 1), pre_p
, NULL
,
8508 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8512 case OMP_CLAUSE_NOWAIT
:
8513 case OMP_CLAUSE_ORDERED
:
8514 case OMP_CLAUSE_UNTIED
:
8515 case OMP_CLAUSE_COLLAPSE
:
8516 case OMP_CLAUSE_TILE
:
8517 case OMP_CLAUSE_AUTO
:
8518 case OMP_CLAUSE_SEQ
:
8519 case OMP_CLAUSE_INDEPENDENT
:
8520 case OMP_CLAUSE_MERGEABLE
:
8521 case OMP_CLAUSE_PROC_BIND
:
8522 case OMP_CLAUSE_SAFELEN
:
8523 case OMP_CLAUSE_SIMDLEN
:
8524 case OMP_CLAUSE_NOGROUP
:
8525 case OMP_CLAUSE_THREADS
:
8526 case OMP_CLAUSE_SIMD
:
8527 case OMP_CLAUSE_IF_PRESENT
:
8528 case OMP_CLAUSE_FINALIZE
:
8531 case OMP_CLAUSE_DEFAULTMAP
:
8532 ctx
->target_map_scalars_firstprivate
= false;
8535 case OMP_CLAUSE_ALIGNED
:
8536 decl
= OMP_CLAUSE_DECL (c
);
8537 if (error_operand_p (decl
))
8542 if (gimplify_expr (&OMP_CLAUSE_ALIGNED_ALIGNMENT (c
), pre_p
, NULL
,
8543 is_gimple_val
, fb_rvalue
) == GS_ERROR
)
8548 if (!is_global_var (decl
)
8549 && TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
8550 omp_add_variable (ctx
, decl
, GOVD_ALIGNED
);
8553 case OMP_CLAUSE_DEFAULT
:
8554 ctx
->default_kind
= OMP_CLAUSE_DEFAULT_KIND (c
);
8561 if (code
== OACC_DATA
8562 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8563 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
8566 *list_p
= OMP_CLAUSE_CHAIN (c
);
8568 list_p
= &OMP_CLAUSE_CHAIN (c
);
8571 gimplify_omp_ctxp
= ctx
;
8572 if (struct_map_to_clause
)
8573 delete struct_map_to_clause
;
8576 /* Return true if DECL is a candidate for shared to firstprivate
8577 optimization. We only consider non-addressable scalars, not
8578 too big, and not references. */
8581 omp_shared_to_firstprivate_optimizable_decl_p (tree decl
)
8583 if (TREE_ADDRESSABLE (decl
))
8585 tree type
= TREE_TYPE (decl
);
8586 if (!is_gimple_reg_type (type
)
8587 || TREE_CODE (type
) == REFERENCE_TYPE
8588 || TREE_ADDRESSABLE (type
))
8590 /* Don't optimize too large decls, as each thread/task will have
8592 HOST_WIDE_INT len
= int_size_in_bytes (type
);
8593 if (len
== -1 || len
> 4 * POINTER_SIZE
/ BITS_PER_UNIT
)
8595 if (lang_hooks
.decls
.omp_privatize_by_reference (decl
))
8600 /* Helper function of omp_find_stores_op and gimplify_adjust_omp_clauses*.
8601 For omp_shared_to_firstprivate_optimizable_decl_p decl mark it as
8602 GOVD_WRITTEN in outer contexts. */
8605 omp_mark_stores (struct gimplify_omp_ctx
*ctx
, tree decl
)
8607 for (; ctx
; ctx
= ctx
->outer_context
)
8609 splay_tree_node n
= splay_tree_lookup (ctx
->variables
,
8610 (splay_tree_key
) decl
);
8613 else if (n
->value
& GOVD_SHARED
)
8615 n
->value
|= GOVD_WRITTEN
;
8618 else if (n
->value
& GOVD_DATA_SHARE_CLASS
)
8623 /* Helper callback for walk_gimple_seq to discover possible stores
8624 to omp_shared_to_firstprivate_optimizable_decl_p decls and set
8625 GOVD_WRITTEN if they are GOVD_SHARED in some outer context
8629 omp_find_stores_op (tree
*tp
, int *walk_subtrees
, void *data
)
8631 struct walk_stmt_info
*wi
= (struct walk_stmt_info
*) data
;
8640 if (handled_component_p (op
))
8641 op
= TREE_OPERAND (op
, 0);
8642 else if ((TREE_CODE (op
) == MEM_REF
|| TREE_CODE (op
) == TARGET_MEM_REF
)
8643 && TREE_CODE (TREE_OPERAND (op
, 0)) == ADDR_EXPR
)
8644 op
= TREE_OPERAND (TREE_OPERAND (op
, 0), 0);
8649 if (!DECL_P (op
) || !omp_shared_to_firstprivate_optimizable_decl_p (op
))
8652 omp_mark_stores (gimplify_omp_ctxp
, op
);
8656 /* Helper callback for walk_gimple_seq to discover possible stores
8657 to omp_shared_to_firstprivate_optimizable_decl_p decls and set
8658 GOVD_WRITTEN if they are GOVD_SHARED in some outer context
8662 omp_find_stores_stmt (gimple_stmt_iterator
*gsi_p
,
8663 bool *handled_ops_p
,
8664 struct walk_stmt_info
*wi
)
8666 gimple
*stmt
= gsi_stmt (*gsi_p
);
8667 switch (gimple_code (stmt
))
8669 /* Don't recurse on OpenMP constructs for which
8670 gimplify_adjust_omp_clauses already handled the bodies,
8671 except handle gimple_omp_for_pre_body. */
8672 case GIMPLE_OMP_FOR
:
8673 *handled_ops_p
= true;
8674 if (gimple_omp_for_pre_body (stmt
))
8675 walk_gimple_seq (gimple_omp_for_pre_body (stmt
),
8676 omp_find_stores_stmt
, omp_find_stores_op
, wi
);
8678 case GIMPLE_OMP_PARALLEL
:
8679 case GIMPLE_OMP_TASK
:
8680 case GIMPLE_OMP_SECTIONS
:
8681 case GIMPLE_OMP_SINGLE
:
8682 case GIMPLE_OMP_TARGET
:
8683 case GIMPLE_OMP_TEAMS
:
8684 case GIMPLE_OMP_CRITICAL
:
8685 *handled_ops_p
= true;
8693 struct gimplify_adjust_omp_clauses_data
8699 /* For all variables that were not actually used within the context,
8700 remove PRIVATE, SHARED, and FIRSTPRIVATE clauses. */
8703 gimplify_adjust_omp_clauses_1 (splay_tree_node n
, void *data
)
8705 tree
*list_p
= ((struct gimplify_adjust_omp_clauses_data
*) data
)->list_p
;
8707 = ((struct gimplify_adjust_omp_clauses_data
*) data
)->pre_p
;
8708 tree decl
= (tree
) n
->key
;
8709 unsigned flags
= n
->value
;
8710 enum omp_clause_code code
;
8714 if (flags
& (GOVD_EXPLICIT
| GOVD_LOCAL
))
8716 if ((flags
& GOVD_SEEN
) == 0)
8718 if (flags
& GOVD_DEBUG_PRIVATE
)
8720 gcc_assert ((flags
& GOVD_DATA_SHARE_CLASS
) == GOVD_SHARED
);
8721 private_debug
= true;
8723 else if (flags
& GOVD_MAP
)
8724 private_debug
= false;
8727 = lang_hooks
.decls
.omp_private_debug_clause (decl
,
8728 !!(flags
& GOVD_SHARED
));
8730 code
= OMP_CLAUSE_PRIVATE
;
8731 else if (flags
& GOVD_MAP
)
8733 code
= OMP_CLAUSE_MAP
;
8734 if ((gimplify_omp_ctxp
->region_type
& ORT_ACC
) == 0
8735 && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl
))))
8737 error ("%<_Atomic%> %qD in implicit %<map%> clause", decl
);
8741 else if (flags
& GOVD_SHARED
)
8743 if (is_global_var (decl
))
8745 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
->outer_context
;
8749 = splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
8750 if (on
&& (on
->value
& (GOVD_FIRSTPRIVATE
| GOVD_LASTPRIVATE
8751 | GOVD_PRIVATE
| GOVD_REDUCTION
8752 | GOVD_LINEAR
| GOVD_MAP
)) != 0)
8754 ctx
= ctx
->outer_context
;
8759 code
= OMP_CLAUSE_SHARED
;
8761 else if (flags
& GOVD_PRIVATE
)
8762 code
= OMP_CLAUSE_PRIVATE
;
8763 else if (flags
& GOVD_FIRSTPRIVATE
)
8765 code
= OMP_CLAUSE_FIRSTPRIVATE
;
8766 if ((gimplify_omp_ctxp
->region_type
& ORT_TARGET
)
8767 && (gimplify_omp_ctxp
->region_type
& ORT_ACC
) == 0
8768 && TYPE_ATOMIC (strip_array_types (TREE_TYPE (decl
))))
8770 error ("%<_Atomic%> %qD in implicit %<firstprivate%> clause on "
8771 "%<target%> construct", decl
);
8775 else if (flags
& GOVD_LASTPRIVATE
)
8776 code
= OMP_CLAUSE_LASTPRIVATE
;
8777 else if (flags
& GOVD_ALIGNED
)
8782 if (((flags
& GOVD_LASTPRIVATE
)
8783 || (code
== OMP_CLAUSE_SHARED
&& (flags
& GOVD_WRITTEN
)))
8784 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
8785 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
8787 tree chain
= *list_p
;
8788 clause
= build_omp_clause (input_location
, code
);
8789 OMP_CLAUSE_DECL (clause
) = decl
;
8790 OMP_CLAUSE_CHAIN (clause
) = chain
;
8792 OMP_CLAUSE_PRIVATE_DEBUG (clause
) = 1;
8793 else if (code
== OMP_CLAUSE_PRIVATE
&& (flags
& GOVD_PRIVATE_OUTER_REF
))
8794 OMP_CLAUSE_PRIVATE_OUTER_REF (clause
) = 1;
8795 else if (code
== OMP_CLAUSE_SHARED
8796 && (flags
& GOVD_WRITTEN
) == 0
8797 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
8798 OMP_CLAUSE_SHARED_READONLY (clause
) = 1;
8799 else if (code
== OMP_CLAUSE_FIRSTPRIVATE
&& (flags
& GOVD_EXPLICIT
) == 0)
8800 OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause
) = 1;
8801 else if (code
== OMP_CLAUSE_MAP
&& (flags
& GOVD_MAP_0LEN_ARRAY
) != 0)
8803 tree nc
= build_omp_clause (input_location
, OMP_CLAUSE_MAP
);
8804 OMP_CLAUSE_DECL (nc
) = decl
;
8805 if (TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
8806 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) == POINTER_TYPE
)
8807 OMP_CLAUSE_DECL (clause
)
8808 = build_simple_mem_ref_loc (input_location
, decl
);
8809 OMP_CLAUSE_DECL (clause
)
8810 = build2 (MEM_REF
, char_type_node
, OMP_CLAUSE_DECL (clause
),
8811 build_int_cst (build_pointer_type (char_type_node
), 0));
8812 OMP_CLAUSE_SIZE (clause
) = size_zero_node
;
8813 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
8814 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_ALLOC
);
8815 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (clause
) = 1;
8816 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
8817 OMP_CLAUSE_CHAIN (nc
) = chain
;
8818 OMP_CLAUSE_CHAIN (clause
) = nc
;
8819 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
8820 gimplify_omp_ctxp
= ctx
->outer_context
;
8821 gimplify_expr (&TREE_OPERAND (OMP_CLAUSE_DECL (clause
), 0),
8822 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8823 gimplify_omp_ctxp
= ctx
;
8825 else if (code
== OMP_CLAUSE_MAP
)
8828 /* Not all combinations of these GOVD_MAP flags are actually valid. */
8829 switch (flags
& (GOVD_MAP_TO_ONLY
8831 | GOVD_MAP_FORCE_PRESENT
))
8834 kind
= GOMP_MAP_TOFROM
;
8836 case GOVD_MAP_FORCE
:
8837 kind
= GOMP_MAP_TOFROM
| GOMP_MAP_FLAG_FORCE
;
8839 case GOVD_MAP_TO_ONLY
:
8842 case GOVD_MAP_TO_ONLY
| GOVD_MAP_FORCE
:
8843 kind
= GOMP_MAP_TO
| GOMP_MAP_FLAG_FORCE
;
8845 case GOVD_MAP_FORCE_PRESENT
:
8846 kind
= GOMP_MAP_FORCE_PRESENT
;
8851 OMP_CLAUSE_SET_MAP_KIND (clause
, kind
);
8852 if (DECL_SIZE (decl
)
8853 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
8855 tree decl2
= DECL_VALUE_EXPR (decl
);
8856 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
8857 decl2
= TREE_OPERAND (decl2
, 0);
8858 gcc_assert (DECL_P (decl2
));
8859 tree mem
= build_simple_mem_ref (decl2
);
8860 OMP_CLAUSE_DECL (clause
) = mem
;
8861 OMP_CLAUSE_SIZE (clause
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8862 if (gimplify_omp_ctxp
->outer_context
)
8864 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
->outer_context
;
8865 omp_notice_variable (ctx
, decl2
, true);
8866 omp_notice_variable (ctx
, OMP_CLAUSE_SIZE (clause
), true);
8868 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
),
8870 OMP_CLAUSE_DECL (nc
) = decl
;
8871 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
8872 if (gimplify_omp_ctxp
->target_firstprivatize_array_bases
)
8873 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
8875 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_POINTER
);
8876 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (clause
);
8877 OMP_CLAUSE_CHAIN (clause
) = nc
;
8879 else if (gimplify_omp_ctxp
->target_firstprivatize_array_bases
8880 && lang_hooks
.decls
.omp_privatize_by_reference (decl
))
8882 OMP_CLAUSE_DECL (clause
) = build_simple_mem_ref (decl
);
8883 OMP_CLAUSE_SIZE (clause
)
8884 = unshare_expr (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl
))));
8885 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
8886 gimplify_omp_ctxp
= ctx
->outer_context
;
8887 gimplify_expr (&OMP_CLAUSE_SIZE (clause
),
8888 pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
8889 gimplify_omp_ctxp
= ctx
;
8890 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
),
8892 OMP_CLAUSE_DECL (nc
) = decl
;
8893 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
8894 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
8895 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (clause
);
8896 OMP_CLAUSE_CHAIN (clause
) = nc
;
8899 OMP_CLAUSE_SIZE (clause
) = DECL_SIZE_UNIT (decl
);
8901 if (code
== OMP_CLAUSE_FIRSTPRIVATE
&& (flags
& GOVD_LASTPRIVATE
) != 0)
8903 tree nc
= build_omp_clause (input_location
, OMP_CLAUSE_LASTPRIVATE
);
8904 OMP_CLAUSE_DECL (nc
) = decl
;
8905 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (nc
) = 1;
8906 OMP_CLAUSE_CHAIN (nc
) = chain
;
8907 OMP_CLAUSE_CHAIN (clause
) = nc
;
8908 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
8909 gimplify_omp_ctxp
= ctx
->outer_context
;
8910 lang_hooks
.decls
.omp_finish_clause (nc
, pre_p
);
8911 gimplify_omp_ctxp
= ctx
;
8914 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
8915 gimplify_omp_ctxp
= ctx
->outer_context
;
8916 lang_hooks
.decls
.omp_finish_clause (clause
, pre_p
);
8917 if (gimplify_omp_ctxp
)
8918 for (; clause
!= chain
; clause
= OMP_CLAUSE_CHAIN (clause
))
8919 if (OMP_CLAUSE_CODE (clause
) == OMP_CLAUSE_MAP
8920 && DECL_P (OMP_CLAUSE_SIZE (clause
)))
8921 omp_notice_variable (gimplify_omp_ctxp
, OMP_CLAUSE_SIZE (clause
),
8923 gimplify_omp_ctxp
= ctx
;
8928 gimplify_adjust_omp_clauses (gimple_seq
*pre_p
, gimple_seq body
, tree
*list_p
,
8929 enum tree_code code
)
8931 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
8936 struct gimplify_omp_ctx
*octx
;
8937 for (octx
= ctx
; octx
; octx
= octx
->outer_context
)
8938 if ((octx
->region_type
& (ORT_PARALLEL
| ORT_TASK
| ORT_TEAMS
)) != 0)
8942 struct walk_stmt_info wi
;
8943 memset (&wi
, 0, sizeof (wi
));
8944 walk_gimple_seq (body
, omp_find_stores_stmt
,
8945 omp_find_stores_op
, &wi
);
8948 while ((c
= *list_p
) != NULL
)
8951 bool remove
= false;
8953 switch (OMP_CLAUSE_CODE (c
))
8955 case OMP_CLAUSE_FIRSTPRIVATE
:
8956 if ((ctx
->region_type
& ORT_TARGET
)
8957 && (ctx
->region_type
& ORT_ACC
) == 0
8958 && TYPE_ATOMIC (strip_array_types
8959 (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
8961 error_at (OMP_CLAUSE_LOCATION (c
),
8962 "%<_Atomic%> %qD in %<firstprivate%> clause on "
8963 "%<target%> construct", OMP_CLAUSE_DECL (c
));
8968 case OMP_CLAUSE_PRIVATE
:
8969 case OMP_CLAUSE_SHARED
:
8970 case OMP_CLAUSE_LINEAR
:
8971 decl
= OMP_CLAUSE_DECL (c
);
8972 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
8973 remove
= !(n
->value
& GOVD_SEEN
);
8976 bool shared
= OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
;
8977 if ((n
->value
& GOVD_DEBUG_PRIVATE
)
8978 || lang_hooks
.decls
.omp_private_debug_clause (decl
, shared
))
8980 gcc_assert ((n
->value
& GOVD_DEBUG_PRIVATE
) == 0
8981 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
8983 OMP_CLAUSE_SET_CODE (c
, OMP_CLAUSE_PRIVATE
);
8984 OMP_CLAUSE_PRIVATE_DEBUG (c
) = 1;
8986 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8987 && (n
->value
& GOVD_WRITTEN
) == 0
8989 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
8990 OMP_CLAUSE_SHARED_READONLY (c
) = 1;
8991 else if (DECL_P (decl
)
8992 && ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8993 && (n
->value
& GOVD_WRITTEN
) != 0)
8994 || (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
8995 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)))
8996 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
8997 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9001 case OMP_CLAUSE_LASTPRIVATE
:
9002 /* Make sure OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE is set to
9003 accurately reflect the presence of a FIRSTPRIVATE clause. */
9004 decl
= OMP_CLAUSE_DECL (c
);
9005 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9006 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
)
9007 = (n
->value
& GOVD_FIRSTPRIVATE
) != 0;
9008 if (code
== OMP_DISTRIBUTE
9009 && OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
9012 error_at (OMP_CLAUSE_LOCATION (c
),
9013 "same variable used in %<firstprivate%> and "
9014 "%<lastprivate%> clauses on %<distribute%> "
9018 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9020 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9021 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9024 case OMP_CLAUSE_ALIGNED
:
9025 decl
= OMP_CLAUSE_DECL (c
);
9026 if (!is_global_var (decl
))
9028 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9029 remove
= n
== NULL
|| !(n
->value
& GOVD_SEEN
);
9030 if (!remove
&& TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
9032 struct gimplify_omp_ctx
*octx
;
9034 && (n
->value
& (GOVD_DATA_SHARE_CLASS
9035 & ~GOVD_FIRSTPRIVATE
)))
9038 for (octx
= ctx
->outer_context
; octx
;
9039 octx
= octx
->outer_context
)
9041 n
= splay_tree_lookup (octx
->variables
,
9042 (splay_tree_key
) decl
);
9045 if (n
->value
& GOVD_LOCAL
)
9047 /* We have to avoid assigning a shared variable
9048 to itself when trying to add
9049 __builtin_assume_aligned. */
9050 if (n
->value
& GOVD_SHARED
)
9058 else if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9060 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9061 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
9066 case OMP_CLAUSE_MAP
:
9067 if (code
== OMP_TARGET_EXIT_DATA
9068 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
)
9073 decl
= OMP_CLAUSE_DECL (c
);
9074 /* Data clauses associated with acc parallel reductions must be
9075 compatible with present_or_copy. Warn and adjust the clause
9076 if that is not the case. */
9077 if (ctx
->region_type
== ORT_ACC_PARALLEL
)
9079 tree t
= DECL_P (decl
) ? decl
: TREE_OPERAND (decl
, 0);
9083 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) t
);
9085 if (n
&& (n
->value
& GOVD_REDUCTION
))
9087 enum gomp_map_kind kind
= OMP_CLAUSE_MAP_KIND (c
);
9089 OMP_CLAUSE_MAP_IN_REDUCTION (c
) = 1;
9090 if ((kind
& GOMP_MAP_TOFROM
) != GOMP_MAP_TOFROM
9091 && kind
!= GOMP_MAP_FORCE_PRESENT
9092 && kind
!= GOMP_MAP_POINTER
)
9094 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
9095 "incompatible data clause with reduction "
9096 "on %qE; promoting to present_or_copy",
9098 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TOFROM
);
9104 if ((ctx
->region_type
& ORT_TARGET
) != 0
9105 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
9107 if (TREE_CODE (decl
) == INDIRECT_REF
9108 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
9109 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (decl
, 0)))
9111 decl
= TREE_OPERAND (decl
, 0);
9112 if (TREE_CODE (decl
) == COMPONENT_REF
)
9114 while (TREE_CODE (decl
) == COMPONENT_REF
)
9115 decl
= TREE_OPERAND (decl
, 0);
9118 n
= splay_tree_lookup (ctx
->variables
,
9119 (splay_tree_key
) decl
);
9120 if (!(n
->value
& GOVD_SEEN
))
9127 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9128 if ((ctx
->region_type
& ORT_TARGET
) != 0
9129 && !(n
->value
& GOVD_SEEN
)
9130 && GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c
)) == 0
9131 && (!is_global_var (decl
)
9132 || !lookup_attribute ("omp declare target link",
9133 DECL_ATTRIBUTES (decl
))))
9136 /* For struct element mapping, if struct is never referenced
9137 in target block and none of the mapping has always modifier,
9138 remove all the struct element mappings, which immediately
9139 follow the GOMP_MAP_STRUCT map clause. */
9140 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_STRUCT
)
9142 HOST_WIDE_INT cnt
= tree_to_shwi (OMP_CLAUSE_SIZE (c
));
9144 OMP_CLAUSE_CHAIN (c
)
9145 = OMP_CLAUSE_CHAIN (OMP_CLAUSE_CHAIN (c
));
9148 else if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_STRUCT
9149 && code
== OMP_TARGET_EXIT_DATA
)
9151 else if (DECL_SIZE (decl
)
9152 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
9153 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_POINTER
9154 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FIRSTPRIVATE_POINTER
9155 && (OMP_CLAUSE_MAP_KIND (c
)
9156 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
9158 /* For GOMP_MAP_FORCE_DEVICEPTR, we'll never enter here, because
9159 for these, TREE_CODE (DECL_SIZE (decl)) will always be
9161 gcc_assert (OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FORCE_DEVICEPTR
);
9163 tree decl2
= DECL_VALUE_EXPR (decl
);
9164 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
9165 decl2
= TREE_OPERAND (decl2
, 0);
9166 gcc_assert (DECL_P (decl2
));
9167 tree mem
= build_simple_mem_ref (decl2
);
9168 OMP_CLAUSE_DECL (c
) = mem
;
9169 OMP_CLAUSE_SIZE (c
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
9170 if (ctx
->outer_context
)
9172 omp_notice_variable (ctx
->outer_context
, decl2
, true);
9173 omp_notice_variable (ctx
->outer_context
,
9174 OMP_CLAUSE_SIZE (c
), true);
9176 if (((ctx
->region_type
& ORT_TARGET
) != 0
9177 || !ctx
->target_firstprivatize_array_bases
)
9178 && ((n
->value
& GOVD_SEEN
) == 0
9179 || (n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
)) == 0))
9181 tree nc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
9183 OMP_CLAUSE_DECL (nc
) = decl
;
9184 OMP_CLAUSE_SIZE (nc
) = size_zero_node
;
9185 if (ctx
->target_firstprivatize_array_bases
)
9186 OMP_CLAUSE_SET_MAP_KIND (nc
,
9187 GOMP_MAP_FIRSTPRIVATE_POINTER
);
9189 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_POINTER
);
9190 OMP_CLAUSE_CHAIN (nc
) = OMP_CLAUSE_CHAIN (c
);
9191 OMP_CLAUSE_CHAIN (c
) = nc
;
9197 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
9198 OMP_CLAUSE_SIZE (c
) = DECL_SIZE_UNIT (decl
);
9199 gcc_assert ((n
->value
& GOVD_SEEN
) == 0
9200 || ((n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
))
9206 case OMP_CLAUSE_FROM
:
9207 case OMP_CLAUSE__CACHE_
:
9208 decl
= OMP_CLAUSE_DECL (c
);
9211 if (DECL_SIZE (decl
)
9212 && TREE_CODE (DECL_SIZE (decl
)) != INTEGER_CST
)
9214 tree decl2
= DECL_VALUE_EXPR (decl
);
9215 gcc_assert (TREE_CODE (decl2
) == INDIRECT_REF
);
9216 decl2
= TREE_OPERAND (decl2
, 0);
9217 gcc_assert (DECL_P (decl2
));
9218 tree mem
= build_simple_mem_ref (decl2
);
9219 OMP_CLAUSE_DECL (c
) = mem
;
9220 OMP_CLAUSE_SIZE (c
) = TYPE_SIZE_UNIT (TREE_TYPE (decl
));
9221 if (ctx
->outer_context
)
9223 omp_notice_variable (ctx
->outer_context
, decl2
, true);
9224 omp_notice_variable (ctx
->outer_context
,
9225 OMP_CLAUSE_SIZE (c
), true);
9228 else if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
9229 OMP_CLAUSE_SIZE (c
) = DECL_SIZE_UNIT (decl
);
9232 case OMP_CLAUSE_REDUCTION
:
9233 decl
= OMP_CLAUSE_DECL (c
);
9234 /* OpenACC reductions need a present_or_copy data clause.
9235 Add one if necessary. Emit error when the reduction is private. */
9236 if (ctx
->region_type
== ORT_ACC_PARALLEL
)
9238 n
= splay_tree_lookup (ctx
->variables
, (splay_tree_key
) decl
);
9239 if (n
->value
& (GOVD_PRIVATE
| GOVD_FIRSTPRIVATE
))
9242 error_at (OMP_CLAUSE_LOCATION (c
), "invalid private "
9243 "reduction on %qE", DECL_NAME (decl
));
9245 else if ((n
->value
& GOVD_MAP
) == 0)
9247 tree next
= OMP_CLAUSE_CHAIN (c
);
9248 tree nc
= build_omp_clause (UNKNOWN_LOCATION
, OMP_CLAUSE_MAP
);
9249 OMP_CLAUSE_SET_MAP_KIND (nc
, GOMP_MAP_TOFROM
);
9250 OMP_CLAUSE_DECL (nc
) = decl
;
9251 OMP_CLAUSE_CHAIN (c
) = nc
;
9252 lang_hooks
.decls
.omp_finish_clause (nc
, pre_p
);
9255 OMP_CLAUSE_MAP_IN_REDUCTION (nc
) = 1;
9256 if (OMP_CLAUSE_CHAIN (nc
) == NULL
)
9258 nc
= OMP_CLAUSE_CHAIN (nc
);
9260 OMP_CLAUSE_CHAIN (nc
) = next
;
9261 n
->value
|= GOVD_MAP
;
9265 && omp_shared_to_firstprivate_optimizable_decl_p (decl
))
9266 omp_mark_stores (gimplify_omp_ctxp
->outer_context
, decl
);
9268 case OMP_CLAUSE_COPYIN
:
9269 case OMP_CLAUSE_COPYPRIVATE
:
9271 case OMP_CLAUSE_NUM_THREADS
:
9272 case OMP_CLAUSE_NUM_TEAMS
:
9273 case OMP_CLAUSE_THREAD_LIMIT
:
9274 case OMP_CLAUSE_DIST_SCHEDULE
:
9275 case OMP_CLAUSE_DEVICE
:
9276 case OMP_CLAUSE_SCHEDULE
:
9277 case OMP_CLAUSE_NOWAIT
:
9278 case OMP_CLAUSE_ORDERED
:
9279 case OMP_CLAUSE_DEFAULT
:
9280 case OMP_CLAUSE_UNTIED
:
9281 case OMP_CLAUSE_COLLAPSE
:
9282 case OMP_CLAUSE_FINAL
:
9283 case OMP_CLAUSE_MERGEABLE
:
9284 case OMP_CLAUSE_PROC_BIND
:
9285 case OMP_CLAUSE_SAFELEN
:
9286 case OMP_CLAUSE_SIMDLEN
:
9287 case OMP_CLAUSE_DEPEND
:
9288 case OMP_CLAUSE_PRIORITY
:
9289 case OMP_CLAUSE_GRAINSIZE
:
9290 case OMP_CLAUSE_NUM_TASKS
:
9291 case OMP_CLAUSE_NOGROUP
:
9292 case OMP_CLAUSE_THREADS
:
9293 case OMP_CLAUSE_SIMD
:
9294 case OMP_CLAUSE_HINT
:
9295 case OMP_CLAUSE_DEFAULTMAP
:
9296 case OMP_CLAUSE_USE_DEVICE_PTR
:
9297 case OMP_CLAUSE_IS_DEVICE_PTR
:
9298 case OMP_CLAUSE_ASYNC
:
9299 case OMP_CLAUSE_WAIT
:
9300 case OMP_CLAUSE_INDEPENDENT
:
9301 case OMP_CLAUSE_NUM_GANGS
:
9302 case OMP_CLAUSE_NUM_WORKERS
:
9303 case OMP_CLAUSE_VECTOR_LENGTH
:
9304 case OMP_CLAUSE_GANG
:
9305 case OMP_CLAUSE_WORKER
:
9306 case OMP_CLAUSE_VECTOR
:
9307 case OMP_CLAUSE_AUTO
:
9308 case OMP_CLAUSE_SEQ
:
9309 case OMP_CLAUSE_TILE
:
9310 case OMP_CLAUSE_IF_PRESENT
:
9311 case OMP_CLAUSE_FINALIZE
:
9319 *list_p
= OMP_CLAUSE_CHAIN (c
);
9321 list_p
= &OMP_CLAUSE_CHAIN (c
);
9324 /* Add in any implicit data sharing. */
9325 struct gimplify_adjust_omp_clauses_data data
;
9326 data
.list_p
= list_p
;
9328 splay_tree_foreach (ctx
->variables
, gimplify_adjust_omp_clauses_1
, &data
);
9330 gimplify_omp_ctxp
= ctx
->outer_context
;
9331 delete_omp_context (ctx
);
9334 /* Gimplify OACC_CACHE. */
9337 gimplify_oacc_cache (tree
*expr_p
, gimple_seq
*pre_p
)
9339 tree expr
= *expr_p
;
9341 gimplify_scan_omp_clauses (&OACC_CACHE_CLAUSES (expr
), pre_p
, ORT_ACC
,
9343 gimplify_adjust_omp_clauses (pre_p
, NULL
, &OACC_CACHE_CLAUSES (expr
),
9346 /* TODO: Do something sensible with this information. */
9348 *expr_p
= NULL_TREE
;
9351 /* Helper function of gimplify_oacc_declare. The helper's purpose is to,
9352 if required, translate 'kind' in CLAUSE into an 'entry' kind and 'exit'
9353 kind. The entry kind will replace the one in CLAUSE, while the exit
9354 kind will be used in a new omp_clause and returned to the caller. */
9357 gimplify_oacc_declare_1 (tree clause
)
9359 HOST_WIDE_INT kind
, new_op
;
9363 kind
= OMP_CLAUSE_MAP_KIND (clause
);
9367 case GOMP_MAP_ALLOC
:
9368 new_op
= GOMP_MAP_RELEASE
;
9373 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_FORCE_ALLOC
);
9374 new_op
= GOMP_MAP_FROM
;
9378 case GOMP_MAP_TOFROM
:
9379 OMP_CLAUSE_SET_MAP_KIND (clause
, GOMP_MAP_TO
);
9380 new_op
= GOMP_MAP_FROM
;
9384 case GOMP_MAP_DEVICE_RESIDENT
:
9385 case GOMP_MAP_FORCE_DEVICEPTR
:
9386 case GOMP_MAP_FORCE_PRESENT
:
9388 case GOMP_MAP_POINTER
:
9399 c
= build_omp_clause (OMP_CLAUSE_LOCATION (clause
), OMP_CLAUSE_MAP
);
9400 OMP_CLAUSE_SET_MAP_KIND (c
, new_op
);
9401 OMP_CLAUSE_DECL (c
) = OMP_CLAUSE_DECL (clause
);
9407 /* Gimplify OACC_DECLARE. */
9410 gimplify_oacc_declare (tree
*expr_p
, gimple_seq
*pre_p
)
9412 tree expr
= *expr_p
;
9414 tree clauses
, t
, decl
;
9416 clauses
= OACC_DECLARE_CLAUSES (expr
);
9418 gimplify_scan_omp_clauses (&clauses
, pre_p
, ORT_TARGET_DATA
, OACC_DECLARE
);
9419 gimplify_adjust_omp_clauses (pre_p
, NULL
, &clauses
, OACC_DECLARE
);
9421 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
9423 decl
= OMP_CLAUSE_DECL (t
);
9425 if (TREE_CODE (decl
) == MEM_REF
)
9426 decl
= TREE_OPERAND (decl
, 0);
9428 if (VAR_P (decl
) && !is_oacc_declared (decl
))
9430 tree attr
= get_identifier ("oacc declare target");
9431 DECL_ATTRIBUTES (decl
) = tree_cons (attr
, NULL_TREE
,
9432 DECL_ATTRIBUTES (decl
));
9436 && !is_global_var (decl
)
9437 && DECL_CONTEXT (decl
) == current_function_decl
)
9439 tree c
= gimplify_oacc_declare_1 (t
);
9442 if (oacc_declare_returns
== NULL
)
9443 oacc_declare_returns
= new hash_map
<tree
, tree
>;
9445 oacc_declare_returns
->put (decl
, c
);
9449 if (gimplify_omp_ctxp
)
9450 omp_add_variable (gimplify_omp_ctxp
, decl
, GOVD_SEEN
);
9453 stmt
= gimple_build_omp_target (NULL
, GF_OMP_TARGET_KIND_OACC_DECLARE
,
9456 gimplify_seq_add_stmt (pre_p
, stmt
);
9458 *expr_p
= NULL_TREE
;
9461 /* Gimplify the contents of an OMP_PARALLEL statement. This involves
9462 gimplification of the body, as well as scanning the body for used
9463 variables. We need to do this scan now, because variable-sized
9464 decls will be decomposed during gimplification. */
9467 gimplify_omp_parallel (tree
*expr_p
, gimple_seq
*pre_p
)
9469 tree expr
= *expr_p
;
9471 gimple_seq body
= NULL
;
9473 gimplify_scan_omp_clauses (&OMP_PARALLEL_CLAUSES (expr
), pre_p
,
9474 OMP_PARALLEL_COMBINED (expr
)
9475 ? ORT_COMBINED_PARALLEL
9476 : ORT_PARALLEL
, OMP_PARALLEL
);
9478 push_gimplify_context ();
9480 g
= gimplify_and_return_first (OMP_PARALLEL_BODY (expr
), &body
);
9481 if (gimple_code (g
) == GIMPLE_BIND
)
9482 pop_gimplify_context (g
);
9484 pop_gimplify_context (NULL
);
9486 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_PARALLEL_CLAUSES (expr
),
9489 g
= gimple_build_omp_parallel (body
,
9490 OMP_PARALLEL_CLAUSES (expr
),
9491 NULL_TREE
, NULL_TREE
);
9492 if (OMP_PARALLEL_COMBINED (expr
))
9493 gimple_omp_set_subcode (g
, GF_OMP_PARALLEL_COMBINED
);
9494 gimplify_seq_add_stmt (pre_p
, g
);
9495 *expr_p
= NULL_TREE
;
9498 /* Gimplify the contents of an OMP_TASK statement. This involves
9499 gimplification of the body, as well as scanning the body for used
9500 variables. We need to do this scan now, because variable-sized
9501 decls will be decomposed during gimplification. */
9504 gimplify_omp_task (tree
*expr_p
, gimple_seq
*pre_p
)
9506 tree expr
= *expr_p
;
9508 gimple_seq body
= NULL
;
9510 gimplify_scan_omp_clauses (&OMP_TASK_CLAUSES (expr
), pre_p
,
9511 omp_find_clause (OMP_TASK_CLAUSES (expr
),
9513 ? ORT_UNTIED_TASK
: ORT_TASK
, OMP_TASK
);
9515 push_gimplify_context ();
9517 g
= gimplify_and_return_first (OMP_TASK_BODY (expr
), &body
);
9518 if (gimple_code (g
) == GIMPLE_BIND
)
9519 pop_gimplify_context (g
);
9521 pop_gimplify_context (NULL
);
9523 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_TASK_CLAUSES (expr
),
9526 g
= gimple_build_omp_task (body
,
9527 OMP_TASK_CLAUSES (expr
),
9528 NULL_TREE
, NULL_TREE
,
9529 NULL_TREE
, NULL_TREE
, NULL_TREE
);
9530 gimplify_seq_add_stmt (pre_p
, g
);
9531 *expr_p
= NULL_TREE
;
9534 /* Helper function of gimplify_omp_for, find OMP_FOR resp. OMP_SIMD
9535 with non-NULL OMP_FOR_INIT. */
9538 find_combined_omp_for (tree
*tp
, int *walk_subtrees
, void *)
9541 switch (TREE_CODE (*tp
))
9547 if (OMP_FOR_INIT (*tp
) != NULL_TREE
)
9551 case STATEMENT_LIST
:
9561 /* Gimplify the gross structure of an OMP_FOR statement. */
9563 static enum gimplify_status
9564 gimplify_omp_for (tree
*expr_p
, gimple_seq
*pre_p
)
9566 tree for_stmt
, orig_for_stmt
, inner_for_stmt
= NULL_TREE
, decl
, var
, t
;
9567 enum gimplify_status ret
= GS_ALL_DONE
;
9568 enum gimplify_status tret
;
9570 gimple_seq for_body
, for_pre_body
;
9572 bitmap has_decl_expr
= NULL
;
9573 enum omp_region_type ort
= ORT_WORKSHARE
;
9575 orig_for_stmt
= for_stmt
= *expr_p
;
9577 switch (TREE_CODE (for_stmt
))
9580 case OMP_DISTRIBUTE
:
9586 if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_UNTIED
))
9587 ort
= ORT_UNTIED_TASK
;
9598 /* Set OMP_CLAUSE_LINEAR_NO_COPYIN flag on explicit linear
9599 clause for the IV. */
9600 if (ort
== ORT_SIMD
&& TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
9602 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), 0);
9603 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
9604 decl
= TREE_OPERAND (t
, 0);
9605 for (tree c
= OMP_FOR_CLAUSES (for_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
9606 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
9607 && OMP_CLAUSE_DECL (c
) == decl
)
9609 OMP_CLAUSE_LINEAR_NO_COPYIN (c
) = 1;
9614 if (OMP_FOR_INIT (for_stmt
) == NULL_TREE
)
9616 gcc_assert (TREE_CODE (for_stmt
) != OACC_LOOP
);
9617 inner_for_stmt
= walk_tree (&OMP_FOR_BODY (for_stmt
),
9618 find_combined_omp_for
, NULL
, NULL
);
9619 if (inner_for_stmt
== NULL_TREE
)
9621 gcc_assert (seen_error ());
9622 *expr_p
= NULL_TREE
;
9627 if (TREE_CODE (for_stmt
) != OMP_TASKLOOP
)
9628 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (for_stmt
), pre_p
, ort
,
9629 TREE_CODE (for_stmt
));
9631 if (TREE_CODE (for_stmt
) == OMP_DISTRIBUTE
)
9632 gimplify_omp_ctxp
->distribute
= true;
9634 /* Handle OMP_FOR_INIT. */
9635 for_pre_body
= NULL
;
9636 if (ort
== ORT_SIMD
&& OMP_FOR_PRE_BODY (for_stmt
))
9638 has_decl_expr
= BITMAP_ALLOC (NULL
);
9639 if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt
)) == DECL_EXPR
9640 && TREE_CODE (DECL_EXPR_DECL (OMP_FOR_PRE_BODY (for_stmt
)))
9643 t
= OMP_FOR_PRE_BODY (for_stmt
);
9644 bitmap_set_bit (has_decl_expr
, DECL_UID (DECL_EXPR_DECL (t
)));
9646 else if (TREE_CODE (OMP_FOR_PRE_BODY (for_stmt
)) == STATEMENT_LIST
)
9648 tree_stmt_iterator si
;
9649 for (si
= tsi_start (OMP_FOR_PRE_BODY (for_stmt
)); !tsi_end_p (si
);
9653 if (TREE_CODE (t
) == DECL_EXPR
9654 && TREE_CODE (DECL_EXPR_DECL (t
)) == VAR_DECL
)
9655 bitmap_set_bit (has_decl_expr
, DECL_UID (DECL_EXPR_DECL (t
)));
9659 if (OMP_FOR_PRE_BODY (for_stmt
))
9661 if (TREE_CODE (for_stmt
) != OMP_TASKLOOP
|| gimplify_omp_ctxp
)
9662 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt
), &for_pre_body
);
9665 struct gimplify_omp_ctx ctx
;
9666 memset (&ctx
, 0, sizeof (ctx
));
9667 ctx
.region_type
= ORT_NONE
;
9668 gimplify_omp_ctxp
= &ctx
;
9669 gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt
), &for_pre_body
);
9670 gimplify_omp_ctxp
= NULL
;
9673 OMP_FOR_PRE_BODY (for_stmt
) = NULL_TREE
;
9675 if (OMP_FOR_INIT (for_stmt
) == NULL_TREE
)
9676 for_stmt
= inner_for_stmt
;
9678 /* For taskloop, need to gimplify the start, end and step before the
9679 taskloop, outside of the taskloop omp context. */
9680 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
9682 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
9684 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
9685 if (!is_gimple_constant (TREE_OPERAND (t
, 1)))
9688 = get_initialized_tmp_var (TREE_OPERAND (t
, 1),
9689 pre_p
, NULL
, false);
9690 tree c
= build_omp_clause (input_location
,
9691 OMP_CLAUSE_FIRSTPRIVATE
);
9692 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (t
, 1);
9693 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
9694 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
9697 /* Handle OMP_FOR_COND. */
9698 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
9699 if (!is_gimple_constant (TREE_OPERAND (t
, 1)))
9702 = get_initialized_tmp_var (TREE_OPERAND (t
, 1),
9703 gimple_seq_empty_p (for_pre_body
)
9704 ? pre_p
: &for_pre_body
, NULL
,
9706 tree c
= build_omp_clause (input_location
,
9707 OMP_CLAUSE_FIRSTPRIVATE
);
9708 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (t
, 1);
9709 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
9710 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
9713 /* Handle OMP_FOR_INCR. */
9714 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
9715 if (TREE_CODE (t
) == MODIFY_EXPR
)
9717 decl
= TREE_OPERAND (t
, 0);
9718 t
= TREE_OPERAND (t
, 1);
9719 tree
*tp
= &TREE_OPERAND (t
, 1);
9720 if (TREE_CODE (t
) == PLUS_EXPR
&& *tp
== decl
)
9721 tp
= &TREE_OPERAND (t
, 0);
9723 if (!is_gimple_constant (*tp
))
9725 gimple_seq
*seq
= gimple_seq_empty_p (for_pre_body
)
9726 ? pre_p
: &for_pre_body
;
9727 *tp
= get_initialized_tmp_var (*tp
, seq
, NULL
, false);
9728 tree c
= build_omp_clause (input_location
,
9729 OMP_CLAUSE_FIRSTPRIVATE
);
9730 OMP_CLAUSE_DECL (c
) = *tp
;
9731 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (orig_for_stmt
);
9732 OMP_FOR_CLAUSES (orig_for_stmt
) = c
;
9737 gimplify_scan_omp_clauses (&OMP_FOR_CLAUSES (orig_for_stmt
), pre_p
, ort
,
9741 if (orig_for_stmt
!= for_stmt
)
9742 gimplify_omp_ctxp
->combined_loop
= true;
9745 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
9746 == TREE_VEC_LENGTH (OMP_FOR_COND (for_stmt
)));
9747 gcc_assert (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
9748 == TREE_VEC_LENGTH (OMP_FOR_INCR (for_stmt
)));
9750 tree c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_ORDERED
);
9751 bool is_doacross
= false;
9752 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
9755 gimplify_omp_ctxp
->loop_iter_var
.create (TREE_VEC_LENGTH
9756 (OMP_FOR_INIT (for_stmt
))
9759 int collapse
= 1, tile
= 0;
9760 c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_COLLAPSE
);
9762 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
9763 c
= omp_find_clause (OMP_FOR_CLAUSES (for_stmt
), OMP_CLAUSE_TILE
);
9765 tile
= list_length (OMP_CLAUSE_TILE_LIST (c
));
9766 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
9768 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
9769 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
9770 decl
= TREE_OPERAND (t
, 0);
9771 gcc_assert (DECL_P (decl
));
9772 gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9773 || POINTER_TYPE_P (TREE_TYPE (decl
)));
9776 if (TREE_CODE (for_stmt
) == OMP_FOR
&& OMP_FOR_ORIG_DECLS (for_stmt
))
9777 gimplify_omp_ctxp
->loop_iter_var
.quick_push
9778 (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt
), i
));
9780 gimplify_omp_ctxp
->loop_iter_var
.quick_push (decl
);
9781 gimplify_omp_ctxp
->loop_iter_var
.quick_push (decl
);
9784 /* Make sure the iteration variable is private. */
9786 tree c2
= NULL_TREE
;
9787 if (orig_for_stmt
!= for_stmt
)
9788 /* Do this only on innermost construct for combined ones. */;
9789 else if (ort
== ORT_SIMD
)
9791 splay_tree_node n
= splay_tree_lookup (gimplify_omp_ctxp
->variables
,
9792 (splay_tree_key
) decl
);
9793 omp_is_private (gimplify_omp_ctxp
, decl
,
9794 1 + (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
))
9796 if (n
!= NULL
&& (n
->value
& GOVD_DATA_SHARE_CLASS
) != 0)
9797 omp_notice_variable (gimplify_omp_ctxp
, decl
, true);
9798 else if (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
9800 c
= build_omp_clause (input_location
, OMP_CLAUSE_LINEAR
);
9801 OMP_CLAUSE_LINEAR_NO_COPYIN (c
) = 1;
9802 unsigned int flags
= GOVD_LINEAR
| GOVD_EXPLICIT
| GOVD_SEEN
;
9804 && bitmap_bit_p (has_decl_expr
, DECL_UID (decl
)))
9806 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
9807 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
9809 struct gimplify_omp_ctx
*outer
9810 = gimplify_omp_ctxp
->outer_context
;
9811 if (outer
&& !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
9813 if (outer
->region_type
== ORT_WORKSHARE
9814 && outer
->combined_loop
)
9816 n
= splay_tree_lookup (outer
->variables
,
9817 (splay_tree_key
)decl
);
9818 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
9820 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
9821 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
9825 struct gimplify_omp_ctx
*octx
= outer
->outer_context
;
9827 && octx
->region_type
== ORT_COMBINED_PARALLEL
9828 && octx
->outer_context
9829 && (octx
->outer_context
->region_type
9831 && octx
->outer_context
->combined_loop
)
9833 octx
= octx
->outer_context
;
9834 n
= splay_tree_lookup (octx
->variables
,
9835 (splay_tree_key
)decl
);
9836 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
9838 OMP_CLAUSE_LINEAR_NO_COPYOUT (c
) = 1;
9839 flags
|= GOVD_LINEAR_LASTPRIVATE_NO_OUTER
;
9846 OMP_CLAUSE_DECL (c
) = decl
;
9847 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (for_stmt
);
9848 OMP_FOR_CLAUSES (for_stmt
) = c
;
9849 omp_add_variable (gimplify_omp_ctxp
, decl
, flags
);
9850 if (outer
&& !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
))
9852 if (outer
->region_type
== ORT_WORKSHARE
9853 && outer
->combined_loop
)
9855 if (outer
->outer_context
9856 && (outer
->outer_context
->region_type
9857 == ORT_COMBINED_PARALLEL
))
9858 outer
= outer
->outer_context
;
9859 else if (omp_check_private (outer
, decl
, false))
9862 else if (((outer
->region_type
& ORT_TASK
) != 0)
9863 && outer
->combined_loop
9864 && !omp_check_private (gimplify_omp_ctxp
,
9867 else if (outer
->region_type
!= ORT_COMBINED_PARALLEL
)
9869 omp_notice_variable (outer
, decl
, true);
9874 n
= splay_tree_lookup (outer
->variables
,
9875 (splay_tree_key
)decl
);
9876 if (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
9878 omp_add_variable (outer
, decl
,
9879 GOVD_LASTPRIVATE
| GOVD_SEEN
);
9880 if (outer
->region_type
== ORT_COMBINED_PARALLEL
9881 && outer
->outer_context
9882 && (outer
->outer_context
->region_type
9884 && outer
->outer_context
->combined_loop
)
9886 outer
= outer
->outer_context
;
9887 n
= splay_tree_lookup (outer
->variables
,
9888 (splay_tree_key
)decl
);
9889 if (omp_check_private (outer
, decl
, false))
9892 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
9894 omp_add_variable (outer
, decl
,
9900 if (outer
&& outer
->outer_context
9901 && (outer
->outer_context
->region_type
9902 == ORT_COMBINED_TEAMS
))
9904 outer
= outer
->outer_context
;
9905 n
= splay_tree_lookup (outer
->variables
,
9906 (splay_tree_key
)decl
);
9908 || (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
9909 omp_add_variable (outer
, decl
,
9910 GOVD_SHARED
| GOVD_SEEN
);
9914 if (outer
&& outer
->outer_context
)
9915 omp_notice_variable (outer
->outer_context
, decl
,
9925 || !bitmap_bit_p (has_decl_expr
, DECL_UID (decl
)));
9926 struct gimplify_omp_ctx
*outer
9927 = gimplify_omp_ctxp
->outer_context
;
9928 if (outer
&& lastprivate
)
9930 if (outer
->region_type
== ORT_WORKSHARE
9931 && outer
->combined_loop
)
9933 n
= splay_tree_lookup (outer
->variables
,
9934 (splay_tree_key
)decl
);
9935 if (n
!= NULL
&& (n
->value
& GOVD_LOCAL
) != 0)
9937 lastprivate
= false;
9940 else if (outer
->outer_context
9941 && (outer
->outer_context
->region_type
9942 == ORT_COMBINED_PARALLEL
))
9943 outer
= outer
->outer_context
;
9944 else if (omp_check_private (outer
, decl
, false))
9947 else if (((outer
->region_type
& ORT_TASK
) != 0)
9948 && outer
->combined_loop
9949 && !omp_check_private (gimplify_omp_ctxp
,
9952 else if (outer
->region_type
!= ORT_COMBINED_PARALLEL
)
9954 omp_notice_variable (outer
, decl
, true);
9959 n
= splay_tree_lookup (outer
->variables
,
9960 (splay_tree_key
)decl
);
9961 if (n
== NULL
|| (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
9963 omp_add_variable (outer
, decl
,
9964 GOVD_LASTPRIVATE
| GOVD_SEEN
);
9965 if (outer
->region_type
== ORT_COMBINED_PARALLEL
9966 && outer
->outer_context
9967 && (outer
->outer_context
->region_type
9969 && outer
->outer_context
->combined_loop
)
9971 outer
= outer
->outer_context
;
9972 n
= splay_tree_lookup (outer
->variables
,
9973 (splay_tree_key
)decl
);
9974 if (omp_check_private (outer
, decl
, false))
9977 || ((n
->value
& GOVD_DATA_SHARE_CLASS
)
9979 omp_add_variable (outer
, decl
,
9985 if (outer
&& outer
->outer_context
9986 && (outer
->outer_context
->region_type
9987 == ORT_COMBINED_TEAMS
))
9989 outer
= outer
->outer_context
;
9990 n
= splay_tree_lookup (outer
->variables
,
9991 (splay_tree_key
)decl
);
9993 || (n
->value
& GOVD_DATA_SHARE_CLASS
) == 0)
9994 omp_add_variable (outer
, decl
,
9995 GOVD_SHARED
| GOVD_SEEN
);
9999 if (outer
&& outer
->outer_context
)
10000 omp_notice_variable (outer
->outer_context
, decl
,
10006 c
= build_omp_clause (input_location
,
10007 lastprivate
? OMP_CLAUSE_LASTPRIVATE
10008 : OMP_CLAUSE_PRIVATE
);
10009 OMP_CLAUSE_DECL (c
) = decl
;
10010 OMP_CLAUSE_CHAIN (c
) = OMP_FOR_CLAUSES (for_stmt
);
10011 OMP_FOR_CLAUSES (for_stmt
) = c
;
10012 omp_add_variable (gimplify_omp_ctxp
, decl
,
10013 (lastprivate
? GOVD_LASTPRIVATE
: GOVD_PRIVATE
)
10014 | GOVD_EXPLICIT
| GOVD_SEEN
);
10018 else if (omp_is_private (gimplify_omp_ctxp
, decl
, 0))
10019 omp_notice_variable (gimplify_omp_ctxp
, decl
, true);
10021 omp_add_variable (gimplify_omp_ctxp
, decl
, GOVD_PRIVATE
| GOVD_SEEN
);
10023 /* If DECL is not a gimple register, create a temporary variable to act
10024 as an iteration counter. This is valid, since DECL cannot be
10025 modified in the body of the loop. Similarly for any iteration vars
10026 in simd with collapse > 1 where the iterator vars must be
10028 if (orig_for_stmt
!= for_stmt
)
10030 else if (!is_gimple_reg (decl
)
10031 || (ort
== ORT_SIMD
10032 && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) > 1))
10034 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
10035 /* Make sure omp_add_variable is not called on it prematurely.
10036 We call it ourselves a few lines later. */
10037 gimplify_omp_ctxp
= NULL
;
10038 var
= create_tmp_var (TREE_TYPE (decl
), get_name (decl
));
10039 gimplify_omp_ctxp
= ctx
;
10040 TREE_OPERAND (t
, 0) = var
;
10042 gimplify_seq_add_stmt (&for_body
, gimple_build_assign (decl
, var
));
10044 if (ort
== ORT_SIMD
10045 && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)) == 1)
10047 c2
= build_omp_clause (input_location
, OMP_CLAUSE_LINEAR
);
10048 OMP_CLAUSE_LINEAR_NO_COPYIN (c2
) = 1;
10049 OMP_CLAUSE_LINEAR_NO_COPYOUT (c2
) = 1;
10050 OMP_CLAUSE_DECL (c2
) = var
;
10051 OMP_CLAUSE_CHAIN (c2
) = OMP_FOR_CLAUSES (for_stmt
);
10052 OMP_FOR_CLAUSES (for_stmt
) = c2
;
10053 omp_add_variable (gimplify_omp_ctxp
, var
,
10054 GOVD_LINEAR
| GOVD_EXPLICIT
| GOVD_SEEN
);
10055 if (c
== NULL_TREE
)
10062 omp_add_variable (gimplify_omp_ctxp
, var
,
10063 GOVD_PRIVATE
| GOVD_SEEN
);
10068 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
10069 is_gimple_val
, fb_rvalue
, false);
10070 ret
= MIN (ret
, tret
);
10071 if (ret
== GS_ERROR
)
10074 /* Handle OMP_FOR_COND. */
10075 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
10076 gcc_assert (COMPARISON_CLASS_P (t
));
10077 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
10079 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
10080 is_gimple_val
, fb_rvalue
, false);
10081 ret
= MIN (ret
, tret
);
10083 /* Handle OMP_FOR_INCR. */
10084 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
10085 switch (TREE_CODE (t
))
10087 case PREINCREMENT_EXPR
:
10088 case POSTINCREMENT_EXPR
:
10090 tree decl
= TREE_OPERAND (t
, 0);
10091 /* c_omp_for_incr_canonicalize_ptr() should have been
10092 called to massage things appropriately. */
10093 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
10095 if (orig_for_stmt
!= for_stmt
)
10097 t
= build_int_cst (TREE_TYPE (decl
), 1);
10099 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
10100 t
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), var
, t
);
10101 t
= build2 (MODIFY_EXPR
, TREE_TYPE (var
), var
, t
);
10102 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
) = t
;
10106 case PREDECREMENT_EXPR
:
10107 case POSTDECREMENT_EXPR
:
10108 /* c_omp_for_incr_canonicalize_ptr() should have been
10109 called to massage things appropriately. */
10110 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
10111 if (orig_for_stmt
!= for_stmt
)
10113 t
= build_int_cst (TREE_TYPE (decl
), -1);
10115 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
10116 t
= build2 (PLUS_EXPR
, TREE_TYPE (decl
), var
, t
);
10117 t
= build2 (MODIFY_EXPR
, TREE_TYPE (var
), var
, t
);
10118 TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
) = t
;
10122 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
10123 TREE_OPERAND (t
, 0) = var
;
10125 t
= TREE_OPERAND (t
, 1);
10126 switch (TREE_CODE (t
))
10129 if (TREE_OPERAND (t
, 1) == decl
)
10131 TREE_OPERAND (t
, 1) = TREE_OPERAND (t
, 0);
10132 TREE_OPERAND (t
, 0) = var
;
10138 case POINTER_PLUS_EXPR
:
10139 gcc_assert (TREE_OPERAND (t
, 0) == decl
);
10140 TREE_OPERAND (t
, 0) = var
;
10143 gcc_unreachable ();
10146 tret
= gimplify_expr (&TREE_OPERAND (t
, 1), &for_pre_body
, NULL
,
10147 is_gimple_val
, fb_rvalue
, false);
10148 ret
= MIN (ret
, tret
);
10151 tree step
= TREE_OPERAND (t
, 1);
10152 tree stept
= TREE_TYPE (decl
);
10153 if (POINTER_TYPE_P (stept
))
10155 step
= fold_convert (stept
, step
);
10156 if (TREE_CODE (t
) == MINUS_EXPR
)
10157 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
10158 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10159 if (step
!= TREE_OPERAND (t
, 1))
10161 tret
= gimplify_expr (&OMP_CLAUSE_LINEAR_STEP (c
),
10162 &for_pre_body
, NULL
,
10163 is_gimple_val
, fb_rvalue
, false);
10164 ret
= MIN (ret
, tret
);
10170 gcc_unreachable ();
10176 OMP_CLAUSE_LINEAR_STEP (c2
) = OMP_CLAUSE_LINEAR_STEP (c
);
10179 if ((var
!= decl
|| collapse
> 1 || tile
) && orig_for_stmt
== for_stmt
)
10181 for (c
= OMP_FOR_CLAUSES (for_stmt
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10182 if (((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
10183 && OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
) == NULL
)
10184 || (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
10185 && !OMP_CLAUSE_LINEAR_NO_COPYOUT (c
)
10186 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
) == NULL
))
10187 && OMP_CLAUSE_DECL (c
) == decl
)
10189 if (is_doacross
&& (collapse
== 1 || i
>= collapse
))
10193 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
10194 gcc_assert (TREE_CODE (t
) == MODIFY_EXPR
);
10195 gcc_assert (TREE_OPERAND (t
, 0) == var
);
10196 t
= TREE_OPERAND (t
, 1);
10197 gcc_assert (TREE_CODE (t
) == PLUS_EXPR
10198 || TREE_CODE (t
) == MINUS_EXPR
10199 || TREE_CODE (t
) == POINTER_PLUS_EXPR
);
10200 gcc_assert (TREE_OPERAND (t
, 0) == var
);
10201 t
= build2 (TREE_CODE (t
), TREE_TYPE (decl
),
10202 is_doacross
? var
: decl
,
10203 TREE_OPERAND (t
, 1));
10206 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
10207 seq
= &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c
);
10209 seq
= &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c
);
10210 gimplify_assign (decl
, t
, seq
);
10215 BITMAP_FREE (has_decl_expr
);
10217 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
10219 push_gimplify_context ();
10220 if (TREE_CODE (OMP_FOR_BODY (orig_for_stmt
)) != BIND_EXPR
)
10222 OMP_FOR_BODY (orig_for_stmt
)
10223 = build3 (BIND_EXPR
, void_type_node
, NULL
,
10224 OMP_FOR_BODY (orig_for_stmt
), NULL
);
10225 TREE_SIDE_EFFECTS (OMP_FOR_BODY (orig_for_stmt
)) = 1;
10229 gimple
*g
= gimplify_and_return_first (OMP_FOR_BODY (orig_for_stmt
),
10232 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
10234 if (gimple_code (g
) == GIMPLE_BIND
)
10235 pop_gimplify_context (g
);
10237 pop_gimplify_context (NULL
);
10240 if (orig_for_stmt
!= for_stmt
)
10241 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
10243 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
10244 decl
= TREE_OPERAND (t
, 0);
10245 struct gimplify_omp_ctx
*ctx
= gimplify_omp_ctxp
;
10246 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
10247 gimplify_omp_ctxp
= ctx
->outer_context
;
10248 var
= create_tmp_var (TREE_TYPE (decl
), get_name (decl
));
10249 gimplify_omp_ctxp
= ctx
;
10250 omp_add_variable (gimplify_omp_ctxp
, var
, GOVD_PRIVATE
| GOVD_SEEN
);
10251 TREE_OPERAND (t
, 0) = var
;
10252 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
10253 TREE_OPERAND (t
, 1) = copy_node (TREE_OPERAND (t
, 1));
10254 TREE_OPERAND (TREE_OPERAND (t
, 1), 0) = var
;
10257 gimplify_adjust_omp_clauses (pre_p
, for_body
,
10258 &OMP_FOR_CLAUSES (orig_for_stmt
),
10259 TREE_CODE (orig_for_stmt
));
10262 switch (TREE_CODE (orig_for_stmt
))
10264 case OMP_FOR
: kind
= GF_OMP_FOR_KIND_FOR
; break;
10265 case OMP_SIMD
: kind
= GF_OMP_FOR_KIND_SIMD
; break;
10266 case OMP_DISTRIBUTE
: kind
= GF_OMP_FOR_KIND_DISTRIBUTE
; break;
10267 case OMP_TASKLOOP
: kind
= GF_OMP_FOR_KIND_TASKLOOP
; break;
10268 case OACC_LOOP
: kind
= GF_OMP_FOR_KIND_OACC_LOOP
; break;
10270 gcc_unreachable ();
10272 gfor
= gimple_build_omp_for (for_body
, kind
, OMP_FOR_CLAUSES (orig_for_stmt
),
10273 TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)),
10275 if (orig_for_stmt
!= for_stmt
)
10276 gimple_omp_for_set_combined_p (gfor
, true);
10277 if (gimplify_omp_ctxp
10278 && (gimplify_omp_ctxp
->combined_loop
10279 || (gimplify_omp_ctxp
->region_type
== ORT_COMBINED_PARALLEL
10280 && gimplify_omp_ctxp
->outer_context
10281 && gimplify_omp_ctxp
->outer_context
->combined_loop
)))
10283 gimple_omp_for_set_combined_into_p (gfor
, true);
10284 if (gimplify_omp_ctxp
->combined_loop
)
10285 gcc_assert (TREE_CODE (orig_for_stmt
) == OMP_SIMD
);
10287 gcc_assert (TREE_CODE (orig_for_stmt
) == OMP_FOR
);
10290 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt
)); i
++)
10292 t
= TREE_VEC_ELT (OMP_FOR_INIT (for_stmt
), i
);
10293 gimple_omp_for_set_index (gfor
, i
, TREE_OPERAND (t
, 0));
10294 gimple_omp_for_set_initial (gfor
, i
, TREE_OPERAND (t
, 1));
10295 t
= TREE_VEC_ELT (OMP_FOR_COND (for_stmt
), i
);
10296 gimple_omp_for_set_cond (gfor
, i
, TREE_CODE (t
));
10297 gimple_omp_for_set_final (gfor
, i
, TREE_OPERAND (t
, 1));
10298 t
= TREE_VEC_ELT (OMP_FOR_INCR (for_stmt
), i
);
10299 gimple_omp_for_set_incr (gfor
, i
, TREE_OPERAND (t
, 1));
10302 /* OMP_TASKLOOP is gimplified as two GIMPLE_OMP_FOR taskloop
10303 constructs with GIMPLE_OMP_TASK sandwiched in between them.
10304 The outer taskloop stands for computing the number of iterations,
10305 counts for collapsed loops and holding taskloop specific clauses.
10306 The task construct stands for the effect of data sharing on the
10307 explicit task it creates and the inner taskloop stands for expansion
10308 of the static loop inside of the explicit task construct. */
10309 if (TREE_CODE (orig_for_stmt
) == OMP_TASKLOOP
)
10311 tree
*gfor_clauses_ptr
= gimple_omp_for_clauses_ptr (gfor
);
10312 tree task_clauses
= NULL_TREE
;
10313 tree c
= *gfor_clauses_ptr
;
10314 tree
*gtask_clauses_ptr
= &task_clauses
;
10315 tree outer_for_clauses
= NULL_TREE
;
10316 tree
*gforo_clauses_ptr
= &outer_for_clauses
;
10317 for (; c
; c
= OMP_CLAUSE_CHAIN (c
))
10318 switch (OMP_CLAUSE_CODE (c
))
10320 /* These clauses are allowed on task, move them there. */
10321 case OMP_CLAUSE_SHARED
:
10322 case OMP_CLAUSE_FIRSTPRIVATE
:
10323 case OMP_CLAUSE_DEFAULT
:
10324 case OMP_CLAUSE_IF
:
10325 case OMP_CLAUSE_UNTIED
:
10326 case OMP_CLAUSE_FINAL
:
10327 case OMP_CLAUSE_MERGEABLE
:
10328 case OMP_CLAUSE_PRIORITY
:
10329 *gtask_clauses_ptr
= c
;
10330 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10332 case OMP_CLAUSE_PRIVATE
:
10333 if (OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
))
10335 /* We want private on outer for and firstprivate
10338 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
10339 OMP_CLAUSE_FIRSTPRIVATE
);
10340 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
10341 lang_hooks
.decls
.omp_finish_clause (*gtask_clauses_ptr
, NULL
);
10342 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
10343 *gforo_clauses_ptr
= c
;
10344 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10348 *gtask_clauses_ptr
= c
;
10349 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10352 /* These clauses go into outer taskloop clauses. */
10353 case OMP_CLAUSE_GRAINSIZE
:
10354 case OMP_CLAUSE_NUM_TASKS
:
10355 case OMP_CLAUSE_NOGROUP
:
10356 *gforo_clauses_ptr
= c
;
10357 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10359 /* Taskloop clause we duplicate on both taskloops. */
10360 case OMP_CLAUSE_COLLAPSE
:
10361 *gfor_clauses_ptr
= c
;
10362 gfor_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10363 *gforo_clauses_ptr
= copy_node (c
);
10364 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr
);
10366 /* For lastprivate, keep the clause on inner taskloop, and add
10367 a shared clause on task. If the same decl is also firstprivate,
10368 add also firstprivate clause on the inner taskloop. */
10369 case OMP_CLAUSE_LASTPRIVATE
:
10370 if (OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
))
10372 /* For taskloop C++ lastprivate IVs, we want:
10373 1) private on outer taskloop
10374 2) firstprivate and shared on task
10375 3) lastprivate on inner taskloop */
10377 = build_omp_clause (OMP_CLAUSE_LOCATION (c
),
10378 OMP_CLAUSE_FIRSTPRIVATE
);
10379 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
10380 lang_hooks
.decls
.omp_finish_clause (*gtask_clauses_ptr
, NULL
);
10381 gtask_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
10382 OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
) = 1;
10383 *gforo_clauses_ptr
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
10384 OMP_CLAUSE_PRIVATE
);
10385 OMP_CLAUSE_DECL (*gforo_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
10386 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (*gforo_clauses_ptr
) = 1;
10387 TREE_TYPE (*gforo_clauses_ptr
) = TREE_TYPE (c
);
10388 gforo_clauses_ptr
= &OMP_CLAUSE_CHAIN (*gforo_clauses_ptr
);
10390 *gfor_clauses_ptr
= c
;
10391 gfor_clauses_ptr
= &OMP_CLAUSE_CHAIN (c
);
10393 = build_omp_clause (OMP_CLAUSE_LOCATION (c
), OMP_CLAUSE_SHARED
);
10394 OMP_CLAUSE_DECL (*gtask_clauses_ptr
) = OMP_CLAUSE_DECL (c
);
10395 if (OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE (c
))
10396 OMP_CLAUSE_SHARED_FIRSTPRIVATE (*gtask_clauses_ptr
) = 1;
10398 = &OMP_CLAUSE_CHAIN (*gtask_clauses_ptr
);
10401 gcc_unreachable ();
10403 *gfor_clauses_ptr
= NULL_TREE
;
10404 *gtask_clauses_ptr
= NULL_TREE
;
10405 *gforo_clauses_ptr
= NULL_TREE
;
10406 g
= gimple_build_bind (NULL_TREE
, gfor
, NULL_TREE
);
10407 g
= gimple_build_omp_task (g
, task_clauses
, NULL_TREE
, NULL_TREE
,
10408 NULL_TREE
, NULL_TREE
, NULL_TREE
);
10409 gimple_omp_task_set_taskloop_p (g
, true);
10410 g
= gimple_build_bind (NULL_TREE
, g
, NULL_TREE
);
10412 = gimple_build_omp_for (g
, GF_OMP_FOR_KIND_TASKLOOP
, outer_for_clauses
,
10413 gimple_omp_for_collapse (gfor
),
10414 gimple_omp_for_pre_body (gfor
));
10415 gimple_omp_for_set_pre_body (gfor
, NULL
);
10416 gimple_omp_for_set_combined_p (gforo
, true);
10417 gimple_omp_for_set_combined_into_p (gfor
, true);
10418 for (i
= 0; i
< (int) gimple_omp_for_collapse (gfor
); i
++)
10420 tree type
= TREE_TYPE (gimple_omp_for_index (gfor
, i
));
10421 tree v
= create_tmp_var (type
);
10422 gimple_omp_for_set_index (gforo
, i
, v
);
10423 t
= unshare_expr (gimple_omp_for_initial (gfor
, i
));
10424 gimple_omp_for_set_initial (gforo
, i
, t
);
10425 gimple_omp_for_set_cond (gforo
, i
,
10426 gimple_omp_for_cond (gfor
, i
));
10427 t
= unshare_expr (gimple_omp_for_final (gfor
, i
));
10428 gimple_omp_for_set_final (gforo
, i
, t
);
10429 t
= unshare_expr (gimple_omp_for_incr (gfor
, i
));
10430 gcc_assert (TREE_OPERAND (t
, 0) == gimple_omp_for_index (gfor
, i
));
10431 TREE_OPERAND (t
, 0) = v
;
10432 gimple_omp_for_set_incr (gforo
, i
, t
);
10433 t
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
10434 OMP_CLAUSE_DECL (t
) = v
;
10435 OMP_CLAUSE_CHAIN (t
) = gimple_omp_for_clauses (gforo
);
10436 gimple_omp_for_set_clauses (gforo
, t
);
10438 gimplify_seq_add_stmt (pre_p
, gforo
);
10441 gimplify_seq_add_stmt (pre_p
, gfor
);
10442 if (ret
!= GS_ALL_DONE
)
10444 *expr_p
= NULL_TREE
;
10445 return GS_ALL_DONE
;
10448 /* Helper function of optimize_target_teams, find OMP_TEAMS inside
10449 of OMP_TARGET's body. */
10452 find_omp_teams (tree
*tp
, int *walk_subtrees
, void *)
10454 *walk_subtrees
= 0;
10455 switch (TREE_CODE (*tp
))
10460 case STATEMENT_LIST
:
10461 *walk_subtrees
= 1;
10469 /* Helper function of optimize_target_teams, determine if the expression
10470 can be computed safely before the target construct on the host. */
10473 computable_teams_clause (tree
*tp
, int *walk_subtrees
, void *)
10479 *walk_subtrees
= 0;
10482 switch (TREE_CODE (*tp
))
10487 *walk_subtrees
= 0;
10488 if (error_operand_p (*tp
)
10489 || !INTEGRAL_TYPE_P (TREE_TYPE (*tp
))
10490 || DECL_HAS_VALUE_EXPR_P (*tp
)
10491 || DECL_THREAD_LOCAL_P (*tp
)
10492 || TREE_SIDE_EFFECTS (*tp
)
10493 || TREE_THIS_VOLATILE (*tp
))
10495 if (is_global_var (*tp
)
10496 && (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (*tp
))
10497 || lookup_attribute ("omp declare target link",
10498 DECL_ATTRIBUTES (*tp
))))
10501 && !DECL_SEEN_IN_BIND_EXPR_P (*tp
)
10502 && !is_global_var (*tp
)
10503 && decl_function_context (*tp
) == current_function_decl
)
10505 n
= splay_tree_lookup (gimplify_omp_ctxp
->variables
,
10506 (splay_tree_key
) *tp
);
10509 if (gimplify_omp_ctxp
->target_map_scalars_firstprivate
)
10513 else if (n
->value
& GOVD_LOCAL
)
10515 else if (n
->value
& GOVD_FIRSTPRIVATE
)
10517 else if ((n
->value
& (GOVD_MAP
| GOVD_MAP_ALWAYS_TO
))
10518 == (GOVD_MAP
| GOVD_MAP_ALWAYS_TO
))
10522 if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp
)))
10526 if (TARGET_EXPR_INITIAL (*tp
)
10527 || TREE_CODE (TARGET_EXPR_SLOT (*tp
)) != VAR_DECL
)
10529 return computable_teams_clause (&TARGET_EXPR_SLOT (*tp
),
10530 walk_subtrees
, NULL
);
10531 /* Allow some reasonable subset of integral arithmetics. */
10535 case TRUNC_DIV_EXPR
:
10536 case CEIL_DIV_EXPR
:
10537 case FLOOR_DIV_EXPR
:
10538 case ROUND_DIV_EXPR
:
10539 case TRUNC_MOD_EXPR
:
10540 case CEIL_MOD_EXPR
:
10541 case FLOOR_MOD_EXPR
:
10542 case ROUND_MOD_EXPR
:
10544 case EXACT_DIV_EXPR
:
10555 case NON_LVALUE_EXPR
:
10557 if (!INTEGRAL_TYPE_P (TREE_TYPE (*tp
)))
10560 /* And disallow anything else, except for comparisons. */
10562 if (COMPARISON_CLASS_P (*tp
))
10568 /* Try to determine if the num_teams and/or thread_limit expressions
10569 can have their values determined already before entering the
10571 INTEGER_CSTs trivially are,
10572 integral decls that are firstprivate (explicitly or implicitly)
10573 or explicitly map(always, to:) or map(always, tofrom:) on the target
10574 region too, and expressions involving simple arithmetics on those
10575 too, function calls are not ok, dereferencing something neither etc.
10576 Add NUM_TEAMS and THREAD_LIMIT clauses to the OMP_CLAUSES of
10577 EXPR based on what we find:
10578 0 stands for clause not specified at all, use implementation default
10579 -1 stands for value that can't be determined easily before entering
10580 the target construct.
10581 If teams construct is not present at all, use 1 for num_teams
10582 and 0 for thread_limit (only one team is involved, and the thread
10583 limit is implementation defined. */
10586 optimize_target_teams (tree target
, gimple_seq
*pre_p
)
10588 tree body
= OMP_BODY (target
);
10589 tree teams
= walk_tree (&body
, find_omp_teams
, NULL
, NULL
);
10590 tree num_teams
= integer_zero_node
;
10591 tree thread_limit
= integer_zero_node
;
10592 location_t num_teams_loc
= EXPR_LOCATION (target
);
10593 location_t thread_limit_loc
= EXPR_LOCATION (target
);
10595 struct gimplify_omp_ctx
*target_ctx
= gimplify_omp_ctxp
;
10597 if (teams
== NULL_TREE
)
10598 num_teams
= integer_one_node
;
10600 for (c
= OMP_TEAMS_CLAUSES (teams
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10602 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
)
10605 num_teams_loc
= OMP_CLAUSE_LOCATION (c
);
10607 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
10610 thread_limit_loc
= OMP_CLAUSE_LOCATION (c
);
10614 expr
= OMP_CLAUSE_OPERAND (c
, 0);
10615 if (TREE_CODE (expr
) == INTEGER_CST
)
10620 if (walk_tree (&expr
, computable_teams_clause
, NULL
, NULL
))
10622 *p
= integer_minus_one_node
;
10626 gimplify_omp_ctxp
= gimplify_omp_ctxp
->outer_context
;
10627 if (gimplify_expr (p
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
, false)
10630 gimplify_omp_ctxp
= target_ctx
;
10631 *p
= integer_minus_one_node
;
10634 gimplify_omp_ctxp
= target_ctx
;
10635 if (!DECL_P (expr
) && TREE_CODE (expr
) != TARGET_EXPR
)
10636 OMP_CLAUSE_OPERAND (c
, 0) = *p
;
10638 c
= build_omp_clause (thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
10639 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = thread_limit
;
10640 OMP_CLAUSE_CHAIN (c
) = OMP_TARGET_CLAUSES (target
);
10641 OMP_TARGET_CLAUSES (target
) = c
;
10642 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
10643 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = num_teams
;
10644 OMP_CLAUSE_CHAIN (c
) = OMP_TARGET_CLAUSES (target
);
10645 OMP_TARGET_CLAUSES (target
) = c
;
10648 /* Gimplify the gross structure of several OMP constructs. */
10651 gimplify_omp_workshare (tree
*expr_p
, gimple_seq
*pre_p
)
10653 tree expr
= *expr_p
;
10655 gimple_seq body
= NULL
;
10656 enum omp_region_type ort
;
10658 switch (TREE_CODE (expr
))
10662 ort
= ORT_WORKSHARE
;
10665 ort
= OMP_TARGET_COMBINED (expr
) ? ORT_COMBINED_TARGET
: ORT_TARGET
;
10668 ort
= ORT_ACC_KERNELS
;
10670 case OACC_PARALLEL
:
10671 ort
= ORT_ACC_PARALLEL
;
10674 ort
= ORT_ACC_DATA
;
10676 case OMP_TARGET_DATA
:
10677 ort
= ORT_TARGET_DATA
;
10680 ort
= OMP_TEAMS_COMBINED (expr
) ? ORT_COMBINED_TEAMS
: ORT_TEAMS
;
10682 case OACC_HOST_DATA
:
10683 ort
= ORT_ACC_HOST_DATA
;
10686 gcc_unreachable ();
10688 gimplify_scan_omp_clauses (&OMP_CLAUSES (expr
), pre_p
, ort
,
10690 if (TREE_CODE (expr
) == OMP_TARGET
)
10691 optimize_target_teams (expr
, pre_p
);
10692 if ((ort
& (ORT_TARGET
| ORT_TARGET_DATA
)) != 0)
10694 push_gimplify_context ();
10695 gimple
*g
= gimplify_and_return_first (OMP_BODY (expr
), &body
);
10696 if (gimple_code (g
) == GIMPLE_BIND
)
10697 pop_gimplify_context (g
);
10699 pop_gimplify_context (NULL
);
10700 if ((ort
& ORT_TARGET_DATA
) != 0)
10702 enum built_in_function end_ix
;
10703 switch (TREE_CODE (expr
))
10706 case OACC_HOST_DATA
:
10707 end_ix
= BUILT_IN_GOACC_DATA_END
;
10709 case OMP_TARGET_DATA
:
10710 end_ix
= BUILT_IN_GOMP_TARGET_END_DATA
;
10713 gcc_unreachable ();
10715 tree fn
= builtin_decl_explicit (end_ix
);
10716 g
= gimple_build_call (fn
, 0);
10717 gimple_seq cleanup
= NULL
;
10718 gimple_seq_add_stmt (&cleanup
, g
);
10719 g
= gimple_build_try (body
, cleanup
, GIMPLE_TRY_FINALLY
);
10721 gimple_seq_add_stmt (&body
, g
);
10725 gimplify_and_add (OMP_BODY (expr
), &body
);
10726 gimplify_adjust_omp_clauses (pre_p
, body
, &OMP_CLAUSES (expr
),
10729 switch (TREE_CODE (expr
))
10732 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_DATA
,
10733 OMP_CLAUSES (expr
));
10736 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_KERNELS
,
10737 OMP_CLAUSES (expr
));
10739 case OACC_HOST_DATA
:
10740 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_HOST_DATA
,
10741 OMP_CLAUSES (expr
));
10743 case OACC_PARALLEL
:
10744 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_OACC_PARALLEL
,
10745 OMP_CLAUSES (expr
));
10748 stmt
= gimple_build_omp_sections (body
, OMP_CLAUSES (expr
));
10751 stmt
= gimple_build_omp_single (body
, OMP_CLAUSES (expr
));
10754 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_REGION
,
10755 OMP_CLAUSES (expr
));
10757 case OMP_TARGET_DATA
:
10758 stmt
= gimple_build_omp_target (body
, GF_OMP_TARGET_KIND_DATA
,
10759 OMP_CLAUSES (expr
));
10762 stmt
= gimple_build_omp_teams (body
, OMP_CLAUSES (expr
));
10765 gcc_unreachable ();
10768 gimplify_seq_add_stmt (pre_p
, stmt
);
10769 *expr_p
= NULL_TREE
;
10772 /* Gimplify the gross structure of OpenACC enter/exit data, update, and OpenMP
10773 target update constructs. */
10776 gimplify_omp_target_update (tree
*expr_p
, gimple_seq
*pre_p
)
10778 tree expr
= *expr_p
;
10781 enum omp_region_type ort
= ORT_WORKSHARE
;
10783 switch (TREE_CODE (expr
))
10785 case OACC_ENTER_DATA
:
10786 case OACC_EXIT_DATA
:
10787 kind
= GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA
;
10791 kind
= GF_OMP_TARGET_KIND_OACC_UPDATE
;
10794 case OMP_TARGET_UPDATE
:
10795 kind
= GF_OMP_TARGET_KIND_UPDATE
;
10797 case OMP_TARGET_ENTER_DATA
:
10798 kind
= GF_OMP_TARGET_KIND_ENTER_DATA
;
10800 case OMP_TARGET_EXIT_DATA
:
10801 kind
= GF_OMP_TARGET_KIND_EXIT_DATA
;
10804 gcc_unreachable ();
10806 gimplify_scan_omp_clauses (&OMP_STANDALONE_CLAUSES (expr
), pre_p
,
10807 ort
, TREE_CODE (expr
));
10808 gimplify_adjust_omp_clauses (pre_p
, NULL
, &OMP_STANDALONE_CLAUSES (expr
),
10810 if (TREE_CODE (expr
) == OACC_UPDATE
10811 && omp_find_clause (OMP_STANDALONE_CLAUSES (expr
),
10812 OMP_CLAUSE_IF_PRESENT
))
10814 /* The runtime uses GOMP_MAP_{TO,FROM} to denote the if_present
10816 for (tree c
= OMP_STANDALONE_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10817 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
10818 switch (OMP_CLAUSE_MAP_KIND (c
))
10820 case GOMP_MAP_FORCE_TO
:
10821 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TO
);
10823 case GOMP_MAP_FORCE_FROM
:
10824 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_FROM
);
10830 else if (TREE_CODE (expr
) == OACC_EXIT_DATA
10831 && omp_find_clause (OMP_STANDALONE_CLAUSES (expr
),
10832 OMP_CLAUSE_FINALIZE
))
10834 /* Use GOMP_MAP_DELETE/GOMP_MAP_FORCE_FROM to denote that "finalize"
10835 semantics apply to all mappings of this OpenACC directive. */
10836 bool finalize_marked
= false;
10837 for (tree c
= OMP_STANDALONE_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
10838 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
10839 switch (OMP_CLAUSE_MAP_KIND (c
))
10841 case GOMP_MAP_FROM
:
10842 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_FORCE_FROM
);
10843 finalize_marked
= true;
10845 case GOMP_MAP_RELEASE
:
10846 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_DELETE
);
10847 finalize_marked
= true;
10850 /* Check consistency: libgomp relies on the very first data
10851 mapping clause being marked, so make sure we did that before
10852 any other mapping clauses. */
10853 gcc_assert (finalize_marked
);
10857 stmt
= gimple_build_omp_target (NULL
, kind
, OMP_STANDALONE_CLAUSES (expr
));
10859 gimplify_seq_add_stmt (pre_p
, stmt
);
10860 *expr_p
= NULL_TREE
;
10863 /* A subroutine of gimplify_omp_atomic. The front end is supposed to have
10864 stabilized the lhs of the atomic operation as *ADDR. Return true if
10865 EXPR is this stabilized form. */
10868 goa_lhs_expr_p (tree expr
, tree addr
)
10870 /* Also include casts to other type variants. The C front end is fond
10871 of adding these for e.g. volatile variables. This is like
10872 STRIP_TYPE_NOPS but includes the main variant lookup. */
10873 STRIP_USELESS_TYPE_CONVERSION (expr
);
10875 if (TREE_CODE (expr
) == INDIRECT_REF
)
10877 expr
= TREE_OPERAND (expr
, 0);
10878 while (expr
!= addr
10879 && (CONVERT_EXPR_P (expr
)
10880 || TREE_CODE (expr
) == NON_LVALUE_EXPR
)
10881 && TREE_CODE (expr
) == TREE_CODE (addr
)
10882 && types_compatible_p (TREE_TYPE (expr
), TREE_TYPE (addr
)))
10884 expr
= TREE_OPERAND (expr
, 0);
10885 addr
= TREE_OPERAND (addr
, 0);
10889 return (TREE_CODE (addr
) == ADDR_EXPR
10890 && TREE_CODE (expr
) == ADDR_EXPR
10891 && TREE_OPERAND (addr
, 0) == TREE_OPERAND (expr
, 0));
10893 if (TREE_CODE (addr
) == ADDR_EXPR
&& expr
== TREE_OPERAND (addr
, 0))
10898 /* Walk *EXPR_P and replace appearances of *LHS_ADDR with LHS_VAR. If an
10899 expression does not involve the lhs, evaluate it into a temporary.
10900 Return 1 if the lhs appeared as a subexpression, 0 if it did not,
10901 or -1 if an error was encountered. */
10904 goa_stabilize_expr (tree
*expr_p
, gimple_seq
*pre_p
, tree lhs_addr
,
10907 tree expr
= *expr_p
;
10910 if (goa_lhs_expr_p (expr
, lhs_addr
))
10915 if (is_gimple_val (expr
))
10919 switch (TREE_CODE_CLASS (TREE_CODE (expr
)))
10922 case tcc_comparison
:
10923 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 1), pre_p
, lhs_addr
,
10927 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
, lhs_addr
,
10930 case tcc_expression
:
10931 switch (TREE_CODE (expr
))
10933 case TRUTH_ANDIF_EXPR
:
10934 case TRUTH_ORIF_EXPR
:
10935 case TRUTH_AND_EXPR
:
10936 case TRUTH_OR_EXPR
:
10937 case TRUTH_XOR_EXPR
:
10938 case BIT_INSERT_EXPR
:
10939 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 1), pre_p
,
10940 lhs_addr
, lhs_var
);
10942 case TRUTH_NOT_EXPR
:
10943 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
,
10944 lhs_addr
, lhs_var
);
10946 case COMPOUND_EXPR
:
10947 /* Break out any preevaluations from cp_build_modify_expr. */
10948 for (; TREE_CODE (expr
) == COMPOUND_EXPR
;
10949 expr
= TREE_OPERAND (expr
, 1))
10950 gimplify_stmt (&TREE_OPERAND (expr
, 0), pre_p
);
10952 return goa_stabilize_expr (expr_p
, pre_p
, lhs_addr
, lhs_var
);
10957 case tcc_reference
:
10958 if (TREE_CODE (expr
) == BIT_FIELD_REF
)
10959 saw_lhs
|= goa_stabilize_expr (&TREE_OPERAND (expr
, 0), pre_p
,
10960 lhs_addr
, lhs_var
);
10968 enum gimplify_status gs
;
10969 gs
= gimplify_expr (expr_p
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
);
10970 if (gs
!= GS_ALL_DONE
)
10977 /* Gimplify an OMP_ATOMIC statement. */
10979 static enum gimplify_status
10980 gimplify_omp_atomic (tree
*expr_p
, gimple_seq
*pre_p
)
10982 tree addr
= TREE_OPERAND (*expr_p
, 0);
10983 tree rhs
= TREE_CODE (*expr_p
) == OMP_ATOMIC_READ
10984 ? NULL
: TREE_OPERAND (*expr_p
, 1);
10985 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr
)));
10987 gomp_atomic_load
*loadstmt
;
10988 gomp_atomic_store
*storestmt
;
10990 tmp_load
= create_tmp_reg (type
);
10991 if (rhs
&& goa_stabilize_expr (&rhs
, pre_p
, addr
, tmp_load
) < 0)
10994 if (gimplify_expr (&addr
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
10998 loadstmt
= gimple_build_omp_atomic_load (tmp_load
, addr
);
10999 gimplify_seq_add_stmt (pre_p
, loadstmt
);
11000 if (rhs
&& gimplify_expr (&rhs
, pre_p
, NULL
, is_gimple_val
, fb_rvalue
)
11004 if (TREE_CODE (*expr_p
) == OMP_ATOMIC_READ
)
11006 storestmt
= gimple_build_omp_atomic_store (rhs
);
11007 gimplify_seq_add_stmt (pre_p
, storestmt
);
11008 if (OMP_ATOMIC_SEQ_CST (*expr_p
))
11010 gimple_omp_atomic_set_seq_cst (loadstmt
);
11011 gimple_omp_atomic_set_seq_cst (storestmt
);
11013 switch (TREE_CODE (*expr_p
))
11015 case OMP_ATOMIC_READ
:
11016 case OMP_ATOMIC_CAPTURE_OLD
:
11017 *expr_p
= tmp_load
;
11018 gimple_omp_atomic_set_need_value (loadstmt
);
11020 case OMP_ATOMIC_CAPTURE_NEW
:
11022 gimple_omp_atomic_set_need_value (storestmt
);
11029 return GS_ALL_DONE
;
11032 /* Gimplify a TRANSACTION_EXPR. This involves gimplification of the
11033 body, and adding some EH bits. */
11035 static enum gimplify_status
11036 gimplify_transaction (tree
*expr_p
, gimple_seq
*pre_p
)
11038 tree expr
= *expr_p
, temp
, tbody
= TRANSACTION_EXPR_BODY (expr
);
11040 gtransaction
*trans_stmt
;
11041 gimple_seq body
= NULL
;
11044 /* Wrap the transaction body in a BIND_EXPR so we have a context
11045 where to put decls for OMP. */
11046 if (TREE_CODE (tbody
) != BIND_EXPR
)
11048 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, tbody
, NULL
);
11049 TREE_SIDE_EFFECTS (bind
) = 1;
11050 SET_EXPR_LOCATION (bind
, EXPR_LOCATION (tbody
));
11051 TRANSACTION_EXPR_BODY (expr
) = bind
;
11054 push_gimplify_context ();
11055 temp
= voidify_wrapper_expr (*expr_p
, NULL
);
11057 body_stmt
= gimplify_and_return_first (TRANSACTION_EXPR_BODY (expr
), &body
);
11058 pop_gimplify_context (body_stmt
);
11060 trans_stmt
= gimple_build_transaction (body
);
11061 if (TRANSACTION_EXPR_OUTER (expr
))
11062 subcode
= GTMA_IS_OUTER
;
11063 else if (TRANSACTION_EXPR_RELAXED (expr
))
11064 subcode
= GTMA_IS_RELAXED
;
11065 gimple_transaction_set_subcode (trans_stmt
, subcode
);
11067 gimplify_seq_add_stmt (pre_p
, trans_stmt
);
11075 *expr_p
= NULL_TREE
;
11076 return GS_ALL_DONE
;
11079 /* Gimplify an OMP_ORDERED construct. EXPR is the tree version. BODY
11080 is the OMP_BODY of the original EXPR (which has already been
11081 gimplified so it's not present in the EXPR).
11083 Return the gimplified GIMPLE_OMP_ORDERED tuple. */
11086 gimplify_omp_ordered (tree expr
, gimple_seq body
)
11091 tree source_c
= NULL_TREE
;
11092 tree sink_c
= NULL_TREE
;
11094 if (gimplify_omp_ctxp
)
11096 for (c
= OMP_ORDERED_CLAUSES (expr
); c
; c
= OMP_CLAUSE_CHAIN (c
))
11097 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
11098 && gimplify_omp_ctxp
->loop_iter_var
.is_empty ()
11099 && (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
11100 || OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
))
11102 error_at (OMP_CLAUSE_LOCATION (c
),
11103 "%<ordered%> construct with %<depend%> clause must be "
11104 "closely nested inside a loop with %<ordered%> clause "
11105 "with a parameter");
11108 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
11109 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
11112 for (decls
= OMP_CLAUSE_DECL (c
), i
= 0;
11113 decls
&& TREE_CODE (decls
) == TREE_LIST
;
11114 decls
= TREE_CHAIN (decls
), ++i
)
11115 if (i
>= gimplify_omp_ctxp
->loop_iter_var
.length () / 2)
11117 else if (TREE_VALUE (decls
)
11118 != gimplify_omp_ctxp
->loop_iter_var
[2 * i
])
11120 error_at (OMP_CLAUSE_LOCATION (c
),
11121 "variable %qE is not an iteration "
11122 "of outermost loop %d, expected %qE",
11123 TREE_VALUE (decls
), i
+ 1,
11124 gimplify_omp_ctxp
->loop_iter_var
[2 * i
]);
11130 = gimplify_omp_ctxp
->loop_iter_var
[2 * i
+ 1];
11131 if (!fail
&& i
!= gimplify_omp_ctxp
->loop_iter_var
.length () / 2)
11133 error_at (OMP_CLAUSE_LOCATION (c
),
11134 "number of variables in %<depend(sink)%> "
11135 "clause does not match number of "
11136 "iteration variables");
11141 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
11142 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SOURCE
)
11146 error_at (OMP_CLAUSE_LOCATION (c
),
11147 "more than one %<depend(source)%> clause on an "
11148 "%<ordered%> construct");
11155 if (source_c
&& sink_c
)
11157 error_at (OMP_CLAUSE_LOCATION (source_c
),
11158 "%<depend(source)%> clause specified together with "
11159 "%<depend(sink:)%> clauses on the same construct");
11164 return gimple_build_nop ();
11165 return gimple_build_omp_ordered (body
, OMP_ORDERED_CLAUSES (expr
));
11168 /* Convert the GENERIC expression tree *EXPR_P to GIMPLE. If the
11169 expression produces a value to be used as an operand inside a GIMPLE
11170 statement, the value will be stored back in *EXPR_P. This value will
11171 be a tree of class tcc_declaration, tcc_constant, tcc_reference or
11172 an SSA_NAME. The corresponding sequence of GIMPLE statements is
11173 emitted in PRE_P and POST_P.
11175 Additionally, this process may overwrite parts of the input
11176 expression during gimplification. Ideally, it should be
11177 possible to do non-destructive gimplification.
11179 EXPR_P points to the GENERIC expression to convert to GIMPLE. If
11180 the expression needs to evaluate to a value to be used as
11181 an operand in a GIMPLE statement, this value will be stored in
11182 *EXPR_P on exit. This happens when the caller specifies one
11183 of fb_lvalue or fb_rvalue fallback flags.
11185 PRE_P will contain the sequence of GIMPLE statements corresponding
11186 to the evaluation of EXPR and all the side-effects that must
11187 be executed before the main expression. On exit, the last
11188 statement of PRE_P is the core statement being gimplified. For
11189 instance, when gimplifying 'if (++a)' the last statement in
11190 PRE_P will be 'if (t.1)' where t.1 is the result of
11191 pre-incrementing 'a'.
11193 POST_P will contain the sequence of GIMPLE statements corresponding
11194 to the evaluation of all the side-effects that must be executed
11195 after the main expression. If this is NULL, the post
11196 side-effects are stored at the end of PRE_P.
11198 The reason why the output is split in two is to handle post
11199 side-effects explicitly. In some cases, an expression may have
11200 inner and outer post side-effects which need to be emitted in
11201 an order different from the one given by the recursive
11202 traversal. For instance, for the expression (*p--)++ the post
11203 side-effects of '--' must actually occur *after* the post
11204 side-effects of '++'. However, gimplification will first visit
11205 the inner expression, so if a separate POST sequence was not
11206 used, the resulting sequence would be:
11213 However, the post-decrement operation in line #2 must not be
11214 evaluated until after the store to *p at line #4, so the
11215 correct sequence should be:
11222 So, by specifying a separate post queue, it is possible
11223 to emit the post side-effects in the correct order.
11224 If POST_P is NULL, an internal queue will be used. Before
11225 returning to the caller, the sequence POST_P is appended to
11226 the main output sequence PRE_P.
11228 GIMPLE_TEST_F points to a function that takes a tree T and
11229 returns nonzero if T is in the GIMPLE form requested by the
11230 caller. The GIMPLE predicates are in gimple.c.
11232 FALLBACK tells the function what sort of a temporary we want if
11233 gimplification cannot produce an expression that complies with
11236 fb_none means that no temporary should be generated
11237 fb_rvalue means that an rvalue is OK to generate
11238 fb_lvalue means that an lvalue is OK to generate
11239 fb_either means that either is OK, but an lvalue is preferable.
11240 fb_mayfail means that gimplification may fail (in which case
11241 GS_ERROR will be returned)
11243 The return value is either GS_ERROR or GS_ALL_DONE, since this
11244 function iterates until EXPR is completely gimplified or an error
11247 enum gimplify_status
11248 gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
11249 bool (*gimple_test_f
) (tree
), fallback_t fallback
)
11252 gimple_seq internal_pre
= NULL
;
11253 gimple_seq internal_post
= NULL
;
11256 location_t saved_location
;
11257 enum gimplify_status ret
;
11258 gimple_stmt_iterator pre_last_gsi
, post_last_gsi
;
11261 save_expr
= *expr_p
;
11262 if (save_expr
== NULL_TREE
)
11263 return GS_ALL_DONE
;
11265 /* If we are gimplifying a top-level statement, PRE_P must be valid. */
11266 is_statement
= gimple_test_f
== is_gimple_stmt
;
11268 gcc_assert (pre_p
);
11270 /* Consistency checks. */
11271 if (gimple_test_f
== is_gimple_reg
)
11272 gcc_assert (fallback
& (fb_rvalue
| fb_lvalue
));
11273 else if (gimple_test_f
== is_gimple_val
11274 || gimple_test_f
== is_gimple_call_addr
11275 || gimple_test_f
== is_gimple_condexpr
11276 || gimple_test_f
== is_gimple_mem_rhs
11277 || gimple_test_f
== is_gimple_mem_rhs_or_call
11278 || gimple_test_f
== is_gimple_reg_rhs
11279 || gimple_test_f
== is_gimple_reg_rhs_or_call
11280 || gimple_test_f
== is_gimple_asm_val
11281 || gimple_test_f
== is_gimple_mem_ref_addr
)
11282 gcc_assert (fallback
& fb_rvalue
);
11283 else if (gimple_test_f
== is_gimple_min_lval
11284 || gimple_test_f
== is_gimple_lvalue
)
11285 gcc_assert (fallback
& fb_lvalue
);
11286 else if (gimple_test_f
== is_gimple_addressable
)
11287 gcc_assert (fallback
& fb_either
);
11288 else if (gimple_test_f
== is_gimple_stmt
)
11289 gcc_assert (fallback
== fb_none
);
11292 /* We should have recognized the GIMPLE_TEST_F predicate to
11293 know what kind of fallback to use in case a temporary is
11294 needed to hold the value or address of *EXPR_P. */
11295 gcc_unreachable ();
11298 /* We used to check the predicate here and return immediately if it
11299 succeeds. This is wrong; the design is for gimplification to be
11300 idempotent, and for the predicates to only test for valid forms, not
11301 whether they are fully simplified. */
11303 pre_p
= &internal_pre
;
11305 if (post_p
== NULL
)
11306 post_p
= &internal_post
;
11308 /* Remember the last statements added to PRE_P and POST_P. Every
11309 new statement added by the gimplification helpers needs to be
11310 annotated with location information. To centralize the
11311 responsibility, we remember the last statement that had been
11312 added to both queues before gimplifying *EXPR_P. If
11313 gimplification produces new statements in PRE_P and POST_P, those
11314 statements will be annotated with the same location information
11316 pre_last_gsi
= gsi_last (*pre_p
);
11317 post_last_gsi
= gsi_last (*post_p
);
11319 saved_location
= input_location
;
11320 if (save_expr
!= error_mark_node
11321 && EXPR_HAS_LOCATION (*expr_p
))
11322 input_location
= EXPR_LOCATION (*expr_p
);
11324 /* Loop over the specific gimplifiers until the toplevel node
11325 remains the same. */
11328 /* Strip away as many useless type conversions as possible
11329 at the toplevel. */
11330 STRIP_USELESS_TYPE_CONVERSION (*expr_p
);
11332 /* Remember the expr. */
11333 save_expr
= *expr_p
;
11335 /* Die, die, die, my darling. */
11336 if (error_operand_p (save_expr
))
11342 /* Do any language-specific gimplification. */
11343 ret
= ((enum gimplify_status
)
11344 lang_hooks
.gimplify_expr (expr_p
, pre_p
, post_p
));
11347 if (*expr_p
== NULL_TREE
)
11349 if (*expr_p
!= save_expr
)
11352 else if (ret
!= GS_UNHANDLED
)
11355 /* Make sure that all the cases set 'ret' appropriately. */
11356 ret
= GS_UNHANDLED
;
11357 switch (TREE_CODE (*expr_p
))
11359 /* First deal with the special cases. */
11361 case POSTINCREMENT_EXPR
:
11362 case POSTDECREMENT_EXPR
:
11363 case PREINCREMENT_EXPR
:
11364 case PREDECREMENT_EXPR
:
11365 ret
= gimplify_self_mod_expr (expr_p
, pre_p
, post_p
,
11366 fallback
!= fb_none
,
11367 TREE_TYPE (*expr_p
));
11370 case VIEW_CONVERT_EXPR
:
11371 if (is_gimple_reg_type (TREE_TYPE (*expr_p
))
11372 && is_gimple_reg_type (TREE_TYPE (TREE_OPERAND (*expr_p
, 0))))
11374 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
11375 post_p
, is_gimple_val
, fb_rvalue
);
11376 recalculate_side_effects (*expr_p
);
11382 case ARRAY_RANGE_REF
:
11383 case REALPART_EXPR
:
11384 case IMAGPART_EXPR
:
11385 case COMPONENT_REF
:
11386 ret
= gimplify_compound_lval (expr_p
, pre_p
, post_p
,
11387 fallback
? fallback
: fb_rvalue
);
11391 ret
= gimplify_cond_expr (expr_p
, pre_p
, fallback
);
11393 /* C99 code may assign to an array in a structure value of a
11394 conditional expression, and this has undefined behavior
11395 only on execution, so create a temporary if an lvalue is
11397 if (fallback
== fb_lvalue
)
11399 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
11400 mark_addressable (*expr_p
);
11406 ret
= gimplify_call_expr (expr_p
, pre_p
, fallback
!= fb_none
);
11408 /* C99 code may assign to an array in a structure returned
11409 from a function, and this has undefined behavior only on
11410 execution, so create a temporary if an lvalue is
11412 if (fallback
== fb_lvalue
)
11414 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
11415 mark_addressable (*expr_p
);
11421 gcc_unreachable ();
11423 case COMPOUND_EXPR
:
11424 ret
= gimplify_compound_expr (expr_p
, pre_p
, fallback
!= fb_none
);
11427 case COMPOUND_LITERAL_EXPR
:
11428 ret
= gimplify_compound_literal_expr (expr_p
, pre_p
,
11429 gimple_test_f
, fallback
);
11434 ret
= gimplify_modify_expr (expr_p
, pre_p
, post_p
,
11435 fallback
!= fb_none
);
11438 case TRUTH_ANDIF_EXPR
:
11439 case TRUTH_ORIF_EXPR
:
11441 /* Preserve the original type of the expression and the
11442 source location of the outer expression. */
11443 tree org_type
= TREE_TYPE (*expr_p
);
11444 *expr_p
= gimple_boolify (*expr_p
);
11445 *expr_p
= build3_loc (input_location
, COND_EXPR
,
11449 org_type
, boolean_true_node
),
11452 org_type
, boolean_false_node
));
11457 case TRUTH_NOT_EXPR
:
11459 tree type
= TREE_TYPE (*expr_p
);
11460 /* The parsers are careful to generate TRUTH_NOT_EXPR
11461 only with operands that are always zero or one.
11462 We do not fold here but handle the only interesting case
11463 manually, as fold may re-introduce the TRUTH_NOT_EXPR. */
11464 *expr_p
= gimple_boolify (*expr_p
);
11465 if (TYPE_PRECISION (TREE_TYPE (*expr_p
)) == 1)
11466 *expr_p
= build1_loc (input_location
, BIT_NOT_EXPR
,
11467 TREE_TYPE (*expr_p
),
11468 TREE_OPERAND (*expr_p
, 0));
11470 *expr_p
= build2_loc (input_location
, BIT_XOR_EXPR
,
11471 TREE_TYPE (*expr_p
),
11472 TREE_OPERAND (*expr_p
, 0),
11473 build_int_cst (TREE_TYPE (*expr_p
), 1));
11474 if (!useless_type_conversion_p (type
, TREE_TYPE (*expr_p
)))
11475 *expr_p
= fold_convert_loc (input_location
, type
, *expr_p
);
11481 ret
= gimplify_addr_expr (expr_p
, pre_p
, post_p
);
11484 case ANNOTATE_EXPR
:
11486 tree cond
= TREE_OPERAND (*expr_p
, 0);
11487 tree kind
= TREE_OPERAND (*expr_p
, 1);
11488 tree data
= TREE_OPERAND (*expr_p
, 2);
11489 tree type
= TREE_TYPE (cond
);
11490 if (!INTEGRAL_TYPE_P (type
))
11496 tree tmp
= create_tmp_var (type
);
11497 gimplify_arg (&cond
, pre_p
, EXPR_LOCATION (*expr_p
));
11499 = gimple_build_call_internal (IFN_ANNOTATE
, 3, cond
, kind
, data
);
11500 gimple_call_set_lhs (call
, tmp
);
11501 gimplify_seq_add_stmt (pre_p
, call
);
11508 ret
= gimplify_va_arg_expr (expr_p
, pre_p
, post_p
);
11512 if (IS_EMPTY_STMT (*expr_p
))
11518 if (VOID_TYPE_P (TREE_TYPE (*expr_p
))
11519 || fallback
== fb_none
)
11521 /* Just strip a conversion to void (or in void context) and
11523 *expr_p
= TREE_OPERAND (*expr_p
, 0);
11528 ret
= gimplify_conversion (expr_p
);
11529 if (ret
== GS_ERROR
)
11531 if (*expr_p
!= save_expr
)
11535 case FIX_TRUNC_EXPR
:
11536 /* unary_expr: ... | '(' cast ')' val | ... */
11537 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
11538 is_gimple_val
, fb_rvalue
);
11539 recalculate_side_effects (*expr_p
);
11544 bool volatilep
= TREE_THIS_VOLATILE (*expr_p
);
11545 bool notrap
= TREE_THIS_NOTRAP (*expr_p
);
11546 tree saved_ptr_type
= TREE_TYPE (TREE_OPERAND (*expr_p
, 0));
11548 *expr_p
= fold_indirect_ref_loc (input_location
, *expr_p
);
11549 if (*expr_p
!= save_expr
)
11555 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
11556 is_gimple_reg
, fb_rvalue
);
11557 if (ret
== GS_ERROR
)
11560 recalculate_side_effects (*expr_p
);
11561 *expr_p
= fold_build2_loc (input_location
, MEM_REF
,
11562 TREE_TYPE (*expr_p
),
11563 TREE_OPERAND (*expr_p
, 0),
11564 build_int_cst (saved_ptr_type
, 0));
11565 TREE_THIS_VOLATILE (*expr_p
) = volatilep
;
11566 TREE_THIS_NOTRAP (*expr_p
) = notrap
;
11571 /* We arrive here through the various re-gimplifcation paths. */
11573 /* First try re-folding the whole thing. */
11574 tmp
= fold_binary (MEM_REF
, TREE_TYPE (*expr_p
),
11575 TREE_OPERAND (*expr_p
, 0),
11576 TREE_OPERAND (*expr_p
, 1));
11579 REF_REVERSE_STORAGE_ORDER (tmp
)
11580 = REF_REVERSE_STORAGE_ORDER (*expr_p
);
11582 recalculate_side_effects (*expr_p
);
11586 /* Avoid re-gimplifying the address operand if it is already
11587 in suitable form. Re-gimplifying would mark the address
11588 operand addressable. Always gimplify when not in SSA form
11589 as we still may have to gimplify decls with value-exprs. */
11590 if (!gimplify_ctxp
|| !gimple_in_ssa_p (cfun
)
11591 || !is_gimple_mem_ref_addr (TREE_OPERAND (*expr_p
, 0)))
11593 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
11594 is_gimple_mem_ref_addr
, fb_rvalue
);
11595 if (ret
== GS_ERROR
)
11598 recalculate_side_effects (*expr_p
);
11602 /* Constants need not be gimplified. */
11609 /* Drop the overflow flag on constants, we do not want
11610 that in the GIMPLE IL. */
11611 if (TREE_OVERFLOW_P (*expr_p
))
11612 *expr_p
= drop_tree_overflow (*expr_p
);
11617 /* If we require an lvalue, such as for ADDR_EXPR, retain the
11618 CONST_DECL node. Otherwise the decl is replaceable by its
11620 /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either. */
11621 if (fallback
& fb_lvalue
)
11625 *expr_p
= DECL_INITIAL (*expr_p
);
11631 ret
= gimplify_decl_expr (expr_p
, pre_p
);
11635 ret
= gimplify_bind_expr (expr_p
, pre_p
);
11639 ret
= gimplify_loop_expr (expr_p
, pre_p
);
11643 ret
= gimplify_switch_expr (expr_p
, pre_p
);
11647 ret
= gimplify_exit_expr (expr_p
);
11651 /* If the target is not LABEL, then it is a computed jump
11652 and the target needs to be gimplified. */
11653 if (TREE_CODE (GOTO_DESTINATION (*expr_p
)) != LABEL_DECL
)
11655 ret
= gimplify_expr (&GOTO_DESTINATION (*expr_p
), pre_p
,
11656 NULL
, is_gimple_val
, fb_rvalue
);
11657 if (ret
== GS_ERROR
)
11660 gimplify_seq_add_stmt (pre_p
,
11661 gimple_build_goto (GOTO_DESTINATION (*expr_p
)));
11666 gimplify_seq_add_stmt (pre_p
,
11667 gimple_build_predict (PREDICT_EXPR_PREDICTOR (*expr_p
),
11668 PREDICT_EXPR_OUTCOME (*expr_p
)));
11673 ret
= gimplify_label_expr (expr_p
, pre_p
);
11674 label
= LABEL_EXPR_LABEL (*expr_p
);
11675 gcc_assert (decl_function_context (label
) == current_function_decl
);
11677 /* If the label is used in a goto statement, or address of the label
11678 is taken, we need to unpoison all variables that were seen so far.
11679 Doing so would prevent us from reporting a false positives. */
11680 if (asan_poisoned_variables
11681 && asan_used_labels
!= NULL
11682 && asan_used_labels
->contains (label
))
11683 asan_poison_variables (asan_poisoned_variables
, false, pre_p
);
11686 case CASE_LABEL_EXPR
:
11687 ret
= gimplify_case_label_expr (expr_p
, pre_p
);
11689 if (gimplify_ctxp
->live_switch_vars
)
11690 asan_poison_variables (gimplify_ctxp
->live_switch_vars
, false,
11695 ret
= gimplify_return_expr (*expr_p
, pre_p
);
11699 /* Don't reduce this in place; let gimplify_init_constructor work its
11700 magic. Buf if we're just elaborating this for side effects, just
11701 gimplify any element that has side-effects. */
11702 if (fallback
== fb_none
)
11704 unsigned HOST_WIDE_INT ix
;
11706 tree temp
= NULL_TREE
;
11707 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (*expr_p
), ix
, val
)
11708 if (TREE_SIDE_EFFECTS (val
))
11709 append_to_statement_list (val
, &temp
);
11712 ret
= temp
? GS_OK
: GS_ALL_DONE
;
11714 /* C99 code may assign to an array in a constructed
11715 structure or union, and this has undefined behavior only
11716 on execution, so create a temporary if an lvalue is
11718 else if (fallback
== fb_lvalue
)
11720 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, post_p
, false);
11721 mark_addressable (*expr_p
);
11728 /* The following are special cases that are not handled by the
11729 original GIMPLE grammar. */
11731 /* SAVE_EXPR nodes are converted into a GIMPLE identifier and
11734 ret
= gimplify_save_expr (expr_p
, pre_p
, post_p
);
11737 case BIT_FIELD_REF
:
11738 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
11739 post_p
, is_gimple_lvalue
, fb_either
);
11740 recalculate_side_effects (*expr_p
);
11743 case TARGET_MEM_REF
:
11745 enum gimplify_status r0
= GS_ALL_DONE
, r1
= GS_ALL_DONE
;
11747 if (TMR_BASE (*expr_p
))
11748 r0
= gimplify_expr (&TMR_BASE (*expr_p
), pre_p
,
11749 post_p
, is_gimple_mem_ref_addr
, fb_either
);
11750 if (TMR_INDEX (*expr_p
))
11751 r1
= gimplify_expr (&TMR_INDEX (*expr_p
), pre_p
,
11752 post_p
, is_gimple_val
, fb_rvalue
);
11753 if (TMR_INDEX2 (*expr_p
))
11754 r1
= gimplify_expr (&TMR_INDEX2 (*expr_p
), pre_p
,
11755 post_p
, is_gimple_val
, fb_rvalue
);
11756 /* TMR_STEP and TMR_OFFSET are always integer constants. */
11757 ret
= MIN (r0
, r1
);
11761 case NON_LVALUE_EXPR
:
11762 /* This should have been stripped above. */
11763 gcc_unreachable ();
11766 ret
= gimplify_asm_expr (expr_p
, pre_p
, post_p
);
11769 case TRY_FINALLY_EXPR
:
11770 case TRY_CATCH_EXPR
:
11772 gimple_seq eval
, cleanup
;
11775 /* Calls to destructors are generated automatically in FINALLY/CATCH
11776 block. They should have location as UNKNOWN_LOCATION. However,
11777 gimplify_call_expr will reset these call stmts to input_location
11778 if it finds stmt's location is unknown. To prevent resetting for
11779 destructors, we set the input_location to unknown.
11780 Note that this only affects the destructor calls in FINALLY/CATCH
11781 block, and will automatically reset to its original value by the
11782 end of gimplify_expr. */
11783 input_location
= UNKNOWN_LOCATION
;
11784 eval
= cleanup
= NULL
;
11785 gimplify_and_add (TREE_OPERAND (*expr_p
, 0), &eval
);
11786 gimplify_and_add (TREE_OPERAND (*expr_p
, 1), &cleanup
);
11787 /* Don't create bogus GIMPLE_TRY with empty cleanup. */
11788 if (gimple_seq_empty_p (cleanup
))
11790 gimple_seq_add_seq (pre_p
, eval
);
11794 try_
= gimple_build_try (eval
, cleanup
,
11795 TREE_CODE (*expr_p
) == TRY_FINALLY_EXPR
11796 ? GIMPLE_TRY_FINALLY
11797 : GIMPLE_TRY_CATCH
);
11798 if (EXPR_HAS_LOCATION (save_expr
))
11799 gimple_set_location (try_
, EXPR_LOCATION (save_expr
));
11800 else if (LOCATION_LOCUS (saved_location
) != UNKNOWN_LOCATION
)
11801 gimple_set_location (try_
, saved_location
);
11802 if (TREE_CODE (*expr_p
) == TRY_CATCH_EXPR
)
11803 gimple_try_set_catch_is_cleanup (try_
,
11804 TRY_CATCH_IS_CLEANUP (*expr_p
));
11805 gimplify_seq_add_stmt (pre_p
, try_
);
11810 case CLEANUP_POINT_EXPR
:
11811 ret
= gimplify_cleanup_point_expr (expr_p
, pre_p
);
11815 ret
= gimplify_target_expr (expr_p
, pre_p
, post_p
);
11821 gimple_seq handler
= NULL
;
11822 gimplify_and_add (CATCH_BODY (*expr_p
), &handler
);
11823 c
= gimple_build_catch (CATCH_TYPES (*expr_p
), handler
);
11824 gimplify_seq_add_stmt (pre_p
, c
);
11829 case EH_FILTER_EXPR
:
11832 gimple_seq failure
= NULL
;
11834 gimplify_and_add (EH_FILTER_FAILURE (*expr_p
), &failure
);
11835 ehf
= gimple_build_eh_filter (EH_FILTER_TYPES (*expr_p
), failure
);
11836 gimple_set_no_warning (ehf
, TREE_NO_WARNING (*expr_p
));
11837 gimplify_seq_add_stmt (pre_p
, ehf
);
11844 enum gimplify_status r0
, r1
;
11845 r0
= gimplify_expr (&OBJ_TYPE_REF_OBJECT (*expr_p
), pre_p
,
11846 post_p
, is_gimple_val
, fb_rvalue
);
11847 r1
= gimplify_expr (&OBJ_TYPE_REF_EXPR (*expr_p
), pre_p
,
11848 post_p
, is_gimple_val
, fb_rvalue
);
11849 TREE_SIDE_EFFECTS (*expr_p
) = 0;
11850 ret
= MIN (r0
, r1
);
11855 /* We get here when taking the address of a label. We mark
11856 the label as "forced"; meaning it can never be removed and
11857 it is a potential target for any computed goto. */
11858 FORCED_LABEL (*expr_p
) = 1;
11862 case STATEMENT_LIST
:
11863 ret
= gimplify_statement_list (expr_p
, pre_p
);
11866 case WITH_SIZE_EXPR
:
11868 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
11869 post_p
== &internal_post
? NULL
: post_p
,
11870 gimple_test_f
, fallback
);
11871 gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
11872 is_gimple_val
, fb_rvalue
);
11879 ret
= gimplify_var_or_parm_decl (expr_p
);
11883 /* When within an OMP context, notice uses of variables. */
11884 if (gimplify_omp_ctxp
)
11885 omp_notice_variable (gimplify_omp_ctxp
, *expr_p
, true);
11889 case DEBUG_EXPR_DECL
:
11890 gcc_unreachable ();
11892 case DEBUG_BEGIN_STMT
:
11893 gimplify_seq_add_stmt (pre_p
,
11894 gimple_build_debug_begin_stmt
11895 (TREE_BLOCK (*expr_p
),
11896 EXPR_LOCATION (*expr_p
)));
11902 /* Allow callbacks into the gimplifier during optimization. */
11907 gimplify_omp_parallel (expr_p
, pre_p
);
11912 gimplify_omp_task (expr_p
, pre_p
);
11918 case OMP_DISTRIBUTE
:
11921 ret
= gimplify_omp_for (expr_p
, pre_p
);
11925 gimplify_oacc_cache (expr_p
, pre_p
);
11930 gimplify_oacc_declare (expr_p
, pre_p
);
11934 case OACC_HOST_DATA
:
11937 case OACC_PARALLEL
:
11941 case OMP_TARGET_DATA
:
11943 gimplify_omp_workshare (expr_p
, pre_p
);
11947 case OACC_ENTER_DATA
:
11948 case OACC_EXIT_DATA
:
11950 case OMP_TARGET_UPDATE
:
11951 case OMP_TARGET_ENTER_DATA
:
11952 case OMP_TARGET_EXIT_DATA
:
11953 gimplify_omp_target_update (expr_p
, pre_p
);
11959 case OMP_TASKGROUP
:
11963 gimple_seq body
= NULL
;
11966 gimplify_and_add (OMP_BODY (*expr_p
), &body
);
11967 switch (TREE_CODE (*expr_p
))
11970 g
= gimple_build_omp_section (body
);
11973 g
= gimple_build_omp_master (body
);
11975 case OMP_TASKGROUP
:
11977 gimple_seq cleanup
= NULL
;
11979 = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END
);
11980 g
= gimple_build_call (fn
, 0);
11981 gimple_seq_add_stmt (&cleanup
, g
);
11982 g
= gimple_build_try (body
, cleanup
, GIMPLE_TRY_FINALLY
);
11984 gimple_seq_add_stmt (&body
, g
);
11985 g
= gimple_build_omp_taskgroup (body
);
11989 g
= gimplify_omp_ordered (*expr_p
, body
);
11992 gimplify_scan_omp_clauses (&OMP_CRITICAL_CLAUSES (*expr_p
),
11993 pre_p
, ORT_WORKSHARE
, OMP_CRITICAL
);
11994 gimplify_adjust_omp_clauses (pre_p
, body
,
11995 &OMP_CRITICAL_CLAUSES (*expr_p
),
11997 g
= gimple_build_omp_critical (body
,
11998 OMP_CRITICAL_NAME (*expr_p
),
11999 OMP_CRITICAL_CLAUSES (*expr_p
));
12002 gcc_unreachable ();
12004 gimplify_seq_add_stmt (pre_p
, g
);
12010 case OMP_ATOMIC_READ
:
12011 case OMP_ATOMIC_CAPTURE_OLD
:
12012 case OMP_ATOMIC_CAPTURE_NEW
:
12013 ret
= gimplify_omp_atomic (expr_p
, pre_p
);
12016 case TRANSACTION_EXPR
:
12017 ret
= gimplify_transaction (expr_p
, pre_p
);
12020 case TRUTH_AND_EXPR
:
12021 case TRUTH_OR_EXPR
:
12022 case TRUTH_XOR_EXPR
:
12024 tree orig_type
= TREE_TYPE (*expr_p
);
12025 tree new_type
, xop0
, xop1
;
12026 *expr_p
= gimple_boolify (*expr_p
);
12027 new_type
= TREE_TYPE (*expr_p
);
12028 if (!useless_type_conversion_p (orig_type
, new_type
))
12030 *expr_p
= fold_convert_loc (input_location
, orig_type
, *expr_p
);
12035 /* Boolified binary truth expressions are semantically equivalent
12036 to bitwise binary expressions. Canonicalize them to the
12037 bitwise variant. */
12038 switch (TREE_CODE (*expr_p
))
12040 case TRUTH_AND_EXPR
:
12041 TREE_SET_CODE (*expr_p
, BIT_AND_EXPR
);
12043 case TRUTH_OR_EXPR
:
12044 TREE_SET_CODE (*expr_p
, BIT_IOR_EXPR
);
12046 case TRUTH_XOR_EXPR
:
12047 TREE_SET_CODE (*expr_p
, BIT_XOR_EXPR
);
12052 /* Now make sure that operands have compatible type to
12053 expression's new_type. */
12054 xop0
= TREE_OPERAND (*expr_p
, 0);
12055 xop1
= TREE_OPERAND (*expr_p
, 1);
12056 if (!useless_type_conversion_p (new_type
, TREE_TYPE (xop0
)))
12057 TREE_OPERAND (*expr_p
, 0) = fold_convert_loc (input_location
,
12060 if (!useless_type_conversion_p (new_type
, TREE_TYPE (xop1
)))
12061 TREE_OPERAND (*expr_p
, 1) = fold_convert_loc (input_location
,
12064 /* Continue classified as tcc_binary. */
12068 case VEC_COND_EXPR
:
12070 enum gimplify_status r0
, r1
, r2
;
12072 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12073 post_p
, is_gimple_condexpr
, fb_rvalue
);
12074 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
12075 post_p
, is_gimple_val
, fb_rvalue
);
12076 r2
= gimplify_expr (&TREE_OPERAND (*expr_p
, 2), pre_p
,
12077 post_p
, is_gimple_val
, fb_rvalue
);
12079 ret
= MIN (MIN (r0
, r1
), r2
);
12080 recalculate_side_effects (*expr_p
);
12084 case VEC_PERM_EXPR
:
12085 /* Classified as tcc_expression. */
12088 case BIT_INSERT_EXPR
:
12089 /* Argument 3 is a constant. */
12092 case POINTER_PLUS_EXPR
:
12094 enum gimplify_status r0
, r1
;
12095 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12096 post_p
, is_gimple_val
, fb_rvalue
);
12097 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
12098 post_p
, is_gimple_val
, fb_rvalue
);
12099 recalculate_side_effects (*expr_p
);
12100 ret
= MIN (r0
, r1
);
12105 switch (TREE_CODE_CLASS (TREE_CODE (*expr_p
)))
12107 case tcc_comparison
:
12108 /* Handle comparison of objects of non scalar mode aggregates
12109 with a call to memcmp. It would be nice to only have to do
12110 this for variable-sized objects, but then we'd have to allow
12111 the same nest of reference nodes we allow for MODIFY_EXPR and
12112 that's too complex.
12114 Compare scalar mode aggregates as scalar mode values. Using
12115 memcmp for them would be very inefficient at best, and is
12116 plain wrong if bitfields are involved. */
12118 tree type
= TREE_TYPE (TREE_OPERAND (*expr_p
, 1));
12120 /* Vector comparisons need no boolification. */
12121 if (TREE_CODE (type
) == VECTOR_TYPE
)
12123 else if (!AGGREGATE_TYPE_P (type
))
12125 tree org_type
= TREE_TYPE (*expr_p
);
12126 *expr_p
= gimple_boolify (*expr_p
);
12127 if (!useless_type_conversion_p (org_type
,
12128 TREE_TYPE (*expr_p
)))
12130 *expr_p
= fold_convert_loc (input_location
,
12131 org_type
, *expr_p
);
12137 else if (TYPE_MODE (type
) != BLKmode
)
12138 ret
= gimplify_scalar_mode_aggregate_compare (expr_p
);
12140 ret
= gimplify_variable_sized_compare (expr_p
);
12145 /* If *EXPR_P does not need to be special-cased, handle it
12146 according to its class. */
12148 ret
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12149 post_p
, is_gimple_val
, fb_rvalue
);
12155 enum gimplify_status r0
, r1
;
12157 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12158 post_p
, is_gimple_val
, fb_rvalue
);
12159 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
12160 post_p
, is_gimple_val
, fb_rvalue
);
12162 ret
= MIN (r0
, r1
);
12168 enum gimplify_status r0
, r1
, r2
;
12170 r0
= gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
,
12171 post_p
, is_gimple_val
, fb_rvalue
);
12172 r1
= gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
,
12173 post_p
, is_gimple_val
, fb_rvalue
);
12174 r2
= gimplify_expr (&TREE_OPERAND (*expr_p
, 2), pre_p
,
12175 post_p
, is_gimple_val
, fb_rvalue
);
12177 ret
= MIN (MIN (r0
, r1
), r2
);
12181 case tcc_declaration
:
12184 goto dont_recalculate
;
12187 gcc_unreachable ();
12190 recalculate_side_effects (*expr_p
);
12196 gcc_assert (*expr_p
|| ret
!= GS_OK
);
12198 while (ret
== GS_OK
);
12200 /* If we encountered an error_mark somewhere nested inside, either
12201 stub out the statement or propagate the error back out. */
12202 if (ret
== GS_ERROR
)
12209 /* This was only valid as a return value from the langhook, which
12210 we handled. Make sure it doesn't escape from any other context. */
12211 gcc_assert (ret
!= GS_UNHANDLED
);
12213 if (fallback
== fb_none
&& *expr_p
&& !is_gimple_stmt (*expr_p
))
12215 /* We aren't looking for a value, and we don't have a valid
12216 statement. If it doesn't have side-effects, throw it away.
12217 We can also get here with code such as "*&&L;", where L is
12218 a LABEL_DECL that is marked as FORCED_LABEL. */
12219 if (TREE_CODE (*expr_p
) == LABEL_DECL
12220 || !TREE_SIDE_EFFECTS (*expr_p
))
12222 else if (!TREE_THIS_VOLATILE (*expr_p
))
12224 /* This is probably a _REF that contains something nested that
12225 has side effects. Recurse through the operands to find it. */
12226 enum tree_code code
= TREE_CODE (*expr_p
);
12230 case COMPONENT_REF
:
12231 case REALPART_EXPR
:
12232 case IMAGPART_EXPR
:
12233 case VIEW_CONVERT_EXPR
:
12234 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
12235 gimple_test_f
, fallback
);
12239 case ARRAY_RANGE_REF
:
12240 gimplify_expr (&TREE_OPERAND (*expr_p
, 0), pre_p
, post_p
,
12241 gimple_test_f
, fallback
);
12242 gimplify_expr (&TREE_OPERAND (*expr_p
, 1), pre_p
, post_p
,
12243 gimple_test_f
, fallback
);
12247 /* Anything else with side-effects must be converted to
12248 a valid statement before we get here. */
12249 gcc_unreachable ();
12254 else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p
))
12255 && TYPE_MODE (TREE_TYPE (*expr_p
)) != BLKmode
)
12257 /* Historically, the compiler has treated a bare reference
12258 to a non-BLKmode volatile lvalue as forcing a load. */
12259 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p
));
12261 /* Normally, we do not want to create a temporary for a
12262 TREE_ADDRESSABLE type because such a type should not be
12263 copied by bitwise-assignment. However, we make an
12264 exception here, as all we are doing here is ensuring that
12265 we read the bytes that make up the type. We use
12266 create_tmp_var_raw because create_tmp_var will abort when
12267 given a TREE_ADDRESSABLE type. */
12268 tree tmp
= create_tmp_var_raw (type
, "vol");
12269 gimple_add_tmp_var (tmp
);
12270 gimplify_assign (tmp
, *expr_p
, pre_p
);
12274 /* We can't do anything useful with a volatile reference to
12275 an incomplete type, so just throw it away. Likewise for
12276 a BLKmode type, since any implicit inner load should
12277 already have been turned into an explicit one by the
12278 gimplification process. */
12282 /* If we are gimplifying at the statement level, we're done. Tack
12283 everything together and return. */
12284 if (fallback
== fb_none
|| is_statement
)
12286 /* Since *EXPR_P has been converted into a GIMPLE tuple, clear
12287 it out for GC to reclaim it. */
12288 *expr_p
= NULL_TREE
;
12290 if (!gimple_seq_empty_p (internal_pre
)
12291 || !gimple_seq_empty_p (internal_post
))
12293 gimplify_seq_add_seq (&internal_pre
, internal_post
);
12294 gimplify_seq_add_seq (pre_p
, internal_pre
);
12297 /* The result of gimplifying *EXPR_P is going to be the last few
12298 statements in *PRE_P and *POST_P. Add location information
12299 to all the statements that were added by the gimplification
12301 if (!gimple_seq_empty_p (*pre_p
))
12302 annotate_all_with_location_after (*pre_p
, pre_last_gsi
, input_location
);
12304 if (!gimple_seq_empty_p (*post_p
))
12305 annotate_all_with_location_after (*post_p
, post_last_gsi
,
12311 #ifdef ENABLE_GIMPLE_CHECKING
12314 enum tree_code code
= TREE_CODE (*expr_p
);
12315 /* These expressions should already be in gimple IR form. */
12316 gcc_assert (code
!= MODIFY_EXPR
12317 && code
!= ASM_EXPR
12318 && code
!= BIND_EXPR
12319 && code
!= CATCH_EXPR
12320 && (code
!= COND_EXPR
|| gimplify_ctxp
->allow_rhs_cond_expr
)
12321 && code
!= EH_FILTER_EXPR
12322 && code
!= GOTO_EXPR
12323 && code
!= LABEL_EXPR
12324 && code
!= LOOP_EXPR
12325 && code
!= SWITCH_EXPR
12326 && code
!= TRY_FINALLY_EXPR
12327 && code
!= OACC_PARALLEL
12328 && code
!= OACC_KERNELS
12329 && code
!= OACC_DATA
12330 && code
!= OACC_HOST_DATA
12331 && code
!= OACC_DECLARE
12332 && code
!= OACC_UPDATE
12333 && code
!= OACC_ENTER_DATA
12334 && code
!= OACC_EXIT_DATA
12335 && code
!= OACC_CACHE
12336 && code
!= OMP_CRITICAL
12338 && code
!= OACC_LOOP
12339 && code
!= OMP_MASTER
12340 && code
!= OMP_TASKGROUP
12341 && code
!= OMP_ORDERED
12342 && code
!= OMP_PARALLEL
12343 && code
!= OMP_SECTIONS
12344 && code
!= OMP_SECTION
12345 && code
!= OMP_SINGLE
);
12349 /* Otherwise we're gimplifying a subexpression, so the resulting
12350 value is interesting. If it's a valid operand that matches
12351 GIMPLE_TEST_F, we're done. Unless we are handling some
12352 post-effects internally; if that's the case, we need to copy into
12353 a temporary before adding the post-effects to POST_P. */
12354 if (gimple_seq_empty_p (internal_post
) && (*gimple_test_f
) (*expr_p
))
12357 /* Otherwise, we need to create a new temporary for the gimplified
12360 /* We can't return an lvalue if we have an internal postqueue. The
12361 object the lvalue refers to would (probably) be modified by the
12362 postqueue; we need to copy the value out first, which means an
12364 if ((fallback
& fb_lvalue
)
12365 && gimple_seq_empty_p (internal_post
)
12366 && is_gimple_addressable (*expr_p
))
12368 /* An lvalue will do. Take the address of the expression, store it
12369 in a temporary, and replace the expression with an INDIRECT_REF of
12371 tmp
= build_fold_addr_expr_loc (input_location
, *expr_p
);
12372 gimplify_expr (&tmp
, pre_p
, post_p
, is_gimple_reg
, fb_rvalue
);
12373 *expr_p
= build_simple_mem_ref (tmp
);
12375 else if ((fallback
& fb_rvalue
) && is_gimple_reg_rhs_or_call (*expr_p
))
12377 /* An rvalue will do. Assign the gimplified expression into a
12378 new temporary TMP and replace the original expression with
12379 TMP. First, make sure that the expression has a type so that
12380 it can be assigned into a temporary. */
12381 gcc_assert (!VOID_TYPE_P (TREE_TYPE (*expr_p
)));
12382 *expr_p
= get_formal_tmp_var (*expr_p
, pre_p
);
12386 #ifdef ENABLE_GIMPLE_CHECKING
12387 if (!(fallback
& fb_mayfail
))
12389 fprintf (stderr
, "gimplification failed:\n");
12390 print_generic_expr (stderr
, *expr_p
);
12391 debug_tree (*expr_p
);
12392 internal_error ("gimplification failed");
12395 gcc_assert (fallback
& fb_mayfail
);
12397 /* If this is an asm statement, and the user asked for the
12398 impossible, don't die. Fail and let gimplify_asm_expr
12404 /* Make sure the temporary matches our predicate. */
12405 gcc_assert ((*gimple_test_f
) (*expr_p
));
12407 if (!gimple_seq_empty_p (internal_post
))
12409 annotate_all_with_location (internal_post
, input_location
);
12410 gimplify_seq_add_seq (pre_p
, internal_post
);
12414 input_location
= saved_location
;
12418 /* Like gimplify_expr but make sure the gimplified result is not itself
12419 a SSA name (but a decl if it were). Temporaries required by
12420 evaluating *EXPR_P may be still SSA names. */
12422 static enum gimplify_status
12423 gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p
, gimple_seq
*post_p
,
12424 bool (*gimple_test_f
) (tree
), fallback_t fallback
,
12427 bool was_ssa_name_p
= TREE_CODE (*expr_p
) == SSA_NAME
;
12428 enum gimplify_status ret
= gimplify_expr (expr_p
, pre_p
, post_p
,
12429 gimple_test_f
, fallback
);
12431 && TREE_CODE (*expr_p
) == SSA_NAME
)
12433 tree name
= *expr_p
;
12434 if (was_ssa_name_p
)
12435 *expr_p
= get_initialized_tmp_var (*expr_p
, pre_p
, NULL
, false);
12438 /* Avoid the extra copy if possible. */
12439 *expr_p
= create_tmp_reg (TREE_TYPE (name
));
12440 gimple_set_lhs (SSA_NAME_DEF_STMT (name
), *expr_p
);
12441 release_ssa_name (name
);
12447 /* Look through TYPE for variable-sized objects and gimplify each such
12448 size that we find. Add to LIST_P any statements generated. */
12451 gimplify_type_sizes (tree type
, gimple_seq
*list_p
)
12455 if (type
== NULL
|| type
== error_mark_node
)
12458 /* We first do the main variant, then copy into any other variants. */
12459 type
= TYPE_MAIN_VARIANT (type
);
12461 /* Avoid infinite recursion. */
12462 if (TYPE_SIZES_GIMPLIFIED (type
))
12465 TYPE_SIZES_GIMPLIFIED (type
) = 1;
12467 switch (TREE_CODE (type
))
12470 case ENUMERAL_TYPE
:
12473 case FIXED_POINT_TYPE
:
12474 gimplify_one_sizepos (&TYPE_MIN_VALUE (type
), list_p
);
12475 gimplify_one_sizepos (&TYPE_MAX_VALUE (type
), list_p
);
12477 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
12479 TYPE_MIN_VALUE (t
) = TYPE_MIN_VALUE (type
);
12480 TYPE_MAX_VALUE (t
) = TYPE_MAX_VALUE (type
);
12485 /* These types may not have declarations, so handle them here. */
12486 gimplify_type_sizes (TREE_TYPE (type
), list_p
);
12487 gimplify_type_sizes (TYPE_DOMAIN (type
), list_p
);
12488 /* Ensure VLA bounds aren't removed, for -O0 they should be variables
12489 with assigned stack slots, for -O1+ -g they should be tracked
12491 if (!(TYPE_NAME (type
)
12492 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12493 && DECL_IGNORED_P (TYPE_NAME (type
)))
12494 && TYPE_DOMAIN (type
)
12495 && INTEGRAL_TYPE_P (TYPE_DOMAIN (type
)))
12497 t
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
12498 if (t
&& VAR_P (t
) && DECL_ARTIFICIAL (t
))
12499 DECL_IGNORED_P (t
) = 0;
12500 t
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
12501 if (t
&& VAR_P (t
) && DECL_ARTIFICIAL (t
))
12502 DECL_IGNORED_P (t
) = 0;
12508 case QUAL_UNION_TYPE
:
12509 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
12510 if (TREE_CODE (field
) == FIELD_DECL
)
12512 gimplify_one_sizepos (&DECL_FIELD_OFFSET (field
), list_p
);
12513 gimplify_one_sizepos (&DECL_SIZE (field
), list_p
);
12514 gimplify_one_sizepos (&DECL_SIZE_UNIT (field
), list_p
);
12515 gimplify_type_sizes (TREE_TYPE (field
), list_p
);
12520 case REFERENCE_TYPE
:
12521 /* We used to recurse on the pointed-to type here, which turned out to
12522 be incorrect because its definition might refer to variables not
12523 yet initialized at this point if a forward declaration is involved.
12525 It was actually useful for anonymous pointed-to types to ensure
12526 that the sizes evaluation dominates every possible later use of the
12527 values. Restricting to such types here would be safe since there
12528 is no possible forward declaration around, but would introduce an
12529 undesirable middle-end semantic to anonymity. We then defer to
12530 front-ends the responsibility of ensuring that the sizes are
12531 evaluated both early and late enough, e.g. by attaching artificial
12532 type declarations to the tree. */
12539 gimplify_one_sizepos (&TYPE_SIZE (type
), list_p
);
12540 gimplify_one_sizepos (&TYPE_SIZE_UNIT (type
), list_p
);
12542 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
12544 TYPE_SIZE (t
) = TYPE_SIZE (type
);
12545 TYPE_SIZE_UNIT (t
) = TYPE_SIZE_UNIT (type
);
12546 TYPE_SIZES_GIMPLIFIED (t
) = 1;
12550 /* A subroutine of gimplify_type_sizes to make sure that *EXPR_P,
12551 a size or position, has had all of its SAVE_EXPRs evaluated.
12552 We add any required statements to *STMT_P. */
12555 gimplify_one_sizepos (tree
*expr_p
, gimple_seq
*stmt_p
)
12557 tree expr
= *expr_p
;
12559 /* We don't do anything if the value isn't there, is constant, or contains
12560 A PLACEHOLDER_EXPR. We also don't want to do anything if it's already
12561 a VAR_DECL. If it's a VAR_DECL from another function, the gimplifier
12562 will want to replace it with a new variable, but that will cause problems
12563 if this type is from outside the function. It's OK to have that here. */
12564 if (expr
== NULL_TREE
12565 || is_gimple_constant (expr
)
12566 || TREE_CODE (expr
) == VAR_DECL
12567 || CONTAINS_PLACEHOLDER_P (expr
))
12570 *expr_p
= unshare_expr (expr
);
12572 /* SSA names in decl/type fields are a bad idea - they'll get reclaimed
12573 if the def vanishes. */
12574 gimplify_expr (expr_p
, stmt_p
, NULL
, is_gimple_val
, fb_rvalue
, false);
12576 /* If expr wasn't already is_gimple_sizepos or is_gimple_constant from the
12577 FE, ensure that it is a VAR_DECL, otherwise we might handle some decls
12578 as gimplify_vla_decl even when they would have all sizes INTEGER_CSTs. */
12579 if (is_gimple_constant (*expr_p
))
12580 *expr_p
= get_initialized_tmp_var (*expr_p
, stmt_p
, NULL
, false);
12583 /* Gimplify the body of statements of FNDECL and return a GIMPLE_BIND node
12584 containing the sequence of corresponding GIMPLE statements. If DO_PARMS
12585 is true, also gimplify the parameters. */
12588 gimplify_body (tree fndecl
, bool do_parms
)
12590 location_t saved_location
= input_location
;
12591 gimple_seq parm_stmts
, parm_cleanup
= NULL
, seq
;
12592 gimple
*outer_stmt
;
12595 timevar_push (TV_TREE_GIMPLIFY
);
12597 init_tree_ssa (cfun
);
12599 /* Initialize for optimize_insn_for_s{ize,peed}_p possibly called during
12601 default_rtl_profile ();
12603 gcc_assert (gimplify_ctxp
== NULL
);
12604 push_gimplify_context (true);
12606 if (flag_openacc
|| flag_openmp
)
12608 gcc_assert (gimplify_omp_ctxp
== NULL
);
12609 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl
)))
12610 gimplify_omp_ctxp
= new_omp_context (ORT_TARGET
);
12613 /* Unshare most shared trees in the body and in that of any nested functions.
12614 It would seem we don't have to do this for nested functions because
12615 they are supposed to be output and then the outer function gimplified
12616 first, but the g++ front end doesn't always do it that way. */
12617 unshare_body (fndecl
);
12618 unvisit_body (fndecl
);
12620 /* Make sure input_location isn't set to something weird. */
12621 input_location
= DECL_SOURCE_LOCATION (fndecl
);
12623 /* Resolve callee-copies. This has to be done before processing
12624 the body so that DECL_VALUE_EXPR gets processed correctly. */
12625 parm_stmts
= do_parms
? gimplify_parameters (&parm_cleanup
) : NULL
;
12627 /* Gimplify the function's body. */
12629 gimplify_stmt (&DECL_SAVED_TREE (fndecl
), &seq
);
12630 outer_stmt
= gimple_seq_first_stmt (seq
);
12633 outer_stmt
= gimple_build_nop ();
12634 gimplify_seq_add_stmt (&seq
, outer_stmt
);
12637 /* The body must contain exactly one statement, a GIMPLE_BIND. If this is
12638 not the case, wrap everything in a GIMPLE_BIND to make it so. */
12639 if (gimple_code (outer_stmt
) == GIMPLE_BIND
12640 && gimple_seq_first (seq
) == gimple_seq_last (seq
))
12641 outer_bind
= as_a
<gbind
*> (outer_stmt
);
12643 outer_bind
= gimple_build_bind (NULL_TREE
, seq
, NULL
);
12645 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
12647 /* If we had callee-copies statements, insert them at the beginning
12648 of the function and clear DECL_VALUE_EXPR_P on the parameters. */
12649 if (!gimple_seq_empty_p (parm_stmts
))
12653 gimplify_seq_add_seq (&parm_stmts
, gimple_bind_body (outer_bind
));
12656 gtry
*g
= gimple_build_try (parm_stmts
, parm_cleanup
,
12657 GIMPLE_TRY_FINALLY
);
12659 gimple_seq_add_stmt (&parm_stmts
, g
);
12661 gimple_bind_set_body (outer_bind
, parm_stmts
);
12663 for (parm
= DECL_ARGUMENTS (current_function_decl
);
12664 parm
; parm
= DECL_CHAIN (parm
))
12665 if (DECL_HAS_VALUE_EXPR_P (parm
))
12667 DECL_HAS_VALUE_EXPR_P (parm
) = 0;
12668 DECL_IGNORED_P (parm
) = 0;
12672 if ((flag_openacc
|| flag_openmp
|| flag_openmp_simd
)
12673 && gimplify_omp_ctxp
)
12675 delete_omp_context (gimplify_omp_ctxp
);
12676 gimplify_omp_ctxp
= NULL
;
12679 pop_gimplify_context (outer_bind
);
12680 gcc_assert (gimplify_ctxp
== NULL
);
12682 if (flag_checking
&& !seen_error ())
12683 verify_gimple_in_seq (gimple_bind_body (outer_bind
));
12685 timevar_pop (TV_TREE_GIMPLIFY
);
12686 input_location
= saved_location
;
12691 typedef char *char_p
; /* For DEF_VEC_P. */
12693 /* Return whether we should exclude FNDECL from instrumentation. */
12696 flag_instrument_functions_exclude_p (tree fndecl
)
12700 v
= (vec
<char_p
> *) flag_instrument_functions_exclude_functions
;
12701 if (v
&& v
->length () > 0)
12707 name
= lang_hooks
.decl_printable_name (fndecl
, 0);
12708 FOR_EACH_VEC_ELT (*v
, i
, s
)
12709 if (strstr (name
, s
) != NULL
)
12713 v
= (vec
<char_p
> *) flag_instrument_functions_exclude_files
;
12714 if (v
&& v
->length () > 0)
12720 name
= DECL_SOURCE_FILE (fndecl
);
12721 FOR_EACH_VEC_ELT (*v
, i
, s
)
12722 if (strstr (name
, s
) != NULL
)
12729 /* Entry point to the gimplification pass. FNDECL is the FUNCTION_DECL
12730 node for the function we want to gimplify.
12732 Return the sequence of GIMPLE statements corresponding to the body
12736 gimplify_function_tree (tree fndecl
)
12742 gcc_assert (!gimple_body (fndecl
));
12744 if (DECL_STRUCT_FUNCTION (fndecl
))
12745 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
12747 push_struct_function (fndecl
);
12749 /* Tentatively set PROP_gimple_lva here, and reset it in gimplify_va_arg_expr
12751 cfun
->curr_properties
|= PROP_gimple_lva
;
12753 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= DECL_CHAIN (parm
))
12755 /* Preliminarily mark non-addressed complex variables as eligible
12756 for promotion to gimple registers. We'll transform their uses
12757 as we find them. */
12758 if ((TREE_CODE (TREE_TYPE (parm
)) == COMPLEX_TYPE
12759 || TREE_CODE (TREE_TYPE (parm
)) == VECTOR_TYPE
)
12760 && !TREE_THIS_VOLATILE (parm
)
12761 && !needs_to_live_in_memory (parm
))
12762 DECL_GIMPLE_REG_P (parm
) = 1;
12765 ret
= DECL_RESULT (fndecl
);
12766 if ((TREE_CODE (TREE_TYPE (ret
)) == COMPLEX_TYPE
12767 || TREE_CODE (TREE_TYPE (ret
)) == VECTOR_TYPE
)
12768 && !needs_to_live_in_memory (ret
))
12769 DECL_GIMPLE_REG_P (ret
) = 1;
12771 if (asan_sanitize_use_after_scope () && sanitize_flags_p (SANITIZE_ADDRESS
))
12772 asan_poisoned_variables
= new hash_set
<tree
> ();
12773 bind
= gimplify_body (fndecl
, true);
12774 if (asan_poisoned_variables
)
12776 delete asan_poisoned_variables
;
12777 asan_poisoned_variables
= NULL
;
12780 /* The tree body of the function is no longer needed, replace it
12781 with the new GIMPLE body. */
12783 gimple_seq_add_stmt (&seq
, bind
);
12784 gimple_set_body (fndecl
, seq
);
12786 /* If we're instrumenting function entry/exit, then prepend the call to
12787 the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
12788 catch the exit hook. */
12789 /* ??? Add some way to ignore exceptions for this TFE. */
12790 if (flag_instrument_function_entry_exit
12791 && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl
)
12792 /* Do not instrument extern inline functions. */
12793 && !(DECL_DECLARED_INLINE_P (fndecl
)
12794 && DECL_EXTERNAL (fndecl
)
12795 && DECL_DISREGARD_INLINE_LIMITS (fndecl
))
12796 && !flag_instrument_functions_exclude_p (fndecl
))
12801 gimple_seq cleanup
= NULL
, body
= NULL
;
12802 tree tmp_var
, this_fn_addr
;
12805 /* The instrumentation hooks aren't going to call the instrumented
12806 function and the address they receive is expected to be matchable
12807 against symbol addresses. Make sure we don't create a trampoline,
12808 in case the current function is nested. */
12809 this_fn_addr
= build_fold_addr_expr (current_function_decl
);
12810 TREE_NO_TRAMPOLINE (this_fn_addr
) = 1;
12812 x
= builtin_decl_implicit (BUILT_IN_RETURN_ADDRESS
);
12813 call
= gimple_build_call (x
, 1, integer_zero_node
);
12814 tmp_var
= create_tmp_var (ptr_type_node
, "return_addr");
12815 gimple_call_set_lhs (call
, tmp_var
);
12816 gimplify_seq_add_stmt (&cleanup
, call
);
12817 x
= builtin_decl_implicit (BUILT_IN_PROFILE_FUNC_EXIT
);
12818 call
= gimple_build_call (x
, 2, this_fn_addr
, tmp_var
);
12819 gimplify_seq_add_stmt (&cleanup
, call
);
12820 tf
= gimple_build_try (seq
, cleanup
, GIMPLE_TRY_FINALLY
);
12822 x
= builtin_decl_implicit (BUILT_IN_RETURN_ADDRESS
);
12823 call
= gimple_build_call (x
, 1, integer_zero_node
);
12824 tmp_var
= create_tmp_var (ptr_type_node
, "return_addr");
12825 gimple_call_set_lhs (call
, tmp_var
);
12826 gimplify_seq_add_stmt (&body
, call
);
12827 x
= builtin_decl_implicit (BUILT_IN_PROFILE_FUNC_ENTER
);
12828 call
= gimple_build_call (x
, 2, this_fn_addr
, tmp_var
);
12829 gimplify_seq_add_stmt (&body
, call
);
12830 gimplify_seq_add_stmt (&body
, tf
);
12831 new_bind
= gimple_build_bind (NULL
, body
, NULL
);
12833 /* Replace the current function body with the body
12834 wrapped in the try/finally TF. */
12836 gimple_seq_add_stmt (&seq
, new_bind
);
12837 gimple_set_body (fndecl
, seq
);
12841 if (sanitize_flags_p (SANITIZE_THREAD
))
12843 gcall
*call
= gimple_build_call_internal (IFN_TSAN_FUNC_EXIT
, 0);
12844 gimple
*tf
= gimple_build_try (seq
, call
, GIMPLE_TRY_FINALLY
);
12845 gbind
*new_bind
= gimple_build_bind (NULL
, tf
, NULL
);
12846 /* Replace the current function body with the body
12847 wrapped in the try/finally TF. */
12849 gimple_seq_add_stmt (&seq
, new_bind
);
12850 gimple_set_body (fndecl
, seq
);
12853 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
12854 cfun
->curr_properties
|= PROP_gimple_any
;
12858 dump_function (TDI_gimple
, fndecl
);
12861 /* Return a dummy expression of type TYPE in order to keep going after an
12865 dummy_object (tree type
)
12867 tree t
= build_int_cst (build_pointer_type (type
), 0);
12868 return build2 (MEM_REF
, type
, t
, t
);
12871 /* Gimplify __builtin_va_arg, aka VA_ARG_EXPR, which is not really a
12872 builtin function, but a very special sort of operator. */
12874 enum gimplify_status
12875 gimplify_va_arg_expr (tree
*expr_p
, gimple_seq
*pre_p
,
12876 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
12878 tree promoted_type
, have_va_type
;
12879 tree valist
= TREE_OPERAND (*expr_p
, 0);
12880 tree type
= TREE_TYPE (*expr_p
);
12881 tree t
, tag
, aptag
;
12882 location_t loc
= EXPR_LOCATION (*expr_p
);
12884 /* Verify that valist is of the proper type. */
12885 have_va_type
= TREE_TYPE (valist
);
12886 if (have_va_type
== error_mark_node
)
12888 have_va_type
= targetm
.canonical_va_list_type (have_va_type
);
12889 if (have_va_type
== NULL_TREE
12890 && POINTER_TYPE_P (TREE_TYPE (valist
)))
12891 /* Handle 'Case 1: Not an array type' from c-common.c/build_va_arg. */
12893 = targetm
.canonical_va_list_type (TREE_TYPE (TREE_TYPE (valist
)));
12894 gcc_assert (have_va_type
!= NULL_TREE
);
12896 /* Generate a diagnostic for requesting data of a type that cannot
12897 be passed through `...' due to type promotion at the call site. */
12898 if ((promoted_type
= lang_hooks
.types
.type_promotes_to (type
))
12901 static bool gave_help
;
12903 /* Use the expansion point to handle cases such as passing bool (defined
12904 in a system header) through `...'. */
12905 source_location xloc
12906 = expansion_point_location_if_in_system_header (loc
);
12908 /* Unfortunately, this is merely undefined, rather than a constraint
12909 violation, so we cannot make this an error. If this call is never
12910 executed, the program is still strictly conforming. */
12911 warned
= warning_at (xloc
, 0,
12912 "%qT is promoted to %qT when passed through %<...%>",
12913 type
, promoted_type
);
12914 if (!gave_help
&& warned
)
12917 inform (xloc
, "(so you should pass %qT not %qT to %<va_arg%>)",
12918 promoted_type
, type
);
12921 /* We can, however, treat "undefined" any way we please.
12922 Call abort to encourage the user to fix the program. */
12924 inform (xloc
, "if this code is reached, the program will abort");
12925 /* Before the abort, allow the evaluation of the va_list
12926 expression to exit or longjmp. */
12927 gimplify_and_add (valist
, pre_p
);
12928 t
= build_call_expr_loc (loc
,
12929 builtin_decl_implicit (BUILT_IN_TRAP
), 0);
12930 gimplify_and_add (t
, pre_p
);
12932 /* This is dead code, but go ahead and finish so that the
12933 mode of the result comes out right. */
12934 *expr_p
= dummy_object (type
);
12935 return GS_ALL_DONE
;
12938 tag
= build_int_cst (build_pointer_type (type
), 0);
12939 aptag
= build_int_cst (TREE_TYPE (valist
), 0);
12941 *expr_p
= build_call_expr_internal_loc (loc
, IFN_VA_ARG
, type
, 3,
12942 valist
, tag
, aptag
);
12944 /* Clear the tentatively set PROP_gimple_lva, to indicate that IFN_VA_ARG
12945 needs to be expanded. */
12946 cfun
->curr_properties
&= ~PROP_gimple_lva
;
12951 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
12953 DST/SRC are the destination and source respectively. You can pass
12954 ungimplified trees in DST or SRC, in which case they will be
12955 converted to a gimple operand if necessary.
12957 This function returns the newly created GIMPLE_ASSIGN tuple. */
12960 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
12962 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
12963 gimplify_and_add (t
, seq_p
);
12965 return gimple_seq_last_stmt (*seq_p
);
12969 gimplify_hasher::hash (const elt_t
*p
)
12972 return iterative_hash_expr (t
, 0);
12976 gimplify_hasher::equal (const elt_t
*p1
, const elt_t
*p2
)
12980 enum tree_code code
= TREE_CODE (t1
);
12982 if (TREE_CODE (t2
) != code
12983 || TREE_TYPE (t1
) != TREE_TYPE (t2
))
12986 if (!operand_equal_p (t1
, t2
, 0))
12989 /* Only allow them to compare equal if they also hash equal; otherwise
12990 results are nondeterminate, and we fail bootstrap comparison. */
12991 gcc_checking_assert (hash (p1
) == hash (p2
));